<?php
  fscanf(STDIN,"%s",$s);
$kisu = array('R','U','D');
$gusu = array('L','U','D');
$flag = true;

for($i=0;$i<(int)(strlen($s));$i++){
   if($i%2==0){

     if(!in_array($s[$i],$kisu)){
       //echo $s[$i];

       $flag = false;
       break;
     }
   }else{
     if(!in_array($s[$i],$gusu)){
       $flag = false;
       break;
     }
   }
}

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

Score: 200 points

Problem Statement

Takahashi will do a tap dance. The dance is described by a string S where each character is L, R, U, or D. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character.

S is said to be easily playable if and only if it satisfies both of the following conditions:

Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is R, U, or D.

Every character in an even position (2-nd, 4-th, 6-th, \ldots) is L, U, or D.

Your task is to print Yes if S is easily playable, and No otherwise.

Constraints

S is a string of length between 1 and 100 (inclusive).

Each character of S is L, R, U, or D.

Input

Input is given from Standard Input in the following format:

S

Output

Print Yes if S is easily playable, and No otherwise.

Sample Input 1

RUDLUDR

Sample Output 1

Yes

Every character in an odd position (1-st, 3-rd, 5-th, 7-th) is R, U, or D.

Every character in an even position (2-nd, 4-th, 6-th) is L, U, or D.

Thus, S is easily playable.

Sample Input 2

DULL

Sample Output 2

No

The 3-rd character is not R, U, nor D, so S is not easily playable.

Sample Input 3

UUUUUUUUUUUUUUU

Sample Output 3

Yes

Sample Input 4

ULURU

Sample Output 4

No

Sample Input 5

RDULULDURURLRDULRLR

Sample Output 5

Yes


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

$arr = str_split($word);

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

for($i=0;$i<count($arr);$i++) {
  if($i % 2 == 0) {
    array_push($a, $arr[$i]);
  } else {
    array_push($b, $arr[$i]);
  }
}

if(in_array('R', $a) && in_array('L', $b)) {
  echo 'No';
} else {
  echo 'Yes';
}

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

Submitted source-code file size, in bytes.

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

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


<?php
$word = trim(fgets(STDIN));
$word_len = strlen($word);
$odd = (R,U,D);
$even = (L,U,D);
for($i = 0; $i < $word_len; $i++){
	$word_i = substr($word, $i, 1);
  	if($i%2 == 0 && in_array($word_i, $odd) == false){
    	echo "No";
        break;
    }elseif($i%2 == 1 && in_array($word_i, $even) == false){
        echo "No";
        break;
    }elseif($i == $word_len - 1){
      	echo "Yes";
    }

}
?>


<?php

 $s = str_split(trim(fgets(STDIN)));
//var_dump($s);
foreach($s as $key => $val){
if($key%2==0&&$val=='L'){
echo 'No';
 exit ;
}
  if($key%2==1&&$val=='R'){
echo 'No';
 exit ;
}
}
echo 'Yes' ;


<?php
fscanf(STDIN, '%d %d %d', $cnt, $def, $solve);
$points = array_fill(1, $cnt, $def-$solve);
for ($i=0; $i < $solve; $i++) {
    fscanf(STDIN, '%d', $idx);
    $points[$idx]++;
}
$len = count($points);
for ($i=1; $i <= $len; $i++) {
    if ($points[$i] > 0) {
        echo "Yes\n";
    } else {
        echo "No\n";
    }
}

Score: 300 points

Problem Statement

Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows.

A game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points.

When a player correctly answers a question, each of the other N-1 players receives minus one (-1) point. There is no other factor that affects the players' scores.

At the end of a game, the players with 0 points or lower are eliminated, and the remaining players survive.

In the last game, the players gave a total of Q correct answers, the i-th of which was given by Player A_i.
For Kizahashi, write a program that determines whether each of the N players survived this game.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq K \leq 10^9

1 \leq Q \leq 10^5

1 \leq A_i \leq N\ (1 \leq i \leq Q)

Input

Input is given from Standard Input in the following format:

N K Q
A_1
A_2
.
.
.
A_Q

Output

Print N lines. The i-th line should contain Yes if Player i survived the game, and No otherwise.

Sample Input 1

6 3 4
3
1
3
2

Sample Output 1

No
No
Yes
No
No
No

In the beginning, the players' scores are (3, 3, 3, 3, 3, 3).

Player 3 correctly answers a question. The players' scores are now (2, 2, 3, 2, 2, 2).

Player 1 correctly answers a question. The players' scores are now (2, 1, 2, 1, 1, 1).

Player 3 correctly answers a question. The players' scores are now (1, 0, 2, 0, 0, 0).

Player 2 correctly answers a question. The players' scores are now (0, 0, 1, -1, -1, -1).

Players 1, 2, 4, 5 and 6, who have 0 points or lower, are eliminated, and Player 3 survives this game.

Sample Input 2

6 5 4
3
1
3
2

Sample Output 2

Yes
Yes
Yes
Yes
Yes
Yes

Sample Input 3

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

Sample Output 3

No
No
No
No
Yes
No
No
No
Yes
No


<?php

$n = trim(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));
$b = explode(' ', trim(fgets(STDIN)));
$c = explode(' ', trim(fgets(STDIN)));

$sum = array_sum($b);
for ($i = 0; $i < $n - 1; $i++) {
    if ($a[$i] + 1 === (int)$a[$i + 1]) {
        $sum += $c[$a[$i] - 1];
    }
}

echo $sum;

Score : 200 points

Problem Statement

Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.

The i-th dish (1 \leq i \leq N) he ate was Dish A_i.

When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.

Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.

Find the sum of the satisfaction points he gained.

Constraints

All values in input are integers.

2 \leq N \leq 20

1 \leq A_i \leq N

A_1, A_2, ..., A_N are all different.

1 \leq B_i \leq 50

1 \leq C_i \leq 50

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}

Output

Print the sum of the satisfaction points Takahashi gained, as an integer.

Sample Input 1

3
3 1 2
2 5 4
3 6

Sample Output 1

14

Takahashi gained 14 satisfaction points in total, as follows:

First, he ate Dish 3 and gained 4 satisfaction points.

Next, he ate Dish 1 and gained 2 satisfaction points.

Lastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.

Sample Input 2

4
2 3 4 1
13 5 8 24
45 9 15

Sample Output 2

74

Sample Input 3

2
1 2
50 50
50

Sample Output 3

150


<?php
# 数値の入力
fscanf(STDIN, "%d", $data1);
$data2 = trim(fgets(STDIN));
$a = explode(" ", $data2);

$anser = $a[$data1-2];

for($i=0; $i<$data1-1; $i++){
    if($i!=0){
        if($a[$i]>=$a[$i-1]){
            $anser += $a[$i-1];
        }else{
            $anser += $a[$i];
        }
    }else{
        $anser += $a[$i];
    }
}

echo $anser;
?>

Score : 300 points

Problem Statement

There is an integer sequence A of length N whose values are unknown.

Given is an integer sequence B of length N-1 which is known to satisfy the following:

B_i \geq \max(A_i, A_{i+1})

Find the maximum possible sum of the elements of A.

Constraints

All values in input are integers.

2 \leq N \leq 100

0 \leq B_i \leq 10^5

Input

Input is given from Standard Input in the following format:

N
B_1 B_2 ... B_{N-1}

Output

Print the maximum possible sum of the elements of A.

Sample Input 1

3
2 5

Sample Output 1

9

A can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.

Sample Input 2

2
3

Sample Output 2

6

Sample Input 3

6
0 153 10 10 23

Sample Output 3

53


Score : 400 points

Problem Statement

There are N people standing in a queue from west to east.

Given is a string S of length N representing the directions of the people.
The i-th person from the west is facing west if the i-th character of S is L, and east if that character of S is R.

A person is happy if the person in front of him/her is facing the same direction.
If no person is standing in front of a person, however, he/she is not happy.

You can perform the following operation any number of times between 0 and K (inclusive):

Operation: Choose integers l and r such that 1 \leq l \leq r \leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.

What is the maximum possible number of happy people you can have?

Constraints

N is an integer satisfying 1 \leq N \leq 10^5.

K is an integer satisfying 1 \leq K \leq 10^5.

|S| = N

Each character of S is L or R.

Input

Input is given from Standard Input in the following format:

N K
S

Output

Print the maximum possible number of happy people after at most K operations.

Sample Input 1

6 1
LRLRRL

Sample Output 1

3

If we choose (l, r) = (2, 5), we have LLLRLL, where the 2-nd, 3-rd, and 6-th persons from the west are happy.

Sample Input 2

13 3
LRRLRLRRLRLLR

Sample Output 2

9

Sample Input 3

10 1
LLLLLRRRRR

Sample Output 3

9

Sample Input 4

9 2
RRRLRLRLL

Sample Output 4

7


<?php

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

list($n, $k) = fget_array();
$str = fget_array()[0];
$count = [];
$result = 0;
for ($i = 1, $j = 0; $i <= $n; $i++) {
    $s = $str[$i] ?? null;
    $prev = $str[$i - 1];
    if ($prev === $s) {
        $j++;
    } else {
        $count[] = $j;
        $result += $j;
        $j = 0;
    }
    $prev = $s;
}

$limit = count($count);
$result += min($k, $limit) * 2;
$result -= [2, 1, 0][max(0, min(2, $limit - $k))];
echo $result;
?>


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

$count = 0;
for($i=0; $i < 3; $i++){
    if($arr_s[$i] == $arr_t[$i]){
        $count++;
    }
}
echo $count;
?>

Score : 100 points

Problem Statement

You will be given a string S of length 3 representing the weather forecast for three days in the past.

The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.

You will also be given a string T of length 3 representing the actual weather on those three days.

The i-th character (1 \leq i \leq 3) of S represents the actual weather on the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.

Print the number of days for which the forecast was correct.

Constraints

S and T are strings of length 3 each.

S and T consist of S, C, and R.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print the number of days for which the forecast was correct.

Sample Input 1

CSS
CSR

Sample Output 1

2

For the first day, it was forecast to be cloudy, and it was indeed cloudy.

For the second day, it was forecast to be sunny, and it was indeed sunny.

For the third day, it was forecast to be sunny, but it was rainy.

Thus, the forecast was correct for two days in this case.

Sample Input 2

SSR
SSR

Sample Output 2

3

Sample Input 3

RRR
SSS

Sample Output 3

0


Score : 200 points

Problem Statement

Takahashi's house has only one socket.

Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.

One power strip with A sockets can extend one empty socket into A empty sockets.

Find the minimum number of power strips required.

Constraints

All values in input are integers.

2 \leq A \leq 20

1 \leq B \leq 20

Input

Input is given from Standard Input in the following format:

A B

Output

Print the minimum number of power strips required.

Sample Input 1

4 10

Sample Output 1

3

3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.

Sample Input 2

8 9

Sample Output 2

2

2 power strips, each with 8 sockets, extend the socket into 15 empty sockets.

Sample Input 3

8 8

Sample Output 3

1


<?php
fscanf(STDIN, '%d %d', $a, $b);
if ($b == 1) {
  echo "0";
  exit;
}

$sum_plug = 0;
$i = 0;
while ($sum_plug < $b) {
  if ($i == 0) {
    $sum_plug += $a;
  } else {
    $sum_plug += $a - 1;
  }
  $i++;
}

echo $i;


<?php
fscanf(STDIN, '%d %d', $a, $b);
if ($b <= 1) {
  echo "0";
  exit;
}
if ($b % $a == 0) {
  echo $b / $a;
} else {
  echo (int)round($b / $a) + 1;
}


<?php
fscanf(STDIN, '%d %d', $a, $b);
echo (int)ceil($b/$a);


<?php

$hoge = explode(' ', trim(fgets(STDIN)));

$count = 1;
$tmp = (int)$hoge[0];
while(1) {
	if($tmp >= (int)$hoge[1]) break;

	$count++;
	$tmp += (int)$hoge[0];
	$tmp -= 1;

}

echo $count."\n";


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

$count = $a_b[0];
$number = 100;

$tap = 1;
for ($i = 0; $i < $number; $i++) {
     if($count >= $a_b[1]){
         break;
     }
     $count += $a_b[0] - 1;
     $tap++;
}

echo $tap;


Score : 300 points

Problem Statement

There are N squares arranged in a row from left to right.

The height of the i-th square from the left is H_i.

You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.

Find the maximum number of times you can move.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq H_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
H_1 H_2 ... H_N

Output

Print the maximum number of times you can move.

Sample Input 1

5
10 4 8 7 3

Sample Output 1

2

By landing on the third square from the left, you can move to the right twice.

Sample Input 2

7
4 4 5 6 6 5 5

Sample Output 2

3

By landing on the fourth square from the left, you can move to the right three times.

Sample Input 3

4
1 2 3 4

Sample Output 3

0


<?php
  $N = fgets(STDIN);
  echo $N*($N-1)/2;
  ?>

Score : 400 points

Problem Statement

For an integer N, we will choose a permutation \{P_1, P_2, ..., P_N\} of \{1, 2, ..., N\}.

Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.

Find the maximum possible value of M_1 + M_2 + \cdots + M_N.

Constraints

N is an integer satisfying 1 \leq N \leq 10^9.

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum possible value of M_1 + M_2 + \cdots + M_N.

Sample Input 1

2

Sample Output 1

1

When the permutation \{P_1, P_2\} = \{2, 1\} is chosen, M_1 + M_2 = 1 + 0 = 1.

Sample Input 2

13

Sample Output 2

78

Sample Input 3

1

Sample Output 3

0


Score : 200 points

Problem Statement

Today is August 24, one of the five Product Days in a year.

A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day):

d_1 \geq 2

d_{10} \geq 2

d_1 \times d_{10} = m

Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D.

In Takahashi Calendar, how many Product Days does a year have?

Constraints

All values in input are integers.

1 \leq M \leq 100

1 \leq D \leq 99

Input

Input is given from Standard Input in the following format:

M D

Output

Print the number of Product Days in a year in Takahashi Calender.

Sample Input 1

15 40

Sample Output 1

10

There are 10 Product Days in a year, as follows (m-d denotes Month m, Day d):

4-22

6-23

6-32

8-24

9-33

10-25

12-26

12-34

14-27

15-35

Sample Input 2

12 31

Sample Output 2

5

Sample Input 3

1 1

Sample Output 3

0


<?php

$n = trim(fgets(STDIN));
$m = explode(' ', trim(fgets(STDIN)));
asort($m);

while (count($m) > 1) {
    $x = array_shift($m);
    $y = array_shift($m);
    $m[] = ($x + $y) / 2;
}

echo current($m) . ".\n";

Score : 300 points

Problem Statement

You have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \leq i \leq N) is v_i.

When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.

After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Constraints

2 \leq N \leq 50

1 \leq v_i \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
v_1 v_2 \ldots v_N

Output

Print a decimal number (or an integer) representing the maximum possible value of the last ingredient remaining.

Your output will be judged correct when its absolute or relative error from the judge's output is at most 10^{-5}.

Sample Input 1

2
3 4

Sample Output 1

3.5

If you start with two ingredients, the only choice is to put both of them in the pot. The value of the ingredient resulting from the ingredients of values 3 and 4 is (3 + 4) / 2 = 3.5.

Printing 3.50001, 3.49999, and so on will also be accepted.

Sample Input 2

3
500 300 200

Sample Output 2

375

You start with three ingredients this time, and you can choose what to use in the first composition. There are three possible choices:

Use the ingredients of values 500 and 300 to produce an ingredient of value (500 + 300) / 2 = 400. The next composition will use this ingredient and the ingredient of value 200, resulting in an ingredient of value (400 + 200) / 2 = 300.

Use the ingredients of values 500 and 200 to produce an ingredient of value (500 + 200) / 2 = 350. The next composition will use this ingredient and the ingredient of value 300, resulting in an ingredient of value (350 + 300) / 2 = 325.

Use the ingredients of values 300 and 200 to produce an ingredient of value (300 + 200) / 2 = 250. The next composition will use this ingredient and the ingredient of value 500, resulting in an ingredient of value (250 + 500) / 2 = 375.

Thus, the maximum possible value of the last ingredient remaining is 375.

Printing 375.0 and so on will also be accepted.

Sample Input 3

5
138 138 138 138 138

Sample Output 3

138


<?php
  fscanf(STDIN, '%d %d', $a, $b);
  $sum = $a + $b;
  $mul = $a * $b;
  $dif = $a - $b;

  echo max($sum, $mul, $dif);

Score : 100 points

Problem Statement

We have two integers: A and B.

Print the largest number among A + B, A - B, and A \times B.

Constraints

All values in input are integers.

-100 \leq A,\ B \leq 100

Input

Input is given from Standard Input in the following format:

A B

Output

Print the largest number among A + B, A - B, and A \times B.

Sample Input 1

-13 3

Sample Output 1

-10

The largest number among A + B = -10, A - B = -16, and A \times B = -39 is -10.

Sample Input 2

1 -33

Sample Output 2

34

The largest number among A + B = -32, A - B = 34, and A \times B = -33 is 34.

Sample Input 3

13 3

Sample Output 3

39

The largest number among A + B = 16, A - B = 10, and A \times B = 39 is 39.


<?php
fscanf(STDIN, "%d %d", $k,$x);
$arr = array();
for ($i=0; $i < $k; $i++) {
  $arr[] = $x + $i;
}
for ($i=1; $i < $k; $i++) {
  $arr[] = $x - $i;
}
sort($arr);
$str = "";
foreach ($arr as $value) {
  $str .= "{$value} ";
}
echo trim($str);
?>

Score : 200 points

Problem Statement

There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.

Among them, some K consecutive stones are painted black, and the others are painted white.

Additionally, we know that the stone at coordinate X is painted black.

Print all coordinates that potentially contain a stone painted black, in ascending order.

Constraints

1 \leq K \leq 100

0 \leq X \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K X

Output

Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.

Sample Input 1

3 7

Sample Output 1

5 6 7 8 9

We know that there are three stones painted black, and the stone at coordinate 7 is painted black. There are three possible cases:

The three stones painted black are placed at coordinates 5, 6, and 7.

The three stones painted black are placed at coordinates 6, 7, and 8.

The three stones painted black are placed at coordinates 7, 8, and 9.

Thus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8, and 9.

Sample Input 2

4 0

Sample Output 2

-3 -2 -1 0 1 2 3

Negative coordinates can also contain a stone painted black.

Sample Input 3

1 100

Sample Output 3

100


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

$arr = [];

for(; $n>0; $n--){
  fscanf(STDIN, "%s", $s);

  $split = str_split($s);
  sort($split);
  $sorted = implode('', $split);

  $arr[$sorted] = isset($arr[$sorted])? $arr[$sorted]+1 : 1;
}

$cnt = 0;
foreach($arr as $str){
  if($str === 1) continue;
  $cnt += array_sum(array_map(function($v){ return $v-1; },range(2,$str)));
}

echo $cnt, "\n";

Score : 300 points

Problem Statement

We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.

For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.

Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Constraints

2 \leq N \leq 10^5

s_i is a string of length 10.

Each character in s_i is a lowercase English letter.

s_1, s_2, \ldots, s_N are all distinct.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Sample Input 1

3
acornistnt
peanutbomb
constraint

Sample Output 1

1

s_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.

Sample Input 2

2
oneplustwo
ninemodsix

Sample Output 2

0

If there is no pair i, j such that s_i is an anagram of s_j, print 0.

Sample Input 3

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

Sample Output 3

4

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.


<?php

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

    for ($i = 0; $i <= $num; $i++) {
       $hoge[] = fgets(STDIN);
    }

	$res = 0;

	for  ($i = 0; $i < $num; $i++) {
      $word = str_split($hoge[$i]);
      sort($word);

      for  ($j = $i+1; $j < $num; $j++) {
        $anagram = str_split($hoge[$j]);
        sort($anagram);
        if($word === $anagram) $res++;
      }

    }
	echo $res;
  ?>


<?php
fscanf(STDIN, "%d", $count);
$lines = [];
for ($i = 0; $i < $count; $i++) {
    $text = trim(fgets(STDIN));
    $chars = str_split((string) $text);
    sort($chars);
    $lines[] = implode('', $chars);
}

//print_r($lines);

$uniques = array_unique($lines);
//print_r($uniques);

$match_count = 0;
foreach ($uniques as $search) {
    $search_count = 0;
    foreach ($lines as $line) {
      	//print_r([$search, $line]);
        if ($search === $line) {
            $search_count += 1;
        }
    }

    if ($search_count == 1) {
        $search_count = 0;
    }
    if ($search_count == 2) {
        $search_count = 1;
    }

    $match_count += $search_count;
}

echo $match_count . "\n";


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

$arr = [];

for(; $n>0; $n--){
  fscanf(STDIN, "%d %d", $a, $b);

  $arr[] = [
    'day' => $a,
    'money' => $b,
  ];
}

$c = array_column($arr, 'money');
array_multisort($c, SORT_ASC, $arr);

$money = 0;
for($i=$m; $i>0; $i--){

  while($job = array_pop($arr)){
    if($job['day'] <= $i) {
      $money += $job['money'];
      break;
    }
  }

}

echo $money, "\n";

Score : 400 points

Problem Statement

There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.

You can take and complete at most one of these jobs in a day.

However, you cannot retake a job that you have already done.

Find the maximum total reward that you can earn no later than M days from today.

You can already start working today.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq A_i \leq 10^5

1 \leq B_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the maximum total reward that you can earn no later than M days from today.

Sample Input 1

3 4
4 3
4 1
2 2

Sample Output 1

5

You can earn the total reward of 5 by taking the jobs as follows:

Take and complete the first job today. You will earn the reward of 3 after four days from today.

Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.

Sample Input 2

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

Sample Output 2

10

Sample Input 3

1 1
2 1

Sample Output 3

0


<?php

$str = trim(fgets(STDIN));
list ($n, $m) = array_map("intval", explode(" ", $str));

$array = [];
for ($i=0; $i<$n; $i++) {
    $tmpStr = trim(fgets(STDIN));
    list ($day, $reward) = array_map("intval", explode(" ", $tmpStr));
    // 報酬が多い順、日数が少ない順にsortして、順番に受けていく
    // 残り日数的に受けられない仕事はスキップ

    if ( !isset($array[$day]) ) {
        $array[$day] = [];
    }
    $array[$day][] = $reward;
}

ksort($array);

$result = 0;
$queue = new SplPriorityQueue();
for ($i=$m-1; 0<=$i; $i--) {
    $remain = $m-$i;

    if ( isset($array[$remain]) ) {
        foreach ($array[$remain] as $reward) {
            $queue->insert($reward, $reward);
        }
    }

    if (!$queue->isEmpty()) {
        $result += $queue->extract();
    }
}

echo "$result\n";


Score : 100 points

Problem Statement

We have two bottles for holding water.

Bottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water.

Bottle 2 contains C milliliters of water.

We will transfer water from Bottle 2 to Bottle 1 as much as possible.

How much amount of water will remain in Bottle 2?

Constraints

All values in input are integers.

1 \leq B \leq A \leq 20

1 \leq C \leq 20

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the integer representing the amount of water, in milliliters, that will remain in Bottle 2.

Sample Input 1

6 4 3

Sample Output 1

1

We will transfer two milliliters of water from Bottle 2 to Bottle 1, and one milliliter of water will remain in Bottle 2.

Sample Input 2

8 3 9

Sample Output 2

4

Sample Input 3

12 3 7

Sample Output 3

0


<?php
$inputs = explode(' ', fgets(STDIN));
$diff = ($inputs[1] + $inputs[2]) - $inputs[0];
echo $diff > 0 ? $diff : 0;


<?php
const INPUT_DELIMITER = " ";

// 標準入力
$input = fgets(STDIN);
$inputArray = explode(INPUT_DELIMITER, $input);

$A = $inputArray[0];
$B = $inputArray[1];
$C = $inputArray[2];

$Ans = $C - ($A - $B);

if ($Ans >= 0) {
    echo $Ans;
} else {
    echo 0;
}


<?php

  	$val = array(
  		'R' => 1,
  		'L' => -1
  	);

	fscanf(STDIN, "%s", $S);
	$strArray = str_split($S);
	$resultArray = array_fill(0, count($strArray), 0);

	$i = 0;
	while ($i < count($strArray)) {

      $count = 0;
      $k = $i;

      while (true) {
        $k += $val[$strArray[$i]];
        $count++;

        if ($strArray[$k] != $strArray[$i]) {
          if ($count % 2 == 0) {
            $resultArray[$k]++;
            break;
          } else {
            $resultArray[$k+(0-$val[$strArray[$i]])]++;
            break;
          }
        }
      }

      $i++;
    }

     echo (implode(" ", $resultArray));
?>

Score : 400 points

Problem Statement

Given is a string S consisting of L and R.

Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left.

The character written on the leftmost square is always R, and the character written on the rightmost square is always L.

Initially, one child is standing on each square.

Each child will perform the move below 10^{100} times:

Move one square in the direction specified by the character written in the square on which the child is standing. L denotes left, and R denotes right.

Find the number of children standing on each square after the children performed the moves.

Constraints

S is a string of length between 2 and 10^5 (inclusive).

Each character of S is L or R.

The first and last characters of S are R and L, respectively.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of children standing on each square after the children performed the moves, in order from left to right.

Sample Input 1

RRLRL

Sample Output 1

0 1 2 1 1

After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.

After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.

After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.

Sample Input 2

RRLLLLRLRRLL

Sample Output 2

0 3 3 0 0 0 1 1 0 2 2 0

Sample Input 3

RRRLLRLLRRRLLLLL

Sample Output 3

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


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

$count = count($arr);
$children = [];
for ($i = 0; $i < $count; $i++) {
  $children[$i] = 1;
}

$number = 2;//pow(10, 100);
for($i = 0; $i < $count; $i++) {

  $k = 0;
  $now = $i;
  while($k < $number) {
    if($arr[$now] === "R"){
      $now += 1;
    } else if($arr[$now] === "L") {
      $now -= 1;
    }
    $k++;
  }

  $children[$i] -= 1;
  $children[$now] += 1;
}

echo implode(" ", $children);


<?php
fscanf(STDIN, "%d %d", $n, $k);
$list = explode(" ", trim(fgets(STDIN)));
$total=array_sum($list);

//約数探し
for($i=$total; $i>=0; $i--){
  if($total%$i==0){
    //約数なら
    $modList=array();
    foreach($list as $v){
      if($v%$i!=0){
  		$modList[count($modList)]=$v%$i;
      }
	}
    sort($modList);

    $tmp=0;
    $sum=0;
    $endKey=count($modList)-1;
    for($j=0; $modList[$j]!=0; $j++){
      $sum+=$modList[$j];
      if(($modList[$endKey]+$tmp+$modList[$j])>=$i){
        $modList[$endKey]=0;
        $tmp=($modList[$endKey]+$tmp+$modList[$j])%$i;
        $endKey--;
      }else{
        $modList[$endKey]+=$modList[$j];
      }
    }
    //sumがk（移動上限）以下なら、iを表示して、終了
    if($sum <= $k){
      echo $i;
      exit;
    }
  }
}

Score : 500 points

Problem Statement

We have a sequence of N integers: A_1, A_2, \cdots, A_N.

You can perform the following operation between 0 and K times (inclusive):

Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element.

Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.

Constraints

2 \leq N \leq 500

1 \leq A_i \leq 10^6

0 \leq K \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_{N-1} A_{N}

Output

Print the maximum possible positive integer that divides every element of A after the operations.

Sample Input 1

2 3
8 20

Sample Output 1

7

7 will divide every element of A if, for example, we perform the following operation:

Choose i = 2, j = 1. A becomes (7, 21).

We cannot reach the situation where 8 or greater integer divides every element of A.

Sample Input 2

2 10
3 5

Sample Output 2

8

Consider performing the following five operations:

Choose i = 2, j = 1. A becomes (2, 6).

Choose i = 2, j = 1. A becomes (1, 7).

Choose i = 2, j = 1. A becomes (0, 8).

Choose i = 2, j = 1. A becomes (-1, 9).

Choose i = 1, j = 2. A becomes (0, 8).

Then, 0 = 8 \times 0 and 8 = 8 \times 1, so 8 divides every element of A. We cannot reach the situation where 9 or greater integer divides every element of A.

Sample Input 3

4 5
10 1 2 22

Sample Output 3

7

Sample Input 4

8 7
1 7 5 6 8 2 6 5

Sample Output 4

5


A, B = map(int, input().split())

if abs(A-B)%2 == 0:
    print((A+B)//2)
else:
    print('IMPOSSIBLE')

Score: 100 points

Problem Statement

We have two distinct integers A and B.

Print the integer K such that |A - K| = |B - K|.

If such an integer does not exist, print IMPOSSIBLE instead.

Constraints

All values in input are integers.

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

A and B are distinct.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the integer K satisfying the condition.

If such an integer does not exist, print IMPOSSIBLE instead.

Sample Input 1

2 16

Sample Output 1

9

|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.

Sample Input 2

0 3

Sample Output 2

IMPOSSIBLE

No integer satisfies the condition.

Sample Input 3

998244353 99824435

Sample Output 3

549034394


<?php

fscanf(STDIN, "%d", $N);
$p = array();
$p = explode(' ', fgets(STDIN));

$result = TRUE;
for ($num=0; $num < count($p); $num++) {
  if ($p[$num] !== $num+1 && $num+1 !== $p[$p[$num]-1]) {
    $result = FALSE;
  }
}

if ($result) {
  echo 'YES';
}
else {
  echo 'NO';
}

Score : 200 points

Problem Statement

We have a sequence p = {p_1,\ p_2,\ ...,\ p_N} which is a permutation of {1,\ 2,\ ...,\ N}.

You can perform the following operation at most once: choose integers i and j (1 \leq i < j \leq N), and swap p_i and p_j. Note that you can also choose not to perform it.

Print YES if you can sort p in ascending order in this way, and NO otherwise.

Constraints

All values in input are integers.

2 \leq N \leq 50

p is a permutation of {1,\ 2,\ ...,\ N}.

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 ... p_N

Output

Print YES if you can sort p in ascending order in the way stated in the problem statement, and NO otherwise.

Sample Input 1

5
5 2 3 4 1

Sample Output 1

YES

You can sort p in ascending order by swapping p_1 and p_5.

Sample Input 2

5
2 4 3 5 1

Sample Output 2

NO

In this case, swapping any two elements does not sort p in ascending order.

Sample Input 3

7
1 2 3 4 5 6 7

Sample Output 3

YES

p is already sorted in ascending order, so no operation is needed.


<?php
  fscanf(STDIN,"%d",$n);
  $p = preg_split("/ /",trim(fgets(STDIN)));
  $count = 0;
  for($i=0;$i<$n;$i++){
    if(($i+1)!=$p[$i]){
      $count++;
    }
  }
  if($count==0 or $count==2){
    echo("YES");
  }else{
    echo("NO");
  }


Score : 300 points

Problem Statement

There are N+1 towns. The i-th town is being attacked by A_i monsters.

We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.

What is the maximum total number of monsters the heroes can cooperate to defeat?

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_{N+1}
B_1 B_2 ... B_N

Output

Print the maximum total number of monsters the heroes can defeat.

Sample Input 1

2
3 5 2
4 5

Sample Output 1

9

If the heroes choose the monsters to defeat as follows, they can defeat nine monsters in total, which is the maximum result.

The first hero defeats two monsters attacking the first town and two monsters attacking the second town.

The second hero defeats three monsters attacking the second town and two monsters attacking the third town.

Sample Input 2

3
5 6 3 8
5 100 8

Sample Output 2

22

Sample Input 3

2
100 1 1
1 100

Sample Output 3

3


<?php
  $n = intval(fgets(STDIN));

  $arrayA = explode(" ", trim(fgets(STDIN)));
  $arrayB = explode(" ", trim(fgets(STDIN)));

  $total = 0;
  for($i=0; $i<$n; $i++){
    if($arrayA[$i]>=$arrayB[$i]){
      $total += $arrayB[$i];
    }else{
      $total += $arrayA[$i];
      $arrayB[$i] -= $arrayA[$i];

      if($arrayB[$i]>0){
        if($arrayA[$i+1]>=$arrayB[$i]){
          $total += $arrayB[$i];
          $array[$i+1] -= $arrayB[$i];
        }else{
          $total += $arrayA[$i+1];
          $arrayA[$i+1] = 0;
        }
      }
    }
  }

  echo $total."\n";


<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B) =  explode(" ",trim(fgets(STDIN)));
$A =  explode(" ",trim(fgets(STDIN)));
$B =  explode(" ",trim(fgets(STDIN)));

$m = 0;
for($i=0;$i<$N;$i++) {
  $maxmon = $A[$i]+$A[$i+1];
  $m += min($B[$i],$maxmon);
}
printf("%d\n",$m);


<?php
define("MOD", 10**9+7);
$str = str_split(str());
$n = count($str);
for($j = 0; $j < 13; $j++){
  $dp[$n-1][$j] = 0;
}
if($str[$n-1] == "?"){
  for($i = 0; $i < 10; $i++){
    $dp[$n-1][$i] = 1;
  }
}else{
  $dp[$n-1][$str[$n-1]] = 1;
}
$c = 0;
$m = 1;
for($i = $n-2; $i>=0; --$i){
  $m*=10;
  $m%=13;
  for($j = 0; $j < 13; ++$j){
    $dp[$i][$j] = 0;
  }
  $dpi = &$dp[$i];
  $dpip = $dp[$i+1];
  if($str[$i] != "?"){
    $diff = $m*intval($str[$i])%13;
    for($j = 0; $j < 13; ++$j){
      $dpi[($j+$diff)%13] = $dpip[$j];
    }
  }else{
    for($k = 0; $k < 10; ++$k){
      $diff = $m*$k%13;
      for($j = 0; $j < 13; ++$j){
        $dpi[($j+$diff)%13] += $dpip[$j];
        $c+=$dpip[$j];
      }
    }
  }
  for($j = 0; $j < 13; ++$j){
    $dpi[$j] %= MOD;
  }
}
echo $dp[0][5];

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Score : 400 points

Problem Statement

Given is a string S. Each character in S is either a digit (0, ..., 9) or ?.

Among the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.

Since the answer can be enormous, print the count modulo 10^9+7.

Constraints

S is a string consisting of digits (0, ..., 9) and ?.

1 \leq |S| \leq 10^5

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of integers satisfying the condition, modulo 10^9+7.

Sample Input 1

??2??5

Sample Output 1

768

For example, 482305, 002865, and 972665 satisfy the condition.

Sample Input 2

?44

Sample Output 2

1

Only 044 satisfies the condition.

Sample Input 3

7?4

Sample Output 3

0

We may not be able to produce an integer satisfying the condition.

Sample Input 4

?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???

Sample Output 4

153716888


Score : 100 points

Problem Statement

It is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2.

Given an integer r, find the area of a regular dodecagon inscribed in a circle of radius r.

Constraints

1 \leq r \leq 100

r is an integer.

Input

Input is given from Standard Input in the following format:

r

Output

Print an integer representing the area of the regular dodecagon.

Sample Input 1

4

Sample Output 1

48

The area of the regular dodecagon is 3 \times 4^2 = 48.

Sample Input 2

15

Sample Output 2

675

Sample Input 3

80

Sample Output 3

19200


<?php
fscanf(STDIN, "%d", $r);
echo 3 * $r * $r;


<?php
$r = trim(fgets(STDIN));
echo 3*$r*$r;
?>


<?php
fscanf(STDIN, "%d", $hankei);
echo (($hankei ^ 2) * 3) . "\n"


<?php
$a = trim(fgets(STDIN));
echo $a*$a*3;


<?php
  fscanf(STDIN,"%d %d", $n, $d);
  $one_look = $d*2+1;
  if ($n%$one_look == 0){
    echo ((int)($n/$one_look))."\n";
  }else{
    echo ((int)($n/$one_look)+1)."\n";
  }
  ?>

Score : 200 points

Problem Statement

There are N apple trees in a row. People say that one of them will bear golden apples.

We want to deploy some number of inspectors so that each of these trees will be inspected.

Each inspector will be deployed under one of the trees. For convenience, we will assign numbers from 1 through N to the trees. An inspector deployed under the i-th tree (1 \leq i \leq N) will inspect the trees with numbers between i-D and i+D (inclusive).

Find the minimum number of inspectors that we need to deploy to achieve the objective.

Constraints

All values in input are integers.

1 \leq N \leq 20

1 \leq D \leq 20

Input

Input is given from Standard Input in the following format:

N D

Output

Print the minimum number of inspectors that we need to deploy to achieve the objective.

Sample Input 1

6 2

Sample Output 1

2

We can achieve the objective by, for example, placing an inspector under Tree 3 and Tree 4.

Sample Input 2

14 3

Sample Output 2

2

Sample Input 3

20 4

Sample Output 3

3


<?php
fscanf(STDIN, "%d%d", $n, $d);
echo ceil($n / ($d * 2 - 1));
?>


<?php
list($n, $d) = ints();
echo ceil($n/($d*2+1));
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}


Score : 300 points

Problem Statement

You are given a sequence of length N: A_1, A_2, ..., A_N.
For each integer i between 1 and N (inclusive), answer the following question:

Find the maximum value among the N-1 elements other than A_i in the sequence.

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 200000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.

Sample Input 1

3
1
4
3

Sample Output 1

4
3
4

The maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.

The maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.

The maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.

Sample Input 2

2
5
5

Sample Output 2

5
5


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

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

arsort($arr);
$max = [];
$i = 0;
foreach ($arr as $key => $value) {
    if($i === 2) break;

    $max[$i]['key'] = $key;
    $max[$i]['value'] = $value;
    $i++;
}

for ($i = 0; $i < $n; $i++) {
    if($i === $max[0]['key']) {
        echo $max[1]['value'] . "\n";
    } else {
        echo $max[0]['value'] . "\n";
    }
}


<?php
# C - Exception Handling

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

$max = 0;
$second = 0;
$array = [];
for ($i = 1; $i <= $N; $i++) {
    fscanf(STDIN, "%d", $a);
    $array[] = $a;
    if ($max < $a) {
        $second = $max;
        $max = $a;
    } elseif ($second < $a) {
        $second = $a;
    }
}

for ($i = 0; $i < $N; $i++) {
    if ($max == $array[$i]) {
        echo $second . PHP_EOL;
        continue;
    }
    echo $max . PHP_EOL;
}


<?php
# 入力
fscanf(STDIN, '%d', $n);
$a = [];
$max = 0;
$max2 = 0;
$max_key = [];
foreach(range(0, $n - 1) as $i) {
    $n = intval(trim(fgets(STDIN)));
    $a[] = $n;
    if ($max < $n) {
        $max2 = $max;
        $max = $n;
        $max_key = [$i];
    } elseif($max === $n) {
        $max_key[] = $i;
    }
}
$cnt_max = count($max_key);
foreach($a as $i => $v) {
    if ($cnt_max === 1 && in_array($i, $max_key)) {
        echo($max2.PHP_EOL);
    } else {
        echo($max.PHP_EOL);
    }
}
?>


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

arsort($a);
$first = current($a);
for ($j = 0; $j < $n; $j++) {
    $a_tmp = $a;
    if ($a_tmp[$j] == $first) {
        unset($a_tmp[$j]);
        $first = current($a_tmp);
    }
    echo $first . PHP_EOL;
}


<?php

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

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

$max = max($array);
$flag = 0;
for($i=0;$i<$n;$i++){

    if($array[$i] == $max && $flag == 0){
        $copy = $array;
        unset($copy[$i]);
        echo max($copy).PHP_EOL;
        $flag = 1;

    }else{
        echo $max.PHP_EOL;
    }

}


<?php
# 入力
fscanf(STDIN, '%d', $n);
$a = [0];
$a[] = array_map('intval', explode(" ", trim(fgets(STDIN))));
$b = [];
for ($i = $n; $i > 0; $i--) {
    $sum = 0;
    for ($j = 2; $i * $j <= $n; $j++) {
        if (in_array($i * $j, $b)) {
            $sum++;
        }
    }
    if ($sum % 2 != $a[$i]) {
        $b[] = $i;
    }
}
$cnt = count($b);
echo $cnt.PHP_EOL;
if ($cnt > 0) {
    echo implode(" ", $b).PHP_EOL;
}
?>

Score : 400 points

Problem Statement

There are N empty boxes arranged in a row from left to right.
The integer i is written on the i-th box from the left (1 \leq i \leq N).

For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.

We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:

For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.

Does there exist a good set of choices? If the answer is yes, find one good set of choices.

Constraints

All values in input are integers.

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

a_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If a good set of choices does not exist, print -1.

If a good set of choices exists, print one such set of choices in the following format:

M
b_1 b_2 ... b_M

where M denotes the number of boxes that will contain a ball, and b_1,\ b_2,\ ...,\ b_M are the integers written on these boxes, in any order.

Sample Input 1

3
1 0 0

Sample Output 1

1
1

Consider putting a ball only in the box with 1 written on it.

There are three boxes with multiples of 1 written on them: the boxes with 1, 2, and 3. The total number of balls contained in these boxes is 1.

There is only one box with a multiple of 2 written on it: the box with 2. The total number of balls contained in these boxes is 0.

There is only one box with a multiple of 3 written on it: the box with 3. The total number of balls contained in these boxes is 0.

Thus, the condition is satisfied, so this set of choices is good.

Sample Input 2

5
0 0 0 0 0

Sample Output 2

0

Putting nothing in the boxes can be a good set of choices.


<?php
fscanf(STDIN, "%d", $n);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$b = []; $r = []; $m = 0;
for ($i=$n - 1; $i >= 0; $i--) {
    $b[$i] = (count_multiple($i + 1, $i + 1) % 2) === $a[$i] ? 0 : 1;
    if ($b[$i] === 1) {
        $r[] = $i + 1;
        $m++;
    }
}
echo $m."\n";
echo implode(' ', $r);
function count_multiple($i, $s) {
    global $b, $n;
    if ($i > $n - 1) return 0;
    return $b[$i] + count_multiple($i + $s, $s);
}
?>


<?php

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

$n = $tmp[0];
$as = explode(" ", $tmp[1]);

$result = array();
$count = 0;

for ($i = count($as) - 1; $i >= 0; $i--) {
    $cnt = 0;
    for ($j = $i; $j < count($as); $j += ($i + 1)) {
        if (isset($result[$j]) && $result[$j] == 1) {
            $cnt++;
        }
    }
    if($cnt == $as[$i] % 2){
        $result[$i] = 0;
    }elseif($cnt == ($as[$i] % 2) - 1){
        $result[$i] = 1;
        $count++;
    }else{
        $result = false;
        break;
    }
}

if($result === false){
    echo "-1";
}else{
    echo $count ."\n";
    foreach ($result as $key => $r){
        if($r == 1){
            echo ($key + 1) ." ";
        }
    }
}


<?php
$n = intval(fgets(STDIN));
$maxLen = 0;
$currentLen = 0;
$currentNum = 10**10;
for($i = 0; $i < $n; $i++){
  $a = intval(fgets(STDIN));
  if($a <= $currentNum){
    $currentNum = $a;
    $currentLen++;
    $maxLen = max($maxLen, $currentLen);
  }else{
    $currentLen = 1;
    $currentNum = $a;
  }
}
echo $maxLen;

Score : 500 points

Problem Statement

You are given a sequence with N integers: A = \{ A_1, A_2, \cdots, A_N \}.
For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:

If A_i and A_j (i < j) are painted with the same color, A_i < A_j.

Find the minimum number of colors required to satisfy the condition.

Constraints

1 \leq N \leq 10^5

0 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the minimum number of colors required to satisfy the condition.

Sample Input 1

5
2
1
4
5
3

Sample Output 1

2

We can satisfy the condition with two colors by, for example, painting 2 and 3 red and painting 1, 4, and 5 blue.

Sample Input 2

4
0
0
0
0

Sample Output 2

4

We have to paint all the integers with distinct colors.


<?php
fscanf(STDIN,"%d",$N);
$arr=explode(" ",fgets(STDIN));
if(array_sum($arr)==0){
    echo "Yes";
    exit;
}
$size=count($arr);
if($size%3!=0){
    echo "No";
    exit;
}
$unq=array_unique($arr);
if(count($unq)!=3){
    echo "No";
    exit;
}
for ($i=1;$i<=$size;$i++) {
    $a1=$i%$size;
    $a2=($i+1)%$size;
    $a3=($i+2)%$size;
    $l=intval($arr[$a1]);
    $c=intval($arr[$a2]);
    $r=intval($arr[$a3]);
    $xor=$l^$r;
    if ($xor!=$c){
        echo "No";
        exit;
    }
}
echo "Yes";

Score : 300 points

Problem Statement

Snuke has N hats. The i-th hat has an integer a_i written on it.

There are N camels standing in a circle.
Snuke will put one of his hats on each of these camels.

If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print Yes; otherwise, print No.

The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself.

What is XOR?

The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non-negative integers x_1, x_2, \ldots, x_n is defined as follows:

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

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

3 \leq N \leq 10^{5}

0 \leq a_i \leq 10^{9}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

Yes

If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is Yes.

Sample Input 2

4
1 2 4 8

Sample Output 2

No

There is no such way to distribute the hats; the answer is No.


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

$N = $s[0];
$memo = array();

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

$a_list = $s;
$tmp_list = array();
foreach($a_list as $value) {
    $tmp_list[(int)$value] = true;
}

function check($pre1, $pre2, $a_list) {
    $first = $pre1;
    global $memo;
    // var_dump($pre1, $pre2, $a_list);
    // var_dump("next");
    unset($a_list[$pre1]);
    unset($a_list[$pre2]);
    while (count($a_list) !== 0) {
        $next = $pre1 ^ $pre2;
        // var_dump($next);
        if (!array_key_exists($next, $a_list)) {
            return false;
        }
        unset($a_list[$next]);
        $pre1 = $pre2;
        $pre2 = $next;
        $memo[$pre1][$pre2] = true;
    }
    if ($first != ($pre1 ^ $pre2)) {
        return false;
    }
    return true;
}

$ret = "No";
$memo2 = array();
for ($i = 0; $i < $N; $i++) {
    $pre1 = (int)$a_list[$i];
    if (isset($memo2[$pre1])) {
        continue;
    }
    for ($j = $i + 1; $j < $N; $j++) {
        $pre2 = (int)$a_list[$j];
        if (isset($memo2[$pre2]) || isset($memo[$pre1][$pre2]) || isset($memo[$pre2][$pre1])) {
            // var_dump($pre1, $pre2);
            continue;
        }
        if (check($pre1, $pre2, $tmp_list)) {
            $ret = "Yes";
            goto end_lable;
        }
    }
    $memo2[$pre1] = true;
}

end_lable:
echo $ret;


<?php

$input = fgets(STDIN);
$array = explode(' ', $input);

$n = (int)$array[0];
$a = (int)$array[1];
$b = (int)$array[2];

$fee = $n * $a;

if ($fee > $b) {
    $fee = $b;
}

echo $fee;

Score : 100 points

Problem Statement

N of us are going on a trip, by train or taxi.

The train will cost each of us A yen (the currency of Japan).

The taxi will cost us a total of B yen.

How much is our minimum total travel expense?

Constraints

All values in input are integers.

1 \leq N \leq 20

1 \leq A \leq 50

1 \leq B \leq 50

Input

Input is given from Standard Input in the following format:

N A B

Output

Print an integer representing the minimum total travel expense.

Sample Input 1

4 2 9

Sample Output 1

8

The train will cost us 4 \times 2 = 8 yen, and the taxi will cost us 9 yen, so the minimum total travel expense is 8 yen.

Sample Input 2

4 2 7

Sample Output 2

7

Sample Input 3

4 2 8

Sample Output 3

8


<?php
  fscanf(STDIN, "%d %d %d", $n, $a, $b);
  $train = $n * $a;
  $taxi = $b;
  echo min($train, $taxi);
  ?>


<?php
# 標準出力
fscanf(STDIN, "%d %d %d",$N,$A,$B);
$answer = 0;

# 一人分の値段の比較
if($A < $B/$N){

	$answer = $A * $N;
}else{

	$answer = $B;
}
echo $answer;
?>


Score : 200 points

Problem Statement

There are N points in a D-dimensional space.

The coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}).

The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}.

How many pairs (i, j) (i < j) are there such that the distance between the i-th point and the j-th point is an integer?

Constraints

All values in input are integers.

2 \leq N \leq 10

1 \leq D \leq 10

-20 \leq X_{ij} \leq 20

No two given points have the same coordinates. That is, if i \neq j, there exists k such that X_{ik} \neq X_{jk}.

Input

Input is given from Standard Input in the following format:

N D
X_{11} X_{12} ... X_{1D}
X_{21} X_{22} ... X_{2D}
\vdots
X_{N1} X_{N2} ... X_{ND}

Output

Print the number of pairs (i, j) (i < j) such that the distance between the i-th point and the j-th point is an integer.

Sample Input 1

3 2
1 2
5 5
-2 8

Sample Output 1

1

The number of pairs with an integer distance is one, as follows:

The distance between the first point and the second point is \sqrt{|1-5|^2 + |2-5|^2} = 5, which is an integer.

The distance between the second point and the third point is \sqrt{|5-(-2)|^2 + |5-8|^2} = \sqrt{58}, which is not an integer.

The distance between the third point and the first point is \sqrt{|-2-1|^2+|8-2|^2} = 3\sqrt{5}, which is not an integer.

Sample Input 2

3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3

Sample Output 2

2

Sample Input 3

5 1
1
2
3
4
5

Sample Output 3

10


<?php
# B - Good Distance

fscanf(STDIN, "%d %d", $N, $D);
$array = [];
for ($i=0;$i<$N;$i++) {
    $array[] = explode(' ', fgets(STDIN));
}

$count = 0;
for ($i=0;$i<$N-1;$i++) {
    for ($j=$i+1;$j<$N;$j++) {
        $sum = 0;
        for ($k=0;$k<$D;$k++) {
            $sum += abs(intval($array[$i][$k]) - intval($array[$j][$k])) * abs(intval($array[$i][$k]) - intval($array[$j][$k]));
        }
        if (is_decimal(sqrt($sum)) && $sum != 0) {
            $count++;
        }
    }
}

echo $count . PHP_EOL;

function is_decimal($value) {
    return filter_var($value, FILTER_VALIDATE_INT) !== false;
}


<?php

$data = explode(" ", trim(fgets(STDIN)));
$n = (int)$data[0];
$d = (int)$data[1];

$points = array();
for ($i = 0; $i < $n; $i++) {
	$data = explode(" ", trim(fgets(STDIN)));
	$points[] = $data;
}

$count = 0;
for ($i = 0; $i < $n; $i++) {
	for ($j = $i + 1; $j < $n; $j++) {
		if (isZ2(dist2($points[$i], $points[$j]))) {
			$count++;
		}
	}
}

print $count;

function dist2($p1, $p2) {
	$sum = 0;
	foreach($p1 as $i => $v) {
		$sum += ($p1[$i] - $p2[$i]) * ($p1[$i] - $p2[$i]);
	}

	return $sum;
}

function isZ2($n) {
	$s = sqrt($n);
	$ss = floor($s);

	if ($n == $s * $s) {
		return true;
	}
	return false;
}


Score : 100 points

Problem Statement

You are given a 4-character string S consisting of uppercase English letters.
Determine if S consists of exactly two kinds of characters which both appear twice in S.

Constraints

The length of S is 4.

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If S consists of exactly two kinds of characters which both appear twice in S, print Yes; otherwise, print No.

Sample Input 1

ASSA

Sample Output 1

Yes

S consists of A and S which both appear twice in S.

Sample Input 2

STOP

Sample Output 2

No

Sample Input 3

FFEE

Sample Output 3

Yes

Sample Input 4

FREE

Sample Output 4

No


<?php

$a = trim(fgets(STDIN));
$b = strlen($a);
$input = str_split($a);
$result = "No";

if ((($input[0] == $input[1] && $input[2] == $input[3]) and ($input[2] != $input[1])) or
    ($input[0] == $input[2] && $input[1] == $input[3]) and ($input[0] != $input[1]) or
    ($input[0] == $input[3] && $input[2] == $input[1]) and ($input[0] != $input[1])) {
    $result = "Yes";
} else if ($input[0] == $input[1] && $input[0] == $input[2]) {
    $result = "No";
} else if ($input[0] == $input[1] && $input[0] == $input[3]) {
    $result = "No";
}
echo $result;
?>


<?php

$a = trim(fgets(STDIN));
$b = strlen($a);
$input = str_split($a);

if($b<=4 && ctype_upper($a) && ctype_alpha($a)) {
    if (($input[0] == $input[1] || $input[0] == $input[2] || $input[0] == $input[3]) && ($input[1] == $input[2] || $input[1] == $input[3] || $input[2] == $input[3])) {
        echo "Yes";
    }else if ($input[0] == $input[1] && $input[2] == $input[3]){
    echo "No";
}else{
    echo "No";
}

?>


<?php

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

if(ctype_lower($input)) {
    if (($input[0] == $input[1] || $input[0] == $input[2] || $input[0] == $input[3]) && ($input[1] == $input[2] || $input[1] == $input[3] || $input[2] == $input[3])) {
        echo "Yes";
    } else {
        echo "No";
    }
}

?>


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

$count1 = mb_substr_count($ant_arr, $ant_arr[0]);
$count2 = mb_substr_count($ant_arr, $ant_arr[1]);
$count3 = mb_substr_count($ant_arr, $ant_arr[2]);
$count4 = mb_substr_count($ant_arr, $ant_arr[3]);

if ($count1 === $count2 && $count4 === $count3) echo "Yes\n";
else echo "No\n";


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

  $tmp = [];
  for($i=0; $i<4; $i++){
    $tmp[$s[$i]] = isset($tmp[$s[$i]]) ? $tmp[$s[$i]]++ : 1;
  }

  $flag = true;
  if(count($tmp)==2){
    foreach($tmp as $num){
      if($num!=2){
        $flag = false;
        break;
      }
    }
  }else{
    $flag = false;
  }

  echo $flag ? "Yes\n" : "No\n";


Score : 200 points

Problem Statement

We have a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n}.

Print the number of elements p_i (1 < i < n) that satisfy the following condition:

p_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.

Constraints

All values in input are integers.

3 \leq n \leq 20

p is a permutation of {1,\ 2,\ ...,\ n}.

Input

Input is given from Standard Input in the following format:

n
p_1 p_2 ... p_n

Output

Print the number of elements p_i (1 < i < n) that satisfy the condition.

Sample Input 1

5
1 3 5 4 2

Sample Output 1

2

p_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.

Sample Input 2

9
9 6 3 2 5 8 7 4 1

Sample Output 2

5


<?php
const INPUT_DELIMITER = " ";
const OUTPUT_DELIMITER = " ";

// 標準入力
$N = fgets(STDIN);
$input = fgets(STDIN);
$inputArray = explode(INPUT_DELIMITER, $input);

$nums = [];
foreach ($inputArray as $input) {
    $nums[] = (int)$input;
}
sort($nums);
//var_dump($nums);

$index = $N / 2;
$K = $nums[$index] - $nums[$index-1];
echo $K;

Score : 300 points

Problem Statement

Takahashi made N problems for competitive programming.
The problems are numbered 1 to N, and the difficulty of Problem i is represented as an integer d_i (the higher, the harder).

He is dividing the problems into two categories by choosing an integer K, as follows:

A problem with difficulty K or higher will be for ARCs.

A problem with difficulty lower than K will be for ABCs.

How many choices of the integer K make the number of problems for ARCs and the number of problems for ABCs the same?

Problem Statement

2 \leq N \leq 10^5

N is an even number.

1 \leq d_i \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
d_1 d_2 ... d_N

Output

Print the number of choices of the integer K that make the number of problems for ARCs and the number of problems for ABCs the same.

Sample Input 1

6
9 1 4 4 6 7

Sample Output 1

2

If we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and 4 will be for ABCs, and the objective is achieved.
Thus, the answer is 2.

Sample Input 2

8
9 1 14 5 5 4 4 14

Sample Output 2

0

There may be no choice of the integer K that make the number of problems for ARCs and the number of problems for ABCs the same.

Sample Input 3

14
99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1

Sample Output 3

42685


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

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

$max = max($num_arr);

$count = 0;

// for ($i = 0; $i < $max; ++$i) {
//     $temp = array_filter($num_arr, function ($num) use($i) {
//         return $num < $i;
//     });

//     if (count($temp) === ($num_count/2)) {
//         ++$count;
//     }
// }
$left = 0;
$right = $num_count-1;

foreach ($num_arr as $num) {
    $temp = array_filter($num_arr, function ($n) use($num) {
        return $n < $num;
    });

    if (count($temp) === ($num_count/2)) {
        $left = $num;
        $right = $num+1;
        $count++;
        break;
    }
}

if ($count == 0) {
    echo "0\n";
    return;
}

for ($i = $left; $i > 0; --$i) {
    $temp = array_filter($num_arr, function ($n) use($i) {
        return $n < $i;
    });

    if (count($temp) !== ($num_count/2)) {
        $left = $i+1;
        break;
    }
}

for ($i = $right; $i > $max; ++$i) {
    $temp = array_filter($num_arr, function ($n) use($i) {
        return $n < $i;
    });

    if (count($temp) !== ($num_count/2)) {
        $right = $i;
        break;
    }
}

echo $right-$left, "\n";


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

$ds = [];
foreach ($input as $v) {
	$ds[] = (int)$v;
}
sort($ds);

$small = $ds[(int)($n / 2 - 1)];
$large = $ds[(int)($n / 2)];

echo $large - $small;


<?PHP
fscanf(STDIN, "%d %d", $N, $K);
$val = (pow(10,9)+7);

//青ボールを並べて、i-1個の仕切りを入れる K-1 C i-1

//赤ボール(N-K個）を並べて、i個の仕切り（青を入れるところ）を入れる
//仕切りは一番前・一番後もOKだから、N-K+１ C i

//求めるのは、K-1 C i-1 ＊ N-K+１ C i

//i=1 〜 Min(K, N-K+1）
//i=1の場合 K-1 C i-1 ＊ N-K+１ C i ＝K-1 C 0 ＊ N-K+１ C 1 = N-K+１
echo ($N-$K+1),PHP_EOL;

//i=2以上の場合
for($i=2; $i <= min($K, $N-$K+1); $i++){
  $ans=1;
  for($j=1; $j<=$i-1; $j++){
    $ans=(int)($ans*(($K-$j) / $j * ($N-$K+2-$j)/ $j ))% $val;
  }
  $ans=(int)($ans*(($N-$K+2-$i)/ $i))% $val;
  echo $ans,PHP_EOL;
}

Score : 400 points

Problem Statement

There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.

First, Snuke will arrange the N balls in a row from left to right.

Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.

How many ways are there for Snuke to arrange the N balls in a row so that Takahashi will need exactly i moves to collect all the blue balls? Compute this number modulo 10^9+7 for each i such that 1 \leq i \leq K.

Constraints

1 \leq K \leq N \leq 2000

Input

Input is given from Standard Input in the following format:

N K

Output

Print K lines. The i-th line (1 \leq i \leq K) should contain the number of ways to arrange the N balls so that Takahashi will need exactly i moves to collect all the blue balls, modulo 10^9+7.

Sample Input 1

5 3

Sample Output 1

3
6
1

There are three ways to arrange the balls so that Takahashi will need exactly one move: (B, B, B, R, R), (R, B, B, B, R), and (R, R, B, B, B). (R and B stands for red and blue, respectively).

There are six ways to arrange the balls so that Takahashi will need exactly two moves: (B, B, R, B, R), (B, B, R, R, B), (R, B, B, R, B), (R, B, R, B, B), (B, R, B, B, R), and (B, R, R, B, B).

There is one way to arrange the balls so that Takahashi will need exactly three moves: (B, R, B, R, B).

Sample Input 2

2000 3

Sample Output 2

1998
3990006
327341989

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


<?php

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

$s_arr = str_split($s);
$len = strlen($s);

$result = true;
$tmp = $s_arr[0];
for ($i = 1; $i < $len; ++$i) {
    if ($tmp == $s_arr[$i]) {
        $result = false;
        break;
    }
    $tmp = $s_arr[$i];
}

echo $result ? 'Good' : 'Bad';

Score : 100 points

Problem Statement

The door of Snuke's laboratory is locked with a security code.

The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.

You are given the current security code S. If S is hard to enter, print Bad; otherwise, print Good.

Constraints

S is a 4-character string consisting of digits.

Input

Input is given from Standard Input in the following format:

S

Output

If S is hard to enter, print Bad; otherwise, print Good.

Sample Input 1

3776

Sample Output 1

Bad

The second and third digits are the same, so 3776 is hard to enter.

Sample Input 2

8080

Sample Output 2

Good

There are no two consecutive digits that are the same, so 8080 is not hard to enter.

Sample Input 3

1333

Sample Output 3

Bad

Sample Input 4

0024

Sample Output 4

Bad


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

$result = false;
for($i=0; $i<strlen($s)-1; $i++){
  if($s[$i]==$s[$i+1]){
    $result = true;
    break;
  }
}

echo ($result ? "Bad" : "Good")."\n";


            <?php
$a=intval(trim(fgets(STDIN)));
        $arr = str_split($a);

    print_r($arr);
        if($arr[0]==$arr[1] ||$arr[1]==$arr[2]||$arr[2]==$arr[3]){
          echo "bad"."\n";
        }
        else{
              echo "good"."\n";
        }
            ?>


<?php
fscanf(STDIN,"%s",$n);
$b=false;

for($i=1;$i<$4;$i++){
	if(substr($n,$i-1,1)==substr($n,$i,1)){
		$b=true;
		break;
	}
}

if($b){
	echo "Bad";
}else{
	echo "Good";
}
?>


<?php
$s = trim(fgets(STDIN));
$s_array = array_map("trim", str_split($s));
$ans = "Good";
for($i=0; $i<3; $i++){
	if($s_array[$i] === $s_array[$i+1]){
		$ans = "Bad";
	}
}
echo $ans . "\n";
?>


<?php
$s = trim(fgets(STDIN));
$s_array = str_split($s);
$ans = "Good";
for($i=0; $i<2; $i++){
	if($s_array[$i] == $s_array[$i+1]){
		$ans = "Bad";
	}
}
echo $ans . "\n";
?>


<?php
# A - Security

$array = str_split((fgets(STDIN)));
$key = $array[0];
for ($i = 1; $i < 4; $i++) {
    if ($array[$i] == $key) {
        echo 'Bad' . PHP_EOL;
        exit;
    } else {
        $key = $array[$i];
    }
}
echo 'Good' . PHP_EOL;


Score : 200 points

Problem Statement

You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.

You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.

You planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.

You want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining N-1 apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the N apples.

Find the flavor of the apple pie made of the remaining N-1 apples when you choose the apple to eat as above.

We can prove that this value is uniquely determined.

Constraints

2 \leq N \leq 200

-100 \leq L \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N L

Output

Find the flavor of the apple pie made of the remaining N-1 apples when you optimally choose the apple to eat.

Sample Input 1

5 2

Sample Output 1

18

The flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively. The optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.

Sample Input 2

3 -1

Sample Output 2

0

The flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal choice is to eat Apple 2, so the answer is (-1)+1=0.

Sample Input 3

30 -50

Sample Output 3

-1044


<?php
                            //4 9 2 3
    fscanf(STDIN,"%d%d%d%d",$A,$B,$C,$D);

    $ansx=0;
    $ansy=0;
    //$B以下の整数で$c,$d,lcm($c,$d)で割り切れるものの個数を求める
    $ansx += intval(floor($B/$C));
    $ansx += intval(floor($B/$D));
    $ansx -= intval(floor($B/lcm($C,$D)));

    $ansy += intval(floor(($A-1)/$C));
    $ansy += intval(floor(($A-1)/$D));
    $ansy -= intval(floor(($A-1)/lcm($C,$D)));
    echo ($B-($A-1))-($ansx-$ansy);

    function lcm($m, $n){
        return $m * $n / gcd($m, $n);
    }
    function gcd($m,$n){
        //$mが大きい値にしておきたい
        if($n>$m)list($m,$n)=array($n,$m);

        //余りが0になるまで割り続けるような
        //計算をする。
        while($n != 0){
            $tmp_n = $n;
            $n = $m % $n;
            $m = $tmp_n;
        }
        return $m;
    }

?>

Score : 300 points

Problem Statement

You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Constraints

1\leq A\leq B\leq 10^{18}

1\leq C,D\leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Sample Input 1

4 9 2 3

Sample Output 1

2

5 and 7 satisfy the condition.

Sample Input 2

10 40 6 8

Sample Output 2

23

Sample Input 3

314159265358979323 846264338327950288 419716939 937510582

Sample Output 3

532105071133627368


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

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

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

 fscanf(STDIN,"%d%d%d%d",$a,$b,$c,$d);
 $b2 = intdiv($b/$c)+intdiv($b/$d)-intdiv($b/lcm($c,$d));
 $a2 = intdiv(($a-1)/$c)+intdiv(($a-1)/$d)-intdiv(($a-1)/lcm($c,$d));

$b = $b-$b2;
$a = $a-1-$a2;
echo $b-$a;


<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($A,$B,$C,$D) =  explode(" ",trim(fgets(STDIN)));
//$a =  explode(" ",trim(fgets(STDIN)));

printf("%d\n",calc($B,$C,$D)-calc($A-1,$C,$D));

function calc($x,$c,$d) {
  $ret = $x;
  $ret -= intdiv($x,$c);
  $ret -= intdiv($x,$d);
  $ret += intdiv($x,lcm($c,$d));
  return $ret;
}

function gcd($a,$b) {
  if ($b == 0) return $a;
  return gcd($b,$a%$b);
}
function lcm($a,$b) {
  $l = gcd($a,$b);
  return $a / $l * $b;
}


<?php
# C - Anti-Division

fscanf(STDIN, "%d %d %d %d", $A, $B, $C, $D);

$A = $A - 1;

#0からA
$ADiviedC = intval($A / $C);
$ADiviedD = intval($A / $D);
$ADiviedGCDCD = intval($A / lcm($C, $D));
$AA = ($A - $ADiviedC - $ADiviedD + $ADiviedGCDCD);

#0からB
$BDiviedC = intval($B / $C);
$BDiviedD = intval($B / $D);
$BDiviedGCDCD = intval($B / lcm($C, $D));
$BB = ($B - $BDiviedC - $BDiviedD + $BDiviedGCDCD);

echo ($BB - $AA) . PHP_EOL;

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

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

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


<?php

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

$div[] = (int)lcm($div[0] , $div[1]);
$maxnumber = $b - $a + 1;

$delete = [];
foreach($div as $number => $value){
    $start = ceil($a / $value);
    $end = floor($b / $value);
    $delete[$number] = (int)($end - $start + 1);

}

$ans =  ($maxnumber - ($delete[0] + $delete[1] - $delete[2]));
echo $ans;
function gcd($m, $n){
    if($n > $m) list($m, $n) = array($n, $m);

    while($n !== 0){
        $tmp_n = $n;
        $n = $m % $n;
        $m = $tmp_n;
    }
    return $m;
}
function lcm($m, $n){
    return $m * $n / gcd($m, $n);
}


<?php
list($n, $k) = ints();
if ($k > ($n - 1) * ($n - 2) / 2) exit('-1');
// 1と他の点を繋ぐ、この時が最短距離2の点の組み合わせは最大となり n-1C2 通り
for ($i = 2; $i <= $n; ++$i) $ans[] =  implode(' ', [1, $i]);
// 減らしたい数だけ直接繋ぐ
$r = ($n - 1) * ($n - 2) / 2 - $k;
for ($i = 2; $i <= $n - 1; ++$i) {
    for ($j = $i + 1; $j <= $n; ++$j) {
        if ($r === 0) break 2;
        $ans[] = implode(' ', [$i, $j]);
        --$r;
    }
}
echo count($ans) . PHP_EOL;
echo implode(PHP_EOL, $ans);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

Score: 500 points

Problem Statement

Does there exist an undirected graph with N vertices satisfying the following conditions?

The graph is simple and connected.

The vertices are numbered 1, 2, ..., N.

Let M be the number of edges in the graph. The edges are numbered 1, 2, ..., M, the length of each edge is 1, and Edge i connects Vertex u_i and Vertex v_i.

There are exactly K pairs of vertices (i,\ j)\ (i < j) such that the shortest distance between them is 2.

If there exists such a graph, construct an example.

Constraints

All values in input are integers.

2 \leq N \leq 100

0 \leq K \leq \frac{N(N - 1)}{2}

Input

Input is given from Standard Input in the following format:

N K

Output

If there does not exist an undirected graph with N vertices satisfying the conditions, print -1.

If there exists such a graph, print an example in the following format (refer to Problem Statement for what the symbols stand for):

M
u_1 v_1
:
u_M v_M

If there exist multiple graphs satisfying the conditions, any of them will be accepted.

Sample Input 1

5 3

Sample Output 1

5
4 3
1 2
3 1
4 5
2 3

This graph has three pairs of vertices such that the shortest distance between them is 2: (1,\ 4), (2,\ 4), and (3,\ 5). Thus, the condition is satisfied.

Sample Input 2

5 8

Sample Output 2

-1

There is no graph satisfying the conditions.


<?php
list($x, $a) = array_map('trim', explode(" ", fgets(STDIN)));
$ans =  trim($x)>= trim($a) ? 10 : 0;
echo $ans . "\n";

?>

Score : 100 points

Problem Statement

X and A are integers between 0 and 9 (inclusive).

If X is less than A, print 0; if X is not less than A, print 10.

Constraints

0 \leq X, A \leq 9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X A

Output

If X is less than A, print 0; if X is not less than A, print 10.

Sample Input 1

3 5

Sample Output 1

0

3 is less than 5, so we should print 0.

Sample Input 2

7 5

Sample Output 2

10

7 is not less than 5, so we should print 10.

Sample Input 3

6 6

Sample Output 3

10

6 is not less than 6, so we should print 10.


<?php
fscanf(STDIN, "%d %d", $X, $A);
echo $X >= $A ? 10 : 0;


Score : 200 points

Problem Statement

A ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \leq i \leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.

How many times will the ball make a bounce where the coordinate is at most X?

Constraints

1 \leq N \leq 100

1 \leq L_i \leq 100

1 \leq X \leq 10000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X
L_1 L_2 ... L_{N-1} L_N

Output

Print the number of times the ball will make a bounce where the coordinate is at most X.

Sample Input 1

3 6
3 4 5

Sample Output 1

2

The ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two are less than or equal to 6.

Sample Input 2

4 9
3 3 3 3

Sample Output 2

4

The ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which four are less than or equal to 9.


Score : 300 points

Problem Statement

There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H).
You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.

Constraints

1 \leq W,H \leq 10^9

0\leq x\leq W

0\leq y\leq H

All values in input are integers.

Input

Input is given from Standard Input in the following format:

W H x y

Output

Print the maximum possible area of the part whose area is not larger than that of the other, followed by 1 if there are multiple ways to cut the rectangle and achieve that maximum, and 0 otherwise.

The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.

Sample Input 1

2 3 1 2

Sample Output 1

3.000000 0

The line x=1 gives the optimal cut, and no other line does.

Sample Input 2

2 2 1 1

Sample Output 2

2.000000 1


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

if ($K == 1) {
    echo "0\n";
    return;
}

echo ($N-$K)."\n";

Score : 100 points

Problem Statement

Takahashi is distributing N balls to K persons.

If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?

Constraints

1 \leq K \leq N \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the maximum possible difference in the number of balls received.

Sample Input 1

3 2

Sample Output 1

1

The only way to distribute three balls to two persons so that each of them receives at least one ball is to give one ball to one person and give two balls to the other person.

Thus, the maximum possible difference in the number of balls received is 1.

Sample Input 2

3 1

Sample Output 2

0

We have no choice but to give three balls to the only person, in which case the difference in the number of balls received is 0.

Sample Input 3

8 5

Sample Output 3

3

For example, if we give 1, 4, 1, 1, 1 balls to the five persons, the number of balls received between the person with the most balls and the person with the fewest balls would be 3, which is the maximum result.


<?php
$n = (int)trim(fgets(STDIN));
if ($n === 1) {
	echo 1;
	exit();
}

$point_list = [];
for ($i=0; $i < $n; $i++) {
	$input = explode(' ', trim(fgets(STDIN)));
	$point_list[] = [
		(int)$input[0],
		(int)$input[1],
	];
}
usort($point_list, function($a, $b){
	return ($a[0] === $b[0]) ? $a[1] - $b[1] : $a[0] - $b[0];
});

$x_map = [];
foreach ($point_list as $key => $p) {
	if (isset($x_map[$p[0]])) {
		$x_map[$p[0]][$p[1]] = $key;
	}else{
		$x_map[$p[0]] = [];
		$x_map[$p[0]][$p[1]] = $key;
	}
}

$min = $n;
for ($i=0; $i < $n; $i++) {
	for ($j=$i+1; $j < $n; $j++) {
		$tmp_p = $point_list[$j][0] - $point_list[$i][0];
		$tmp_q = $point_list[$j][1] - $point_list[$i][1];
		if ($tmp_p === 0 && $tmp_q === 0) {
			continue;
		}
		$cost = 0;
		$keys = [];
		for ($k=0; $k < $n; $k++) {
			if (in_array($k, $keys)) {
				continue;
			}
			$cost += 1;
			$right_x = $point_list[$k][0];
			$right_y = $point_list[$k][1];
			while (isset($x_map[$right_x + $tmp_p][$right_y + $tmp_q])) {
				$keys[] = $x_map[$right_x + $tmp_p][$right_y + $tmp_q];
				$right_x += $tmp_p;
				$right_y += $tmp_q;
			}
			$left_x = $point_list[$k][0];
			$left_y = $point_list[$k][1];
			while (isset($x_map[$left_x - $tmp_p][$left_y - $tmp_q])) {
				$keys[] = $x_map[$left_x - $tmp_p][$left_y - $tmp_q];
				$left_x -= $tmp_p;
				$left_y -= $tmp_q;
			}
		}
		// echo $tmp_p . ', ' . $tmp_q . ' cost:' . $cost . PHP_EOL;
		$min = min($min, $cost);
	}
}
echo $min;

Score : 300 points

Problem Statement

There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i).

We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation:

Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.

Find the minimum total cost required to collect all the balls when we optimally choose p and q.

Constraints

1 \leq N \leq 50

|x_i|, |y_i| \leq 10^9

If i \neq j, x_i \neq x_j or y_i \neq y_j.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the minimum total cost required to collect all the balls.

Sample Input 1

2
1 1
2 2

Sample Output 1

1

If we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by collecting them in the order (1, 1), (2, 2).

Sample Input 2

3
1 4
4 6
7 8

Sample Output 2

1

If we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by collecting them in the order (7, 8), (4, 6), (1, 4).

Sample Input 3

4
1 1
1 2
2 1
2 2

Sample Output 3

2


// 標準入力からの入力値を変数に代入します
$input = fgets(STDIN);
// 取得した入力値を半角スペースで分解します
$array = explode(" ", $input);

sort($array);

echo $array[0]+$array[1];

Score : 100 points

Problem Statement

There are three airports A, B and C, and flights between each pair of airports in both directions.

A one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours.

Consider a route where we start at one of the airports, fly to another airport and then fly to the other airport.

What is the minimum possible sum of the flight times?

Constraints

1 \leq P,Q,R \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

P Q R

Output

Print the minimum possible sum of the flight times.

Sample Input 1

1 3 4

Sample Output 1

4

The sum of the flight times in the route A \rightarrow B \rightarrow C: 1 + 3 = 4 hours

The sum of the flight times in the route A \rightarrow C \rightarrow C: 4 + 3 = 7 hours

The sum of the flight times in the route B \rightarrow A \rightarrow C: 1 + 4 = 5 hours

The sum of the flight times in the route B \rightarrow C \rightarrow A: 3 + 4 = 7 hours

The sum of the flight times in the route C \rightarrow A \rightarrow B: 4 + 1 = 5 hours

The sum of the flight times in the route C \rightarrow B \rightarrow A: 3 + 1 = 4 hours

The minimum of these is 4 hours.

Sample Input 2

3 2 3

Sample Output 2

5


Score : 200 points

Problem Statement

We have N weights indexed 1 to N. The mass of the weight indexed i is W_i.

We will divide these weights into two groups: the weights with indices not greater than T, and those with indices greater than T, for some integer 1 \leq T < N. Let S_1 be the sum of the masses of the weights in the former group, and S_2 be the sum of the masses of the weights in the latter group.

Consider all possible such divisions and find the minimum possible absolute difference of S_1 and S_2.

Constraints

2 \leq N \leq 100

1 \leq W_i \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
W_1 W_2 ... W_{N-1} W_N

Output

Print the minimum possible absolute difference of S_1 and S_2.

Sample Input 1

3
1 2 3

Sample Output 1

0

If T = 2, S_1 = 1 + 2 = 3 and S_2 = 3, with the absolute difference of 0.

Sample Input 2

4
1 3 1 1

Sample Output 2

2

If T = 2, S_1 = 1 + 3 = 4 and S_2 = 1 + 1 = 2, with the absolute difference of 2. We cannot have a smaller absolute difference.

Sample Input 3

8
27 23 76 2 3 5 62 52

Sample Output 3

2


Score : 300 points

Problem Statement

There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step.
He can climb up one or two steps at a time.

However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.

How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps?
Find the count modulo 1\ 000\ 000\ 007.

Constraints

1 \leq N \leq 10^5

0 \leq M \leq N-1

1 \leq a_1 < a_2 < ... < a_M \leq N-1

Input

Input is given from Standard Input in the following format:

N M
a_1
a_2
.
.
.
a_M

Output

Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007.

Sample Input 1

6 1
3

Sample Output 1

4

There are four ways to climb up the stairs, as follows:

0 \to 1 \to 2 \to 4 \to 5 \to 6

0 \to 1 \to 2 \to 4 \to 6

0 \to 2 \to 4 \to 5 \to 6

0 \to 2 \to 4 \to 6

Sample Input 2

10 2
4
5

Sample Output 2

0

There may be no way to climb up the stairs without setting foot on the broken steps.

Sample Input 3

100 5
1
23
45
67
89

Sample Output 3

608200469

Be sure to print the count modulo 1\ 000\ 000\ 007.


<?php

fscanf(STDIN, "%d %d", $height, $width);

for($i = 0; $i<$height; $i++){
    $nmap= trim(fgets(STDIN));
    $map[$i] = str_split($nmap);
}

$h_map = [];
$w_map = [];
$max = 0;
for($i=0;$i<$height;$i++){
    for($j =0; $j<$width;$j++){
        $light = 0;
        if($map[$i][$j] == "#"){
            continue;
        }else{
            if(isset($h_map[$i][$j])){
                $light = $h_map[$i][$j];
            }else{
                $light = checkHeight($i, $j);
            }
            if($max - $light > $width ){
                continue;
            }
            if(isset($w_map[$i][$j])){
                $light += $w_map[$i][$j];
            }else{
                $light += checkWidth($i, $j);
            }
            $light--;
            $max = max($light, $max);
        }

    }

}
echo $max;

function checkHeight($i, $j){
    global $map, $height, $h_map;
    $num =0;
    $start =$i;
    $end = $height-1;
    for($t=$i; $t<$height; $t++) {
        if ($map[$t][$j] == ".") {
            $num++;
        } else {
            $end = $t - 1;
            break;
        }
    }
    $num = $num -1;
    for($t=$start; $t<=$end;$t++){
        $h_map[$t][$j] = $num;
    }
    return($num);
}

function checkWidth($i, $j){
    global $map, $width, $w_map;
    $num =0;
    $start = $j;
    $end = $width-1;
    for($t=$j; $t<$width; $t++) {
        if ($map[$i][$t] == ".") {
            $num++;
        } else {
            $end = $t - 1;
            break;
        }
    }
    $num = $num -1;
    for($t=$start; $t<=$end;$t++){
        $w_map[$i][$t] = $num;
    }
    return($num);
}

Score : 400 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.

Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.
The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.
In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.

Snuke wants to maximize the number of squares lighted by the lamp.

You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is #, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is ., there is no obstacle on that square.

Find the maximum possible number of squares lighted by the lamp.

Constraints

1 \leq H \leq 2,000

1 \leq W \leq 2,000

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

. occurs at least once in one of the strings S_i (1 \leq i \leq H).

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the maximum possible number of squares lighted by the lamp.

Sample Input 1

4 6
#..#..
.....#
....#.
#.#...

Sample Output 1

8

If Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.

Sample Input 2

8 8
..#...#.
....#...
##......
..###..#
...#..#.
##....#.
#...#...
###.#..#

Sample Output 2

13


<?php

fscanf(STDIN, "%d %d", $height, $width);

for($i = 0; $i<$height; $i++){
    $nmap= trim(fgets(STDIN));
    $map[$i] = str_split($nmap);
}

$h_map = [];
$w_map = [];
$max = 0;
for($i=0;$i<$height;$i++){
    for($j =0; $j<$width;$j++){
        $light = 0;
        if($map[$i][$j] == "#"){
            continue;
        }else{
            if(isset($h_map[$i][$j])){
                $light = $h_map[$i][$j];
            }else{
                $light = checkHeight($i, $j);
            }
            if($max - $light > $width ){
                continue;
            }
            if(isset($w_map[$i][$j])){
                $light += $w_map[$i][$j];
            }else{
                $light += checkWidth($i, $j);
            }
            $light--;
            $max = max($light, $max);
        }

    }

}
echo $max;

function checkHeight($i, $j){
    global $map, $height, $h_map;
    $num =0;
    $start = 0;
    for($t=$i; $t>=0; $t--) {
        if ($map[$t][$j] == ".") {
            $num++;
        } else {
            $start = $t + 1;
            break;
        }
    }
    $end = $height-1;
    for($t=$i; $t<$height; $t++) {
        if ($map[$t][$j] == ".") {
            $num++;
        } else {
            $end = $t - 1;
            break;
        }
    }
    $num = $num -1;
    for($t=$start; $t<=$end;$t++){
        $h_map[$t][$j] = $num;
    }
    return($num);
}

function checkWidth($i, $j){
    global $map, $width, $w_map;
    $num =0;
    $start = 0;
    for($t=$j; $t>=0; $t--) {
        if ($map[$i][$t] == ".") {
            $num++;
        } else {
            $start = $t + 1;
            break;
        }
    }
    $end = $width-1;
    for($t=$j; $t<$width; $t++) {
        if ($map[$i][$t] == ".") {
            $num++;
        } else {
            $end = $t - 1;
            break;
        }
    }
    $num = $num -1;
    for($t=$start; $t<=$end;$t++){
        $w_map[$i][$t] = $num;
    }
    return($num);
}


<?php
//error_reporting(0);
list($N,$A,$B,$C,$D) =  explode(" ",trim(fgets(STDIN)));
$S = trim(fgets(STDIN));
//$p = explode(" ",trim(fgets(STDIN)));

$S[$A-1]='A';
$S[$B-1]='B';
$result = false;
if ($C < $D) {
  if (preg_match("/\.{2,}/",$S,$matches)) {
    $result=true;
  }
}
else {
  if (preg_match("/\.{3,}/",$S,$matches)) {
    $result=true;
  }
}
if ($result)
  printf("Yes\n");
else
  printf("No\n");

Score : 400 points

Problem Statement

There are N squares arranged in a row, numbered 1, 2, ..., N from left to right.
You are given a string S of length N consisting of . and #. If the i-th character of S is #, Square i contains a rock; if the i-th character of S is ., Square i is empty.

In the beginning, Snuke stands on Square A, and Fnuke stands on Square B.

You can repeat the following operation any number of times:

Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.

You want to repeat this operation so that Snuke will stand on Square C and Fnuke will stand on Square D.

Determine whether this is possible.

Constraints

4 \leq N \leq 200\ 000

S is a string of length N consisting of . and #.

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

Square A, B, C and D do not contain a rock.

A, B, C and D are all different.

A < B

A < C

B < D

Input

Input is given from Standard Input in the following format:

N A B C D
S

Output

Print Yes if the objective is achievable, and No if it is not.

Sample Input 1

7 1 3 6 7
.#..#..

Sample Output 1

Yes

The objective is achievable by, for example, moving the two persons as follows. (A and B represent Snuke and Fnuke, respectively.)

A#B.#..

A#.B#..

.#AB#..

.#A.#B.

.#.A#B.

.#.A#.B

.#..#AB

Sample Input 2

7 1 3 7 6
.#..#..

Sample Output 2

No

Sample Input 3

15 1 3 15 13
...#.#...#.#...

Sample Output 3

Yes


<?php
/**
 * AGC034
 * A - Kenken Race
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d %d %d %d %d", $n, $a, $b, $c, $d);
$s = trim(fgets(STDIN));

$dp_sunuke[$a] = (($s[$a - 1] ?? false) == '.');
$dp_sunuke[$b] = (($s[$b - 1] ?? false) == '.');

if ($dp_sunuke[$a] == false or $dp_sunuke[$b] == false) {
    echo 'No', PHP_EOL;
    exit;
}
if ($c > $n or $d > $n) {
    echo 'No', PHP_EOL;
    exit;
}

$funuke_ok = [];
$sunuke_ok = [];

// echo 'funuke', PHP_EOL;
for ($i = $b + 1; $i <= $d; $i++) {
    $dp_funuke[$i] = (($s[$i - 1] ?? false) == '.') and (($dp_funuke[$i - 1] ?? false) or ($dp_funuke[$i - 2] ?? false));
    // echo $i, ':', $dp_funuke[$i], PHP_EOL;
    $funuke_ok[] = $i;
}

// echo 'sunuke', PHP_EOL;
for ($i = $a + 1; $i <= $c; $i++) {
    $dp_sunuke[$i] = (($s[$i - 1] ?? false) == '.') and (($dp_sunuke[$i - 1] ?? false) or ($dp_sunuke[$i - 2] ?? false));
    // echo $i, ':', $dp_sunuke[$i], PHP_EOL;
    $sunuke_ok[] = $i;
}

if (count(array_diff($funuke_ok, $sunuke_ok)) == 0 or count(array_diff($sunuke_ok, $funuke_ok)) == 0) {
    echo 'No', PHP_EOL;
    exit;
}

if ($dp_sunuke[$c] and $dp_funuke[$d]) {
    echo 'Yes', PHP_EOL;
} else {
    echo 'No', PHP_EOL;
}


<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($N,$M) =  explode(" ",trim(fgets(STDIN)));
//$p = explode(" ",trim(fgets(STDIN)));

printf("%d\n",180*($N-2));

Score : 100 points

Problem Statement

Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides.

Print the answer in degrees, but do not print units.

Constraints

3 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print an integer representing the sum of the interior angles of a regular polygon with N sides.

Sample Input 1

3

Sample Output 1

180

The sum of the interior angles of a regular triangle is 180 degrees.

Sample Input 2

100

Sample Output 2

17640


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

$cnt_0=0;
$cnt_x=0;
$s=false;

for($i=0;$i<strlen($str);$i++){
	if(substr($str,$i,1)=="o"){
		$cnt_o++;
	}else{
		$cnt_x++;
	}

	if($cnt_o==7 && $i<15){
		echo "YES";
		break;
	}
	if($cnt_x==8){
		echo "NO";
		break;
	}

	if($cnt_o==8){
		echo "YES";
		break;
	}
}

?>

Score : 200 points

Problem Statement

Takahashi is competing in a sumo tournament.
The tournament lasts for 15 days, during which he performs in one match per day.
If he wins 8 or more matches, he can also participate in the next tournament.

The matches for the first k days have finished.
You are given the results of Takahashi's matches as a string S consisting of o and x.
If the i-th character in S is o, it means that Takahashi won the match on the i-th day; if that character is x, it means that Takahashi lost the match on the i-th day.

Print YES if there is a possibility that Takahashi can participate in the next tournament, and print NO if there is no such possibility.

Constraints

1 \leq k \leq 15

S is a string of length k consisting of o and x.

Input

Input is given from Standard Input in the following format:

S

Output

Print YES if there is a possibility that Takahashi can participate in the next tournament, and print NO otherwise.

Sample Input 1

oxoxoxoxoxoxox

Sample Output 1

YES

Takahashi has 7 wins and 7 losses before the last match. If he wins that match, he will have 8 wins.

Sample Input 2

xxxxxxxx

Sample Output 2

NO


<?php

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

$array = str_split($str);

$size = count($array);
$win = 0;
foreach($array as $letter){
    if($letter == "o"){
        $win++;
    }
}
$residue = 15 -$size;

if($win + $residue < 8){
    echo "NO";
}else{
    echo "YES";
}


<?php
list($A,$P)=sscanf(trim(fgets(STDIN)),"%d %d");
print(floor(($A*3 + $P) / 2));

Score : 100 points

Problem Statement

We have A apples and P pieces of apple.

We can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.

Find the maximum number of apple pies we can make with what we have now.

Constraints

All values in input are integers.

0 \leq A, P \leq 100

Input

Input is given from Standard Input in the following format:

A P

Output

Print the maximum number of apple pies we can make with what we have.

Sample Input 1

1 3

Sample Output 1

3

We can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.

Sample Input 2

0 1

Sample Output 2

0

We cannot make an apple pie in this case, unfortunately.

Sample Input 3

32 21

Sample Output 3

58