<?php
list($n) = ints();
$a = ints();
$b = ints();
for ($i = 0; $i < $n; ++$i) {
    if ($a[$i] > $b[$i]) $c1 += $a[$i] - $b[$i];
    elseif ($a[$i] < $b[$i]) $c2 += intdiv($b[$i] - $a[$i], 2);
}
echo $c2 >= $c1 ? 'Yes' : 'No';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

Score : 300 points

Problem Statement

You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N.
Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal.

Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions simultaneously:

Add 2 to a_i.

Add 1 to b_j.

Constraints

1 ≤ N ≤ 10 000

0 ≤ a_i,b_i ≤ 10^9 (1 ≤ i ≤ N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 .. a_N
b_1 b_2 .. b_N

Output

If we can repeat the operation zero or more times so that the sequences a and b become equal, print Yes; otherwise, print No.

Sample Input 1

3
1 2 3
5 2 2

Sample Output 1

Yes

For example, we can perform three operations as follows to do our job:

First operation: i=1 and j=2. Now we have a = \{3,2,3\}, b = \{5,3,2\}.

Second operation: i=1 and j=2. Now we have a = \{5,2,3\}, b = \{5,4,2\}.

Third operation: i=2 and j=3. Now we have a = \{5,4,3\}, b = \{5,4,3\}.

Sample Input 2

5
3 1 4 1 5
2 7 1 8 2

Sample Output 2

No

Sample Input 3

5
2 7 1 8 2
3 1 4 1 5

Sample Output 3

No


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

Score : 300 points

Problem Statement

We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).

You are initially in the top-left square, (1, 1).
You will travel to the bottom-right square, (2, N), by repeatedly moving right or down.

The square (i, j) contains A_{i, j} candies.
You will collect all the candies you visit during the travel.
The top-left and bottom-right squares also contain candies, and you will also collect them.

At most how many candies can you collect when you choose the best way to travel?

Constraints

1 \leq N \leq 100

1 \leq A_{i, j} \leq 100 (1 \leq i \leq 2, 1 \leq j \leq N)

Input

Input is given from Standard Input in the following format:

N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}

Output

Print the maximum number of candies that can be collected.

Sample Input 1

5
3 2 2 4 1
1 2 2 2 1

Sample Output 1

14

The number of collected candies will be maximized when you:

move right three times, then move down once, then move right once.

Sample Input 2

4
1 1 1 1
1 1 1 1

Sample Output 2

5

You will always collect the same number of candies, regardless of how you travel.

Sample Input 3

7
3 3 4 5 4 5 3
5 3 4 4 2 3 2

Sample Output 3

29

Sample Input 4

1
2
3

Sample Output 4

5

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", $a, $b);
if (preg_match('/[.]/',sqrt($a.$b))){
  echo("No");
} else {
  echo("Yes");
}

Score : 200 points

Problem Statement

AtCoDeer the deer has found two positive integers, a and b.
Determine whether the concatenation of a and b in this order is a square number.

Constraints

1 ≤ a,b ≤ 100

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

If the concatenation of a and b in this order is a square number, print Yes; otherwise, print No.

Sample Input 1

1 21

Sample Output 1

Yes

As 121 = 11 × 11, it is a square number.

Sample Input 2

100 100

Sample Output 2

No

100100 is not a square number.

Sample Input 3

12 10

Sample Output 3

No


<?php

$ab = explode(' ',trim(fgets(STDIN)));
$ab = intval(implode('',$ab));

echo floor(sqrt($ab))**2 == $ab ? 'Yes' : 'No';

?>


<?php
/**
 * Created by PhpStorm.
 * User: souta
 * Date: 2018/02/13
 * Time: 9:30
 */

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

$sqrt = sqrt( sprintf("%d%d",$a,$b) );

if( $sqrt == intval($sqrt) ){
    echo 'Yes'."\n";
}else{
    echo 'No'."\n";
}

?>


<?php

fscanf(STDIN, '%d', $n);
$input = [];
for ($i = 0;$i < $n; $i++){
    $input[] = explode(' ',rtrim(fgets(STDIN), PHP_EOL));
}

$before_t = 0;
$before_x = 0;
$before_y = 0;

foreach ($input as $value) {
    $diff_t = abs($value[0] - $before_t);
    $diff_p = abs(($value[1]+$value[2]) - ($before_x + $before_y));

//    var_dump($diff_t, $diff_p,$diff_t < $diff_p);
    if ($diff_t < $diff_p) {
        echo 'No' . PHP_EOL;
        return;
    }

    if ($diff_t % 2 !== 0 && $diff_p %2 === 0) {
        echo 'No'.PHP_EOL;
        return;
    } elseif ($diff_t %2 === 0 && $diff_p %2 !== 0) {
        echo 'No'.PHP_EOL;
        return;
    }

    $before_t = $value[0];
    $before_x = $value[1];
    $before_y = $value[2];
}
echo 'Yes'.PHP_EOL;

Score : 300 points

Problem Statement

AtCoDeer the deer is going on a trip in a two-dimensional plane.
In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.

If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1).
Note that he cannot stay at his place.
Determine whether he can carry out his plan.

Constraints

1 ≤ N ≤ 10^5

0 ≤ x_i ≤ 10^5

0 ≤ y_i ≤ 10^5

1 ≤ t_i ≤ 10^5

t_i < t_{i+1} (1 ≤ i ≤ N-1)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N

Output

If AtCoDeer can carry out his plan, print Yes; if he cannot, print No.

Sample Input 1

2
3 1 2
6 1 1

Sample Output 1

Yes

For example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1), (1,0), then (1,1).

Sample Input 2

1
2 100 100

Sample Output 2

No

It is impossible to be at (100,100) two seconds after being at (0,0).

Sample Input 3

2
5 1 1
100 1 1

Sample Output 3

No


<?php

//$_input = explode(
//    "\n",
//    '2
//3 1 2
//6 1 1
//
//'
//);

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

$planCount = (int) getNext();

$lastTime = 0;
$lastPosX = 0;
$lastPosY = 0;

for ($i = 0; $i < $planCount; ++$i) {
    $temp = explode(' ', getNext());
    $plan = [
        't' => (int) $temp[0],
        'x' => (int) $temp[1],
        'y' => (int) $temp[2],
    ];

    $diffTime = $plan['t'] - $lastTime;
    $diffX = abs($plan['x'] - $lastPosX);
    $diffY = abs($plan['y'] - $lastPosY);

    if (
        $diffX + $diffY > $diffTime
        ||  ($diffTime - ($diffX + $diffY)) % 2 === 1
    ) {
        echo "No\n";
        exit();
    }

    $lastTime = $plan['t'];
    $lastPosX = $plan['x'];
    $lastPosY = $plan['y'];
}

echo "Yes\n";


<?php

$plans = [
    0 => [0, 0, 0]
];

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

for ($i = 1; $i <= $n; ++$i) {
    list($t, $tx, $ty) = fscanf(STDIN, "%d %d %d");
    list($pt, $px, $py) = $plans[$i - 1];

    $movable = $t - $pt;
    $moved = abs($tx - $px) + abs($ty - $py);
    if ($movable >= $moved && ($movable - $moved) % 2 == 0) {
        $plans[$i] = [$t, $tx, $ty];
    } else {
        echo "No" .PHP_EOL;
        return;
    }
}

echo "Yes" . PHP_EOL;


<?php
fscanf(STDIN, "%d %d %d", $N, $A, $B);
echo (($B - $A) % 2 == 0) ? "Alice\n" : "Borys\n";

Score : 300 points

Problem Statement

A game is played on a strip consisting of N cells consecutively numbered from 1 to N.

Alice has her token on cell A. Borys has his token on a different cell B.

Players take turns, Alice moves first.
The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1.
Note that it's disallowed to move the token outside the strip or to the cell with the other player's token.
In one turn, the token of the moving player must be shifted exactly once.

The player who can't make a move loses, and the other player wins.

Both players want to win. Who wins if they play optimally?

Constraints

2 \leq N \leq 100

1 \leq A < B \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print Alice if Alice wins, Borys if Borys wins, and Draw if nobody wins.

Sample Input 1

5 2 4

Sample Output 1

Alice

Alice can move her token to cell 3.
After that, Borys will be unable to move his token to cell 3, so he will have to move his token to cell 5.
Then, Alice moves her token to cell 4. Borys can't make a move and loses.

Sample Input 2

2 1 2

Sample Output 2

Borys

Alice can't make the very first move and loses.

Sample Input 3

58 23 42

Sample Output 3

Borys


<?php
list($s) = strs();
echo '2018' . substr($s, 4);
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}

Score : 100 points

Problem Statement

On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in yyyy/mm/dd format. For example, January 23, 2018 should be written as 2018/01/23.

After finishing the document, she noticed that she had mistakenly wrote 2017 at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to 2018 and prints it.

Constraints

S is a string of length 10.

The first eight characters in S are 2017/01/.

The last two characters in S are digits and represent an integer between 1 and 31 (inclusive).

Input

Input is given from Standard Input in the following format:

S

Output

Replace the first four characters in S with 2018 and print it.

Sample Input 1

2017/01/07

Sample Output 1

2018/01/07

Sample Input 2

2017/01/31

Sample Output 2

2018/01/31


<?php

$N = trim(fgets(STDIN));
$mochi = [];
for($i=0; $i<$N; $i++){
    $mochi[] = trim(fgets(STDIN));
}
$mochi = array_unique($mochi);
echo count($mochi);

?>

Score : 200 points

Problem Statement

An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.

Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?

Constraints

1 ≤ N ≤ 100

1 ≤ d_i ≤ 100

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
d_1
:
d_N

Output

Print the maximum number of layers in a kagami mochi that can be made.

Sample Input 1

4
10
8
8
6

Sample Output 1

3

If we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.

Sample Input 2

3
15
15
15

Sample Output 2

1

When all the mochi have the same diameter, we can only have a 1-layered kagami mochi.

Sample Input 3

7
50
30
50
100
50
80
30

Sample Output 3

4


<?php
$n = fgets(STDIN);
$discs = array();
for ($i = 0; $i < $n; $i++) {
    $disc = fgets(STDIN);
    if (array_search($disc, $discs) === false) {
        array_push($discs, $disc);
    }
}
echo count($discs);
?>


<?php
$n = fgets(STDIN);
$num = [];
for ($i = 0; $i < $n; $i++) {
    $num[] = trim(fgets(STDIN));
}
echo count(array_unique($num));
?>


<?php
fscanf(STDIN, "%d", $N);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d", $d[$i]);
}
echo count(array_unique($d)) . "\n";


<?php
$N = trim(fgets(STDIN));
$d = []; $max = 1;
while($in = trim(fgets(STDIN))) {
    $d[] = $in;
}
$unique_d = array_unique($d, SORT_NUMERIC);
$max = count($unique_d);
echo $max;


<?php
$M = trim(fgets(STDIN));
print 48-$M . "\n";

Score : 100 points

Problem Statement

How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?

Constraints

1≤M≤23

M is an integer.

Input

Input is given from Standard Input in the following format:

M

Output

If we have x hours until New Year at M o'clock on 30th, December, print x.

Sample Input 1

21

Sample Output 1

27

We have 27 hours until New Year at 21 o'clock on 30th, December.

Sample Input 2

12

Sample Output 2

36


<?php
list($q) = ints();
$n = pow(10, 5);
$isPrime = isPrimeArr($n);
$cusum[1] = 0;
for ($i = 1; $i <= $n; $i++) {
    if ($i % 2 === 0) {
        $cusum[$i + 1] = $cusum[$i];
        continue;
    }
    if ($isPrime[$i] && $isPrime[intdiv($i + 1, 2)]) {
        $cusum[$i + 1] = $cusum[$i] + 1;
    } else {
        $cusum[$i + 1] = $cusum[$i];
    }
}
for ($i = 0; $i < $q; $i++) {
    list($l, $r) = ints();
    $ans[] = $cusum[$r + 1] - $cusum[$l];
}
echo implode(PHP_EOL, $ans);

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

function isPrimeArr($max)
{
    $arr = array_fill(0, $max + 1, true);
    $arr[0]  = $arr[1] = false;
    $rmax = (int) floor(sqrt($max));
    for ($i = 2; $i <= $rmax; $i++) {
        for ($j = 2 * $i; $j <= $max; $j += $i) {
            $arr[$j] = false;
        }
    }
    return $arr;
}

Score : 400 points

Problem Statement

We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime.

You are given Q queries.

In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.

Constraints

1≤Q≤10^5

1≤l_i≤r_i≤10^5

l_i and r_i are odd.

All input values are integers.

Input

Input is given from Standard Input in the following format:

Q
l_1 r_1
:
l_Q r_Q

Output

Print Q lines. The i-th line (1≤i≤Q) should contain the response to the i-th query.

Sample Input 1

1
3 7

Sample Output 1

2

3 is similar to 2017, since both 3 and (3+1)/2=2 are prime.

5 is similar to 2017, since both 5 and (5+1)/2=3 are prime.

7 is not similar to 2017, since (7+1)/2=4 is not prime, although 7 is prime.

Thus, the response to the first query should be 2.

Sample Input 2

4
13 13
7 11
7 11
2017 2017

Sample Output 2

1
0
0
1

Note that 2017 is also similar to 2017.

Sample Input 3

6
1 53
13 91
37 55
19 51
73 91
13 49

Sample Output 3

4
4
1
1
1
2


<?php
	fscanf(STDIN, "%d %d %d %d", $A, $B, $C, $D);
	$L = $A + $B;
	$R = $C + $D;
	if($L == $R){
		echo 'Balanced';
	}else if($L > $R){
		echo 'Left';
	}else{
		echo 'Right';
	}
?>

Score : 100 points

Problem Statement

A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.

Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.

Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

Constraints

1\leq A,B,C,D \leq 10

All input values are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

Sample Input 1

3 8 7 1

Sample Output 1

Left

The total weight of the masses on the left pan is 11, and the total weight of the masses on the right pan is 8. Since 11>8, we should print Left.

Sample Input 2

3 4 5 2

Sample Output 2

Balanced

The total weight of the masses on the left pan is 7, and the total weight of the masses on the right pan is 7. Since 7=7, we should print Balanced.

Sample Input 3

1 7 6 4

Sample Output 3

Right

The total weight of the masses on the left pan is 8, and the total weight of the masses on the right pan is 10. Since 8<10, we should print Right.


<?php
list($x, $y) = ints();
$ans = 0;
while ($x <= $y) {
    $ans++;
    $x *= 2;
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

Score : 300 points

Problem Statement

As a token of his gratitude, Takahashi has decided to give his mother an integer sequence.
The sequence A needs to satisfy the conditions below:

A consists of integers between X and Y (inclusive).

For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.

Find the maximum possible length of the sequence.

Constraints

1 \leq X \leq Y \leq 10^{18}

All input values are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

Print the maximum possible length of the sequence.

Sample Input 1

3 20

Sample Output 1

3

The sequence 3,6,18 satisfies the conditions.

Sample Input 2

25 100

Sample Output 2

3

Sample Input 3

314159265 358979323846264338

Sample Output 3

31


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

// $ratio = $Y / $X;

// $ans = floor(log($ratio, 2)) + 1;

// echo $ans . PHP_EOL;

$ans = 0;

while($Y >= $X) {
    $ans++;
    $X *= 2;
}

echo $ans . PHP_EOL;


<?php
  $s = str_split(trim(fgets(STDIN)));
  $t = str_split(trim(fgets(STDIN)));
  sort($s);
  rsort($t);
  $len = min(count($s),count($t));
  for($i=0; $i<$len; $i++){
      if($s[$i] == $t[$i]){
          unset($s[$i]);
          unset($t[$i]);
      }
  }
  if(count($s) == 0 && count($t)>0){
      echo "Yes";
      exit;
  }

  $len = max(count($s),count($t));

  for($i=0; $i<$len; $i++){
      if(isset($s[$i])) $ss = $s[$i];
      if(isset($t[$i])) $tt = $t[$i];
      if($ss < $tt){
          echo "Yes";
          exit;
      }else{
          echo "No";
          exit;
      }
  }
  echo "No";

Score : 200 points

Problem Statement

You are given strings s and t, consisting of lowercase English letters.
You will create a string s' by freely rearranging the characters in s.
You will also create a string t' by freely rearranging the characters in t.
Determine whether it is possible to satisfy s' < t' for the lexicographic order.

Notes

For a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:

N < M and a_1 = b_1, a_2 = b_2, ..., a_N = b_N.

There exists i (1 \leq i \leq N, M) such that a_1 = b_1, a_2 = b_2, ..., a_{i - 1} = b_{i - 1} and a_i < b_i. Here, letters are compared using alphabetical order.

For example, xy < xya and atcoder < atlas.

Constraints

The lengths of s and t are between 1 and 100 (inclusive).

s and t consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s
t

Output

If it is possible to satisfy s' < t', print Yes; if it is not, print No.

Sample Input 1

yx
axy

Sample Output 1

Yes

We can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa.

Sample Input 2

ratcode
atlas

Sample Output 2

Yes

We can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort < tslaa.

Sample Input 3

cd
abc

Sample Output 3

No

No matter how we rearrange cd and abc, we cannot achieve our objective.

Sample Input 4

w
ww

Sample Output 4

Yes

Sample Input 5

zzz
zzz

Sample Output 5

No


<?php
$s = trim(fgets(STDIN));
$n = strlen($s);
$input=explode(' ',trim(fgets(STDIN)));
$x = $input[0];
$y = $input[1];
$initial_x = 0;
$group_x = array();
$group_y = array();

$i = 0;
while($s[$i] == 'F') {
  $initial_x++;
  $i++;
}

$is_dir_x = TRUE;
$count = 0;
for(;$i<$n;$i++) {
  if($s[$i] == 'T') {
    if($count > 0) {
      if($is_dir_x) {
        $group_x[] = $count;
      } else {
        $group_y[] = $count;
      }
      $count = 0;
    }
    $is_dir_x = !$is_dir_x;
  } else {
    $count++;
  }
}
if($count > 0) {
  if($is_dir_x) {
    $group_x[] = $count;
  } else {
    $group_y[] = $count;
  }
  $count = 0;
}

$set_x = array();
$set_x[$initial_x] = TRUE;
foreach($group_x as $gx) {
  $add_keys = array();
  foreach($set_x as $key => $value) {
    if($value === TRUE) {
      if(!isset($set_x[$key + $gx])) {
        $add_keys[] = $key + $gx;
      }
      if(!isset($set_x[$key - $gx])) {
        $add_keys[] = $key - $gx;
      }
    }
    $set_x[$key] = NULL;
  }
  foreach($add_keys as $key) {
    $set_x[$key] = TRUE;
  }
}

$set_y = array();
$set_y[0] = TRUE;
foreach($group_y as $gy) {
  $add_keys = array();
  foreach($set_y as $key => $value) {
    if($value === TRUE) {
      if(!isset($set_y[$key + $gy])) {
        $add_keys[] = $key + $gy;
      }
      if(!isset($set_y[$key - $gy])) {
        $add_keys[] = $key - $gy;
      }
    }
    $set_y[$key] = NULL;
  }
  foreach($add_keys as $key) {
    $set_y[$key] = TRUE;
  }
}

if(isset($set_x[$x]) && isset($set_y[$y])) {
  echo 'Yes'.PHP_EOL;
} else {
  echo 'No'.PHP_EOL;
}

//print_r($set_x);
//print_r($set_y);
?>

Score : 500 points

Problem Statement

A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive x-axis direction.

This robot will be given an instruction sequence s.
s consists of the following two kinds of letters, and will be executed in order from front to back.

F : Move in the current direction by distance 1.

T : Turn 90 degrees, either clockwise or counterclockwise.

The objective of the robot is to be at coordinates (x, y) after all the instructions are executed.
Determine whether this objective is achievable.

Constraints

s consists of F and T.

1 \leq |s| \leq 8 000

x and y are integers.

|x|, |y| \leq |s|

Input

Input is given from Standard Input in the following format:

s
x y

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.

Sample Input 6

TTTT
1 0

Sample Output 6

No


<?php
  $num = fscanf(STDIN, "%d", $a);
  $str =  explode(" ", fgets(STDIN));

$count = 0;
$flag = 0;
while(!$flag){
	foreach($str as $key => $val){
		if($val % 2 == 1){
    		$flag++;
        	break;
        }else{
        	$str[$key] = $str[$key] / 2;
        }
	}
  	if($flag){break;}
  	$count++;
}

echo $count . "\n";
?>

Score : 200 points

Problem Statement

There are N positive integers written on a blackboard: A_1, ..., A_N.

Snuke can perform the following operation when all integers on the blackboard are even:

Replace each integer X on the blackboard by X divided by 2.

Find the maximum possible number of operations that Snuke can perform.

Constraints

1 \leq N \leq 200

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible number of operations that Snuke can perform.

Sample Input 1

3
8 12 40

Sample Output 1

2

Initially, [8, 12, 40] are written on the blackboard.
Since all those integers are even, Snuke can perform the operation.

After the operation is performed once, [4, 6, 20] are written on the blackboard.
Since all those integers are again even, he can perform the operation.

After the operation is performed twice, [2, 3, 10] are written on the blackboard.
Now, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.

Thus, Snuke can perform the operation at most twice.

Sample Input 2

4
5 6 8 10

Sample Output 2

0

Since there is an odd number 5 on the blackboard already in the beginning, Snuke cannot perform the operation at all.

Sample Input 3

6
382253568 723152896 37802240 379425024 404894720 471526144

Sample Output 3

8


<?php

$N = fgets(STDIN);
$A = split(" ", fgets(STDIN));
$cnt = 0;

for (;;) {
  $all_gu = true;

  for ($i=0; $i < $N; $i++) {
    if ($A[$i] %2 !== 0) {
      $all_gu = false;
      break;
    } else {
      $A[$i] = $A[$i] / 2;
    }
  }

  if (!$all_gu) {
    break;
  } else {
    $cnt++;
  }
}

echo $cnt . "\n";

?>


<?php
fscanf(STDIN, "%d %d", $n, $k);
$a = explode(' ', trim(fgets(STDIN)));

$c = array_count_values($a);
arsort($c);
$d = count($c) - $k;
$x = 0;
for ($i = 0; $i < $d; $i++) {
	$x += array_pop($c);
}
echo $x;

Score : 300 points

Problem Statement

Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.

He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.

Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

Constraints

1 \leq K \leq N \leq 200000

1 \leq A_i \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of balls that Takahashi needs to rewrite the integers on them.

Sample Input 1

5 2
1 1 2 2 5

Sample Output 1

1

For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.

Sample Input 2

4 4
1 1 2 2

Sample Output 2

0

Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.

Sample Input 3

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

Sample Output 3

3


<?php
fscanf(STDIN, "%d %d %d", $a ,$b, $c);
$fee = $a * $b;
if ($fee > $c) {
  $fee = $c;
}
echo $fee."\n";
?>

Score : 100 points

Problem Statement

You are parking at a parking lot. You can choose from the following two fee plans:

Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours.

Plan 2: The fee will be B yen, regardless of the duration.

Find the minimum fee when you park for N hours.

Constraints

1≤N≤20

1≤A≤100

1≤B≤2000

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

When the minimum fee is x yen, print the value of x.

Sample Input 1

7 17 120

Sample Output 1

119

If you choose Plan 1, the fee will be 7×17=119 yen.

If you choose Plan 2, the fee will be 120 yen.

Thus, the minimum fee is 119 yen.

Sample Input 2

5 20 100

Sample Output 2

100

The fee might be the same in the two plans.

Sample Input 3

6 18 100

Sample Output 3

100


<?php

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

$array = str_split($n);
$count = 0;

for ($i = 1; $i <= strlen($n); $i++){
    $count += $array[$i];
}

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

Score : 200 points

Problem Statement

An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.

Given an integer N, determine whether it is a Harshad number.

Constraints

1?N?10^8

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print Yes if N is a Harshad number; print No otherwise.

Sample Input 1

12

Sample Output 1

Yes

f(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.

Sample Input 2

57

Sample Output 2

No

f(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number.

Sample Input 3

148

Sample Output 3

No


Score : 300 points

Problem Statement

Joisino is planning to open a shop in a shopping street.

Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.

There are already N stores in the street, numbered 1 through N.

You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.

Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.

Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.

Constraints

1≤N≤100

0≤F_{i,j,k}≤1

For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.

-10^7≤P_{i,j}≤10^7

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}
:
F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}
P_{1,0} ... P_{1,10}
:
P_{N,0} ... P_{N,10}

Output

Print the maximum possible profit of Joisino's shop.

Sample Input 1

1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2

Sample Output 1

8

If her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.

Sample Input 2

2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1

Sample Output 2

-2

Note that a shop must be open during at least one period, and the profit may be negative.

Sample Input 3

3
1 1 1 1 1 1 0 0 1 1
0 1 0 1 1 1 1 0 1 0
1 0 1 1 0 1 0 1 0 1
-8 6 -2 -8 -8 4 8 7 -6 2 2
-9 2 0 1 7 -5 0 -2 -6 5 5
6 -6 7 -9 6 -5 8 0 -9 -7 -7

Sample Output 3

23


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

try {
	if (check($str[0], 'K')) {
		// A
		if ($str[1] . $str[2] . $str[3] == 'KIH') {
			// AKIH
			if (check($str[4], 'B')) {
				// AKIHA
				if ($str[5] == 'B') {
					// AKIHAB
					if (check($str[6], 'R')) {
						// AKIHABA
						if (isset($str[7]) and $str[7] == 'R') {
							// AKIHABAR
							if (!isset($str[8]) or ($str[8] == 'A') and !isset($str[9])) {
								// true
								echo 'YES';
							} else {
								throw new Exception('fail');
							}
						} else {
							throw new Exception('fail');
						}
					} else {
						// AKIHABR
						if (!isset($str[7]) or (($str[7] == 'A') and !isset($str[8]))) {
							echo 'YES';
						} else {
							throw new Exception('fail');
						}
					}
				} else {
					throw new Exception('fail');
				}
			} else {
				// AKIHB
				if (check($str[5], 'R')) {
					// AKIHBA
					if (isset($str[6]) and $str[6] == 'R') {
						// AKIHABAR
						if (!isset($str[7]) or (($str[7] == 'A') and !isset($str[8]))) {
							echo 'YES';
						} else {
							throw new Exception('fail');
						}
					} else {
						throw new Exception('fail');
					}
				} else {
					// AKIHBR
					if (!isset($str[6]) or (($str[6] == 'A') and !isset($str[7]))) {
						echo 'YES';
					} else {
						throw new Exception('fail');
					}
				}
			}
		} else {
			throw new Exception('fail');
		}
	} else {
		// K
		if ($str[1] . $str[2] == 'IH') {
			// KIH
			if (check($str[3], 'B')) {
				// KIHA
				if (isset($str[4]) and $str[4] == 'B') {
					// KIHAB
					if (check($str[5], 'R')) {
						// KIHABA
						if (isset($str[6]) and $str[6] == 'R') {
							// KIHABAR
							if (!isset($str[7]) or (($str[7] == 'A') and !isset($str[8]))) {
								// true
								echo 'YES';
							} else {
								throw new Exception('fail');
							}
						} else {
							throw new Exception('fail');
						}
					} else {
						// KIHABR
						if (!isset($str[6]) or (($str[6] == 'A') and !isset($str[7]))) {
							//true
							echo 'YES';
						} else {
							throw new Exception('fail');
						}
					}
				} else {
					throw new Exception('fail');
				}
			} else {
				// KIHB
				if (check($str[4], 'R')) {
					// KIHBA
					if (isset($str[5]) and $str[5] == 'R') {
						// KIHABAR
						if (!isset($str[6]) or (($str[6] == 'A') and !isset($str[7]))) {
							// true
							echo 'YES';
						} else {
							throw new Exception('fail');
						}
					} else {
						throw new Exception('fail');
					}
				} else {
					// KIHBR
					if (!isset($str[5]) or (($str[5] == 'A') and !isset($str[6]))) {
						// KIHBR
						echo 'YES';
						// true
					} else {
						throw new Exception('fail');
					}
				}
			}
		} else {
			throw new Exception('fail');
		}
	}
} catch (Exception $e) {
	echo 'NO';
}

function check ($str, $next_char) {
	if ($str == 'A') {
		return true;
	} elseif($str == $next_char)  {
		return false;
	} else {
		throw new Exception('fail');
	}
}

Score : 300 points

Problem Statement

You are given a string S.

Takahashi can insert the character A at any position in this string any number of times.

Can he change S into AKIHABARA?

Constraints

1 \leq |S| \leq 50

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If it is possible to change S into AKIHABARA, print YES; otherwise, print NO.

Sample Input 1

KIHBR

Sample Output 1

YES

Insert one A at each of the four positions: the beginning, immediately after H, immediately after B and the end.

Sample Input 2

AKIBAHARA

Sample Output 2

NO

The correct spell is AKIHABARA.

Sample Input 3

AAKIAHBAARA

Sample Output 3

NO


Score : 100 points

Problem Statement

We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.

You are given a 4-digit integer N. Answer the question: Is N good?

Constraints

1000 ≤ N ≤ 9999

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N is good, print Yes; otherwise, print No.

Sample Input 1

1118

Sample Output 1

Yes

N is good, since it contains three consecutive 1.

Sample Input 2

7777

Sample Output 2

Yes

An integer is also good when all the digits are the same.

Sample Input 3

1234

Sample Output 3

No


<?php
    fscanf(STDIN, "%d", $n);
    $count = 1;
    $array = str_split($n);
    for($i = 0; $i < count($array) -1; $i ++){
      if($array[$i] == $array[$i + 1]){
        $count++;
      }
    }
    if($count >= 3){
      echo 'Yes';
    }else{
      echo 'No';
    }
  ?>


<?php

$input = trim(fgets(STDIN));
$prev1 = 1;
$prev2 = 2;

if ( $input == 1 ) echo $prev1;
elseif ( $input == 2 ) echo $prev2;
else {
for ( $i = 3; $i  <= $input; $i++ )
{
   $cur = $prev1 + $prev2;
   $prev1 = $prev2;
   $prev2 = $cur;
}

 echo $cur;
}

?>


<?php

    fscanf(STDIN,"%d",$N);
        $before1 = 2;
        $before_result = 1;
        // if($N==1){
        //     echo $before_result."\n";
        // }else{
            $l_now=0;
            for($i=1;$i<$N;$i++){
                $l_now = $before1+$before_result;
                $before1 = $before_result;
                $before_result = $l_now;
                echo "$l_now";
            }

            echo $l_now."\n";

        // }

Score : 200 points

Problem Statement

It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.

You are given an integer N. Find the N-th Lucas number.

Here, the i-th Lucas number L_i is defined as follows:

L_0=2

L_1=1

L_i=L_{i-1}+L_{i-2} (i≥2)

Constraints

1≤N≤86

It is guaranteed that the answer is less than 10^{18}.

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the N-th Lucas number.

Sample Input 1

5

Sample Output 1

11

L_0=2

L_1=1

L_2=L_0+L_1=3

L_3=L_1+L_2=4

L_4=L_2+L_3=7

L_5=L_3+L_4=11

Thus, the 5-th Lucas number is 11.

Sample Input 2

86

Sample Output 2

939587134549734843


<?php
$tmp = [];
$file = fopen("./stdin.txt", "r");
if ($file) {
    while ($line = fgets($file)) {
        $tmp[] = trim($line);
    }
}
fclose($file);

$tmp = [];
while ($line = fgets(STDIN)) {
    $tmp[] = trim($line);
}

// 全ての間に+入れておく
$list = str_split(wordwrap($tmp[0], 1, '+', true));

$n = 3;

for ($bit = 0; $bit < (1 << $n); $bit++) {
    $thisList = $list;
    for ($i = 0; $i < $n; $i++) {
        if ($bit & (1 << $i)) {
            $minus = 2 * $i + 1;
            $thisList[$minus] = '-';
        }
    }

    $result = $thisList[0];
    for ($l = 2; $l <= 6; $l = $l + 2) {
        if ($thisList[$l - 1] === '+') {
            $result += $thisList[$l];
        } else {
            $result -= $thisList[$l];
        }
    }

    if ($result === 7) {
        echo implode('', $thisList) . '=7';
        break;
    }
}

Score : 300 points

Problem Statement

Sitting in a station waiting room, Joisino is gazing at her train ticket.

The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).

In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.

The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

Constraints

0≤A,B,C,D≤9

All input values are integers.

It is guaranteed that there is a solution.

Input

Input is given from Standard Input in the following format:

ABCD

Output

Print the formula you made, including the part =7.

Use the signs + and -.

Do not print a space between a digit and a sign.

Sample Input 1

1222

Sample Output 1

1+2+2+2=7

This is the only valid solution.

Sample Input 2

0290

Sample Output 2

0-2+9+0=7

0 - 2 + 9 - 0 = 7 is also a valid solution.

Sample Input 3

3242

Sample Output 3

3+2+4-2=7


Score : 100 points

Problem Statement

You are given a grid with 2 rows and 3 columns of squares.
The color of the square at the i-th row and j-th column is represented by the character C_{ij}.

Write a program that prints YES if this grid remains the same when rotated 180 degrees, and prints NO otherwise.

Constraints

C_{i,j}(1 \leq i \leq 2, 1 \leq j \leq 3) is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

C_{11}C_{12}C_{13}
C_{21}C_{22}C_{23}

Output

Print YES if this grid remains the same when rotated 180 degrees; print NO otherwise.

Sample Input 1

pot
top

Sample Output 1

YES

This grid remains the same when rotated 180 degrees.

Sample Input 2

tab
bet

Sample Output 2

NO

This grid does not remain the same when rotated 180 degrees.

Sample Input 3

eye
eel

Sample Output 3

NO


<?php
fscanf(STDIN, "%s", $a);
fscanf(STDIN, "%s", $b);
echo $a == strrev($b) ? 'YES' : 'NO';


<?php
echo -fgets(STDIN) + 2 * fgets(STDIN);

Score : 100 points

Problem Statement

Takahashi is a user of a site that hosts programming contests.

When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows:

Let the current rating of the user be a.

Suppose that the performance of the user in the contest is b.

Then, the new rating of the user will be the avarage of a and b.

For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000.

Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest.

Find the performance required to achieve it.

Constraints

0 \leq R, G \leq 4500

All input values are integers.

Input

Input is given from Standard Input in the following format:

R
G

Output

Print the performance required to achieve the objective.

Sample Input 1

2002
2017

Sample Output 1

2032

Takahashi's current rating is 2002.

If his performance in the contest is 2032, his rating will be the average of 2002 and 2032, which is equal to the desired rating, 2017.

Sample Input 2

4500
0

Sample Output 2

-4500

Although the current and desired ratings are between 0 and 4500, the performance of a user can be below 0.


<?php
fscanf(STDIN, "%d" ,$n);
fscanf(STDIN, "%d" ,$k);
$double = 0;
$sum    = 0;
$ans    = 1;
for ($i=0;$i<$n;$i++) {
	$double = $ans * 2;
	$sum    = $ans + $k;
	if ($double < $sum) {
		$ans = $double;
	}else {
		$ans = $sum;
	}
}
echo $ans;

Score : 200 points

Problem Statement

Square1001 has seen an electric bulletin board displaying the integer 1.
He can perform the following operations A and B to change this value:

Operation A: The displayed value is doubled.

Operation B: The displayed value increases by K.

Square1001 needs to perform these operations N times in total.
Find the minimum possible value displayed in the board after N operations.

Constraints

1 \leq N, K \leq 10

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the minimum possible value displayed in the board after N operations.

Sample Input 1

4
3

Sample Output 1

10

The value will be minimized when the operations are performed in the following order: A, A, B, B.

In this case, the value will change as follows: 1 → 2 → 4 → 7 → 10.

Sample Input 2

10
10

Sample Output 2

76

The value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.

In this case, the value will change as follows: 1 → 2 → 4 → 8 → 16 → 26 → 36 → 46 → 56 → 66 → 76.

By the way, this contest is AtCoder Beginner Contest 076.


<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%d", $m);
$num = 1;
for ($i = 0; $i < $n; $i++) {
  if ($num < $m) {
    $num = $num * 2;
  } else {
    $num = $num + $m;
  }
}
echo $num;


<?php
    list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
    if($a == $b){
        echo $c;
    }elseif($a == $c){
        echo $b;
    }else{
        echo $a;
    }
?>

Score : 100 points

Problem Statement

You are given three integers, A, B and C.

Among them, two are the same, but the remaining one is different from the rest.

For example, when A=5,B=7,C=5, A and C are the same, but B is different.

Find the one that is different from the rest among the given three integers.

Constraints

-100 \leq A,B,C \leq 100

A, B and C are integers.

The input satisfies the condition in the statement.

Input

Input is given from Standard Input in the following format:

A B C

Output

Among A, B and C, print the integer that is different from the rest.

Sample Input 1

5 7 5

Sample Output 1

7

This is the same case as the one in the statement.

Sample Input 2

1 1 7

Sample Output 2

7

In this case, C is the one we seek.

Sample Input 3

-100 100 100

Sample Output 3

-100


Score : 300 points

Problem Statement

You are given an integer N.

Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w.

If there are multiple solutions, any of them will be accepted.

Constraints

It is guaranteed that, for the given integer N, there exists a solution such that h,n,w \leq 3500.

Inputs

Input is given from Standard Input in the following format:

N

Outputs

Print a triple of positive integers h, n and w that satisfies the condition, in the following format:

h n w

Sample Input 1

2

Sample Output 1

1 2 2

4/2 = 1/1 + 1/2 + 1/2.

Sample Input 2

3485

Sample Output 2

872 1012974 1539173474040

It is allowed to use an integer exceeding 3500 in a solution.

Sample Input 3

4664

Sample Output 3

3498 3498 3498


<?php
list($s) = strs();
$cnt = 0;
for ($i = 0; $i < strlen($s); ++$i)
    if ($s[$i] === '1') ++$cnt;
echo $cnt . PHP_EOL;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}

Score : 100 points

Problem Statement

Snuke prepared 6 problems for a upcoming programming contest.
For each of those problems, Rng judged whether it can be used in the contest or not.

You are given a string S of length 6.
If the i-th character of s is 1, it means that the i-th problem prepared by Snuke is accepted to be used; 0 means that the problem is not accepted.

How many problems prepared by Snuke are accepted to be used in the contest?

Constraints

The length of S is 6.

S consists of 0 and 1.

Inputs

Input is given from Standard Input in the following format:

S

Outputs

Print the number of problems prepared by Snuke that are accepted to be used in the contest.

Sample Input 1

111100

Sample Output 1

4

The first, second, third and fourth problems are accepted, for a total of four.

Sample Input 2

001001

Sample Output 2

2

Sample Input 3

000000

Sample Output 3

0


Score : 200 points

Problem Statement

We have a grid with N rows and M columns of squares. Initially, all the squares are white.

There is a button attached to each row and each column.
When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa.
When a button attached to a column is pressed, the colors of all the squares in that column are inverted.

Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.

Constraints

1 \leq N,M \leq 1000

0 \leq K \leq NM

Input

Input is given from Standard Input in the following format:

N M K

Output

If Takahashi can have exactly K black squares in the grid, print Yes; otherwise, print No.

Sample Input 1

2 2 2

Sample Output 1

Yes

Press the buttons in the order of the first row, the first column.

Sample Input 2

2 2 1

Sample Output 2

No

Sample Input 3

3 5 8

Sample Output 3

Yes

Press the buttons in the order of the first column, third column, second row, fifth column.

Sample Input 4

7 9 20

Sample Output 4

No


<?php
  fscanf(STDIN,"%d",$n);
  fscanf(STDIN,"%d",$k);
$num=trim(explode(" ",fgets(STDIN)));
for($i=0;$i<$n;$i++){
	$num[$i]=intval($num[$i]);
}
$sum=0;
for($i=0;$i<$n;$i++){
	$max=$num[$i];
  	$max=max($num[$i],$k-$num[$i]);
    $max=2*$max;
    $sum =$sum+$max;

}
echo $sum.PHP_EOL;

Score : 200 points

Problem Statement

There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i).
Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.

In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.
Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i).
Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.

When activated, each type of robot will operate as follows.

When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.

When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.

Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

Constraints

1 \leq N \leq 100

1 \leq K \leq 100

0 < x_i < K

All input values are integers.

Inputs

Input is given from Standard Input in the following format:

N
K
x_1 x_2 ... x_N

Outputs

Print the minimum possible total distance covered by robots.

Sample Input 1

1
10
2

Sample Output 1

4

There are just one ball, one type-A robot and one type-B robot.

If the type-A robot is used to collect the ball, the distance from the robot to the ball is 2, and the distance from the ball to the original position of the robot is also 2, for a total distance of 4.

Similarly, if the type-B robot is used, the total distance covered will be 16.

Thus, the total distance covered will be minimized when the type-A robot is used. The output should be 4.

Sample Input 2

2
9
3 6

Sample Output 2

12

The total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot.

Sample Input 3

5
20
11 12 9 17 12

Sample Output 3

74


const SEARCH_NUM = 9;

$result = false;

$num = trim(fgets(STDIN));

if(floor($num / 10) == SEARCH_NUM){
	$result = true;
}
if(($num % 10) == 9){
	$result = true;
}

if($result){
	echo "Yes";
}else{
	echo "No";
}

Score : 100 points

Problem Statement

It is September 9 in Japan now.

You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?

Constraints

10≤N≤99

Input

Input is given from Standard Input in the following format:

N

Output

If 9 is contained in the decimal notation of N, print Yes; if not, print No.

Sample Input 1

29

Sample Output 1

Yes

The one's digit of 29 is 9.

Sample Input 2

72

Sample Output 2

No

72 does not contain 9.

Sample Input 3

91

Sample Output 3

Yes


<?php
// AtCoder My Practice
// 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()); }

// 解説読後 https://atcoder.jp/img/abc073/editorial.pdf

list($N, $M, $R) = getInts();
$rs = getInts();

$path = array();
for ($i = 0; $i <= $N; $i++) {
    $path[] = array_fill(0, $N+1, 300000000);
}

for ($i = 0; $i < $M; $i++) {
    list($a, $b, $c) = getInts();
    $path[$a][$b] = $c;
    $path[$b][$a] = $c;
}

// ワーシャルフロイド
for ($i = 1; $i <= $N; $i++) {
    for ($j = 1; $j <= $N; $j++) {
        for ($k = 1; $k <= $N; $k++) {
            if ($path[$j][$k] > $path[$j][$i] + $path[$i][$k]) {
                $path[$j][$k] = $path[$j][$i] + $path[$i][$k];
            }
        }
    }
}
printf("1\n");

Score : 400 points

Problem Statement

There are N towns in the State of Atcoder, connected by M bidirectional roads.

The i-th road connects Town A_i and B_i and has a length of C_i.

Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order).

She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road.

If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?

Constraints

2≤N≤200

1≤M≤N×(N-1)/2

2≤R≤min(8,N) (min(8,N) is the smaller of 8 and N.)

r_i≠r_j (i≠j)

1≤A_i,B_i≤N, A_i≠B_i

(A_i,B_i)≠(A_j,B_j),(A_i,B_i)≠(B_j,A_j) (i≠j)

1≤C_i≤100000

Every town can be reached from every town by road.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M R
r_1 ... r_R
A_1 B_1 C_1
:
A_M B_M C_M

Output

Print the distance traveled by road if Joisino visits the towns in the order that minimizes it.

Sample Input 1

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

Sample Output 1

2

For example, if she visits the towns in the order of 1, 2, 3, the distance traveled will be 2, which is the minimum possible.

Sample Input 2

3 3 2
1 3
2 3 2
1 3 6
1 2 2

Sample Output 2

4

The shortest distance between Towns 1 and 3 is 4. Thus, whether she visits Town 1 or 3 first, the distance traveled will be 4.

Sample Input 3

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

Sample Output 3

3


<?php
	fscanf(STDIN, "%d %d", $X, $t);
	$remaining = $X - $t;
	if($remaining < 0){
		echo 0;
	}else{
		echo $remaining;
	}
?>

Score : 100 points

Problem Statement

We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand.

How many grams of sand will the upper bulb contains after t seconds?

Constraints

1≤X≤10^9

1≤t≤10^9

X and t are integers.

Input

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

X t

Output

Print the number of sand in the upper bulb after t second.

Sample Input 1

100 17

Sample Output 1

83

17 out of the initial 100 grams of sand will be consumed, resulting in 83 grams.

Sample Input 2

48 58

Sample Output 2

0

All 48 grams of sand will be gone, resulting in 0 grams.

Sample Input 3

1000000000 1000000000

Sample Output 3

0


<?php
fscanf(STDIN,"%d",$x);
fscanf(STDIN,"%d",$t);
if($x >= $t){
  echo $x-$t;

}else {
  echo 0;
  echo '\n';
}
 ?>


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

//for ($i = 0; $i < count($s_arr); $i++) {
//  if ($i === 0 || $i % 2 === 0){
//      echo $s_arr[$i];
//  }
//}

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

Score : 200 points

Problem Statement

You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.

Constraints

Each character in s is a lowercase English letter.

1≤|s|≤10^5

Input

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

s

Output

Print the string obtained by concatenating all the characters in the odd-numbered positions.

Sample Input 1

atcoder

Sample Output 1

acdr

Extract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.

Sample Input 2

aaaa

Sample Output 2

aa

Sample Input 3

z

Sample Output 3

z

Sample Input 4

fukuokayamaguchi

Sample Output 4

fkoaaauh


<?php
$text = fgets(STDIN);
$len = strlen($text);
for ($i = 0; $i < $len; $i ++) {
    if (($i + 1) % 2 !== 0) {
        echo $text[$i];
    }
}
?>


<?php
  $n = trim(fgets(STDIN));
  $p = explode(" ", trim(fgets(STDIN)));
  $cnt = 0;
  $ans = 0;
  for($i=0; $i<$n; $i++){
      if($p[$i]-1 == $i){
          $cnt++;

          if($i == $n-1){
              if($cnt > 1){
                  $cnt--;
                  $ans += ceil($cnt/2);
              } else {
                  $ans += $cnt;
              }
          }
      }else{
          if($cnt > 1){
              $cnt--;
              $ans += ceil($cnt/2);
          } else {
              $ans += $cnt;
          }
          $cnt=0;
      }
  }
  echo $ans;

Score : 400 points

Problem Statement

You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N.
You can perform the following operation any number of times (possibly zero):

Operation: Swap two adjacent elements in the permutation.

You want to have p_i ≠ i for all 1≤i≤N.
Find the minimum required number of operations to achieve this.

Constraints

2≤N≤10^5

p_1,p_2,..,p_N is a permutation of 1,2,..,N.

Input

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

N
p_1 p_2 .. p_N

Output

Print the minimum required number of operations

Sample Input 1

5
1 4 3 5 2

Sample Output 1

2

Swap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the condition.
This is the minimum possible number, so the answer is 2.

Sample Input 2

2
1 2

Sample Output 2

1

Swapping 1 and 2 satisfies the condition.

Sample Input 3

2
2 1

Sample Output 3

0

The condition is already satisfied initially.

Sample Input 4

9
1 2 4 9 5 8 7 3 6

Sample Output 4

3


<?php
list($n) = ints();
$p = ints();
$ans = $cnt = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($p[$i] === $i + 1) {
        $cnt++;
    } else {
        if ($cnt >= 1) $ans += max(1, $cnt - 1);
        $cnt = 0;
    }
    if ($i === $n - 1 && $cnt >= 1) $ans += max(1, $cnt - 1);
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


<?php

$nums1 = (fgets(STDIN));
$nums2 = strrev($nums1);
echo $nums1 == $nums2 ? 'Yes' : 'No';

?>

Score : 100 points

Problem Statement

You are given a three-digit positive integer N.

Determine whether N is a palindromic number.

Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.

Constraints

100≤N≤999

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N is a palindromic number, print Yes; otherwise, print No.

Sample Input 1

575

Sample Output 1

Yes

N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.

Sample Input 2

123

Sample Output 2

No

N=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.

Sample Input 3

812

Sample Output 3

No


<?php
    fscanf(STDIN, "%s", $a);
    $b = substr($a,-1) . substr($a,1,2);
    $output = "No";
    if ($a == $b) {$output = "Yes";}
    echo $output . "\n";
?>


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

  if($a < $c){
    if($b < $d){
      if( $b > $c ) echo $b - $c;
      else echo "0";
    }else{
      echo $d-$c;
    }
  }else{
    if($d < $b){
      if( $d > $a ) echo $d - $a;
      else echo "0";
      exit;
    }else{
      echo $b-$a;
    }
  }

Score : 200 points

Problem Statement

Alice and Bob are controlling a robot. They each have one switch that controls the robot.

Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.

Bob started holding down his button C second after the start-up, and released his button D second after the start-up.

For how many seconds both Alice and Bob were holding down their buttons?

Constraints

0≤A<B≤100

0≤C<D≤100

All input values are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.

Sample Input 1

0 75 25 100

Sample Output 1

50

Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.

Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.

Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.

Sample Input 2

0 33 66 99

Sample Output 2

0

Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.

Sample Input 3

10 90 20 80

Sample Output 3

60


<?php
list($a, $b, $c, $d) = ints();
echo max(0, min($b, $d) - max($a, $c));
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


<?php

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

$counter = 0;

for($i = $a; $i < $b; $i++){
	if($c < $i && $i<= $d){
		$counter++;
	}
}

echo $counter;

?>


<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) {
    list($t) = ints();
    if ($i > 0) $ans = lcm($ans, $t);
    else $ans = $t;
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

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

// 最大公約数（3つ以上）
function gcdAll($arr)
{
    $gcd = array_pop($arr);
    foreach ($arr as $a) {
        $gcd = gcd($gcd, $a);
    }
    return $gcd;
}

// 最小公倍数（2つ）
function lcm($m, $n)
{
    return (int) ($m / gcd($m, $n) * $n);
}

// 最小公倍数（3つ以上）
function lcmAll($arr)
{
    $lcm = array_pop($arr);
    foreach ($arr as $a) {
        $lcm = lcm($lcm, $a);
    }
    return $lcm;
}

Score : 300 points

Problem Statement

We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds.

Initially, the hand of every clock stands still, pointing directly upward.

Now, Dolphin starts all the clocks simultaneously.

In how many seconds will the hand of every clock point directly upward again?

Constraints

1≤N≤100

1≤T_i≤10^{18}

All input values are integers.

The correct answer is at most 10^{18} seconds.

Input

Input is given from Standard Input in the following format:

N
T_1
:
T_N

Output

Print the number of seconds after which the hand of every clock point directly upward again.

Sample Input 1

2
2
3

Sample Output 1

6

We have two clocks. The time when the hand of each clock points upward is as follows:

Clock 1: 2, 4, 6, ... seconds after the beginning

Clock 2: 3, 6, 9, ... seconds after the beginning

Therefore, it takes 6 seconds until the hands of both clocks point directly upward.

Sample Input 2

5
2
5
10
1000000000000000000
1000000000000000000

Sample Output 2

1000000000000000000


<?php
$n = trim(fgets(STDIN));
$i = 0;
while($i < $n){
$a[] = trim(fgets(STDIN));
++$i;
}

rsort($a);
$ans = $a[0];
if($ans > pow(10,17)*5){
echo $ans;
}else{
$i = 1;
while($i < $n){
$x = lcm($ans,$a[$i]);
if($x > $ans){
$ans = $x;
}
++$i;
}
echo $ans;
}

function gcd($a,$b){
return ($a % $b) ? gcd($b,$a % $b) : $b;
}
function lcm($a,$b){
return $a * $b / gcd($a,$b);
}


<?php
fscanf(STDIN, "%s", $letters);
$first_letter = substr($letters, 0, 1);
$final_letter = substr($letters, -1, 1);
$middle_letters = mb_strlen($letters) - 2;
echo $first_letter  + $middle_letters + $final_letter;

Score : 200 points

Problem Statement

The word internationalization is sometimes abbreviated to i18n.
This comes from the fact that there are 18 letters between the first i and the last n.

You are given a string s of length at least 3 consisting of lowercase English letters.
Abbreviate s in the same way.

Constraints

3 ≤ |s| ≤ 100 (|s| denotes the length of s.)

s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

Print the abbreviation of s.

Sample Input 1

internationalization

Sample Output 1

i18n

Sample Input 2

smiles

Sample Output 2

s4s

Sample Input 3

xyz

Sample Output 3

x1z


<?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);
$c = count($s_arr);

$abbr = $s[0] . $c - 2 . $s[$c - 1];

echo $abbr;


<?php
fscanf(STDIN, "%s", $s);
$cnt = strlen($s);
$start = substr($s,  0, 1);
$end   = substr($s, -1, 1);
echo $start . $cnt . $end;


<?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;
  }
}
$H = $key->A[0];
$W = $key->A[1];
$N = $key->X[0][0];
$a=array();
foreach($key->X[1] as $v) {
  $a[]=$v;
}
$pos=0;
for($y=0;$y<$H;$y++) {
  $line[$y]=str_pad("",$W);
  for($x=0;$x<$W;$x++) {
    $line[$y][$x]=" ";
    $c = getColor($pos,$a);
    if ($c !== false) {
      $pos++;
      $line[$y][$x]=$c;
    }
  }
  if ($y%2==1) $line[$y]=strrev($line[$y]);
}
for($i=0;$i<$H;$i++) {
  printf("%s\n",$line[$i]);
}
function getColor($pos,$col) {
  $chk=0;
  foreach($col as $k=>$c) {
    if ($chk <= $pos && $pos < $chk+$c) {
      return $k+1;
    }
    $chk+=$c;
  }
  return false;
}

Score : 400 points

Problem Statement

We have a grid with H rows and W columns of squares.
Snuke is painting these squares in colors 1, 2, ..., N.
Here, the following conditions should be satisfied:

For each i (1 ≤ i ≤ N), there are exactly a_i squares painted in Color i. Here, a_1 + a_2 + ... + a_N = H W.

For each i (1 ≤ i ≤ N), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i.

Find a way to paint the squares so that the conditions are satisfied.
It can be shown that a solution always exists.

Constraints

1 ≤ H, W ≤ 100

1 ≤ N ≤ H W

a_i ≥ 1

a_1 + a_2 + ... + a_N = H W

Input

Input is given from Standard Input in the following format:

H W
N
a_1 a_2 ... a_N

Output

Print one way to paint the squares that satisfies the conditions.
Output in the following format:

c_{1 1} ... c_{1 W}
:
c_{H 1} ... c_{H W}

Here, c_{i j} is the color of the square at the i-th row from the top and j-th column from the left.

Sample Input 1

2 2
3
2 1 1

Sample Output 1

1 1
2 3

Below is an example of an invalid solution:

1 2
3 1

This is because the squares painted in Color 1 are not 4-connected.

Sample Input 2

3 5
5
1 2 3 4 5

Sample Output 2

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

Sample Input 3

1 1
1
1

Sample Output 3

1


<?php
    $n = trim(fgets(STDIN));
    echo "ABC".$n;
?>

Score : 100 points

Problem Statement

This contest, AtCoder Beginner Contest, is abbreviated as ABC.

When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.

What is the abbreviation for the N-th round of ABC? Write a program to output the answer.

Constraints

100 ≤ N ≤ 999

Input

Input is given from Standard Input in the following format:

N

Output

Print the abbreviation for the N-th round of ABC.

Sample Input 1

100

Sample Output 1

ABC100

The 100th round of ABC is ABC100.

Sample Input 2

425

Sample Output 2

ABC425

Sample Input 3

999

Sample Output 3

ABC999


<?php

// ABC068C
fscanf(STDIN, "%d%d", $n, $m);
$first_way = array();
$second_way = array();
for ($i = 0; $i < $m; $i++) {
    fscanf(STDIN, '%d%d', $a, $b);
    if ($a == 1) {
        $first_way[] = $b;
    } elseif ($b == $n) {
        $second_way[] = $a;
    }
}
$first_way = array_unique($first_way);
$second_way = array_unique($second_way);

foreach ($first_way as $value) {
    if (isset($second_way[$value])) {
        echo 'POSSIBLE';
        return;
    }
}

echo 'IMPOSSIBLE';

Score : 300 points

Problem Statement

In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.
For convenience, we will call them Island 1, Island 2, ..., Island N.

There are M kinds of regular boat services between these islands.
Each service connects two islands. The i-th service connects Island a_i and Island b_i.

Cat Snuke is on Island 1 now, and wants to go to Island N.
However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.

Help him.

Constraints

3 ≤ N ≤ 200 000

1 ≤ M ≤ 200 000

1 ≤ a_i < b_i ≤ N

(a_i, b_i) \neq (1, N)

If i \neq j, (a_i, b_i) \neq (a_j, b_j).

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

If it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.

Sample Input 1

3 2
1 2
2 3

Sample Output 1

POSSIBLE

Sample Input 2

4 3
1 2
2 3
3 4

Sample Output 2

IMPOSSIBLE

You have to use three boat services to get to Island 4.

Sample Input 3

100000 1
1 99999

Sample Output 3

IMPOSSIBLE

Sample Input 4

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

Sample Output 4

POSSIBLE

You can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.


Score : 600 points

Problem Statement

We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller.

Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.

It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.

You are given an integer K. Find an integer sequence a_i such that the number of times we will perform the above operation is exactly K. It can be shown that there is always such a sequence under the constraints on input and output in this problem.

Constraints

0 ≤ K ≤ 50 \times 10^{16}

Input

Input is given from Standard Input in the following format:

K

Output

Print a solution in the following format:

N
a_1 a_2 ... a_N

Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.

Sample Input 1

0

Sample Output 1

4
3 3 3 3

Sample Input 2

1

Sample Output 2

3
1 0 3

Sample Input 3

2

Sample Output 3

2
2 2

The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].

Sample Input 4

3

Sample Output 4

7
27 0 0 0 0 0 0

Sample Input 5

1234567894848

Sample Output 5

10
1000 193 256 777 0 1 1192 1234567891011 48 425


<?php

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

$total = $a + $b;

if ($a % 3 ===0 || $b % 3 === 0 ||  $total % 3 === 0) {
    echo 'Possible';
} else {
    echo 'Impossible';
}

?>

Score : 100 points

Problem Statement

Snuke is giving cookies to his three goats.

He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins).

Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.

Constraints

1 \leq A,B \leq 100

Both A and B are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

If it is possible to give cookies so that each of the three goats can have the same number of cookies, print Possible; otherwise, print Impossible.

Sample Input 1

4 5

Sample Output 1

Possible

If Snuke gives nine cookies, each of the three goats can have three cookies.

Sample Input 2

1 1

Sample Output 2

Impossible

Since there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them.


<?php

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

$total=0;
foreach ($arr as $value) {
	$total += $value;
}

if ($total % 3 === 0) {
    echo 'Possible';
} else {
    echo 'Impossible';
}

?>


<?php

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

if(($a+$b)%3 == 0) {
    echo 'Possible';

}else if ($a%3 == 0 )
{
    echo 'Possible';
}else if ($b%3 == 0 )
{
    echo 'Possible';
}
else{
    echo 'Impossible';
}


<?php
	$a = trim(fgets(STDIN));
	$b = trim(fgets(STDIN));
	$count = 0;
	if((($a * $b * ($a + $b))%3 == 0)&&(($a * $b * ($a + $b)) != 0)){echo "Possible";}
   else{echo "Impossible";}
?>


<?php
fscanf(STDIN, "%d %d", $n, $k);
$ary = explode(" ", fgets(STDIN));
rsort($ary);
$long = 0;

for($i = 0; $i < $k; $i++) {
	$long += $ary[$i];
}
echo $long."\n";

Score : 200 points

Problem Statement

Snuke has N sticks.
The length of the i-th stick is l_i.

Snuke is making a snake toy by joining K of the sticks together.

The length of the toy is represented by the sum of the individual sticks that compose it.
Find the maximum possible length of the toy.

Constraints

1 \leq K \leq N \leq 50

1 \leq l_i \leq 50

l_i is an integer.

Input

Input is given from Standard Input in the following format:

N K
l_1 l_2 l_3 ... l_{N}

Output

Print the answer.

Sample Input 1

5 3
1 2 3 4 5

Sample Output 1

12

You can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.

Sample Input 2

15 14
50 26 27 21 41 7 42 35 7 5 5 36 39 1 45

Sample Output 2

386


<?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();
$P = $in->nextInt();

$A = [];
for ($i = 0;$i < $N;$i++) {
	$A[] = $in->nextInt();
}

$dp = [];
for ($i = 0;$i < $N+1;$i++) {
	$dp[] = [];
	for($j = 0;$j < $N+1;$j++) {
		$dp[][] = [];
		for($k = 0;$k < 2;$k++) {
			$dp[$i][$j][$k] = 0;
		}
	}
}

$dp[0][0][0] = 1;
for ($i = 0;$i < $N;$i++) {
	for($j = 0;$j < $N;$j++) {
		$dp[$i+1][$j][0] += $dp[$i][$j][0];
		$dp[$i+1][$j+1][$A[$i]%2] += $dp[$i][$j][0];
		$dp[$i+1][$j][1] += $dp[$i][$j][1];
		$dp[$i+1][$j+1][($A[$i]+1)%2] += $dp[$i][$j][1];
	}
}
$ans = 0;
for ($i = 0;$i <= $N;$i++) {
	$ans += $dp[$N][$i][$P];
}

$out->println($ans);

?>

Score : 200 points

Problem Statement

There are N bags of biscuits. The i-th bag contains A_i biscuits.

Takaki will select some of these bags and eat all of the biscuits inside.
Here, it is also possible to select all or none of the bags.

He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2.
How many such ways to select bags there are?

Constraints

1 \leq N \leq 50

P = 0 or 1

1 \leq A_i \leq 100

Input

Input is given from Standard Input in the following format:

N P
A_1 A_2 ... A_N

Output

Print the number of ways to select bags so that the total number of biscuits inside is congruent to P modulo 2.

Sample Input 1

2 0
1 3

Sample Output 1

2

There are two ways to select bags so that the total number of biscuits inside is congruent to 0 modulo 2:

Select neither bag. The total number of biscuits is 0.

Select both bags. The total number of biscuits is 4.

Sample Input 2

1 1
50

Sample Output 2

0

Sample Input 3

3 0
1 1 1

Sample Output 3

4

Two bags are distinguished even if they contain the same number of biscuits.

Sample Input 4

45 1
17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26

Sample Output 4

17592186044416


<?php
fscanf(STDIN, "%d %d", $n, $p);
$result = pow(2, int($n-1));
echo $result;


$input1 = fgets(STDIN);
$input2 = fgets(STDIN);

$input1_ary = split(" ",input1);
$input2_ary = split(" ",input2);

$kotae = 0;
foreach($input2_ary as $key => $val){}
  $amari = $val%2;
  if($input1_ary == $amari){
    $kotae++;
  }
}


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

 $s_modi=$s;

for($i=0;$i<strlen($s);$i++){
  $s_modi = substr($s_modi, 0, -1);
  $len = (int)(strlen($s_modi)/2);
  $front = substr($s_modi,0,(strlen($s_modi)-$len));
  $back = substr($s_modi,$len,$len);
  //echo "front ${front} back ${back} \n";
  if($front==$back){
    echo strlen($s_modi)."\n";
    break;
  }
}

Score : 200 points

Problem Statement

We will call a string that can be obtained by concatenating two equal strings an even string.
For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not.

You are given an even string S consisting of lowercase English letters.
Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S.
It is guaranteed that such a non-empty string exists for a given input.

Constraints

2 \leq |S| \leq 200

S is an even string consisting of lowercase English letters.

There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S.

Input

Input is given from Standard Input in the following format:

S

Output

Print the length of the longest even string that can be obtained.

Sample Input 1

abaababaab

Sample Output 1

6

abaababaab itself is even, but we need to delete at least one character.

abaababaa is not even.

abaababa is not even.

abaabab is not even.

abaaba is even. Thus, we should print its length, 6.

Sample Input 2

xxxx

Sample Output 2

2

xxx is not even.

xx is even.

Sample Input 3

abcabcabcabc

Sample Output 3

6

The longest even string that can be obtained is abcabc, whose length is 6.

Sample Input 4

akasakaakasakasakaakas

Sample Output 4

14

The longest even string that can be obtained is akasakaakasaka, whose length is 14.


<?php
fscanf(STDIN, "%s", $str);
$cnt = strlen($str);
for ($i = 1; $i < $cnt; $i++) {
  $str = substr($str, 0, strlen($str)-1);
  if (strlen($str)%2 == 1){
    continue;
  }
  $half_str = substr($str, 0, strlen($str)/2);
  if ($str == $half_str . $half_str) {
    echo strlen($str);
    break;
  }
}


<?php

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

if(count($a_li)%2==0){
  $kisu_gusu_juge = 0;
}else{
  $kisu_gusu_juge = 1;
}

for($i=0;$i<count($a_li);$i++){
  if($i%2 == $kisu_gusu_juge){
    $re .= $a_li[$i];
  }else{
    $re = $a_li[$i].$re;
  }
}

//for($i=0;$i<strlen($re);$i++){
  //echo $re[$i]." ";
//}

Score : 300 points

Problem Statement

You are given an integer sequence of length n, a_1, ..., a_n.
Let us consider performing the following n operations on an empty sequence b.

The i-th operation is as follows:

Append a_i to the end of b.

Reverse the order of the elements in b.

Find the sequence b obtained after these n operations.

Constraints

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

0 \leq a_i \leq 10^9

n and a_i are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print n integers in a line with spaces in between.
The i-th integer should be b_i.

Sample Input 1

4
1 2 3 4

Sample Output 1

4 2 1 3

After step 1 of the first operation, b becomes: 1.

After step 2 of the first operation, b becomes: 1.

After step 1 of the second operation, b becomes: 1, 2.

After step 2 of the second operation, b becomes: 2, 1.

After step 1 of the third operation, b becomes: 2, 1, 3.

After step 2 of the third operation, b becomes: 3, 1, 2.

After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.

After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.

Thus, the answer is 4 2 1 3.

Sample Input 2

3
1 2 3

Sample Output 2

3 1 2

As shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.

Sample Input 3

1
1000000000

Sample Output 3

1000000000

Sample Input 4

6
0 6 7 6 7 0

Sample Output 4

0 6 6 0 7 7


<?php

$n = intval(fgets(STDIN));
$e = array_map('intval', preg_split('/\s/', fgets(STDIN)));

$arr = [];
foreach($e as $idx => $sp) {
    if ($idx % 2 == 0) {
      $arr[] = $sp;
    } else {
      array_unshift($arr, $sp);
    }
}

if ($n % 2 > 0) {
    for($i = $n - 1; $i >= 0; $i--) echo $arr[$i] . ' ';
} else {
    for($i = 0; $i < $n; $i++) echo $arr[$i] . ' ';
}


<?php
$l1 =fgets(STDIN);
$l2 = explode(' ', fgets(STDIN));
for ($i = 0; $i < $l1; $i++) {
 $res[] = $l2[$i];
 $res = array_reverse($res);
}
echo implode(' ', $res);


<?php
  declare(strict_types=1);

  const MOD = 1e9 + 7;

  fscanf(STDIN, "%i", $n);
  $xs = explode(" ", trim(fgets(STDIN)));

  $bucket = [];
  foreach ($xs as $i => $x)
  {
      if (isset($bucket[$x]))
      {
          $dup_l = $bucket[$x];
          $dup_r = $i;
          break;
      }
      $bucket[$x] = $i;
  }

  $inverse = function($x)
  {
      $t = 1;
      $p = MOD - 2;
      while ($p > 0)
      {
          if ($p & 1)
          {
              $t = $t * $x % MOD;
          }

          $x = $x * $x % MOD;
          $p >>= 1;
      }
      return $t;
  };

  $frac = [0 => 1];
  for ($i = 0; $i < $n + 1; ++$i)
  {
      $frac[$i + 1] = $frac[$i] * ($i + 1) % MOD;
  }

  $combination = function($n, $r) use ($inverse, $frac)
  {
      if ($n < $r)
      {
          return 0;
      }

      return $frac[$n] * $inverse($frac[$r] * $frac[$n - $r] % MOD) % MOD;
  };

  $t = $dup_l + $n - $dup_r;
  for ($k = 1; $k <= $n + 1; ++$k)
  {
      echo ($combination($n + 1, $k) - $combination($t, $k - 1) + MOD) % MOD, PHP_EOL;
  }

Score : 600 points

Problem Statement

You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n.
It is known that each of the n integers 1,...,n appears at least once in this sequence.

For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Notes

If the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.

A subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5, while 3,1,2 and 1,10,100 are not.

Constraints

1 \leq n \leq 10^5

1 \leq a_i \leq n

Each of the integers 1,...,n appears in the sequence.

n and a_i are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_{n+1}

Output

Print n+1 lines.
The k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 10^9+7.

Sample Input 1

3
1 2 1 3

Sample Output 1

3
5
4
1

There are three subsequences with length 1: 1 and 2 and 3.

There are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and 2,3.

There are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3.

There is one subsequence with length 4: 1,2,1,3.

Sample Input 2

1
1 1

Sample Output 2

1
1

There is one subsequence with length 1: 1.

There is one subsequence with length 2: 1,1.

Sample Input 3

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

Sample Output 3

32
525
5453
40919
237336
1107568
4272048
13884156
38567100
92561040
193536720
354817320
573166440
818809200
37158313
166803103
166803103
37158313
818809200
573166440
354817320
193536720
92561040
38567100
13884156
4272048
1107568
237336
40920
5456
528
33
1

Be sure to print the numbers modulo 10^9+7.


<?php

$count = trim(fgets(STDIN));

$rec_array = trim(fgets(STDIN));

$parts = explode(" ", $rec_array);

$array = array();

$string = '';
$i = 0;
foreach ($parts as $i => $part)
{
	$i++;

	if ($i % 2 == ($count % 2 == 1))
	{
		$string = trim($part . " " . $string);
	}
	else
	{
		$string = trim($string . " " .$part);
	}
}

if ($i % 2 ==1)
{
}

$string = trim($string);

echo $string."\n";


<?php

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

if ($b<$a){
    echo 'delicious';
}elseif
    ($x>$b-$a){echo 'safe';}else{echo 'dangerous';
    }

Score : 100 points

Problem Statement

Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier.
He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.

Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.

Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.

Write a program that outputs delicious if he found it delicious, safe if he did not found it delicious but did not get a stomachache either, and dangerous if he got a stomachache.

Constraints

1 ≤ X,A,B ≤ 10^9

Input

Input is given from Standard Input in the following format:

X A B

Output

Print delicious if Takahashi found the food delicious; print safe if he neither found it delicious nor got a stomachache; print dangerous if he got a stomachache.

Sample Input 1

4 3 6

Sample Output 1

safe

He ate the food three days after the "best-by" date. It was not delicious or harmful for him.

Sample Input 2

6 5 1

Sample Output 2

delicious

He ate the food by the "best-by" date. It was delicious for him.

Sample Input 3

3 7 12

Sample Output 3

dangerous

He ate the food five days after the "best-by" date. It was harmful for him.


Score : 300 points

Problem Statement

Snuke has N dogs and M monkeys. He wants them to line up in a row.

As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.

How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).
Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.

Constraints

1 ≤ N,M ≤ 10^5

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of possible arrangements, modulo 10^9+7.

Sample Input 1

2 2

Sample Output 1

8

We will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA.

Sample Input 2

3 2

Sample Output 2

12

Sample Input 3

1 8

Sample Output 3

0

Sample Input 4

100000 100000

Sample Output 4

530123477


<?php
$n = intval(fgets(STDIN));
for($i = 0; $i < $n; $i++){
    fscanf(STDIN, "%d%d", $x, $y);
    $X[] = $x-1;
    $Y[] = $y-1;
    $orderX[$i] = $i;
    $orderY[$i] = $i;
}
array_multisort($X, $orderX);
array_multisort($Y, $orderY);

$k = new Kruskal($n);
for($i = 0; $i < $n - 1; $i++){
    $k->connect($orderX[$i] + 1, $orderX[$i+1] + 1, abs($X[$i] - $X[$i+1]));
    $k->connect($orderY[$i] + 1, $orderY[$i+1] + 1, abs($Y[$i] - $Y[$i+1]));
}
echo $k->build();

class Kruskal{
    public $I, $J, $L;
    public $uft;
    function __construct($n){
        $this->uft = new UFT($n);
    }
    function connect($i, $j, $l){
        $this->I[] = $i;
        $this->J[] = $j;
        $this->L[] = $l;
    }
    function build(){
        $total = 0;
        array_multisort($this->L, $this->I, $this->J);
        foreach($this->L as $k => $l){
            if($this->uft->getRoot($this->I[$k]) != $this->uft->getRoot($this->J[$k])){
                $this->uft->unite($this->I[$k], $this->J[$k]);
                $total+=$l;
            }
        }
        return $total;
    }
}

class UFT{
    public $parent;
    public $size;
    public $rank;
    public function __construct($size){
        for($i = 1; $i <= $size; $i++){
            $this->size[$i] = 1;
            $this->rank[$i] = 1;
            $this->parent[$i] = 0;
        }
    }
    public function dump(){
        o("--------------");
        o($this->parent);
        o($this->size);
        o($this->rank);
    }
    public function getRoot($i){
        if($this->parent[$i] == 0){
            return $i;
        }else{
            return $this->getRoot($this->parent[$i]);
        }
    }
    public function unite($i, $j){
        $rootI = $this->getRoot($j);
        $rootJ = $this->getRoot($i);
        if($rootJ == $rootI)return false;//元から同じグループ
        if($this->rank[$rootI] > $this->rank[$rootJ])list($rootI, $rootJ) = [$rootJ, $rootI];//Rank(J)>Rank(I)に揃えておく
        $this->parent[$rootI] = $rootJ;
        if($this->rank[$rootI] == $this->rank[$rootJ]){
            $this->rank[$rootJ]++;
        }
        $this->size[$rootJ]+=$this->size[$rootI];
        $this->size[$rootI] = '*';//不要な情報となるので潰す/デバッグ出力向けに*を入れている
        $this->rank[$rootI] = '*';//同上
    }
    public function size($i){return $this->size[$this->getRoot($i)];}
    public function isUnion($i, $j){return $this->getRoot($i) == $this->getRoot($j);}
}

Score : 500 points

Problem Statement

There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.

You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads.

Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?

Constraints

2 ≤ N ≤ 10^5

0 ≤ x_i,y_i ≤ 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_N y_N

Output

Print the minimum necessary amount of money in order to build roads so that it will be possible to travel between every pair of towns by traversing roads.

Sample Input 1

3
1 5
3 9
7 8

Sample Output 1

3

Build a road between Towns 1 and 2, and another between Towns 2 and 3. The total cost is 2+1=3 yen.

Sample Input 2

6
8 3
4 9
12 19
18 1
13 5
7 6

Sample Output 2

8


Score : 300 points

Problem Statement

Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:

For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.

There is a string s consisting of lowercase English letters.
Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same.
Find the minimum necessary number of operations.

Constraints

1 ≤ |s| ≤ 100

s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

Print the minimum necessary number of operations to achieve the objective.

Sample Input 1

serval

Sample Output 1

3

One solution is: serval → srvvl → svvv → vvv.

Sample Input 2

jackal

Sample Output 2

2

One solution is: jackal → aacaa → aaaa.

Sample Input 3

zzz

Sample Output 3

0

All the characters in s are the same from the beginning.

Sample Input 4

whbrjpjyhsrywlqjxdbrbaomnw

Sample Output 4

8

In 8 operations, he can change s to rrrrrrrrrrrrrrrrrr.


<?php

$cat_count = trim(fgets(STDIN));

$string = trim(fgets(STDIN));

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

$counts = array();

$MAX = 0;

foreach ($array as $item)
{
	$counts[$item] ++;
}

ksort($counts);

if (count($counts) > 2)
{
	echo "No\n";
	die();
}

$high		 = max(array_keys($counts));
$high_count	 = $counts[$high];
$low		 = max(array_keys($counts)) - 1;
$low_count	 = $counts[$low];

//all cats say the same thing
if ($low_count === null)
{
	//all unique -> number is one less than number of cats
	if (($high + 1) == $cat_count)
	{
		echo "Yes\n";
		die();
	}

	//all non-unique
	if ($high <= ($cat_count / 2))
	{
		echo "Yes\n";
		die();
	}
}
else
{
	$unique_hat_count = $low_count;

	$total_hat_colors = $high;

	$non_unqiue_colors	 = $total_hat_colors - $unique_hat_count;
	$non_unqiue_cats	 = $cat_count - $unique_hat_count;

	if (($non_unqiue_cats != 0) && ($non_unqiue_colors == 0))
	{
		echo "NO\n";
		die();
	}

		if (($non_unqiue_cats == 0) && ($non_unqiue_colors != 0))
	{
		echo "NO\n";
		die();
	}

	if ($non_unqiue_colors <= ($non_unqiue_cats / 2))
	{
		echo "Yes\n";
		die();
	}
}

echo "No\n";

Score : 700 points

Problem Statement

There are N cats.
We number them from 1 through N.

Each of the cats wears a hat.
Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."

Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.

Constraints

2 ≤ N ≤ 10^5

1 ≤ a_i ≤ N-1

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print Yes if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print No otherwise.

Sample Input 1

3
1 2 2

Sample Output 1

Yes

For example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it is consistent with the remarks of the cats.

Sample Input 2

3
1 1 2

Sample Output 2

No

From the remark of cat 1, we can see that cat 2 and 3 wear hats of the same color.
Also, from the remark of cat 2, we can see that cat 1 and 3 wear hats of the same color.
Therefore, cat 1 and 2 wear hats of the same color, which contradicts the remark of cat 3.

Sample Input 3

5
4 3 4 3 4

Sample Output 3

No

Sample Input 4

3
2 2 2

Sample Output 4

Yes

Sample Input 5

4
2 2 2 2

Sample Output 5

Yes

Sample Input 6

5
3 3 3 3 3

Sample Output 6

No


<?php
$input = rtrim(fgets(STDIN));
$number = str_replace(' ', '', $input);
if ($number % 4 === 0) {
    echo 'YES';
} else {
    echo "NO";
}

Score : 100 points

Problem Statement

AtCoDeer has three cards, one red, one green and one blue.

An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.

We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.

Is this integer a multiple of 4?

Constraints

1 ≤ r, g, b ≤ 9

Input

Input is given from Standard Input in the following format:

r g b

Output

If the three-digit integer is a multiple of 4, print YES (case-sensitive); otherwise, print NO.

Sample Input 1

4 3 2

Sample Output 1

YES

432 is a multiple of 4, and thus YES should be printed.

Sample Input 2

2 3 4

Sample Output 2

NO

234 is not a multiple of 4, and thus NO should be printed.


<?php
$line          = fgets(STDIN);
$numbers       = explode(' ', $line);
$number_string = $numbers[0] . $numbers[1] . $numbers[2];

if ($number % 4 === 0) {
    print 'YES';
} else {
    print 'NO';
}


<?php
fscanf(STDIN, "%d %d %d", $r, $g, $b);
$array = [$r, $g, $b];
$str = implode($array);
if((int)$str % 4 === 0){
  echo 'YES';
}else{
  echo 'NO';
}
?>


<?php
list($n) = ints();
$a = ints();
echo max($a) - min($a);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

Score : 200 points

Problem Statement

It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.

There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses.

Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.

Constraints

1 ≤ N ≤ 100

0 ≤ a_i ≤ 1000

a_i is an integer.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum distance to be traveled.

Sample Input 1

4
2 3 7 9

Sample Output 1

7

The travel distance of 7 can be achieved by starting at coordinate 9 and traveling straight to coordinate 2.

It is not possible to do with a travel distance of less than 7, and thus 7 is the minimum distance to be traveled.

Sample Input 2

8
3 1 4 1 5 9 2 6

Sample Output 2

8

There may be more than one house at a position.


<?php
fscanf(STDIN, "%d %d", $a, $b);
$ans = $a+$b;
if ($ans >= 10){
    print("error\n");
} else {
    print("$ans\n");
}
?>

Score : 100 points

Problem Statement

You are given two integers A and B as the input. Output the value of A + B.

However, if A + B is 10 or greater, output error instead.

Constraints

A and B are integers.

1 ≤ A, B ≤ 9

Input

Input is given from Standard Input in the following format:

A B

Output

If A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B.

Sample Input 1

6 3

Sample Output 1

9

Sample Input 2

6 4

Sample Output 2

error


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

  $v=[];
  for($i=0;$i<strlen($s);$i++){
    if(isset($v[$s[$i]])) {
      echo "no".PHP_EOL;
      exit;
    }
    $v[$s[$i]]=true;
  }
  echo "yes".PHP_EOL;

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.

Constraints

2 ≤ |S| ≤ 26, where |S| denotes the length of S.

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If all the characters in S are different, print yes (case-sensitive); otherwise, print no.

Sample Input 1

uncopyrightable

Sample Output 1

yes

Sample Input 2

different

Sample Output 2

no

Sample Input 3

no

Sample Output 3

yes


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

$re = array();
$zero_flag = true;
for($i=0;$i<$n;$i++){
    fscanf(STDIN,"%d",$s);
    $s_li[] = $s;
    if($s%10!=0){
      $zero_flag = false;
    }
 }

if($zero_flag){
  echo "0\n";
  exit;
}

sort($s_li);
$sum = array_sum($s_li);
$i=0;
$sum_re = $sum;
while($sum_re%10==0){
  $sum_re = $sum;
  $sum_re -= $s_li[$i];
  $i++;
}
//print_r($s_li);

echo $sum_re."\n";

Score : 300 points

Problem Statement

You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well.

However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?

Constraints

All input values are integers.

1 ≤ N ≤ 100

1 ≤ s_i ≤ 100

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the maximum value that can be displayed as your grade.

Sample Input 1

3
5
10
15

Sample Output 1

25

Your grade will be 25 if the 10-point and 15-point questions are answered correctly and the 5-point question is not, and this grade will be displayed correctly. Your grade will become 30 if the 5-point question is also answered correctly, but this grade will be incorrectly displayed as 0.

Sample Input 2

3
10
10
15

Sample Output 2

35

Your grade will be 35 if all the questions are answered correctly, and this grade will be displayed correctly.

Sample Input 3

3
10
20
30

Sample Output 3

0

Regardless of whether each question is answered correctly or not, your grade will be a multiple of 10 and displayed as 0.