<?php
$N = (int)trim(fgets(STDIN));
$input = (int)trim(fgets(STDIN));
$A = explode(" ", $input);
$n = 0;

foreach ($A as $value){
    if ($value%2 == 0){
        if (($value%3 == 0)or($value%5 == 0)){
            $n = print 'APPROVED';
            break;
        }
    }
}

if ($n === 0){
    print 'DENIED';
}
?>

Score: 200 points

Problem Statement

You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria.

According to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied:

All even numbers written on the document are divisible by 3 or 5.

If the immigrant should be allowed entry according to the regulation, output APPROVED; otherwise, print DENIED.

Notes

The condition in the statement can be rephrased as "If x is an even number written on the document, x is divisible by 3 or 5".
Here "if" and "or" are logical terms.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq A_i \leq 1000

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

If the immigrant should be allowed entry according to the regulation, print APPROVED; otherwise, print DENIED.

Sample Input 1

5
6 7 9 10 31

Sample Output 1

APPROVED

The even numbers written on the document are 6 and 10.

All of them are divisible by 3 or 5, so the immigrant should be allowed entry.

Sample Input 2

3
28 27 24

Sample Output 2

DENIED

28 violates the condition, so the immigrant should not be allowed entry.


<?php

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

$array = explode(" ", $chars);
$isAccepted = true;

for($i=0;$i<$n;$i++){
  if($array[$i] % 2 == 0){
    if(($array[$i] % 3 == 0) || ($array[$i] % 5 == 0)){
    } else {
      $isAccepted = false;
    }
  }
}

if($isAccepted){
  $answer = "APPROVED";
} else {
  $answer = "DENIED";
}

echo $answer.PHP_EOL;

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

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

$ss = array();
for ($i=0; $i < $n; $i++) {
  fscanf(STDIN, "%s", $s);
  if (isset($ss[$s])) {
    $ss[$s]++;
  } else {
    $ss[$s] = 0;
  }
}

arsort($ss);

$before = 0;
$answers = array();
foreach ($ss as $k => $v) {
  if ($v >= $before) {
    $answers[] = $k;
  } else {
    break;
  }
  $before = $v;
}

asort($answers);

foreach ($answers as $answer) {
  echo $answer . "\n";
}

Score: 300 points

Problem Statement

We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it.

Print all strings that are written on the most number of votes, in lexicographical order.

Constraints

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

S_i (1 \leq i \leq N) are strings consisting of lowercase English letters.

The length of S_i (1 \leq i \leq N) is between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print all strings in question in lexicographical order.

Sample Input 1

7
beat
vet
beet
bed
vet
bet
beet

Sample Output 1

beet
vet

beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.

Sample Input 2

8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo

Sample Output 2

buffalo

Sample Input 3

7
bass
bass
kick
kick
bass
kick
kick

Sample Output 3

kick

Sample Input 4

4
ushi
tapu
nichia
kun

Sample Output 4

kun
nichia
tapu
ushi


<?php

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

$ss = array();
for ($i=0; $i < $n; $i++) {
  fscanf(STDIN, "%s", $s);
  if (isset($ss[$s])) {
    $ss[$s]++;
  } else {
    $ss[$s] = 0;
  }
}

arsort($ss);

$before = 0;
foreach ($ss as $k => $v) {
  if ($v >= $before) {
    echo $k . "\n";
  } else {
    exit;
  }
  $before = $v;
}


<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B,$C) = explode(" ",trim(fgets(STDIN)));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
//function chmax(&$a,$b) {if ($a<$b){$a=$b;return true;}return false;}
//function chmix(&$a,$b) {if ($a>$b){$a=$b;return true;}return false;}

$res = array();
for($i=0;$i<$N;$i++) {
  $S=trim(fgets(STDIN));
  if (isset($res[$S])) {
    $res[$S]+=1;
  }
  else {
    $res[$S]=1;
  }
}
$maxmatch = max($res);
$rr = array();
foreach($res as $k=>$v) {
  if ($v == $maxmatch) {
    $rr[]=$k;
  }
}
sort($rr);
foreach($rr as $v) {
  printf("%s\n",$v);
}


Score : 100 points

Problem Statement

We have A balls with the string S written on each of them and B balls with the string T written on each of them.

From these balls, Takahashi chooses one with the string U written on it and throws it away.

Find the number of balls with the string S and balls with the string T that we have now.

Constraints

S, T, and U are strings consisting of lowercase English letters.

The lengths of S and T are each between 1 and 10 (inclusive).

S \not= T

S=U or T=U.

1 \leq A,B \leq 10

A and B are integers.

Input

Input is given from Standard Input in the following format:

S T
A B
U

Output

Print the answer, with space in between.

Sample Input 1

red blue
3 4
red

Sample Output 1

2 4

Takahashi chose a ball with red written on it and threw it away.
Now we have two balls with the string S and four balls with the string T.

Sample Input 2

red blue
5 5
blue

Sample Output 2

5 4

Takahashi chose a ball with blue written on it and threw it away.
Now we have five balls with the string S and four balls with the string T.


<?php

$s = trim(fgets(STDIN));

echo str_repeat('*', strlen($s));

Score : 200 points

Problem Statement

Given is a string S. Replace every character in S with x and print the result.

Constraints

S is a string consisting of lowercase English letters.

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

Input

Input is given from Standard Input in the following format:

S

Output

Replace every character in S with x and print the result.

Sample Input 1

sardine

Sample Output 1

xxxxxxx

Replacing every character in S with x results in xxxxxxx.

Sample Input 2

xxxx

Sample Output 2

xxxx

Sample Input 3

gone

Sample Output 3

xxxx


<?php

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

$accumulated_expected_value = [0];
for ($i = 0; $i < $n; ++$i) {
    $sum = 0;
    for ($j = 1; $j <= $p_list[$i]; ++$j) {
        $sum += $j;
    }

    $accumulated_expected_value[$i + 1] = $accumulated_expected_value[$i] + ($sum / $p_list[$i]);
}

$sum_expected_value = [];
for ($i = $k; $i <= $n; ++$i) {
    $sum_expected_value[] = $accumulated_expected_value[$i] - $accumulated_expected_value[$i - $k];
}

echo max($sum_expected_value);

Score : 400 points

Problem Statement

We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.

We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.

Constraints

1 ≤ K ≤ N ≤ 200000

1 ≤ p_i ≤ 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N

Output

Print the maximum possible value of the expected value of the sum of the numbers shown.

Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

5 3
1 2 2 4 5

Sample Output 1

7.000000000000

When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.

Sample Input 2

4 1
6 6 6 6

Sample Output 2

3.500000000000

Regardless of which die we choose, the expected value of the number shown is 3.5.

Sample Input 3

10 4
17 13 13 12 15 20 10 13 17 11

Sample Output 3

32.000000000000


<?php
    list($n, $k) = explode(" ", trim(fgets(STDIN)));
    $arr = explode(" ", trim(fgets(STDIN)));
    for($i = 0; $i < $n; $i++){
        $sum = 0;
        for($j = 0; $j < $arr[$i]; $j++){
            $sum = $sum + $j + 1;
        }
        $arr[$i] = $sum / $arr[$i];
    }
    $ans = 0;
    $ans = floatval($ans);
    for($i = 0; $i < $n - $k + 1; $i++){
        $tmp = 0;
        $tmp = floatval($tmp);
        for($j = 0; $j < $k; $j++){
            $tmp += floatval($arr[$i + $j]);
        }
        if($ans < $tmp){
            $ans = $tmp;
        }
    }
    echo $ans;
?>


<?php
fscanf(STDIN, "%d %d", $h, $a);
echo ceil($h/$a);

Score : 100 points

Problem Statement

Serval is fighting with a monster.

The health of the monster is H.

In one attack, Serval can decrease the monster's health by A.
There is no other way to decrease the monster's health.

Serval wins when the monster's health becomes 0 or below.

Find the number of attacks Serval needs to make before winning.

Constraints

1 \leq H \leq 10^4

1 \leq A \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H A

Output

Print the number of attacks Serval needs to make before winning.

Sample Input 1

10 4

Sample Output 1

3

After one attack, the monster's health will be 6.

After two attacks, the monster's health will be 2.

After three attacks, the monster's health will be -2.

Thus, Serval needs to make three attacks to win.

Sample Input 2

1 10000

Sample Output 2

1

Sample Input 3

10000 1

Sample Output 3

10000


<?php

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

$n_str = trim(fgets(STDIN));
$n_list = explode(' ', $n_str);

echo (array_sum($n_list) >= $h) ? 'Yes' : 'No';

Score : 200 points

Problem Statement

Raccoon is fighting with a monster.

The health of the monster is H.

Raccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.
There is no other way to decrease the monster's health.

Raccoon wins when the monster's health becomes 0 or below.

If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.

Constraints

1 \leq H \leq 10^9

1 \leq N \leq 10^5

1 \leq A_i \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H N
A_1 A_2 ... A_N

Output

If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.

Sample Input 1

10 3
4 5 6

Sample Output 1

Yes

The monster's health will become 0 or below after, for example, using the second and third moves.

Sample Input 2

20 3
4 5 6

Sample Output 2

No

Sample Input 3

210 5
31 41 59 26 53

Sample Output 3

Yes

Sample Input 4

211 5
31 41 59 26 53

Sample Output 4

No


<?php
$input = '';
while ($line = fgets(STDIN)) {
  $input = implode(' ', [$input, trim($line)]);
}

$input = explode(' ', trim($input));

$input = array_map(function($i){ return (int)$i;}, $input);

$total = 0;

for ($i = 2; $i < count($input); $i++) {
  $total += $input[$i];
}

echo $total >= $input[0] ? 'Yes' : 'No';


<?php
  fscanf(STDIN, "%d %d", $h,$n);
while ($a = fgets(STDIN)){
$skill = explode(" ", $a);
  $hit=array_sum($skill);
   if($h>$hit){
  echo "No";
  }else{
  echo "Yes";
  }
};
?>


<?php
list($H, $N) = ints();
$dp = array_fill(0, $N + 1, array_fill(0, $H + 1, 10**18));
$dp[0][0] = 0;
for($i = 1; $i <= $N; $i++){
  $dp[$i] = $dp[$i-1];
  list($a, $b) = ints();
  for($j = 1; $j <= $H; $j++){
    if($j - $a >= 0){
      $dp[$i][$j] = min($dp[$i][$j], $dp[$i][$j-$a]+$b);
    }else{
      $dp[$i][$j] = min($dp[$i][$j], $b);
    }
  }
}
//o($dp);
echo $dp[$N][$H];
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function 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(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}

Score : 500 points

Problem Statement

Ibis is fighting with a monster.

The health of the monster is H.

Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points.

The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.

Ibis wins when the health of the monster becomes 0 or below.

Find the minimum total Magic Points that have to be consumed before winning.

Constraints

1 \leq H \leq 10^4

1 \leq N \leq 10^3

1 \leq A_i \leq 10^4

1 \leq B_i \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H N
A_1 B_1
:
A_N B_N

Output

Print the minimum total Magic Points that have to be consumed before winning.

Sample Input 1

9 3
8 3
4 2
2 1

Sample Output 1

4

First, let us cast the first spell to decrease the monster's health by 8, at the cost of 3 Magic Points. The monster's health is now 1.

Then, cast the third spell to decrease the monster's health by 2, at the cost of 1 Magic Point. The monster's health is now -1.

In this way, we can win at the total cost of 4 Magic Points.

Sample Input 2

100 6
1 1
2 3
3 9
4 27
5 81
6 243

Sample Output 2

100

It is optimal to cast the first spell 100 times.

Sample Input 3

9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461

Sample Output 3

139815


<?php
	$input = explode(' ', trim(fgets(STDIN)));
	echo $input[0] === $input[1]
    	? 'Yes'
      	: 'NO';

Score : 100 points

Problem Statement

Takahashi is participating in a programming contest, AXC001. He has just submitted his code to Problem A.

The problem has N test cases, all of which must be passed to get an AC verdict.

Takahashi's submission has passed M cases out of the N test cases.

Determine whether Takahashi's submission gets an AC.

Constraints

1 \leq N \leq 100

0 \leq M \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

If Takahashi's submission gets an AC, print Yes; otherwise, print No.

Sample Input 1

3 3

Sample Output 1

Yes

All three test cases have been passed, so his submission gets an AC.

Sample Input 2

3 2

Sample Output 2

No

Only two out of the three test cases have been passed, so his submission does not get an AC.

Sample Input 3

1 1

Sample Output 3

Yes


<?php
fscanf(STDIN, "%d%d", $A, $B);
if($A == $B){
    echo "Yes";
}else{
    echo "No";
}


<?php

fscanf(STDIN,"%d",$n);
$p = explode(" ",trim(fgets(STDIN)));

$max = $n;
$cnt=0;
for($i=0;$i<count($p);$i++){
	if($max>=$p[$i]){
      $max = $p[$i];
      $cnt++;
    }
}
echo $cnt;

?>

Score : 300 points

Problem Statement

Given is a permutation P_1, \ldots, P_N of 1, \ldots, N.
Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:

For any integer j (1 \leq j \leq i), P_i \leq P_j.

Constraints

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

P_1, \ldots, P_N is a permutation of 1, \ldots, N.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
P_1 ... P_N

Output

Print the number of integers i that satisfy the condition.

Sample Input 1

5
4 2 5 1 3

Sample Output 1

3

i=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.

Similarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.

Sample Input 2

4
4 3 2 1

Sample Output 2

4

All integers i (1 \leq i \leq N) satisfy the condition.

Sample Input 3

6
1 2 3 4 5 6

Sample Output 3

1

Only i=1 satisfies the condition.

Sample Input 4

8
5 7 4 2 6 8 1 3

Sample Output 4

4

Sample Input 5

1
1

Sample Output 5

1


<?php

list($n) = explode(' ', trim(fgets(STDIN)));
$p_list = explode(' ', trim(fgets(STDIN)));

$counter = 0;
$min = $n;
foreach ($p_list as $p) {
    if ($p > $min) {
        continue;
    }

    ++$counter;
    $min = $p;
}

echo $counter;


<?php

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

$edges = [];
$restriction_edges = [];
for ($i = 0; $i < $n - 1; ++$i) {
    $restriction_edges[$i] = 0;
    fscanf(STDIN, "%d%d", $a, $b);

    if (!isset($edges[$a])) {
        $edges[$a] = [];
    }

    if (!isset($edges[$b])) {
        $edges[$b] = [];
    }

    $edges[$a][$b] = $i;
    $edges[$b][$a] = $i;
}

$path = [1 => []];
makePath($path, 1, $edges);

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

for ($i = 0; $i < $m; ++$i) {
    fscanf(STDIN, "%d%d", $u, $v);
    foreach (findPath($u, $v, $path) as $edge_id) {
        $restriction_edges[$edge_id] += 2 ** $i;
    }
}

$answer = 0;
for ($i = 0; $i < 2 ** $m; ++$i) {
    $count = 0;
    foreach ($restriction_edges as $edge_id => $value) {
        if ($value & $i) {
            ++$count;
        }
    }

    $will_add = true;
    for ($j = 0; $j < 2 ** $m; ++$j) {
        if ($i & 2 ** $j) {
            $will_add = !$will_add;
        }
    }

    if ($will_add) {
        $answer += 2 ** ($n - 1 - $count);
    } else {
        $answer -= 2 ** ($n - 1 - $count);
    }
}

echo $answer;

function makePath(array &$path, int $target_vertex_id, array $edges): void
{
    foreach ($edges[$target_vertex_id] as $next_vertex_id => $edge_id) {
        if (isset($path[$next_vertex_id])) {
            continue;
        }
        $path[$next_vertex_id] = array_merge($path[$target_vertex_id], [$edge_id]);
        makePath($path, $next_vertex_id, $edges);
    }
}

function findPath(int $u, int $v, array $path): array
{
    $path_u = $path[$u];
    $path_v = $path[$v];

    $path_lca = array_intersect($path_u, $path_v);

    return array_diff(array_merge($path_u, $path_v), $path_lca);
}

Score : 600 points

Problem Statement

We have a tree with N vertices numbered 1 to N.
The i-th edge in this tree connects Vertex a_i and Vertex b_i.

Consider painting each of these edges white or black. There are 2^{N-1} such ways to paint the edges. Among them, how many satisfy all of the following M restrictions?

The i-th (1 \leq i \leq M) restriction is represented by two integers u_i and v_i, which mean that the path connecting Vertex u_i and Vertex v_i must contain at least one edge painted black.

Constraints

2 \leq N \leq 50

1 \leq a_i,b_i \leq N

The graph given in input is a tree.

1 \leq M \leq \min(20,\frac{N(N-1)}{2})

1 \leq u_i < v_i \leq N

If i \not= j, either u_i \not=u_j or v_i\not=v_j

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}
M
u_1 v_1
:
u_M v_M

Output

Print the number of ways to paint the edges that satisfy all of the M conditions.

Sample Input 1

3
1 2
2 3
1
1 3

Sample Output 1

3

The tree in this input is shown below:

All of the M restrictions will be satisfied if Edge 1 and 2 are respectively painted (white, black), (black, white), or (black, black), so the answer is 3.

Sample Input 2

2
1 2
1
1 2

Sample Output 2

1

The tree in this input is shown below:

All of the M restrictions will be satisfied only if Edge 1 is painted black, so the answer is 1.

Sample Input 3

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

Sample Output 3

9

The tree in this input is shown below:

Sample Input 4

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

Sample Output 4

62

The tree in this input is shown below:


<?php

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

$vertices = [];
$edges = [];
for ($i = 0; $i < $n - 1; ++$i) {
    fscanf(STDIN, "%d%d", $a, $b);

    if (!isset($vertices[$a])) {
        $vertices[$a] = new Vertex($a);
        $edges[$a] = [];
    }

    if (!isset($vertices[$b])) {
        $vertices[$b] = new Vertex($b);
        $edges[$b] = [];
    }

    $edges[$a][$b] = new Edge($i, $vertices[$a], $vertices[$b]);
    $edges[$b][$a] = new Edge($i, $vertices[$b], $vertices[$a]);
}

$tree = new Tree($vertices, $edges);

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

$restriction_list = [['term_num' => 0, 'paths' => []]];
for ($i = 0; $i < $m; ++$i) {
    fscanf(STDIN, "%d%d", $u, $v);

    $lca = $tree->findLCA($u, $v);
    $path_u = $tree->getPathsIdList($lca, $u);
    $path_v = $tree->getPathsIdList($lca, $v);

    $new_restrictions = [];
    foreach ($restriction_list as $restrictions) {
        ++$restrictions['term_num'];
        $restrictions['paths'] = array_unique(array_merge($restrictions['paths'], $path_u, $path_v));
        $new_restrictions[] = $restrictions;
    }

    $restriction_list = array_merge($restriction_list, $new_restrictions);
}

$answer = 0;
foreach ($restriction_list as $restrictions) {
    if ($restrictions['term_num'] % 2 === 0) {
        $answer += 2 ** ($n - 1 - count($restrictions['paths']));
    } else {
        $answer -= 2 ** ($n - 1 - count($restrictions['paths']));
    }
}
echo $answer;

class Tree
{
    public $vertices;
    public $downstream_edges = [];
    public $upstream_edges = [];

    public function __construct(array $vertices, array $edges)
    {
        $this->vertices = $vertices;

        $this->vertices[1]->setDepth(0);

        $this->composeTree($this->vertices[1], $edges);
    }

    protected function composeTree(Vertex $vertex, array $edges)
    {
        $this->downstream_edges[$vertex->id] = [];
        foreach ($edges[$vertex->id] as $child_id => $edge) {
            $this->downstream_edges[$vertex->id][$child_id] = $edge;
            $this->upstream_edges[$child_id] = $edge;

            $vertex->addChild($this->vertices[$child_id]);

            unset($edges[$child_id][$vertex->id]);

            $this->composeTree($this->vertices[$child_id], $edges);
        }
    }

    public function findLCA(int $i, int $j): int
    {
        $vertex_i = $this->vertices[$i];
        $vertex_j = $this->vertices[$j];

        $i_parent = $vertex_i->depth > $vertex_j->depth ? $vertex_i->findNthParent($vertex_i->depth - $vertex_j->depth) : $vertex_i;
        $j_parent = $vertex_i->depth > $vertex_j->depth ? $vertex_j : $vertex_j->findNthParent($vertex_j->depth - $vertex_i->depth);
        while ($i_parent !== $j_parent) {
            $i_parent = $i_parent->findNthParent(1);
            $j_parent = $j_parent->findNthParent(1);
        }

        return $i_parent->id;
    }

    public function getPathsIdList(int $i, int $j): array
    {
        $from = $this->vertices[$i];
        $to = $this->vertices[$j];

        $paths_id_list = [];
        if ($from->id === $to->id) {
            return $paths_id_list;
        }

        while ($to->id !== $from->id) {
            $paths_id_list[] = $this->upstream_edges[$to->id]->id;
            $to = $to->parent;
        }

        return $paths_id_list;
    }
}

class Edge
{
    public $id;
    public $source;
    public $target;

    public function __construct(int $id, Vertex $source, Vertex $target)
    {
        $this->id = $id;
        $this->source = $source;
        $this->target = $target;
    }
}

class Vertex
{
    public $id;
    public $parent;
    public $children = [];
    public $depth;

    public function __construct(int $id)
    {
        $this->id = $id;
    }

    public function addChild(Vertex $child): void
    {
        $this->children[] = $child;
        $child->setParent($this);
        $child->setDepth($this->depth + 1);
    }

    public function setParent(Vertex $parent): void
    {
        $this->parent = $parent;
    }

    public function setDepth(int $depth): void
    {
        $this->depth = $depth;
    }

    public function findNthParent(int $generation): ?self
    {
        if ($generation === 0) {
            return $this;
        }

        if ($this->parent === null) {
            return null;
        }
        return $this->parent->findNthParent($generation - 1);
    }
}


Score : 200 points

Problem Statement

In a factory, there are N robots placed on a number line.
Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.

We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect.
Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.

Find the maximum number of robots that we can keep.

Constraints

1 \leq N \leq 100,000

0 \leq X_i \leq 10^9 (1 \leq i \leq N)

1 \leq L_i \leq 10^9 (1 \leq i \leq N)

If i \neq j, X_i \neq X_j.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 L_1
X_2 L_2
\vdots
X_N L_N

Output

Print the maximum number of robots that we can keep.

Sample Input 1

4
2 4
4 3
9 3
100 5

Sample Output 1

3

By removing Robot 2, we can keep the other three robots.

Sample Input 2

2
8 20
1 10

Sample Output 2

1

Sample Input 3

5
10 1
2 1
4 1
6 1
8 1

Sample Output 3

5


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

    for($i=0;$i<$M;$i++){
        list($p,$s) = array_map(null,explode(" ",trim(fgets(STDIN))));

        $INFO[intval($p)][] = $s;
    }
    if($M==0){
        echo "0 0";
        exit;
    }

    // var_dump($INFO);

    $miss = 0;
    $clear = 0;

    //各問いに対して初めてACするまでするのにかかった提出回数を出す
    foreach($INFO as $value1){
        foreach($value1 as $value2){
            if($value2 == "WA"){
                $miss++;
            }else{
                $clear++;
                break;
            }
        }
    }
    echo $clear." ".$miss;

?>

Score : 300 points

Problem Statement

Takahashi participated in a contest on AtCoder.

The contest had N problems.

Takahashi made M submissions during the contest.

The i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).

The number of Takahashi's correct answers is the number of problems on which he received an AC once or more.

The number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.

Find the numbers of Takahashi's correct answers and penalties.

Constraints

N, M, and p_i are integers.

1 \leq N \leq 10^5

0 \leq M \leq 10^5

1 \leq p_i \leq N

S_i is AC or WA.

Input

Input is given from Standard Input in the following format:

N M
p_1 S_1
:
p_M S_M

Output

Print the number of Takahashi's correct answers and the number of Takahashi's penalties.

Sample Input 1

2 5
1 WA
1 AC
2 WA
2 AC
2 WA

Sample Output 1

2 2

In his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.

In his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.

Thus, he has two correct answers and two penalties.

Sample Input 2

100000 3
7777 AC
7777 AC
7777 AC

Sample Output 2

1 0

Note that it is pointless to get an AC more than once on the same problem.

Sample Input 3

6 0

Sample Output 3

0 0


<?php
define("MOD", 10**9+7);
list($N, $K) = ints();
$A = ints();
sort($A);
$minSum = 0;
$maxSum = 0;
foreach($A as $i => $a){
    if($N-$i-1 >= $K-1){
        $minSum += $a * nCm($N-$i-1, $K-1);
        $minSum %= MOD;
    }
}
$A = array_reverse($A);
foreach($A as $i => $a){
    if($N-$i-1 >= $K-1){
        $maxSum += ($a * nCm($N-$i-1, $K-1)) % MOD;
        $maxSum %= MOD;
    }
}
echo ($maxSum + MOD - $minSum)%MOD;

//足し算
function addm($a, $b){
    return ($a + $b) % MOD;
}
//引き算
function subm($a, $b){
    return ($a + MOD - $b) % MOD;
}
//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}
//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}
//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}
//階乗
function factorialm($a){
    static $memo = false;
    if(!$memo){
        $memo = [];
        $num = 1;
        $memo[0] = 1;
        for($i = 1; $i <= 100000; $i++){
            $num*=$i;
            $num%=MOD;
            $memo[$i] = $num;
        }
    }
    return $memo[$a];
}
//順列
function nPm($n, $m){
    if($m == 0)return 1;
    return nPm($n, $m - 1) * ($n - $m + 1) % MOD;
}
//組み合わせ
function nCm($n, $m){
    $m = min($m, $n-$m);
    return divm(nPm($n, $m), factorialm($m));
}
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 : 500 points

Problem Statement

For a finite set of integers X, let f(X)=\max X - \min X.

Given are N integers A_1,...,A_N.

We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways.

Since the answer can be enormous, print it \bmod (10^9+7).

Constraints

1 \leq N \leq 10^5

1 \leq K \leq N

|A_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N K
A_1 ... A_N

Output

Print the answer \bmod (10^9+7).

Sample Input 1

4 2
1 1 3 4

Sample Output 1

11

There are six ways to choose S: \{1,1\},\{1,3\},\{1,4\},\{1,3\},\{1,4\}, \{3,4\} (we distinguish the two 1s). The value of f(S) for these choices are 0,2,3,2,3,1, respectively, for the total of 11.

Sample Input 2

6 3
10 10 10 -10 -10 -10

Sample Output 2

360

There are 20 ways to choose S. In 18 of them, f(S)=20, and in 2 of them, f(S)=0.

Sample Input 3

3 1
1 1 1

Sample Output 3

0

Sample Input 4

10 6
1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0

Sample Output 4

999998537

Print the sum \bmod (10^9+7).


Score : 600 points

Problem Statement

Given are N points (x_i, y_i) in a two-dimensional plane.

Find the minimum radius of a circle such that all the points are inside or on it.

Constraints

2 \leq N \leq 50

0 \leq x_i \leq 1000

0 \leq y_i \leq 1000

The given N points are all different.

The values in input are all 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 radius of a circle such that all the N points are inside or on it.

Your output will be considered correct if the absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

2
0 0
1 0

Sample Output 1

0.500000000000000000

Both points are contained in the circle centered at (0.5,0) with a radius of 0.5.

Sample Input 2

3
0 0
0 1
1 0

Sample Output 2

0.707106781186497524

Sample Input 3

10
10 9
5 9
2 0
0 0
2 7
3 3
2 5
10 0
3 7
1 9

Sample Output 3

6.726812023536805158

If the absolute or relative error from our answer is at most 10^{-6}, the output will be considered correct.


fscanf(STDIN, "%d", $k);
fscanf(STDIN, "%d", $x);
if(500 * $k >= $x){
  echo 'Yes';
  echo '
';
}else{
  echo 'No';
  echo '
';
}

Score : 100 points

Problem Statement

Takahashi has K 500-yen coins. (Yen is the currency of Japan.)
If these coins add up to X yen or more, print Yes; otherwise, print No.

Constraints

1 \leq K \leq 100

1 \leq X \leq 10^5

Input

Input is given from Standard Input in the following format:

K X

Output

If the coins add up to X yen or more, print Yes; otherwise, print No.

Sample Input 1

2 900

Sample Output 1

Yes

Two 500-yen coins add up to 1000 yen, which is not less than X = 900 yen.

Sample Input 2

1 501

Sample Output 2

No

One 500-yen coin is worth 500 yen, which is less than X = 501 yen.

Sample Input 3

4 2000

Sample Output 3

Yes

Four 500-yen coins add up to 2000 yen, which is not less than X = 2000 yen.


<?php

$n = trim(fgets(STDIN));
$p = explode(' ', trim(fgets(STDIN)));
$x = $q = explode(' ', trim(fgets(STDIN)));
sort($x);
$pstr = implode($p);
$qstr = implode($q);

$r = pat($x);

$ansl = $ansr = 0;
$c = 0;
for($i=0; $i<count($r); $i++){
  $c++;
  if ($r[$i] == $pstr){
    $ansl = $i;
  }
  if ($r[$i] == $qstr){
    $ansr = $i;
  }
}

$ans =  abs($ansl-$ansr);
echo $ans;

function pat($a, $s = '')
{
  $r = array();
  if (count($a) && is_array($a)) {
    foreach ($a as $k => $v) {
      $_s = $s . $v;
      $_a = $a;
      unset($_a[$k]);
      $_r = pat($_a, $_s);
      $r = array_merge($r, $_r);
    }
  } else {
    $r[] = $s;
  }
  return $r;
}

?>

Score : 300 points

Problem Statement

We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).

There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Notes

For two sequences X and Y, X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \leq i < k) and X_k < Y_k.

Constraints

2 \leq N \leq 8

P and Q are permutations of size N.

Input

Input is given from Standard Input in the following format:

N
P_1 P_2 ... P_N
Q_1 Q_2 ... Q_N

Output

Print |a - b|.

Sample Input 1

3
1 3 2
3 1 2

Sample Output 1

3

There are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3), (2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come 2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.

Sample Input 2

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

Sample Output 2

17517

Sample Input 3

3
1 2 3
1 2 3

Sample Output 3

0


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

printf("%s%s\n", $t, $s);
?>

Score : 100 points

Problem Statement

Given are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.

Constraints

S and T are strings consisting of lowercase English letters.

The lengths of S and T are between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

S T

Output

Print the resulting string.

Sample Input 1

oder atc

Sample Output 1

atcoder

When S = oder and T = atc, concatenating T and S in this order results in atcoder.

Sample Input 2

humu humu

Sample Output 2

humuhumu


Score : 200 points

Problem Statement

Takahashi has A cookies, and Aoki has B cookies.
Takahashi will do the following action K times:

If Takahashi has one or more cookies, eat one of his cookies.

Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.

If they both have no cookies, do nothing.

In the end, how many cookies will Takahashi and Aoki have, respectively?

Constraints

0 \leq A \leq 10^{12}

0 \leq B \leq 10^{12}

0 \leq K \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B K

Output

Print the numbers of Takahashi's and Aoki's cookies after K actions.

Sample Input 1

2 3 3

Sample Output 1

0 2

Takahashi will do the following:

He has two cookies, so he eats one of them.

Now he has one cookie left, and he eats it.

Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.

Thus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.

Sample Input 2

500000000000 500000000000 1000000000000

Sample Output 2

0 0

Watch out for overflows.


<?php

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

while (1) {
    $flg = true;
    $sqrt = sqrt($x);

    for ($i = 2; $i <= $sqrt; ++$i) {
        if ($x % $i === 0) {
            $flg = false;
            break;
        }
    }

    if ($flg) {
        break;
    }

    ++$x;
}

echo $x;

Score: 300 points

Problem Statement

Find the minimum prime number greater than or equal to X.

Notes

A prime number is an integer greater than 1 that cannot be evenly divided by any positive integer except 1 and itself.

For example, 2, 3, and 5 are prime numbers, while 4 and 6 are not.

Constraints

2 \le X \le 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

Print the minimum prime number greater than or equal to X.

Sample Input 1

20

Sample Output 1

23

The minimum prime number greater than or equal to 20 is 23.

Sample Input 2

2

Sample Output 2

2

X itself can be a prime number.

Sample Input 3

99992

Sample Output 3

100003


<?php
//$N = trim(fgets(STDIN));
list($N,$K) =  explode(" ",trim(fgets(STDIN)));
list($R,$S,$P) =  explode(" ",trim(fgets(STDIN)));
$T = trim(fgets(STDIN));
//$A =  explode(" ",trim(fgets(STDIN)));

$sum = 0;
$out = array();
for($i=0;$i<$N;$i++) {
  switch($T[$i]) {
    case "r":
      if (isset($out[$i-$K]) && $out[$i-$K]=="p") {
        $out[]="r";
      }
      else {
        $sum += $P;
        $out[]="p";
      }
      break;
    case "s":
      if (isset($out[$i-$K]) && $out[$i-$K]=="r") {
        $out[]="s";
      }
      else {
        $sum += $R;
        $out[]="r";
      }
      break;
    case "p":
      if (isset($out[$i-$K]) && $out[$i-$K]=="s") {
        $out[]="p";
      }
      else {
        $sum += $S;
        $out[]="s";
      }
      break;
  }
}
printf("%d\n",$sum);

Score : 400 points

Problem Statement

At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:

The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)

Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):

R points for winning with Rock;

S points for winning with Scissors;

P points for winning with Paper.

However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)

Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.

The information Takahashi obtained is given as a string T. If the i-th character of T (1 \leq i \leq N) is r, the machine will play Rock in the i-th round. Similarly, p and s stand for Paper and Scissors, respectively.

What is the maximum total score earned in the game by adequately choosing the hand to play in each round?

Notes

In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.

If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;

if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;

if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;

if both players play the same hand, it is a draw.

Constraints

2 \leq N \leq 10^5

1 \leq K \leq N-1

1 \leq R,S,P \leq 10^4

N,K,R,S, and P are all integers.

|T| = N

T consists of r, p, and s.

Input

Input is given from Standard Input in the following format:

N K
R S P
T

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

The machine will play {Rock, Scissors, Rock, Paper, Rock}.

We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points.
We cannot earn more points, so the answer is 27.

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996


<?php
fscanf(STDIN, "%d%d", $N, $M);
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
sort($A);

//累積和を作る
$AS[-1] = 0;
foreach($A as $i => $a){
    $AS[$i] = ($AS[$i-1] ?? 0) + $a;
}

//満足度がi以上の握手のパターン表を作っておく
for($i = 0; $i < 10**5*2+1; $i++){
    $lbmemo[$i] = lower_bound($A, $i);
}

//めぐる式二分探索 -- $k以上の値の個数がMを超えるなかで最大のkを求める
$ok = 0;
$ng = 10**5*2+1;
while(abs($ok - $ng) > 1){
    $mid = intdiv($ok+$ng, 2);
    $sum = 0;
    $count = 0;
    if(isOK($mid)){
        $ok = $mid;
    }else{
        $ng = $mid;
    }
}
echo $sum - $ok * ($count - $M);
function isOK($bound){
    global $M, $A, $AS, $N, $sum, $count, $lbmemo;
    foreach($A as $a){
        $i = $lbmemo[$bound - $a] ?? 0;
        $ok = $N - $i;
        $count += $ok;
        $sum += $AS[$N - 1] - $AS[$i - 1] + $a * $ok;
    }
    return $count >= $M;
}
function lower_bound($array, $key){
    global $N;
    $min = -1;
    $max = $N;
    while($max - $min > 1){
        $c = intdiv($min + $max, 2);
        if($array[$c] >= $key){
            $max = $c;
        }else{
            $min = $c;
        }
    }
    return $max;
}

Score : 500 points

Problem Statement

Takahashi has come to a party as a special guest.
There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i.

Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0).
A handshake will be performed as follows:

Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same).

Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y.

However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:

Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q).

What is the maximum possible happiness after M handshakes?

Constraints

1 \leq N \leq 10^5

1 \leq M \leq N^2

1 \leq A_i \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_N

Output

Print the maximum possible happiness after M handshakes.

Sample Input 1

5 3
10 14 19 34 33

Sample Output 1

202

Let us say that Takahashi performs the following handshakes:

In the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.

In the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.

In the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.

Then, we will have the happiness of (34+34)+(34+33)+(33+34)=202.

We cannot achieve the happiness of 203 or greater, so the answer is 202.

Sample Input 2

9 14
1 3 5 110 24 21 34 5 3

Sample Output 2

1837

Sample Input 3

9 73
67597 52981 5828 66249 75177 64141 40773 79105 16076

Sample Output 3

8128170


Score : 300 points

Problem Statement

2N players are running a competitive table tennis training on N tables numbered from 1 to N.

The training consists of rounds.
In each round, the players form N pairs, one pair per table.
In each pair, competitors play a match against each other.
As a result, one of them wins and the other one loses.

The winner of the match on table X plays on table X-1 in the next round,
except for the winner of the match on table 1 who stays at table 1.

Similarly, the loser of the match on table X plays on table X+1 in the next round,
except for the loser of the match on table N who stays at table N.

Two friends are playing their first round matches on distinct tables A and B.
Let's assume that the friends are strong enough to win or lose any match at will.
What is the smallest number of rounds after which the friends can get to play a match against each other?

Constraints

2 \leq N \leq 10^{18}

1 \leq A < B \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the smallest number of rounds after which the friends can get to play a match against each other.

Sample Input 1

5 2 4

Sample Output 1

1

If the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.

Sample Input 2

5 2 3

Sample Output 2

2

If both friends win two matches in a row, they will both move to table 1.


<?php
list($n, $a, $b) = ints();

if(abs($a-$b)%2 == 0){
    printf("%d", intdiv(abs($a-$b),2));
}else{
    printf("%d", min(max($n-$a, $n-$b) - intdiv(abs($a-$b),2), max($a-1, $b-1) - intdiv(abs($a-$b),2)));
}

function ints(){
  return array_map("intval", explode(" ", 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";
    }
}


<?php
$n = intval(trim(fgets(STDIN)));
if($n % 3 != 0){
    echo "-1";
}else{
    for($y = 0; $y < $n; $y++){
        for($x = 0; $x < $n; $x++){
            $map[$y][$x] = ".";
        }
    }
    for($y = 0; $y < floor($n/3); $y++){
        for($x = $n-2-$y*2; $x < $n-2-$y*2 + 2; $x++){
            $map[$y][$x] = "a";
            $map[$x][$y] = "a";
        }
    }
    foreach($map as $line){
        echo implode("", $line),"\n";
    }
}

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 : 900 points

Problem Statement

Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid.
Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.

For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row.
We define the quality of each column similarly.

Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column,
or determine that such a placement doesn't exist.

Constraints

2 \le N \le 1000

Input

Input is given from Standard Input in the following format:

N

Output

If the required domino placement doesn't exist, print a single integer -1.

Otherwise, output your placement as N strings of N characters each.
If a square is not covered, the corresponding character must be . (a dot).
Otherwise, it must contain a lowercase English letter.
Squares covered by the same domino piece must contain the same letter.
If two squares have a common side but belong to different pieces, they must contain different letters.

Sample Input 1

6

Sample Output 1

aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b

The quality of every row and every column is 2.

Sample Input 2

2

Sample Output 2

-1


<?php

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

$arr = [1 => 1, 2 => 2, 3=> 3];

unset($arr[$a], $arr[$b]);

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

Score: 100 points

Problem Statement

Takahashi is solving quizzes. He has easily solved all but the last one.

The last quiz has three choices: 1, 2, and 3.

With his supernatural power, Takahashi has found out that the choices A and B are both wrong.

Print the correct choice for this problem.

Constraints

Each of the numbers A and B is 1, 2, or 3.

A and B are different.

Input

Input is given from Standard Input in the following format:

A
B

Output

Print the correct choice.

Sample Input 1

3
1

Sample Output 1

2

When we know 3 and 1 are both wrong, the correct choice is 2.

Sample Input 2

1
2

Sample Output 2

3


Score : 300 points

Problem Statement

Takahashi is organizing a party.

At the party, each guest will receive one or more snack pieces.

Takahashi predicts that the number of guests at this party will be A or B.

Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.

We assume that a piece cannot be divided and distributed to multiple guests.

Constraints

1 \leq A, B \leq 10^5

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests.

Sample Input 1

2 3

Sample Output 1

6

When we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.

Sample Input 2

123 456

Sample Output 2

18696

Sample Input 3

100000 99999

Sample Output 3

9999900000


<?php
  fscanf(STDIN,"%d %d",$a,$b);
  echo ($a*$b)."\n";


<?php

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

$count = 0;
for($i=0;$i<count($a_li);$i++){
	if($i+1 != $a_li[$i]){
      array_splice($a_li,$i,1);
      $flag = true;
      $i -= 1;
      $count++;
    }
}
if(count($a_li) == 0){
  echo "-1\n";
}else{
  echo $count."\n";
}

Score : 400 points

Problem Statement

We have N bricks arranged in a row from left to right.

The i-th brick from the left (1 \leq i \leq N) has an integer a_i written on it.

Among them, you can break at most N-1 bricks of your choice.

Let us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \leq i \leq K), the i-th of those brick from the left has the integer i written on it.

Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.

Constraints

All values in input are integers.

1 \leq N \leq 200000

1 \leq a_i \leq N

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.

Sample Input 1

3
2 1 2

Sample Output 1

1

If we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.

Sample Input 2

3
2 2 2

Sample Output 2

-1

In this case, there is no way to break some of the bricks to satisfy Snuke's desire.

Sample Input 3

10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

7

Sample Input 4

1
1

Sample Output 4

0

There may be no need to break the bricks at all.


<?php
  fscanf(STDIN, "%d", $n);
  $array = explode(' ', trim(fgets(STDIN)));
  $i=0;
  while($i<count($array)){
    if($array[$i] != $i+1){
      unset($array[$i]);
      $array = array_values($array);
      $i--;
    }
    $i++;
  }
  if(empty($array)){
    echo -1;
  }else{
    echo $n-count($array);
  }
?>


<?php

class Inputs
{
    public static function d()
    {
        fscanf(STDIN, '%d', $a);
        return $a;
    }
    public static function line()
    {
        return fgets(STDIN);
    }
}

$n = Inputs::d();
$a = Inputs::line();

$as = explode(' ', $a);

$leave_count = 1;

foreach ($as as $brick) {
    if ($leave_count === intval($brick)) {
        $leave_count++;
    }
}

$break_count = count($as) - ($leave_count - 1);

echo (($break_count === count($as)) ? -1 : $break_count) . PHP_EOL;


<?php
$h = STDIN;
$max = (int)fgets($h);
$a = str_split(fgets($h));

//10
//3 1 4 1 5 9 2 6 5 3

$i = 0;
$ans = $max;
foreach ($a as $item) {
    $num = (int)$item;
    if ($num === $i + 1) {
        ++$i;
        continue;
    }
}
if ($i === 0) {
    echo -1;
}else{
    echo $ans - $i;
}


<?php
  fscanf(STDIN, "%d %d %d",$a, $b, $c);
if($a + $b + $c => 22) {
  echo 'bust';
} else {
  echo 'win';
}

Score : 100 points

Problem Statement

Given are three integers A_1, A_2, and A_3.

If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.

Constraints

1 \leq A_i \leq 13 \ \ (i=1,2,3)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A_1 A_2 A_3

Output

If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.

Sample Input 1

5 7 9

Sample Output 1

win

5+7+9=21, so print win.

Sample Input 2

13 7 2

Sample Output 2

bust

13+7+2=22, so print bust.


<?php
echo array_sum(array_map('intval', explode(" ", trim(fgets(STDIN))))) >= 22 ? 'bust' : 'win';


Score : 200 points

Problem Statement

Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.

Given is a string S. Find the minimum number of hugs needed to make S palindromic.

Constraints

S is a string consisting of lowercase English letters.

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

Input

Input is given from Standard Input in the following format:

S

Output

Print the minimum number of hugs needed to make S palindromic.

Sample Input 1

redcoder

Sample Output 1

1

For example, we can change the fourth character to o and get a palindrome redooder.

Sample Input 2

vvvvvv

Sample Output 2

0

We might need no hugs at all.

Sample Input 3

abcdabc

Sample Output 3

2


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


<?php
$n = intval(fgets(STDIN));
for($i = 0; $i < $n; $i++){
  $a[$i] = intval(fgets(STDIN));
  for($j = 0; $j < $a[$i]; $j++){
    list($b, $c) = array_map("intval", explode(" ", trim(fgets(STDIN))));
    $map[$i][$b-1] = $c;
  }
}
$max = 0;
for($i = 0, $I = 2**$n; $i < $I; $i++){
  $bits = sprintf("%0".$n."b", $i);
  $flag = true;
  foreach($map as $from => $row){
    if($bits[$from] == "1"){
      foreach($row as $to => $v){
        if($bits[$to] != $v){
          $flag = false;
          continue 3;
        }
      }
    }
  }
  if($flag){
    $sum = 0;
    for($j = 0; $j < $n; $j++){
      $sum+=$bits[$j];
    }
    $max = max($max, $sum);
  }
}
echo $max;

Score : 300 points

Problem Statement

There are N people numbered 1 to N. Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not.

Person i gives A_i testimonies. The j-th testimony by Person i is represented by two integers x_{ij} and y_{ij}. If y_{ij} = 1, the testimony says Person x_{ij} is honest; if y_{ij} = 0, it says Person x_{ij} is unkind.

How many honest persons can be among those N people at most?

Constraints

All values in input are integers.

1 \leq N \leq 15

0 \leq A_i \leq N - 1

1 \leq x_{ij} \leq N

x_{ij} \neq i

x_{ij_1} \neq x_{ij_2} (j_1 \neq j_2)

y_{ij} = 0, 1

Input

Input is given from Standard Input in the following format:

N
A_1
x_{11} y_{11}
x_{12} y_{12}
:
x_{1A_1} y_{1A_1}
A_2
x_{21} y_{21}
x_{22} y_{22}
:
x_{2A_2} y_{2A_2}
:
A_N
x_{N1} y_{N1}
x_{N2} y_{N2}
:
x_{NA_N} y_{NA_N}

Output

Print the maximum possible number of honest persons among the N people.

Sample Input 1

3
1
2 1
1
1 1
1
2 0

Sample Output 1

2

If Person 1 and Person 2 are honest and Person 3 is unkind, we have two honest persons without inconsistencies, which is the maximum possible number of honest persons.

Sample Input 2

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

Sample Output 2

0

Assuming that one or more of them are honest immediately leads to a contradiction.

Sample Input 3

2
1
2 0
1
1 0

Sample Output 3

1


<?php
define('MOD', 10 ** 9 + 7);
fscanf(STDIN, '%d', $n);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = 0;
for ($k = 0; $k < 60; $k++) {
    $cnt_1 = 0;
    for ($i = 0; $i < $n; $i++) {
        if (($a[$i] >> $k) & 1) $cnt_1++;
    }
    $ans = modAdd($ans, modMul(modMul($n - $cnt_1, $cnt_1), modPow(2, $k)));
}
echo $ans . PHP_EOL;

// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}

Score : 400 points

Problem Statement

We have N integers. The i-th integer is A_i.

Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Constraints

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

0 \leq A_i < 2^{60}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the value \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).

Sample Input 1

3
1 2 3

Sample Output 1

6

We have (1\mbox{ XOR } 2)+(1\mbox{ XOR } 3)+(2\mbox{ XOR } 3)=3+2+1=6.

Sample Input 2

10
3 1 4 1 5 9 2 6 5 3

Sample Output 2

237

Sample Input 3

10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820

Sample Output 3

103715602

Print the sum modulo (10^9+7).


<?php

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

fscanf(STDIN, "%d%d", $m2, $d2);

if($m != $m2){
    echo 1;
}else{
    echo 0;
}

Score: 100 points

Problem Statement

In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019.

Integers M_1, D_1, M_2, and D_2 will be given as input.

It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1.

Determine whether the date 2019-M_1-D_1 is the last day of a month.

Constraints

Both 2019-M_1-D_1 and 2019-M_2-D_2 are valid dates in the Gregorian calendar.

The date 2019-M_2-D_2 follows 2019-M_1-D_1.

Input

Input is given from Standard Input in the following format:

M_1 D_1
M_2 D_2

Output

If the date 2019-M_1-D_1 is the last day of a month, print 1; otherwise, print 0.

Sample Input 1

11 16
11 17

Sample Output 1

0

November 16 is not the last day of a month.

Sample Input 2

11 30
12 1

Sample Output 2

1

November 30 is the last day of November.


<?php
  $n=fgets(STDIN);
  $S=$n/1.08;
  $d=ceil($S);
  if (floor($d*1.08)==$n){
    echo $d;

  }else{
    echo :(;

Score: 200 points

Problem Statement

Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it.

The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer).

Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer.

If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.

Constraints

1 \leq N \leq 50000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If there are values that could be X, the price of the apple pie before tax, print any one of them.

If there are multiple such values, printing any one of them will be accepted.

If no value could be X, print :(.

Sample Input 1

432

Sample Output 1

400

If the apple pie is priced at 400 yen before tax, you have to pay 400 \times 1.08 = 432 yen to buy one.

Otherwise, the amount you have to pay will not be 432 yen.

Sample Input 2

1079

Sample Output 2

:(

There is no possible price before tax for which you have to pay 1079 yen with tax.

Sample Input 3

1001

Sample Output 3

927

If the apple pie is priced 927 yen before tax, by rounding down 927 \times 1.08 = 1001.16, you have to pay 1001 yen.


<?php
  $n = intVal(trim(fgets(STDIN)));
  $s = array_map("intVal", explode(" ", trim(fgets(STDIN))));
  $color = 0;
  $ans = 1;
  $MOD = 1000000007;
  $cur = [-1, -1, -1];

  if($s[0] != 0){
    echo 0 . PHP_EOL;
    exit();
  }
  foreach($s as $c){
    if($c == 0){
      if($color >= 3){
        echo 0 . PHP_EOL;
        exit;
      }
      $cur[$color] = 0;
      $color += 1;
      $ans %= $MOD;
    }else{
      $x = 0;
      foreach($cur as $curn){
        if($curn == $c-1){
          $x += 1;
        }
      }
      if($x == 0){
        echo 0 . PHP_EOL;
        exit();
      }
      $ans *= $x;
      $ans %= $MOD;
      $idx = array_search($c-1, $cur);
      $cur[$idx] += 1;
    }
  }

  if($color == 0){
    $ans *= 1;
  }elseif($color == 1){
    $ans *= 3;
  }else{
    $ans *= 6;
  }
  $ans %= $MOD;
  echo $ans . PHP_EOL;
?>

Score: 500 points

Problem Statement

N people are standing in a queue, numbered 1, 2, 3, ..., N from front to back. Each person wears a hat, which is red, blue, or green.

The person numbered i says:

"In front of me, exactly A_i people are wearing hats with the same color as mine."

Assuming that all these statements are correct, find the number of possible combinations of colors of the N people's hats.

Since the count can be enormous, compute it modulo 1000000007.

Constraints

1 \leq N \leq 100000

0 \leq A_i \leq N-1

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_N

Output

Print the number of possible combinations of colors of the N people's hats, modulo 1000000007.

Sample Input 1

6
0 1 2 3 4 5

Sample Output 1

3

We have three possible combinations, as follows:

Red, Red, Red, Red, Red, Red

Blue, Blue, Blue, Blue, Blue, Blue

Green, Green, Green, Green, Green, Green

Sample Input 2

3
0 0 0

Sample Output 2

6

Sample Input 3

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

Sample Output 3

115295190


Score: 600 points

Problem Statement

Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east.

They start simultaneously at the same point and moves as follows towards the east:

Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever.

Aoki runs B_1 meters per minute for the first T_1 minutes, then runs at B_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever.

How many times will Takahashi and Aoki meet each other, that is, come to the same point? We do not count the start of the run. If they meet infinitely many times, report that fact.

Constraints

1 \leq T_i \leq 100000

1 \leq A_i \leq 10^{10}

1 \leq B_i \leq 10^{10}

A_1 \neq B_1

A_2 \neq B_2

All values in input are integers.

Input

Input is given from Standard Input in the following format:

T_1 T_2
A_1 A_2
B_1 B_2

Output

Print the number of times Takahashi and Aoki will meet each other.

If they meet infinitely many times, print infinity instead.

Sample Input 1

1 2
10 10
12 4

Sample Output 1

1

They will meet just once, \frac{4}{3} minutes after they start, at \frac{40}{3} meters from where they start.

Sample Input 2

100 1
101 101
102 1

Sample Output 2

infinity

They will meet 101, 202, 303, 404, 505, 606, ... minutes after they start, that is, they will meet infinitely many times.

Sample Input 3

12000 15700
3390000000 3810000000
5550000000 2130000000

Sample Output 3

113

The values in input may not fit into a 32-bit integer type.


<?php
fscanf(STDIN, '%d', $n);
for ($i  = 0; $i < $n - 1; $i++) {
    fscanf(STDIN, '%d %d', $a, $b);
    $a--;
    $b--;
    $g[$a][] = $b;
    $g[$b][] = $a; // 無向グラフの場合
    $a_arr[] = $a;
    $b_arr[] = $b;
}
$color = array_fill(0, $n, array_fill(0, $n, null));

dfs($g, $a_arr[0], $seen, $color);
$arr = [];
$max = -1;
foreach ($color as $i => $a) {
    foreach ($a as $j => $v) {
        if (is_null($v)) continue;
        if ($i < $j) $arr[] = $v;
        $max = max($v, $max);
    }
}
echo $max . PHP_EOL;
foreach ($arr as $v) {
    echo $v . PHP_EOL;
}

function dfs($g, $v = 0, &$seen, &$color)
{
    $seen[$v] = true;

    if (is_null($g[$v])) return;

    // まず彩色済みの辺の色を調べる
    $colors = [];
    foreach ($g[$v] as $next_v) {
        if ($seen[$next_v]) $colors[] = $color[$v][$next_v];
    }

    // 未彩色の辺に彩色
    $i = 1;
    foreach ($g[$v] as $next_v) {
        if (!$seen[$next_v]) {
            while (in_array($i, $colors)) {
                $i++;
            }
            $color[$v][$next_v] = $color[$next_v][$v] = $i;
            $i++;
        }
    }

    // 未調査の頂点に移動
    foreach ($g[$v] as $next_v) {
        if ($seen[$next_v]) continue;
        dfs($g, $next_v, $seen, $color);
    }
}

Score : 400 points

Problem Statement

Given is a tree G with N vertices.
The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i.

Consider painting the edges in G with some number of colors.
We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.

Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.

Constraints

2 \le N \le 10^5

1 \le a_i \lt b_i \le N

All values in input are integers.

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}

Output

Print N lines.

The first line should contain K, the number of colors used.

The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer representing the color of the i-th edge, where 1 \le c_i \le K must hold.

If there are multiple colorings with the minimum number of colors that satisfy the condition, printing any of them will be accepted.

Sample Input 1

3
1 2
2 3

Sample Output 1

2
1
2

Sample Input 2

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

Sample Output 2

4
1
2
3
4
1
1
2

Sample Input 3

6
1 2
1 3
1 4
1 5
1 6

Sample Output 3

5
1
2
3
4
5


Score: 500 points

Problem Statement

N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.

The preliminary stage consists of several rounds, which will take place as follows:

All the N contestants will participate in the first round.

When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:

The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.

For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).

When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.

The preliminary stage ends when 9 or fewer contestants remain.

Ringo, the chief organizer, wants to hold as many rounds as possible.
Find the maximum possible number of rounds in the preliminary stage.

Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.

Constraints

1 \leq M \leq 200000

0 \leq d_i \leq 9

d_1 \neq 0

d_i \neq d_{i+1}

c_i \geq 1

2 \leq c_1 + \ldots + c_M \leq 10^{15}

Input

Input is given from Standard Input in the following format:

M
d_1 c_1
d_2 c_2
:
d_M c_M

Output

Print the maximum possible number of rounds in the preliminary stage.

Sample Input 1

2
2 2
9 1

Sample Output 1

3

In this case, N = 229 contestants will participate in the first round. One possible progression of the preliminary stage is as follows:

229 contestants participate in Round 1, 49 contestants participate in Round 2, 13 contestants participate in Round 3, and 4 contestants advance to the finals.

Here, three rounds take place in the preliminary stage, which is the maximum possible number.

Sample Input 2

3
1 1
0 8
7 1

Sample Output 2

9

In this case, 1000000007 will participate in the first round.


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

Score : 100 points

Problem Statement

Given is an integer r.

How many times is the area of a circle of radius r larger than the area of a circle of radius 1?

It can be proved that the answer is always an integer under the constraints given.

Constraints

1 \leq r \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

r

Output

Print the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.

Sample Input 1

2

Sample Output 1

4

The area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.

Note that output must be an integer - for example, 4.0 will not be accepted.

Sample Input 2

100

Sample Output 2

10000


<?php

$a = fgets(STDIN);
echo $a*$a;
?>

<?php

$a = fgets(STDIN);
echo $a*$a;
?>


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


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

echo $a * $a;


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

echo($n*$n);


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

  $len = strlen($s);
  if($len%2 == 1){
    echo "No";
    exit;
  }

  if(substr($s, 0, $len/2) == substr($s, $len/2, $len/2)){
    echo "Yes";
    exit;
  }else{
    echo "No";
    exit;
  }

Score : 200 points

Problem Statement

Given are a positive integer N and a string S of length N consisting of lowercase English letters.

Determine whether the string is a concatenation of two copies of some string.
That is, determine whether there is a string T such that S = T + T.

Constraints

1 \leq N \leq 100

S consists of lowercase English letters.

|S| = N

Input

Input is given from Standard Input in the following format:

N
S

Output

If S is a concatenation of two copies of some string, print Yes; otherwise, print No.

Sample Input 1

6
abcabc

Sample Output 1

Yes

Let T = abc, and S = T + T.

Sample Input 2

6
abcadc

Sample Output 2

No

Sample Input 3

1
z

Sample Output 3

No


<?php

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

if($n==1 && $n%2!=0){
  echo "No\n";
  exit;
}
for($i=0;$i<(int)$n/2;$i++){
  $front .= $s[$i];
}

for($i=(int)$n/2;$i<$n;$i++){
  $back .= $s[$i];
}

if($front==$back){
  echo "Yes\n";
}else{
    echo "No\n";

}


<?php
fscanf(STDIN, '%d', $length);
fscanf(STDIN, '%s', $string);

echo solve($length, $string);
echo "\n";

function solve($len, $str) {
    if ($len % 2 !== 0) {
        return "No";
    }

    $chars = str_split($str);
    $counts = array_count_values($chars);

    foreach ($counts as $cnt) {
        if ($cnt !== 2) {
            return "No";
        }
    }

    return "Yes";
}


<?php
$N = intval(trim(fgets(STDIN)));
$S = intval(trim(fgets(STDIN)));
$T= substr($S, $N/2);
$S2 = $T . $T;
if($S == $S2 && $N%2 === 0){
    echo 'Yes';
} else {
    echo 'No';
}


<?php

$N = trim(fgets(STDIN));
$S = trim(fgets(STDIN));

if ($N % 2 !== 0) {
    exit("No");
}

$arr = str_split($S, $N / 2);
if ($arr[0] === $arr[1]) {
    echo "Yes";
}else {
    echo "No";
}


<?php
list($n, $m) = ints();
for($i = 2; $i <= $n; $i++){
  $map[$i][$i-1] = 0;
}
for($i = 0; $i < $m; $i++){
  list($from, $to, $d) = ints();
  $map[$from][$to] = $d;
}
$D = [];
$pq = new SplPriorityQueue();
for($i = 1; $i <= $n; $i++){
  $D[$i] = $i == 1 ? 0 : 10**18;
  $prev[$i] = 0;
  $pq->insert($i, -$D[$i]);
}
while($pq->count()){
  $node = $pq->extract();
  foreach($map[$node] as $to => $length){
    $alt = $D[$node] + $length;
    if($D[$to] > $alt){
      $D[$to] = $alt;
      $prev[$to] = $node['data'];
      $pq->insert($to, -$alt);
    }
  }
}
printf("%d", $D[$n] == 10**18 ? -1 : $D[$n]);

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 : 600 points

Problem Statement

We have N points numbered 1 to N arranged in a line in this order.

Takahashi decides to make an undirected graph, using these points as the vertices.
In the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph.
The i-th operation is as follows:

The operation uses integers L_i and R_i between 1 and N (inclusive), and a positive integer C_i. For every pair of integers (s, t) such that L_i \leq s < t \leq R_i, add an edge of length C_i between Vertex s and Vertex t.

The integers L_1, ..., L_M, R_1, ..., R_M, C_1, ..., C_M are all given as input.

Takahashi wants to solve the shortest path problem in the final graph obtained. Find the length of the shortest path from Vertex 1 to Vertex N in the final graph.

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq L_i < R_i \leq N

1 \leq C_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1 C_1
:
L_M R_M C_M

Output

Print the length of the shortest path from Vertex 1 to Vertex N in the final graph.
If there is no shortest path, print -1 instead.

Sample Input 1

4 3
1 3 2
2 4 3
1 4 6

Sample Output 1

5

We have an edge of length 2 between Vertex 1 and Vertex 2, and an edge of length 3 between Vertex 2 and Vertex 4, so there is a path of length 5 between Vertex 1 and Vertex 4.

Sample Input 2

4 2
1 2 1
3 4 2

Sample Output 2

-1

Sample Input 3

10 7
1 5 18
3 4 8
1 3 5
4 7 10
5 9 8
6 10 5
8 10 3

Sample Output 3

28


<?php
//これは嘘
$s=trim(fgets(STDIN)).">";
$n=strlen($s);
$key=array_keys(str_split($s),"<");
if($key != null){
  $ans=array_fill(0,$n,0);
  $m=count($key);
  $c=0;
  $i=0;
  $key=array_flip($key);
  while($i<$n){
    if(isset($key[$i])){
      if(isset($key[$i-1])){
        $ans[$i]=$ans[$i-1]+1;
      }
      ++$i;
    }else{
      $c=$i;
      while($i<$n && !isset($key[$i])){
        ++$i;
      }
      $ans[$c]=max($ans[$c-1]+1,$i-$c);
      ++$c;
      while($c<$i){
        $ans[$c]=$i-$c;
        ++$c;
      }
    }
  }
  echo array_sum($ans);
}else{
  echo (int)($n-1)*$n/2;
}

Score : 300 points

Problem Statement

Given is a string S of length N-1.
Each character in S is < or >.

A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \leq i \leq N-1):

If S_i= <: a_i<a_{i+1}

If S_i= >: a_i>a_{i+1}

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Constraints

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

S is a string of length N-1 consisting of < and >.

Input

Input is given from Standard Input in the following format:

S

Output

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Sample Input 1

<>>

Sample Output 1

3

a=(0,2,1,0) is a good sequence whose sum is 3.
There is no good sequence whose sum is less than 3.

Sample Input 2

<>>><<><<<<<>>><

Sample Output 2

28


Score : 200 points

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.

Given an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cannot, print No.

Constraints

1 \leq N \leq 100

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes; if it cannot, print No.

Sample Input 1

10

Sample Output 1

Yes

10 can be represented as, for example, 2 \times 5.

Sample Input 2

50

Sample Output 2

No

50 cannot be represented as the product of two integers between 1 and 9.

Sample Input 3

81

Sample Output 3

Yes


Score : 300 points

Problem Statement

Takahashi is standing on a multiplication table with infinitely many rows and columns.

The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1).

In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).

Given an integer N, find the minimum number of moves needed to reach a square that contains N.

Constraints

2 \leq N \leq 10^{12}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum number of moves needed to reach a square that contains the integer N.

Sample Input 1

10

Sample Output 1

5

(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.

Sample Input 2

50

Sample Output 2

13

(5, 10) can be reached in 13 moves.

Sample Input 3

10000000019

Sample Output 3

10000000018

Both input and output may be enormous.


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

  // 半分以下
  if ($x * 2 <= $b * $a * $a){
    echo rad2deg(atan($b / ((2*$x) / ($b*$a))));
  }
  // 半分より多い
  else{
    $p = (($a * $b) - ($x / $a)) * (2 / $a);
    $tan = $p / $a;
    echo sprintf("%f", rad2deg(atan($tan) )) . PHP_EOL;
  }

Score : 400 points

Problem Statement

Takahashi has a water bottle with the shape of a rectangular prism whose base is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm}. (The thickness of the bottle can be ignored.)

We will pour x~\mathrm{cm}^3 of water into the bottle, and gradually tilt the bottle around one of the sides of the base.

When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.

Constraints

All values in input are integers.

1 \leq a \leq 100

1 \leq b \leq 100

1 \leq x \leq a^2b

Input

Input is given from Standard Input in the following format:

a b x

Output

Print the maximum angle in which we can tilt the bottle without spilling any water, in degrees.
Your output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6}.

Sample Input 1

2 2 4

Sample Output 1

45.0000000000

This bottle has a cubic shape, and it is half-full. The water gets spilled when we tilt the bottle more than 45 degrees.

Sample Input 2

12 21 10

Sample Output 2

89.7834636934

This bottle is almost empty. When the water gets spilled, the bottle is nearly horizontal.

Sample Input 3

3 1 8

Sample Output 3

4.2363947991

This bottle is almost full. When the water gets spilled, the bottle is still nearly vertical.


Score : 100 points

Problem Statement

The window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)

We will close the window so as to minimize the total horizontal length of the uncovered part of the window.
Find the total horizontal length of the uncovered parts of the window then.

Constraints

1 \leq A \leq 100

1 \leq B \leq 100

A and B are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the total horizontal length of the uncovered parts of the window.

Sample Input 1

12 4

Sample Output 1

4

We have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.

Sample Input 2

20 15

Sample Output 2

0

If the window is completely covered, print 0.

Sample Input 3

20 30

Sample Output 3

0

Each curtain may be longer than the window.


<?php
fscanf(STDIN, "%d %d", $a, $b);
echo max(0, $a - $b * 2);


<?php

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

$sum = array_sum($arr);
$x = $sum * $sum;

$y = 0;
foreach ($arr as $d) {
    $y += $d * $d;
}

echo ($x - $y) / 2;

Score : 200 points

Problem Statement

It's now the season of TAKOYAKI FESTIVAL!

This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i.

As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points.

There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values.

Constraints

All values in input are integers.

2 \leq N \leq 50

0 \leq d_i \leq 100

Input

Input is given from Standard Input in the following format:

N
d_1 d_2 ... d_N

Output

Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served.

Sample Input 1

3
3 1 2

Sample Output 1

11

There are three possible choices:

Eat the first and second takoyaki. You will restore 3 health points.

Eat the second and third takoyaki. You will restore 2 health points.

Eat the first and third takoyaki. You will restore 6 health points.

The sum of these values is 11.

Sample Input 2

7
5 0 7 8 3 3 2

Sample Output 2

312


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

$total = 0;
for ($i=0; $i<$n; $i++) {
  for ($j=$i+1; $j<$n; $j++) {
    $total += $exploded_numbers[$i] * $exploded_numbers[$j];
  }
}

echo $total;


<?php
fscanf(STDIN, "%d", $N);
$array = explode(" ",trim(fgets(STDIN)));
$sum = 0;
for($i=0; $i<$N; $i++){
    for($s=$i+1; $s<$N; $s++){
        $sum = $sum + ($array[$i] * $array[$s]);
    }
}
echo $sum;
?>


<?php

 $N = trim(fgets(STDIN));
 $S = trim(fgets(STDIN));

$array = str_split($S);

for ($i = 0; $i < $N-1; $i++) {
    for ($j = $i + 1; $j < $N; $j++) {
        if ($array[$i] !== $array[$j]) {
            break;
        } else {
            unset($array[$i]);
            $i++;
        }
    }
}
echo count($array);

Score : 300 points

Problem Statement

There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.

Adjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.

Ultimately, how many slimes will be there?

Constraints

1 \leq N \leq 10^5

|S| = N

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the final number of slimes.

Sample Input 1

10
aabbbbaaca

Sample Output 1

5

Ultimately, these slimes will fuse into abaca.

Sample Input 2

5
aaaaa

Sample Output 2

1

All the slimes will fuse into one.

Sample Input 3

20
xxzaffeeeeddfkkkkllq

Sample Output 3

10


<?php

	$str1 = fgets(STDIN);
	$str = fgets(STDIN);
	$array = str_split($str);

	$cnt = 0;
	$previous = '';

	foreach ($array as $char) {
		if ($char === $previous) {
			continue;
		} else {
			$cnt++;
		}
		$previous = $char;
	}

	echo $cnt . "\n";


<?php

	$str1 = fgets(STDIN);
	$str = fgets(STDIN);
	$array = str_split($str);

	$cnt = 0;
	$previous = '';

	foreach ($array as $char) {
		if ($char === $previous) {
			continue;
		} else {
			$cnt++;
		}
		$previous = $char;
	}

	echo $cnt;


<?php

//文字列の入力
fscanf(STDIN,"%d",$n);
fscanf(STDIN,"%s",$s);

$mojis = str_split($s);
$a = "";
$count = 0;

foreach ($mojis as $moji){
    if ($a !== $moji)
        $count++;
        $count = $moji;

}

echo $count;


<?php

$N = trim(fgets(STDIN));
$D = trim(fgets(STDIN));
$D = str_split($D);

$ans = 1;
$x = $D[0];
for ($i=1; $i < count($D); $i++) {
    if ($D[$i] == $x) {
        continue;
    }
    $ans++;
    $x = $D[$i];
}
echo $ans;


<?php
    $sankaku = fgets(STDIN);
    $create = fgets(STDIN);
    $c_array = explode(' ', $create);
    asort($c_array);

    $cnt = 0;
    for($i=0; $i<$sankaku-2; $i++){
        $a = (int)$c_array[$i];
        for($j=$i+1; $j<$sankaku; $j++){
            $b = (int)$c_array[$j];
            for($n=$j+1; $n<$sankaku; $n++){
                $c = (int)$c_array[$n];
                if($a < $b + $c &&
                   $b < $a + $c &&
                   $c < $a + $b
                )
                $cnt = $cnt + 1;
            }
        }
    }
    echo $cnt;
?>

Score : 400 points

Problem Statement

Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.

He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:

a < b + c

b < c + a

c < a + b

How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.

Constraints

All values in input are integers.

3 \leq N \leq 2 \times 10^3

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

Only one triangle can be formed: the triangle formed by the first, second, and third sticks.

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23


<?php

//整数の入力
fscanf(STDIN,"%s", $n);

//N以下の奇数の数を数える
for($i = 1; $i <= $n; $i++) {
    if($i%2 !==0){
        $b[] = $i;
    }
}

$count = count($b);
$total = $count / $n;

echo sprintf("%s",$total);

Score : 100 points

Problem Statement

Given is an integer N.

Takahashi chooses an integer a from the positive integers not greater than N with equal probability.

Find the probability that a is odd.

Constraints

1 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the probability that a is odd.
Your output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-6}.

Sample Input 1

4

Sample Output 1

0.5000000000

There are four positive integers not greater than 4: 1, 2, 3, and 4. Among them, we have two odd numbers: 1 and 3. Thus, the answer is \frac{2}{4} = 0.5.

Sample Input 2

5

Sample Output 2

0.6000000000

Sample Input 3

1

Sample Output 3

1.0000000000


<?php
// Your code here!
$input = explode(" ",trim(fgets(STDIN)));

list($N,$H) = $input;

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

foreach($array_H as $val){
    if($val >= $H)$count[] = $val;
}

echo count($count).PHP_EOL;

?>


<?php
  fscanf(STDIN, "%d %d",$num $req);
  $arr = explode(" ",trim(fgets(STDIN)));

  $cnt = 0;
  foreach($arr as $cm){
    if($req <= $cm){
      $cnt++;
    }
  }

  echo $cnt;

Score : 200 points

Problem Statement

N friends of Takahashi has come to a theme park.

To ride the most popular roller coaster in the park, you must be at least K centimeters tall.

The i-th friend is h_i centimeters tall.

How many of the Takahashi's friends can ride the roller coaster?

Constraints

1 \le N \le 10^5

1 \le K \le 500

1 \le h_i \le 500

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
h_1 h_2 \ldots h_N

Output

Print the number of people among the Takahashi's friends who can ride the roller coaster.

Sample Input 1

4 150
150 140 100 200

Sample Output 1

2

Two of them can ride the roller coaster: the first and fourth friends.

Sample Input 2

1 500
499

Sample Output 2

0

Sample Input 3

5 1
100 200 300 400 500

Sample Output 3

5


<?php
  $a1 = explode(' ', trim(fgets(STDIN)));
  $h = explode(' ', trim(fgets(STDIN)));
  $n = $a1[0];
  $k = $a1[1];
  $ans = 0;
  foreach ($h as $num) {
    if ($num >= $k) {
      $ans++;
    }
  }
echo $ans . PHP_EOL;


<?php

function fget_array($dlmt = null) {
    $input = trim(fgets(STDIN));
    return $dlmt ? explode($dlmt, $input) : str_split($input);
}

list($n, $k) = fget_array(' ');
$h = fget_array(' ');
$cnt = 0;
for ($i = 0; $i < $n; $i++) {
    if ($h[$i] >= $k) $cnt++;
}
echo $cnt;
?>


<?php

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

$array = explode(" ", trim(fgets(STDIN)));
$ans = 0;
foreach($array as $value){
    if($h <= $value){
        $ans++;
    }
}

echo $ans;


<?php
fscanf(STDIN, "%d", $n);
$a = explode(" ",fgets(STDIN));
asort($a);
$sortA = array_keys($a);
function plusOne($n) {
    return($n + 1);
}
$sortA = array_map('plusOne', $sortA);
$sortAseparated = implode(" ", $sortA);
echo $sortAseparated . "\n";

Score : 300 points

Problem Statement

Takahashi is a teacher responsible for a class of N students.

The students are given distinct student numbers from 1 to N.

Today, all the students entered the classroom at different times.

According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).

From these records, reconstruct the order in which the students entered the classroom.

Constraints

1 \le N \le 10^5

1 \le A_i \le N

A_i \neq A_j (i \neq j)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

Print the student numbers of the students in the order the students entered the classroom.

Sample Input 1

3
2 3 1

Sample Output 1

3 1 2

First, student number 3 entered the classroom.

Then, student number 1 entered the classroom.

Finally, student number 2 entered the classroom.

Sample Input 2

5
1 2 3 4 5

Sample Output 2

1 2 3 4 5

Sample Input 3

8
8 2 7 3 4 5 6 1

Sample Output 3

8 2 4 5 6 7 3 1


<?php
$num=trim(fgets(STDIN));
$number=trim(fgets(STDIN));
$number=explode(" ",$number);
asort($number);
$arrs=array_keys($number);
$answer="";
foreach($arrs as $arr){
  	$arr=intval($arr);
	$answer.=strval($arr+1)." ";
}
echo $answer;


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

$a = (int)$input[0];
$b = (int)$input[1];

// 最大公約数
$gcd = gcd($a, $b);

// 1
$cnt = 1;
if ($gcd === 1) {
	echo $cnt;
	exit();
}
// 2以上
$tmp = $gcd;
$max = (int)ceil(sqrt($gcd));
for ($i=2; $i <= $max; $i++) {
	$flg = false;
	while ($tmp % $i === 0) {
		$tmp = (int)floor($tmp/$i);
		$flg = true;
	}
	if ($flg) {
		$cnt += 1;
	}
}
// if ($cnt === 1 ) {
// 	$cnt += 1;
// }
echo $cnt;

function gcd($m,$n){
	if ($m === $n) {
		return $m;
	}
	$large = max($m,$n);
	$small = min($m,$n);
	$q = $large % $small;
	if ($q === 0) {
		return $small;
	}else{
		return gcd($small, $q);
	}
}
// 素数判定
// function sieve($n){
// 	$list = range(2, $n);
// 	$result = [1];
// 	for ($i=1; $i < $n; $i++) {
// 		// echo implode(' ', $list) , PHP_EOL;
// 		$tmp_list = [];
// 		$target = array_shift($list);
// 		if (empty($target)) {
// 			break;
// 		}
// 		$result[] = $target;
// 		foreach ($list as $v) {
// 			if ($v % $target !== 0) {
// 				$tmp_list[] = $v;
// 			}
// 		}
// 		$list = $tmp_list;
// 	}
// 	return $result;
// }

Score : 400 points

Problem Statement

Given are positive integers A and B.

Let us choose some number of positive common divisors of A and B.

Here, any two of the chosen divisors must be coprime.

At most, how many divisors can we choose?

Definition of common divisor

An integer d is said to be a common divisor of integers x and y when d divides both x and y.

Definition of being coprime

Integers x and y are said to be coprime when x and y have no positive common divisors other than 1.

Definition of dividing

An integer x is said to divide another integer y when there exists an integer \alpha such that y = \alpha x.

Constraints

All values in input are integers.

1 \leq A, B \leq 10^{12}

Input

Input is given from Standard Input in the following format:

A B

Output

Print the maximum number of divisors that can be chosen to satisfy the condition.

Sample Input 1

12 18

Sample Output 1

3

12 and 18 have the following positive common divisors: 1, 2, 3, and 6.

1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can choose 1, 2, and 3, which achieve the maximum result.

Sample Input 2

420 660

Sample Output 2

4

Sample Input 3

1 2019

Sample Output 3

1

1 and 2019 have no positive common divisors other than 1.


<?php
list($H, $W, $A, $B) = ints();
for($i = 0; $i < $H; $i++){
  for($j = 0; $j < $W; $j++){
    echo (($j < $A) + ($i < $B)) % 2;
  }
  echo "\n";
}

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

We have a square grid with H rows and W columns.
Snuke wants to write 0 or 1 in each of the squares.
Here, all of the following conditions have to be satisfied:

For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)

For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.

Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.

Constraints

1 \leq H,W \leq 1000

0 \leq A

2 \times A \leq W

0 \leq B

2 \times B \leq H

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H W A B

Output

If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.

If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:

s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}

Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.

If multiple solutions exist, printing any of them will be accepted.

Sample Input 1

3 3 1 1

Sample Output 1

100
010
001

Every row contains two 0s and one 1, so the first condition is satisfied.
Also, every column contains two 0s and one 1, so the second condition is satisfied.

Sample Input 2

1 5 2 0

Sample Output 2

01010


<?php
$str = trim(fgets(STDIN));
  $arr = ["Sunny","Cloudy","Rainy"];
  if($str==$arr[0]) {
    echo $arr[1];
  }
  elseif($str==$arr[1]) {
  	echo $arr[2];
  }
  else {
   echo $arr[0];
  }

Score: 100 points

Problem Statement

The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...

Given is a string S representing the weather in the town today. Predict the weather tomorrow.

Constraints

S is Sunny, Cloudy, or Rainy.

Input

Input is given from Standard Input in the following format:

S

Output

Print a string representing the expected weather tomorrow, in the same format in which input is given.

Sample Input 1

Sunny

Sample Output 1

Cloudy

In Takahashi's town, a sunny day is followed by a cloudy day.

Sample Input 2

Rainy

Sample Output 2

Sunny


<?php
$Weather = array("Sunny", "Cloudy", "Rainy");
$ans = fgets(STDIN);
function num($x){
    if($x == 2){
        return 0;
    }else{
        return $x++;
    }
}
$a = array_search($ans, $Weather);
echo $Weather[num($a)];
?>


<?php
    fscanf(STDIN, "%s", $s);
    $result = '';
    if($s === 'Sunny'){
        $result = 'Cloudy';
    }else if($s === 'Cloudy'){
        $result =  'Rainy';
    }else if($s === 'Rainy'){
        $result = 'Sunny';
    }
    echo $result;
  ?>


<?php
    fscanf(STDIN, "%s", $s);
    switch($s){
        case 'Sunny':
        echo 'Cloudy';
        break;
        case 'Cloudy';
        echo 'Rainy';
        break;
        case 'Rainy';
        echo 'Sunny';
        break;
    }
  ?>


<?php
fscanf(STDIN, "%s", $s);
switch ($s) {
    case 'Sunny':
        $s = 'Cloudy';
        break;
    case 'Cloudy':
        $s = 'Rainy';
        break;
    case 'Rainy':
        $s = 'Sunny';
        break;
}
echo $s;


<?php
	$a = fgets(STDIN);
	if($a == 'Sunny'){
      echo('Cloudy');
    }elseif($a == 'Cloudy'){
      echo('Rainy');
    }elseif($a == 'Rainy'){
      echo('Sunny');
    }


<?php
# 数値の入力
fscanf(STDIN, "%s", $data1);
$anser = 'Sunny';
if($data1=='Sunny'){
    $anser = 'Cloudy';
}elseif($data1=='Cloudy'){
    $anser = 'Rainy';
}else{
}

echo $anser;
?>