<?php
while (true) {
    $inputString = getInputStringBothEndsRemovedSpaces();
    list($a, $operator, $b) = explodeStringWithSpaces($inputString);

    switch ($operator) {
        case '+':
            $result = addingTwoNum($a, $b);
            break;
        case '-':
            $result = subTractTwoNum($a, $b);
            break;
        case '*':
            $result = multiplyTwoNum($a, $b);
            break;
        case '/':
            $result = divideTwoNumByFloorPoint($a, $b);
            break;
        case '?':
            exit;
    }
    echo $result, PHP_EOL;
}

function getInputStringBothEndsRemovedSpaces()
{
    return trim(fgets(STDIN));
}

function explodeStringWithSpaces($inputString)
{
    return explode(' ', $inputString);
}

function addingTwoNum($a, $b)
{
    return $a + $b;
}

function subTractTwoNum($a, $b)
{
    return $a - $b;
}

function multiplyTwoNum($a, $b)
{
    return $a * $b;
}

function divideTwoNumByFloorPoint($a, $b)
{
    return floor($a / $b);
}


<?php

$nums = array();
while (true) {

    list($a, $op, $b) = explode(" ", trim(fgets(STDIN)));

    if($op == "?"){
        break;
    }

    if ($op == "+") {
        array_push($nums, $a + $b);
    }else if($op == "-"){
        array_push($nums, $a - $b);
    }else if($op == "/"){
        array_push($nums, $a / $b);
    }else{
        array_push($nums, $a * $b);
    }
}
echo implode("\n", $nums), PHP_EOL;

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

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

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
fscanf(STDIN, "%d", $n);

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

list($min, $max, $total) = array_reduce($nums, function ($carry, $n) {
    if ($n < $carry[0]) {
        $carry[0] = $n;
    }

    if ($carry[1] < $n) {
        $carry[1] = $n;
    }

    $carry[2] += $n;

    return $carry;
}, array(1000001, -1000001, 0));

echo "$min $max $total\n";

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 = fgets(STDIN);
$array = explode(" ", trim(fgets(STDIN)));
echo min($array)." ".max($array)." ".array_sum($array)."\n";


<?php

$main = new Main;
$main->execute();

class Main {

    public function execute()
    {
        while (true) {
            fscanf(STDIN, '%d %d', $height, $width);

            if (! $this->canExecute($width, $height)) return;

            $rect = new Rectangle($width, $height);
            $rect->draw();
        }
    }

    public function canExecute($width, $height)
    {
        return ($width != 0) && ($height != 0);
    }

}

/**
 * ????????¢???????????????
 */
class Rectangle {
    private $width;
    private $height;
    private $char = '#';

    public function __construct($width, $height)
    {
        $this->width  = $width;
        $this->height = $height;
    }

    public function draw()
    {
        for ($line = 0; $line < $this->height; $line++) {
             $this->drawLine($this->width, $this->char);
        }
        $this->drawEmptyLine();
    }

    public function drawLine()
    {
        echo str_repeat($this->char, $this->width), PHP_EOL;
    }

    public function drawEmptyLine()
    {
        echo 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

(new Main)->execute();

class Rectangle
{
    private $height;
    private $width;
    private $style;

    private $rectangle = [];

    public function __construct($height, $width, $style)
    {
        $this->height = $height;
        $this->width  = $width;
        $this->style  = $style;

        $this->rectangle = $this->make();
    }

    private function make()
    {
        $rectangle = [];
        for ($height = 0; $height < $this->height; $height++) {
            $rectangle[$height] = str_repeat($this->style, $this->width);
        }
        return $rectangle;
    }

    private function setColsInnerFrame($thickness, $style)
    {
        foreach ($this->rectangle as $height => $_) {
            for ($width = 0; $width < $thickness; $width++) {
                $this->rectangle[$height][$width]                    = $style;
                $this->rectangle[$height][$this->width - $width - 1] = $style;
            }
        }
    }

    private function setRowsInnerFrame($thickness, $style)
    {
        foreach ($this->rectangle as $height => $_) {
            if ($height >= $thickness) { return; }

            $this->rectangle[$height]                     = str_repeat($style, $this->width);
            $this->rectangle[$this->height - $height - 1] = str_repeat($style, $this->width);
        }
    }

    public function setCheckerboardPattern($style = '#')
    {
        $checkLine = str_pad('', $this->width + 1, $style.$this->style);

        foreach ($this->rectangle as $height => $_) {
            $row = substr($checkLine, $height % 2, $this->width);
            $this->rectangle[$height] = $row;
        }

        return $this;
    }

    public function setInnerFrame($thickness = 1, $style = '#')
    {
        if ($thickness > $this->width) {
            $thickness = $this->width;
        }

        $this->setRowsInnerFrame($thickness, $style);
        $this->setColsInnerFrame($thickness, $style);

        return $this;
    }

    public function get()
    {
        return implode(PHP_EOL, $this->rectangle).PHP_EOL;
    }
}

class Main
{
    public function execute()
    {
        while (true) {
            list($height, $width) = $this->getStdinExplodedBy(' ');
            if ($this->invalid($height, $width)) { return; }

            $rectangle = (new Rectangle($height, $width, '.'))
                ->setInnerFrame(1, '#')
                ->get();

            $this->draw($rectangle);
        }
    }

    private function getStdinExplodedBy($delimiter)
    {
        return explode($delimiter, trim(fgets(STDIN)));
    }

    private function invalid($height, $width)
    {
        return $height == 0 && $width == 0;
    }

    public function draw($shape)
    {
        echo $shape, PHP_EOL;
    }
}

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(fscanf(STDIN, "%d%d", $h, $w)){
    if($h == 0 && $w == 0){
        return 1;
    }
$count = 0;
for($i = 0; $i < $h; $i++){

$a = substr(str_repeat("#.", ceil($w/2)), 0, $w);
$b = substr(str_repeat(".#", ceil($w/2)), 0, $w);

if($count % 2 == 0){
    echo $a.PHP_EOL;
    $count++;
}else {
    echo $b.PHP_EOL;
    $count++;
}
}echo PHP_EOL; //for
} //while
?>

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

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

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

#.#
.#.
#.#

#.
.#

#


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
    fscanf(STDIN,"%d",$n);
    $i=1;

    while(true){
        $flag=false;
        if($i%3==0){
            $flag=true;
        }
        $a=$i;
        while($a>0){
            if($a%10==3){
                $flag=true;
            }
            $a/=10;
        }
        if($flag){
            echo " ".$i;
        }
        if($i==$n)break;
        $i++;
    }
    echo "\n";


<?php

$data = explode(" ", trim(fgets(STDIN)));
$data_reverse = array_reverse($data);

foreach ($data_reverse as $value) {
    printf("%d", $value);
    if ($value !== end($data_reverse)) {
        printf(" ");
    }
}

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
$card_count = trim(fgets(STDIN));
$card_kind = array('S','H','C','D');
$card_set = array();
foreach ($card_kind as $kind) {
    for( $i = 1 ; $i <= 13 ; ++ $i ){
        array_push($card_set,$kind.' '.$i);
    }
}
$find_card_set = array();
while($input = trim(fgets(STDIN))){
    array_push($find_card_set,$input);
}
$missing_card_set = array_diff($card_set,$find_card_set);
if (count($missing_card_set)>0) echo join($missing_card_set,PHP_EOL),PHP_EOL;

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

(new Main)->execute();

class Main
{
    public function execute()
    {
        $house = new House();
        $n = getInput();
        for ($i = 0; $i < $n; $i++) {
            fscanf(STDIN, '%d %d %d %d', $b, $f, $r, $v);
            $house->put($b, $f, $r, $v);
        }
        $tenant = $house->merge();
        echo $house->merge2($tenant);
    }
}

class House
{
    private $room;
    private $floor;
    private $buildings;

    public function __construct()
    {
        $rooms     = array_fill_keys(range(1, 10), 0);
        $floors    = array_fill_keys(range(1, 3), $rooms);
        $buildings = array_fill_keys(range(1, 4), $floors);
    }

    public function put($b, $f, $r, $v)
    {
        $this->buildings[$b][$f][$r] = $v;
    }

    public function merge()
    {
        foreach ($this->buildings as $floors) {
            $floor = array();
                foreach ($floors as $rooms) {
                    $floor[] = sprintf(' %s%s', implode(' ', $rooms), PHP_EOL);
            }
        $tenant[] = implode('', $floor);

        }
        return $tenant;
    }

    public function merge2($tenant)
    {
        return implode(str_repeat('#', 20) . "\n", $tenant);
    }
}

function getInput()
{
    return trim(getInput());
}

Official House

You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room.

For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left.

Assume that initially no person lives in the building.

Input

In the first line, the number of notices n is given. In the following n lines, a set of four integers b, f, r and v which represents ith notice is given in a line.

Output

For each building, print the information of 1st, 2nd and 3rd floor in this order. For each floor information, print the number of tenants of 1st, 2nd, .. and 10th room in this order. Print a single space character before the number of tenants. Print "####################" (20 '#') between buildings.

Constraints

No incorrect building, floor and room numbers are given.

0 ≤ the number of tenants during the management ≤ 9

Sample Input

3
1 1 3 8
3 2 2 7
4 3 8 1

Sample Output

0 0 8 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
####################
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
####################
0 0 0 0 0 0 0 0 0 0
0 7 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
####################
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0


<?php
    $room = array_pad(array(),10,0);
    for($i = 0; $i < 4; $i++){
        for($j = 0; $j < 3; $j++){
            $building[$i][$j] = $room;
        }
    }
    $bar = str_repeat("#",20);

    $record_num = trim(fgets(STDIN));

    for($i = 0; $i < $record_num; $i++){
        list($b, $f, $r, $v) = explode(" ",trim(fgets(STDIN)));
        $building[--$b][--$f][--$r] += $v;
    }

    foreach($building as $key1 => $value1){
        foreach($value1 as $key2 => $value2){
            print " ".implode(" ",$value2)."\n";
        }
        if($key1 == $record_num - 1) exit;
        print $bar."\n";
    }


<?php
        define("AIDA", "####################");
        define("STEP",3);
        define("ROOM",10);
        define("BUILD",4);
        define("NINZU",9);

        $array_tmp1 = array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
        $array_tmp2 = array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
        $array_tmp3 = array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
        $array_bld1  = array( $array_tmp1, $array_tmp2, $array_tmp3 );
        $array_bld2  = array( $array_tmp1, $array_tmp2, $array_tmp3 );
        $array_bld3  = array( $array_tmp1, $array_tmp2, $array_tmp3 );
        $array_bld4  = array( $array_tmp1, $array_tmp2, $array_tmp3 );

        // 情報入力
        $inf_cnt = trim(fgets(STDIN));
        for($loop_cnt = 0; $loop_cnt < $inf_cnt; $loop_cnt++ )
        {
                $input = preg_split('/ /', trim(fgets(STDIN)));
                $b = $input[0] -1;
                $f = $input[1] -1;
                $r = $input[2] -1;
                $v = $input[3] -1;

                if( $b >= 0 and $b < BUILD and
                    $f >= 0 and $f < STEP  and
                    $r >= 0 and $r < ROOM  and
                    $v < NINZU
                )
                {
                        switch($b)
                        {
                                case 0:
                                        $ninzu = $v + $array_bld1[$f][$r];
                                        break;
                                case 1:
                                        $ninzu = $v + $array_bld2[$f][$r];
                                        break;
                                case 2:
                                        $ninzu = $v + $array_bld3[$f][$r];
                                        break;
                                case 3:
                                        $ninzu = $v + $array_bld4[$f][$r];
                                        break;
                                default:
                                        echo "error\n";
                                        break;
                        }

                        // 管理過程での入居者数確認
                        if( 0 <= $ninzu and
                            NINZU > $ninzu
                        )
                        {
                                switch($b)
                                {
                                        case 0:
                                                $array_bld1[$f][$r] = $ninzu;
                                                break;
                                        case 1:
                                                $array_bld2[$f][$r] = $ninzu;
                                                break;
                                        case 2:
                                                $array_bld3[$f][$r] = $ninzu;
                                                break;
                                        case 3:
                                                $array_bld4[$f][$r] = $ninzu;
                                                break;
                                        default:
                                                echo "error\n";
                                                break;
                                }
                        }
                }
        }

        // 結果出力
        for($loop_cnt1 = 0; $loop_cnt1 < BUILD; $loop_cnt1++)
        {
                for($loop_cnt2 = 0; $loop_cnt2 < STEP; $loop_cnt2++)
                {
                        for($loop_cnt3 = 0; $loop_cnt3 < ROOM; $loop_cnt3++)
                        {
                                switch($loop_cnt1)
                                {
                                        case 0:
                                                echo $array_bld1[$loop_cnt2][$loop_cnt3] , " ";
                                                break;
                                        case 1:
                                                echo $array_bld2[$loop_cnt2][$loop_cnt3] , " ";
                                                break;
                                        case 2:
                                                echo $array_bld3[$loop_cnt2][$loop_cnt3] , " ";
                                                break;
                                        case 3:
                                                echo $array_bld4[$loop_cnt2][$loop_cnt3] , " ";
                                                break;
                                        default:
                                                echo "error\n";
                                                break;
                                }
                        }
                        echo "\n";
                }
                if($loop_cnt1 != BUILD-1)
                {
                        echo AIDA;
                        echo "\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


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

fscanf(STDIN, '%d %d %d', $n, $m, $l);

for ($i = 0; $i < ($n + $m); $i++) {
    if ($i < $n) {
        $A[] = explode(' ', trim(fgets(STDIN)));
    } else {
        $B[] = explode(' ', trim(fgets(STDIN)));
    }
}

for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $l; $j++) {
        $C[$i][$j] = 0;
        for ($k = 0; $k < $m; $k++) {
            $C[$i][$j] += memoizeProduct($A, $B, $i, $j, $k);
        }
    }
    $result[] = implode(' ', $C[$i]);
}

echo implode(PHP_EOL, $result), PHP_EOL;

function memoizeProduct($A, $B, $i, $j, $k)
{
    static $memo;

    if (isset($memo[$i][$j][$k])) {
        return $memo[$i][$j][$k];
    }

    $memo[$i][$j][$k] = $A[$i][$k] * $B[$k][$j];

    return $memo[$i][$j][$k];
}

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

Matrix Multiplication

Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula:

\[
c_{ij} = \sum_{k=1}^m a_{ik}b_{kj}
\]

where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.

Input

In the first line, three integers $n$, $m$ and $l$ are given separated by space characters

In the following lines, the $n \times m$ matrix $A$ and the $m \times l$ matrix $B$ are given.

Output

Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space character between adjacent elements.

Constraints

$1 \leq n, m, l \leq 100$

$0 \leq a_{ij}, b_{ij} \leq 10000$

Sample Input

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

Sample Output

1 8 5
0 9 6
4 23 14

Note

      解説


<?php
        // Input < n,m,l
        do
        {
                $input = preg_split('/ /', trim(fgets(STDIN)));
                if(3 != count($input))
                {
                        continue;
                }

                $n = $input[0];
                $m = $input[1];
                $l = $input[2];
                if( 1 <= $n and 100 > $n and
                    1 <= $m and 100 > $m and
                    1 <= $l and 100 > $l
                )
                {
                        break;
                }
        }while(1);

        // Input < A(n*m)
        $arrayA = array();
        for($loop_n = 0; $loop_n < $n;  $loop_n++)
        {
                $input = preg_split('/ /', trim(fgets(STDIN)));
                if($m == count($input))
                {
                        $arrayA[] = $input;
                }
                else
                {
                        $loop_n--;
                }
        }

        // Input < B(m*l)
        $arrayB = array();
        for($loop_m = 0; $loop_m < $m;  $loop_m++)
        {
                $input = preg_split('/ /', trim(fgets(STDIN)));
                if($l == count($input))
                {
                        $arrayB[] = $input;
                }
                else
                {
                        $loop_m--;
                }
        }

        // Output < C(n*l)
        for($i = 0; $i < $n; $i++)
        {
                $ans = array();
                for($j = 0; $j < $l; $j++)
                {
                        $c = 0;
                        for($k = 0; $k < $m; $k++)
                        {
                                $c = $c + $arrayA[$i][$k] * $arrayB[$k][$j];
                        }
                        $ans[] = $c;
                }
                echo implode(' ' , $ans) . "\n";
        }
?>


Toggling Cases

Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.

Input

A string is given in a line.

Output

Print the converted string in a line. Note that you do not need to convert any characters other than alphabetical letters.

Constraints

The length of the input string < 1200

Sample Input

fAIR, LATER, OCCASIONALLY CLOUDY.

Sample Output

Fair, later, occasionally cloudy.


<?php

$chars = str_split(file_get_contents('php://stdin'));

$alphabet = array_fill_keys(range('a', 'z'), 0);
foreach ($chars as $c) {
    if (! ctype_alpha($c)) { continue; }

    $alphabet[strtolower($c)]++;
}

foreach ($alphabet as $char => $count) {
    printf('%s : %d%s', $char, $count, PHP_EOL);
}

Counting Characters

Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.

Input

A sentence in English is given in several lines.

Output

Prints the number of alphabetical letters in the following format:

a : The number of 'a'
b : The number of 'b'
c : The number of 'c'
.
.
z : The number of 'z'

Constraints

The number of characters in the sentence < 1200

Sample Input

This is a pen.

Sample Output

a : 1
b : 0
c : 0
d : 0
e : 1
f : 0
g : 0
h : 1
i : 2
j : 0
k : 0
l : 0
m : 0
n : 1
o : 0
p : 1
q : 0
r : 0
s : 2
t : 1
u : 0
v : 0
w : 0
x : 0
y : 0
z : 0


<?php

$input = file_get_contents('php://stdin');

$alphabet = array_fill_keys(range('a', 'z'), 0);
foreach (str_split($input) as $c) {
    if (! ctype_alpha($c)) { continue; }

    $alphabet[strtolower($c)]++;
}

foreach ($alphabet as $char => $count) {
    printf('%s : %d%s', $char, $count, PHP_EOL);
}


<?php

$str = file_get_contents('php://stdin');

$alphabet = array_fill_keys(range('a', 'z'), 0);
foreach (str_split($str) as $c) {
    if (! ctype_alpha($c)) { continue; }

    $alphabet[strtolower($c)]++;
}

foreach ($alphabet as $char => $count) {
    printf('%s : %d%s', $char, $count, PHP_EOL);
}


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
$p = trim(fgets(STDIN));
$s = trim(fgets(STDIN));

$p = $p.$p;
$lp = strlen($p);
$ls = strlen($s);

for ($i = 0;$i < $lp-$ls;$i++) {
    $tmp = substr($p, $i, $ls);
    if ($tmp == $s) {
        echo 'Yes'.PHP_EOL;
        return;
    }
}

echo 'No'.PHP_EOL;


<?php
$str = rtrim(fgets(STDIN));
$chk = rtrim(fgets(STDIN));
$str = $str . $str;

if (strpos($str, $chk) !== false) {
    echo 'Yes';
} else {
    echo 'No';
}


<?php
$S = trim(fgets(STDIN));
$P = trim(fgets(STDIN));
$S1 = $S;
$S2 = "";
$P1 = $P;
$i = 1;
    $S2 = $S1.$S1;
    if(strpos($S2, "$P1") !== false){
        echo "YES";
}else{
   echo "NO";
}
?>


<?PHP
$s = trim(fgets(STDIN));
$connect_s = $s . $s;
$p = trim(fgets(STDIN));
$result = false !== strpos($connect_s, $p) ? 'Yes' : 'No';
echo $result. PHP_EOL;


<?php

fscanf(STDIN, '%s', $W);

$W = strtolower($W);
$T = array();
$cnt = 0;

while (($line = trim(fgets(STDIN))) !== '') {
    if ($line === 'END_OF_TEXT') {
        break;
    }

    $line = strtolower($line);
    foreach (explode(' ', $line) as $T) {
        if ($W === $T) {
            $cnt++;
        }
    }
}

echo $cnt, PHP_EOL;

Finding a Word

Write a program which reads a word W and a text T, and prints the number of word W which appears in text T

T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.

Constraints

The length of W ≤ 10

W consists of lower case letters

The length of T in a line ≤ 1000

Input

In the first line, the word W is given. In the following lines, the text T is given separated by space characters and newlines.

"END_OF_TEXT" indicates the end of the text.

Output

Print the number of W in the text.

Sample Input

computer
Nurtures computer scientists and highly-skilled computer engineers
who will create and exploit "knowledge" for the new era.
Provides an outstanding computer environment.
END_OF_TEXT

Sample Output

3


<?php
  $str = trim(fgets(STDIN));
  $result = "";
  while (true) {
    $ary = trim(fgets(STDIN));
    $result += (" " . $ary . " ");
    if ($ary == "END_OF_TEXT") {
      print(substr_count(strtolower($result), (' ' . strtolower($str) . ' ')));
      return;
    }
  }
?>


<?php
    $cards = str_split(trim(fgets(STDIN)));

    while($input = trim(fgets(STDIN))) {

        if(!is_numeric($input)){
            echo implode("", $cards)."\n";
            if($input == "-") exit;
            $cards = str_split($input);
            continue;
        }

        for($i = 0; $i < $input; $i++){
            array_push($cards,array_shift($cards));
        }
    }

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


<?php
$n = trim(fgets(STDIN));
$t_score = 0;
$h_score = 0;

for($i = 0; $i < $n; $i++){
    $card = explode(" ", trim(fgets(STDIN)));
    $t_card = $card[0];
    $h_card = $card[1];
    if($t_card > $h_card){
        $t_score += 3;
    }elseif ($t_card < $h_card) {
        $h_score += 3;
    }else{
        $t_score += 1;
        $h_score += 1;
    }
}
printf("%d %d%s",$t_score,$h_score,PHP_EOL);
?>

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

fscanf(STDIN, '%s', $string);
fscanf(STDIN, '%d', $n);

$chars = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);

for ($i = 0; $i < $n; $i++) {
    $line = trim(fgets(STDIN));

    $ops = preg_split('/ /', $line);

    if ('replace' === $ops[0]) {
        $chars = replace($chars, $ops[1], $ops[2], $ops[3]);
    }

    if ('reverse' === $ops[0]) {
        $chars = reverse($chars, $ops[1], $ops[2]);
    }

    if ('print' === $ops[0]) {
        print_chars($chars, $ops[1], $ops[2]);
    }
}

function replace($chars, $from, $to, $replace)
{
    if (is_array($replace)) {
        $replaces = $replace;
    }
    else {
        $replaces = preg_split('//', $replace, -1, PREG_SPLIT_NO_EMPTY);
    }

    for ($i = $from, $j =0; $i <= $to; $i++, $j++) {
        $chars[$i] = $replaces[$j];
    }

    return $chars;
}

function reverse($chars, $from, $to)
{
    $reverse_chars = array();
    for ($i = $from; $i <= $to; $i++) {
        $reverse_chars[] = $chars[$i];
    }
    $reverse_chars = reverse_all($reverse_chars);

    return replace($chars, $from, $to, $reverse_chars);
}

function reverse_all($chars)
{
    $reversed = array();

    for ($i = count($chars) - 1; $i >= 0; $i--) {
        $reversed[] = $chars[$i];
    }

    return $reversed;
}

function print_chars($chars, $from, $to)
{
    for ($i = $from; $i <= $to; $i++) {
        echo $chars[$i];
    }
    echo "\n";
}

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
	$str = trim( fgets( STDIN ) );
	$n = trim( fgets( STDIN ) );
	while( $n-- ) {
		$cmds = explode( " ", trim( fgets(STDIN) ) );
		$s = $cmds[1];
		$e = $cmds[2];
		$len = $e-$s+1;
		if( "print" == $cmds[0] ) {
			print substr( $str, $s, $len ).PHP_EOL;
		} else if( "reverse" == $cmds[0] ) {
			$str = substr( $str, 0, $s ).strrev( substr( $str, $s, $len ) ).substr( $str, $e+1 );
		} else if( "replace" == $cmds[0] ) {
			$str = substr( $str, 0, $s ).$cmds[3].substr( $str, $e+1 );
		}
	}
	return;
?>


Score : 100 points

Problem Statement

You are given an integer K.
Print the string obtained by repeating the string ACL K times and concatenating them.

For example, if K = 3, print ACLACLACL.

Constraints

1 \leq K \leq 5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the string obtained by repeating the string ACL K times and concatenating them.

Sample Input 1

3

Sample Output 1

ACLACLACL


<?php
fscanf(STDIN, "%d", $N);
$zorome_count = 0;
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d", $a, $b);
    if ($a == $b) {
        $zorome_count++;
    } else {
        $zorome_count = 0;
    }
    if ($zorome_count == 3) {
        echo "Yes\n";
        exit;
    }
}
echo "No\n";

Score : 200 points

Problem Statement

Tak performed the following action N times: rolling two dice.
The result of the i-th roll is D_{i,1} and D_{i,2}.

Check if doublets occurred at least three times in a row.
Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.

Constraints

3 \leq N \leq 100

1\leq D_{i,j} \leq 6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
D_{1,1} D_{1,2}
\vdots
D_{N,1} D_{N,2}

Output

Print Yes if doublets occurred at least three times in a row. Print No otherwise.

Sample Input 1

5
1 2
6 6
4 4
3 3
3 2

Sample Output 1

Yes

From the second roll to the fourth roll, three doublets occurred in a row.

Sample Input 2

5
1 1
2 2
3 4
5 5
6 6

Sample Output 2

No

Sample Input 3

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

Sample Output 3

Yes


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
$stdin = trim(fgets(STDIN));
if($stdin == 0){
  echo 1;
}
else{
  echo 0;
}

Score : 100 points

Problem Statement

Given is an integer x that is greater than or equal to 0, and less than or equal to 1.
Output 1 if x is equal to 0, or 0 if x is equal to 1.

Constraints

0 \leq x \leq 1

x is an integer

Input

Input is given from Standard Input in the following format:

x

Output

Print 1 if x is equal to 0, or 0 if x is equal to 1.

Sample Input 1

1

Sample Output 1

0

Sample Input 2

0

Sample Output 2

1


<?php

  $n = fgets(STDIN);
  if($n==0){
    echo 1."\n";
  }else{
    echo 0."\n";
  }


<?php
//標準入力一行取得
$stdin = trim(fgets(STDIN));
if($stdin == '0'){
    echo '1';
} else {
    echo '0';
}
?>


<?php
list($a, $b, $c, $d) = array_map('intval', explode(' ', fgets(STDIN)));
printf("%d", max($a * $c, $a * $d, $b * $c, $b * $d));

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
[$n] = ints();
$mod = 10**9+7;

$none = 1;
$only0 = 0;
$only9 = 0;
$both = 0;
for($i = 0; $i < $n; $i++){
    [$none, $only0, $only9, $both] = [
        ($none * 8) % $mod,
        ($none + $only0 * 9) % $mod,
        ($none + $only9 * 9) % $mod,
        ($both * 10 + $only0 + $only9) % $mod
    ];
}
echo $both;

function str(){return trim(fgets(STDIN));}
function ints($n = false){
  if($n===false){
    return array_map('intval',explode(' ',trim(fgets(STDIN))));
  }else{$ret = [];for($i = 0; $i < $n; $i++)foreach(array_map('intval',explode(' ',trim(fgets(STDIN)))) as $j => $v)$ret[$j][] = $v;return $ret;}
}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array\n";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$M = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      if($both == 0){
        $G[$a][] = $b;
      }elseif($both == 1){
        $G[$a][] = $b;
        $G[$b][] = $a;
      }else{
        $G[$b][] = $a;
      }
    }else{
      list($a, $b, $d) = $values;
      if($both == 0){
        $G[$a][] = [$b, $d];
      }elseif($both == 1){
        $G[$a][] = [$b, $d];
        $G[$b][] = [$a, $d];
      }else{
        $G[$b][] = [$a, $d];
      }
    }
  }
  return $G;
}

Score : 300 points

Problem Statement

How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions?

0 \leq A_i \leq 9

There exists some i such that A_i=0 holds.

There exists some i such that A_i=9 holds.

The answer can be very large, so output it modulo 10^9 + 7.

Constraints

1 \leq N \leq 10^6

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer modulo 10^9 + 7.

Sample Input 1

2

Sample Output 1

2

Two sequences \{0,9\} and \{9,0\} satisfy all conditions.

Sample Input 2

1

Sample Output 2

0

Sample Input 3

869121

Sample Output 3

2511445


<?php
fscanf(STDIN, "%d %d", $N, $M);
$r = [];
$g = array_fill(1, $N, null);
$ans = 0;
$cnt = 0;
for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%d %d", $A, $B);
    $r[$A][$B] = 1;
    $r[$B][$A] = 1;
}
$memo = [];
for ($i = 1; $i <= $N; $i++) {
    if (is_null($g[$i])) {
        $cnt++;
        $g[$i] = $cnt;
    } else {
        continue;
    }
    $stack = [];
    $memo = [];
    $t = $i;
    while(true) {
        if (!isset($r[$t])) break;
        foreach ($r[$t] as $k => $dummy) {
            if (!isset($memo[$k])) {
                $memo[$k] = 1;
                $stack[] = $k;
                $g[$k] = $cnt;
            }
        }
        if ($stack) {
            $t = array_pop($stack);
        } else {
            break;
        }
    }
}
printf("%d", max(array_count_values($g)));

Score : 400 points

Problem Statement

There are N persons called Person 1 through Person N.

You are given M facts that "Person A_i and Person B_i are friends." The same fact may be given multiple times.

If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.

Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.

At least how many groups does he need to make?

Constraints

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

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

1\leq A_i,B_i\leq N

A_i \neq B_i

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
\vdots
A_M B_M

Output

Print the answer.

Sample Input 1

5 3
1 2
3 4
5 1

Sample Output 1

3

Dividing them into three groups such as \{1,3\}, \{2,4\}, and \{5\} achieves the goal.

Sample Input 2

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

Sample Output 2

4

Sample Input 3

10 4
3 1
4 1
5 9
2 6

Sample Output 3

3


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.


$stdin = trim(fgets(STDIN));
$array = explode(" ", $stdin);

$n = (int) $array[0];

$x =  (int) $array[1];

$tako = $n / $x;

$tako = ceil($tako);

$t = (int) $array[2];

$ans = $tako * $t;

echo $ans;


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

$takoyaki = 0;
while ($takoyaki < $n) {
    $count += $t;
    $takoyaki += $x;
}

echo $count . "\n";


<?php
$str = fgets(STDIN);
$strlen = strlen($str);

$sum = 0;
for($i=0;$i<$strlen; $i++){
    $sum += (int)$str[$i];
}

echo ($sum % 9 == 0)? "YES" : "NO" ;

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
// Your code here!
    $stdin = trim(fgets(STDIN));
    $flg = false;
    $count = 0;
    for($i = 0; $i < strlen($stdin); $i++) {
        if ($flg == false && $stdin[$i] == 'R') {
            $count = 1;
            $flg = true;
        } else if ($flg && $stdin[$i] == 'R') {
            $count++;
        } else {
            $flg = false;
        }
    }
    echo $count;
?>

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
$s = trim(fgets(STDIN));
$ans = 0;
$max = 0;
for ($i = 0;$i < strlen($s);++$i) {
    if($s[$i] == "R") {
        ++$max;
    } else {
        $ans = max($ans,$max);
        $max = 0;
    }
}
echo $ans.PHP_EOL;


Score : 200 points

Problem Statement

We have sticks numbered 1, \cdots, N. The length of Stick i (1 \leq i \leq N) is L_i.

In how many ways can we choose three of the sticks with different lengths that can form a triangle?

That is, find the number of triples of integers (i, j, k) (1 \leq i < j < k \leq N) that satisfy both of the following conditions:

L_i, L_j, and L_k are all different.

There exists a triangle whose sides have lengths L_i, L_j, and L_k.

Constraints

1 \leq N \leq 100

1 \leq L_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 \cdots L_N

Output

Print the number of ways to choose three of the sticks with different lengths that can form a triangle.

Sample Input 1

5
4 4 9 7 5

Sample Output 1

5

The following five triples (i, j, k) satisfy the conditions: (1, 3, 4), (1, 4, 5), (2, 3, 4), (2, 4, 5), and (3, 4, 5).

Sample Input 2

6
4 5 4 3 3 5

Sample Output 2

8

We have two sticks for each of the lengths 3, 4, and 5. To satisfy the first condition, we have to choose one from each length.

There is a triangle whose sides have lengths 3, 4, and 5, so we have 2 ^ 3 = 8 triples (i, j, k) that satisfy the conditions.

Sample Input 3

10
9 4 6 1 9 6 10 6 6 8

Sample Output 3

39

Sample Input 4

2
1 1

Sample Output 4

0

No triple (i, j, k) satisfies 1 \leq i < j < k \leq N, so we should print 0.


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

$inputs = trim(fgets(STDIN));
$inputs = array_map("intval", explode(" ", $inputs));

$comb_arr = [];
for ($i = 0; $i < $N; $i++) {
    $a = $inputs[$i];
    for ($j = 0; $j < $N; $j++) {
        $b = $inputs[$j];
        if ($a === $b) {
            continue;
        }
        for($k = 0; $k < $N; $k++) {
            $c = $inputs[$k];
            if ($b !== $c && $c !== $a) {
                if ($a+$b > $c && $b+$c > $a && $c+$a > $b) {
                    $arr = [];
                    $arr[] = $i;
                    $arr[] = $j;
                    $arr[] = $k;
                    sort($arr);
                    if (!in_array($arr, $comb_arr)) {
                        $comb_arr[] = $arr;
                    }
                }
            }
        }
    }
}

echo count($comb_arr) . "\n";


<?php
fscanf(STDIN, '%f %f %f', $start, $cnt, $length);
if ($cnt == $length) {
    $ans = $start;
} elseif ($cnt * $length == abs($start)) {
    $ans = 0;
} elseif($cnt * $length < abs($start)) {
    $ans = abs($start) - $cnt * $length;
} elseif ($cnt == 1) {
    $ans = $start - $length;
} else {
    $ans = abs($start) % $length;
    if (($cnt % 2 == 0 && $length % 2 == 0) || ($cnt % 2 != 0 && $length % 2 != 0)) {
        $ans = $length - $ans;
    }
}
echo (int)abs($ans);

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
fscanf(STDIN, '%f %f %f', $start, $cnt, $length);
if ($cnt == $length) {
    $ans = $start;
} elseif ($cnt * $length == abs($start)) {
    $ans = 0;
} elseif($cnt * $length < abs($start)) {
    $ans = abs($start) - $cnt * $length;
} elseif ($cnt == 1) {
    $ans = $start - $length;
} else {
    $ans = abs($start) % $length;
    if ($cnt % 2 == 0) {
        $ans = $length - $ans;
    }
}
echo (int)abs($ans);


<?php
[$N, $K] = fscanf(STDIN, "%d%d");
$P = [0, ...fscanf(STDIN, str_repeat("%d", $N))];
$C = [0, ...fscanf(STDIN, str_repeat("%d", $N))];
$loop = [];
$lno = 0;
$visited = array_fill(1,$N,0);
for($i=1;$i<=$N;$i++){
    if($visited[$i] === 1){
        continue;
    }
    $t = $i;
    while($visited[$t] !==1){
        $loop[$lno][] = $C[$t];
        $visited[$t] = 1;
        $t = $P[$t];
    }
    $lno++;
}
$max = PHP_INT_MIN;
foreach($loop as $value){
    $sum = array_sum($value);
    $count = count($value);
    $point = 0;
    $tmp_max = PHP_INT_MIN;
    if($sum >= 0){

        $lcount = intdiv($K, $count);
        $point = $lcount * array_sum($value);
        $zan = $K - $lcount * $count;
        $max = max($point, $max);
    }else{
        if($K >= $count){
            $zan = $count-1;
        }else{
            $zan = $K;
        }
    }

    for($i=1;$i<=$zan;$i++){
        $tmp_point = 0;
        for($j=0;$j<$count;$j++){
            if($j === 0){
                for($k = 0;$k < $i; $k++){
                    $tmp_point += $value[$k];
                }
                $tmp_max = max($tmp_point, $tmp_max);
            }else{
                if($j + $i  > $count){
                    $newj = $j + $i - $count -1;
                }else{
                    $newj = $j + $i - 1;
                }
                $tmp_point -= $value[$j-1];
                $tmp_point += $value[$newj];
                $tmp_max = max($tmp_point, $tmp_max);
            }
        }

    }
    $max = max($max,  $point + $tmp_max);

}
echo $max;

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
list($n, $k) = ints();
$p = ints();
for ($i = 0; $i < $n; ++$i) --$p[$i];
$c = ints();
$max = PHP_INT_MIN;
for ($i = 0; $i < $n; ++$i) {
    $_k = $k;
    $visited = [];
    $visited[$i] = true;
    $ss = [];
    $s = 0;
    $cur = $i;
    $d[$i] = 0;
    $cnt = 0;
    $loop = false;
    while ($cnt < $k) {
        ++$cnt;
        $cur = $p[$cur];
        $s += $c[$cur];
        if (isset($visited[$cur])) {
            $loop = true;
            $_k -= $d[$cur];
            $loop_d = $cnt - $d[$cur];
            $loop_s = $s - $ss[$cur];
            break;
        }
        $ss[$cur] = $s;
        $visited[$cur] = true;
        $d[$cur] = $cnt;
    }
    if ($loop && $loop_s > 0) {
        $_max = $ss[$cur] + intdiv($_k, $loop_d) * $loop_s;
        $_k %= $loop_d;
        $s = $_max;
        for ($j = 0; $j < $_k; ++$j) {
            $cur = $p[$cur];
            $s += $c[$cur];
            $_max = max($_max, $s);
        }
        $max = max($max, $_max);
    } else {
        $max = max($max, max($ss));
    }
}
echo $max;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Score : 500 points

Problem Statement

There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column (1 \leq j \leq C). The i-th item is at (r_i, c_i) and has the value v_i.

Takahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, j), he can move to (i + 1, j) or (i, j + 1) (but cannot move to a non-existent square).

He can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.

Find the maximum possible sum of the values of items he picks up.

Constraints

1 \leq R, C \leq 3000

1 \leq K \leq \min(2 \times 10^5, R \times C)

1 \leq r_i \leq R

1 \leq c_i \leq C

(r_i, c_i) \neq (r_j, c_j) (i \neq j)

1 \leq v_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

R C K
r_1 c_1 v_1
r_2 c_2 v_2
:
r_K c_K v_K

Output

Print the maximum possible sum of the values of items Takahashi picks up.

Sample Input 1

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

Sample Output 1

8

He has two ways to get to the goal:

Visit (1, 1), (1, 2), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 5 = 8.

Visit (1, 1), (2, 1), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 4 = 7.

Thus, the maximum possible sum of the values of items he picks up is 8.

Sample Input 2

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

Sample Output 2

29

We have four items in the 1-st row. The optimal choices are as follows:

Visit (1, 1) (1, 2), (1, 3), (1, 4), (2, 4), and (2, 5), in this order, and pick up all items except the one on (1, 2). Then, the total value of the items he picks up will be 3 + 4 + 2 + 20 = 29.

Sample Input 3

4 5 10
2 5 12
1 5 12
2 3 15
1 2 20
1 1 28
2 4 26
3 2 27
4 5 21
3 5 10
1 3 10

Sample Output 3

142


<?php
  fscanf(STDIN,"%d",$x);
  if(30<=$x) echo "Yes\n";
  else echo "No\n";

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


<?php
  $input_line = trim(fgets(STDIN));
  if ($input_line >= 30) {
    echo('OK');
  } else {
   echo('NO');
  };
?>


<?php

fscanf(STDIN, '%d %d', $N, $D);

$count = 0;

for ($i=0; $i < $N; $i++) {
    fscanf(STDIN, '%d %d', $x, $y);
    $dist = sqrt(pow($x, 2) + pow($y, 2));

    if ($dist <= $D) {
        $count++;
    }
}

echo $count;

echo PHP_EOL;

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
$num = trim(fgets(STDIN));
$seven = 7;
$count = 1;

    while(1){
        if($seven % $num == 0){
            echo $seven."\n";
            echo $count;
            break;
        }else{
            $seven = pow(10,$count) * 7 + $seven;
            $count++;

        }
    }

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
  list($n, $k) = explode(" ", trim(fgets(STDIN)));

  $a = array_map('intval', explode(" ", trim(fgets(STDIN))));

  sort($a);

  $R = $a[$n-1];
  $L = 0;

  while($R-$L>1){
    $ans = intdiv($R+$L, 2);
    //echo "RL:".$R." ".$L." ".$ans.PHP_EOL;
    $cut = 0;
    for ($i=0; $i<$n; $i++) {
      $cnt = intdiv($ans + $a[$i]-1, $ans)-1;
      if($cnt > 0){
        $cut += $cnt;
      }
    }
    //echo $cut.PHP_EOL;

    if($cut <= $k){
      $R = $ans;
    }else{
      $L = $ans;
    }

  }

  echo $R;

Score : 500 points

Problem Statement

We have N logs of lengths A_1,A_2,\cdots A_N.

We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t.

Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.

Constraints

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

0 \leq K \leq 10^9

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 \cdots A_N

Output

Print an integer representing the answer.

Sample Input 1

2 3
7 9

Sample Output 1

4

First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.

Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.

Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.

In this case, the longest length of a log will be 3.5, which is the shortest possible result. After rounding up to an integer, the output should be 4.

Sample Input 2

3 0
3 4 5

Sample Output 2

5

Sample Input 3

10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202

Sample Output 3

292638192


<?php
list($n, $k) = ints();
$a = ints();
// 全ての丸太をx未満の長さにするのに必要な回数がk以下となる時のxの最小値を求める
rsort($a);
$ok = $a[0];
$ng = 0;
while (abs($ok - $ng) > 1) {
    $mid = intdiv($ok + $ng, 2);
    $cnt = 0;

    $ok2 = 10 ** 9;
    for ($i = 0; $i < $n; ++$i) {
        $ng2 = -1;
        while (abs($ok2 - $ng2) > 1) {
            $mid2 = intdiv($ok2 + $ng2, 2);
            if ($mid2 * $mid >= $a[$i]) $ok2 = $mid2;
            else $ng2 = $mid2;
        }
        $cnt += $ok2 - 1;
    }
    if ($cnt <= $k) $ok = $mid;
    else $ng = $mid;
}
echo $ok;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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.


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

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

?>

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
list($n) = ints();
for ($i = 0; $i < $n; ++$i) {
    list($x[$i], $y[$i], $p[$i]) = ints();
    /*    if (isset($cntx[$x[$i]])) ++$cntx[$x[$i]];
    else $cntx[$x[$i]] = 1;
    if (isset($cnty[$y[$i]])) ++$cnty[$y[$i]];
    else $cnty[$y[$i]] = 1;*/
}
for ($k = 0; $k <= $n; ++$k) $ans[] = dfs($k);
echo implode(PHP_EOL, $ans);
function dfs($k = 0, $d = 0, $lxs = [true], $lys = [true])
{
    global $n, $x, $y, $cntx, $cnty;
    if (count($lxs) + count($lys) - 2 > $k) return PHP_INT_MAX;
    if ($d === $n || count($lxs) + count($lys) - 2 === $k) return calc($lxs, $lys);
    $res[] = dfs($k, $d + 1, $lxs, $lys);
    $_lxs = $lxs;
    $_lys = $lys;
    $_lxs[$x[$d]] = true;
    $_lys[$y[$d]] = true;
    $res[] = dfs($k, $d + 1, $_lxs, $lys);
    $res[] = dfs($k, $d + 1, $lxs, $_lys);
    $res[] = dfs($k, $d + 1, $_lxs, $_lys);
    return min($res);
}
function calc($lxs, $lys)
{
    global $n, $x, $y, $p;
    $res = 0;
    $lxs = array_keys($lxs);
    $lys = array_keys($lys);
    for ($i = 0; $i < $n; ++$i) {
        $dist = PHP_INT_MAX;
        foreach ($lxs as $lx)
            $dist = min($dist, abs($x[$i] - $lx));
        foreach ($lys as $ly)
            $dist = min($dist, abs($y[$i] - $ly));
        $res += $dist * $p[$i];
    }
    return $res;
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

Score: 500 points

Problem Statement

New AtCoder City has an infinite grid of streets, as follows:

At the center of the city stands a clock tower. Let (0, 0) be the coordinates of this point.

A straight street, which we will call East-West Main Street, runs east-west and passes the clock tower. It corresponds to the x-axis in the two-dimensional coordinate plane.

There are also other infinitely many streets parallel to East-West Main Street, with a distance of 1 between them. They correspond to the lines \ldots, y = -2, y = -1, y = 1, y = 2, \ldots in the two-dimensional coordinate plane.

A straight street, which we will call North-South Main Street, runs north-south and passes the clock tower. It corresponds to the y-axis in the two-dimensional coordinate plane.

There are also other infinitely many streets parallel to North-South Main Street, with a distance of 1 between them. They correspond to the lines \ldots, x = -2, x = -1, x = 1, x = 2, \ldots in the two-dimensional coordinate plane.

There are N residential areas in New AtCoder City. The i-th area is located at the intersection with the coordinates (X_i, Y_i) and has a population of P_i. Each citizen in the city lives in one of these areas.

The city currently has only two railroads, stretching infinitely, one along East-West Main Street and the other along North-South Main Street.

M-kun, the mayor, thinks that they are not enough for the commuters, so he decides to choose K streets and build a railroad stretching infinitely along each of those streets.

Let the walking distance of each citizen be the distance from his/her residential area to the nearest railroad.

M-kun wants to build railroads so that the sum of the walking distances of all citizens, S, is minimized.

For each K = 0, 1, 2, \dots, N, what is the minimum possible value of S after building railroads?

Constraints

1 \leq N \leq 15

-10 \ 000 \leq X_i \leq 10 \ 000

-10 \ 000 \leq Y_i \leq 10 \ 000

1 \leq P_i \leq 1 \ 000 \ 000

The locations of the N residential areas, (X_i, Y_i), are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 Y_1 P_1
X_2 Y_2 P_2
: : :
X_N Y_N P_N

Output

Print the answer in N+1 lines.

The i-th line (i = 1, \ldots, N+1) should contain the minimum possible value of S after building railroads for the case K = i-1.

Sample Input 1

3
1 2 300
3 3 600
1 4 800

Sample Output 1

2900
900
0
0

When K = 0, the residents of Area 1, 2, and 3 have to walk the distances of 1, 3, and 1, respectively, to reach a railroad.

Thus, the sum of the walking distances of all citizens, S, is 1 \times 300 + 3 \times 600 + 1 \times 800 = 2900.

When K = 1, if we build a railroad along the street corresponding to the line y = 4 in the coordinate plane, the walking distances of the citizens of Area 1, 2, and 3 become 1, 1, and 0, respectively.

Then, S = 1 \times 300 + 1 \times 600 + 0 \times 800 = 900.

We have many other options for where we build the railroad, but none of them makes S less than 900.

When K = 2, if we build a railroad along the street corresponding to the lines x = 1 and x = 3 in the coordinate plane, all citizens can reach a railroad with the walking distance of 0, so S = 0. We can also have S = 0 when K = 3.

The figure below shows the optimal way to build railroads for the cases K = 0, 1, 2.

The street painted blue represents the roads along which we build railroads.

Sample Input 2

5
3 5 400
5 3 700
5 5 1000
5 7 700
7 5 400

Sample Output 2

13800
1600
0
0
0
0

The figure below shows the optimal way to build railroads for the cases K = 1, 2.

Sample Input 3

6
2 5 1000
5 2 1100
5 5 1700
-2 -5 900
-5 -2 600
-5 -5 2200

Sample Output 3

26700
13900
3200
1200
0
0
0

The figure below shows the optimal way to build railroads for the case K = 3.

Sample Input 4

8
2 2 286017
3 1 262355
2 -2 213815
1 -3 224435
-2 -2 136860
-3 -1 239338
-2 2 217647
-1 3 141903

Sample Output 4

2576709
1569381
868031
605676
366338
141903
0
0
0

The figure below shows the optimal way to build railroads for the case K = 4.


<?php
fscanf(STDIN, "%d %d %d", $a, $b, $c);
$count = 0;
for ($i=1;$i<=$b;$i++) {
    $number = $i * $c;
    if ($a<=$number && $number<=$b){
        $count++;
    }
}
echo $count;
?>

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
fscanf(STDIN, "%d", $n);
$a = explode(" ", fgets(STDIN));

$counts = [];
foreach ($a as $index => $point) {
    if (!($index % 2 == 0)) {
        if (!($point % 2 == 0)) {
            array_push($counts, $point);
        }
    }
}
echo count($counts);

Score : 200 points

Problem Statement

We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i.

How many squares i satisfy both of the following conditions?

The assigned number, i, is odd.

The written integer is odd.

Constraints

All values in input are integers.

1 \leq N, a_i \leq 100

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \cdots a_N

Output

Print the number of squares that satisfy both of the conditions.

Sample Input 1

5
1 3 4 5 7

Sample Output 1

2

Two squares, Square 1 and 5, satisfy both of the conditions.

For Square 2 and 4, the assigned numbers are not odd.

For Square 3, the written integer is not odd.

Sample Input 2

15
13 76 46 15 50 98 93 77 31 43 84 90 6 24 14

Sample Output 2

3


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
$D = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($N,$M,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
$c = array_map('intval',explode(" ",trim(fgets(STDIN))));
for($i=0;$i<$D;$i++) {
  $s[]=array_map('intval',explode(" ",trim(fgets(STDIN))));
}
for($i=0;$i<$D;$i++) {
  $t[]=(int)trim(fgets(STDIN));
  printf("%d\n",compute_score($t));
}

function compute_score($out) {
  global $D,$s,$c;
  $last = array_fill(0,26,0);
  $outcnt = count($out);

  for($d=0;$d<$outcnt;$d++) {
    $last[$out[$d]-1]=$d+1;
    for($i=0;$i<26;$i++) {
      $score -= ($d + 1 - $last[$i]) * $c[$i];
    }
    $score += $s[$d][$out[$d]-1];
  }
  return $score;
}

(Please read problem A first. The maximum score you can get by solving this problem B is 1, which will have almost no effect on your ranking.)

Beginner's Guide

Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.

Problem Statement

You will be given a contest schedule for D days.
For each d=1,2,\ldots,D, calculate the satisfaction at the end of day d.

Input

Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.

D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}
t_1
t_2
\vdots
t_D

The constraints and generation methods for the input part are the same as those for Problem A.

For each d, t_d is an integer satisfying 1\leq t_d \leq 26, and your program is expected to work correctly for any value that meets the constraints.

Output

Let v_d be the satisfaction at the end of day d.
Print D integers v_d to Standard Output in the following format:

v_1
v_2
\vdots
v_D

Sample Input 1

5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13

Sample Output 1

18398
35037
51140
65837
79325

Note that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case.

Next Step

We can build a solution (schedule) for this problem in the order of day 1, day 2, and so on. And for every partial solution we have built, we can calculate the goodness (satisfaction) by using the above score calculator. So we can construct the following algorithm: for each d=1,2,\ldots,D, we select the contest type that maximizes the satisfaction at the end of day d. You may have already encountered this kind of "greedy algorithms" in algorithm contests such as ABC. Greedy algorithms can guarantee the optimality for several problems, but unfortunately, it doesn't ensure optimality for this problem. However, even if it does not ensure optimality, we can still obtain a reasonable solution in many cases. Let's go back to Problem A and implement the greedy algorithm by utilizing the score calculator you just implemented!

Greedy methods can be applied to a variety of problems, are easy to implement, and often run relatively fast compared to other methods. Greedy is often the most powerful method when we need to process huge inputs.
We can further improve the score by changing the greedy selection criteria (evaluation function), keeping multiple candidates instead of focusing on one best partial solution (beam search), or using the output of greedy algorithms as an initial solution of other methods.
For more information, please refer to the editorial that will be published after the contest.


$a=fgets(STDIN);

$result=$a+$a**2+$a**3;
echo $result;

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

    $char = fgets(STDIN);
    if(ctype_upper($char)){
        echo 'A';
    }else{
        echo '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
// Your code here!
    $char = trim(fgets(STDIN));

    if(ctype_upper($char)){
        echo "A\n";
    }else{
        echo "a\n";
    }
?>


<?php
    list($N, $K) = explode(' ', trim(fgets(STDIN)));
    $fruits = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $total = 0;

    sort($fruits, SORT_NUMERIC);

    for($i = 0; $i < $K; $i++){
        $total += $fruits[$i];
    }
    echo $total;
?>

Score : 200 points

Problem Statement

A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots, p_N yen per item, respectively. (Yen is the currency of Japan.)

Here, we will choose K kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.

Constraints

1 \leq K \leq N \leq 1000

1 \leq p_i \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 p_2 \ldots p_N

Output

Print an integer representing the minimum possible total price of fruits.

Sample Input 1

5 3
50 100 80 120 80

Sample Output 1

210

This shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen, and 80 yen, respectively.

The minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen when choosing Fruit 1, 3, and 5.

Sample Input 2

1 1
1000

Sample Output 2

1000


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

sort($fruits);

$sum = 0;
for($i=0; $i<$k; $i++){
    $sum += $fruits[$i];
}
echo $sum;


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)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))));
$Q = (int)trim(fgets(STDIN));
$sum = array_sum($A);
$cv = array_count_values($A);
for($i=0;$i<$Q;$i++) {
  list($B,$C) = array_map('intval',explode(" ",trim(fgets(STDIN))));
  //$C-$B * $cv[$B]増えるはず
  $cv[$C]+=$cv[$B];
  $sum+=($C-$B)*$cv[$B];
  printf("%d\n",$sum);
  $cv[$B]=0;
}

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

for($i=0;$i<$N;$i++) {
  $x = 0;
  for($j=0;$j<$N;$j++) {
    if ($j==$i) continue;
    //自分以外とxor;
    $x = $x ^ $A[$j];
  }
  $res[]=$x;
}
printf("%s\n",implode(" ",$res));

Score : 500 points

Problem Statement

There are N Snuke Cats numbered 1, 2, \ldots, N, where N is even.

Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.

Recently, they learned the operation called xor (exclusive OR).

What is xor?

For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:

When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3~\textrm{xor}~5 = 6.

They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.

We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i.
Using this information, restore the integer written on the scarf of each Snuke Cat.

Constraints

All values in input are integers.

2 \leq N \leq 200000

N is even.

0 \leq a_i \leq 10^9

There exists a combination of integers on the scarfs that is consistent with the given information.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_N

Output

Print a line containing N integers separated with space.

The i-th of the integers from the left should represent the integer written on the scarf of Snuke Cat i.

If there are multiple possible solutions, you may print any of them.

Sample Input 1

4
20 11 9 24

Sample Output 1

26 5 7 22

5~\textrm{xor}~7~\textrm{xor}~22 = 20

26~\textrm{xor}~7~\textrm{xor}~22 = 11

26~\textrm{xor}~5~\textrm{xor}~22 = 9

26~\textrm{xor}~5~\textrm{xor}~7 = 24

Thus, this output is consistent with the given information.


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

foreach($value as $index => $array) {
    if($value === 0) {
        echo $index+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


<?php

$X = array_map('intval', explode(' ', trim(fgets(STDIN))));

for ($i = 0; $i < 5; ++$i) {
    if ($X[$i] == 0) {
        echo $i + 1, PHP_EOL;
    }
}


<?php
   list($X,$Y) = array_map('intval',explode(" ",trim(fgets(STDIN))));
$ashi=0;
for($a=0;$a<=$X;$a++){
  if($a*2+4*($X-$a)==$Y){
    echo "Yes"exit;
  }
}
echo "No";

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
$stdin = file_get_contents('php://stdin');
$stdin = explode("\n", trim($stdin));
list($x, $n) = explode(' ', $stdin[0]);
$p = explode(' ', $stdin[1]);
$max = max($p);
$max = max($x, $max) + 1;
$min = NULL;
$ans = NULL;

for ($i = 1; $i <= $max; $i++) {
  if (in_array($i, $p)) {
    continue;
  }
  $abs = abs($i - $x);
  if ($min === NULL || $min > $abs) {
    $min = $abs;
    $ans = $i;
  }
}
echo $ans;

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
  fscanf(STDIN, "%d %d", $x, $n);

  if ($n == 0) {
    echo $x;
    return;
  }

  $nums = explode(' ', str_replace("\n", '', fgets(STDIN)));
  $ans;

  $i = 0;
  while (1) {
    if (array_search($x - $i, $nums) === false) {
      $ans = $x - $i;
      break;
    } else if (array_search($x + $i, $nums) === false) {
      $ans = $x + $i;
      break;
    } else {
      $i++;
    }
  }

  echo $ans;


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

foreach($p as $v) {
  $key[$v]=1;
}

for($i=0;$i<200;$i++) {
  if (!isset($key[$X-$i])) {
    printf("%d\n",$X-$i);
    exit;
  }
  if (!isset($key[$X+$i])) {
    printf("%d\n",$X+$i);
    exit;
  }
}