Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.

The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.

Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print  - 1.

NoteIn the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.


You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW".Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).

The first line of the input contains one integer n (2 ≤ n ≤ 100, n is even) — the size of the chessboard.  The second line of the input contains  integer numbers  (1 ≤ pi ≤ n) — initial positions of the pieces. It is guaranteed that all the positions are distinct.

Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.

NoteIn the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.In the second example the possible strategy is to move  in 4 moves, then  in 3 moves,  in 2 moves and  in 1 move.

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


As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!

The first input line contains an integer n (1 ≤ n ≤ 109).

Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).

NoteIn the first sample number .In the second sample number 512 can not be represented as a sum of two triangular numbers.

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;


The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good:    Elements of the main diagonal.   Elements of the secondary diagonal.   Elements of the "middle" row — the row which has exactly  rows above it and the same number of rows below it.   Elements of the "middle" column — the column that has exactly  columns to the left of it and the same number of columns to the right of it.    The figure shows a 5 × 5 matrix.   The good elements are marked with green.  Help the Smart Beaver count the sum of good elements of the given matrix.

The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are:    1 ≤ n ≤ 5  The input limitations for getting 100 points are:   1 ≤ n ≤ 101

Print a single integer — the sum of good matrix elements.

NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure.


Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions:   After the cutting each ribbon piece should have length a, b or c.  After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting.

The first line contains four space-separated integers n, a, b and c (1 ≤ n, a, b, c ≤ 4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers a, b and c can coincide.

Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.

NoteIn the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.

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

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


Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?

The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.

In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).

NoteIn the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.

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


Vasya plays Robot Bicorn Attack.The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string s. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string s.Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round.

The only line of input contains non-empty string s obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters.

Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1.

NoteIn the first example the string must be split into numbers 1, 2 and 34.In the second example the string must be split into numbers 90, 0 and 0. In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes.


Drazil is playing a math game with Varda.Let's define  for positive integer x as a product of factorials of its digits. For example, .First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:1. x doesn't contain neither digit 0 nor digit 1.2.  = .Help friends find such number.

The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in a. The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.

Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.

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;

}


Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.

The only line of the input contains a single integer n (1 ≤ n ≤ 1000) — the position of the digit you need to print.

NoteIn the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.In the second sample, the digit at position 11 is '0', it belongs to the integer 10.

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


Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.You are given a string $$$s$$$ consisting of $$$n$$$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $$$s$$$ = "BBAABBBA" the answer is two-gram "BB", which contained in $$$s$$$ three times. In other words, find any most frequent two-gram.Note that occurrences of the two-gram can overlap with each other.

The first line of the input contains integer number $$$n$$$ ($$$2 \le n \le 100$$$) — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ capital Latin letters.

Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $$$s$$$ as a substring (i.e. two consecutive characters of the string) maximal number of times.

NoteIn the first example "BA" is also valid answer.In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.

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


Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically  — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $$$4.5$$$ would be rounded up to $$$5$$$ (as in example 3), but $$$4.4$$$ would be rounded down to $$$4$$$.This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $$$5$$$ (maybe even the dreaded $$$2$$$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $$$5$$$ for the course. Of course, Vasya will get $$$5$$$ for the lab works he chooses to redo.Help Vasya — calculate the minimum amount of lab works Vasya has to redo.

The first line contains a single integer $$$n$$$ — the number of Vasya's grades ($$$1 \leq n \leq 100$$$). The second line contains $$$n$$$ integers from $$$2$$$ to $$$5$$$ — Vasya's grades for his lab works.

Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $$$5$$$.

NoteIn the first sample, it is enough to redo two lab works to make two $$$4$$$s into $$$5$$$s.In the second sample, Vasya's average is already $$$4.75$$$ so he doesn't have to redo anything to get a $$$5$$$.In the second sample Vasya has to redo one lab work to get rid of one of the $$$3$$$s, that will make the average exactly $$$4.5$$$ so the final grade would be $$$5$$$.


Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).  Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.

The first line contains a single integer n (1 ≤ n ≤ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 ≤ xi ≤ 106) — the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.

In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).

NoteThe first test from the statement is on the picture to the left, the second test is on the picture to the right.

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


Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters.There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers.The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking!

The first line contains a positive integer n (1 ≤ n ≤ 100) — the length of the interview. The second line contains the string s of length n, consisting of lowercase English letters.

Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.

NoteThe first sample contains one filler word ogogo, so the interview for printing is "a***b".The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".

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

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

use strict;
use warnings;

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

print $str . "\n";

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

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


Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.Solve the problem to show that it's not a NP problem.

The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).

Print single integer, the integer that appears maximum number of times in the divisors.  If there are multiple answers, print any of them.

NoteDefinition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.htmlThe first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

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

	}


Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n + 1)-th day again he uses the pen number 1, on the (n + 2)-th — he uses the pen number 2 and so on.On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the pen he uses that day. On Sunday Stepan has a day of rest, he does not stend the ink of the pen he uses that day. Stepan knows the current volume of ink in each of his pens. Now it's the Monday morning and Stepan is going to use the pen number 1 today. Your task is to determine which pen will run out of ink before all the rest (that is, there will be no ink left in it), if Stepan will use the pens according to the conditions described above.

The first line contains the integer n (1 ≤ n ≤ 50 000) — the number of pens Stepan has. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of milliliters of ink which the pen number i currently has.

Print the index of the pen which will run out of ink before all (it means that there will be no ink left in it), if Stepan will use pens according to the conditions described above.  Pens are numbered in the order they are given in input data. The numeration begins from one.  Note that the answer is always unambiguous, since several pens can not end at the same time.

NoteIn the first test Stepan uses ink of pens as follows:   on the day number 1 (Monday) Stepan will use the pen number 1, after that there will be 2 milliliters of ink in it;  on the day number 2 (Tuesday) Stepan will use the pen number 2, after that there will be 2 milliliters of ink in it;  on the day number 3 (Wednesday) Stepan will use the pen number 3, after that there will be 2 milliliters of ink in it;  on the day number 4 (Thursday) Stepan will use the pen number 1, after that there will be 1 milliliters of ink in it;  on the day number 5 (Friday) Stepan will use the pen number 2, after that there will be 1 milliliters of ink in it;  on the day number 6 (Saturday) Stepan will use the pen number 3, after that there will be 1 milliliters of ink in it;  on the day number 7 (Sunday) Stepan will use the pen number 1, but it is a day of rest so he will not waste ink of this pen in it;  on the day number 8 (Monday) Stepan will use the pen number 2, after that this pen will run out of ink. So, the first pen which will not have ink is the pen number 2.


Polycarp is going to participate in the contest. It starts at $$$h_1:m_1$$$ and ends at $$$h_2:m_2$$$. It is guaranteed that the contest lasts an even number of minutes (i.e. $$$m_1 \% 2 = m_2 \% 2$$$, where $$$x \% y$$$ is $$$x$$$ modulo $$$y$$$). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from $$$10:00$$$ to $$$11:00$$$ then the answer is $$$10:30$$$, if the contest lasts from $$$11:10$$$ to $$$11:12$$$ then the answer is $$$11:11$$$.

The first line of the input contains two integers $$$h_1$$$ and $$$m_1$$$ in the format hh:mm. The second line of the input contains two integers $$$h_2$$$ and $$$m_2$$$ in the same format (hh:mm). It is guaranteed that $$$0 \le h_1, h_2 \le 23$$$ and $$$0 \le m_1, m_2 \le 59$$$. It is guaranteed that the contest lasts an even number of minutes (i.e. $$$m_1 \% 2 = m_2 \% 2$$$, where $$$x \% y$$$ is $$$x$$$ modulo $$$y$$$). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.

Print two integers $$$h_3$$$ and $$$m_3$$$ ($$$0 \le h_3 \le 23, 0 \le m_3 \le 59$$$) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.


This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly  times consecutively. In other words, array a is k-periodic, if it has period of length k.For example, any array is n-periodic, where n is the array length. Array [2, 1, 2, 1, 2, 1] is at the same time 2-periodic and 6-periodic and array [1, 2, 1, 1, 2, 1, 1, 2, 1] is at the same time 3-periodic and 9-periodic.For the given array a, consisting only of numbers one and two, find the minimum number of elements to change to make the array k-periodic. If the array already is k-periodic, then the required value equals 0.

The first line of the input contains a pair of integers n, k (1 ≤ k ≤ n ≤ 100), where n is the length of the array and the value n is divisible by k. The second line contains the sequence of elements of the given array a1, a2, ..., an (1 ≤ ai ≤ 2), ai is the i-th element of the array.

Print the minimum number of array elements we need to change to make the array k-periodic. If the array already is k-periodic, then print 0.

NoteIn the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1].In the second sample, the given array already is 4-periodic.In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1, 1, 1, 1, 1, 1] — this array is simultaneously 1-, 3- and 9-periodic.

#!/usr/bin/perl

use bignum;

$PI=3.14159265358979323846;
$MOD=1000000007;

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

while(<>=~/ /){
	$ats=0;
	@a=();
	@_=split/ /,<>;
	for $j(0..@_-1){
		$_[$j]-1 and $a[$j%$']++;
		}
#	print "@a\n";
	for (@a){
		$_ and $ats+=min($`/$'-$_,$_)
		}
	print "$ats\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
}


Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t + s, t + s + 1, t + 2s, t + 2s + 1, etc.  Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time x (in seconds), so he asked you to tell him if it's gonna bark at that time.

The first and only line of input contains three integers t, s and x (0 ≤ t, x ≤ 109, 2 ≤ s ≤ 109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.

Print a single "YES" (without quotes) if the pineapple will bark at time x or a single "NO" (without quotes) otherwise in the only line of output.

NoteIn the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52.


Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation:x = b·s(x)a + c,  where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x.The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.

The first line contains three space-separated integers: a, b, c (1 ≤ a ≤ 5; 1 ≤ b ≤ 10000;  - 10000 ≤ c ≤ 10000).

Print integer n — the number of the solutions that you've found. Next print n integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.


In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: "North", "South", "West", "East".Limak isn’t sure whether the description is valid. You must help him to check the following conditions:  If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South.  If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North.  The journey must end on the North Pole. Check if the above conditions are satisfied and print "YES" or "NO" on a single line.

The first line of the input contains a single integer n (1 ≤ n ≤ 50). The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, ) — the length and the direction of the i-th part of the journey, according to the description Limak got.

Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.

5
7500 South
10000 East
3500 North
4444 West
4000 North

4
50 South
50 North
15000 South
15000 North

NoteDrawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole.


Arkadiy has lots square photos with size a × a. He wants to put some of them on a rectangular wall with size h × w. The photos which Arkadiy will put on the wall must form a rectangular grid and the distances between neighboring vertically and horizontally photos and also the distances between outside rows and columns of photos to the nearest bound of the wall must be equal to x, where x is some non-negative real number. Look on the picture below for better understanding of the statement.  Arkadiy haven't chosen yet how many photos he would put on the wall, however, he want to put at least one photo. Your task is to determine the minimum value of x which can be obtained after putting photos, or report that there is no way to put positive number of photos and satisfy all the constraints. Suppose that Arkadiy has enough photos to make any valid arrangement according to the constraints.Note that Arkadiy wants to put at least one photo on the wall. The photos should not overlap, should completely lie inside the wall bounds and should have sides parallel to the wall sides.

The first line contains three integers a, h and w (1 ≤ a, h, w ≤ 109) — the size of photos and the height and the width of the wall.

Print one non-negative real number — the minimum value of x which can be obtained after putting the photos on the wall. The absolute or the relative error of the answer must not exceed 10 - 6. Print -1 if there is no way to put positive number of photos and satisfy the constraints.

NoteIn the first example Arkadiy can put 7 rows of photos with 5 photos in each row, so the minimum value of x equals to 0.5.In the second example Arkadiy can put only 1 photo which will take the whole wall, so the minimum value of x equals to 0.In the third example there is no way to put positive number of photos and satisfy the constraints described in the statement, so the answer is -1.


Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 × 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.  The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.  Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.

The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 ≤ r1, r2, c1, c2, d1, d2 ≤ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.

Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes). If there are several solutions, output any.

NotePay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.


Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a and b can be either painted Red or Blue.After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue.Note that she can paint tiles in any order she wants.Given the required information, find the maximum number of chocolates Joty can get.

The only line contains five integers n, a, b, p and q (1 ≤ n, a, b, p, q ≤ 109).

Print the only integer s — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

# read and parse one line
sub rd {
    my $f = <STDIN>;
    chomp ( $f );
    my @r = split m/ /, $f;
    return @r;
}

# maximum function
sub max {
    return ($_[0] > $_[1] ? $_[0] : $_[1]);
}

# euclid's algorithm
sub gcd {
    my $a = shift @_;
    my $b = shift @_;
    if ( $b == 0 ) {
	return $a;
    }
    else {
	return &gcd ( $b, $a % $b );
    }
}

my $n, $a, $b, $p, $q;
($n, $a, $b, $p, $q) = &rd;

my $sum = 0;
my $bigger = max ( $p, $q );

my $num_a = 0;
my $num_b = 0;
my $num_both = 0;
my $gcd = &gcd( $a, $b );
my $lcm = ($a / $gcd) * ($b / $gcd) * $gcd;

$num_both = int ($n / ($lcm));
$num_a = int (($n / $a) - $num_both);
$num_b = int (($n / $b) - $num_both);

my $ans = 0;

$ans = ($num_a * $p) + ($num_b * $q) + ($num_both * $bigger);

print "$ans\n";

# read and parse one line
sub rd {
    my $f = <STDIN>;
    chomp ( $f );
    my @r = split m/ /, $f;
    return @r;
}

# maximum function
sub max {
    return ($_[0] > $_[1] ? $_[0] : $_[1]);
}

my $n, $a, $b, $p, $q;
($n, $a, $b, $p, $q) = &rd;

my $sum = 0;
my $bigger = max ( $p, $q );

my $num_a = 0;
my $num_b = 0;
my $num_both = 0;

$num_both = int ($n / ($a * $b));
$num_a = int (($n / $a) - $num_both);
$num_b = int (($n / $b) - $num_both);

my $ans = 0;

$ans = ($num_a * $p) + ($num_b * $q) + ($num_both * $bigger);

print "$ans\n";


Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:  After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.

The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.

Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.

Note   To print the string from the first sample it would be optimal to perform the following sequence of rotations:   from 'a' to 'z' (1 rotation counterclockwise),  from 'z' to 'e' (5 clockwise rotations),  from 'e' to 'u' (10 rotations counterclockwise),  from 'u' to 's' (2 counterclockwise rotations).  In total, 1 + 5 + 10 + 2 = 18 rotations are required.

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;


The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.Help the park administration count the number of ways to place the benches.

The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.

Output one integer — the number of ways to place the benches.

#!/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**2 * ($n-1)**2 * ($n-2)**2 * ($n-3)**2 * ($n-4)**2)/120;
print "$result\n";


You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.

First line contains an integer n (6 ≤ n ≤ 8) – the length of the string. Next line contains a string consisting of n characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).

Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).

NoteHere's a set of names in a form you can paste into your solution:["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}

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

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

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


One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.

The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends. Next line contains string s — colors of baloons.

Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary.

NoteIn the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».


While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:  Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":    Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?

The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.

If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line.

NoteYou can find the picture clarifying the first sample case in the statement above.


This version of the problem differs from the next one only in the constraint on $$$n$$$.Note that the memory limit in this problem is lower than in others.You have a vertical strip with $$$n$$$ cells, numbered consecutively from $$$1$$$ to $$$n$$$ from top to bottom.You also have a token that is initially placed in cell $$$n$$$. You will move the token up until it arrives at cell $$$1$$$.Let the token be in cell $$$x > 1$$$ at some moment. One shift of the token can have either of the following kinds:   Subtraction: you choose an integer $$$y$$$ between $$$1$$$ and $$$x-1$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$x - y$$$.  Floored division: you choose an integer $$$z$$$ between $$$2$$$ and $$$x$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$\lfloor \frac{x}{z} \rfloor$$$ ($$$x$$$ divided by $$$z$$$ rounded down). Find the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$ using one or more shifts, and print it modulo $$$m$$$. Note that if there are several ways to move the token from one cell to another in one shift, all these ways are considered distinct (check example explanation for a better understanding).

The only line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$10^8 < m < 10^9$$$; $$$m$$$ is a prime number) — the length of the strip and the modulo.

Print the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$, modulo $$$m$$$.

NoteIn the first test, there are three ways to move the token from cell $$$3$$$ to cell $$$1$$$ in one shift: using subtraction of $$$y = 2$$$, or using division by $$$z = 2$$$ or $$$z = 3$$$.There are also two ways to move the token from cell $$$3$$$ to cell $$$1$$$ via cell $$$2$$$: first subtract $$$y = 1$$$, and then either subtract $$$y = 1$$$ again or divide by $$$z = 2$$$.Therefore, there are five ways in total.


From beginning till end, this message has been waiting to be conveyed.For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times:  Remove any two elements s and t from the set, and add their concatenation s + t to the set. The cost of such operation is defined to be , where f(s, c) denotes the number of times character c appears in string s.Given a non-negative integer k, construct any valid non-empty set of no more than 100 000 letters, such that the minimum accumulative cost of the whole process is exactly k. It can be shown that a solution always exists.

The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.

Output a non-empty string of no more than 100 000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string. Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters.

NoteFor the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows:  {"ab", "a", "b", "a", "b", "a", "b"}, with a cost of 0;  {"aba", "b", "a", "b", "a", "b"}, with a cost of 1;  {"abab", "a", "b", "a", "b"}, with a cost of 1;  {"abab", "ab", "a", "b"}, with a cost of 0;  {"abab", "aba", "b"}, with a cost of 1;  {"abab", "abab"}, with a cost of 1;  {"abababab"}, with a cost of 8. The total cost is 12, and it can be proved to be the minimum cost of the process.

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

	}


You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?

Input will begin with an integer N (1 ≤ N ≤ 50), the number of slices of pie.  Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.

Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.

NoteIn the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.

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


Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $$$n$$$ rows and $$$m$$$ columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo $$$10^9 + 7$$$.

The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100\,000$$$), the number of rows and the number of columns of the field.

Print one integer, the number of random pictures modulo $$$10^9 + 7$$$.

NoteThe picture below shows all possible random pictures of size $$$2$$$ by $$$3$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

my $MOD = 1e9 + 7;

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

	my( $n, $m ) = split;

	$debug and print "[$n $m]";

	print +( fib( $n - 0 ) * 2 + 2 * fib( $m - 0 ) - 2 ) % $MOD;
	}

sub fib {
	my $fib = shift;

	my $i = 1;
	my $j = 1;

	while( $fib >= 1 ){
		$fib --;
		my $tmp = $j;
		$j += $i;
		$i = $tmp;

		$j %= $MOD;
		}

	return $i % $MOD;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

my $MOD = 1e9 + 7;

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

	my( $n, $m ) = split;

	$debug and print "[$n $m]";

	print fib( $n - 0 ) * 2 + 2 * fib( $m - 0 ) - 2;
	}

sub fib {
	my $fib = shift;

	my $i = 1;
	my $j = 1;

	while( $fib >= 1 ){
		$fib --;
		my $tmp = $j;
		$j += $i;
		$i = $tmp;

		$j %= $MOD;
		}

	return $i % $MOD;
	}


Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them.Your task is: given the n and t print an integer strictly larger than zero consisting of n digits that is divisible by t. If such number doesn't exist, print  - 1.

The single line contains two numbers, n and t (1 ≤ n ≤ 100, 2 ≤ t ≤ 10) — the length of the number and the number it should be divisible by.

Print one such positive number without leading zeroes, — the answer to the problem, or  - 1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.

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


Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum:Find the sum modulo 1073741824 (230).

The first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 2000).

Print a single integer — the required sum modulo 1073741824 (230).

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;


There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", "D" and "C") and a rank (in the increasing order "6", "7", "8", "9", "T", "J", "Q", "K" and "A"). At the beginning of the game one suit is arbitrarily chosen as trump. The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards’ ranks are. In all other cases you can not beat the second card with the first one.You are given the trump suit and two different cards. Determine whether the first one beats the second one or not.

The first line contains the tramp suit. It is "S", "H", "D" or "C". The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the suit ("S", "H", "D" and "C").

Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes).


You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.Your task is to find such minimum number v, that you can form presents using numbers from a set 1, 2, ..., v. Of course you may choose not to present some numbers at all.A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.

The only line contains four positive integers cnt1, cnt2, x, y (1 ≤ cnt1, cnt2 < 109; cnt1 + cnt2 ≤ 109; 2 ≤ x < y ≤ 3·104) — the numbers that are described in the statement. It is guaranteed that numbers x, y are prime.

Print a single integer — the answer to the problem.

NoteIn the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend. In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4.

use strict;
use warnings;

my ($cnt1, $cnt2, $x, $y) = split(' ', <>);
my $low = 1; my $high = 1 << 31; my $mid; my $ans = $high;

for(0..60){
	$mid = ($low + $high) >> 1;

	my $c = int($mid / ($x * $y));

	if($mid - $c >= $cnt1 + $cnt2){
		$ans = $ans > $mid ? $mid : $ans;
		$high = $mid;
	}
	else{
		$low = $mid + 1;
	}
}

print $ans;


Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word s.

The first and only line contains the word s, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.

If Vasya managed to say hello, print "YES", otherwise print "NO".

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

}


«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every k-th dragon got punched in the face with a frying pan. Every l-th dragon got his tail shut into the balcony door. Every m-th dragon got his paws trampled with sharp heels. Finally, she threatened every n-th dragon to call her mom, and he withdrew in panic.How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of d dragons?

Input data contains integer numbers k, l, m, n and d, each number in a separate line (1 ≤ k, l, m, n ≤ 10, 1 ≤ d ≤ 105).

NoteIn the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.

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

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

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

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

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;


Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.  Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x = A × 10B is true. In our case A is between 0 and 9 and B is non-negative.Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.

The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character 'e' (0 ≤ a ≤ 9, 0 ≤ d < 10100, 0 ≤ b ≤ 100) — the scientific notation of the desired distance value. a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.

Print the only real number x (the desired distance value) in the only line in its decimal notation.  Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.  Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).


— Thanks a lot for today.— I experienced so many great things.— You gave me memories like dreams... But I have to leave now...— One last request, can you...— Help me solve a Codeforces problem?— ......— What?Chtholly has been thinking about a problem for days:If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!

The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).

Output single integer — answer to the problem.

NoteIn the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.In the second example, .

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


There is a building consisting of $$$10~000$$$ apartments numbered from $$$1$$$ to $$$10~000$$$, inclusive.Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are $$$11, 2, 777, 9999$$$ and so on.Our character is a troublemaker, and he calls the intercoms of all boring apartments, till someone answers the call, in the following order:  First he calls all apartments consisting of digit $$$1$$$, in increasing order ($$$1, 11, 111, 1111$$$).  Next he calls all apartments consisting of digit $$$2$$$, in increasing order ($$$2, 22, 222, 2222$$$)  And so on. The resident of the boring apartment $$$x$$$ answers the call, and our character stops calling anyone further.Our character wants to know how many digits he pressed in total and your task is to help him to count the total number of keypresses.For example, if the resident of boring apartment $$$22$$$ answered, then our character called apartments with numbers $$$1, 11, 111, 1111, 2, 22$$$ and the total number of digits he pressed is $$$1 + 2 + 3 + 4 + 1 + 2 = 13$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 36$$$) — the number of test cases. The only line of the test case contains one integer $$$x$$$ ($$$1 \le x \le 9999$$$) — the apartment number of the resident who answered the call. It is guaranteed that $$$x$$$ consists of the same digit.

For each test case, print the answer: how many digits our character pressed in total.


Fox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small as possible.Please help Ciel to find this minimal sum.

The first line contains an integer n (2 ≤ n ≤ 100). Then the second line contains n integers: x1, x2, ..., xn (1 ≤ xi ≤ 100).

Output a single integer — the required minimal sum.

NoteIn the first example the optimal way is to do the assignment: x2 = x2 - x1.In the second example the optimal sequence of operations is: x3 = x3 - x2, x2 = x2 - x1.

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


Imagine a city with n horizontal streets crossing m vertical streets, forming an (n - 1) × (m - 1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.  The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.

The first line of input contains two integers n and m, (2 ≤ n, m ≤ 20), denoting the number of horizontal streets and the number of vertical streets. The second line contains a string of length n, made of characters '<' and '>', denoting direction of each horizontal street. If the i-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south. The third line contains a string of length m, made of characters '^' and 'v', denoting direction of each vertical street. If the i-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.

If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".

NoteThe figure above shows street directions in the second sample test case.


In Omkar's last class of math, he learned about the least common multiple, or $$$LCM$$$. $$$LCM(a, b)$$$ is the smallest positive integer $$$x$$$ which is divisible by both $$$a$$$ and $$$b$$$.Omkar, having a laudably curious mind, immediately thought of a problem involving the $$$LCM$$$ operation: given an integer $$$n$$$, find positive integers $$$a$$$ and $$$b$$$ such that $$$a + b = n$$$ and $$$LCM(a, b)$$$ is the minimum value possible.Can you help Omkar solve his ludicrously challenging math problem?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10$$$). Description of the test cases follows. Each test case consists of a single integer $$$n$$$ ($$$2 \leq n \leq 10^{9}$$$).

For each test case, output two positive integers $$$a$$$ and $$$b$$$, such that $$$a + b = n$$$ and $$$LCM(a, b)$$$ is the minimum possible.

NoteFor the first test case, the numbers we can choose are $$$1, 3$$$ or $$$2, 2$$$. $$$LCM(1, 3) = 3$$$ and $$$LCM(2, 2) = 2$$$, so we output $$$2 \ 2$$$.For the second test case, the numbers we can choose are $$$1, 5$$$, $$$2, 4$$$, or $$$3, 3$$$. $$$LCM(1, 5) = 5$$$, $$$LCM(2, 4) = 4$$$, and $$$LCM(3, 3) = 3$$$, so we output $$$3 \ 3$$$.For the third test case, $$$LCM(3, 6) = 6$$$. It can be shown that there are no other pairs of numbers which sum to $$$9$$$ that have a lower $$$LCM$$$.


Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the size of downloaded data per second.The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.Let's suppose that video's length is c seconds and Valeric and Valerko wait t seconds before the watching. Then for any moment of time t0, t ≤ t0 ≤ c + t, the following condition must fulfill: the size of data received in t0 seconds is not less than the size of data needed to watch t0 - t seconds of the video.Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses.

The first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 1000, a > b). The first number (a) denotes the size of data needed to watch one second of the video. The second number (b) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (c) denotes the video's length in seconds.

Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses.

NoteIn the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watching video 1 second, one unit of data will be downloaded and Valerik and Valerko will have 4 units of data by the end of watching. Also every moment till the end of video guys will have more data then necessary for watching.In the second sample guys need 2 · 10 = 20 units of data, so they have to wait 5 seconds and after that they will have 20 units before the second second ends. However, if guys wait 4 seconds, they will be able to watch first second of video without pauses, but they will download 18 units of data by the end of second second and it is less then necessary.

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