<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));

if($a > $b){
  echo "a > b".PHP_EOL;
}else if($a < $b){
  "a < b".PHP_EOL;
}else{
  "a == b".PHP_EOL;
}

Small, Large, or Equal

Write a program which prints small/large/equal relation of given two integers a and b.

Input

Two integers a and b separated by a single space are given in a line.

Output

For given two integers a and b, print

a < b

if a is less than b,

a > b

if a is greater than b, and

a == b

if a equals to b.

Constraints

-1000 ≤ a, b ≤ 1000

Sample Input 1

1 2

Sample Output 1

a < b

Sample Input 2

4 3

Sample Output 2

a > b

Sample Input 3

5 5

Sample Output 3

a == b


<?php
if (basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {
  while ($line = fgets(STDIN)) {
      list($a, $b) = explode(' ', $line);
      $c = null;
      if ($a == $b) {
        $c = '==';
      } else if ($a > $b) {
          $c = '>';
      } else {
          $c = '<';
      }
      echo 'a ' . $c . ' b';
  }
}
?>

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


<?php
$num = trim(fgets(STDIN));
$tmp = explode(' ', $num);
if ($tmp[0] > $tmp[1]) {
 echo 'a > b';
} else if ($tmp[0] > $tmp[1]) {
 echo 'a < b';
} else {
 echo 'a == b';
}
?>


<?php

while($line=fgets(STDIN)){
    $data = explode(" ", $line);
    if ($data[0] > $data[1]) {
        echo "a > b" . PHP_EOL;
    } elseif($data[0] < $data[1]) {
        echo "a < b" . PHP_EOL;
    } else {
        echo "a == b" . PHP_EOL;
    }
}


<?php
    $x = fgets(STDIN);
    $ary = explode(" ",$x);
    if($ary[0] < $ary[1]){
        echo "a < b\n";
    }elseif($ary[0] > $ary[1]){
        echo "a > b\n";
    }elseif($ary[0] == $ary[1]){
        echo "a = b\n";
    }


<?php

fscanf(STDIN, '%d %d %d', $a, $b, $c);

if ($a < $b && $b < $c) {
    echo 'Yes';
} else {
    echo 'No';
}

echo PHP_EOL;

Range

Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".

Input

Three integers a, b and c separated by a single space are given in a line.

Output

Print "Yes" or "No" in a line.

Constraints

0 ≤ a, b, c ≤ 100

Sample Input 1

1 3 8

Sample Output 1

Yes

Sample Input 2

3 8 1

Sample Output 2

No


<?php

$stdin = preg_split('/ /', trim(fgets(STDIN)));
$a = intval($stdin[0]);
$b = intval($stdin[1]);
$c = intval($stdin[2]);

if ($a < $b && $b < $c) {
	print("Yes\n");
} else {
	print("No\n");
}


<?php

fscanf(STDIN, "%d %d %d", $a, $b, $c);

$result = ($a < $b && $b < $c) ? ('Yes') : ('No');
printf("%s%s", $result, PHP_EOL);


<?php
$input = trim(fgets(STDIN));
list($a,$b,$c) = explode(" ", $input);
if($a < $b){
    if($b < $c){
    echo "Yes\n";
    }else{
        echo "No\n";
    }
}else{
    echo "No\n";
}


<?php
list($a,$b,$c) = explode(' ', trim(fgets(STDIN)));
if ($a < $b && $b < $c) {
  print("Yes");
} else {
  print("No");
}
?>


<?php
list($a,$b,$c) = explode(' ', trim(fgets(STDIN)));
if ($a < $b && $b < $c) {
  print("Yes\n");
} else {
  print("No\n");
}?>


<?php
fscanf(STDIN, "%d %d %d", $a, $b, $c);
$array = [];
$array[] = $a;
$array[] = $b;
$array[] = $c;
sort($array);
$answer = implode(' ', $array);
echo $answer.PHP_EOL;

Sorting Three Numbers

Write a program which reads three integers, and prints them in ascending order.

Input

Three integers separated by a single space are given in a line.

Output

Print the given integers in ascending order in a line. Put a single space between two integers.

Constraints

1 ≤ the three integers ≤ 10000

Sample Input 1

3 8 1

Sample Output 1

1 3 8


<?php
    $answer = array(
        0 => 'No',
        1 => 'Yes',
    );
    fscanf(STDIN, '%d %d %d %d %d', $w, $h, $x, $y, $r);
    $isInclude = (pow($w, 2) >= pow(($x + $r), 2) && pow(($y + $r), 2) <= pow($h, 2));
    echo $answer[$isInclude], PHP_EOL;

MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Circle in a Rectangle

Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.

Input

Five integers $W$, $H$, $x$, $y$ and $r$ separated by a single space are given in a line.

Output

Print "Yes" if the circle is placed inside the rectangle, otherwise "No" in a line.

Constraints

$ -100 \leq x, y \leq 100$

$ 0 < W, H, r \leq 100$

Sample Input 1

5 4 2 2 1

Sample Output 1

Yes

Sample Input 2

5 4 2 4 1

Sample Output 2

No


while ($line = fgets(STDIN)) {
    $line = rtrim($line);
    $data = explode(" ", $line);

    if ($data[2] < 0) || $data[3] < 0 {
        echo "No" . PHP_EOL;
    } else {
        if ($data[2] + $data[4] <= $data[0] && ($data[3] + $data[4] <= $data[1]) {
            echo "Yes" . PHP_EOL;
        } else {
            echo "No" . PHP_EOL;
        }
    }
}


<?php
  $ary = array();
  while (true) {
    $st = trim(fgets(STDIN));
    if ($st == "0") {
      break;
    }
    array_push($ary, $st);
  }
  $i = 1;
  $count = count($ary);
  foreach ($ary as $val) {
    print ("Case " . $i . ": " . $val);
    if ($i+1 < $count) {
      print "\n";
    }
    $i++;
  }
  unset($val);
?>

Print Test Cases

In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.

Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.

Input

The input consists of multiple datasets. Each dataset consists of an integer x in a line.

The input ends with an integer 0. You program should not process (print) for this terminal symbol.

Output

For each dataset, print x in the following format:

Case i: x

where i is the case number which starts with 1. Put a single space between "Case" and i. Also, put a single space between ':' and x.

Constraints

1 ≤ x ≤ 10000

The number of datasets ≤ 10000

Sample Input

3
5
11
7
8
19
0

Sample Output

Case 1: 3
Case 2: 5
Case 3: 11
Case 4: 7
Case 5: 8
Case 6: 19


<?php
	$i = 1;
	while( $i ) {
		fscanf( STDIN, "%d", $x );
		if( 0 == $x ) { break; }

		echo "Case ".$i.": ".$x.PHP_EOL;
		$i++;
	}
?>


<?php
$i = 1;
while($input = trim(fgets(STDIN))){
    if($input == 0){
        return;
    }
    echo "Case ".$i.": ". $input. PHP_EOL;
    $i++;
}
?>


<?php
$count = 1;
for($i = 1; true; $i++){
    $x = trim(fgets(STDIN));
    if($x == 0){
        return;
    }
printf("Case %d: %d", $i, $x);
echo PHP_EOL;
}
?>


<?php
for ($i=1; true; $i++) {
  $data = trim(fgets(STDIN));
  if ($data === "0") break;
  echo "Case $i: $data".PHP_EOL;
}


<?php
$input = trim(fgets(STDIN));
$x =1;
while($input!==0){
 echo ("Case ".$x.":");
 echo  (" ".$input);
$input = trim(fgets(STDIN));
$x++;
}
exit;
?>


<?php

$input = trim(fgets(STDIN));
$x =1;
while($input!== '0'){
 echo ("Case ".$x.":");
 echo  (" ".$input);
$input = trim(fgets(STDIN));
$x++;
if($input == '0'){
	break;
 }
}
exit;
?>


<?php
$x =1;
while($input = trim(fgets(STDIN))){
	echo ("Case".$x.":".$input);
	$x++;

}
exit;
?>


<?php

    while(true){

        $x = intval(fgets(STDIN));

        if($x == 0){

            break;

        }else{

            $array[] = $x;

        }
    }

    foreach ($array as $result){

        $i = 1;
        echo("Case " . $i . ": " . $result . "\n");
        $i++;

    }
?>


<?php
while (true) {
	fscanf(STDIN,"%d%d",$x,$y);
	if (!$x && !$y) break;
	$group = [(int)$x, (int)$y];
	sort($group);
	echo implode(" ", $group);
}

Swapping Two Numbers

Write a program which reads two integers x and y, and prints them in ascending order.

Input

The input consists of multiple datasets. Each dataset consists of two integers x and y separated by a single space.

The input ends with two 0 (when both x and y are zero). Your program should not process for these terminal symbols.

Output

For each dataset, print x and y in ascending order in a line. Put a single space between x and y.

Constraints

0 ≤ x, y ≤ 10000

the number of datasets ≤ 3000

Sample Input

3 2
2 2
5 3
0 0

Sample Output

2 3
2 2
3 5


<?php
while(true){
    $input = explode(" ",trim(fgets(STDIN)));
    $x = $input[0];
    $y = $input[1];
    if($x == 0 && $y == 0) break;
    if($x > $y){
        echo $y." ".$x."\n";
    } else {
        echo $x." ".$y."\n";
    }
}


<?php
$arr = array();
while ($line = fgets(STDIN)) {
  $arr = explode(' ', $line);
  sort($arr);
  $line = implode(' ', $arr);
  echo $line ."\n";
}


<?php

    while(true){

        $num = preg_split('/ /', trim(fgets(STDIN)));

        if($num[0] == 0 && $num[1] == 0){

            break;

        }else{

            $array[] = (min($num) . " " . max($num));

        }
    }

    $i = 1;

    foreach ($array as $result){

        if($i != count($array)){

            echo($result . "\n");

        }else{

            echo($result);

        }

    }

?>


<?php
while ($line = fgets(STDIN)) {
    $nums = array_map('intval', explode(" ", trim($line)));

    if ($nums[0] === 0 && $nums[1] === 0) {
        exit;
    } elseif ($nums[0] < $nums[1]) {
        echo $nums[0]." ".$nums[1].PHP_EOL;
    } else {
        echo $nums[1]." ".$nums[0].PHP_EOL;
    }
}
?>


<?php

$stdin = preg_split('/ /', trim(fgets(STDIN)));
$a = intval($stdin[0]);
$b = intval($stdin[1]);
$c = intval($stdin[2]);
$count = 0;

for ($i = $a; $i <= $b; $i++) {
	if ($c % $i == 0) {
		$count++;
	}
}

print("{$count}\n");

How Many Divisors?

Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.

Input

Three integers a, b and c are given in a line separated by a single space.

Output

Print the number of divisors in a line.

Constraints

1 ≤ a, b, c ≤ 10000

a ≤ b

Sample Input 1

5 14 80

Sample Output 1

3


<?php
$input = explode(" ",trim(fgets(STDIN)));
$a = intval($input[0]);
$b = intval($input[1]);
$c = intval($input[2]);
$cnt = 0;
for($i=$a;$i<=$b;$i++){
    if($c%$i===0){
        $cnt++;
    }
}
echo $cnt;


<?php
while ($line = fgets(STDIN)) {
    $line = rtrim($line);
    $data = explode(" ", $line);

    $d = (int)$data[0] / (int)$data[1];
    $r = (int)$data[0] % (int)$data[1];
    $f = (int)$data[0] / (int)$data[1];

    printf("%d %d %f\n", $d, $r, $f);
}

A/B Problem

Write a program which reads two integers a and b, and calculates the following values:

a ÷ b: d (in integer)

remainder of a ÷ b: r (in integer)

a ÷ b: f (in real number)

Input

Two integers a and b are given in a line.

Output

Print d, r and f separated by a space in a line. For f, the output should not contain an absolute error greater than 10-5.

Constraints

1 ≤ a, b ≤ 109

Sample Input 1

3 2

Sample Output 1

1 1 1.50000


<?php
    fscanf(STDIN, '%d %d', $a, $b);
    echo floor($a / $b) . " " . ($a % $b) . " ";
    echo printf('%.5f',$a / $b);


<?php
$circleRadius = trim(fgets(STDIN));
printf("%f %f%s", (M_PI * pow($circleRadius, 2)), (2 * M_PI * $circleRadius), PHP_EOL);

Circle

Write a program which calculates the area and circumference of a circle for given radius r.

Input

A real number r is given.

Output

Print the area and circumference of the circle in a line. Put a single space between them. The output should not contain an absolute error greater than 10-5.

Constraints

0 < r < 10000

Sample Input 1

2

Sample Output 1

12.566371 12.566371

Sample Input 2

3

Sample Output 2

28.274334 18.849556


<?php
$input = trim(fgets(STDIN));
$result[] = $input * $input * pi();
$result[] = ($input * 2) * pi();
echo implode(' ', $result);
?>


<?php
$a = trim(fgets(STDIN));
printf("%f %f", $a*2*pi(), $a*$a*pi());


<?php

while (true) {
    fscanf(STDIN, '%d %s %d', $a, $op, $b);
    $result = culc($a, $op, $b);

    if (is_null($result)) { break; }
    $results[] = $result;
}

printf('%s%s', implode(PHP_EOL, $results), PHP_EOL);

function culc($a, $op, $b)
{
    switch ($op) {
        case '+':
            return $a + $b;
        case '-':
            return $a - $b;
        case '*':
            return $a * $b;
        case '/':
            return (float)($a / $b);
    }

    return null;
}

Simple Calculator

Write a program which reads two integers a, b and an operator op, and then prints the value of a op b.

The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.

Input

The input consists of multiple datasets. Each dataset is given in the following format.

a op b

The input ends with a dataset where op = '?'. Your program should not process for this dataset.

Output

For each dataset, print the value in a line.

Constraints

0 ≤ a, b ≤ 20000

No divisions by zero are given.

Sample Input 1

1 + 2
56 - 18
13 * 2
100 / 10
27 + 81
0 ? 0

Sample Output 1

3
38
26
10
108


<?php
    while(true){
        $num = explode(" ",trim(fgets(STDIN)));
        $a = $num[0];
        $op = $num[1];
        $b = $num[2];
        if($op == '+'){
    	    $ans = $a + $b;
        } elseif($op == '-' ){
    	    $ans = $a - $b;
        } elseif($op == '*'){
    	    $ans = $a * $b;
        } elseif($op == '/'){
    	    $ans = floor($a/$b);
        } else{
    	    break;
        }
        echo $ans .PHP_EOL;
    }


<?php
  $t = fgets(STDIN);
  $ary = explode(" ", trim(fgets(STDIN)));
  $min = min($ary);
  $max = max($ary);
  $sum = array_sum($ary);
  print ($min . " " . $max . " " . $sum);
?>

MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Min, Max and Sum

Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.

Input

In the first line, an integer $n$ is given. In the next line, $n$ integers $a_i$ are given in a line.

Output

Print the minimum value, maximum value and sum in a line. Put a single space between the values.

Constraints

$0 < n \leq 10000$

$-1000000 \leq a_i \leq 1000000$

Sample Input

5
10 1 5 4 17

Sample Output

1 17 37


<?php
$n=(int)trim(fgets(STDIN));
$a=explode(' ',trim(fgets(STDIN)));

$mi=$mx=$sm=(int)$a[0];

for($i=1;$i<$n;$i++){
  $ai=(int)$a[$i];
  if($ai<$mi){$mi=$ai;}
  elseif($mx<$ai){$mx=$ai;}
  $sm+=$ai;
}

echo $mi,' ',$mx,' ',$sm;
?>


<?php
$n=trim(fgets(STDIN));
$a=explode(' ',trim(fgets(STDIN)));

$mi=$mx=$sm=$a[0];

for($i=1;$i<$n;$i++){
  $ai=$a[$i];
  if($ai<$mi){$mi=$ai;}
  elseif($mx<$ai){$mx=$ai;}
  $sm+=$ai;
}

echo $mi,' ',$mx,' ',$sm;
?>


<?php
fgets(STDIN);
$arr = explode(' ', trim(fgets(STDIN)));
echo min($arr),' ',max($arr),' ',array_sum($arr), PHP_EOL;


<?php
    $input_line1 = intval(trim(fgets(STDIN)));
    $input_line2 = trim(fgets(STDIN));

    $nums = array_map('intval', explode(' ', $input_line2));

    sort($nums);
    echo $nums[0];
    echo " ";
    echo $nums[$input_line1-1];
    echo " ";
    echo array_sum($nums);
    echo "\n";
?>


<?php

do {
    fscanf(STDIN, '%d %d', $input['height'], $input['width']);
    $inputs[] = $input;
} while ($input['height'] != 0 && $input['width'] != 0);

foreach($inputs as $input) {
    Rectangle::printRectangle($input['height'], $input['width']);
    echo PHP_EOL;
}

class Rectangle {

    public static function printRectangle($height, $width)
    {
        $rectangle = [];

        for ($i = 0; $i < $height; $i++) {
            $rectangle[] = str_repeat('#', $width);
        }
        echo implode(PHP_EOL, $rectangle), PHP_EOL;
    }
}

Print a Rectangle

Draw a rectangle which has a height of H cm and a width of W cm. Draw a 1-cm square by single '#'.

Input

The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space.

The input ends with two 0 (when both H and W are zero).

Output

For each dataset, print the rectangle made of H × W '#'.

Print a blank line after each dataset.

Constraints

1 ≤ H ≤ 300

1 ≤ W ≤ 300

Sample Input

3 4
5 6
2 2
0 0

Sample Output

####
####
####

######
######
######
######
######

##
##


<?php
while(1) {
    list($h, $w) = explode(" ", fgets(STDIN));
    if($h==0 && $w==0) break;
    for($y=0; $y<$h; $y++) {
        echo(str_repeat("#", (int)$w));
        echo("\n");
    }
    echo("\n");
}


Print a Frame

Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm.

##########
#........#
#........#
#........#
#........#
##########

Input

The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space.

The input ends with two 0 (when both H and W are zero).

Output

For each dataset, print the frame made of '#' and '.'.

Print a blank line after each dataset.

Constraints

3 ≤ H ≤ 300

3 ≤ W ≤ 300

Sample Input

3 4
5 6
3 3
0 0

Sample Output

####
#..#
####

######
#....#
#....#
#....#
######

###
#.#
###


<?php
while (true) {
    list($height, $width) = getSpacesByExplodeTrimInput();
    $lines = array();

    if ($height == 0 && $width == 0) {
        break;
    }

    for ($i = 0; $i < $height; $i++) {
        if ($i % 2) {
                $lines[] = setOddNumLine($width);
        } else {
                $lines[] = setEvenNumLine($width);
        }
    }

    echo implode($lines), PHP_EOL;
}

function getSpacesByExplodeTrimInput()
{
    return explode(' ', trim(fgets(STDIN)));
}

function setEvenNumLine($width)
{
    $line = "";
    for ($i = 0; $i < $width; $i++) {
        $line .= $i % 2 ? "#" : ".";
    }
    return $line.PHP_EOL;
}

function setOddNumLine($width)
{
    $line = "";
    for ($i = 0; $i < $width; $i++) {
        $line .= $i % 2 ? "." : "#";
    }
    return $line.PHP_EOL;
}

Print a Chessboard

Draw a chessboard which has a height of H cm and a width of W cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm.

#.#.#.#.#.
.#.#.#.#.#
#.#.#.#.#.
.#.#.#.#.#
#.#.#.#.#.
.#.#.#.#.#

Note that the top left corner should be drawn by '#'.

Input

The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space.

The input ends with two 0 (when both H and W are zero).

Output

For each dataset, print the chessboard made of '#' and '.'.

Print a blank line after each dataset.

Constraints

1 ≤ H ≤ 300

1 ≤ W ≤ 300

Sample Input

3 4
5 6
3 3
2 2
1 1
0 0

Sample Output

#.#.
.#.#
#.#.

#.#.#.
.#.#.#
#.#.#.
.#.#.#
#.#.#.

#.#
.#.
#.#

#.
.#

#


<?php
    while(true){
        list($height, $width) = explode(" ",trim(fgets(STDIN)));

        if($height == 0 && $width == 0) exit;

        $bar[0] = str_repeat("#.",floor($width / 2));
        $bar[1] = str_repeat(".#",floor($width / 2));

        if($width % 2 == 1){
            $bar[0] .= "#";
            $bar[1] .= ".";
        }

        for($j = 0; $j < $height ; $j++){
            print $bar[$j % 2]."\n";
        }
        print "\n";
    }


<?php
while (1) {
    list($h, $w) = explode(" ", trim(fgets(STDIN)));
    if ($h == 0 && $w == 0) exit;

    $str = str_repeat('.#', ($w/2)+1);
    for ($i = 0; $i < $h; $i++) {
        echo substr($str, ($i % 2) ? 0 : 1, $w) . PHP_EOL;
    }
    echo PHP_EOL;
}


Structured Programming

In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops.

Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto.

Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements.

void call(int n){
int i = 1;
CHECK_NUM:
int x = i;
if ( x % 3 == 0 ){
cout << " " << i;
goto END_CHECK_NUM;
}
INCLUDE3:
if ( x % 10 == 3 ){
cout << " " << i;
goto END_CHECK_NUM;
}
x /= 10;
if ( x ) goto INCLUDE3;
END_CHECK_NUM:
if ( ++i <= n ) goto CHECK_NUM;

cout << endl;
}

Input

An integer n is given in a line.

Output

Print the output result of the above program for given integer n.

Constraints

3 ≤ n ≤ 10000

Sample Input

30

Sample Output

3 6 9 12 13 15 18 21 23 24 27 30

Put a single space character before each element.


<?php
$inputNum = trim(fgets(STDIN));

for ($i = 1; $i <= $inputNum; $i++) {
    $num = $i;
    if ($num % 3 == 0) {
        $conditionMatchedNum[] = $i;
        continue;
    }
    while ($num) {
        if ($num % 10 == 3) {
            $conditionMatchedNum[] = $i;
            break;
        }
        $num = floor($num / 10);
    }
}

echo ' '.implode(' ', $conditionMatchedNum), PHP_EOL;


<?php
$inputNum = trim(fgets(STDIN));

for ($i=1; $i <= $inputNum; $i++) {
    if (($i % 3 == 0) || preg_match('/3/', $i))
        $nums[] = $i;
}

echo sprintf(' %d',implode(' ', $nums)), PHP_EOL;


<?php

fscanf(STDIN, '%d', $n);
$line = trim(fgets(STDIN));
$arr = explode(' ', $line);
$arr = array_reverse($arr);
echo implode(' ', $arr), PHP_EOL;

Reversing Numbers

Write a program which reads a sequence and prints it in the reverse order.

Input

The input is given in the following format:

n
a1 a2 . . . an

n is the size of the sequence and ai is the ith element of the sequence.

Output

Print the reversed sequence in a line. Print a single space character between adjacent elements (Note that your program should not put a space character after the last element).

Constraints

n ≤ 100

0 ≤ ai < 1000

Sample Input 1

5
1 2 3 4 5

Sample Output 1

5 4 3 2 1

Sample Input 2

8
3 3 4 4 5 8 7 9

Sample Output 2

9 7 8 5 4 4 3 3

Note

      解説


<?php
  $a = trim(fgets(STDIN));
  $ary = explode(" ", trim(fgets(STDIN)));
  print (array_reverse($ary) . "\n");
?>


<?php
$n = trim(fgets(STDIN));
$in = explode(" ", trim(fgets(STDIN)));
krsort($in);
$out = implode(" ", $in);
echo $out;


<?php

  $stdin = trim(fgets(STDIN));
  $stdin2 = trim(fgets(STDIN));

  $stdin = (int)$stdin;
  $num_array = explode(" ",$stdin2);

  $r_array = array_reverse($num_array);

  $int_array = array();

  foreach ($r_array as $item) {
    array_push($int_array,(int)$item);
  }
// var_dump($int_array);
  for ($i=0; $i < $stdin; $i++) {
    if ($i < $stdin-1) {
        echo $int_array[$i]." ";
    }else{
      echo $int_array[$i]."\n";
    }
  }
  // echo "\n";

  // var_dump($int_array);
 ?>


<?php
	fscanf( STDIN, "%d", $n );
	$shcd = array( 'S', 'H', 'C', 'D' );
	$cardSet = array();
	for( $i=0; $i<4; $i++ ) {
		for( $j=1; $j<=13; $j++ ) {
			array_push( $cardSet, $shcd[$i].' '.$j );
		}
	}
	$taroCards = array();
	for( $i=0; $i<$n; $i++ ) {
		$c = trim( fgets( STDIN ) );
		array_push( $taroCards, $c );
	}
	$result = array_diff( $cardSet, $taroCards  );
	if( count( $result ) ) {
		print implode( PHP_EOL, $result );
	} else {
		return;
	}
?>

Finding Missing Cards

Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers).

The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.

Input

In the first line, the number of cards n (n ≤ 52) is given.

In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.

Output

Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line.
Arrange the missing cards in the following priorities:

Print cards of spades, hearts, clubs and diamonds in this order.

If the suits are equal, print cards with lower ranks first.

Sample Input

47
S 10
S 11
S 12
S 13
H 1
H 2
S 6
S 7
S 8
S 9
H 6
H 8
H 9
H 10
H 11
H 4
H 5
S 2
S 3
S 4
S 5
H 12
H 13
C 1
C 2
D 1
D 2
D 3
D 4
D 5
D 6
D 7
C 3
C 4
C 5
C 6
C 7
C 8
C 9
C 10
C 11
C 13
D 9
D 10
D 11
D 12
D 13

Sample Output

S 1
H 3
H 7
C 12
D 8

Note

      解説


<?php
$a = trim(fgets(STDIN));
$suit = array("S", "H", "C", "D");
$card_set = [];
foreach($suit as $kind){
    for($i = 1; $i <= 13; $i++){
        array_push($card_set, $kind." ".$i);
    }
}
$input_set =[];
while($input = trim(fgets(STDIN))){
array_push($input_set,$input);
}
$missing_card = array_diff($card_set, $input_set);
if($a !== 52){
echo implode(PHP_EOL,$missing_card);
}
?>


<?php
while(true){
    list($m,$f,$r)= explode(" ",trim(fgets(STDIN)));
    $total = $m + $f;
    if($m == -1 && $f == -1 && $r == -1) break;
    if($m == -1 || $f == -1 || $total < 30){
        echo "F\n";
    } elseif($total >= 80){
        echo "A\n";
    } elseif($total >= 65){
        echo "B\n";
    } elseif($total >= 50 || $r >= 50){
        echo "C\n";
    } else {
        echo "D\n";
    }
}

Grading

Write a program which reads a list of student test scores and evaluates the performance for each student.

The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1.

The final performance of a student is evaluated by the following procedure:

If the student does not take the midterm or final examination, the student's grade shall be F.

If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.

If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.

If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.

If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.

If the total score of the midterm and final examination is less than 30, the student's grade shall be F.

Input

The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line.

The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols.

The number of datasets (the number of students) does not exceed 50.

Output

For each dataset, print the grade (A, B, C, D or F) in a line.

Sample Input

40 42 -1
20 30 -1
0 2 -1
-1 -1 -1

Sample Output

A
C
F


<?php

    while(true){
        $mark = explode(" ", trim(fgets(STDIN)));
        if(array_sum($mark) == -3) exit;

        $total = $mark[0] + $mark[1];

        if($mark[0] * $mark[1] < 0 || $total < 30){
            echo "F"."\n";
        } elseif ($total >= 80) {
            echo "A"."\n";
        } elseif ($total >= 65){
            echo "B"."\n";
        } elseif ($total < 50 && $mark[2] < 50){
            echo "D"."\n";
        } else {
            echo "C"."\n";
        }
    }


<?php
	while (true) {
		$result = trim(fgets(STDIN));
		list($n, $x) = explode(" ", $result);

		if ($n == 0 && $x == 0) break;

		$result = array();
		for ($i = 1; $i <= $n; $i++) {
			for ($j = 1; $j <= $n; $j++) {
				if ($i == $j) continue;
				for ($k = 1; $k <= $n; $k++) {
					if ($i == $k || $j == $k) continue;
					if ($i + $j + $k == $x) {
						$arr = array($i, $j, $k);
						sort($arr);
						$val = implode("", $arr);
						if (!in_array($val, $result)) {
							$result[] = $val;
						}
					}
				}
			}
		}

		print count($result) . "\n";
	}

How many ways?

Write a program which identifies the number of combinations of three integers which satisfy the following conditions:

You should select three distinct integers from 1 to n.

A total sum of the three integers is x.

For example, there are two combinations for n = 5 and x = 9.

1 + 3 + 5 = 9

2 + 3 + 4 = 9

Input

The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.

The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.

Constraints

3 ≤ n ≤ 100

0 ≤ x ≤ 300

Output

For each dataset, print the number of combinations in a line.

Sample Input

5 9
0 0

Sample Output

2

Note

      解説


<?php

while (true) {
    fscanf(STDIN, '%d %d', $n, $x);

    if (isEnd($n, $x)) { break; };

    $count = 0;
    for ($i = 1; $i < $n; $i++) {
        for ($j = $i + 1; $j < $n - 1; $j++) {
            if ($x - ($i + $j) <= $n) {
                $count++;
var_dump($i, $j, $x - ($i + $j), PHP_EOL);
            }
        }
    }
    $result[] = $count;
}

echo implode(PHP_EOL, $result), PHP_EOL;

function isEnd($n, $x)
{
    return !($n || $x);
}


<?php

//1行目の入力値＝文字列sを2倍にしてくっつける
$strS = trim(fgets(STDIN));
$strS = str_repeat($strS, 2);

/*上で処理した文字列sにおいて2行目の入力値＝文字列pが存在するか検索して、
1回でも存在すればyesを出力、そうでなければnoを出力*/
$strP = trim(fgets(STDIN));
if (strpos($strS, $strP) !== false) {
    echo "Yes" . "\n";
} else {
    echo "No" . "\n";
}

MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Ring

Write a program which finds a pattern $p$ in a ring shaped text $s$.

Input

In the first line, the text $s$ is given.

In the second line, the pattern $p$ is given.

Output

If $p$ is in $s$, print Yes in a line, otherwise No.

Constraints

$1 \leq $ length of $p \leq $ length of $s \leq 100$

$s$ and $p$ consists of lower-case letters

Sample Input 1

vanceknowledgetoad
advance

Sample Output 1

Yes

Sample Input 2

vanceknowledgetoad
advanced

Sample Output 2

No


<?php

while (true) {
    $data_set = trim(fgets(STDIN));
    if ('-' == $data_set) break;

    $loop = trim(fgets(STDIN));
    for ($i = 0; $i < $loop; $i++) {
        $pos = trim(fgets(STDIN));
        $data_set = substr($data_set, -(strlen($data_set) - $pos)) . substr($data_set, 0, $pos);
    }
    echo $data_set . PHP_EOL;
}

Shuffle

Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter.

A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck.

The deck of cards is represented by a string as follows.

abcdeefab

The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.

For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:

eefababcd

You can repeat such shuffle operations.

Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).

Input

The input consists of multiple datasets. Each dataset is given in the following format:

A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm

The input ends with a single character '-' for the string.

Constraints

The length of the string ≤ 200

1 ≤ m ≤ 100

1 ≤ hi < The length of the string

The number of datasets ≤ 10

Output

For each dataset, print a string which represents the final state in a line.

Sample Input

aabc
3
1
2
1
vwxyz
2
3
4
-

Sample Output

aabc
xyzvw


Card Game

Taro and Hanako are playing card games. They have n cards each, and they compete n turns. At each turn Taro and Hanako respectively puts out a card.
The name of the animal consisting of alphabetical letters is written on each card, and the bigger one in lexicographical order becomes the winner of that turn. The winner obtains 3 points. In the case of a draw, they obtain 1 point each.

Write a program which reads a sequence of cards Taro and Hanako have and reports the final scores of the game.

Input

In the first line, the number of cards n is given. In the following n lines, the cards for n turns are given respectively. For each line, the first string represents the Taro's card and the second one represents Hanako's card.

Constraints

n ≤ 1000

The length of the string ≤ 100

Output

Print the final scores of Taro and Hanako respectively. Put a single space character between them.

Sample Input

3
cat dog
fish fish
lion tiger

Sample Output

1 7


<?php
  $str = trim(fgets(STDIN));
  $num = trim(fgets(STDIN));
  for($i = 0; $i < $num; $i++) {
    // list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
    $d = explode(" ", trim(fgets(STDIN)));
    if ($d[0] == "print") {
      if ($i == ($num-1)) {
        print(substr($str, $d[1], ($d[2]+1)));
      } else {
        print(substr($str, $d[1], ($d[2]+1)) . "\n");
      }
    } else if ($d[0] == "reverse") {
      $x = substr($str, $d[1], ($d[2]+1));
      $x = strrev($x);
      $str = substr_replace($str, $x, $d[1], ($d[2]+1));
    } else if ($d[0] == "replace") {
      $str = substr_replace($str, $d[3], $d[1], $d[2]);
    }
  }
?>

MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Transformation

Write a program which performs a sequence of commands to a given string $str$. The command is one of:

print a b: print from the a-th character to the b-th character of $str$

reverse a b: reverse from the a-th character to the b-th character of $str$

replace a b p: replace from the a-th character to the b-th character of $str$ with p

Note that the indices of $str$ start with 0.

Input

In the first line, a string $str$ is given. $str$ consists of lowercase letters. In the second line, the number of commands q is given. In the next q lines, each command is given in the above mentioned format.

Output

For each print command, print a string in a line.

Constraints

$1 \leq $ length of $str \leq 1000$

$1 \leq q \leq 100$

$0 \leq a \leq b < $ length of $str$

for replace command, $b - a + 1 = $ length of $p$

Sample Input 1

abcde
3
replace 1 3 xyz
reverse 0 2
print 1 4

Sample Output 1

xaze

Sample Input 2

xyz
3
print 0 2
replace 0 2 abc
print 0 2

Sample Output 2

xyz
abc


<?php
fscanf(STDIN,"%s",$str);
fscanf(STDIN,"%s",$q);

while($order = trim(fgets(STDIN))){
    $array = explode(" ",$order);

    if ($array[0] == "print"){
        $str = print_ab($str,$array[1],$array[2]);
        echo $str.PHP_EOL;

    }elseif ($array[0] == "reverse"){
        $str = reverse($str,$array[1],$array[2]);

    }elseif ($array[0] == "replace"){
        $str = replace($str,$array[1],$array[2],$array[3]);
    }
}//while

//----------------
//kansuu
//----------------
function print_ab($text,$a,$b){
    return substr($text, $a, $b-$a+1);
}

function reverse($text,$a,$b){
    $change = strrev(substr($text, $a, $b-$a+1));
    return substr_replace($text, $change, $a, $b-$a+1);
}

function replace($text,$a,$b,$p){
    return substr_replace($text, $p, $a, $b-$a+1);
}


<?php
    $str = trim(fgets(STDIN));
    $record_cound = trim(fgets(STDIN));

    for($i = 0; $i < $record_cound; $i++){
        $order = explode(" ",trim(fgets(STDIN)));
        $a = $order[1];
        $b = $order[2];
        $length = $b - $a + 1;

        switch ($order[0]){
            case 'print':
                print substr($str, $a, $length)."\n";
                break;
            case 'reverse':
                $str = substr_replace($str, strrev(substr($str, $a, $length)), $a, $length);
                break;
            case 'replace':
                $str = substr_replace($str, $order[3], $a, $length);
                break;
        }
    }


<?php
$str = trim(fgets(STDIN));
$n = trim(fgets(STDIN));

for ($i = 0; $i < $n; $i++) {
  $line = explode(" ", trim(fgets(STDIN)));
  $order = $line[0];
  $a = $line[1];
  $len = $line[2] - $a + 1;

  if ($order == "print")
    echo substr($str, $a, $len) . "\n";
  elseif ($order == "reverse")
    $str = substr_replace(
      $str,
      strrev(substr($str, $a, $len)),
      $a,
      $len
    );
  else
    $str = substr_replace($str, $line[3], $a, $len);
}


<?php
	$n = trim(fgets(STDIN));
	$s = null;
	$rootn = sqrt($n);
	for($i = 2; $i <= $rootn; ++$i){
		while(true){
			if(($n % $i) == 0){
				$s = $s . " " . $i;
			}
			else{
				break;
			}
		}
	}
	echo $n . ":" . $s;
?>

Prime Factorization

Factorize a given integer n.

Input

n

An integer n is given in a line.

Output

Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor.

Constraints

2 ≤ n ≤ 109

Sample Input 1

12

Sample Output 1

12: 2 2 3

Sample Input 2

126

Sample Output 2

126: 2 3 3 7


<?php
  fscanf(STDIN, "%s", $s);
$arr = str_split($s);
$value = $arr[array_key_last($arr)];
if($value=="e"){
echo $s."s";
}else{
echo $s."es";
}

Score : 100 points

Problem Statement

In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters.

In Taknese, the plural form of a noun is spelled based on the following rules:

If a noun's singular form does not end with s, append s to the end of the singular form.

If a noun's singular form ends with s, append es to the end of the singular form.

You are given the singular form S of a Taknese noun. Output its plural form.

Constraints

S is a string of length 1 between 1000, inclusive.

S contains only lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the plural form of the given Taknese word.

Sample Input 1

apple

Sample Output 1

apples

apple ends with e, so its plural form is apples.

Sample Input 2

bus

Sample Output 2

buses

bus ends with s, so its plural form is buses.

Sample Input 3

box

Sample Output 3

boxs


Score : 300 points

Problem Statement

Given is a positive integer N.
How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?

Constraints

2 \leq N \leq 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

3

Sample Output 1

3

There are 3 tuples of integers that satisfy A \times B + C = 3: (A, B, C) = (1, 1, 2), (1, 2, 1), (2, 1, 1).

Sample Input 2

100

Sample Output 2

473

Sample Input 3

1000000

Sample Output 3

13969985


<?php
fscanf(STDIN, "%d %d %d %d", $a,$b,$c,$d);
if($a*$b >$d*$c){
  echo $a*$b;}else{
  echo $d*$c;}
?>

Score : 200 points

Problem Statement

Given are integers a,b,c and d.
If x and y are integers and a \leq x \leq b and c\leq y \leq d hold, what is the maximum possible value of x \times y?

Constraints

-10^9 \leq a \leq b \leq 10^9

-10^9 \leq c \leq d \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a b c d

Output

Print the answer.

Sample Input 1

1 2 1 1

Sample Output 1

2

If x = 1 and y = 1 then x \times y = 1.
If x = 2 and y = 1 then x \times y = 2.
Therefore, the answer is 2.

Sample Input 2

3 5 -4 -2

Sample Output 2

-6

The answer can be negative.

Sample Input 3

-1000000000 0 -1000000000 0

Sample Output 3

1000000000000000000


<?php
  $input = trim(fgets(STDIN));
  $array = explode(' ',$input);

  if($array[0]<=$array[1]*$array[2]){
    echo "Yes";
  }else{
    echo "No";
  }

?>

Score : 100 points

Problem Statement

Takahashi is meeting up with Aoki.

They have planned to meet at a place that is D meters away from Takahashi's house in T minutes from now.

Takahashi will leave his house now and go straight to the place at a speed of S meters per minute.

Will he arrive in time?

Constraints

1 \leq D \leq 10000

1 \leq T \leq 10000

1 \leq S \leq 10000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

D T S

Output

If Takahashi will reach the place in time, print Yes; otherwise, print No.

Sample Input 1

1000 15 80

Sample Output 1

Yes

It takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters per minute. They have planned to meet in 15 minutes so he will arrive in time.

Sample Input 2

2000 20 100

Sample Output 2

Yes

It takes 20 minutes to go 2000 meters to the place at a speed of 100 meters per minute. They have planned to meet in 20 minutes so he will arrive just on time.

Sample Input 3

10000 1 1

Sample Output 3

No

He will be late.


<?php

$t = str_split(fgets(STDIN));
$s = str_split(fgets(STDIN));
array_pop($t);
array_pop($s);

$roop = count($t)-count($s);
$result=0;

for($i=0;$i<=$roop;$i++){
    $new_res = 0;
    for($j=0;$j<count($s);$j++){
        if($s[$i+$j] != $t[$j]){
            $new_res++;
        }
    }
    if($result<$new_res){
        $result=$new_res;
    }
}
echo $result."\n";

Score : 200 points

Problem Statement

Given are two strings S and T.

Let us change some of the characters in S so that T will be a substring of S.

At least how many characters do we need to change?

Here, a substring is a consecutive subsequence. For example, xxx is a substring of yxxxy, but not a substring of xxyxx.

Constraints

The lengths of S and T are each at least 1 and at most 1000.

The length of T is at most that of S.

S and T consist of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print the minimum number of characters in S that need to be changed.

Sample Input 1

cabacc
abc

Sample Output 1

1

For example, changing the fourth character a in S to c will match the second through fourth characters in S to T.

Since S itself does not have T as its substring, this number of changes - one - is the minimum needed.

Sample Input 2

codeforces
atcoder

Sample Output 2

6


<?php
list($N,$X,$T)=sscanf(trim(fgets(STDIN)),"%d %d %d");
print(ceil($N / $X) * $T);

Score : 100 points

Problem Statement

Takahashi loves takoyaki - a ball-shaped snack.

With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.

How long does it take to make N takoyaki?

Constraints

1 \leq N,X,T \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X T

Output

Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.

Sample Input 1

20 12 6

Sample Output 1

12

He can make 12 pieces of takoyaki in the first 6 minutes and 8 more in the next 6 minutes, so he can make 20 in a total of 12 minutes.

Note that being able to make 12 in 6 minutes does not mean he can make 2 in 1 minute.

Sample Input 2

1000 1 1000

Sample Output 2

1000000

It seems to take a long time to make this kind of takoyaki.


<?php
# スペース区切りの整数の入力
fscanf(STDIN, "%d", $n);

$sum = 0;
for ($i=0; $i < strlen($n); $i++) {
    $sum += substr($n,$i,1);
}

if ($sum % 9 === 0) {
    echo "Yes".PHP_EOL;
} else {
    echo "No".PHP_EOL;
}

Score : 200 points

Problem Statement

An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9.

Determine whether N is a multiple of 9.

Constraints

0 \leq N < 10^{200000}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N is a multiple of 9, print Yes; otherwise, print No.

Sample Input 1

123456789

Sample Output 1

Yes

The sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so 123456789 is a multiple of 9.

Sample Input 2

0

Sample Output 2

Yes

Sample Input 3

31415926535897932384626433832795028841971693993751058209749445923078164062862089986280

Sample Output 3

No


<?php
fscanf(STDIN, "%d", $n);

$sum = 0;
while (true) {
    if ($n < 10) {
        $sum += $n;
        break;
    }
    $sum += $n % 10;
    $n = intdiv($n, 10);
}

if ($sum % 9 == 0) {
    echo "Yes\n";
} else {
    echo "No\n";
}


<?php
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($H,$W) = array_map('intval',explode(" ",trim(fgets(STDIN))));
list($Ch,$Cw) = array_map('intval',explode(" ",trim(fgets(STDIN))));
list($Dh,$Dw) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$Ch=$Ch-1;
$Cw=$Cw-1;
$Dh=$Dh-1;
$Dw=$Dw-1;
for($i=0;$i<$H;$i++) {
  $S[]=trim(fgets(STDIN));
}
$used = array();
$usedlist = array();
$goal = false;
$warp = 0;

$res = search($Ch,$Cw);
if ($res) {
  printf("%d\n",0);
  exit;
}
while(1) {
  $list = getUsedList($warp);
  if (count($list)==0) break;
  $warp++;
  foreach($list as $v) {
    //到達済み位置からワープ可能な位置を探す
    $p = canwarp($v[0],$v[1]);
    if (count($p)==0) continue;
    //ワープ可能地点があった場合はそこから探す
    foreach($p as $vv) {
      $res = search($vv[0],$vv[1]);
      if ($res) break;
    }
  }
  if ($goal) break;
}
if ($goal) printf("%d\n",$warp);
else printf("-1\n");

function search($row,$col) {
  global $S,$Dw,$Dh,$H,$W,$used,$goal,$warp,$usedlist;
  if (isset($used[$row][$col])) {
    return false;
  }
  if ($row<0 || $H<=$row || $col < 0 || $W <= $col || $S[$row][$col]=="#") {
    return false;
  }
  if (isset($used[$row][$col])) {
    return false;
  }
  $used[$row][$col]=$warp;
  $usedlist[$warp][]=array($row,$col);

  if ($row==$Dh && $col==$Dw) {
    $goal = true;
    return true;
  }
  search($row,$col+1);
  search($row,$col-1);
  search($row+1,$col);
  search($row-1,$col);

  return $goal;
}

function canwarp($row,$col) {
  global $S,$Dw,$Dh,$H,$W,$used,$goal;
  $warppos=array();
  for($i=$row-2;$i<=$row+2;$i++) {
    for($j=$col-2;$j<=$col+2;$j++) {
      $crow = $i;
      $ccol = $j;
      if ($crow>= 0 && $H>$crow && $ccol >= 0 && $W > $ccol && $S[$crow][$ccol]=="." && !isset($used[$crow][$ccol])) {
        $warppos[]=array($crow,$ccol);
      }
    }
  }
  return $warppos;
}

function getUsedList($depth)
{
  global $H,$W,$used,$usedlist;
  $ret=array();
  if (!isset($usedlist[$depth])) return $ret;
  foreach($usedlist[$depth] as $v) {
    $ret[]=array($v[0],$v[1]);
  }
  return $ret;
}

Score : 400 points

Problem Statement

A maze is composed of a grid of H \times W squares - H vertical, W horizontal.

The square at the i-th row from the top and the j-th column from the left - (i,j) - is a wall if S_{ij} is # and a road if S_{ij} is ..

There is a magician in (C_h,C_w). He can do the following two kinds of moves:

Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.

Move B: Use magic to warp himself to a road square in the 5\times 5 area centered at the square he is currently in.

In either case, he cannot go out of the maze.

At least how many times does he need to use the magic to reach (D_h, D_w)?

Constraints

1 \leq H,W \leq 10^3

1 \leq C_h,D_h \leq H

1 \leq C_w,D_w \leq W

S_{ij} is # or ..

S_{C_h C_w} and S_{D_h D_w} are ..

(C_h,C_w) \neq (D_h,D_w)

Input

Input is given from Standard Input in the following format:

H W
C_h C_w
D_h D_w
S_{11}\ldots S_{1W}
\vdots
S_{H1}\ldots S_{HW}

Output

Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print -1 instead.

Sample Input 1

4 4
1 1
4 4
..#.
..#.
.#..
.#..

Sample Output 1

1

For example, by walking to (2,2) and then using the magic to travel to (4,4), just one use of magic is enough.

Note that he cannot walk diagonally.

Sample Input 2

4 4
1 4
4 1
.##.
####
####
.##.

Sample Output 2

-1

He cannot move from there.

Sample Input 3

4 4
2 2
3 3
....
....
....
....

Sample Output 3

0

No use of magic is needed.

Sample Input 4

4 5
1 2
2 5
#.###
####.
#..##
#..##

Sample Output 4

2


<?php
  $s = trim(fgets(STDIN));
  $cnt = 0;
  $ans = 0;
  for($i=0; $i<3; $i++){
      if($s[$i] == "R"){
          $cnt++;
      }else{
          $ans = max($cnt, $ans);
          $cnt = 0;
      }
  }
  echo $ans;

Score : 100 points

Problem Statement

We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is S, it means it was sunny on the i-th day; if that character is R, it means it was rainy on that day.

Find the maximum number of consecutive rainy days in this period.

Constraints

|S| = 3

Each character of S is S or R.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of consecutive rainy days in the period.

Sample Input 1

RRS

Sample Output 1

2

We had rain on the 1-st and 2-nd days in the period. Here, the maximum number of consecutive rainy days is 2, so we should print 2.

Sample Input 2

SSS

Sample Output 2

0

It was sunny throughout the period. We had no rainy days, so we should print 0.

Sample Input 3

RSR

Sample Output 3

1

We had rain on the 1-st and 3-rd days - two "streaks" of one rainy day, so we should print 1.


<?php
/* =====
 * 各種入力
 * ===== */
    $input = explode(" ", trim(fgets(STDIN)));
    $x = $input[0];
    $k = $input[1];
    $d = $input[2];

/* =====
 * 初期位置が最大移動距離より遠い場合
 * ===== */
    if(abs($x) > $k * $d){
        $pos =  abs($x) - $k * $d;
    }else{
        $pos_temp = abs($x % ($d * 2));

        $pos = min($pos_temp, abs($pos_temp - $d * 2));
    }
    echo $pos;
?>

Score : 300 points

Problem Statement

Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.

More specifically, in one move, he can go from coordinate x to x + D or x - D.

He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.

Find the minimum possible absolute value of the coordinate of the destination.

Constraints

-10^{15} \leq X \leq 10^{15}

1 \leq K \leq 10^{15}

1 \leq D \leq 10^{15}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X K D

Output

Print the minimum possible absolute value of the coordinate of the destination.

Sample Input 1

6 2 4

Sample Output 1

2

Takahashi is now at coordinate 6. It is optimal to make the following moves:

Move from coordinate 6 to (6 - 4 =) 2.

Move from coordinate 2 to (2 - 4 =) -2.

Here, the absolute value of the coordinate of the destination is 2, and we cannot make it smaller.

Sample Input 2

7 4 3

Sample Output 2

1

Takahashi is now at coordinate 7. It is optimal to make, for example, the following moves:

Move from coordinate 7 to 4.

Move from coordinate 4 to 7.

Move from coordinate 7 to 4.

Move from coordinate 4 to 1.

Here, the absolute value of the coordinate of the destination is 1, and we cannot make it smaller.

Sample Input 3

10 1 2

Sample Output 3

8

Sample Input 4

1000000000000000 1000000000000000 1000000000000000

Sample Output 4

1000000000000000

The answer can be enormous.


<?php
  //dが速度　kが時間　d*k<x場合はx-$d*k
//d*k>x場合 kが偶数の時　$x/$k 　kが奇数の時 $x/$k+1回
  	fscanf(STDIN,"%d%d%d",$x,$k,$d);
	if(abs($x)>$k*$d){
      echo (abs($x)-$k*$d);
    }else{
      if((int)($x/$d)%2==0){
        echo abs(abs($x)-$d*abs((int)($x/$d)));
      }else{
//        echo "hoge".($d*(int)($x/$d));
        echo abs(abs($x)-$d*abs((int)($x/$d))-$d);
      }
    }


<?php
list($x, $k, $d) = explode(" ", trim(fgets(STDIN)) );

$prev_x = PHP_INT_MAX;
$prev2_x = PHP_INT_MAX;
while($k > 0){
    # ２つ前まで記録を撮っておく
    $prev2_x = $prev_x;
    $prev_x = $x;

    # 移動処理
    if($x >= 0){
        $x = $x - $d;
    }else{
        $x = $x + $d;
    }
    $k--;

    # 同じ位置を反復しだしたら偶数分減らす
    if($prev2_x == $x){
        $k = $k % 2;
    }

}
echo abs($x);


<?php

fscanf(STDIN, "%d%d", $n, $k);
$p_list = explode(' ', trim(fgets(STDIN)));
$c_list = explode(' ', trim(fgets(STDIN)));

$current_square = 1;
$accumulated_c = [];
for ($i = 0; $i < $n; ++$i) {
    $current_square = $p_list[$current_square - 1];
    if ($i === 0) {
        $accumulated_c[$i] = $c_list[$current_square - 1];
    } else {
        $accumulated_c[$i] = $accumulated_c[$i - 1] + $c_list[$current_square - 1];
    }
}

$answer = max($c_list);
$k_prime = $k <= $n ? $k : $k % $n;
for ($i = 0; $i < $n; ++$i) {
    for ($j = 1; $j <= $k_prime; ++$j) {
        $point = $i + $j < $n ? $accumulated_c[$i + $j] - $accumulated_c[$i] : $accumulated_c[$i + $j - $n] + $accumulated_c[$n - 1] - $accumulated_c[$i];
        if ($point > $answer) {
            $answer = $point;
        }
    }
}

if ($k > $n && $accumulated_c[$n - 1] > 0) {
    $answer += $accumulated_c[$n - 1] * (($k - $k_prime) / $n);
}

echo $answer;

Score : 400 points

Problem Statement

Takahashi will play a game using a piece on an array of squares numbered 1, 2, \cdots, N. Square i has an integer C_i written on it. Also, he is given a permutation of 1, 2, \cdots, N: P_1, P_2, \cdots, P_N.

Now, he will choose one square and place the piece on that square. Then, he will make the following move some number of times between 1 and K (inclusive):

In one move, if the piece is now on Square i (1 \leq i \leq N), move it to Square P_i. Here, his score increases by C_{P_i}.

Help him by finding the maximum possible score at the end of the game. (The score is 0 at the beginning of the game.)

Constraints

2 \leq N \leq 5000

1 \leq K \leq 10^9

1 \leq P_i \leq N

P_i \neq i

P_1, P_2, \cdots, P_N are all different.

-10^9 \leq C_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
P_1 P_2 \cdots P_N
C_1 C_2 \cdots C_N

Output

Print the maximum possible score at the end of the game.

Sample Input 1

5 2
2 4 5 1 3
3 4 -10 -8 8

Sample Output 1

8

When we start at some square of our choice and make at most two moves, we have the following options:

If we start at Square 1, making one move sends the piece to Square 2, after which the score is 4. Making another move sends the piece to Square 4, after which the score is 4 + (-8) = -4.

If we start at Square 2, making one move sends the piece to Square 4, after which the score is -8. Making another move sends the piece to Square 1, after which the score is -8 + 3 = -5.

If we start at Square 3, making one move sends the piece to Square 5, after which the score is 8. Making another move sends the piece to Square 3, after which the score is 8 + (-10) = -2.

If we start at Square 4, making one move sends the piece to Square 1, after which the score is 3. Making another move sends the piece to Square 2, after which the score is 3 + 4 = 7.

If we start at Square 5, making one move sends the piece to Square 3, after which the score is -10. Making another move sends the piece to Square 5, after which the score is -10 + 8 = -2.

The maximum score achieved is 8.

Sample Input 2

2 3
2 1
10 -7

Sample Output 2

13

Sample Input 3

3 3
3 1 2
-1000 -2000 -3000

Sample Output 3

-1000

We have to make at least one move.

Sample Input 4

10 58
9 1 6 7 8 4 3 2 10 5
695279662 988782657 -119067776 382975538 -151885171 -177220596 -169777795 37619092 389386780 980092719

Sample Output 4

29507023469

The absolute value of the answer may be enormous.


<?php
$k = trim(fgets(STDIN));

if ($k % 2 == 0) {
    echo "-1".PHP_EOL;
    exit;
}

$a = 7;
for($i = 1; $i < 1000000; ++$i) {
    if ($a % $k == 0) {
        echo $i.PHP_EOL;
        exit;
    }
    $a = $a % $k; // $kで割り切れるときは割っておく（桁あふれ防止？）
    $a = $a * 10 + 7;
}

echo "-1".PHP_EOL;

Score : 100 points

Problem Statement

You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.

The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?

Constraints

-40 \leq X \leq 40

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print Yes if you will turn on the air conditioner; print No otherwise.

Sample Input 1

25

Sample Output 1

No

Sample Input 2

30

Sample Output 2

Yes


Score : 200 points

Problem Statement

We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).

Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?

We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.

Constraints

1 \leq N \leq 2\times 10^5

0 \leq D \leq 2\times 10^5

|X_i|,|Y_i| \leq 2\times 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D
X_1 Y_1
\vdots
X_N Y_N

Output

Print an integer representing the number of points such that the distance from the origin is at most D.

Sample Input 1

4 5
0 5
-2 4
3 4
4 -4

Sample Output 1

3

The distance between the origin and each of the given points is as follows:

\sqrt{0^2+5^2}=5

\sqrt{(-2)^2+4^2}=4.472\ldots

\sqrt{3^2+4^2}=5

\sqrt{4^2+(-4)^2}=5.656\ldots

Thus, we have three points such that the distance from the origin is at most 5.

Sample Input 2

12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

Sample Output 2

7

Multiple points may exist at the same coordinates.

Sample Input 3

20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669

Sample Output 3

6


<?php
$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($N,$D) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$x = 7 % $N;
$S=array();
$i=1;
while(!isset($S[$x])) {
  if ($x == 0) {
    printf("%d\n",$i);
    exit;
  }
  $S[$x]=1;
  $x = ($x*10+7)%$N;
  $i++;
}
printf("%d\n",-1);

Score : 300 points

Problem Statement

Takahashi loves the number 7 and multiples of K.

Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.)

If the sequence contains no multiples of K, print -1 instead.

Constraints

1 \leq K \leq 10^6

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.)

Sample Input 1

101

Sample Output 1

4

None of 7, 77, and 777 is a multiple of 101, but 7777 is.

Sample Input 2

2

Sample Output 2

-1

All elements in the sequence are odd numbers; there are no multiples of 2.

Sample Input 3

999983

Sample Output 3

999982


<?php

$k = fgets(STDIN);
$s = 7;
$flag = true;
$result=1;

while($flag){
    if($k%2==0){
        echo "-1\n";
    }
    if($s%$k==0){
        $flag=false;
    }else{
        $result++;
        $s=$s*10+7;
        if($s>php_int_max){
            while($s>php_int_max){
                $s-$k;
            }
        }
    }
}

echo $result."\n";
// echo $s."\n";
// echo $s/$k."\n";


<?php

$n = trim(fgets(STDIN));
$isi = trim(fgets(STDIN));
$isi = str_split($isi);

$r_cnt = array_count_values($isi)['R'];
$isi = array_chunk($isi, $r_cnt);

if(in_array('W', $isi[0]) && array_count_values($isi[0])['W']){
    $cng_cnt = array_count_values($isi[0])['W'];
}else{
    echo 0;
    exit;
}

echo $cng_cnt;

Score : 400 points

Problem Statement

An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; R stands for red and W stands for white.

You can do the following two kinds of operations any number of times in any order:

Choose two stones (not necessarily adjacent) and swap them.

Choose one stone and change its color (from red to white and vice versa).

According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Constraints

2 \leq N \leq 200000

c_i is R or W.

Input

Input is given from Standard Input in the following format:

N
c_{1}c_{2}...c_{N}

Output

Print an integer representing the minimum number of operations needed.

Sample Input 1

4
WWRR

Sample Output 1

2

For example, the two operations below will achieve the objective.

Swap the 1-st and 3-rd stones from the left, resulting in RWWR.

Change the color of the 4-th stone from the left, resulting in RWWW.

Sample Input 2

2
RR

Sample Output 2

0

It can be the case that no operation is needed.

Sample Input 3

8
WRWWRWRR

Sample Output 3

3


<?php

[$X] = fscanf(STDIN, "%d");

echo 10 - intdiv($X, 200);

Score: 100 points

Problem Statement

M-kun is a competitor in AtCoder, whose highest rating is X.

In this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given:

From 400 through 599: 8-kyu

From 600 through 799: 7-kyu

From 800 through 999: 6-kyu

From 1000 through 1199: 5-kyu

From 1200 through 1399: 4-kyu

From 1400 through 1599: 3-kyu

From 1600 through 1799: 2-kyu

From 1800 through 1999: 1-kyu

What kyu does M-kun have?

Constraints

400 \leq X \leq 1999

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the kyu M-kun has, as an integer.
For example, if he has 8-kyu, print 8.

Sample Input 1

725

Sample Output 1

7

M-kun's highest rating is 725, which corresponds to 7-kyu.

Thus, 7 is the correct output.

Sample Input 2

1600

Sample Output 2

2

M-kun's highest rating is 1600, which corresponds to 2-kyu.

Thus, 2 is the correct output.


Score: 200 points

Problem Statement

M-kun has the following three cards:

A red card with the integer A.

A green card with the integer B.

A blue card with the integer C.

He is a genius magician who can do the following operation at most K times:

Choose one of the three cards and multiply the written integer by 2.

His magic is successful if both of the following conditions are satisfied after the operations:

The integer on the green card is strictly greater than the integer on the red card.

The integer on the blue card is strictly greater than the integer on the green card.

Determine whether the magic can be successful.

Constraints

1 \leq A, B, C \leq 7

1 \leq K \leq 7

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C
K

Output

If the magic can be successful, print Yes; otherwise, print No.

Sample Input 1

7 2 5
3

Sample Output 1

Yes

The magic will be successful if, for example, he does the following operations:

First, choose the blue card. The integers on the red, green, and blue cards are now 7, 2, and 10, respectively.

Second, choose the green card. The integers on the red, green, and blue cards are now 7, 4, and 10, respectively.

Third, choose the green card. The integers on the red, green, and blue cards are now 7, 8, and 10, respectively.

Sample Input 2

7 4 2
3

Sample Output 2

No

He has no way to succeed in the magic with at most three operations.


<?php
$arg1 = fgets(STDIN);
$kaisu = fgets(STDIN);
list($card['red'], $card['green'], $card['blue']) = explode(" ", $arg1);

if(($card['blue'] * $kaisu - 1) > ($card['green'] * $kaisu - 1) && ($card['green'] * $kaisu - 1) > $card['red']){
    echo "Yes";
}else{
    echo "No";
}

?>


<?php
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($N,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$rw[0]=0;
for($i=0;$i<$N;$i++) {
  $rw[$i+1]=$rw[$i]+$A[$i];
}
//足してもかけても大小はかわらない？
for($i=0;$i<$N-$K;$i++) {
  if ($rw[$K+$i]-$rw[$i]<$rw[$K+$i+1]-$rw[$i+1]) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }
}

Score: 300 points

Problem Statement

M-kun is a student in Aoki High School, where a year is divided into N terms.

There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:

For the first through (K-1)-th terms: not given.

For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.

M-kun scored A_i in the exam at the end of the i-th term.

For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is strictly greater than the grade for the (i-1)-th term.

Constraints

2 \leq N \leq 200000

1 \leq K \leq N-1

1 \leq A_i \leq 10^{9}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 A_3 \ldots A_N

Output

Print the answer in N-K lines.

The i-th line should contain Yes if the grade for the (K+i)-th term is greater than the grade for the (K+i-1)-th term, and No otherwise.

Sample Input 1

5 3
96 98 95 100 20

Sample Output 1

Yes
No

His grade for each term is computed as follows:

3-rd term: (96 \times 98 \times 95) = 893760

4-th term: (98 \times 95 \times 100) = 931000

5-th term: (95 \times 100 \times 20) = 190000

Sample Input 2

3 2
1001 869120 1001

Sample Output 2

No

Note that the output should be No if the grade for the 3-rd term is equal to the grade for the 2-nd term.

Sample Input 3

15 7
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9

Sample Output 3

Yes
Yes
No
Yes
Yes
No
Yes
Yes


<?php

fscanf(STDIN,"%d",$n);
$arr=array_map('intval',explode(" ",fgets(STDIN)));
$chart=[];
$x=0;
$y=0;
$money=1000;
for($i=1;$i<$n;$i++){
    $chart[$x][$y]=$arr[$i-1];
    $y+=1;

    if($arr[$i]==end($arr)){
        if($arr[$i-1]<$arr[$i]){
            $chart[$x][$y]=$arr[$i];
        }else{
            $chart[$x+1][0]=$arr[$i];
        }
        break;
    }elseif($arr[$i-1]>$arr[$i]){
        $x+=1;
        $y=0;
    }
}
for($j=0;$j<count($chart);$j++){
    if(count($chart[$j])>=2){
    $money=intdiv($money,min($chart[$j]))*max($chart[$j])+$money%min($chart[$j]);
    }
}
echo $money;

Score: 400 points

Problem Statement

To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.

He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:

A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day.

In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time.

Buy stock: Pay A_i yen and receive one stock.

Sell stock: Sell one stock for A_i yen.

What is the maximum possible amount of money that M-kun can have in the end by trading optimally?

Constraints

2 \leq N \leq 80

100 \leq A_i \leq 200

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the maximum possible amount of money that M-kun can have in the end, as an integer.

Sample Input 1

7
100 130 130 130 115 115 150

Sample Output 1

1685

In this sample input, M-kun has seven days of trading. One way to have 1685 yen in the end is as follows:

Initially, he has 1000 yen and no stocks.

Day 1: Buy 10 stocks for 1000 yen. Now he has 0 yen.

Day 2: Sell 7 stocks for 910 yen. Now he has 910 yen.

Day 3: Sell 3 stocks for 390 yen. Now he has 1300 yen.

Day 4: Do nothing.

Day 5: Buy 1 stock for 115 yen. Now he has 1185 yen.

Day 6: Buy 10 stocks for 1150 yen. Now he has 35 yen.

Day 7: Sell 11 stocks for 1650 yen. Now he has 1685 yen.

There is no way to have 1686 yen or more in the end, so the answer is 1685.

Sample Input 2

6
200 180 160 140 120 100

Sample Output 2

1000

In this sample input, it is optimal to do nothing throughout the six days, after which we will have 1000 yen.

Sample Input 3

2
157 193

Sample Output 3

1216

In this sample input, it is optimal to buy 6 stocks in Day 1 and sell them in Day 2, after which we will have 1216 yen.


Score : 100 points

Problem Statement

How many multiples of d are there among the integers between L and R (inclusive)?

Constraints

All values in input are integers.

1 \leq L \leq R \leq 100

1 \leq d \leq 100

Input

Input is given from Standard Input in the following format:

L R d

Output

Print the number of multiples of d among the integers between L and R (inclusive).

Sample Input 1

5 10 2

Sample Output 1

3

Among the integers between 5 and 10, there are three multiples of 2: 6, 8, and 10.

Sample Input 2

6 20 7

Sample Output 2

2

Among the integers between 6 and 20, there are two multiples of 7: 7 and 14.

Sample Input 3

1 100 1

Sample Output 3

100


<?php
  list($L, $R, $d) = explode(" ", trim(fgets(STDIN)));

  $min = intdiv($L + $d - 1, $d);
  $max = intdiv($R, $d);

  echo $max - $min + 1;


Score : 300 points

Problem Statement

Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:

1 \leq x,y,z

x^2 + y^2 + z^2 + xy + yz + zx = n

Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).

Constraints

All values in input are integers.

1 \leq N \leq 10^4

Input

Input is given from Standard Input in the following format:

N

Output

Print N lines. The i-th line should contain the value f(i).

Sample Input 1

20

Sample Output 1

0
0
0
0
0
1
0
0
0
0
3
0
0
0
0
0
3
3
0
0

For n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.

For n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.

For n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.

For n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.


<?php
list($n) = ints();
$max = (int) (sqrt($n) + 1);
$ans = array_fill(1, $n, 0);
for ($x = 1; $x <= $max; ++$x) {
    for ($y = $x; $y <= $max; ++$y) {
        for ($z = $y; $z <= $max; ++$z) {
            $t = $x ** 2 + $y ** 2 + $z ** 2 + $x * $y + $y * $z + $x * $z;
            if ($t <= $n) {
                $c = count(array_unique([$x, $y, $z]));
                if ($c === 3) $ans[$t] += 6;
                elseif ($c === 2) $ans[$t] += 3;
                else ++$ans[$t];
            }
        }
    }
}
echo implode(PHP_EOL, $ans);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


<?php
list($N, $K) = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$A = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

sort($A);

$ans = 1;
$n = 0;
$mod = 1000000007;

while ($n !== $K) {
    $len = count($A);
    if (isset($A[$len-2]) && $A[$len-2] >= 0) {
        if ($A[0] * $A[1] > $A[$len-1] * $A[$len-2] && $n + 1 < $K) {
            $n += 2;
            $ans *= array_shift($A) * array_shift($A);
        } else {
            $n += 1;
            $ans *= array_pop($A);
        }
    } else {
        if ($A[$len-1] > 0 && $n + 1 < $K) {
            $n += 2;
            $ans *= array_shift($A) * array_shift($A);
            var_dump($ans);
        } else {
            $n += 1;
            $ans *= array_pop($A);
        }
    }
    $ans %= $mod;
}

echo $ans >= 0 ? $ans : $mod + $ans;

Score : 500 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

We will choose exactly K of these elements. Find the maximum possible product of the chosen elements.

Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

Constraints

1 \leq K \leq N \leq 2\times 10^5

|A_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N K
A_1 \ldots A_N

Output

Print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

Sample Input 1

4 2
1 2 -3 -4

Sample Output 1

12

The possible products of the two chosen elements are 2, -3, -4, -6, -8, and 12, so the maximum product is 12.

Sample Input 2

4 3
-1 -2 -3 -4

Sample Output 2

1000000001

The possible products of the three chosen elements are -24, -12, -8, and -6, so the maximum product is -6.

We print this value modulo (10^9+7), that is, 1000000001.

Sample Input 3

2 1
-1 1000000000

Sample Output 3

1000000000

The possible products of the one chosen element are -1 and 1000000000, so the maximum product is 1000000000.

Sample Input 4

10 10
1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1

Sample Output 4

999983200

Be sure to print the product modulo (10^9+7).


Score : 100 points

Problem Statement

Given an integer a as input, print the value a + a^2 + a^3.

Constraints

1 \leq a \leq 10

a is an integer.

Input

Input is given from Standard Input in the following format:

a

Output

Print the value a + a^2 + a^3 as an integer.

Sample Input 1

2

Sample Output 1

14

When a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.

Print the answer as an input. Outputs such as 14.0 will be judged as incorrect.

Sample Input 2

10

Sample Output 2

1110


<?php
  $a = trim(fgets(STDIN));
  $b = trim(fgets(STDIN));
  for($i = 0; $i < strlen($a); $i++)$count+=$a[$i]!=$b[$i];
  echo $count;

Score : 200 points

Problem Statement

Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.

Operation: Choose one character of S and replace it with a different character.

Constraints

S and T have lengths between 1 and 2\times 10^5 (inclusive).

S and T consists of lowercase English letters.

S and T have equal lengths.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print the answer.

Sample Input 1

cupofcoffee
cupofhottea

Sample Output 1

4

We can achieve the objective in four operations, such as the following:

First, replace the sixth character c with h.

Second, replace the eighth character f with t.

Third, replace the ninth character f with t.

Fourth, replace the eleventh character e with a.

Sample Input 2

abcde
bcdea

Sample Output 2

5

Sample Input 3

apple
apple

Sample Output 3

0

No operations may be needed to achieve the objective.


<?php

  $a = fgets(STDIN);
  $b = fgets(STDIN);

  $length = strlen($a);

  $result = 0;

  for($i=0; $i< $length; $i++)
  {
    if($a[$i] !== $b[$i]){
      $result += 1;
    }
  }

  echo $result -1;


<?php
list($S) = sscanf(trim(fgets(STDIN)), "%s");
if(ctype_upper($S)){
    print("A");
}else{
    print("a");
}

Score : 100 points

Problem Statement

An uppercase or lowercase English letter \alpha will be given as input.
If \alpha is uppercase, print A; if it is lowercase, print a.

Constraints

\alpha is an uppercase (A - Z) or lowercase (a - z) English letter.

Input

Input is given from Standard Input in the following format:

α

Output

If \alpha is uppercase, print A; if it is lowercase, print a.

Sample Input 1

B

Sample Output 1

A

B is uppercase, so we should print A.

Sample Input 2

a

Sample Output 2

a

a is lowercase, so we should print a.


<?php

fscanf(STDIN, "%s", $a);

if (ctype_upper($a)) {
  echo "A";
} else {
  echo "a";
}


<?php
	$num = trim(fgets(STDIN));
	$abc = range('a', 'z');

	while (true) {
  		$num--;
  		$a = $num % 26;
  		$num = floor($num / 26);
  		$name[] = $abc[$a];
  		if ($num < 1){
        	break;
        }
	}
	for($i=count($name); $i>=0; $i--){
    	echo $name[$i];
    }

?>

Score : 300 points

Problem Statement

1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:

the dogs numbered 1,2,\cdots,26 were respectively given the names a, b, ..., z;

the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names aa, ab, ac, ..., zy, zz;

the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names aaa, aab, aac, ..., zzy, zzz;

the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names aaaa, aaab, aaac, ..., zzzy, zzzz;

the dogs numbered 475255,475256,\cdots were respectively given the names aaaaa, aaaab, ...;

and so on.

To sum it up, the dogs numbered 1, 2, \cdots were respectively given the following names:

a, b, ..., z, aa, ab, ..., az, ba, bb, ..., bz, ..., za, zb, ..., zz, aaa, aab, ..., aaz, aba, abb, ..., abz, ..., zzz, aaaa, ...

Now, Roger asks you:

"What is the name for the dog numbered N?"

Constraints

N is an integer.

1 \leq N \leq 1000000000000001

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer to Roger's question as a string consisting of lowercase English letters.

Sample Input 1

2

Sample Output 1

b

Sample Input 2

27

Sample Output 2

aa

Sample Input 3

123456789

Sample Output 3

jjddja


<?php
$n = (int)fgets(STDIN);
$ans = "";
while($n > 0){
  $n--;
  $ans.=chr(ord('a') + $n%26);
  $n = intdiv($n, 26);
}
echo strrev($ans);


<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
 $n--;
 $s = 'abcdefghijklmnopqrstuvwxyz';
 $ans = [];
 while(1){
   $m = $n%26;
   $n = intdiv($n, 26);
   $ans[] = $s[$m];
   if($n == 0){
     break;
   }
   $n--;
 }

 $ans = array_reverse($ans);

 $start = 0;
 for ($i=$start; $i<count($ans); $i++) {
   echo $ans[$i];
 }


<?php
fscanf(STDIN,"%d",$n);
$a_li = explode(" ",trim(fgets(STDIN)));
$sum = array_sum($a_li);
$count_val = array();
foreach($a_li as $a){
  $count_val[$a]++;
}
//print_r($count_val);
fscanf(STDIN,"%d",$q);
for($i=0;$i<$q;$i++){
	fscanf(STDIN,"%d%d",$b,$c);
   	$sum = ($sum+($c-$b)*$count_val[$b]);
  	echo $sum."\n";
  	$count_val[$c] += $count_val[$b];
  	$count_val[$b] = 0;
    //print_r($count_val);
}

Score : 400 points

Problem Statement

You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.

You will now successively do the following Q operations:

In the i-th operation, you replace every element whose value is B_{i} with C_{i}.

For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Constraints

All values in input are integers.

1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}

B_{i} \neq C_{i}

Input

Input is given from Standard Input in the following format:

N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}

Output

Print Q integers S_{i} to Standard Output in the following format:

S_{1}
S_{2}
\vdots
S_{Q}

Note that S_{i} may not fit into a 32-bit integer.

Sample Input 1

4
1 2 3 4
3
1 2
3 4
2 4

Sample Output 1

11
12
16

Initially, the sequence A is 1,2,3,4.

After each operation, it becomes the following:

2, 2, 3, 4

2, 2, 4, 4

4, 4, 4, 4

Sample Input 2

4
1 1 1 1
3
1 2
2 1
3 5

Sample Output 2

8
4
4

Note that the sequence A may not contain an element whose value is B_{i}.

Sample Input 3

2
1 2
3
1 100
2 100
100 1000

Sample Output 3

102
200
2000


<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $a = array_map('intval', explode(" ", trim(fgets(STDIN))));
  $sum = 0;
  $count = [];
  for ($i=0; $i<$n; $i++) {
    if(!isset($count[$a[$i]])) $count[$a[$i]] = 0;
    $count[$a[$i]]++;
    $sum += $a[$i];
  }
  $sum = array_sum($a);

  list($q) = explode(" ", trim(fgets(STDIN)));
  for ($i=0; $i<$q; $i++) {
    list($b, $c) = array_map('intval', explode(" ", trim(fgets(STDIN))));
    $count_b = 0;
    if(isset($count[$b])) {
      $count_b = $count[$b];
      if(!isset($count[$c])) $count[$c] = 0;
      $count[$c] += $count_b;
      $count[$b] = 0;
      $sum += ($c - $b) * $count_b;
    }
    echo $sum.PHP_EOL;
  }


<?php
$arr = array_map('intval', explode(' ', fgets(STDIN)));
echo array_search(0, $arr) + 1;

Score : 100 points

Problem Statement

We have five variables x_1, x_2, x_3, x_4, and x_5.

The variable x_i was initially assigned a value of i.

Snuke chose one of these variables and assigned it 0.

You are given the values of the five variables after this assignment.

Find out which variable Snuke assigned 0.

Constraints

The values of x_1, x_2, x_3, x_4, and x_5 given as input are a possible outcome of the assignment by Snuke.

Input

Input is given from Standard Input in the following format:

x_1 x_2 x_3 x_4 x_5

Output

If the variable Snuke assigned 0 was x_i, print the integer i.

Sample Input 1

0 2 3 4 5

Sample Output 1

1

In this case, Snuke assigned 0 to x_1, so we should print 1.

Sample Input 2

1 2 0 4 5

Sample Output 2

3


Score : 200 points

Problem Statement

There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.

Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.

Constraints

1 \leq X \leq 100

1 \leq Y \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

If there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes; otherwise, print No.

Sample Input 1

3 8

Sample Output 1

Yes

The statement "there are 3 animals in total in the garden, and they have 8 legs in total" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.

Sample Input 2

2 100

Sample Output 2

No

There is no combination of numbers of cranes and turtles in which this statement is correct.

Sample Input 3

1 2

Sample Output 3

Yes

We also consider the case in which there are only cranes or only turtles.


<?php

declare(strict_types=1);

fscanf(STDIN, "%d%d", $a, $b);

if ($b % 2 == 0 && ($b / $a) <= 4) {
    echo 'Yes';
} else {
    echo 'No';
}


<?php

 $a = explode(" ", fgets(STDIN));

 echo isTrue($a[0],$a[1]);

function isTrue($count,$num){

   while($count != 0){

     if($num >= 4){
      	$num -= 4;
     }elseif($num >= 2){
      	$num -= 2;
     }

     if($num == 0){
      return "Yes";
     }

     $count--;

   }
   return "No";
}


<?php
  fscanf(STDIN, "%d %d", $dobutsu, $ashi);
  for($i = 0;$i < $dobutsu;$i++) {
      $tsuru = $i;
      $kame = $dobutsu - $tsuru;

      if($ashi === ($tsuru * 2 + $kame * 4)) {
        echo "Yes";
        exit(0);
      }
  }
  echo "No";


<?php
  $tmp = explode(" ",trim(fgets(STDIN)));

  $x = $tmp[0];
  $n = $tmp[1];

  $tmpData = explode(" ",trim(fgets(STDIN)));
  $data = [];
  foreach($tmpData as $val){
    $data[$val] = $val;
  }

  for($i=0; $i<=100; $i++){
    $val1 = $x-$i;
    $val2 = $x+$i;

    if(!isset($data[$val1])){
      echo $val1."\n";
      break;
    }else if(!isset($data[$val2])){
      echo $val2."\n";
      break;
    }
  }

Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.


<?php
declare(strict_types=1);

list($x, $n) = explode(" ", trim(fgets(STDIN)));
$p = explode(" ", trim(fgets(STDIN)));
$max = $x;
$min = $x;
for ($i = 0; $i < 101; $i++) {
    if (in_array($max, $p)) $max++;
    if (in_array($min, $p)) $min--;
}
if ($x - $min > $max - $x) echo $max;
else echo $min;


<?php

fscanf(STDIN, "%d%d", $x, $n);
$p_list = explode(' ', trim(fgets(STDIN)));

$lte = $x;
$gte = $x;
while (in_array($lte, $p_list) && in_array($gte, $p_list)) {
    --$lte;
    ++$gte;
}

if (!in_array($lte, $p_list)) {
    echo $lte;
} else {
    echo $gte;
}


<?php
list($X, $N) = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$hun = range(0, 100);
$P = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$_P = array_diff($hun, $P);
sort($_P);

$min_abs = $X;
$ans = 0;

foreach ($_P as $p) {
    if (abs($X - $p) < $min_abs) {
        $min_abs = abs($X - $p);
        $ans = $p;
    }
}

echo $ans;


<?php
  $s = fgets(STDIN);
  echo substr($s, 0, 3);

Score : 100 points

Problem Statement

When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters.
You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.

Constraints

3 \leq |S| \leq 20

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print your answer.

Sample Input 1

takahashi

Sample Output 1

tak

Sample Input 2

naohiro

Sample Output 2

nao


<?php
  fscanf(STDIN, "%d %d", $a, $v);
  fscanf(STDIN, "%d %d", $b, $w);
  fscanf(STDIN, "%d", $t);

  for ($i = $t; $i > 0 ; $i--) {
    // code...
    $a += $v;
    $b += $w;
    if($a == $b){
      echo 'YES';
      return;
    }
  }

  if ($b == $a) {
    // code...
    echo 'YES';

  }else {
    // code...
    echo 'NO';
  }

Score : 200 points

Problem Statement

Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second.
The other child is now at coordinate B, and she can travel the distance of W per second.

He can catch her when his coordinate is the same as hers.
Determine whether he can catch her within T seconds (including exactly T seconds later).
We assume that both children move optimally.

Constraints

-10^9 \leq A,B \leq 10^9

1 \leq V,W \leq 10^9

1 \leq T \leq 10^9

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A V
B W
T

Output

If "it" can catch the other child, print YES; otherwise, print NO.

Sample Input 1

1 2
3 1
3

Sample Output 1

YES

Sample Input 2

1 2
3 2
3

Sample Output 2

NO

Sample Input 3

1 2
3 3
3

Sample Output 3

NO


<?php
fscanf(STDIN,"%d %d",$A,$V);
fscanf(STDIN,"%d %d",$B,$W);
fscanf(STDIN,"%d",$T);

$ans = 'NO';
if ($A == $B) {
  echo "YES";
}elseif ($A < $B && $V <= $W) {
  echo 'NO';
}


Score : 500 points

Problem Statement

We have N bulbs arranged on a number line, numbered 1 to N from left to right.
Bulb i is at coordinate i.

Each bulb has a non-negative integer parameter called intensity.
When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.
Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:

For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.

Find the intensity of each bulb after the K operations.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq K \leq 2 \times 10^5

0 \leq A_i \leq N

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:

A{'}_1 A{'}_2 \ldots A{'}_N

Sample Input 1

5 1
1 0 0 1 0

Sample Output 1

1 2 2 1 2

Initially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.
Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.

Sample Input 2

5 2
1 0 0 1 0

Sample Output 2

3 3 4 4 3


<?php
  // 標準入力取得
  $inputs = fgets(STDIN);
  $inputs = str_replace(PHP_EOL, '', $inputs);

  // 電球の個数と操作の回数を定義
  list($dNum, $opNum) = preg_split('/\s+/', $inputs);

  $dStatuses = fgets(STDIN);
  $dStatuses = str_replace(PHP_EOL, '', $dStatuses);

  // 電球のステータスを配列として定義
  $dStatusArray = preg_split('/\s+/', $dStatuses);

  // 指定された回数同じ操作を繰り返す
  $cnt = 0;
  for ($i = 0; $i <= $opNum; $i++) {
    $changeResult = array_fill(0, $dNum, 0); // 変更結果を保存するための配列を定義
    $tmpArray = $dStatusArray;
    foreach ($tmpArray as $key => $value) {
      for($i = -$value; $i <= $value; $i++) {
        // 配列が存在しない場合には続行
        if ($key + $i >= 0 && $key + $i < $dNum) {
          // 配列があった場合には所定の処理を実行する
          $changeResult[$key + $i] += 1;
        }

      }
    }
    $cnt += 1;
    $dStatusArray = $changeResult;
  }

  echo implode(" ", $dStatuses);


<?php
fscanf(STDIN, '%d', $cnt);
$nums = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = true;
for ($i=0; $i < $cnt; $i++) {
    (int)$ans *= $nums[$i];
}
$limit = pow(10, 18);
if ($ans > $limit) {
    $ans = -1;
}
echo $ans;

Score : 100 points

Problem Statement

Compute A \times B.

Constraints

1 \leq A \leq 100

1 \leq B \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the value A \times B as an integer.

Sample Input 1

2 5

Sample Output 1

10

We have 2 \times 5 = 10.

Sample Input 2

100 100

Sample Output 2

10000


<?php
// Your code here!
fscanf(STDIN,"%d%d",$a,$b);
//$a_li = explode(" ",trim(fgets(STDIN)));
//for($i=0;$i<$n;$i++)

echo ($a*$b)."\n";

?>


<?php
$N = (int)fgets(STDIN);
if ($N === 1) {
    echo 0;
    return;
}

$sqrt_N = (int)sqrt($N) + 1;

$map_of_prime = [];
for ($i = 2; $i < $sqrt_N; $i++) {
    $map_of_prime[$i] = 0;
    while ($N % $i === 0) {
        $map_of_prime[$i] += 1;
        $N = $N / $i;
    }
}

$ans = 0;
foreach ($map_of_prime as $prime) {
    if ($prime > 0) {
        $i = 1;
        while ($prime >= $i) {
            $ans += 1;
            $prime -= $i;
            $i += 1;
        }
    }
}

echo $ans ? $ans : 1;

Score : 400 points

Problem Statement

Given is a positive integer N. Consider repeatedly applying the operation below on N:

First, choose a positive integer z satisfying all of the conditions below:

z can be represented as z=p^e, where p is a prime number and e is a positive integer;

z divides N;

z is different from all integers chosen in previous operations.

Then, replace N with N/z.

Find the maximum number of times the operation can be applied.

Constraints

All values in input are integers.

1 \leq N \leq 10^{12}

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum number of times the operation can be applied.

Sample Input 1

24

Sample Output 1

3

We can apply the operation three times by, for example, making the following choices:

Choose z=2 (=2^1). (Now we have N=12.)

Choose z=3 (=3^1). (Now we have N=4.)

Choose z=4 (=2^2). (Now we have N=1.)

Sample Input 2

1

Sample Output 2

0

We cannot apply the operation at all.

Sample Input 3

64

Sample Output 3

3

We can apply the operation three times by, for example, making the following choices:

Choose z=2 (=2^1). (Now we have N=32.)

Choose z=4 (=2^2). (Now we have N=8.)

Choose z=8 (=2^3). (Now we have N=1.)

Sample Input 4

1000000007

Sample Output 4

1

We can apply the operation once by, for example, making the following choice:

z=1000000007 (=1000000007^1). (Now we have N=1.)

Sample Input 5

997764507000

Sample Output 5

7


<?php

$s = trim(fgets(STDIN));
$pd = 'PD';
$p = 'D';
echo str_replace('?','D',$s);

Score : 200 points

Problem Statement

For a string S consisting of the uppercase English letters P and D, let the doctoral and postdoctoral quotient of S be the total number of occurrences of D and PD in S as contiguous substrings. For example, if S = PPDDP, it contains two occurrences of D and one occurrence of PD as contiguous substrings, so the doctoral and postdoctoral quotient of S is 3.

We have a string T consisting of P, D, and ?.

Among the strings that can be obtained by replacing each ? in T with P or D, find one with the maximum possible doctoral and postdoctoral quotient.

Constraints

1 \leq |T| \leq 2 \times 10^5

T consists of P, D, and ?.

Input

Input is given from Standard Input in the following format:

T

Output

Print one string with the maximum possible doctoral and postdoctoral quotient among the strings that can be obtained by replacing each ? in T with P or D.
If there are multiple such strings, you may print any of them.

Sample Input 1

PD?D??P

Sample Output 1

PDPDPDP

This string contains three occurrences of D and three occurrences of PD as contiguous substrings, so its doctoral and postdoctoral quotient is 6, which is the maximum doctoral and postdoctoral quotient of a string obtained by replacing each ? in T with P or D.

Sample Input 2

P?P?

Sample Output 2

PDPD


<?php
  $coin = 0;
  fscanf(STDIN, "%d", $t);

  function x(&$n, $x, $c){
    $coin = 0;
    while(true) {
        if(($n/$x) > 1) {
          $coin = $coin + $c;
          $n = floor($n/$x);
        }
        if(($n/$x) < 1) {
          break;
        }
        if(($n/$x) == 1) {
          $coin++;
          break;
        }
    }
    return $coin;
  }
  for($i=0;$i<$t;$i++) {
    $coin = 0;
    fscanf(STDIN, "%d %d %d %d %d ", $n, $a, $b, $c, $d);

    $coin = $coin + x($n, 5, $c);
    $coin = $coin + x($n, 3, $b);
    $coin = $coin + x($n, 2, $a);
    $coin = $coin + $n * $d;
    echo $coin.PHP_EOL;
  }

Score : 400 points

Problem Statement

You start with the number 0 and you want to reach the number N.

You can change the number, paying a certain amount of coins, with the following operations:

Multiply the number by 2, paying A coins.

Multiply the number by 3, paying B coins.

Multiply the number by 5, paying C coins.

Increase or decrease the number by 1, paying D coins.

You can perform these operations in arbitrary order and an arbitrary number of times.

What is the minimum number of coins you need to reach N?

You have to solve T testcases.

Constraints

1 \le T \le 10

1 \le N \le 10^{18}

1 \le A, B, C, D \le 10^9

All numbers N, A, B, C, D are integers.

Input

The input is given from Standard Input. The first line of the input is

T

Then, T lines follow describing the T testcases.
Each of the T lines has the format

N A B C D

Output

For each testcase, print the answer on Standard Output followed by a newline.

Sample Input 1

5
11 1 2 4 8
11 1 2 2 8
32 10 8 5 4
29384293847243 454353412 332423423 934923490 1
900000000000000000 332423423 454353412 934923490 987654321

Sample Output 1

20
19
26
3821859835
23441258666

For the first testcase, a sequence of moves that achieves the minimum cost of 20 is:

Initially x = 0.

Pay 8 to increase by 1 (x = 1).

Pay 1 to multiply by 2 (x = 2).

Pay 1 to multiply by 2 (x = 4).

Pay 2 to multiply by 3 (x = 12).

Pay 8 to decrease by 1 (x = 11).

For the second testcase, a sequence of moves that achieves the minimum cost of 19 is:

Initially x = 0.

Pay 8 to increase by 1 (x = 1).

Pay 1 to multiply by 2 (x = 2).

Pay 2 to multiply by 5 (x = 10).

Pay 8 to increase by 1 (x = 11).


<?php
  function is_edge($n, $p) {
    $c = get_column($n, $p);
    $r = get_row($n, $p);
  	if($c === 1||$c === $n) {
      return true;
    } else if($r === 1||$r === $n) {
      return true;
    }
    return false;
  }
  function get_column($n, $p) {
    if(($p % $n) === 0) {
      return $n;
    }
    return ($p % $n);
  }
  function get_row($n, $p) {
    return (int) ceil($p / $n);
  }

  $record = [];
  function exit_maze($n, $p) {
    if(is_edge($n, $p)) {
      $record[$p] = false;
      return true;
    }

    return false;
  }
fscanf(STDIN, "%d", $n);
$p = explode(' ', fgets(STDIN));

$count=0;
$ct=0;
for($i = 0;$i<($n*$n);$i++) {
  $ct++;
  if(!exit_maze($n, (int) $p[$i])) {
//echo get_row($n, (int) $p[$i])."gyo";
//echo get_column($n, (int) $p[$i])."rets";
  //  echo $p[$i].PHP_EOL;
    $count++;
  }
}
echo $count." ".$ct;
//var_dump(is_edge($n, (int) $p[$i]));
//echo get_row($n, (int) $p[$i])."gyo";
//echo get_column($n, (int) $p[$i])."rets";

Score : 700 points

Problem Statement

Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2.

At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat.
To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column).
While leaving the cinema, it might be that a certain viewer x goes through a seat currently occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever.

Compute the number of pairs of viewers (x, y) such that y will hate x forever.

Constraints

2 \le N \le 500

The sequence P_1, P_2, \dots, P_{N^2} is a permutation of \{1, 2, \dots, N^2\}.

Input

The input is given from Standard Input in the format

N
P_1 P_2 \cdots P_{N^2}

Output

If ans is the number of pairs of viewers described in the statement, you should print on Standard Output

ans

Sample Input 1

3
1 3 7 9 5 4 8 6 2

Sample Output 1

1

Before the end of the movie, the viewers are arranged in the cinema as follows:

1 2 3
4 5 6
7 8 9

The first four viewers leaving the cinema (1, 3, 7, 9) can leave the cinema without going through any seat, so they will not be hated by anybody.

Then, viewer 5 must go through one of the seats where viewers 2, 4, 6, 8 are currently seated while leaving the cinema; hence he will be hated by at least one of those viewers.

Finally the remaining viewers can leave the cinema (in the order 4, 8, 6, 2) without going through any occupied seat (actually, they can leave the cinema without going through any seat at all).

Sample Input 2

4
6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8

Sample Output 2

3

Sample Input 3

6
11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30

Sample Output 3

11