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

$sc = new Scanner();
$n = $sc->nextInt();
$f = substr($n,-1,1);
switch($f) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        $result = 'hon';
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        $result = 'pon';
        break;
    case 3:
        $result = 'bon';
        break;
}
out::println($result);

Score: 100 points

Problem Statement

The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.

When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of "本" in the phrase "N 本" for a positive integer N not exceeding 999 is as follows:

hon when the digit in the one's place of N is 2, 4, 5, 7, or 9;

pon when the digit in the one's place of N is 0, 1, 6 or 8;

bon when the digit in the one's place of N is 3.

Given N, print the pronunciation of "本" in the phrase "N 本".

Constraints

N is a positive integer not exceeding 999.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

16

Sample Output 1

pon

The digit in the one's place of 16 is 6, so the "本" in "16 本" is pronounced pon.

Sample Input 2

2

Sample Output 2

hon

Sample Input 3

183

Sample Output 3

bon


<?php

$maxLength = trim(fgets(STDIN));
$input = trim(fgets(STDIN));
$inputLength = strlen($input);

if ($maxLength <= $inputLength) {
    $input = substr($input, 0, $maxLength)."...";
}
echo $input;

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

Score: 200 points

Problem Statement

We have a string S consisting of lowercase English letters.

If the length of S is at most K, print S without change.

If the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result.

Constraints

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

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:

K
S

Output

Print a string as stated in Problem Statement.

Sample Input 1

7
nikoandsolstice

Sample Output 1

nikoand...

nikoandsolstice has a length of 15, which exceeds K=7.

We should extract the first 7 characters in this string, append ... to the end of them, and print the result nikoand....

Sample Input 2

40
ferelibenterhominesidquodvoluntcredunt

Sample Output 2

ferelibenterhominesidquodvoluntcredunt

The famous quote from Gaius Julius Caesar.

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", $num);
$sentence = rtrim(fgets(STDIN));
$numOfSentense = mb_strlen($sentense);

if ($numOfSentense >= $num) {
    print (substr($sentence, 0, $num)) . '...';
} else {
    print($sentense);
}


<?php
  fscanf(STDIN, "%d", $k);
  fscanf(STDIN, "%s", $s);
$num=strlen($s);
if($num<=$k){
echo $s;
}else{
$arr = str_split($s,$k);
  echo $arr[0]."...";
}
?>


 <?php
    list($A,$B,$H,$M) = array_map('intval',explode(" ",(trim(fgets(STDIN)))));

    //H時M分の時の針の角度を求めたいので0時0分を共に0度として計算する。
    $angle_a = 360/12 * $H;
    $angle_b = 360/60 * $M;

    $diff =  abs($angle_b-$angle_a);

    if($diff>180){
        $diff = 360 - $diff;
    }

    $C = sqrt($A**2 + $B**2 - 2*$A*$B*cos(deg2rad($diff)));

    echo $C."\n";

?>

Score: 300 points

Problem Statement

Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively.

An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.

At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?

Constraints

All values in input are integers.

1 \leq A, B \leq 1000

0 \leq H \leq 11

0 \leq M \leq 59

Input

Input is given from Standard Input in the following format:

A B H M

Output

Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.

Sample Input 1

3 4 9 0

Sample Output 1

5.00000000000000000000

The two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.

Sample Input 2

3 4 10 40

Sample Output 2

4.56425719433005567605

The two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.


<?php

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

fscanf(STDIN, "%d %d", $N, $M);
$adj_rooms = [];
for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%d %d", $A_i, $B_i);
    $adj_rooms[$A_i][] = $B_i;
    $adj_rooms[$B_i][] = $A_i;
}

$dist_t[1] = 0;
$way_t = [];

searchChild(1);

if (count($dist_t) < $N) {
    echo "No\n";
    exit;
}

echo "Yes\n";
for ($i = 2; $i <= $N; $i++) {
    echo $way_t[$i], "\n";
}

function searchChild (int $target_room) {
    global $dist_t, $way_t, $adj_rooms;
    foreach ($adj_rooms[$target_room] as $adj_room) {
        if (! isset($dist_t[$adj_room]) or $dist_t[$adj_room] > $dist_t[$target_room] + 1) {
            $dist_t[$adj_room] = $dist_t[$target_room] + 1;
            $way_t[$adj_room] = $target_room;
            searchChild($adj_room);
        }
    }
}

Score: 400 points

Problem Statement

There is a cave.

The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.

It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.

Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.

If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.

Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

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

1 \leq A_i, B_i \leq N\ (1 \leq i \leq M)

A_i \neq B_i\ (1 \leq i \leq M)

One can travel between any two rooms by traversing passages.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
:
A_M B_M

Output

If there is no way to place signposts satisfying the objective, print No.

Otherwise, print N lines. The first line should contain Yes, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i.

Sample Input 1

4 4
1 2
2 3
3 4
4 2

Sample Output 1

Yes
1
2
2

If we place the signposts as described in the sample output, the following happens:

Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \to 1. This is the minimum number of passages possible.

Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \to 2 \to 1. This is the minimum number of passages possible.

Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \to 2 \to 1. This is the minimum number of passages possible.

Thus, the objective is satisfied.

Sample Input 2

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

Sample Output 2

Yes
6
5
5
1
1

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


<?php

const MOD = 1000000007;
bcscale(36);

fscanf(STDIN, "%d", $N);
$p_count = 0;
$n_count = 0;
$ans = 1;
$ans_list = [];
$ans_list[0] = 0;
$p_list =[];
$n_list= [];
$zero_count = 0;
$a_zero = 0;
$b_zero = 0;
for($i=1;$i<=$N;$i++){
    $ans *= 2;
    $ans %= MOD;
    if($ans > 1){
        $ans_list[$i] = $ans-1;
    }else{
        $ans_list[$i] = $ans + MOD - 1;
    }

    fscanf(STDIN, "%d%d", $a, $b);
    $map[$i] = [$a, $b];
    if($a == 0 && $b == 0){
        $zero_count++;
    }elseif($a == 0){

        $p_list[0][] = $i;
        $p_count++;

    }elseif($b == 0){

        $n_list[0][] = $i;
        $n_count++;
    }else {

        if (($a > 0 && $b > 0) || $a < 0 && $b < 0) {
            $div = md5(bcdiv($b, $a));

            $p_list[$div][] = $i;
            $p_count++;
        } else{
            $n_list[md5(bcdiv(abs($a), abs($b)))][] = $i;
            $n_count++;
        }
    }
}
$diff = $N;
$ans = 1;
    foreach($p_list as $key => $value){
        if(isset($n_list[$key])){
            $p = count($p_list[$key]);
            $n = count($n_list[$key]);
            $ans = $ans * (($ans_list[$p] + $ans_list[$n] + 1) %MOD) % MOD;
            $diff -= ($p + $n);
        }
    }

    $diff-=$zero_count;

echo ($ans * (($ans_list[$diff]+1) %MOD)  -1 + $zero_count) %MOD;

Score: 500 points

Problem Statement

We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.

We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.

The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0.

In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.

Constraints

All values in input are integers.

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

-10^{18} \leq A_i, B_i \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

Print the count modulo 1000000007.

Sample Input 1

3
1 2
-1 1
2 -1

Sample Output 1

5

There are five ways to choose the set of sardines, as follows:

The 1-st

The 1-st and 2-nd

The 2-nd

The 2-nd and 3-rd

The 3-rd

Sample Input 2

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

Sample Output 2

479


<?php

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

  if (strpos($t, $s) !== false) {
    // code...
    if (strlen($t) == strlen($s)+ 1) {
      // code...
      if(substr($t,0,-1) == $a){
      echo "Yes";
      return;
      }
    }
  }
 echo 'No';

Score : 100 points

Problem Statement

Takahashi wants to be a member of some web service.

He tried to register himself with the ID S, which turned out to be already used by another user.

Thus, he decides to register using a string obtained by appending one character at the end of S as his ID.

He is now trying to register with the ID T. Determine whether this string satisfies the property above.

Constraints

S and T are strings consisting of lowercase English letters.

1 \leq |S| \leq 10

|T| = |S| + 1

Input

Input is given from Standard Input in the following format:

S
T

Output

If T satisfies the property in Problem Statement, print Yes; otherwise, print No.

Sample Input 1

chokudai
chokudaiz

Sample Output 1

Yes

chokudaiz can be obtained by appending z at the end of chokudai.

Sample Input 2

snuke
snekee

Sample Output 2

No

snekee cannot be obtained by appending one character at the end of snuke.

Sample Input 3

a
aa

Sample Output 3

Yes


<?php
$name = rtrim(fgets(STDIN));
$namePlus = rtrim(fgets(STDIN));

if (strlen($name) + 1 == strlen($namePlus)) {
    echo 'Yes';
} else {
    echo 'No';
}


A,B,C,K=map(int, input().split())
sum=0
if A>=K:
  sum=A
  print(sum)
  exit()
r=K-A
sum=A
if B>=r:
  print(sum)
  exit()
r=r-B
print(sum+r*(-1))

Score : 200 points

Problem Statement

We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.

We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

Constraints

All values in input are integers.

0 \leq A, B, C

1 \leq K \leq A + B + C \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

A B C K

Output

Print the maximum possible sum of the numbers written on the cards chosen.

Sample Input 1

2 1 1 3

Sample Output 1

2

Consider picking up two cards with 1s and one card with a 0.
In this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000


<?php
fscanf(STDIN, "%d %d %d %d", $a, $b, $c, $k);
if ($k <= $a) {
    echo $k.PHP_EOL;
} elseif ($k <= $a + $b) {
    echo $a.PHP_EOL;
} else {
    echo $a - ($k - $a - $c).PHP_EOL;
}


<?php

$line = explode(' ', fgets(STDIN));

$A = (int)$line[0];
$B = (int)$line[1];
$C = (int)$line[2];
$K = (int)$line[3];

if(full_up_with_ab($A, $B, $K)){
  echo $A;
}else {
  if(full_up_with_abc($A, $B, $C, $K)){
    $C = $K - ($A + $B);
  }
  echo $A - $C;
}

function full_up_with_ab($A, $B, $K){
  return ($A + $B) >= $K;
}

function full_up_with_abc($A, $B, $C, $K){
  return ($A + $B + $C) >= $K;
}


<?php
fscanf(STDIN,"%d %d %d %d",$a,$b,$c,$K);
/*
$a(+1)が0になるまで$aを引き、
$aが0になったらなったら$b(+0)が0になるまで引き、
$bが0になったら$c(-1)を0になるまで引く
*/
$n = 0; //出力値を初期化

// $K-$aが0以下だったら$nは1*$a
// $K-$aが1以上、かつ$K-$bが0以下だったら$nは1*$a (+ 0*$b) ※0*$bは0なので無視
// $K-$aが1以上、かつ$K-$bが1以上だったら$nは1*$a + (-1)*$c (+ 0*$b)

if($K-($a+$b) < 1){
    $n = $a;
}else{
    $n = $a + (-1 * ($K-($a+$b)));
}
echo $n;
?>


Score : 300 points

Problem

Takahashi, who is a novice in competitive programming, wants to learn M algorithms.
Initially, his understanding level of each of the M algorithms is 0.

Takahashi is visiting a bookstore, where he finds N books on algorithms.
The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M).
There is no other way to increase the understanding levels of the algorithms.

Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Constraints

All values in input are integers.

1\leq N, M\leq 12

1\leq X\leq 10^5

1\leq C_i \leq 10^5

0\leq A_{i, j} \leq 10^5

Input

Input is given from Standard Input in the following format:

N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M}

Output

If the objective is not achievable, print -1; otherwise, print the minimum amount of money needed to achieve it.

Sample Input 1

3 3 10
60 2 2 4
70 8 7 9
50 2 3 9

Sample Output 1

120

Buying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.

Sample Input 2

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

Sample Output 2

-1

Buying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.

Sample Input 3

8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2

Sample Output 3

1067


<?php
$N = (int)fgets(STDIN);
$S = [];
$prefix = false;
$suffix = false;
$num_of_L = 0;
$num_of_R = 0;

for ($i = 0; $i < $N; $i++) {
    $s = trim(fgets(STDIN));
    $old_s = '';
    while ($s !== $old_s) {
        $old_s = $s;
        $s = str_replace('()', '', $s);
    }
    $num_of_L += mb_substr_count($s, '(');
    $num_of_R += mb_substr_count($s, ')');

    echo 'Yes';
    return;
    if ($s[0] === '(') {
        $prefix = true;
    }
    if ($s[strlen($s)-1] === ')') {
        $suffix = true;
    }
}

if (($num_of_L === 0 && $num_of_R === 0) || ($prefix && $suffix && $num_of_L === $num_of_R)) {
    echo 'Yes';
    return;
}
echo 'No';

Score : 600 points

Problem Statement

A bracket sequence is a string that is one of the following:

An empty string;

The concatenation of (, A, and ) in this order, for some bracket sequence A ;

The concatenation of A and B in this order, for some non-empty bracket sequences A and B /

Given are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?

Constraints

1 \leq N \leq 10^6

The total length of the strings S_i is at most 10^6.

S_i is a non-empty string consisting of ( and ).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

If a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.

Sample Input 1

2
)
(()

Sample Output 1

Yes

Concatenating (() and ) in this order forms a bracket sequence.

Sample Input 2

2
)(
()

Sample Output 2

No

Sample Input 3

4
((()))
((((((
))))))
()()()

Sample Output 3

Yes

Sample Input 4

3
(((
)
)

Sample Output 4

No


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

if ($S === 'ABC') {
    echo 'ARC';
} else {
    echo 'ABC';
}
echo PHP_EOL;

Score : 100 points

Problem Statement

AtCoder Inc. holds a contest every Saturday.

There are two types of contests called ABC and ARC, and just one of them is held at a time.

The company holds these two types of contests alternately: an ARC follows an ABC and vice versa.

Given a string S representing the type of the contest held last week, print the string representing the type of the contest held this week.

Constraints

S is ABC or ARC.

Input

Input is given from Standard Input in the following format:

S

Output

Print the string representing the type of the contest held this week.

Sample Input 1

ABC

Sample Output 1

ARC

They held an ABC last week, so they will hold an ARC this week.


<?php
 $s = trim(fgets(STDIN));
echo $s == "ABC" ? "ARC" : "ABC";

  ?>


<?php

	$in = trim(fgets(STDIN));

	if($in == "ABC") {
      echo "ARC";
    } else {
      echo "ABC";
    }

?>


<?php

  $last = trim(fgets(STDIN));
echo $last === 'ABC' ? 'ARC' : 'ABC';


<?php
	fscanf(STDIN, "%s", $str);
	if ($str == "ABC") {
      	echo "ARC\n";
    } else {
        echo "ABC\n";
    }


<?php

  $s = trim(fgets(STDIN));

  if ($s == "ABC") {
    // code...
    echo 'ARC';
  }else {
    // code...
    echo 'ABC';
  }


<?php
$s = trim(fgets(STDIN));
echo ($s == 'ABC') ? 'ARC' : 'ABC';


<?php

    $in = explode(" ", trim(fgets(STDIN)));
    $num_spots = $in[0];
    $num_routes = $in[1];
    $spots = explode(" ", trim(fgets(STDIN)));
    array_unshift($spots, 0);
    // print_r($spots);

    $i = 1;
    while($i < $num_routes+1) {
        $routes[$i] = explode(" ", trim(fgets(STDIN)));
        ++$i;
    }

    $i = 1;
    while($i < $num_spots+1) {
        $max[$i] = $spots[$i];

        $j = 1;
        while($j < $num_routes+1) {
            if($routes[$j][0] == $i) {
                $max[$i] = max($max[$i], $spots[$routes[$j][1]]);
            } elseif($routes[$j][1] == $i) {
                $max[$i] = max($max[$i], $spots[$routes[$j][0]]);
            }
            ++$j;
        }
        ++$i;
    }

    // print_r($max);

    $count = 0;
    $i = 1;
    while($i < $num_spots) {
        if($max[$i] <= $spots[$i]) {
            ++$count;
        }
        ++$i;
    }

    echo $count;
?>

Score : 300 points

Problem Statement

There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.
There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.

Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.
Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.

How many good observatories are there?

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq H_i \leq 10^9

1 \leq A_i,B_i \leq N

A_i \neq B_i

Multiple roads may connect the same pair of observatories.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M

Output

Print the number of good observatories.

Sample Input 1

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

Sample Output 1

2

From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.

From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.

From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.

From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.

Thus, the good observatories are Obs. 3 and 4, so there are two good observatories.

Sample Input 2

6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6

Sample Output 2

3


Score : 400 points

Problem Statement

Give a pair of integers (A, B) such that A^5-B^5 = X.
It is guaranteed that there exists such a pair for the given integer X.

Constraints

1 \leq X \leq 10^9

X is an integer.

There exists a pair of integers (A, B) satisfying the condition in Problem Statement.

Input

Input is given from Standard Input in the following format:

X

Output

Print A and B, with space in between.
If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them.

A B

Sample Input 1

33

Sample Output 1

2 -1

For A=2 and B=-1, A^5-B^5 = 33.

Sample Input 2

1

Sample Output 2

0 -1


<?php
  $x = trim(fgets(STDIN));
  echo pow($x-1,(1/5))." -1\n";


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

while (true) {

    $a = floor(nthRoot($n, 5));

    $tmp = $n - pow($a,5);
    $b = nthRoot($tmp, 5);

    if ($b == floor($b)){
        break;
    }

    $a = $a - 1;
}

if (!$b == 0) {
    $b = $b * (-1);
}

echo  $a . " " . $b;

function nthRoot($x,$n){
    return pow($x, 1 / $n);
}

?>


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

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

$cnt = 0;
for ($i=0; $i < $n; $i++) {
    for ($j=($i + 1); $j < $n; $j++) {
        if (($j - $i) == $arr[$i] + $arr[$j]){
            $cnt = $cnt + 1;
        }
    }
}

echo $cnt;
return;

?>

Score: 500 points

Problem Statement

You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.

There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i.

According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction.

The absolute difference of their attendee numbers is equal to the sum of their heights.

There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above?

P.S.: We cannot let you know the secret.

Constraints

All values in input are integers.

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

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

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the number of pairs satisfying the condition.

Sample Input 1

6
2 3 3 1 3 1

Sample Output 1

3

A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.

A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.

A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.

No other pair satisfies the condition, so you should print 3.

Sample Input 2

6
5 2 4 2 8 8

Sample Output 2

0

No pair satisfies the condition, so you should print 0.

Sample Input 3

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

Sample Output 3

22


Score : 600 points

Problem Statement

There is a game that involves three variables, denoted A, B, and C.

As the game progresses, there will be N events where you are asked to make a choice.
Each of these choices is represented by a string s_i. If s_i is AB, you must add 1 to A or B then subtract 1 from the other; if s_i is AC, you must add 1 to A or C then subtract 1 from the other; if s_i is BC, you must add 1 to B or C then subtract 1 from the other.

After each choice, none of A, B, and C should be negative.

Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.

Constraints

1 \leq N \leq 10^5

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

N, A, B, C are integers.

s_i is AB, AC, or BC.

Input

Input is given from Standard Input in the following format:

N A B C
s_1
s_2
:
s_N

Output

If it is possible to make N choices under the condition, print Yes; otherwise, print No.

Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (A, B, or C) to which you add 1 in the i-th choice.

Sample Input 1

2 1 3 0
AB
AC

Sample Output 1

Yes
A
C

You can successfully make two choices, as follows:

In the first choice, add 1 to A and subtract 1 from B. A becomes 2, and B becomes 2.

In the second choice, add 1 to C and subtract 1 from A. C becomes 1, and A becomes 1.

Sample Input 2

3 1 0 0
AB
BC
AB

Sample Output 2

No

Sample Input 3

1 0 9 0
AC

Sample Output 3

No

Sample Input 4

8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB

Sample Output 4

Yes
C
B
B
C
C
B
A
A


<?php
[$N, $A, $B, $C] = ints();
for($i = 0; $i < $N; $i++){
    $S[] = str();
}
$ans = "";
for($i = 0; $i < $N-1; $i++){
    $s = $S[$i];
    $next = $S[$i+1];
    if(${$s[0]} > 0){
        ${$s[0]}--;
        ${$s[1]}++;
        $ok = isOK($next);
        if($ok)$ans .= $s[1]."\n";
        else{
        ${$s[0]}++;
        ${$s[1]}--;
        }
        if($ok)continue;
    }
    if(${$s[1]} > 0){
        ${$s[1]}--;
        ${$s[0]}++;
        $ok = isOK($next);
        if($ok)$ans .= $s[0]."\n";
        else{
        ${$s[1]}++;
        ${$s[0]}--;
        }
        if($ok)continue;
    }
    echo "No";
    exit;
}
$last = $S[$N-1];
if(${$last[0]}>0){
    echo "Yes","\n";
    echo $ans;
    echo $last[1];
}elseif(${$last[1]}>0){
    echo "Yes","\n";
    echo $ans;
    echo $last[0];
}else{
    echo "No";
}

function isOK($next){
    global $A, $B, $C;
    if(${$next[0]} || ${$next[1]})return true;
    return false;
}

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

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

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


<?php
$target = trim(fgets(STDIN));
list($min, $max) = explode(' ', trim(fgets(STDIN)));

$result = '';
for($i=$min; $i<=$max; $i++){
    if($i % $target == 0){
        $result = 'OK';
        break;
    }
}

if($result == 'OK'){
    echo $result;
} else {
    echo 'NG';
}

Score: 100 points

Problem Statement

Takahashi the Jumbo will practice golf.

His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).

If he can achieve the objective, print OK; if he cannot, print NG.

Constraints

All values in input are integers.

1 \leq A \leq B \leq 1000

1 \leq K \leq 1000

Input

Input is given from Standard Input in the following format:

K
A B

Output

If he can achieve the objective, print OK; if he cannot, print NG.

Sample Input 1

7
500 600

Sample Output 1

OK

Among the multiples of 7, for example, 567 lies between 500 and 600.

Sample Input 2

4
5 7

Sample Output 2

NG

No multiple of 4 lies between 5 and 7.

Sample Input 3

1
11 11

Sample Output 3

OK


<?php

// 標準入力を一行ずつ配列に代入します
while ($line = fgets(STDIN)) {
   $tmp[] = trim($line);
}

// 配列の各要素をさらに分解します
foreach ($tmp as $key => $value) {
  $array[] = explode(" ", $value);
}

$target_value_array = $array[1];
for ($i = $target_value_array[0]; $i <= $target_value_array[1]; $i++) {
    if($i+1 == $array[1][1]){
        echo "NG";
        break;
    }

    if ($i % $array[0][0] == 0){
        echo "OK";
        break;
    }

}

?>


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

$deposit = 100;
$year = 0;

while ($deposit < $x) {
    $deposit += floor($deposit / 100);
    $year++;
}

echo $year . "\n";

?>

Score : 200 points

Problem Statement

Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.

The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)

Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?

Constraints

101 \le X \le 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

Print the number of years it takes for Takahashi's balance to reach X yen or above for the first time.

Sample Input 1

103

Sample Output 1

3

The balance after one year is 101 yen.

The balance after two years is 102 yen.

The balance after three years is 103 yen.

Thus, it takes three years for the balance to reach 103 yen or above.

Sample Input 2

1000000000000000000

Sample Output 2

3760

Sample Input 3

1333333333

Sample Output 3

1706


<?php
fscanf(STDIN, "%d", $x);
$money = 100;
$year = 0;
while($money < $x){
  $money = $money * 1.01;
  $year++;
}
 echo $year;
?>


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

$yen = 100;
$year = 0;
while (true) {
    if ($yen >= $n){
        echo $year;
        return;
    }

    $yen = floor($yen * 1.01);
    $year++;
}

?>


<?php
// C
fscanf(STDIN, '%d %d %d', $n, $m, $q);
for ($i  = 0; $i < $q; $i++) fscanf(STDIN, '%d %d %d %d', $a[], $b[], $c[], $d[]);
func();
echo max($scores);

function func($a = [])
{
    global $n, $m, $scores;

    if (count($a) === $n) {
        $scores[] = calcScore($a);
        return;
    }

    $s = count($a) > 0 ? $a[count($a) - 1] : 1;
    for ($i = $s; $i <= $m; $i++) {
        func(array_merge($a, [$i]));
    }
}

function calcScore($arr)
{
    global $q, $a, $b, $c, $d;
    $sum = 0;
    for ($i = 0; $i < $q; $i++) {
        $sum += $arr[$b[$i] - 1] - $arr[$a[$i] - 1] === $c[$i] ? $d[$i] : 0;
    }
    return $sum;
}

Score : 300 points

Problem Statement

Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).

Consider a sequence A satisfying the following conditions:

A is a sequence of N positive integers.

1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.

Let us define a score of this sequence as follows:

The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)

Find the maximum possible score of A.

Constraints

All values in input are integers.

2 ≤ N ≤ 10

1 \leq M \leq 10

1 \leq Q \leq 50

1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )

0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )

(a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)

1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )

Input

Input is given from Standard Input in the following format:

N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q

Output

Print the maximum possible score of A.

Sample Input 1

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

Sample Output 1

110

When A = \{1, 3, 4\}, its score is 110. Under these conditions, no sequence has a score greater than 110, so the answer is 110.

Sample Input 2

4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328

Sample Output 2

357500

Sample Input 3

10 10 1
1 10 9 1

Sample Output 3

1


Score : 100 points

Problem Statement

There are S sheep and W wolves.

If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.

If the wolves will attack the sheep, print unsafe; otherwise, print safe.

Constraints

1 \leq S \leq 100

1 \leq W \leq 100

Input

Input is given from Standard Input in the following format:

S W

Output

If the wolves will attack the sheep, print unsafe; otherwise, print safe.

Sample Input 1

4 5

Sample Output 1

unsafe

There are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.

Sample Input 2

100 2

Sample Output 2

safe

Many a sheep drive away two wolves.

Sample Input 3

10 10

Sample Output 3

unsafe


<?php
list($S, $W) = explode(' ', fgets(STDIN));
if ($W >= $S) {
    echo 'unsafe';
} else {
    echo 'safe';
}


<?php
list($S,$W)=sscanf(trim(fgets(STDIN)),"%d %d");
if($S <= $W){
    printf("unsafe");
}else{
    printf("safe");
}


<?php

fgets(STDIN);

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

echo count($arr);

Score : 300 points

Problem Statement

You drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.

How many kinds of items did you get?

Constraints

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

S_i consists of lowercase English letters and has a length between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print the number of kinds of items you got.

Sample Input 1

3
apple
orange
apple

Sample Output 1

2

You got two kinds of items: apple and orange.

Sample Input 2

5
grape
grape
grape
grape
grape

Sample Output 2

1

Sample Input 3

4
aaaa
a
aaa
aa

Sample Output 3

4


<?php
//error_reporting(0);
//$N = (int)trim(fgets(STDIN));
//$R = trim(fgets(STDIN));
list($N,$M) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$sum = array_sum($A);
printf("%d\n",max(-1,$N-$sum));

Score : 200 points

Problem Statement

Takahashi has N days of summer vacation.

His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.

He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.

What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?

If Takahashi cannot finish all the assignments during the vacation, print -1 instead.

Constraints

1 \leq N \leq 10^6

1 \leq M \leq 10^4

1 \leq A_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_M

Output

Print the maximum number of days Takahashi can hang out during the vacation, or -1.

Sample Input 1

41 2
5 6

Sample Output 1

30

For example, he can do the first assignment on the first 5 days, hang out on the next 30 days, and do the second assignment on the last 6 days of the vacation. In this way, he can safely spend 30 days hanging out.

Sample Input 2

10 2
5 6

Sample Output 2

-1

He cannot finish his assignments.

Sample Input 3

11 2
5 6

Sample Output 3

0

He can finish his assignments, but he will have no time to hang out.

Sample Input 4

314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3

Sample Output 4

9


<?php
$count_employee = trim(fgets(STDIN));
$staffs = explode(" ", trim(fgets(STDIN)));
foreach($staffs as $staff){
	$boss_count[$staff]++;
}
for($i=1; $i<=$count_employee; $i++){
  if($boss_count[$i]){
    fputs(STDOUT, $boss_count[$i]."\n");
  }else{
    fputs(STDOUT, "0\n");
  }
}
?>

Score : 300 points

Problem Statement

A company has N members, who are assigned ID numbers 1, ..., N.

Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.

When a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.

You are given the information that the immediate boss of the member numbered i is the member numbered A_i. For each member, find how many immediate subordinates it has.

Constraints

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

1 \leq A_i < i

Input

Input is given from Standard Input in the following format:

N
A_2 ... A_N

Output

For each of the members numbered 1, 2, ..., N, print the number of immediate subordinates it has, in its own line.

Sample Input 1

5
1 1 2 2

Sample Output 1

2
2
0
0
0

The member numbered 1 has two immediate subordinates: the members numbered 2 and 3.

The member numbered 2 has two immediate subordinates: the members numbered 4 and 5.

The members numbered 3, 4, and 5 do not have immediate subordinates.

Sample Input 2

10
1 1 1 1 1 1 1 1 1

Sample Output 2

9
0
0
0
0
0
0
0
0
0

Sample Input 3

7
1 2 3 4 5 6

Sample Output 3

1
1
1
1
1
1
0


<?php

$stdin1 = trim(fgets(STDIN));
$stdin2 = trim(fgets(STDIN));

$input1 = explode(" ", $stdin1);
$N = $input1[0];

$A = explode(" ", $stdin2);
$res = [];

for ($i = 1; $i <= $N; $i++) {
    $currentEmployee = $i;
    $res[$currentEmployee] = 0;
    for ($j = 0; $j < count($A); $j++) {
        if ($currentEmployee == $A[$j]) {
            $res[$currentEmployee]++;
        }
    }
}
foreach ($res as $employeeNumber => $subordinateNumber) {
    echo $subordinateNumber . "\n";
}


<?php
  fscanf(STDIN,"%d",$n);
  $a = explode(" ",trim(fgets(STDIN)));
  $ans = array();
  for($i=0; $i<count($a); $i++){
    $ans[$a[$i]] += 1;
  }

  for($i=1; $i<=$n; $i++){
    if(array_key_exists($i,$ans)){
      echo $ans[$i]."\n";
    }else{
      echo "0\n";
    }
  }


<?php
$N = (int)trim(fgets(STDIN));
$A = explode(' ', fgets(STDIN));
$A = array_map(function ($a) {
    return (int)$a;
}, $A);
$ans = 0;
$prefix = 0;
$suffix = 0;

while ($prefix + $suffix < $N) {
    $max = 0;
    $to_front = false;
    $max_i = 0;
    for ($i = 0; $i < $N; $i++) {
        if ($i < ($N - $suffix) / 2) {
            $new_happy = $A[$i] * ($N - $i - 1 - $suffix);
            if ($new_happy > $max || ($new_happy === $max && $A[$i] > $A[$max_i])) {
                $max = $new_happy;
                $to_front = false;
                $max_i = $i;
            }
        } else {
            $new_happy = $A[$i] * ($i - $prefix);
            if ($new_happy > $max || ($new_happy === $max && $A[$i] > $A[$max_i])) {
                $max = $new_happy;
                $to_front = true;
                $max_i = $i;
            }
        }
    }
    if ($to_front) {
        $prefix += 1;
    } else {
        $suffix += 1;
    }
    $A[$max_i] = 0;
    $ans += $max;
    $max = 0;
}

echo $ans;

Score : 500 points

Problem Statement

There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i.

You can rearrange these children just one time in any order you like.

When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points.

Find the maximum total happiness points the children can earn.

Constraints

2 \leq N \leq 2000

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum total happiness points the children can earn.

Sample Input 1

4
1 3 4 2

Sample Output 1

20

If we move the 1-st child from the left to the 3-rd position from the left, the 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and the 4-th child to the 2-nd position, the children earns 1 \times |1-3|+3 \times |2-4|+4 \times |3-1|+2 \times |4-2|=20 happiness points in total.

Sample Input 2

6
5 5 6 1 1 1

Sample Output 2

58

Sample Input 3

6
8 6 9 1 2 1

Sample Output 3

85


<?php
$input_line = trim(fgets(STDIN));
$input_line = (int)$input_line;
$sum = 0;
for ($i = 1; $i < $input_line; $i++) {
  if ($i % 3 != 0 && $i % 5 != 0){
    $sum += $i;
  }
}
echo $sum;
?>

Score : 200 points

Problem Statement

Let us define the FizzBuzz sequence a_1,a_2,... as follows:

If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}.

If the above does not hold but 3 divides i, a_i=\mbox{Fizz}.

If none of the above holds but 5 divides i, a_i=\mbox{Buzz}.

If none of the above holds, a_i=i.

Find the sum of all numbers among the first N terms of the FizzBuzz sequence.

Constraints

1 \leq N \leq 10^6

Input

Input is given from Standard Input in the following format:

N

Output

Print the sum of all numbers among the first N terms of the FizzBuzz sequence.

Sample Input 1

15

Sample Output 1

60

The first 15 terms of the FizzBuzz sequence are:

1,2,\mbox{Fizz},4,\mbox{Buzz},\mbox{Fizz},7,8,\mbox{Fizz},\mbox{Buzz},11,\mbox{Fizz},13,14,\mbox{FizzBuzz}

Among them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.

Sample Input 2

1000000

Sample Output 2

266666333332

Watch out for overflow.


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

    // 最初にひけるだけひく

    if ((int)$n > (int)$k) {

    //echo floor($n / $k) . PHP_EOL;
    //echo (int)$n . PHP_EOL;
    //echo (int)$k . PHP_EOL;
    //echo (int)(floor($n / $k)) * ((int)$k);
        $n = (int)$n - ((int)(floor($n / $k)) * (int)$k);
    }
    //echo $n . PHP_EOL;

    while (true) {
        # code...
        //echo 'n1 = ' . $n . PHP_EOL;
        //echo 'k1 = ' . $k . PHP_EOL;

        $a = abs((int)$n - (int)$k);

        //echo 'a = ' . $a . PHP_EOL;

        if ((int)$n > (int)$a){
            $n = $a;
        } else {
            break;
        }

        //echo 'n = ' . $n . PHP_EOL;
    }
    echo $n;
?>

Score : 300 points

Problem Statement

Given any integer x, Aoki can do the operation below.

Operation: Replace x with the absolute difference of x and K.

You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Constraints

0 ≤ N ≤ 10^{18}

1 ≤ K ≤ 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the minimum possible value taken by N after Aoki does the operation zero or more times.

Sample Input 1

7 4

Sample Output 1

1

Initially, N=7.

After one operation, N becomes |7-4| = 3.

After two operations, N becomes |3-4| = 1, which is the minimum value taken by N.

Sample Input 2

2 6

Sample Output 2

2

N=2 after zero operations is the minimum.

Sample Input 3

1000000000000000000 1

Sample Output 3

0


<?php
fscanf(STDIN, "%d %d", $N, $K);
$result=$N-$K;
do{
    $result = $result-$K;
}while($result > 0);

echo($result);
?>


Score : 400 points

Problem Statement

A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:

In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.

For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.

You are given a positive integer K. Find the K-th smallest lunlun number.

Constraints

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer.

Sample Input 1

15

Sample Output 1

23

We will list the 15 smallest lunlun numbers in ascending order:

1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
21,
22,
23.

Thus, the answer is 23.

Sample Input 2

1

Sample Output 2

1

Sample Input 3

13

Sample Output 3

21

Sample Input 4

100000

Sample Output 4

3234566667

Note that the answer may not fit into the 32-bit signed integer type.


<?php

    // AtCoder Beginner Contest 161
    // D - Lunlun Number

    $k = in_int();

    $idx = 0;
    $i = 1;
    while (true) {
        if (is_lunlun($i)) {
            $idx++;
            if ($idx == $k) {
                out($i);
                break;
            }
        }
        $i++;
    }

    function is_lunlun($s) {
        $arr = str_split($s);
        $len = count($arr);
        for ($i = 0; $i < $len; $i++) {
            if ($i != 0) {
                if (abs($arr[$i - 1] - $arr[$i]) > 1) {
                    return false;
                }
            }
            if ($i != $len - 1) {
                if (abs($arr[$i] - $arr[$i + 1]) > 1) {
                    return false;
                }
            }
        }
        return true;
    }

    /**
    * お手伝い関数さんたち
    */
    function in() {
        return trim(fgets(STDIN));
    }
    function in_int() {
        return (int)in();
    }
    function in_vals() {
        return explode(' ', in());
    }
    function in_ints() {
        return array_map('intval', in_vals());
    }
    function out($s) {
        echo $s . PHP_EOL;
    }
    function yes() {
        out('Yes');
    }
    function no() {
        out('No');
    }


<?php

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

$array = str_split($str);

if($array[2] && $array[3] && $array[4] === $array[5]){
	echo 'Yes';
}else{
	echo 'No';
}

?>

Score : 100 points

Problem Statement

A string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal.

Given a string S, determine whether it is coffee-like.

Constraints

S is a string of length 6 consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If S is coffee-like, print Yes; otherwise, print No.

Sample Input 1

sippuu

Sample Output 1

Yes

In sippuu, the 3-rd and 4-th characters are equal, and the 5-th and 6-th characters are also equal.

Sample Input 2

iphone

Sample Output 2

No

Sample Input 3

coffee

Sample Output 3

Yes


<?php
  $str_arr = str_split(fgets(STDIN));

  if($str_arr[2] == $str_arr[3] && $str_arr[4] == $str_arr[5])
    print("Yes\n");
  else
    print("No\n");

?>


Score : 200 points

Problem Statement

Takahashi loves gold coins. He gains 1000 happiness points for each 500-yen coin he has and gains 5 happiness points for each 5-yen coin he has. (Yen is the currency of Japan.)

Takahashi has X yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?

(We assume that there are six kinds of coins available: 500-yen, 100-yen, 50-yen, 10-yen, 5-yen, and 1-yen coins.)

Constraints

0 \leq X \leq 10^9

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the maximum number of happiness points that can be earned.

Sample Input 1

1024

Sample Output 1

2020

By exchanging his money so that he gets two 500-yen coins and four 5-yen coins, he gains 2020 happiness points, which is the maximum number of happiness points that can be earned.

Sample Input 2

0

Sample Output 2

0

He is penniless - or yenless.

Sample Input 3

1000000000

Sample Output 3

2000000000

He is a billionaire - in yen.


<?php

// test
// echo 'please enter: ';
// $a = 0;
// fscanf(STDIN,"%s %s", $a, $b);
// var_dump($a, $b);

// 読み込み
// echo 'please enter: ';
// K, Nを読み取る
fscanf(STDIN, "%d %d", $K, $N);
// Aiを読み取る
$string = fgets(STDIN);
// 文字列を数値に変換する関数
function stringToInt($string) {
  $int = (int)$string;
  return $int;
}
// Ai配列を作成する
$result[] = array_map(stringToInt, explode(" ", $string));
$A = $result[0];
array_push($A, $K+$A[0]);

// いざ求める
$distanceBetweenTwoHouses = 0;
for($i=0;$i<$N;$i++){
  $tempDistance = $A[$i+1] - $A[$i];
  if ($tempDistance > $distanceBetweenTwoHouses) {
    $distanceBetweenTwoHouses = $tempDistance;
  }
}

// echo $distanceBetweenTwoHouses;

echo $K - $distanceBetweenTwoHouses;
?>

Score : 300 points

Problem Statement

There is a circular pond with a perimeter of K meters, and N houses around them.

The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.

When traveling between these houses, you can only go around the pond.

Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Constraints

2 \leq K \leq 10^6

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

0 \leq A_1 < ... < A_N < K

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K N
A_1 A_2 ... A_N

Output

Print the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Sample Input 1

20 3
5 10 15

Sample Output 1

10

If you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.

Sample Input 2

20 3
0 5 15

Sample Output 2

10

If you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.


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

$sum = 0;
$max = 0;

for($i = 1; $i < count($a_a); $i++){
	$tmp = $a_a[$i] - $a_a[$i - 1];
	if($tmp > $max){
		$max = $tmp;
	}
	$sum += $tmp;
}

$tmp = $a_a[0] + $k - $a_a[count($a_a) - 1];
if($tmp > $max){
	$max = $tmp;
}
$sum += $tmp;

echo $sum - $max;
?>


<?php
fscanf(STDIN, "%d %d", $k, $n);
$as=explode(' ',trim(fgets(STDIN)));
$max = 0;
foreach ($as as $i => $a) {
  $dis = $i == 0 ? $a + $k - $as[$n-1] : $a - $as[$i-1];
  $max = max($max, $dis);
}
echo $k - $max;


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

    if($str != strrev($str)){
        echo "No";
        return ;
    }

    $len = strlen($str);

    $str1 = $str;
    $len1 = (($len - 1) / 2);
    $str1 = substr($str1, 0,$len1+1);
    if($str1 != strrev($str1)){
        echo "No";
        return;
    }

    $str2 = $str;
    $len2 = (($len + 3) / 2);
    $str2 = substr($str2, $len2 - 1,$len+1);

    if($str2 != strrev($str2)){
        echo "No";
      	return;
    }
	echo "Yes";

Score : 100 points

Problem Statement

We have N+M balls, each of which has an integer written on it.

It is known that:

The numbers written on N of the balls are even.

The numbers written on M of the balls are odd.

Find the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even.

It can be shown that this count does not depend on the actual values written on the balls.

Constraints

0 \leq N,M \leq 100

2 \leq N+M

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the answer.

Sample Input 1

2 1

Sample Output 1

1

For example, let us assume that the numbers written on the three balls are 1,2,4.

If we choose the two balls with 1 and 2, the sum is odd;

If we choose the two balls with 1 and 4, the sum is odd;

If we choose the two balls with 2 and 4, the sum is even.

Thus, the answer is 1.

Sample Input 2

4 3

Sample Output 2

9

Sample Input 3

1 1

Sample Output 3

0

Sample Input 4

13 3

Sample Output 4

81

Sample Input 5

0 3

Sample Output 5

3


<?php
list($n,$m)=explode(" ",trim(fgets(STDIN)));
echo $n*($n-1)/2+$m*($m-1)/2;


<?php
define("MOD", 100);
$n = intval(trim(fgets(STDIN)));
$s = trim(fgets(STDIN));
$n = strlen($s);
$kigu = 0;
for($i = 0; $i < $n; $i++){
    $dp[$i] = ((int)$s[$i])-1;
    $kigu ^= ($dp[$i]%2) * ((($n-1) & $i) == $i);
}
if($kigu == 1){
    echo 1;
}else{
    if(array_search(1, $dp)){
        echo 0;
    }else{
        echo 2;
    }
}

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;
}
/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}
//配列の最大公約数
function gcdAll($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

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

//配列の最小公倍数
function lcmAll($array){
    $lcm = $array[0];
    for($i = 1; $i < count($array); $i++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}

function prepareMod($n){
    global $f, $invf;
    $f[0] = $invf[0] = $invf[1] = 1;
    for($i = 1; $i <= $n; $i++)$f[$i] = $f[$i-1]*$i%MOD;
    for($i = 2; $i <= $n; $i++)$invf[$i] = (MOD - intdiv(MOD, $i))*$invf[MOD%$i]%MOD;
    for($i = 2; $i <= $n; $i++)$invf[$i] = $invf[$i]*$invf[$i-1]%MOD;
}
function nCm($n, $m){
    global $f, $invf;
    if($n < 0 || $n - $m < 0)return 0;
    return $f[$n] * $invf[$n-$m] % MOD * $invf[$m] % MOD;
}

Score : 700 points

Problem Statement

Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3.
Let x_{i,j} defined as follows:

x_{1,j} := a_j \quad (1 \leq j \leq N)

x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i)

Find x_{N,1}.

Constraints

2 \leq N \leq 10^6

a_i = 1,2,3 (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
a_1a_2\ldotsa_N

Output

Print x_{N,1}.

Sample Input 1

4
1231

Sample Output 1

1

x_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.

x_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.

x_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.

Finally, x_{4,1} = |0-1| = 1, so the answer is 1.

Sample Input 2

10
2311312312

Sample Output 2

0


Score : 100 points

Problem Statement

Print the K-th element of the following sequence of length 32:

1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51

Constraints

1 \leq K \leq 32

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the K-th element.

Sample Input 1

6

Sample Output 1

2

The 6-th element is 2.

Sample Input 2

27

Sample Output 2

5

The 27-th element is 5.


<?php

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

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

if ($a === 1 && $b === 1) {
  echo 1;
  exit;
}

echo (int)ceil(($a * $b) / 2);

?>

Score : 200 points

Problem Statement

We have a board with H horizontal rows and W vertical columns of squares.
There is a bishop at the top-left square on this board.
How many squares can this bishop reach by zero or more movements?

Here the bishop can only move diagonally.
More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds:

r_1 + c_1 = r_2 + c_2

r_1 - c_1 = r_2 - c_2

For example, in the following figure, the bishop can move to any of the red squares in one move:

Constraints

1 \leq H, W \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H \ W

Output

Print the number of squares the bishop can reach.

Sample Input 1

4 5

Sample Output 1

10

The bishop can reach the cyan squares in the following figure:

Sample Input 2

7 3

Sample Output 2

11

The bishop can reach the cyan squares in the following figure:

Sample Input 3

1000000000 1000000000

Sample Output 3

500000000000000000


<?php
list($H,$W)=sscanf(trim(fgets(STDIN)),"%d %d");
if($H == 1){
    echo 1;
    exit;
}
if($W == 1){
    echo 1;
    exit;
}

$p1 = ceil($W / 2);
$p2 = floor($W / 2); //きりすて
$calc = 0;
$calc = $p1 * ceil($H/2);
$calc += $p2 * floor($H/2);
echo (int)$calc;


<?php
list($h,$w)=explode(" ",trim(fgets(STDIN)));
echo (int)ceil($h*$w/2);


<?php
fscanf(STDIN, '%s', $pat);
echo ($pat === 'AAA' || $pat === 'BBB') ? 'No' : 'Yes';
echo "\n";

Score : 100 points

Problem Statement

In AtCoder City, there are three stations numbered 1, 2, and 3.

Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A, Company A operates Station i; if S_i is B, Company B operates Station i.

To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them.

Determine if there is a pair of stations that will be connected by a bus service.

Constraints

Each character of S is A or B.

|S| = 3

Input

Input is given from Standard Input in the following format:

S

Output

If there is a pair of stations that will be connected by a bus service, print Yes; otherwise, print No.

Sample Input 1

ABA

Sample Output 1

Yes

Company A operates Station 1 and 3, while Company B operates Station 2.

There will be a bus service between Station 1 and 2, and between Station 2 and 3, so print Yes.

Sample Input 2

BBA

Sample Output 2

Yes

Company B operates Station 1 and 2, while Company A operates Station 3.

There will be a bus service between Station 1 and 3, and between Station 2 and 3, so print Yes.

Sample Input 3

BBB

Sample Output 3

No

Company B operates all the stations. Thus, there will be no bus service, so print No.


<?php
  $input = -fgets(STDIN);

  if(
    strpos($input, "A") !== false &&
    strpos($input, "B") !== false
  ) {
    print("Yes\n");
    return;
  }
  print("No\n");
?>


<?php
$s = str();
echo $s[0] != $s[1] || $s[1] != $s[2] ? "Yes" : "No";
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;
}
/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}
//配列の最大公約数
function gcdAll($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

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

//配列の最小公倍数
function lcmAll($array){
    $lcm = $array[0];
    for($i = 1; $i < count($array); $i++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


Score : 200 points

Problem Statement

Takahashi has many red balls and blue balls. Now, he will place them in a row.

Initially, there is no ball placed.

Takahashi, who is very patient, will do the following operation 10^{100} times:

Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.

How many blue balls will be there among the first N balls in the row of balls made this way?

Constraints

1 \leq N \leq 10^{18}

A, B \geq 0

0 < A + B \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of blue balls that will be there among the first N balls in the row of balls.

Sample Input 1

8 3 4

Sample Output 1

4

Let b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.

Sample Input 2

8 0 4

Sample Output 2

0

He placed only red balls from the beginning.

Sample Input 3

6 2 4

Sample Output 3

2

Among bbrrrr, there are two blue balls.


<?php

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

    $count_loop = (int)($n/($a+$b));
    $left_count = $n%($a+$b);

    if($left_count>=$a){
        echo $count_loop*$a+$a."\n";
    }else{
        echo $count_loop*$a+$left_count."\n";
    }


<?php
fscanf(STDIN, '%d %d %d', $cnt, $blue, $red);
$sum = $blue + $red;
$loop = intdiv($cnt, $sum);
$ans = $blue * $loop;
$rest = $cnt - ($loop * $sum);
$ans += min($blue, $rest);
echo $ans;
echo "\n";


<?php
    $input = explode(" ", fgets(STDIN));
    $all = intval($input[0]);
    $blue = intval($input[1]);
    $red = intval($input[2]);

    if ($blue == 0) {
        echo 0;
    } else {
        echo $all - $red;
    }
?>


<?php

    // 末尾に改行をつけて出力
    function output($str) {
        echo $str . PHP_EOL;
    }

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

    $blue = (int)(floor($n / ($a + $b)) * $a);
    $wk = $n % ($a + $b);
    if ($wk > $a) {
        $blue += $a;
    } else {
        $blue += $wk;
    }
    output($blue);


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

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

$sc = new Scanner();
$N = $sc->nextInt();
$A = $sc->nextInt();
$B = $sc->nextInt();
$AB = $A + $B;

$i = intval(floor($N / $AB));
$j = $N % $AB;

$k = $j - $B <= 0 ? 0 : $N - $B;

out::println($i * $A + $k);


<?php

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

$one_time_ball = $a + $b;

$time = $n % $one_time_ball;

$rest_ball = $n - $one_time_ball * $time;
$rest_a_ball = $rest_ball > $a ? $a : $rest_ball;

echo $a * $time + $rest_a_ball;


Score : 300 points

Problem Statement

Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.)

Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer.

If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print -1.

Constraints

1 \leq A \leq B \leq 100

A and B are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print -1.

Sample Input 1

2 2

Sample Output 1

25

If the price of a product before tax is 25 yen, the amount of consumption tax levied on it is:

When the consumption tax rate is 8 percent: \lfloor 25 \times 0.08 \rfloor = \lfloor 2 \rfloor = 2 yen.

When the consumption tax rate is 10 percent: \lfloor 25 \times 0.1 \rfloor = \lfloor 2.5 \rfloor = 2 yen.

Thus, the price of 25 yen satisfies the condition. There are other possible prices, such as 26 yen, but print the minimum such price, 25.

Sample Input 2

8 10

Sample Output 2

100

If the price of a product before tax is 100 yen, the amount of consumption tax levied on it is:

When the consumption tax rate is 8 percent: \lfloor 100 \times 0.08 \rfloor = 8 yen.

When the consumption tax rate is 10 percent: \lfloor 100 \times 0.1 \rfloor = 10 yen.

Sample Input 3

19 99

Sample Output 3

-1

There is no price before tax satisfying this condition, so print -1.


<?php

    // 末尾に改行をつけて出力
    function output($str) {
        echo $str . PHP_EOL;
    }

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

    $lower = floor($a / 0.08);
    $upper = floor($b / 0.10) + 10;
    $resul = -1;
    for ($i = $lower; $i <= $upper; $i++) {
        $p1 = floor($i * 0.08);
        $p2 = floor($i * 0.10);
        if ($p1 == $p2) {
            $result = $i;
            break;
        }
    }

    output($result);


<?php

fscanf(STDIN,"%s",$s);
fscanf(STDIN,"%d",$q);
$revers_flag = -1;
for($i=0;$i<$q;$i++){
  $command = explode(" ",trim(fgets(STDIN)));
  if($command[0] == 1){
    $revers_flag *= -1;
  }else{
    if($revers_flag == 1){
      if($command[1]==1){
        $s .= $command[2];
      }else{
        $s = $command[2].$s;
      }
      //echo $i." ".$s."\n";
    }else{
      if($command[1]==1){
         $s = $command[2].$s;

      }else{
 		$s .= $command[2];
      }
    }
  }
}

if($revers_flag == 1){
  for($i=strlen($s)-1;$i>=0;$i--){
    echo $s[$i];
  }
}else{
  echo $s;
}

Score : 400 points

Problem Statement

Takahashi has a string S consisting of lowercase English letters.

Starting with this string, he will produce a new one in the procedure given as follows.

The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following:

If T_i = 1: reverse the string S.

If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.

If F_i = 1 : Add C_i to the beginning of the string S.

If F_i = 2 : Add C_i to the end of the string S.

Help Takahashi by finding the final string that results from the procedure.

Constraints

1 \leq |S| \leq 10^5

S consists of lowercase English letters.

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

T_i = 1 or 2.

F_i = 1 or 2, if provided.

C_i is a lowercase English letter, if provided.

Input

Input is given from Standard Input in the following format:

S
Q
Query_1
:
Query_Q

In the 3-rd through the (Q+2)-th lines, Query_i is one of the following:

1

which means T_i = 1, and:

2 F_i C_i

which means T_i = 2.

Output

Print the resulting string.

Sample Input 1

a
4
2 1 p
1
2 2 c
1

Sample Output 1

cpa

There will be Q = 4 operations. Initially, S is a.

Operation 1: Add p at the beginning of S. S becomes pa.

Operation 2: Reverse S. S becomes ap.

Operation 3: Add c at the end of S. S becomes apc.

Operation 4: Reverse S. S becomes cpa.

Thus, the resulting string is cpa.

Sample Input 2

a
6
2 2 a
2 1 b
1
2 2 c
1
1

Sample Output 2

aabc

There will be Q = 6 operations. Initially, S is a.

Operation 1: S becomes aa.

Operation 2: S becomes baa.

Operation 3: S becomes aab.

Operation 4: S becomes aabc.

Operation 5: S becomes cbaa.

Operation 6: S becomes aabc.

Thus, the resulting string is aabc.

Sample Input 3

y
1
2 1 x

Sample Output 3

xy


<?php

    // 末尾に改行をつけて出力
    function output($str) {
        echo $str . PHP_EOL;
    }

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

    $sr = strrev($s);
    $reverse = false;
    while ($query = trim(fgets(STDIN))) {
        if ($query[0] == '1') {
            // type1
            $reverse = !$reverse;
        } else {
            // type2
            $char = $char;
            if ($query[2] == 1) {
                if ( ! $reverse) {
                    $s = $char.$s;
                    $sr = $sr.$char;
                } else {
                    $s = $s.$char;
                    $sr = $char.$sr;
                }
            } else {
                if ( ! $reverse) {
                    $s = $s.$char;
                    $sr = $char.$sr;
                } else {
                    $s = $char.$s;
                    $sr = $sr.$char;
                }
            }
        }
    }
    if ($reverse) {
        output($sr);
    } else {
        output($s);
    }


<?php

    // 末尾に改行をつけて出力
    function output($str) {
        echo $str . PHP_EOL;
    }

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

    $sr = strrev($s);
    $reverse = false;
    while ($query = trim(fgets(STDIN))) {
        if ($query[0] == '1') {
            // type1
            $reverse = !$reverse;
        } else {
            // type2
            if ($query[2] == 1) {
                if ( ! $reverse) {
                    $s = $query[4].$s;
                    $sr = $sr.$query[4];
                } else {
                    $s = $s.$query[4];
                    $sr = $query[4].$sr;
                }
            } else {
                if ( ! $reverse) {
                    $s = $s.$query[4];
                    $sr = $query[4].$sr;
                } else {
                    $s = $query[4].$s;
                    $sr = $sr.$query[4];
                }
            }
        }
    }
    if ($reverse) {
        output($sr);
    } else {
        output($s);
    }


<?php
  $s[] = trim(fgets(STDIN));
  $n = trim(fgets(STDIN));
  for($i = 0; $i < $n; $i++){
    $temp = explode(" ", trim(fgets(STDIN)));
    if($temp[0] == 1){
      $s = array_reverse($s);
    }else{
      if($temp[1] == 1){
        array_unshift($s, $temp[2]);
      }else{
        array_push($s, $temp[2]);
      }
    }
  }
  $ans = implode("", $s);
  echo $ans;
 ?>


Score : 600 points

Problem Statement

There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable.

Takahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line.

Choose a robot and activate it. This operation cannot be done when there is a robot moving.

While Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively.

How many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous.

Constraints

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

-10^9 \leq X_i \leq 10^9

1 \leq D_i \leq 10^9

X_i \neq X_j (i \neq j)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 D_1
:
X_N D_N

Output

Print the number of possible sets of robots remaining on the number line, modulo 998244353.

Sample Input 1

2
1 5
3 3

Sample Output 1

3

There are three possible sets of robots remaining on the number line: \{1, 2\}, \{1\}, and \{\}.

These can be achieved as follows:

If Takahashi activates nothing, the robots \{1, 2\} will remain.

If Takahashi activates Robot 1, it will activate Robot 2 while moving, after which there will be no robots on the number line. This state can also be reached by activating Robot 2 and then Robot 1.

If Takahashi activates Robot 2 and finishes doing the operation, the robot \{1\} will remain.

Sample Input 2

3
6 5
-1 10
3 3

Sample Output 2

5

There are five possible sets of robots remaining on the number line: \{1, 2, 3\}, \{1, 2\}, \{2\}, \{2, 3\}, and \{\}.

Sample Input 3

4
7 10
-10 3
4 3
-4 3

Sample Output 3

16

None of the robots influences others.

Sample Input 4

20
-8 1
26 4
0 5
9 1
19 4
22 20
28 27
11 8
-3 20
-25 17
10 4
-18 27
24 28
-11 19
2 27
-2 18
-1 12
-24 29
31 29
29 7

Sample Output 4

110

Remember to print the count modulo 998244353.


Score : 200 points

Problem Statement

We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.

The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.

Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.

Constraints

All values in input are integers.

1 \leq A_{i, j} \leq 100

A_{i_1, j_1} \neq A_{i_2, j_2} ((i_1, j_1) \neq (i_2, j_2))

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

A_{1, 1} A_{1, 2} A_{1, 3}
A_{2, 1} A_{2, 2} A_{2, 3}
A_{3, 1} A_{3, 2} A_{3, 3}
N
b_1
\vdots
b_N

Output

If we will have a bingo, print Yes; otherwise, print No.

Sample Input 1

84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30

Sample Output 1

Yes

We will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.

Sample Input 2

41 7 46
26 89 2
78 92 8
5
6
45
16
57
17

Sample Output 2

No

We will mark nothing.

Sample Input 3

60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34

Sample Output 3

Yes

We will mark all the squares.


<?php
list($n) = ints();
list($s) = strs();
for ($i = 0; $i < $n; ++$i) $a[] = 1 << (ord($s[$i]) - 97);
$st = new SegmentTree($a);
list($q) = ints();
for ($i = 0; $i < $q; ++$i) {
    list($type, $a, $b) = strs();
    if ($type === '1') {
        $st->set($a - 1, 1 << (ord($b) - 97));
    } else {
        $output[] = popcount($st->get($a - 1, $b, 0, 0, $st->n));
    }
}
echo implode(PHP_EOL, $output);
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function popcount($x)
{
    $res = 0;
    while ($x > 0) {
        $x &= $x - 1;
        ++$res;
    }
    return $res;
}
// セグメントツリー
// 更新と取得を O(logN) で行う
class SegmentTree
{
    public $n;
    private $node;
    const UNIT = 0; // 単位元 問題に応じて変更する

    public function __construct(array $a)
    {
        $l = count($a);
        $n = 1;
        while ($n < $l) $n *= 2;
        $node = array_fill(0, 2 * $n - 1, self::UNIT);
        for ($i = 0; $i < $l; ++$i) $node[$i + $n - 1] = $a[$i];
        $this->n = $n;
        $this->node = $node;
        $this->updateAll();
    }

    private function updateAll(): void
    {
        $n = $this->n;
        $node = $this->node;
        for ($i = $n - 2; $i >= 0; --$i)
            $node[$i] = $this->op($node[2 * $i + 1], $node[2 * $i + 2]);
        $this->node = $node;
    }

    public function set(int $x, int $v): void
    {
        $n = $this->n;
        $node = $this->node;
        $x += $n - 1;
        $node[$x] = $v;
        while ($x > 0) {
            $x = intdiv($x - 1, 2);
            $node[$x] = $this->op($node[2 * $x + 1], $node[2 * $x + 2]);
        }
        $this->node = $node;
    }

    // 区間 [a, b)
    public function get(int $a, int $b, int $k = 0, int $l = 0, int $r = -1): int
    {
        // 範囲外
        if ($a >= $r || $b <= $l) return self::UNIT;
        // 完全に含む
        if ($a <= $l && $b >= $r) return $this->node[$k];
        // 一部含む
        return $this->op(
            $this->get($a, $b, 2 * $k + 1, $l, intdiv($l + $r, 2)),
            $this->get($a, $b, 2 * $k + 2, intdiv($l + $r, 2), $r)
        );
    }

    // 二項演算 問題に応じて変更する
    private function op(int $a, int $b): int
    {
        return $a | $b;
    }
}

Score : 500 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters.

Process Q queries of the following two types:

Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)

Type 2: answer the number of different characters occurring in the substring of S between the l_q-th and r_q-th characters (inclusive).

Constraints

N, Q, i_q, l_q, and r_q are integers.

S is a string consisting of lowercase English letters.

c_q is a lowercase English letter.

1 \leq N \leq 500000

1 \leq Q \leq 20000

|S| = N

1 \leq i_q \leq N

1 \leq l_q \leq r_q \leq N

There is at least one query of type 2 in each testcase.

Input

Input is given from Standard Input in the following format:

N
S
Q
Query_1
\vdots
Query_Q

Here, Query_i in the 4-th through (Q+3)-th lines is one of the following:

1 i_q c_q

2 l_q r_q

Output

For each query of type 2, print a line containing the answer.

Sample Input 1

7
abcdbbd
6
2 3 6
1 5 z
2 1 1
1 4 a
1 7 d
2 1 7

Sample Output 1

3
1
5

In the first query, cdbb contains three kinds of letters: b , c , and d, so we print 3.

In the second query, S is modified to abcdzbd.

In the third query, a contains one kind of letter: a, so we print 1.

In the fourth query, S is modified to abcazbd.

In the fifth query, S does not change and is still abcazbd.

In the sixth query, abcazbd contains five kinds of letters: a, b, c, d, and z, so we print 5.


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

function op($a, $b){return $a | $b;}

for($i = 0; $i < $n; $i++){
  $array[] = 1<<(ord($str[$i])-97);
}
$seg = new SegTree($array);

while($Q--){
  list($q, $a, $b) = explode(" ", trim(fgets(STDIN)));
  if($q == "1"){
    $seg->set($a-1, 1<<(ord($b)-97));
  }else{
    $ret[] = popcount($seg->get($a-1, $b));
  }
}
echo implode("\n", $ret);

class SegTree{
  public $tree;
  public $bits;
  function __construct($n){
    if(is_array($n)){
      $array = $n;
      $n = count($array);
      $this->bits = max(1, ceil(log($n)/log(2)));
      for($i = $n, $I = 2**$this->bits; $i < $I; ++$i){
        $array[] = 0;
      }
      $this->tree[0] = $array;
      $this->rollupAll();
    }else{
      $this->bits = max(1, ceil(log($n)/log(2)));
      for($i = 0; $i < $this->bits; ++$i){
        $this->tree[$i] = array_fill(0, 2**($this->bits-$i), 0);
      }
    }
  }
  function rollupAll(){
    for($i = 1; $i < $this->bits; ++$i){
      $treei = &$this->tree[$i];
      $treeim = $this->tree[$i-1];
      for($j = 0, $J = 2**($this->bits - $i + 1); $j < $J; $j+=2){
        $treei[$j>>1] = op($treeim[$j], $treeim[$j+1]);
      }
    }
  }
  function set($i, $amount){
    $this->tree[0][$i] = $amount;
    for($j = 1, $J = $this->bits; $j < $J; ++$j){
      $this->tree[$j][$i>>$j] = op($this->tree[$j-1][$i>>$j<<1], $this->tree[$j-1][($i>>$j<<1) + 1]);
    }
  }
  function get($f, $t){
    $sum = 0;
    $tree = $this->tree;
    $bits = $this->bits;
    $i = 0;
    while($f!=$t){
      $treei = $tree[$i];
      if(($f >> $i) & 1 == 1){
        $sum = op($sum, $treei[$f>>$i]);
        $f+=1<<$i;
      }
      if(($t >> $i) & 1 == 1){
        $sum = op($sum, $treei[($t>>$i)-1]);
        $t-=1<<$i;
      }
      ++$i;
    }
    return $sum;
  }
}

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;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


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

for($i = 0; $i < 26; $i++){
  $array[$i] = array_fill(0, $n, 0);
}
for($i = 0; $i < $n; $i++){
  $array[ord($str[$i])-97][$i]++;
}
for($i = 0; $i < 26; $i++){
  $seg[$i] = new SegTree($array[$i]);
}

while($Q--){
  list($q, $a, $b) = explode(" ", trim(fgets(STDIN)));
  $a--;$b--;
  if($q == "1"){
    if($str[$a] != $b){
      $seg[ord($str[$a])-97]->add($a, -1);
      $seg[ord($b)-97]->add($a,  1);
      $str[$a] = $b;
    }
  }else{
    $c = 0;
    for($i = 0; $i < 26; $i++){
      $c += $seg[$i]->sumBetween($a, $b) > 0;
    }
    echo $c,"\n";
  }
}

class SegTree{
  public $tree;
  public $bits;
  function __construct($n){
    if(is_array($n)){
      $this->bits = max(1, ceil(log(count($n))/log(2)));
      $this->tree[$this->bits] = $n;
      for($i = count($n), $I = 2**$this->bits; $i < $I; ++$i){
        $this->tree[$this->bits][] = 0;
      }
      for($i = $this->bits - 1; $i >= 1 ; --$i){
        $treei = &$this->tree[$i];
        $treeip = $this->tree[$i+1];
        for($j = 0, $J = 2**$i; $j < $J; $j++){
          $treei[$j] = $treeip[$j*2] + $treeip[$j*2+1];
        }
      }
    }else{
      $this->bits = max(1, ceil(log($n)/log(2)));
      for($i = 1; $i <= $this->bits; ++$i){
        $this->tree[$i] = array_fill(0, 2**$i, 0);
      }
    }
  }
  function add($i, $amount = 1){
    for($j = $this->bits; $j >= 1; --$j){
      $this->tree[$j][$i] += $amount;
      $i>>=1;
    }
  }
  function sumLTE($t){return $this->sumLT($t+1);}
  function sumLT($t){
    $ret = 0;
    for($i = $this->bits; $i >= 1 ; --$i){
        if(($t >> ($i-1)) & 1){
          $ret += $this->tree[$this->bits - $i + 1][($t >> ($i-1)) ^ 1];
        }
    }
    return $ret;
  }
  function sum(){
    return array_sum($this->tree[1]);
  }
  function sumBetween($f, $t){
    return $this->sumLT($t+1) - $this->sumLT($f);
  }
}

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;
}


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

$arr = array_fill(0, $n, 0);
for($i = 0; $i < 26; $i++){
  $array[$i] = $arr;
}
for($i = 0; $i < $n; $i++){
  $array[ord($str[$i])-97][$i]++;
}
for($i = 0; $i < 26; $i++){
  $seg[$i] = new SegTree($array[$i]);
}
while($Q--){
  list($q, $a, $b) = explode(" ", trim(fgets(STDIN)));
  $a--;$b--;
  if($q == "1"){
    if($str[$a] != $b){
      $seg[ord($str[$a])-97]->add($a, -1);
      $seg[ord($b)-97]->add($a,  1);
      $str[$a] = $b;
    }
  }else{
    $c = 0;
    for($i = 0; $i < 26; $i++){
      $c += $seg[$i]->sumBetween($a, $b) > 0;
    }
    echo $c,"\n";
  }
}

class SegTree{
  public $tree;
  public $bits;
  function __construct($n){
    if(is_array($n)){
      $this->bits = max(1, ceil(log(count($n))/log(2)));
      $this->tree[$this->bits] = $n;
      for($i = count($n), $I = 2**$this->bits; $i < $I; ++$i){
        $this->tree[$this->bits][] = 0;
      }
      for($i = $this->bits - 1; $i >= 1 ; --$i){
        for($j = 0; $j < 2**$i; $j++){
          $this->tree[$i][$j] = $this->tree[$i+1][$j*2] + $this->tree[$i+1][$j*2+1];
        }
      }
    }else{
      $this->bits = max(1, ceil(log($n)/log(2)));
      for($i = 1; $i <= $this->bits; ++$i){
        $this->tree[$i] = array_fill(0, 2**$i, 0);
      }
    }
  }
  function add($i, $amount = 1){
    for($j = $this->bits; $j >= 1; --$j){
      $this->tree[$j][$i] += $amount;
      $i>>=1;
    }
  }
  function sumLTE($t){return $this->sumLT($t+1);}
  function sumLT($t){
    $ret = 0;
    for($i = $this->bits; $i >= 1 ; --$i){
        if(($t >> ($i-1)) & 1){
          $ret += $this->tree[$this->bits - $i + 1][($t >> ($i-1)) ^ 1];
        }
    }
    return $ret;
  }
  function sum(){
    return array_sum($this->tree[1]);
  }
  function sumBetween($f, $t){
    return $this->sumLT($t+1) - $this->sumLT($f);
  }
}

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;
}


<?php

fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $string);
$array = str_split($string);
fscanf(STDIN, "%d", $q);

while($q--){
    fscanf(STDIN, "%d%d%s", $n, $st, $ed);
    if($n==1){
        $array[$st-1] = $ed;
    }else{
        echo count(array_unique(array_slice($array,$st-1,(int)$ed - $st + 1))).PHP_EOL;
    }
}


Score : 100 points

Problem Statement

Takahashi is a member of a programming competition site, ButCoder.

Each member of ButCoder is assigned two values: Inner Rating and Displayed Rating.

The Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or more contests. Otherwise, the Displayed Rating will be their Inner Rating minus 100 \times (10 - K) when the member has participated in K contests.

Takahashi has participated in N contests, and his Displayed Rating is R. Find his Inner Rating.

Constraints

All values in input are integers.

1 \leq N \leq 100

0 \leq R \leq 4111

Input

Input is given from Standard Input in the following format:

N R

Output

Print his Inner Rating.

Sample Input 1

2 2919

Sample Output 1

3719

Takahashi has participated in 2 contests, which is less than 10, so his Displayed Rating is his Inner Rating minus 100 \times (10 - 2) = 800.

Thus, Takahashi's Inner Rating is 2919 + 800 = 3719.

Sample Input 2

22 3051

Sample Output 2

3051


<?php
// Your code here!
$input = explode(' ',fgets(STDIN));
$degits = base_convert($input[0], 10, intval($input[1]));
echo strlen($degits);
?>

Score : 200 points

Problem Statement

Given is an integer N. Find the number of digits that N has in base K.

Notes

For information on base-K representation, see Positional notation - Wikipedia.

Constraints

All values in input are integers.

1 \leq N \leq 10^9

2 \leq K \leq 10

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of digits that N has in base K.

Sample Input 1

11 2

Sample Output 1

4

In binary, 11 is represented as 1011.

Sample Input 2

1010101 10

Sample Output 2

7

Sample Input 3

314159265 3

Sample Output 3

18


<?php
$args = explode(" ", trim(fgets(STDIN)));
$value = intval($args[0]);
$digit = intval($args[1]);
$i = 1;
while ($value >= $digit) {
  $value = floor($value / $digit);
  $i++;
}
echo $i . PHP_EOL;


<?php
    list($a, $b) = explode(" ", trim(fgets(STDIN)));
    echo base_convert($a, 10, $b);
?>


<?php
$person = trim(fgets(STDIN));
$arr_place = explode(" ", fgets(STDIN));
$sum = 0;
foreach ($arr_place as $place) {
    $sum += intval($place);
}
$average = round($sum/$person);
$power = 0;
foreach ($arr_place as $place) {
    $power += pow(($place - $average), 2);
}
echo $power;
?>

Score : 300 points

Problem Statement

There are N people living on a number line.

The i-th person lives at coordinate X_i.

You are going to hold a meeting that all N people have to attend.

The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting.

Find the minimum total points of stamina the N people have to spend.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq X_i \leq 100

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print the minimum total stamina the N people have to spend.

Sample Input 1

2
1 4

Sample Output 1

5

Assume the meeting is held at coordinate 2. In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.

Note that you can hold the meeting only at an integer coordinate.

Sample Input 2

7
14 14 2 13 56 2 37

Sample Output 2

2354


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

$p = (int)round(array_sum($exploded_numbers) / $n);
$sum = 0;
foreach ($exploded_numbers as $num) {
  $sum += pow($num - $p, 2);
}

echo $sum;


<?php
define("MOD", 10**9+7);
list($n,$a,$b)=explode(" ",trim(fgets(STDIN)));
$i=1;
$ans=powerm(2,$n)-1;
$ans-=nCm($n,$a);
$ans-=nCm($n,$b);
echo ($ans<0)?$ans+MOD:$ans;

//yoichiro's func
//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}

//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}

//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}

//階乗
function factorialm($a){
    if($a == 0)return 1;
    return factorialm($a - 1) * $a % MOD;
}

//順列
function nPm($n, $m){
    if($m == 0)return 1;
    return nPm($n, $m - 1) * ($n - $m + 1) % MOD;
}

//組み合わせ
function nCm($n, $m){
    $m = min($m, $n-$m);
    return divm(nPm($n, $m), factorialm($m));
}

Score : 400 points

Problem Statement

Akari has n kinds of flowers, one of each kind.

She is going to choose one or more of these flowers to make a bouquet.

However, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.

How many different bouquets are there that Akari can make?

Find the count modulo (10^9 + 7).

Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.

Constraints

All values in input are integers.

2 \leq n \leq 10^9

1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5)

Input

Input is given from Standard Input in the following format:

n a b

Output

Print the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print 0.)

Sample Input 1

4 1 3

Sample Output 1

7

In this case, Akari can choose 2 or 4 flowers to make the bouquet.

There are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4, so there are a total of 7 different bouquets that Akari can make.

Sample Input 2

1000000000 141421 173205

Sample Output 2

34076506

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


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

    // 前処理
    $fact = [];
    $fact[0] = 1;
    for($i=1;$i<=$n;$i++)
    {
        // $nまでの階乗を求める
        $fact[$i] = $fact[$i-1]*$i%$m;
    }
    $ifact = [];
    $ifact[$n] = repeatSqrt($fact[$n], $m-2, $m);
    for($i=$n;$i>=1;$i--)
    {
        // $nまでの階乗の逆元を求める
        $ifact[$i-1] = $ifact[$i]*$i%$m;
    }
//    var_dump($fact);
//    var_dump($ifact);

    $ans = 0;

    if($k>$n){
        $k=$n;
    }

    for($i=0; $i<=$k; $i++)
    {
        $nCi = ($fact[$n]*$ifact[$i]%$m)*$ifact[$n-$i]%$m;
        $n1Ci = ($fact[$n-1]*$ifact[$i]%$m)*$ifact[$n-1-$i]%$m;
//        echo $i." ".$nCi." ".$n1Ci.PHP_EOL;

      $ans = ($ans+($nCi*$n1Ci%$m))%$m;
    }

    echo $ans;
    exit;

    /**
     * 繰り返し二乗法
     * @param $n
     * @param $p
     * @param $m mod P
     * @param $a
     */
    function repeatSqrt($b, $p, $m)
    {
    if($p==1)
    {
        return $b;
    }
    else if($p%2 == 0)
    {
        $t = repeatSqrt($b, floor($p/2), $m);
        return ($t * $t) % $m;
    }
    else
    {
        return ($b * repeatSqrt($b, $p-1, $m)) % $m;
    }
    }

    /**
     * 組み合わせ
     * @param $n 全体の数
     * @param $a 取り出す数
     * @param $m mod
     */
    function combination($n, $a, $m)
    {
        $x=1; // bunbo
        $y=1; // bunshi
        for($i=0;$i<$a;$i++)
        {
            $x=$x*($n-$i)%$m;
            $y=$y*($i+1)%$m;
        }
        $y=repeatSqrt($y, $m-2, $m);
        return ($x*$y)%$m;
    }

Score : 500 points

Problem Statement

There is a building with n rooms, numbered 1 to n.

We can move from any room to any other room in the building.

Let us call the following event a move: a person in some room i goes to another room j~ (i \neq j).

Initially, there was one person in each room in the building.

After that, we know that there were exactly k moves happened up to now.

We are interested in the number of people in each of the n rooms now. How many combinations of numbers of people in the n rooms are possible?

Find the count modulo (10^9 + 7).

Constraints

All values in input are integers.

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

2 \leq k \leq 10^9

Input

Input is given from Standard Input in the following format:

n k

Output

Print the number of possible combinations of numbers of people in the n rooms now, modulo (10^9 + 7).

Sample Input 1

3 2

Sample Output 1

10

Let c_1, c_2, and c_3 be the number of people in Room 1, 2, and 3 now, respectively. There are 10 possible combination of (c_1, c_2, c_3):

(0, 0, 3)

(0, 1, 2)

(0, 2, 1)

(0, 3, 0)

(1, 0, 2)

(1, 1, 1)

(1, 2, 0)

(2, 0, 1)

(2, 1, 0)

(3, 0, 0)

For example, (c_1, c_2, c_3) will be (0, 1, 2) if the person in Room 1 goes to Room 2 and then one of the persons in Room 2 goes to Room 3.

Sample Input 2

200000 1000000000

Sample Output 2

607923868

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

Sample Input 3

15 6

Sample Output 3

22583772


Score: 100 points

Problem Statement

A triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.

You will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.

Constraints

A, B, and C are all integers between 1 and 9 (inclusive).

Input

Input is given from Standard Input in the following format:

A B C

Output

If the given triple is poor, print Yes; otherwise, print No.

Sample Input 1

5 7 5

Sample Output 1

Yes

A and C are equal, but B is different from those two numbers, so this triple is poor.

Sample Input 2

4 4 4

Sample Output 2

No

A, B, and C are all equal, so this triple is not poor.

Sample Input 3

4 9 6

Sample Output 3

No

Sample Input 4

3 3 4

Sample Output 4

Yes