<?php
define("MOD", 10**9+7);
fscanf(STDIN, "%d%d", $N, $M);

$rootM = $M**0.5;
for($j = 2; $j <= $M+0.01; $j++){
    if($M%$j == 0){
        @$map[$j]++;
        $M/=$j;
        $rootM = $M**0.5;
        $j--;
    }
}
//@$map[$M]++;
$product = 1;
foreach($map as $prime => $count){
    $product *= nCm($count + $N - 1, $count);
    $product %= MOD;
}
printf("%d", $product);

//足し算
function addm($a, $b){
    return ($a + $b) % MOD;
}
//引き算
function subm($a, $b){
    return ($a + MOD - $b) % MOD;
}
//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}
//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}
//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}
//階乗
function factorialm($a){
    if($a == 0)return 1;
    return factorialm($a - 1) * $a % MOD;
}
//順列
function nPm($n, $m){
    if($m == 0)return 1;
    return nPm($n, $m - 1) * ($n - $m + 1) % MOD;
}
//組み合わせ
function nCm($n, $m){
    $m = min($m, $n-$m);
    return divm(nPm($n, $m), factorialm($m));
}


<?php
fscanf(STDIN,'%d%d%d',$A,$B,$C);
$array = [$A,$B,$C];
rsort($array);
echo $array[0]*10+$array[1]+$array[2];

 ?>

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

Score : 100 points

Problem Statement

You have decided to give an allowance to your child depending on the outcome of the game that he will play now.

The game is played as follows:

There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it.

The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)

Then, the amount of the allowance will be equal to the resulting value of the formula.

Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.

Constraints

All values in input are integers.

1 \leq A, B, C \leq 9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the maximum possible amount of the allowance.

Sample Input 1

1 5 2

Sample Output 1

53

The amount of the allowance will be 53 when the panels are arranged as 52+1, and this is the maximum possible amount.

Sample Input 2

9 9 9

Sample Output 2

108

Sample Input 3

6 6 7

Sample Output 3

82

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%d%d',$A,$B,$C);
$array = [$A,$B,$C];
$array_sorted = asort($array);
echo $array_sorted[0]*10+$array_sorted[1]+$array_sorted[2];

 ?>


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

echo $nums[0] * 10 + $nums[1] + $nums[2];


<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function arrayIn(){
		$buf = explode(" ", fgets(STDIN));
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->arrayIn();

		$ans = array();

		$a = $s[0];
		$b = $s[1];
		$c = $s[2];

		$ans[] = ( ( $b * 10 ) + $c ) + $a;
		$ans[] = ( ( $c * 10 ) + $b ) + $a;
		$ans[] = ( ( $a * 10 ) + $b ) + $c;
		$ans[] = ( ( $b * 10 ) + $a ) + $c;
		$ans[] = ( ( $a * 10 ) + $c ) + $b;
		$ans[] = ( ( $c * 10 ) + $a ) + $b;

		rsort($ans);

		echo $ans[0] . "\n";
	}
}
?>


<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function arrayIn(){
		$buf = explode(" ", fgets(STDIN));
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->arrayIn();

		$ans = array();

		$a = $s[0];
		$b = $s[1];
		$c = $s[2];

		$ans[] = $a + ( ( $b * 10 ) + $c );
		$ans[] = ( ( $a * 10 ) + $b ) + $c;

		rsort($ans);

		echo $ans[0] . "\n";
	}
}
?>


<?php
list($a,$b,$c) = explode(" ",trim(fgets(STDIN)));
$m = max($a,$b,$c);
echo $m*9+$a+$b+$c;


<?php
  list($n, $m, $x, $y) = explode(" ", trim(fgets(STDIN)));

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

  rsort($xa);
  sort($ya);

  if($xa[0] < $ya[0] && $ya[0] > $x && $xa[0] < $y){
    echo "No War";
  }else{
    echo "War";
  }

Score : 200 points

Problem Statement

Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.

The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.

One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.

If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.

X < Z \leq Y

x_1, x_2, ..., x_N < Z

y_1, y_2, ..., y_M \geq Z

Determine if war will break out.

Constraints

All values in input are integers.

1 \leq N, M \leq 100

-100 \leq X < Y \leq 100

-100 \leq x_i, y_i \leq 100

x_1, x_2, ..., x_N \neq X

x_i are all different.

y_1, y_2, ..., y_M \neq Y

y_i are all different.

Input

Input is given from Standard Input in the following format:

N M X Y
x_1 x_2 ... x_N
y_1 y_2 ... y_M

Output

If war will break out, print War; otherwise, print No War.

Sample Input 1

3 2 10 20
8 15 13
16 22

Sample Output 1

No War

The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.

X = 10 < 16 \leq 20 = Y

8, 15, 13 < 16

16, 22 \geq 16

Sample Input 2

4 2 -48 -1
-20 -35 -91 -23
-22 66

Sample Output 2

War

Sample Input 3

5 3 6 8
-10 3 1 5 -100
100 6 14

Sample Output 3

War


<?php
$NMXY = fgets(STDIN);
$N = (int)explode(" ",$NMXY)[0];
$M = (int)explode(" ",$NMXY)[1];
$X = (int)explode(" ",$NMXY)[2];
$Y = (int)explode(" ",$NMXY)[3];
$xArray = array_map("intval",explode(" ",fgets(STDIN)));
$xMax = max($xArray);
$yArray = array_map("intval",explode(" ",fgets(STDIN)));
$yMin = min($yArray);
foreach (range($X+1,$Y) as $num){
    if($xMax < $num and $yMin >= $num){
        echo "No War";
        exit();
    }else{
    }
}
echo "War";
?>


<?php
$input = trim(fgets(STDIN));
list($x_num, $y_num, $x, $y) = explode(' ', $input);
$input = trim(fgets(STDIN));
$xs = explode(' ', $input);
$input = trim(fgets(STDIN));
$ys = explode(' ', $input);

foreach(range($x+1, $y-1) as $z) {
    $ok = true;
    foreach($xs as $xn) {
        if($xn >= $z) {
            $ok = false;
        }
    }
    foreach($ys as $yn) {
        if($yn < $z) {
            $ok = false;
        }
    }

    if($ok) {
        echo 'No War';
        exit;
    }
}

echo 'War';


<?php
$a = explode(' ', trim(fgets(STDIN)));
$x = explode(' ', trim(fgets(STDIN)));
$y = explode(' ', trim(fgets(STDIN)));
(count($x) === count(array_unique($x))) ? sort($x) : array();
(count($y) === count(array_unique($y))) ? sort($y) : array();
$z_a = ($a[2] !== $a[3]) ? mt_rand($a[2], $a[3]) : false;
$z = array();
if(!empty($x) && !empty($y))
{
    $z = ($x[$a[1]-1] !== $y[0]) ? mt_rand($x[$a[1]-1], $y[0]) : false;
}

if($z && $z_a)
{
    echo 'No War';
}
else
{
    echo 'War';
}


<?php
$a = explode(' ', trim(fgets(STDIN)));
$x = explode(' ', trim(fgets(STDIN)));
$y = explode(' ', trim(fgets(STDIN)));
sort($x);
sort($y);
$z_a = ($a[2] == $a[3]) ? mt_rand($a[2], $a[3]) : false;
$z = mt_rand($x[$a[1]-1], $y[0]);

if($z && $z_a)
{
    echo 'No War';
}
else
{
    echo 'War';
}


<?php

$input = trim(fgets(STDIN));
$input = explode(" ", $input);

$n = (int)$input[0];
$m = (int)$input[1];
$x = (int)$input[2];
$y = (int)$input[3];

$x_array = [];
$y_array = [];

$input = trim(fgets(STDIN));
$input = explode(" ", $input);
foreach ($input as $value) {
	$x_array[] = (int)$value;
	if (count($x_array) >= $n) {
		break;
	}
}

$input = trim(fgets(STDIN));
$input = explode(" ", $input);
foreach ($input as $value) {
	$y_array[] = (int)$value;
	if (count($y_array) >= $m) {
		break;
	}
}

rsort($x_array);
sort($y_array);

if ($x_array[0] < $y && $y_array[0] > $x && $x < $y && $x_array[0] < $y_array[0]) {
	echo 'No War';
}else{
	echo 'War';
}


<?php

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

list( , , $X, $Y) = input_and_explode();
$xn = input_and_explode();
$ym = input_and_explode();

$max_x = max($xn);
$min_y = min($ym);

$war = true;
foreach (range($X + 1, $Y) as $Z) {
    if ($max_x < $Z && $min_y >= $Z) {
        $war = false;
    }
}

echo ($war ? 'War' : 'No War') . "\n";


<?= (array_product(fscanf(STDIN,"%d %d")) & 1) ?'Yes':'No' ?>

Score : 100 points

Problem Statement

You are given integers A and B, each between 1 and 3 (inclusive).

Determine if there is an integer C between 1 and 3 (inclusive) such that A \times B \times C is an odd number.

Constraints

All values in input are integers.

1 \leq A, B \leq 3

Input

Input is given from Standard Input in the following format:

A B

Output

If there is an integer C between 1 and 3 that satisfies the condition, print Yes; otherwise, print No.

Sample Input 1

3 1

Sample Output 1

Yes

Let C = 3. Then, A \times B \times C = 3 \times 1 \times 3 = 9, which is an odd number.

Sample Input 2

1 2

Sample Output 2

No

Sample Input 3

2 2

Sample Output 3

No


<?php
$AB = explode(" ", trim(fgets(STDIN)));
if($AB[0] % 2 == 1 && $AB[1] % 2 == 1){
	printf("Yes");
}else{
	printf("No");
}
?>


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

if ($a * $b % 2 === 0) {
  echo "No\n";
} else {
  echo "Yes\n";
}
?>


<?php
class In {
    private $array = [];
    private $length = 0;
    private $count = 0;

    function __construct()	{
		$str = trim(fgets(STDIN));
        $this->array = explode(' ', $str);
        $this->length = count($this->array);
    }

    public function get(int $i){
        $this->array[$i];
    }

    public function next() {
        return $this->array[$this->count++];
    }
    public function hasNext() {
        return $this->count < $this->length;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
    public function nextString() {
        return (string)$this->next();
    }
}

class Out {
    public static function line($str = "") {
        echo $str . PHP_EOL;
    }
}

$in = new In();
if($in->nextInt() * $in->nextInt() % 2 == 1){
    Out::line("Yes");
}else{
    Out::line("No");
}


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

        $multiplied = $a * $b;

        if ($multiplied % 3 !== 0) {
            echo 'No';
        } else {
            echo 'Yes';
        }


<?php
list($a,$b)=explode(" ",trim(fgets(STDIN)));
echo ($a==2||$b==2)?"No":"Yes";


<?php

//$abc = explode(" ",trim(fgets(STDIN)));
fscanf(STDIN,"%d",$n);
$count=0;

$w_li = array();
for($i=0;$i<$n;$i++){
	$w_li[] = trim(fgets(STDIN));
}

$last_word=$w_li[0][strlen($w_li[0])-1];

for($i=1;$i<$n;$i++){
  if($last_word!=$w_li[$i][0]){
    echo "No\n";
    exit;
  }
  $last_word=$w_li[$i][strlen($w_li[$i])-1];
}

$uni = array_unique($w_li);

if(count($uni)!=count($w_li)){
      echo "No\n";
}else{
  echo "Yes\n";
}

Score : 200 points

Problem Statement

Takahashi is practicing shiritori alone again today.

Shiritori is a game as follows:

In the first turn, a player announces any one word.

In the subsequent turns, a player announces a word that satisfies the following conditions:

That word is not announced before.

The first character of that word is the same as the last character of the last word announced.

In this game, he is practicing to announce as many words as possible in ten seconds.

You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

Constraints

N is an integer satisfying 2 \leq N \leq 100.

W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
W_1
W_2
:
W_N

Output

If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

Sample Input 1

4
hoge
english
hoge
enigma

Sample Output 1

No

As hoge is announced multiple times, the rules of shiritori was not observed.

Sample Input 2

9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly

Sample Output 2

Yes

Sample Input 3

8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa

Sample Output 3

No

Sample Input 4

3
abc
arc
agc

Sample Output 4

No


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

$W = [];
for ($i = 0; $i < $N; $i++) {
    array_push($W,trim(fgets(STDIN)));
}

# 重複チェック
# array_uniqueがどの程度の速度のものかは調べてない
# けど、処理対象のサイズがせいぜい１００件なので、多分大丈夫
if ($W !== array_unique($W)){
    die('No');
}

# 繋がってるかチェック
for ($i = 0; $i < $N-1; $i++) {
    // 繋がってるかチェック
    if (substr($W[$i], -1, 1) !== substr($W[$i+1], 0, 1)) {
        die('No');
    }
}

echo 'Yes';
?>


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

$W = [];
for ($i = 0; $i < $N; $i++) {
    array_push($W,trim(fgets(STDIN)));
}

# 重複チェック
# array_uniqueがどの程度の速度のものかは調べてない
# けど、処理対象のサイズがせいぜい１００件なので、多分大丈夫
if ($W !== array_unique($W)){
    die('No');
}

# 繋がってるかチェック
for ($i = 0; $i < $N; $i++) {
    // 繋がってるかチェック
    if (substr($W[$i - 1], -1, 1) !== substr($W[$i], 0, 1)) {
        die('No');
    }
}

echo 'Yes';
?>


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

$W = [];
for ($i = 0; $i < $N; $i++) {
    array_push($W,trim(fgets(STDIN)));
}

$said = [];
for ($i = 0; $i < $N; $i++) {
    if($i!==0){
        // もう言ったかチェック
        if(in_array ($W[$i],$said)){
            die('No');
        }
        // 繋がってるかチェック
        if (substr($W[$i - 1], -1, 1) !== substr($W[$i], 0, 1)) {
            die('No');
        }
    }
    array_push($said,$W[$i]);
}

echo 'Yes';
?>


<?php
$max = trim(fgets(STDIN));
for( $i=0; $i<$max; $i++ )
{
  $wordList[] = trim(fgets(STDIN));
}

$count = count( $wordList );
$unique = array_unique( $wordList );

if( $count != count($unique) )
{
  echo 'No';
  die;
}

$word = array_shift($wordList);
$word = str_split($word);
$before = $word[ count($word)-1 ];
foreach( $wordList as $word )
{
  $word = str_split($word);
  if( $before != $word[0] )
  {
    echo 'No';
    die;
  }

  $before = $word[ count($word)-1 ];
}

echo 'Yes';


<?php

// ABC109B
$w_array = array();
fscanf(STDIN, '%d', $n);
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, '%s', $w);
    if (in_array($w, $w_array)) {
        echo 'No';
        return;
    }
    if (!empty($w_array)) {
        if (substr($w, 0, 1) !== substr($w_array[count($w_array) - 1], -1, 1)) {
            echo 'No';
            return;
        }
    }
    $w_array[] = $w;
}

echo 'Yes';


<?php
// 整数の入力
fscanf(STDIN, "%d", $n);

$answer = true;
//単語たちの入力
$data = array();
for ($i = 0; $i < $n; $i++) {
  // 文字列の入力
  $string = fscanf(STDIN, "%s");
  foreach($data as $d) {
    if($d === $string) {
      $answer = false;
    }
  }
  $data[] = $string;
}

if ($answer) {
  $word = $data[0];
  foreach($data as $a) {
    if ($a === $word) {
      continue;
    }
    //前の単語の最後の文字と今の単語の最初の文字が合ってるか
    $last = $word[0][strlen($word[0]) - 1];
    $first = $a[0][0];
    if ($last !== $first) {
      $answer = false;
      break;
    }
    $word = $a;
  }
}

if ($answer) {
  echo "Yes\n";
} else {
  echo "No\n";
}

?>


<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d", $N);

$bool = true;

for ($i = 0; $i < $N; $i++) {
	fscanf(STDIN, "%s", $W);
	if (isset($dict[$W])) {
		$bool = false;
		break;
	} else {
		$dict[$W] = 1;
	}
	if (!isset($prev)) {
	} else {
		$first = substr($W, 0, 1);
		if ($first != $prev) {
			$bool = false;
			break;
		}
	}
	$prev = substr($W, -1);
}

echo $bool ? "Yes" : "No";


<?php

$n = (int)trim(fgets(STDIN));
$w = array();
for ($i = 0; $i < $n; $i+=1){
    $w[] =trim(fgets(STDIN));
}

$tmp = array_unique($w);

if (count($tmp) != count($w))
{
    echo "No\n";
}else{
    $tmp = $w[0];
    $flag = true;
    for ($i = 1; $i < $n; $i+=1)
    {
        if(substr($tmp, count($tmp)) != substr($w[$i], 0, 1))
        {
            $flag = false;
            break;
        }
    }

    if($flag)
        echo "Yes\n";
    else
        echo "No\n";
}
?>


<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function lineIn(){
		$buf = fgets(STDIN);
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->lineIn();

		$ans = 0;
		$buf = array();

		for($i = 0; $i < $s; $i++){
			$buf[] = $this->lineIn();
		}

		$unique = array_unique($buf);

		if(sizeof($unique) != sizeof($buf)){
			echo "No\n";
		}else{
			$t = "";
			$b = $buf[0][0];
			foreach($buf as $k => $v){
				$t = $v[0];
				if($b != $t){
					echo "No\n";
					return false;
				}
				$b = $v[(strlen($v) - 1)];
			}
			unset($k);
			unset($v);

			echo "Yes\n";
			return true;
		}
	}
}
?>


<?php
$n=trim(fgets(STDIN));
$i=0;
while($i<$n){
  $a[]=trim(fgets(STDIN));
  ++$i;
}
$b=array_count_values($a);
$c=count($b);
if($c!=$n){
  echo "No";
}else{
  $j=0;
  while($j<$n-1){
    $k=strlen($a[$j]);
    if($a[$j][$k-1]==$a[$j+1][0]){
      --$i;
    }else{
      echo "No";
      exit;
    }
    ++$j;
  }
  echo "Yes";
}


<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}
$s = getq();
$moji=array();
for($i=0;$i<$s;$i++){
	array_push($moji,getq());
}
for($i=0;$i<$s;$i++){
	for($j=0;$j<$s;$j++){
		if($i!=$j){
		if($moji[$i]==$moji[$j]){
			echo "No\n";
			exit(0);
		}
		}
	}
}
for($i=1;$i<$s;$i++){
	//echo($moji[$i][0] ."-". $moji[$i-1][strlen($moji[$i-1])-1]);
	if($moji[$i][0] != $moji[$i-1][strlen($moji[$i-1])-1]){
		echo "No\n";
		exit(0);
	}
}
echo "Yes\n";
?>


Score : 300 points

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

Move 1: travel from coordinate y to coordinate y + D.

Move 2: travel from coordinate y to coordinate y - D.

Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

Print the maximum value of D that enables you to visit all the cities.

Sample Input 1

3 3
1 7 11

Sample Output 1

2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999


<?php

function gcd($m, $n){
    if($n > $m) list($m, $n) = array($n, $m);

    while($n !== 0){
        $tmp_n = $n;
        $n = $m % $n;
        $m = $tmp_n;
    }
    return $m;
}

fscanf(STDIN,"%d%d",$n,$x);
$x_li = explode(" ",trim(fgets(STDIN)));
$x_li[] = $x;
sort($x_li);
$gcd = $x_li[1]-$x_li[0];
for($i=1;$i<count($x_li)-1;$i++){
  $dis = $x[$i+1]-$x[$i];
  $gcd = gcd($gcd,$dis);
}

echo $gcd;


<?php
  fscanf(STDIN, "%d%d", $n, $x);
  $x_li = explode(" ",trim(fgets(STDIN)));
  if($n == 1){
      echo abs($x-$x_li[0]);
      exit;
  }
  $min = (10**9)+1;
  for($i=0; $i<$n; $i++){
      $min = min(abs($x_li[$i]-$x),$min);
  }
  echo $min;


<?php
// C
fscanf(STDIN, '%d %d', $N, $X);
$x = array_map('intval', explode(' ', trim(fgets(STDIN))));
$gcd = abs($x[0] - $X);
for ($i = 0; $i < $N; $i++) {
    $gcd = gcd($gcd, abs($x[$i] - $X));
}
echo $gcd;

// 最大公約数（2つ）
function gcd($m, $n)
{
    if (!$n) return $m;
    return gcd($n, $m % $n);
}


<?php
fscanf(STDIN, "%d %d", $N, $X);
$x = array_map("intval", explode(" ", trim(fgets(STDIN))));
$x[] = $X;
rsort($x);
$x_min = min($x);
$x = array_map(function($a) use($x_min) {return $a - $x_min;}, $x);

for ($i = 1; $i <= $N; $i++) {
    if (!isset($ans)) {
        $ans = gcd($x[$i - 1], $x[$i]);
    } else {
        $ans = gcd($ans, $x[$i]);
    }
    if ($ans === 1) break;
}
echo $ans;

//最大公約数
function gcd($m, $n){
    if($n > $m) list($m, $n) = array($n, $m);

    while($n !== 0){
        $tmp_n = $n;
        $n = $m % $n;
        $m = $tmp_n;
    }
    return $m;
}


<?php
fscanf(STDIN, "%d %d", $max, $start);
$cities = trim(fgets(STDIN));
$cities = explode( " ", $cities );
rsort($cities);

if( $max == 1 )
{
  echo abs($cities[0]- $start);
  die;
}

if( $cities[0] > $start )
{ array_unshift($cities, $start); }
elseif( $cities[$max-1] < $start )
{ $cities[] = $start; }

for( $i=1; $i<$max; $i++ )
{
  if( $cities[$i-1] < $start && $start < $cities[$i] )
  {
    $distances[] = $cities[$i-1] - $start;
    $distances[] = $start - $cities[$i];
  }
  else
  { $distances[] = $cities[$i-1] - $cities[$i]; }
}

$distances = array_unique($distances);
$distances = array_values($distances);
sort($distances);

$step = $distances[0];
$count = count($distances);
$result = false;
while( !$result )
{
  $result = true;
  for( $i=0; $i<$count; $i++  )
  {
    if( $distances[$i] % $step != 0 )
    {
      break;
    }
  }

  if( $i < $count )
  {
    $result = false;
    $step = floor( $step/2 );
  }
}

echo $step;


<?php

$args = [];
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$x = (int)$input[1];

while(true){
	$input = explode(' ', trim(fgets(STDIN)));
	foreach ($input as $value) {
		if ($value !== '') {
			$args[] = (int)$value;
			++$cnt;
		}
		if (count($args) >= $n) {
			break;
		}
	}
	if (count($args) >= $n) {
		break;
	}
}

$args[] = $x;
sort($args);
$diff_array = [];
$length = count($args);
for ($i=1; $i < $length; $i++) {
	$diff_array[] = $args[$i] - $args[$i-1];
}
$diff_array = array_unique($diff_array, SORT_NUMERIC);
sort($diff_array);
$min = $diff_array[0];

for ($i=$min; $i > 0; $i--) {
	$flg = true;
	foreach ($diff_array as $value) {
		if ($value % $i !== 0) {
			$flg = false;
			break;
		}
	}
	if ($flg) {
		echo $i;
		break;
	}
}


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

  if($d == 0){
    if($n == 100) echo 101;
    else echo $n;
  }else if($d == 1){
    echo $n * 100;
  }else if($d == 2){
  	echo $n * 10000;
  }

Score: 200 points

Problem Statement

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.

As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.

Find the N-th smallest integer that would make Ringo happy.

Constraints

D is 0, 1 or 2.

N is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

D N

Output

Print the N-th smallest integer that can be divided by 100 exactly D times.

Sample Input 1

0 5

Sample Output 1

5

The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...

Thus, the 5-th smallest integer that would make Ringo happy is 5.

Sample Input 2

1 11

Sample Output 2

1100

The integers that can be divided by 100 exactly once are as follows: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1 \ 000, 1 \ 100, ...

Thus, the integer we are seeking is 1 \ 100.

Sample Input 3

2 85

Sample Output 3

850000

The integers that can be divided by 100 exactly twice are as follows: 10 \ 000, 20 \ 000, 30 \ 000, ...

Thus, the integer we are seeking is 850 \ 000.


<?php
// B
fscanf(STDIN, '%d %d', $d, $n);
echo $n * 100 ** $d;


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


<?php
  $base_num = explode(" ",fgets(STDIN));
  $ans = 0;

  if((int)$base_num[0] == 0)
  {
    if((int)$base_num[1] == 100)
    {
  		$ans = 101;
    }
    else
    {
  		$ans = (int)$base_num[1];
    }
  }
  else if((int)$base_num[0] == 1)
  {
  		$ans = (int)$base_num[1] * 100;
  }
  else
  {
  		$ans = (int)$base_num[1] * 10000;
  }
  echo $ans;


<?php
//error_reporting(0);
//$A = trim(fgets(STDIN));
list($D,$N) = explode(" ",trim(fgets(STDIN)));
//$A  = explode(" ",trim(fgets(STDIN)));
if ($N==100) $N=101;
switch($D) {
case 0:
  printf("%d\n",$N);
  break;
case 1:
  printf("%d\n",$N*100);
  break;
case 2:
  printf("%d\n",$N*10000);
  break;
}


<?php /*atcoder.php*/

$at = new Atcoder();
$at->main();
unset($at);

class Atcoder{
	private function arrayIn(){
		$buf = explode(" ", fgets(STDIN));
		return $this->killNewLine($buf);
	}
	private function killNewLine($buf = null){
		$buf = str_replace("\r\n", "", $buf);
		$buf = str_replace("\n", "", $buf);
		$buf = str_replace("\r", "", $buf);
		return $buf;
	}

	public function main(){
		$s = $this->arrayIn();

		$d = $s[0];
		$n = $s[1];

		$ans = 0;

		switch ($d){
			case (0):
			if(100 == $n){
				$ans = 101;
			}else{
				$ans = 1 * $n;
			}
			break;
			case (1):
			$ans = 100 * $n;
			break;
			case (2):
			$ans = 100 * 100 * $n;
			break;
			default:
			break;
		}
		echo $ans;
	}
}
?>


Score : 200 points

Problem Statement

You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?

Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Constraints

0 \leq A, B, C \leq 50

A + B + C \geq 1

50 \leq X \leq 20 000

A, B and C are integers.

X is a multiple of 50.

Input

Input is given from Standard Input in the following format:

A
B
C
X

Output

Print the number of ways to select coins.

Sample Input 1

2
2
2
100

Sample Output 1

2

There are two ways to satisfy the condition:

Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.

Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.

Sample Input 2

5
1
0
150

Sample Output 2

0

Note that the total must be exactly X yen.

Sample Input 3

30
40
50
6000

Sample Output 3

213


<?php
$coin_500 = trim(fgets(STDIN));
$coin_100 = trim(fgets(STDIN));
$coin_50 = trim(fgets(STDIN));
$price = trim(fgets(STDIN));
$count = 0;

for($i=0;$i<=$coin_500;$i++) {
  for($j=0;$j<=$coin_100;$j++) {
	for($k=0;$k<=$coin_50;$k++) {
      $sum = $i*500 + $j*100 + $k*50;
      if($sum == $price) {
        $count++;
      }
    }
  }
}

echo $count;


<?php
$a = fgets(STDIN);
$b = fgets(STDIN);
$c = fgets(STDIN);
$x = fgets(STDIN);

$result = 0;
for($fiveH = 0; $fiveH <= $a; $fiveH++) {
    for($hund = 0; $hund <= $b; $hund++) {
        for($fifty = 0; $fifty <= $c; $fifty++) {
            if(500 * $fiveH + 100 * $hund + 50 * $fifty == $x) {
           		$result++;
            }
        }
    }
}
echo($result);


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$x = trim(fgets(STDIN));

$count = 0;
for ($i = 0; $i <= $a; $i++) {
  for ($j = 0; $j <= $b; $j++) {
    for ($k = 0; $k <= $c; $k++) {
      $result = 0;
      $result += $i * 500;
      $result += $j * 100;
      $result += $k * 50;
      if ($result == $x) {
        $count++;
      }
    }
  }
}

echo $count;


<?php
$sc = new Scanner();

$coin_500 = $sc->nextInt();
$coin_100 = $sc->nextInt();
$coin_50 = $sc->nextInt();
$total = $sc->nextInt();

$case = 0;

$coin_total = 0;
for ($i = 0; $coin_500 >= $i; $i++) {
    for ($j = 0; $coin_100 >= $j; $j++) {
        for ($k = 0; $coin_50 >= $k; $k++) {
            $coin_total = 500 * $i + 100 * $j + 50 * $k;
            if ($coin_total === $total) {
                $case++;
            }
        }
    }
}

out::println($case);

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function println($str = "")
    {
        echo $str . PHP_EOL;
    }
}


<?php
  $five_hundred = trim(fgets(STDIN));
  $one_hundred = trim(fgets(STDIN));
  $fifty = trim(fgets(STDIN));
  $target = trim(fgets(STDIN));

  $cnt = 0;
  for($i = 0; $i <= $five_hundred; $i++){
    for($j = 0; $j <= $one_hundred; $j++){
      $k = $target - ($i * 500 + $j * 100);
      if($k >= 0 && $k / 50 <= $fifty){
        $cnt++;
      }
    }
  }
  echo $cnt;
?>


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$vallance = trim(fgets(STDIN));
$ans = 0;

for($i = 0;$i<=$a;++$i){
	for($j = 0;$j<=$b;++$j){
    	for($k = 0;$k<=$c;++$k){
        	if($i * 500 + $j * 100 + $k * 50 ==$vallance){
            	$ans++;
            }
        }
    }
}
echo $ans;


<?php
	while (!feof(STDIN))
	{
		$stdin[] = trim(fgets(STDIN));
	}
	$a = (int)$stdin[0];
	$b = (int)$stdin[1];
	$c = (int)$stdin[2];
	$x = (int)$stdin[3];

	$answer = 0;
	if (!is_ok1($a) || !is_ok1($b) || !is_ok1($c))
	{
		echo $answer;
	}

	if (!is_ok2($a+$b+$c))
	{
		echo $answer;
	}

	if (!is_ok3($x))
	{
		echo $answer;
	}

	for ($i=0; $i<=$a; $i++)
	{
		for ($j=0; $j<=$b; $j++)
		{
			for ($k=0; $k<=$c; $k++)
			{
				$total = (500*$i)+(100*$j)+(50*$k);
				if (is_ok4($x, $total))
				{
					$answer++;
				}
			}
		}
	}
	echo $answer;

	function is_ok1($num)
	{
		if ((!is_int($num)) || ($num < 0 || 50 < $num))
		{
			return false;
		}
		return true;
	}

	function is_ok2($total)
	{
		if(($total) < 0)
		{
			return false;
		}
		return true;
	}

	function is_ok3($stdin_total)
	{
		if(($stdin_total < 50) || (20000 < $stdin_total) || ($stdin_total % 50 != 0))
		{
			return false;
		}
		return true;
	}

	function is_ok4($stdin_total, $total)
	{
		if ($total != $stdin_total)
		{
			return false;
		}
		return true;
	}
?>


<?php
$a = (int)trim(fgets(STDIN));
$b = (int)trim(fgets(STDIN));
$c = (int)trim(fgets(STDIN));
$x = (int)trim(fgets(STDIN));
$ans = 0;
for($tmp = 0; $tmp <= $a; $tmp++){
    for($tmp2 = 0; $tmp2 <= $b; $tmp2++){
        for($tmp3 = 0; $tmp3 <= $c; $tmp3++){
            if (500*$tmp+100*$tmp2+50*$tmp3 == $x){
                $ans++;
            }
        }
    }
}
echo ($ans)."\n";
?>


<?php
# 整数の入力
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%d", $b);
fscanf(STDIN, "%d", $c);
fscanf(STDIN, "%d", $x);

#定義
$counta = 0;
$countb = 0;
$countc = 0;
$ans = 0;

#繰り返し処理
for ($k =0 ; $k <= $c ; $k++){
for ($j =0 ; $j <= $b ; $j++){
for ($i =0 ; $i <= $a ; $i++){
  $counta++;
  if ($counta *500 + $countb *100 + $countc *50 == $x ){
     $ans++;

 }
}
 $counta = 0;
  $countb++;
  if ($counta *500 + $countb *100 + $countc *50 == $x ){
 $ans++;

  }
}
 $counta = 0;
 $countb = 0;
 $countc++;
  if ($counta *500 + $countb *100 + $countc *50 == $x ){
 $ans++;

  }
}

echo $ans;
?>


<?php
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%d", $b);
fscanf(STDIN, "%d", $c);
fscanf(STDIN, "%d", $x);

$kotae = 0;
$a_max = min($a, floor($have/500)*500);
$b_max = min($b, floor($have/100)*100);
$c_max = min($c, floor($have/50)*50);
$cur_a = 0;
$cur_b = 0;
$cur_c = 0;
for ($cur_a = 0; $cur_a <= $a_max; $cur_a+=500) {
  for ($cur_b = 0; $cur_b <= $b_max; $cur_b+=100) {
    for ($cur_c = 0; $cur_c <= $c_max; $cur_c+=50) {
      if ($cur_a + $cur_b + $cur_c == $x){$kotae++;}
    }
  }
}
echo $kotae;
?>


<?php
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%d", $b);
fscanf(STDIN, "%d", $c);
fscanf(STDIN, "%d", $x);

$kotae = 0;
$a_max = min($a, floor($have/500)*500);
$b_max = min($b, floor($have/100)*100);
$c_max = min($c, floor($have/50)*50);
$cur_a = 0;
$cur_b = 0;
$cur_c = 0;
while(1) {
 for ($cur_a = 0; $cur_a < $a_max; $cur_a++) {
   for ($cur_b = 0; $cur_b < $b_max; $cur_b++) {
     for ($cur_c = 0; $cur_c < $c_max; $cur_c++) {
       if ($cur_a * 500 + $cur_b * 100 + $cur_c * 50 == $x){$kotae++;}
     }
   }
 }
}
echo $kotae;
?>


function test( $a, $b) {

  if ($a * $b % 2 == 0) {
}

Score : 100 points

Problem Statement

AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.

Constraints

1 ≤ a,b ≤ 10000

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

If the product is odd, print Odd; if it is even, print Even.

Sample Input 1

3 4

Sample Output 1

Even

As 3 × 4 = 12 is even, print Even.

Sample Input 2

1 21

Sample Output 2

Odd

As 1 × 21 = 21 is odd, print Odd.


// 標準入力
$input = fgets(STDIN);

$input_array = explode(" ", $input);

if(($input_array[0]*$input_array[1]) % 2 == 0){
	echo("Even");
}else{
	echo("Odd");
}


<?php
$input_line = trim(fgets(STDIN));
for ($i = 0; $i < $input_line; $i++) {
  $s = trim(fgets(STDIN));
  $s = str_replace(array("\r\n","\r","\n"), '', $s);
  $s = explode(" ", $s);
  echo "hello = ".$s[0]." , world = ".$s[1]."\n";
}
?>


<?php
# スペース区切りの整数の入力
fscanf(STDIN, "%d %d", $b, $c);
# 出力
if ($b + $c == 2){
    echo('Even');
}else{
    echo('Odd');
}
?>


<?php
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner();
$a = $sc->nextInt();
$b = $sc->nextInt();
$c = $a * $b;

if ($c % 2 == 0) {
    out::println('Even');
} else {
    out::printIn('Odd');
}


<?php
fscanf(STDIN, "%d %d", $a,$b);
if ($a % 2 == 0 || $b % 2 == 0){
  echo "Even";
} else {
  echo "Odd";
}


<?php

        $in = fgets(STDIN);
        $in_array = explode(" ", trim($in));
        $a = (int)$in_array[0];
        $b = (int)$in_array[1];
        if($a * $b % 2 == 0){
            echo "Even";
        } else {
            echo "Odd";
        }

?>


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

$c = $a * $b;

$d = $c % 2;

$result = ($d == 0) ? "Odd" : "Even";

# 出力
echo $result;
?>


fscanf(STDIN, "%d %d", $a, $b);
if(($a * $b) %2  === 0){
            echo 'Odd';
        }else{
            echo 'Even';
        }


<?php
// Your code here!
//積が奇数なら Odd と、 偶数なら Even と出力せよ。

    $input = trim(fgets(STDIN));
    $input = explode(" ",$input);
    $total = $input[0]*$input[1];

    if($total %2 == 0){
        echo "Even";
    }else{
        echo "Odd";
    }

?>


<?php

// 練習用
$nums = explode(' ',fgets(STDIN));

if (array_product($nums)%2 === 0) {
    echo 'Even';
}else{
    echo 'Odd';
};

?>


<?
fscanf(STDIN, "%d %d", $first, $second);
print($first * $second % 2 == 0 ? "Even" : "Odd");


fscanf(STDIN, "%d %d", $first, $second);
print($first * $second % 2 == 0 ? "Even" : "Odd" );


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
echo $a*$b%2===0 ? 'Even' : 'Odd';


<?php

$line = fgets(STDIN);
$tmp = explode(" ", $line);

$result = $tmp[0] . $tmp[1];

for ($i = 1; $i <= 100; $i++) {
	if ($i * $i === (int)$result) {
    	echo "Yes\n";
      	exit;
    }
}
echo "No\n";


<?php

$p = explode(" ",trim(fgets(STDIN)));
$result = $p[0] * $p[1];

if($result % 2 == 0){
    echo 'Even';}
else{
    echo "Odd";}


class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(" ", $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function printIn($str = "")
    {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner();
$a = $sc->nextInt();
$b = $sc->nextInt();
$result = $a * $b;

if($result % 2 === 0){
print 'Even';
}else {
print 'odd';
}


<?php
fscanf("%d %d",$a,$b);

if($a * $b % 2){
	echo "Odd";
}else{
	echo "Even";
}

?>


<?php
  fscanf(STDIN, "%d %d", $a, $b);
  $num = $a*$b;
  if ($num%2 == 0){
    echo "Even";
  }else{
    echo "Odd";
  }
?>


<?php
fscanf(STDIN, "%d %d", $a, $b);
$product = $a * $b;
if ($product % 2 === 0) {
	echo 'Even' . "\n";
} else {
	echo 'Odd' . "\n";
}


<?php
  fscanf(STDIN, "%d %d", $a, $b);
  if ($a*$b%2 === 0) {
  echo "Even";
  } else {
  	echo "Odd";
  }
  ?>


<?php
    list($a, $b) = explode(" ", trim(fgets(STDIN)));
    if($a * $b % 2 == 0){
        echo "Even";
    }else{
        echo "Odd";
    }
?>


<?php
#include <stdio.h>
# 整数の入力
fscanf(STDIN, "%d %d", $a, $b);
$mod2 = ($a * $b) % 2;
if($mod2 == 1){
  $result = "Odd";
} else {
  $result = "Even";
}
echo $result."\n";


$a = explode(" ", fgets(STDIN));
// echo $a;
// echo "\n";
// print_r($a);
if ($a[0] % 2 == 0 or $a[1] % 2 == 0) {
    echo "Even";
} else {
    echo "Odd";
}


fscanf(STDIN, "%d %d", $b, $c);
$a = $b*$c;
if ($a % 2 === 0) {
  echo "Even";
} else {
  echo "Odd";
}


<?php

function judgeEvenOrOdd($a, $b) {
    $c = $a * $b;

    if ($c / 2 == 0) {
        return 'Even';
    } else {
        return 'Odd';
    }
}


1 <= $a <= 10000
  1 <= $b <= 100000

function odd($a * $b)
{
    // 渡された整数が奇数かどうかを返します
    return(odd);
}

function even($a * $b)
{
    // 渡された整数が偶数かどうかを返します
    return(even);
}


<?php
    fscanf(STDIN, "%d %d", $a, $b);
    if($a * $b % 2 === 0){
      echo 'Even';
    }else{
      echo 'Odd';
    }

  ?>


$input = trim(fgets(STDIN));
$nums = explode(" ",$input);
$num = $nums[0]*$nums[1];

if ($num%2 == 0){
  echo 'Even';
} else {
  echo 'Odd';
}


function getArrayFromStdin() {
	$line = trim(fgets(STDIN));
	$line = str_replace(array("\r\n","\r","\n"), '', $line);
	$line = explode(" ", $line);
	return $line;
}

$s = getArrayFromStdin();

$result = ($s[0] * $s[1]) % 2 === 1 ? 'Odd' : 'Even';
echo $result;


<?php
$sums = fgets(STDIN);
$sum = explode(" ",$sums);
$sum1 = $sum[0] * $sum[1];
if($sum1 % 2 ==0){
  echo "Even";
}else{
  echo "Odd";
}
?>


<?php

	$sum1 = fgets(STDIN);
	$sum2 = fgets(STDIN);

	$sum = $sum1 * $sum2;

	if($sum % 2 === 0){
      echo "Even";
    }else{
      echo "Odd";
    }
?>


<?php
  fscanf(STDIN, "%d %d", $a, $b);
  $sum = $a + $b;
  if($sum % 2 === 0) {
    echo "Even\n";
  } else {
    echo "Odd\n";
  }


<?php
fscanf(STDIN, "%d %d", $a, $b);
echo ($a * $b) % 2 == 0 ? 'Even': 'Odd';


<?php
  $multiple = $a * $b;
  $text = $multiple % 2 == 0 ? 'Even' : 'Odd';
  echo $text;


<?php
  $multiple = $a * $b;
  if ($multiple % 2 == 0) {
    echo 'Even';
  } else {
    echo 'Odd';
  }


<?php
  if (($a * $b) % 2 == 0) {
    echo 'Even';
  } else {
    echo 'Odd';
  }


<?php
  $text = ($a * $b) % 1 ? 'Odd' : 'Even';
  echo $text;


<?php
  $a = 0;
  $b = 0;
  fscanf(STDIN,"%d %d",$a,$b);

  if(($a*$b)%2 == 0){
  print "Event";
  }else{
  print "Odd";
  }
  ?>


<?php
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner;
$b = $sc->nextInt();
$c = $sc->nextInt();

$d = $b * $c;
if ($d % 2 == 0) {
  out::println('Even');
} else {
  out::println('Odd');
}

?>


<?php
$input=explode(' ',trim(fgets(STDIN)));
//trim = 空白文字を取り除く
//fgets = ファイルから一行取り除く
//STDIN = input streamみたいなもので標準入力（standard input）とも言われます。
if(($input[0] * $input[1])%2 == 0){
    echo "Even";
}else{
    echo 'Odd';
}
?>


<?php
  	fscanf(STDIN, '%d %d', $x, $y);
	if($x * $y % 2 == 0){
      	echo 'Even';
    }else{
      	echo 'Odd';
    }


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

CONST EVEN='Even';
CONST ODD='Odd';

if($a % 2 ===0){
    print EVEN;
    exit;
}

if($b % 2 ===0){
    print EVEN;
    exit;
}
print ODD;
exit;


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

CONST EVEN='Even';
CONST ODD='Odd';

if($a % 2 ===0){
    return EVEN;
}

if($b % 2 ===0){
    return EVEN;
}
return ODD;


<?php
  fscanf(STDIN,'%d%d',$A,$B);
  $seki=$A*$B;
  if($seki%2==0){
  echo 'Even';

  }else{
    echo 'Odd';
  }

?>


<?php
  echo array_product(explode(' ', fgets(STDIN))) % 2 ? 'Odd' : 'Even';
?>


<?php
  $input = explode(" ",fgets(STDIN));
  $a = $input[0];
  $b = $input[1];
  if(($a*$b)%2 == 0){
    echo "Even";
  }else{
    echo "Odd";
  }


<?php
  echo array_product(explode(" ", fgets(STDIN)) % 2 ? "Odd" : "Even";
?>


<?php

fscanf(STDIN,"%d %d",$a,$b);
echo $a*$b%2==0?'Even':'Odd'.PHP_EOL;


<?php
  fscanf(STDIN, "%d %d", $a, $b);
if($a * $b % 2 == 0){
  echo "Odd";
}else{
  echo "Even";
}


<?php
list($a, $b) = explode(' ', fgets(STDIN));
echo $a * $b % 2 === 0 ? 'Even' : 'Odd';
?>


<?php

$val = explode(" ", trim(fgets(STDIN)));
$a = $val[0];
$b = $val[1];
echo ($a * $b % 2) ? "Odd" : "Even";
echo PHP_EOL;


Score : 300 points

Problem Statement

The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.

According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Constraints

1 ≤ N ≤ 2000

1000 ≤ Y ≤ 2 × 10^7

N is an integer.

Y is a multiple of 1000.

Input

Input is given from Standard Input in the following format:

N Y

Output

If the total value of N bills cannot be Y yen, print -1 -1 -1.

If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed.

Sample Input 1

9 45000

Sample Output 1

4 0 5

If the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9 5000-yen bills, so the output 0 9 0 is also correct.

Sample Input 2

20 196000

Sample Output 2

-1 -1 -1

When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000-yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.

Sample Input 3

1000 1234000

Sample Output 3

14 27 959

There are also many other possibilities.

Sample Input 4

2000 20000000

Sample Output 4

2000 0 0


<?php
// Context
class LieDetector
{
    public $algorithm = null;

    private $number_of_bills = 0;
    private $total_amount = 0;

    public function setElements()
    {
        $input = explode(" ", trim(fgets(STDIN)));
        $this->number_of_bills = $input[0];
        $this->total_amount = $input[1];
    }

    public function execLieDitect()
    {
        return $this->algorithm->lieDitect($this->number_of_bills, $this->total_amount);
    }
}

// Strategy
interface Algorithm
{
    public function lieDitect($number_of_bills, $total_amount);
}

// ConcreteStrategy
class tripleLoop implements Algorithm
{
    public function lieDitect($number_of_bills, $total_amount)
    {
        $number_of_10000_yen_bills = 0;
        $number_of_5000_yen_bills = 0;
        $number_of_1000_yen_bills = 0;

        for (
            $number_of_10000_yen_bills = $number_of_bills;
            $number_of_10000_yen_bills >= 0;
            $number_of_10000_yen_bills--
        ) {
            for (
                $number_of_5000_yen_bills = $number_of_bills - $number_of_10000_yen_bills;
                $number_of_5000_yen_bills >= 0;
                $number_of_5000_yen_bills--
            ) {
                $number_of_1000_yen_bills = $number_of_bills - ($number_of_10000_yen_bills + $number_of_5000_yen_bills);
                $sum_amount = 10000 * $number_of_10000_yen_bills + 5000 * $number_of_5000_yen_bills + 1000 * $number_of_1000_yen_bills;
                if ($sum_amount == $total_amount) {
                    return "${number_of_10000_yen_bills} ${number_of_5000_yen_bills} ${number_of_1000_yen_bills}";
                }
            }
        }
    }
}

// Main
$machine = new LieDetector();

$machine->algorithm = new tripleLoop();
$machine->setElements();
echo $machine->execLieDitect();


<?php
#include <stdio.h>
//1≤N≤2000
//1000≤Y≤2×10^7
//N は整数である。お札の枚数：N枚
//Y は1000の倍数である。合計金額：Y円
# 整数の入力
$chars = trim(fgets(STDIN));
$array = explode(" ", $chars);
$n = $array[0];
$y = $array[1];

$maxYukichiNumber = floor($y / 10000);
$isPossible = false;

for($i=0;$i<$maxYukichiNumber;$i++){
  $maxHiguchiNumber = floor(($y - $i * 10000) / 5000);
  for($j=0;$j<$maxHiguchiNumber;$j++){
    $k = $n - $i - $j;
    $sum = $i * 10000 + $j * 5000 + $k * 1000;
    if($sum == $y){
      $numbers = ["yukichi" => $i, "higuchi" => $j, "soseki" => $k];
      $isPossible = true;
      break;
    }
  }
}

if(!$isPossible){
  $numbers = ["yukichi" => -1, "higuchi" => -1, "soseki" => -1];
}

$result = $numbers["yukichi"]." ".$numbers["higuchi"]." ".$numbers["soseki"];

echo $result."\n";


<?php
#include <stdio.h>
//1≤N≤2000
//1000≤Y≤2×10^7
//N は整数である。お札の枚数：N枚
//Y は1000の倍数である。合計金額：Y円
# 整数の入力
$chars = trim(fgets(STDIN));
$array = explode(" ", $chars);
$n = $array[0];
$y = $array[1];

$numbers = array("yukichi" => 0, "higuchi" => 0, "soseki" => 0);
$maxYukichiNumber = floor($y / 10000);
$isPossible = false;

for($i=0;$i<$maxYukichiNumber;$i++){
  $maxHiguchiNumber = floor(($y - $i * 10000) / 5000);
  for($j=0;$j<$maxHiguchiNumber;$j++){
    $k = $n - $i - $j;
    $sum = $i * 10000 + $j * 5000 + $k * 1000;
    if($sum == $y){
      $numbers = ["yukichi" => $i, "higuchi" => $j, "soseki" => $k];
      $isPossible = true;
      break;
    }
  }
}

if(!$isPossible){
  $numbers = ["yukichi" => -1, "higuchi" => -1, "soseki" => -1];
}

$result = $numbers[0]." ".$numbers[1]." ".$numbers[2];

echo $result."\n";


<?php

$s = new Scanner();

$n=$s->nextInt();
$y=$s->nextInt();

for ($i=0; $i <=$n ; $i++) {
    # code...
    if (1000*$i<=$y) {
        for ($j=0; $j <= $n-$i; $j++) {
            # code...
            if ((1000*$i+5000*$j)<=$y) {
                if ($i*1000+$j*5000+($n-$i-$j)*10000==$y) {
                    out::println(($n-$i-$j).' '.$j.' '.$i);
                    return;
                }
            }
        }
    }
}
out::println('-1 -1 -1');

#文字列・数値の標準入力クラス
class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext()
    {
        return $this->pointer < $this->count;
    }
    public function nextInt()
    {
        return (int)$this->next();
    }
    public function nextDouble()
    {
        return (double)$this->next();
    }
}

#改行ありの標準出力クラス
class out
{
    public static function println($str = "")
    {
        echo $str . PHP_EOL;
    }
}


<?php

$s = new Scanner();

$n=$s->nextInt();
$y=$s->nextInt();

for ($i=0; $i <=$n ; $i++) {
    # code...
    for ($j=0; $j <= $n-$i; $j++) {
        # code...
        for ($k=0; $k <=$n-$i-$j ; $k++) {
            # code...
            if ($i+$j+$k==$n) {
                if ($i*1000+$j*5000+$k*10000==$y) {
                    out::println($k.' '.$j.' '.$i);
                    return;
                }
            }
        }
    }
}
out::println('-1 -1 -1');

#文字列・数値の標準入力クラス
class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext()
    {
        return $this->pointer < $this->count;
    }
    public function nextInt()
    {
        return (int)$this->next();
    }
    public function nextDouble()
    {
        return (double)$this->next();
    }
}

#改行ありの標準出力クラス
class out
{
    public static function println($str = "")
    {
        echo $str . PHP_EOL;
    }
}


Score : 400 points

Problem Statement

You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:

Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.

Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.

The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Constraints

1 ≤ N ≤ 10^5

1 ≤ H ≤ 10^9

1 ≤ a_i ≤ b_i ≤ 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N H
a_1 b_1
:
a_N b_N

Output

Print the minimum total number of attacks required to vanish the monster.

Sample Input 1

1 10
3 5

Sample Output 1

3

You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.

Sample Input 2

2 10
3 5
2 6

Sample Output 2

2

In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster.

Sample Input 3

4 1000000000
1 1
1 10000000
1 30000000
1 99999999

Sample Output 3

860000004

Sample Input 4

5 500
35 44
28 83
46 62
31 79
40 43

Sample Output 4

9


<?php
fscanf(STDIN, "%d%d", $N, $H);
for($i = 0; $i < $N; $i++){
    fscanf(STDIN, "%d%d", $a[], $b[]);
}
$max = max($a);
rsort($b);
$count = 0;
for($i = 0; $i < $N; $i++){
    if($b[$i]<$max)break;
    $H-=$b[$i];
    $count++;
    if($H<=0){echo $count,"\n";exit;}
}
echo $count + ceil($H/$max),"¥n";


<?php
$input = explode(' ', trim(fgets(STDIN)));
$n = (int)$input[0];
$h = (int)$input[1];

$katana = [];
$c_max = 0;
for ($i=1; $i <= $n; $i++) {
	$input = explode(' ', trim(fgets(STDIN)));
	$katana[$i] = [
		'throw' => (int)$input[1],
	];
	$c_max = max($c_max, (int)$input[0]);
}

$count = 0;
$damage = 0;
for ($j=1; $j<=$n ; $j++) {
	$tmp_k = $katana[$j];
	if ($tmp_k['throw']>$c_max) {
		$damage += $tmp_k['throw'];
		++$count;
		if ($h <= $damage) {
			break;
		}
	}
}
if ($h > $damage) {
	$count += ceil(($h-$damage) / $c_max);
}
echo $count;


<?php

fscanf(STDIN, "%d %d", $n, $h);

$a = array();
$b = array();

for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%d %d", $a[], $b[]);
}
rsort($b);
rsort($a);
$b_total = 0;
$cnt = 0;
foreach ($b as $value) {
    if ($value > $a[0]) {
        $b_total += $value;
        $cnt ++;
        if ($b_total >= $h) {
            break;
        }
    }
}

if ($b_total < $h) {
    $cnt += floor(($h - $b_total) / $a[0]);
    if (($h - $b_total) % $a[0] != 0) {
        $cnt++;
    }
}
echo $cnt;


<?php

fscanf(STDIN,"%d %d",$N,$H);

$a = [];
$b = [];

for($i=0;$i<$N;$i++){
  fscanf(STDIN,"%d %d",$a[$i],$b[$i]);
}

$count = 0;

$a_max = max($a);
$b_min = min($b);

if($a_max < $b_min){
  if(array_sum($b) > $H){
    rsort($b);
    $sum = 0;
    for($i=0;$i<count($b);$i++){
      $sum += $b[$i];
      $count ++;
      if($sum > $H){
        break;
      }
    }
  }else{
    $count = count($b) + intval(($H-array_sum($b))/$a_max);
  }
}else{
  $b_filter = array_filter($b,function($val)use($a_max){
    return $val > $a_max;
  });

  $count = count($b_filter)+intval(($H-array_sum($b_filter))/$a_max);
}
echo $count;


Score : 200 points

Problem Statement

Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Constraints

1 \leq N \leq 10^4

1 \leq A \leq B \leq 36

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Sample Input 1

20 2 5

Sample Output 1

84

Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84.

Sample Input 2

10 1 2

Sample Output 2

13

Sample Input 3

100 4 16

Sample Output 3

4554


<?php

$input = explode(" ",trim(fgets(STDIN)));
$roop = $input[0];
$min = $input[1];
$max = $input[2];
for($i=1; $i<=$roop;$i++){
     $d = str_split($i);
     $d = array_sum($d);
    if($min <= $d && $d <= $max){
        $total[] = $i;
    }
}
echo array_sum($total);


<?php
$input = array_map('intval', explode(" ", trim(fgets(STDIN))));
$N = $input[0];
$A = $input[1];
$B = $input[2];

for ($i=1; $i < $N+1; $i++) {
    for ($j=0; $j < strlen($i); $j++) {
        $num += $i%10;
    }
    if (($A<=$num)and($B>=$num)) {
        $total += $i;
    }
}
print $total;


<?php
$input = array_map('intval', explode(" ", trim(fgets(STDIN))));
$N = $input[0];
$A = $input[1];
$B = $input[2];

for ($i=1; $i < $N+1; $i++) {
    for ($j=0; $j < strlen($i); $j++) {
        $num += $i%10;
    }
    if (($A<=$num)and($B>=$num)) {
        $total += $num;
    }
}
print $total


<?php
// 1以上N以下の整数のうち、10進法での各桁の和がA以上B以下であるものの総和を出力せよ。
$nab = explode(' ', trim(fgets(STDIN)));
$n   = $nab[0];
$a   = $nab[1];
$b   = $nab[2];

$sum = 0;
for ($i = 1; $i <= $n; $i++) {
    $sum_digit = sumEachDigit($i);
    if ($sum_digit >= $a && $sum_digit <= $b) {
        $sum += $i;
    }
}

print "$sum\n";

function sumEachDigit(int $number)
{
    $sum = 0;
    while ($number !== 0) {
        $sum    += $number % 10;
        $number = intdiv($number, 10);
    }
    return $sum;
}


<?php
#include <stdio.h>
# 整数の入力
fscanf(STDIN, "%d %d %d", $n, $a, $b);
$sum = 0;

for($i=1;$i<$n+1;$i++){
  $stringI = (string)$i;
  $splitArray = [];
  $splitArray = str_split($stringI);
  $sumOfArray = array_sum($splitArray);

  if($sumOfArray >= $a){
    if($sumOfArray <= $b){
      $sum = $sum + $sumOfArray;
    }
  }
}

echo $sum."\n";


<?php
#include <stdio.h>
# 整数の入力
fscanf(STDIN, "%d %d %d", $n, $a, $b);
$sum = 0;

for($i=1;$i<$n+1;$i++){
  $splitArray = [];
  $splitArray = str_split((string)$i);

  $sumOfArray = [];
  $sumOfArray = array_sum($splitArray);

  if($sumOfArray >= $a){
    if($sumOfArray <= $b){
      $sum = $sum + $sumOfArray;
    }
  }
}

echo $sum."\n";


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

$n = $input_line[0];
$a = $input_line[1];
$b = $input_line[2];

$ans_sum = 0;

for ($i = 1; $i <= $n; $i++) {
  $sum = 0;
  $num_strlen = str_split(strval($i));
  foreach ($num_strlen as $v) {
    $sum += intval($v);
  }
  if ($sum >= $a && $sum <= $b) {
    $ans_sum += $i;
  }
}

print $ans_sum;


<?php
  	fscanf(STDIN, '%d %d %d', $end, $min, $max);

	for($i = 1; $i <= $end; $i++){
      	$num = $i;
      	$digit_sum = 0;
      	while($num > 0){
          	$digit_sum += $num % 10;
          	$num = (int) $num / 10;
        }
      	if($digit_sum >= $min && $digit_sum <= $max){
          	$result += $i;
        }
    }
	echo $result;


<?php
  $input = trim(fgets(STDIN));
  $input = str_replace(array("\r\n", "\r", "\n"), "", $input);
  $array = explode(" ", $input);

  $sum = 0;
  for( $i = 1; $i <= $array[0]; $i++){
    $input_num = str_split($i);
    $num = array_sum($input_num);

    if( $num >= $array[1] && $num <= $array[2]){
      $sum+=$i;
    }
  }

  echo $sum;
?>


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

$ans = 0;

for ($i = 1; $i <= $N; $i++) {
    $str = strval($i);
    $arr = str_split($str);
    // var_dump($arr);
    $ttl = array_sum($arr);
    // printf("%d %d\n", $i, $ttl);
    if ($ttl >= $A && $ttl <= $B) {
        // printf("%d\n", $i);
        $ans += $i;
    }
}

echo $ans . "\n";


<?php
$N = trim(fgets(STDIN));
$A = trim(fgets(STDIN));
$B = trim(fgets(STDIN));

$res = 0;

for($i = 1;$i < $N + 1;$i++){
    $sum = 0;
    for($j = 0;$j < strlen(strval($i));$j++){
        $sum += intval(strval($i)[$j]);
    }
    if($sum >= $A && $sum <= $B) $res += $i;
}

print $res;
?>


<?php
$N = trim(fgets(STDIN));
$A = trim(fgets(STDIN));
$B = trim(fgets(STDIN));

$res = 0;

for($i = 1;$i < $N + 1;$i++){
    $sum = 0;
    for($j = 0;$j < strlen(strval($i));$j++){
        $sum += intval(strval($i)[$j]);
    }
    if($sum >= $A && $sum <= $B) $res += $i;
}

echo $res;
?>


Score : 100 points

Problem Statement

Snuke has a grid consisting of three squares numbered 1, 2 and 3.
In each square, either 0 or 1 is written. The number written in Square i is s_i.

Snuke will place a marble on each square that says 1.
Find the number of squares on which Snuke will place a marble.

Constraints

Each of s_1, s_2 and s_3 is either 1 or 0.

Input

Input is given from Standard Input in the following format:

s_{1}s_{2}s_{3}

Output

Print the answer.

Sample Input 1

101

Sample Output 1

2

A marble will be placed on Square 1 and 3.

Sample Input 2

000

Sample Output 2

0

No marble will be placed on any square.


<?php

$result = 0;
$s = trim(fgets(STDIN));
$s = str_replace(array("\r\n","\r","\n"), '', $s);
$s = str_split($s);

for ($i=0; $i<3; $i++) {
    if ($s[$i] != 0) {
        $result++;
    }
}

echo $result;


<?php
$s = fgets(STDIN);
echo substr_count($s,1);
?>


<?php
	$n = fgets(STDIN);
	$a = explode(" ",fgets(STDIN));
	for($i=0;$i < $n;$i++){
    	$a[$i] = intval($a[$i]);
    }
$ans = 0;
$endflag = false;
while(true){
	for($i=0;$i < $n;$i++){
    	if($a[$i] % 2 == 0){
        	$a[$i] /= 2;
        }else{
          	$endflag = true;
        }
    }
  if($endflag)break;
  $ans++;
}

echo $ans;
?>


<?php
  $array = explode(trim(fgets(STDIN)));
  $count = array_sum($array);
  echo $count;
?>


<?php
  $n = fgets(STDIN);
  $numbers = explode(' ',fgets(STDIN));
  $a = 0;
  $continue = true;
  while ($continue) {
    foreach ($numbers as $number) {
    	if($number%2 != 0) {
        	$continue = false;
          	break;
        } else {
        	$number = $number/2;
        }
    }
  $a++;
  }
  echo $a;

  ?>


<?php
fscanf(STDIN "%d %d %d", $a, $b, $c);
$B = $a+$b+$c;
echo $B
  ?>


<?php
    $n = str_split(trim(fgets(STDIN)));
    $ans = 0;
    for($i = 0; $i < count($n); $i++){
        if($n[$i] == 1){
            $ans++;
        }
    }
    echo $ans;
?>


<?php
#include <stdio.h>
# 整数の入力
fscanf(STDIN, "%d", $a);
$array = str_split($a);
$count = 0;
for($i=0;$i<3;$i++){
 if ($array[$i] == "1"){
  $count = $count + 1;
 }
}
echo $count."\n";


<?php
#include <stdio.h>
# 整数の入力
fscanf(STDIN, "%d", $a);
$array = split($a);
$count = 0;
for($i=0;$i<3;$i++){
 if ($array[$i] == 1){
  $count = $count + 1;
 }
}
echo $count."\n";


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

$cnt = 0;

for ($i = 0; $i < 3; $i++) {
    $cnt += $input[$i];
}

echo $cnt . PHP_EOL;


<?php
  while ($line = fgets(STDIN)) {
   $array[] = trim($line);
  }
  $count = 0;
  $n = (int)$array[0];
  $figure = explode(" ", $array[1]);

  for($i = 0; $i < $n; $i++) {
   $figure[$i] = (int)$figure[$i];
  }

  while(true) {
    $flag = false;
    for($i = 0; $i < $n; $i++) {
     if($figure[$i] % 2 != 0) $flag = true;
    }

    if($flag) break;

    for($i = 0; $i < $n; $i++) {
     $figure[$i] /= 2;
    }

    $count++;
  }
  echo($count);


<?php
	$word = fgets(STDIN);
	echo substr_count($word, '1');
?>


<?php
	$boxList = expload(fgets(STDIN));
	$count = 0;

	foreach($boxList as $num){
		if($num == '1') {
			$count++;
		}
	}

	echo $count;
?>


<?php

$input = trim(fgets(STDIN));
$input = str_replace(array('\r','\r','\r'), '', $input);
$array = str_split($input);

$count = 0;
    for( $i = 0; $i < count($array); $i++) {
    if( $array[$i] == 1) {
        $count++;
    }
}
echo $count;
?>


$input = trim(fgets(STDIN));
$input = str_replace(array('\r','\r','\r'), '', $input);
$array = str_split($input);

$count = 0;
for( $i = 0; $i < count($array); $i++) {
  	if( $array[$i] == 1) {
    	$count++;
   	}
}
echo $count;


 $input = trim(fgets(STDIN));
 $array = str_split($input);

 $count = 0;
 for($i = 0; $i < count($array); $i++) {
 	if($array[$i] == 1) {
    	$count++;
    }
 }
 echo $count;


$input = trim(fgets(STDIN));
  $array = str_split($input);
  $count = 0;
  for ($i=0; $i=count($array); $i++){
    if ($array[$i] == 1) $count++;
  }
  echo $count;


  $input = trim(fgets(STDIN));
  $array = str_split($input);

  $count = 0;
  for($i = 0; $i < count($array); $i++) {
    if($array[$i] == 1) {
      $count++;
    }
  }
  echo $count;


$input = trim(fgets(STDIN));
  $array = str_split($input);
  $count = 0;
  for ($i=0; $i<3; $i++){
    if ($array[$i] == 1) $count++;
  }
  echo $count;


<?php
    fscanf(STDIN, "%s", $s);
    $array = str_split($s);
    $count = 0;
    for($i = 0; $i < count($array); $i ++){
      if($array[$i] === 1){
        $count += 1;
      }
    }
    echo $count;
  ?>


<?php
    fscanf(STDIN, "%d", $s);
    $array = str_split($s);
    $count = 0;
    for($i = 0; $i < count($array); $i ++){
      if($array[$i] === 1){
        $count += 1;
      }
    }
    echo $count;
  ?>


<?php
function getArrayFromStdin() {
	$line = trim(fgets(STDIN));
	$line = str_replace(array("\r\n","\r","\n"), '', $line);
	$line = explode(" ", $line);
	return $line;
}

$n = trim(fgets(STDIN));
$numbers = getArrayFromStdin();

$count = 0;
while(true) {
  $flg = true;
  for ($i = 0; $i < $n; $i++) {
    if ($numbers[$i] % 2) {
      $flg = false;
      break;
    } else {
      $numbers[$i] /= 2;
    }
  }

  if ($flg) {
    $count += 1;
  } else {
    break;
  }
}

echo $count;


<?php
    fscanf(STDIN, "%s", $s);
    $array = str_split($s);
    var_dump($array);
    for($i = 0; $i < 3; $i++){
        if($array[$i] === '1'){
            $answer++ ;
        }
    }
    echo $answer;
?>


<?php
fscanf(STDIN, "%s", $a);
echo substr_count($a, 1);
?>


<php?

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

$x = 0;
for ($a = 1)
  $x++;
elseif ($b = 1)
  $x++
  elseif($c = 1)
    $x++;
else
  break
end
  echo $X;

  ?>


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

$arr = str_split($a);
$result = array_keys('1',$arr);
echo count($result);


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

$arr = str_split($a);
$result = array_search('1',$arr);
echo $result;


<?php
  $nums = str_split(trim(fgets(STDIN)));
  echo array_sum($nums);


<?php
  fscanf(STDIN, '%d%d%d', $a, $b, $c);
  echo $a + $b + $c;


<?php
$sc = new Scanner();
$a = $sc->next();

$count = 0;
str_replace("1", "", $a, $count);
out::println($count);

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function println($str = "")
    {
        echo $str . PHP_EOL;
    }
}


<?php
$f = fopen( 'php://stdin', 'r' );
$line = str_replace(array("\n", "\r"), '', fgets($f));
$stringParts = str_split($line);
$out = 0;
for ($i = 0; $i < 3; $i++) {
    $out = $out + $stringParts[i];
}
echo($out);


<?php
	$array = str_split(fgets(STDIN));
	$count = array_count_values($array);
	echo $count[1] ? $count[1] : 0;
?>


<?php

  $kotae=trim(fgets(STDIN));
echo mb_substr_count($kotae, "1");
?>


#!/usr/bin/env php
<?php
function genInputs() {
    while(($input = rtrim(fgets(STDIN))) !== false) {
        foreach (explode(' ', $input) as $v) {
            yield $v;
        }
    }
}
function getNext($gen) {
    $value = $gen->current();
    $gen->next();
    return $value;
}
$gen = genInputs();

$s = getNext($gen);
$n = 0;
for ($i = 0; $i < strlen($s); $i++) {
    if ($s[$i] == 1) {
        $n++;
    }
}
echo $n.PHP_EOL;


<?php
  $N = trim(fgets(STDIN));
  $input = trim(fgets(STDIN));
  $input = str_replace(array("\r\n","\r","\n"), '', $input);
  $array = explode(" ", $input);

  $opeCnt = 0;
  $isEven = true;

  while(true){
    for( $i = 0; $i < $N; $i++) {
      if( $array[$i] % 2 == 1) {
        $isEven = false;
        break 2;
      }
    }
    if($isEven){
      for( $i = 0; $i < $N; $i++){
        $array[$i] = $array[$i] / 2;
        $opeCnt++;
      }
    }
  }
  echo $opeCnt / $N;
?>


<?php

//$_input = explode(
//    "\n",
//    '000'
//);

function getNext() {
    return trim(
        isset($GLOBALS['_input'])
            ? array_shift($GLOBALS['_input'])
            : fgets(STDIN)
    );
}

$s = getNext();
$count = count(array_filter(str_split($s), function ($x) {
    return $x === '1';
}));

printf("%d\n", $count);


<?php
  echo substr_count(fgets(STDIN), 1);
?>


<?php
fscanf(STDIN,'%s',$S);
$Sarray=str_split($S);
$judge=0;
for ($i=0; $i <=2 ; $i++) {
  // code...
  if($Sarray[$i]=='1'){
    $judge+=1;
  }
}
echo $judge;
 ?>


<?php
  echo substr_count(fget(STDIN), 1);

?>


<?php
 echo substr_count(fgets(STDIN),1);


<?php
echo substr_count(fgets(STDIN), 1);
?>


<?php
fscanf(STDIN, "%s", $s);
echo substr_count($s, '1');


<?php
  //?の部分は全部aいれればいい
  //tの大きさが連続する?より小さい場合は?、tの末尾を?の末尾と合わせ、aで埋める
  //tの方が大きい場合は、?に末尾から入る分だけ入れて、tがsの中にあるか判別
fscanf(STDIN,"%s",$s);
fscanf(STDIN,"%s",$t);
$s_len = strlen($s);
$t_len = strlen($t);
$count = 0;
$res_start = 0;
for($i=0;$i<=$s_len-$t_len;$i++){
  for($j=$i;$j<$i+$t_len;$j++){
    //echo $s[$j]." ".$t[$j-$i]."\n";
    if($s[$j]==$t[$j-$i] || $s[$j]=='?'){
      $count++;
    }
  }
  if($count == $t_len){
    $res_start = $i;
  }
  //echo "-----------\n";
  $count = 0;
}

for($i=$res_start;$i<$res_start+$t_len;$i++){
  $s[$i] = $t[$i-$res_start];
}

for($i=0;$i<$s_len;$i++){
  if($s[$i]=='?'){
    $s[$i] = 'a';
  }
}
//echo $res_start;

echo $s."\n";

Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.

One more thing he found is a sheet of paper with the following facts written on it:

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.


<?php
list($_s) = strs();
list($t) = strs();
$len_s = strlen($_s);
$len_t = strlen($t);
for ($i = $len_s - $len_t; $i >= 0; --$i) {
    $_sub = substr($_s, $i, $len_s);
    $flag = true;
    for ($j = 0; $j < $len_t; ++$j) {
        if ($_sub[$j] !== '?' && $_sub[$j] !== $t[$j]) {
            $flag = false;
            break;
        }
    }
    if ($flag) {
        $_s = substr_replace($_s, $t, $i, $len_t);
        $_s = str_replace('?', 'a', $_s);
        echo $_s;
        exit;
    }
}
echo 'UNRESTORABLE';
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


<?php
$s = trim(fgets(STDIN));
$t = trim(fgets(STDIN));

for($i = 0; $i <= strlen($s) - strlen($t); $i++){
    $flag = true;
    for($j = 0; $j < strlen($t); $j++){
        if($s[$i+$j] == $t[$j] || $s[$i+$j] == "?"){
            //ok
        }else{
            $flag = false;
        }
    }
    if($flag){
        $str = "";
        for($j = 0; $j < strlen($s); $j++){
            if($j >= $i && $j < $i + strlen($t)){
                $str.= $t[$j-$i];
            }else{
                if($s[$j] == "?"){
                    $str.= "a";
                }else{
                    $str.= $s[$j];
                }
            }
        }
        $ret[] = $str;
    }
}
if(isset($ret)){
    sort($ret);
    echo $ret[0];
}else{
    echo "UNRESTORABLE";
}


<?php

$s = trim(fgets(STDIN));
$t = trim(fgets(STDIN));

$s_len = strlen($s);
$t_len = strlen($t);

$repeat = $s_len - $t_len+1;
$flg = false;
for ($i=0; $i < $repeat ; $i++) {
	$s_end = $s_len-$i-1;
	for ($j=0; $j < $t_len ; $j++) {
		$cur_s = $s[$s_end-$j];
		$cur_t = $t[$t_len-$j-1];
		if ($cur_s !== $cur_t && ($cur_s !== '?')){
			break;
		}
		if ($j === $t_len-1) {
			$flg = true;
			for ($k=0; $k < $t_len ; $k++) {
				$s[$s_end-$k] = $t[$t_len-$k-1];
			}
		}
	}
	if ($flg) {
		break;
	}
}

if ($flg) {
	for ($i=0; $i < $s_len; $i++) {
		$tmp = $s[$i];
		if ($tmp === '?') {
			echo 'a';
		}else{
			echo $tmp;
		}
	}
}else{
	echo 'UNRESTORABLE';
}


<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%s", $T);

$arrS = str_split($S);
$arrT = str_split($T);

for ($i = count($arrS) - count($arrT); $i >= 0; $i--) {
    if (DEBUG) echo "i:{$i}\n";
    $tmpS = $arrS;
    $tmpT = $arrT;
    $flg = true;
    for ($j = 0; $j < count($arrT); $j++) {
        if (DEBUG) echo "{$i} {$j} {$arrT[$j]} {$arrS[$i + $j]}\n";
        if ($arrT[$j] == $arrS[$i + $j] || "?" == $arrS[$i + $j]) {

        } else {
            $flg = false;
        }
    }
    if (DEBUG) var_dump($flg);
    if ($flg) {
        $newStr = substr($S, 0, $i);
        $newStr .= $T;
        $newStr .= substr($S, strlen($newStr));
        $newStr = str_replace("?", "a", $newStr);
        echo $newStr . PHP_EOL;
        exit;
    } else {
    }
}
echo "X\n";
echo "UNRESTORABLE\n";


<?php
error_reporting(0);
$S = trim(fgets(STDIN));
$T = trim(fgets(STDIN));
//$A = explode(" ",trim(fgets(STDIN)));
//list($N,$M) = explode(" ",trim(fgets(STDIN)));
//a????にSが一致するか調べて一致したらそれ以外の?をaにする？
$len = strlen($T);
$newt =  str_pad($T[0],$len,"?");
$news = str_replace($newt,$T,$S);
if ($news == $S) {
  printf("UNRESTORABLE\n");
  exit;
}
printf("%s\n",str_replace("?","a",$news));


Score : 200 points

Problem Statement

You are given an H × W grid.

The squares in the grid are described by H strings, S_1,...,S_H.

The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).

. stands for an empty square, and # stands for a square containing a bomb.

Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.

(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)

He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.

Print the strings after the process.

Constraints

1 \leq H,W \leq 50

S_i is a string of length W consisting of # and ..

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the H strings after the process.

The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W).

Sample Input 1

3 5
.....
.#.#.
.....

Sample Output 1

11211
1#2#1
11211

For example, let us observe the empty square at the first row from the top and first column from the left.

There is one bomb square adjacent to this empty square: the square at the second row and second column.

Thus, the . corresponding to this empty square is replaced with 1.

Sample Input 2

3 5
#####
#####
#####

Sample Output 2

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

It is possible that there is no empty square.

Sample Input 3

6 6
#####.
#.#.##
####.#
.#..#.
#.##..
#.#...

Sample Output 3

#####3
#8#7##
####5#
4#65#2
#5##21
#4#310


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

for($i=0;$i<$H;$i++){
    $array[] = trim(fgets(STDIN));
}

$new_arr = [];

for($row=0;$row<$H;$row++){
    for($col=0;$col<$K;$col++){
        $count = 0;
        if($array[$row][$col] === "#"){
            $new_arr[$row][$col] = $array[$row][$col];
        }else{
            if(isset($array[$row-1][$col-1]) && $array[$row-1][$col-1] == "#") $count++;
            if(isset($array[$row-1][$col]) && $array[$row-1][$col] == "#") $count++;
            if(isset($array[$row-1][$col+1]) && $array[$row-1][$col+1] == "#") $count++;
            if(isset($array[$row][$col-1]) && $array[$row][$col-1] == "#") $count++;
            if(isset($array[$row][$col+1]) && $array[$row][$col+1] == "#") $count++;
            if(isset($array[$row+1][$col-1]) && $array[$row+1][$col-1] == "#") $count++;
            if(isset($array[$row+1][$col]) && $array[$row+1][$col] == "#") $count++;
            if(isset($array[$row+1][$col+1]) && $array[$row+1][$col+1] == "#") $count++;
            $new_arr[$row][$col] = $count;
        }
    }
}
print_r($new_arr);
?>


<?php
error_reporting(0);
//$A = explode(" ",trim(fgets(STDIN)));
list($H,$W) = explode(" ",trim(fgets(STDIN)));
for($i=0;$i<$H;$i++) {
  $S[]=trim(fgets(STDIN));
}
for($i=0;$i<$H;$i++) {
  for($j=0;$j<$W;$j++) {
    if ($S[$i][$j]==".") {
      //空きマスの場合は数えて置き換える
      $S[$i][$j]=countbomb($i,$j);
    }
  }
}
foreach($S as $l) {
  printf("%s\n",$l);
}
function countbomb($h,$w) {
  global $S,$H,$W;
  $cnt=0;
  $hfrom=max($h-1,0);
  $hto  =min($h+1,$H);
  $wfrom=max($w-1,0);
  $wto  =min($w+1,$W);

  //printf("%d %d %d %d %d %d\n",$h,$w,$hfrom,$hto,$wfrom,$wto);
  for($i=$hfrom;$i<=$hto;$i++) {
    for($j=$wfrom;$j<=$wto;$j++) {
      if ($S[$i][$j]=="#") $cnt++;
    }
  }
  return $cnt;
}


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

  $ans = 0;
  for ($i=0; $i<$n; $i++) {
    list($l, $r) = explode(" ", trim(fgets(STDIN)));
    $ans += ($r - $l + 1);
  }

  echo $ans;

Score : 200 points

Problem Statement

Joisino is working as a receptionist at a theater.

The theater has 100000 seats, numbered from 1 to 100000.

According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).

How many people are sitting at the theater now?

Constraints

1≤N≤1000

1≤l_i≤r_i≤100000

No seat is occupied by more than one person.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
l_1 r_1
:
l_N r_N

Output

Print the number of people sitting at the theater.

Sample Input 1

1
24 30

Sample Output 1

7

There are 7 people, sitting at Seat 24,25,26,27,28,29 and 30.

Sample Input 2

2
6 8
3 3

Sample Output 2

4


<?php
list($n) = ints();
$ans = 0;
for ($i = 0; $i < $n; ++$i) {
    list($l, $r) = ints();
    $ans += $r - $l + 1;
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


<?php
fscanf(STDIN,'%d',$N);
$count=0;
for ($i=1; $i <=$N ; $i++) {
  // code...
  fscanf(STDIN,'%d%d',$X,$Y);
  $count+=$Y-$X+1;
}
echo $count;

 ?>


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

$ans = 0;

for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d", $l, $r);
    $ans += ($r - $l) + 1;
}

echo $ans . PHP_EOL;


<?php
    fscanf(STDIN, "%d", $n);
    while (!feof(STDIN)) {
        fscanf(STDIN, "%d %d", $a, $b);
        $number[] = $b - $a + 1;
    }
    $total = array_sum($number);
    echo $total . "\n";
?>


<?php
// Try AtCoder
// author: Leonardone @ NEETSDKASU

function gets() { return trim(fgets(STDIN)); }
function geti() { return intval(gets()); }
function getVals() { return explode(' ', gets()); }
function getInts() { return array_map(intval, getVals()); }

$N = gets();

$ans = 0;

for ($i = 0; $i < $N; $i++) {
    list($li, $ri) = getInts();
    $ans += $ri - $li + 1;
}

echo $ans;


<?php
error_reporting(0);
//list($x,$t) = explode(" ",trim(fgets(STDIN)));
$N = trim(fgets(STDIN));
$ret=0;
for($i=0;$i<$N;$i++) {
  $l = explode(" ",trim(fgets(STDIN)));
  $ret += $l[1]-$l[0]+1;
}
printf("%d\n",$ret);


<?php
$alphabets = str_split('abcdefghijklmnopqrstuvwxyz');
$S         = str_split(trim(fgets(STDIN)));
sort($S);
$S = array_unique($S);

$ans = 'None';
foreach ($alphabets as $i => $alphabet) {
    if ($alphabet !== $S[$i]) {
        $ans = $alphabet;
        break;
    }
}

echo $ans;

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Constraints

1 \leq |S| \leq 10^5 (|S| is the length of string S.)

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the lexicographically smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Sample Input 1

atcoderregularcontest

Sample Output 1

b

The string atcoderregularcontest contains a, but does not contain b.

Sample Input 2

abcdefghijklmnopqrstuvwxyz

Sample Output 2

None

This string contains every lowercase English letter.

Sample Input 3

fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg

Sample Output 3

d


<?php
  $s = trim(fgets(STDIN));
  $li = [];
  for($i=0; $i<strlen($s); $i++){
    $li[$s[$i]]=1;
  }
  $moji = 'a';

  while($moji!='z'){
    if(!isset($li[$moji])){
      echo $moji."\n";
      exit;
    }
    $moji++;
  }
  echo "None\n";


<?php
	fscanf(STDIN,"%s",$s);
	$memo=array();
	for($i=0;$i<strlen($s);$i++){
      if(!in_array($s[$i],$memo)){
        $memo[] = $s[$i];
      }
    }

	sort($memo);
	//print_r($memo);
	$abc='a';
	for($i=0;$i<count($memo);$i++){
      if($abc!=$memo[$i]){
        echo $abc."\n";
        exit;
      }
         $abc++;
    }

	if(count($memo)!=26){
      echo $abc."\n";
    }else{
		echo "None\n";
    }


<?php

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

$arrayS = str_split($s);
$aToz = range('a','z');
$b = strlen($aToz);

$total = [];

for ($i = 0; $i < $b; $i++) {
    if (!in_array($aToz[$i], $arrayS)) {
        $total[] = $aToz[$i];
    }
}

if (strlen($total) == strlen($b)) {
    echo 'None';
} else {
    echo $total[0];
}


class help {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}
$input = trim(fgets(STDIN));
$alphabet = str_split('abcdefghijklmnopqrstuvwxyz');
$n = [];

var_dump($input);
for ($i=0; $i < count($alphabet); $i++) {
  if (strpos($input, $alphabet[$i]) === false) {
    $n[] = $alphabet[$i];
  }
}
sort($n);
help::println($n[0]);


<?php

class In {

	private $buf = [];
	private $count = 0;
	private $pointer = 0;

	public function nextLine() {
		$ret = '';
		if($this->hasNext()){
			while($this->hasNext()){
				$ret .= $this->next();
			}
		}else{
			$ret = trim(fgets(STDIN));
		}

		return $ret;
	}

	public function next() {
		if(!$this->hasNext()) {
			$str = trim(fgets(STDIN));
			$this->buf = explode(' ',$str);
			$this->count = count($this->buf);
			$this->pointer = 0;
		}

		return $this->buf[$this->pointer++];
	}

	public function hasNext() {
		return $this->pointer < $this->count;
	}

	public function nextInt() {
		return (int)$this->next();
	}

	public function nextDouble() {
		return (double)$this->next();
	}
}

class Out {
	public function println($str = '') {
		echo $str . PHP_EOL;
	}
}

$in = new In();
$out = new Out();

$len = ord('z') - ord('a')+1;
$appear = [];
for ($i = 0;$i < $len;$i++) {
	$appear[] = false;
}

$S = $in->next();
$S = str_split($S);
foreach ($S as $s) {
	$appear[ord($s) - ord('a')] = true;
}

for ($i = 0;$i < $len;$i++) {
	if ($appear[$i] === false) {
		$out->println(chr(ord('a')+$i));
		return;
	}
}

$out->println('None');

?>


<?php
    fscanf(STDIN, "%s", $input);
    $input = str_split($input);
    sort($input);
    array_unique($input);
    $lowercase = str_split('abcdefghijklmnopqrstuvwxyz');
    $not_found = array_diff($lowercase, $input);
    $output = implode($not_found);
    if ($output == '') { echo 'None' . "\n"; }
    else { echo $output[0] . "\n"; }
?>


<?php
$n = trim(fgets(STDIN));
$a = explode(" ", trim(fgets(STDIN)));
$q = $d = $s = 0;
foreach($a as $num){
    if($num % 4 == 0){
        $q++;
    }elseif($num % 2 == 0){
        $d++;
    }else{
        $s++;
    }
}
if($d)$s++;
echo "$s $d $q\n";
if($q + 1 >= $s){
    echo "Yes";
}else{
    echo "No";
}

Score : 400 points

Problem Statement

We have a sequence of length N, a = (a_1, a_2, ..., a_N).
Each a_i is a positive integer.

Snuke's objective is to permute the element in a so that the following condition is satisfied:

For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If Snuke can achieve his objective, print Yes; otherwise, print No.

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

It is impossible to permute a so that the condition is satisfied.

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes


<?php

$count = trim(fgets(STDIN));

$string = trim(fgets(STDIN));

$array = explode(" ", $string);

$count_odd = 0;
$count_fours = 0;

foreach ($array as $item)
{
    if ($item%2 == 1)
    {
        $count_odd++;
    }

    if ($item%4 == 0)
    {
        $count_fours++;
    }
}

if ($count_fours >= $count_odd)
{
    echo "Yes";
}
else
{
    echo "No";

}

echo "\n";
die();


<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d", $N);
$a = explode(" ", trim(fgets(STDIN)));

$odd = $even = $half = 0;

for ($i = 0; $i < $N; $i++) {
    switch ($a[$i] % 4) {
        case 1:
            $odd++;
            break;
        case 0:
            $even++;
            break;
        case 3:
            $odd++;
            break;
        case 2:
            $half++;
            break;
    }
}

if ($half == 0) {
    if ($odd <= $even + 1) {
        echo "Yes\n";
    } else {
        echo "No\n";
    }
} else {
    if ($odd <= $even) {
        echo "Yes\n";
    } else {
        echo "No\n";
    }
}


<?php

	$data = explode(" ", trim(fgets(STDIN)));
	$n = $data[0];
	$a = $data[1];
	$b = $data[2];
	if($n == 1){
	    if($a == $b) echo 1;
	    else echo 0;
	} else {
	    if($a>$b) echo 0;
	    else{
	        $n -= 2;
	        echo ($b - $a) * $n + 1;
	    }
	}

?>

Score : 200 points

Problem Statement

Snuke has N integers. Among them, the smallest is A, and the largest is B.
We are interested in the sum of those N integers. How many different possible sums there are?

Constraints

1 ≤ N,A,B ≤ 10^9

A and B are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of the different possible sums.

Sample Input 1

4 4 6

Sample Output 1

5

There are five possible sums: 18=4+4+4+6, 19=4+4+5+6, 20=4+5+5+6, 21=4+5+6+6 and 22=4+6+6+6.

Sample Input 2

5 4 3

Sample Output 2

0

Sample Input 3

1 7 10

Sample Output 3

0

Sample Input 4

1 3 3

Sample Output 4

1


<?php

class In {

	private $buf = [];
	private $count = 0;
	private $pointer = 0;

	public function nextLine() {
		$ret = '';
		if($this->hasNext()){
			while($this->hasNext()){
				$ret .= $this->next();
			}
		}else{
			$ret = trim(fgets(STDIN));
		}

		return $ret;
	}

	public function next() {
		if(!$this->hasNext()) {
			$str = trim(fgets(STDIN));
			$this->buf = explode(' ',$str);
			$this->count = count($this->buf);
			$this->pointer = 0;
		}

		return $this->buf[$this->pointer++];
	}

	public function hasNext() {
		return $this->pointer < $this->count;
	}

	public function nextInt() {
		return (int)$this->next();
	}

	public function nextDouble() {
		return (double)$this->next();
	}
}

class Out {
	public function println($str = '') {
		echo $str . PHP_EOL;
	}
}

$in = new In();
$out = new Out();

$N = $in->nextInt();
$A = $in->nextInt();
$B = $in->nextInt();

if ($A > $B) {
	$out->println(0);
	return;
}

if ($N <= 1) {
	if ($A == $B) {
		$out->println(1);
	} else {
		$out->println(0);
	}
	return;
}

$ans = ($N - 2) * ($B - $A) + 1;

$out->println($ans);

?>


<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$N = $key->A[0];
$A = $key->A[1];
$B = $key->A[2];

if ($A > $B) {
  printf("0\n");
  exit;
}
if ($N==1) {
  if ($A != $B) {
    printf("0\n");
    exit;
  }
  else {
    printf("1\n");
    exit;
  }
}
printf("%d\n",($B-$A)*($N-2)+1);


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

if($n == 1){
if($a == $b){
echo 1;
}else{
echo 0;
}
}else{
if($a > $b){
echo 0;
}elseif($a == $b){
echo 1;
}else{
$n = $n - 2;
$d = ($b - $a) * $n + 1;
echo $d;
}
}


<?php
list($s) = strs();
$n = strlen($s);
for ($i = 0; $i < $n; ++$i) {
    if ($s[$i] === 'A' && !isset($a)) $a = $i;
    if ($s[$i] === 'Z') $z = $i;
}
echo $z - $a + 1;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}

Score : 200 points

Problem Statement

Snuke has decided to construct a string that starts with A and ends with Z, by taking out a substring of a string s (that is, a consecutive part of s).

Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A and ends with Z.

Constraints

1 ≦ |s| ≦ 200{,}000

s consists of uppercase English letters.

There exists a substring of s that starts with A and ends with Z.

Input

The input is given from Standard Input in the following format:

s

Output

Print the answer.

Sample Input 1

QWERTYASDFZXCV

Sample Output 1

5

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.

Sample Input 2

ZABCZ

Sample Output 2

4

Sample Input 3

HASFJGHOGAKZZFEGA

Sample Output 3

12


<?php

$input = trim(fgets(STDIN));
$strpos = strpos($input,"A");
$length = strlen($input);
$input = str_split($input);

for($i=0; $i<$length;$i++){
    if($input[$i] == "Z"){
        $z = $i;
    }
}
echo $z - $strpos+1;


<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(" ", $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function printIn($str = "")
    {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner;

$s = $sc->next();
$s_arr = str_split($s);

$a = strpos($s,'A');
$z = strpos($s,'Z');

$ans = 0;
for ($i = $a; $i <= $z; $i++) {
    $ans ++;
}
echo $ans;


<?php

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

$tmpLen = PHP_INT_MIN;
for ($i=0; $i < strLen($s)-1; $i++)
{
    if($s[$i]==='A')
    {
        for ($j=$i+1; $j < strlen($s); $j++) {
            if($s[$j] === 'Z' && $tmpLen < $j-$i)
            {
                $tmpLen = $j-$i;
            }
        }

    }
}

echo $tmpLen+1 . PHP_EOL;


<?php
$input = trim(fgets(STDIN));
$A_point = array();
$Z_point = array();
for($i = 0; $i < strlen($input); $i++){
	switch($input[$i]){
		case 'A':
			$A_point[] = $i;
			break;
		case 'Z':
			$Z_point[] = $i;
			break;
		default:
	}
}
echo max($Z_point) - min($A_point) + 1;
?>


<?php
fscanf(STDIN, "%s", $s);
echo strrpos($s, 'Z') - strpos($s, 'A') + 1;


<?php
  declare(strict_types=1);

  $s = str_split(fgets(STDIN), 1);
  $idx_a = 0;
  $idx_z = 110110110;
  $i = 0;
  foreach ($s as $c)
  {
      if ($idx_a === 0 && $c == 'A')
      {
          $idx_a = $i;
      }
      else if ($c == 'Z')
      {
          $idx_z = $i;
      }

      $i++;
  }
  echo ($idx_z - $idx_a + 1).PHP_EOL;
?>


Score : 200 points

Problem Statement

You are given two integers K and S.

Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.

How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?

Constraints

2≤K≤2500

0≤S≤3K

K and S are integers.

Input

The input is given from Standard Input in the following format:

K S

Output

Print the number of the triples of X, Y and Z that satisfy the condition.

Sample Input 1

2 2

Sample Output 1

6

There are six triples of X, Y and Z that satisfy the condition:

X = 0, Y = 0, Z = 2

X = 0, Y = 2, Z = 0

X = 2, Y = 0, Z = 0

X = 0, Y = 1, Z = 1

X = 1, Y = 0, Z = 1

X = 1, Y = 1, Z = 0

Sample Input 2

5 15

Sample Output 2

1

The maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z.


<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(" ", $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function printIn($str = "")
    {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner;

$K = $sc->nextInt();
$S = $sc->nextInt();
$count = 0;

for ($x = 0; $x < $K; $x++) {
    for ($y = 0; $y < $K; $y++) {
        for ($z = 0; $z < $K; $z++) {
            $sum = $x + $y + $z;
            if ($sum === $S) {
                $count++;
            }
        }
    }
}
echo $count;


<?php
  $input = explode(" ", fgets(STDIN));
  $K = intval($input[0]);
  $S = intval($input[1]);

  $count = 0;
  for ($x = 0; $x <= $K; $x++) {
    for ($y = 0; $y <= $K; $y++) {
      // K以内でx + y = z
      $z = $S - ($x + $y);
      // S - x + y を保存してて、K以内だったらまたif分にいく
      if ($z <= $K) {
        if ($x + $y + $z == $S) {
          $count++;
        }
      }
    }
  }
  echo $count;


<?php
  $input = explode(" ", fgets(STDIN));
  $K = $input[0];
  $S = $input[1];
  $count = 0;
  $i = $K;
  $j = $K;
  $k = $K;

  $mix = $i + $j + $k;
  if($mix < $S){
    echo 0;
    exit();
  }

  elseif($i + $j + $k == $S){
    echo 1;
    exit();
  }

  for($i=$K;$i>=0;$i--){
	  if($i == $S && $j == 0 && $k == 0){
      $count++;
      continue;
    }
    elseif($i > $S){
      continue;
    }

    for($j=$K;$j>=0;$j--){
      if($i + $j == $S && $k == 0){
        $count++;
        continue;
      }
      elseif($i + $j > $S){
        continue;
      }
      for($k=$K;$k>=0;$k--){

        if($i + $j + $k == $S){
          $count++;
          continue;
        }
        elseif($i + $j + $k > $S){
          continue;
        }
      }
    }
  }
  echo $count;
?>


<?php
/**
 * @see: https://atcoder.jp/contests/abc051/tasks/abc051_b
 */

function getInput(): array
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

function calculate(int $K, int $S): int
{
    $numberOfTriples = 0;

    for ($X = 0; $X <= min($K, $S); $X++) {
        for ($Y = 0; $Y <= min($K, $S - $X); $Y++) {
            $Z = $S - $X - $Y;

            if (0 <= $Z && $Z <= $K) {
                $numberOfTriples++;
            }
        }
    }

    return $numberOfTriples;
}

list($K, $S) = getInput();

$result = calculate($K, $S);

echo $result . PHP_EOL;


<?php
/**
 * @see: https://atcoder.jp/contests/abc051/tasks/abc051_b
 */

function getInput(): array
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

function calculate(int $K, int $S): int
{
    $numberOfTriples = 0;

    for ($X = 0; $X <= $S; $X++) {
        for ($Y = 0; $Y <= $S - $X; $Y++) {
            $Z = $S - $X - $Y;

            if (0 <= $Z && $Z <= $K) {
                $numberOfTriples++;
            }
        }
    }

    return $numberOfTriples;
}

list($K, $S) = getInput();

$result = calculate($K, $S);

echo $result . PHP_EOL;


<?php
$stdin = trim(fgets(STDIN));
$ar = explode(" ",$stdin);
$K = $ar[0];
$S = $ar[1];
$sum=0;
$iandj=false;
//全部同じなら1追加，全部違ったら3追加，のこりは2
for($i=0;$i<=$K;$i++){
        for($j=0;$j<=$i;$j++){
                if($i==$j)$iandj=true;
                else $iandj=false;
                for($k=0;$k<=$j;$k++){
                        if($i+$j+$k == $S){
                                $jandk=$j==$k;
                                if(($iandj && $jandk) or !($iandj or $jandk or $k==$i))
                                        $sum+=1;
                                else    $sum+=3;
                        }
                }
        }
}
print ($sum);


<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$K = $key->A[0];
$S = $key->A[1];
$res = array();
for($i=0;$i<=$K;$i++) {
  for($j=0;$j<=$K;$j++) {
    for($k=0;$k<=$K;$k++) {
      if ($i+$j+$k==$S) {
        $res[]=sprintf("%d,%d,%d",$i,$j,$k);
      }
    }
  }
}
printf("%d\n",count($res));


<?php
fscanf(STDIN, "%s", $s);
$s= strrev($s);
$array = array("dream","dreamer","erase","eraser");
foreach($array as $k => $v){
  $array[$k] = strrev($v);
}
$ans = true;
for($i=0;$i<=strlen($s);){
  $ansz = false;
  foreach($array as $v){
    if(strpos($s,$v,$i)===$i){
      $i += strlen($v);
      $ansz = true;
    }
  }
  if($ansz == false){
    $ans = false;
    break;
  }
}
  if($ans == true){
    echo "YES";
  }else{
    echo "NO";}

?>

Score : 300 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:

Append one of the following at the end of T: dream, dreamer, erase and eraser.

Constraints

1≦|S|≦10^5

S consists of lowercase English letters.

Input

The input is given from Standard Input in the following format:

S

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

Sample Input 1

erasedream

Sample Output 1

YES

Append erase and dream at the end of T in this order, to obtain S = T.

Sample Input 2

dreameraser

Sample Output 2

YES

Append dream and eraser at the end of T in this order, to obtain S = T.

Sample Input 3

dreamerer

Sample Output 3

NO