<?php
fscanf(STDIN, "%d %d", $N, $R);
if ($N >= 10) {
    echo($R).PHP_EOL;
} else {
    $ans = $R + (100 * (10 - $N));
    echo $ans.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
$N = trim(fgets(STDIN));
$I = explode(' ', trim(fgets(STDIN)));

$r = null;

$min = min($I);
$max = max($I) + 1;

for (; $min < $max; ++$min) {

    $c = 0;

    for ($i = 0; $i < $N; ++$i) {
        $c += pow($I[$i] - $min, 2);
    }

    if ($r == null || $r > $c) $r = $c;
}

echo $r;

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

Submitted source-code file size, in bytes.

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

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


<?php
$query = fgets(STDIN);
list($N,$N1) = sscanf($query,"%d %d");
echo strlen(base_convert($N, 10, $N1));

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
list($n, $k) = ints();
$c = 0;
while($n){
    $n = intdiv($n, $k);
    $c++;
}
echo $c;
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;
}


<?php
fscanf(STDIN, "%d", $n);
$inputs = array_map('intval', explode(' ', trim(fgets(STDIN))));
$max = max($inputs);
$min = min($inputs);

$decs = [];
for ($i = 1; $max > $i; $i++) {
    $tmp = 0;
    foreach ($inputs as $input) {
        $x = $input - $i;
        $y = pow($x, 2);
        #echo join(", ", [$input, $i, $n, $x, $y]) . "\n";
        $tmp += $y;
    }
    #echo "=" . $tmp . "\n";
    $decs[] = $tmp;
}
#echo join(",", $decs) . "\n";
echo min($decs);

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


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


<?php
    $n = trim(fgets(STDIN));
    $arr = explode(" ", trim(fgets(STDIN)));
    $flg = 0;
    $cnt = 0;
    for($i = 0; $i < $n; $i++){
        if($arr[$i] % 2 == 0){
            $cnt++;
            if($arr[$i] % 3 == 0 || $arr[$i] % 5 == 0){
                $flg++;
            }
        }
    }
    if($cnt == $flg){
        echo "APPROVED";
    }else{
        echo "DENIED";
    }
?>

Score: 200 points

Problem Statement

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

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

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

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

Notes

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

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq A_i \leq 1000

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

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

Sample Input 1

5
6 7 9 10 31

Sample Output 1

APPROVED

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

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

Sample Input 2

3
28 27 24

Sample Output 2

DENIED

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


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

$evenNum = 0;
$approvedNum = 0;

foreach ($a as $value) {
    if ($value % 2 === 0) {
        $evenNum++;

        if ($value % 3 === 0 || $value % 5 === 0) {
            $approvedNum++;
        }
    }
}
if($evenNum == $approvedNum){
    echo "APPROVED";
} else {
    echo "DENIED";
}


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

$flg = true;
foreach ($a as $value) {
//    var_dump((int)$value,(int)$value % 2 !==0,(int)$value %3 !== 0);
    if ((int)$value % 2 !==0) {
        continue;
    }

    if ((int)$value %3 === 0) {
        continue;
    } else if((int)$value %5 === 0) {
        continue;
    } else {
        $flg = false;
        break;
    }

}

if ($flg === true) {

    echo 'APPROVED'.PHP_EOL;
} else {
    echo "DENIED".PHP_EOL;
}


<?php

fscanf(STDIN, "%s %s", $strA, $strB);
fscanf(STDIN, "%d %d", $cnt1, $cnt2);
fscanf(STDIN, "%s", $sctStr);

If($sctStr == $strA) {
  	$cnt1 = $cnt1 - 1;
} Else If ($sctStr == $strB) {
 	$cnt2 = $cnt2 - 1;
}

echo $cnt1." ".$cnt2;

Score : 100 points

Problem Statement

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

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

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

Constraints

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

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

S \not= T

S=U or T=U.

1 \leq A,B \leq 10

A and B are integers.

Input

Input is given from Standard Input in the following format:

S T
A B
U

Output

Print the answer, with space in between.

Sample Input 1

red blue
3 4
red

Sample Output 1

2 4

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

Sample Input 2

red blue
5 5
blue

Sample Output 2

5 4

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


<?php

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

$kaisu = strlen($a);
$moji = null;

for($i = 1; $i <= $kaisu; $i++) {
  $moji = $moji.'x';
}

echo $moji;

Score : 200 points

Problem Statement

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

Constraints

S is a string consisting of lowercase English letters.

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

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

sardine

Sample Output 1

xxxxxxx

Replacing every character in S with x results in xxxxxxx.

Sample Input 2

xxxx

Sample Output 2

xxxx

Sample Input 3

gone

Sample Output 3

xxxx


<?php
fscanf(STDIN, '%s', $s);
$ans = $s;
$s_len = strlen($s);
for($i = 0; $i < $s_len; $i++) {
    $ans[$i] = 'x';
}
echo $ans, PHP_EOL;


<?php
fscanf(STDIN, "%s", $s);
$ans = ""
for(i = 0 ; i < strlen($s) ; i++){
	$ans += "x";
}
echo $ans
?>


<?php
$in = trim(fgets(STDIN));
$n = strlen($in);
for ($i = 0; $i < $n; $i++) {
     echo "x";
}
echo "\n";
?>


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

echo str_repeat('x', strlen($S)) . PHP_EOL;


<?php

$n = trim(fgets(STDIN));
$line = explode(" ", trim(fgets(STDIN)));

$value_count = array_count_values($line);
$max = max($value_count);
if($max == 1){
    echo 'YES';
}else{
    echo 'NO';
}

?>

Score : 300 points

Problem Statement

Given is a sequence of integers A_1, A_2, ..., A_N.
If its elements are pairwise distinct, print YES; otherwise, print NO.

Constraints

2 ≤ N ≤ 200000

1 ≤ A_i ≤ 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

If the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.

Sample Input 1

5
2 6 1 4 5

Sample Output 1

YES

The elements are pairwise distinct.

Sample Input 2

6
4 1 3 1 6 2

Sample Output 2

NO

The second and fourth elements are identical.

Sample Input 3

2
10000000 10000000

Sample Output 3

NO


<?php
fscanf(STDIN, "%d", $n);
$s = trim(fgets(STDIN));
$numbers = explode(' ', $s);
$uniques = array_unique($numbers);
var_dump($uniques);
echo count($numbers) === count($uniques) ? 'YES' : 'NO';


<?php
$N = fgets(STDIN);
$A = fgets(STDIN);
$val=(int)$N;

for ($i = 0; $i<$varl; ++$i){
  echo $A[$i];
  for ($j = $i+1; $j < $val; ++$j){
    if ($A[$i] == $A[$j]){
      echo $A[$j];
      echo "NO";
      exit(0);
    }
  }
}
echo "YES";

?>


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

  $unique_array = array_unique($stack);
  if (count($unique_array) === count($stack)) {
    echo "YES";
  }
  else {
    echo "NO";
  }

?>


<?php
fscanf(STDIN, "%d %d", $n, $k);
$p = array_map('intval', explode(' ', trim(fgets(STDIN))));
foreach ($p as $i => $v) {
    $p[$i]++;
}
$max = 0;
$s = 0;
$q = new SplQueue();
for ($i = 0; $i < count($p); ++$i) {
    $s += $p[$i];
    $q->enqueue($p[$i]);
    if ($q->count() > $k) {
        $s -= $q->dequeue();
    }
    if ($q->count() == $k) {
        $max = max($max, $s);
    }
}
printf("%.10f", $max / 2);

Score : 400 points

Problem Statement

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

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

Constraints

1 ≤ K ≤ N ≤ 200000

1 ≤ p_i ≤ 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N

Output

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

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

Sample Input 1

5 3
1 2 2 4 5

Sample Output 1

7.000000000000

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

Sample Input 2

4 1
6 6 6 6

Sample Output 2

3.500000000000

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

Sample Input 3

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

Sample Output 3

32.000000000000


<?php

fscanf(STDIN, '%d %d', $n, $k);

$p = explode(' ', rtrim(fgets(STDIN), PHP_EOL));

function kitaiti($d) {
    $sum = 0;
    for ($i = $d; $i > 0; $i --) {
        $sum += $i;
    }
    return (float)$sum / $d;
}

$ppp = [];
foreach ($p as $pp) {
    $ppp[] = kitaiti($pp);
}

$cache = 0;
//$point = 0;
$aaa = $n - $k;
for ($i = 0; $i <= $aaa; $i++) {
    $tmp = 0.0;
    $bbb = $i+$k;
    for ($y = $i; $y < $bbb;$y++){
        $tmp += $ppp[$y];
    }
    if ($tmp > $cache) {
        $cache = $tmp;
//        $point = $i;
    }
}

//$fuga = 0.0;
//$ccc = $point+$k;
//for ($y = $point; $y < $ccc;$y++){
//    $fuga += kitaiti($p[$y]);
//}

echo sprintf('%7f', $cache).PHP_EOL;


<?php

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

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

//1.どの区間を選択するか
$i = 0;
// 1位だけ残す
$topScore = 0;
$lim = ($n - $k + 1);
while ($i < $lim) {
    $j = 0;
    //区間の和をScore
    $score = 0;
    while ($j < $k) {
        $index = $i + $j;
        $score += $input[$index];
        $j++;
    }
    if ($topScore < $score) {
        $topScore = $score;
    }
    $i++;
}

//2.その場合の期待値はいくつか
//期待値の計算は、(1+Pi)/2 で良い

//スコア÷2と　K÷2の和が期待値
print ($topScore / 2 + $k / 2);


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

$res=0;

foreach($P as $v) {
  $sum = array_sum(range(1,$v,1));
  $k[] = $sum/$v;
}

$res = 0;
for($i=0;$i<=$N-$K;$i++) {
  $sum = 0;
  for($j=$i;$j<$i+$K;$j++) {
    $sum += $k[$j];
  }
  $res = max($res,$sum);
}
printf("%f\n",$res);


Score : 500 points

Problem Statement

Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.

Constraints

1 \leq N < 10^{100}

1 \leq K \leq 3

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the count.

Sample Input 1

100
1

Sample Output 1

19

The following 19 integers satisfy the condition:

1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100

Sample Input 2

25
2

Sample Output 2

14

The following 14 integers satisfy the condition:

11,12,13,14,15,16,17,18,19,21,22,23,24,25

Sample Input 3

314159
2

Sample Output 3

937

Sample Input 4

9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3

Sample Output 4

117879300


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

$exp = strlen((string)$n) - 1;

$sum = 0;
switch ($k) {
	case 1:
		for ($i=0; $i <= $exp; $i++) {
			for ($inum=1; $inum <= 9; $inum++) {
				$num = $inum * pow(10, $i);
				if ($num <= $n) {
					$sum += 1;
				}
			}
		}
		break;
	case 2:
		for ($i=0; $i <= $exp-1; $i++) {
			$num = 0;
			for ($inum=1; $inum <= 9; $inum++) {
				if ($inum * pow(10, $i) >= $n) {
					break;
				}
				if ($i === $exp) {
					for ($j=$i+1; $j <= $exp; $j++) {
						for ($jnum=1; $jnum <= 9; $jnum++) {
							$num = $inum * pow(10, $i) + $jnum * pow(10, $j);
							if ($num <= $n) {
								$sum += 1;
							}
						}
					}
				}else{
					$sum += ModComb::singleComb($i, 1, 1000000007) * 9;
				}
			}
		}
		break;
	case 3:
		for ($i=$exp; $i >= 2; $i--) {
			$num = 0;
			for ($inum=1; $inum <= 9; $inum++) {
				if ($inum * pow(10, $i) >= $n) {
					break;
				}
				if ($i === $exp) {
					for ($j=$i-1; $j >= 1; $j--) {
						for ($jnum=1; $jnum <= 9; $jnum++) {
							if ($inum * pow(10, $i) + $jnum * pow(10, $j) >= $n) {
								break;
							}
							for ($k=$j-1; $k >= 0; $k--) {
								for ($knum=1; $knum <= 9; $knum++) {
									$num = $inum * pow(10, $i) + $jnum * pow(10, $j) + $knum * pow(10, $k);
									if ($num > $n) {
										break;
									}
									$sum += 1;
								}
							}
						}
					}
				}else{
					$sum += ModComb::singleComb($i, 2, 1000000007) * 81;
				}
			}
		}
		break;
}

echo $sum;

class ModComb
{
	// 事前計算テーブル
	private $f_table  = [1]; // $n! % $mod
	private $if_table = [1]; // $k!の($mod-2)乗 % $mod
	// 十分大きな素数にする
	private $mod = 0;

	public function __construct($max = 10000, $mod = 1000000007){
		$this->mod = $mod;
		// 事前計算
		$this->calcFactorial($max);
	}

	// 組み合わせ計算（nCm）
	public function comb($n, $m){
		if ($n === 0 && $m === 0) {
			return 1;
		}
		if ($n < $m || $n < 0) {
			return 0;
		}
		if (!isset($this->f_table[$n])) {
			$this->calcFactorial($n);
		}
		return ($this->if_table[$n - $m] * $this->if_table[$m] % $this->mod) * $this->f_table[$n] % $this->mod;
	}

	// logNで組み合わせを算出する。繰り返し多数の計算が不要な場合にはこちらの方が高速
	public static function singleComb($n, $m, $mod){
		if ($n === 0 && $m === 0) {
			return 1;
		}
		if ($n < $m || $n < 0) {
			return 0;
		}
		$f_n    = self::singleFact($n, $mod);
		$if_n_m = self::sigleBinPow(self::singleFact($n-$m, $mod), $mod-2, $mod) % $mod;
		$if_m   = self::sigleBinPow(self::singleFact($m, $mod), $mod-2, $mod) % $mod;
		return ($if_n_m * $if_m % $mod) * $f_n % $mod;
	}

	private static function singleFact($n, $mod){
		if ($n < 2) {
			return 1;
		}
		$table = [];
		for ($i=0; $i < $n; $i++) {
			$table[$i] = $i+1;
		}
		$idx = 1;
		while ($idx <= $n) {
			$span = $idx<<1;
			for ($i=0; $i < $n; $i+=$span) {
				if ($idx + $i < $n) {
					$table[$i] = ($table[$i] * $table[$i+$idx]) % $mod;
				}
			}
			$idx = $idx<<1;
		}
		return $table[0];
	}

	private static function sigleBinPow($x, $n, $mod){
		$ans = 1;
		$bin = decbin($n);
		$cur_pos = strlen($bin) -1;
		while ($cur_pos >= 0) {
			if ($bin[$cur_pos] == '1') {
				$ans = ($ans * $x) % $mod;
			}
			$x = ($x * $x) % $mod;
			--$cur_pos;
		}
		return $ans;
	}

	// 順列計算（nPm）
	public function perm($n, $m){
		if ($n < $m) {
			return 0;
		}
		if (!isset($this->f_table[$n])) {
			$this->calcFactorial($n);
		}
		return ($this->if_table[$n - $m] % $this->mod) * $this->f_table[$n] % $this->mod;
	}

	// 重複組合せ計算（nHm）
	public function dupc($n, $m){
		if ($n === 0 && $m === 0) {
			return 1;
		}
		if ($n < 0 || $m === 0) {
			return 0;
		}
		if (!isset($this->f_table[$n + $m - 1])) {
			$this->calcFactorial($n + $m - 1);
		}
		return ($this->if_table[$n - 1] * $this->if_table[$m] % $this->mod) * $this->f_table[$n + $m - 1] % $this->mod;
	}

	// 既存の事前計算結果テーブルの末尾から$maxまでの階乗までtableを拡張する。
	private function calcFactorial($max){
		$already = count($this->f_table);
		for($i = $already; $i <= $max; $i++){
			$this->f_table[$i] = $this->f_table[$i-1] * $i % $this->mod;
			$this->if_table[$i] = $this->if_table[$i-1] * $this->binPow($i, $this->mod-2) % $this->mod;
		}
	}

	// $xの$n乗を2進数で高速に計算する
	// これを単体で利用する場合、コンストラクタの$maxは低めで良い
	public function binPow($x, $n){
		$ans = 1;
		$bin = decbin($n);
		$cur_pos = strlen($bin) -1;
		while ($cur_pos >= 0) {
			if ($bin[$cur_pos] == '1') {
				$ans = ($ans * $x) % $this->mod;
			}
			$x = ($x * $x) % $this->mod;
			--$cur_pos;
		}
		return $ans;
	}
}


<?php

const MOD = 10 ** 9 + 7;

fscanf(STDIN, "%d%d%d%d", $r_1, $c_1, $r_2, $c_2);

$factorials = [1, 1];
$inv_factorials = [1, 1];
$inv_numbers = [null, 1];
for ($i = 2; $i <= $r_2 + $c_2 + 2; ++$i) {
    $factorials[$i] = $factorials[$i - 1] * $i % MOD;
    $inv_numbers[$i] = MOD - $inv_numbers[MOD % $i] * intdiv(MOD, $i) % MOD;
    $inv_factorials[$i] = $inv_factorials[$i - 1] * $inv_numbers[$i] % MOD;
}

echo frc($r_2 + 1, $c_2 + 1) - frc($r_1, $c_2 + 1) - frc($r_2 + 1, $c_1) + frc($r_1, $c_1);

function frc(int $r, int $c): int
{
    global $factorials;
    global $inv_factorials;

    return ($factorials[$r + $c] * $inv_factorials[$r]) % MOD * $inv_factorials[$c] % MOD;
}

Score : 600 points

Problem Statement

Snuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction.

Let us define a function f(r, c) as follows:

f(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)

Given are integers r_1, r_2, c_1, and c_2.
Find the sum of f(i, j) over all pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute this value modulo (10^9+7).

Constraints

1 ≤ r_1 ≤ r_2 ≤ 10^6

1 ≤ c_1 ≤ c_2 ≤ 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

r_1 c_1 r_2 c_2

Output

Print the sum of f(i, j) modulo (10^9+7).

Sample Input 1

1 1 2 2

Sample Output 1

14

For example, there are two paths from the point (0, 0) to the point (1, 1): (0,0) → (0,1) → (1,1) and (0,0) → (1,0) → (1,1), so f(1,1)=2.

Similarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.

Sample Input 2

314 159 2653 589

Sample Output 2

602215194


$input = explode(' ', fgets(STDIN));
$lifePoint = $input[0];
$attackPoint = $input[1];
$attackCount = 0;

while($lifePoint > 0) {
  $lifePoint = ($lifePoint - $attackPoint);
  $attackCount++;
}
echo $attackCount . PHP_EOL;

Score : 100 points

Problem Statement

Serval is fighting with a monster.

The health of the monster is H.

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

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

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

Constraints

1 \leq H \leq 10^4

1 \leq A \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H A

Output

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

Sample Input 1

10 4

Sample Output 1

3

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

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

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

Thus, Serval needs to make three attacks to win.

Sample Input 2

1 10000

Sample Output 2

1

Sample Input 3

10000 1

Sample Output 3

10000


<?php
  fscanf(STDIN,"%d%d",$h,$n);
 $a_li = explode(" ",trim(fgets(STDIN)));
 foreach($a_li as $a){
   $h -= $a;
 }

if($h<=0){
  echo "Yes";
}else{
  echo "No";
}

Score : 200 points

Problem Statement

Raccoon is fighting with a monster.

The health of the monster is H.

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

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

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

Constraints

1 \leq H \leq 10^9

1 \leq N \leq 10^5

1 \leq A_i \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H N
A_1 A_2 ... A_N

Output

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

Sample Input 1

10 3
4 5 6

Sample Output 1

Yes

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

Sample Input 2

20 3
4 5 6

Sample Output 2

No

Sample Input 3

210 5
31 41 59 26 53

Sample Output 3

Yes

Sample Input 4

211 5
31 41 59 26 53

Sample Output 4

No


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

rsort($inputs);
$damages = array_slice($inputs, 0, $n);
$total = array_sum($damages);
//var_dump([$inputs, $damages, $total]);

if ($h <= $total) {
    echo "YES";
} else {
    echo "NO";
}


<?php
fscanf(STDIN, '%f', $life);

function attack($hp) {
    if ($hp <= 1) {
        return 1;
    }
    return 1 + attack(floor($hp/2)) * 2;
}

echo attack($life);

Score : 400 points

Problem Statement

Caracal is fighting with a monster.

The health of the monster is H.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

If the monster's health is 1, it drops to 0.

If the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \lfloor X/2 \rfloor.

(\lfloor r \rfloor denotes the greatest integer not exceeding r.)

Caracal wins when the healths of all existing monsters become 0 or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

1 \leq H \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H

Output

Find the minimum number of attacks Caracal needs to make before winning.

Sample Input 1

2

Sample Output 1

3

When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of 1.

Then, Caracal can attack each of these new monsters once and win with a total of three attacks.

Sample Input 2

4

Sample Output 2

7

Sample Input 3

1000000000000

Sample Output 3

1099511627775


<?php
    $H = trim(fgets(STDIN));
    function f($h){
        if($h == 1) return 1;
        return f(floor($h/2))*2+1;
    }
    echo f($H);
?>


Score : 500 points

Problem Statement

Ibis is fighting with a monster.

The health of the monster is H.

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

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

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

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

Constraints

1 \leq H \leq 10^4

1 \leq N \leq 10^3

1 \leq A_i \leq 10^4

1 \leq B_i \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H N
A_1 B_1
:
A_N B_N

Output

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

Sample Input 1

9 3
8 3
4 2
2 1

Sample Output 1

4

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

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

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

Sample Input 2

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

Sample Output 2

100

It is optimal to cast the first spell 100 times.

Sample Input 3

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

Sample Output 3

139815


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

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}


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

If($a == $b) {
  echo 'Yes';
} else {
  echo 'No';
}

Score : 100 points

Problem Statement

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

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

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

Determine whether Takahashi's submission gets an AC.

Constraints

1 \leq N \leq 100

0 \leq M \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

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

Sample Input 1

3 3

Sample Output 1

Yes

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

Sample Input 2

3 2

Sample Output 2

No

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

Sample Input 3

1 1

Sample Output 3

Yes


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


<?php
// Your code here!

$inputList = explode(' ', fgets(STDIN));
echo $inputList[0] === $inputList[1] ? 'Yes' : 'No';


<?php

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

echo $a[0] === $a[1]? 'Yes': 'No';


<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$x = trim(fgets($handle));
$a=explode(' ',$x);
if($a[0]-$a[1]==0)
{
    echo "Yes";
}else
    echo "No";
?>


Score : 200 points

Problem Statement

Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?

Constraints

1 \leq a \leq 9

1 \leq b \leq 9

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

Print the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)

Sample Input 1

4 3

Sample Output 1

3333

We have two strings 444 and 3333. Between them, 3333 is the lexicographically smaller.

Sample Input 2

7 7

Sample Output 2

7777777


<?php
  fscanf(STDIN, "%d %d", $a, $b);
if($a == $b || $a > $b) {
  echo str_repeat($b, $a);
} else {
  echo str_repeat($a, $b);
}


<?php
  function fc($arg1,$arg2) {
  	$res = "";
  	for($n=0;$n<=$arg2;$n++) {
      $res = $res.$arg1;
    }
  	return $res;
}

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

	$str1 = "a" . fc($a,$b);
	$str2 = "a" .  fc($b,$a);

  if($str1 > $str2) {
    $res = $str2;
  } elseif($str2 > $str1) {
    $res = $str1;
  } else {
    $res = $str1;
  }

	print substr($res,2,strlen($res));

?>


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

  $count = 0;
  foreach ($exploded_numbers as $key => $val) {
    if ($key-1 >= 0) {
      for ($i=0; $i<=$key-1; $i++) {
          if ($val > $exploded_numbers[$i]) {
            continue 2;
          }
      }
      $count++;
    } else {
      $count++;
    }
  }
echo $count;

Score : 300 points

Problem Statement

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

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

Constraints

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

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
P_1 ... P_N

Output

Print the number of integers i that satisfy the condition.

Sample Input 1

5
4 2 5 1 3

Sample Output 1

3

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

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

Sample Input 2

4
4 3 2 1

Sample Output 2

4

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

Sample Input 3

6
1 2 3 4 5 6

Sample Output 3

1

Only i=1 satisfies the condition.

Sample Input 4

8
5 7 4 2 6 8 1 3

Sample Output 4

4

Sample Input 5

1
1

Sample Output 5

1


<?php

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

$count = 0;
$min = null;
for ($i=0; $i < $n; $i++) {
  if ($min == null || $min > $array[$i]) {
    $min = $array[$i];
  }
  if ($array[$i] <= $min) {
    $count++;
  }
}

echo $count;


<?php

$n = (int) trim(fgets(STDIN));

$a = $b = [];
for ($i = 1; $i <= $n; $i++) {
    $target = (string)$i;

    $last = $target[mb_strlen($target) - 1];
    if ($last === '0') {
        continue;
    }

    $a[] = "$target[0]$last";
    $b[] = "$last$target[0]";
}

$valuesA = array_count_values($a);
$valuesB = array_count_values($b);

$ans = 0;

foreach ($valuesA as $k => $v) {
    if (isset($valuesB[$k])) {
        $ans += $v * $valuesB[$k];
    }
}

echo $ans;

Score : 400 points

Problem Statement

Given is a positive integer N.

Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:

When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Constraints

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

25

Sample Output 1

17

The following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).

Sample Input 2

1

Sample Output 2

1

Sample Input 3

100

Sample Output 3

108

Sample Input 4

2020

Sample Output 4

40812

Sample Input 5

200000

Sample Output 5

400000008


<?php
define('MOD', 10 ** 9 + 7);
list($n) = ints();
$primes = primesArr((int) sqrt(10 ** 6) + 1);
$a = ints();
$lcm = $a[0];
for ($i = 0; $i < $n; ++$i) {
    $pfs[$i] = primeFactorization($a[$i]);
    foreach ($pfs[$i] as $k => $v) {
        if (isset($cnt[$k])) $cnt[$k] = max($cnt[$k], $v);
        else $cnt[$k] = $v;
    }
}
$ans = 0;
for ($i = 0; $i < $n; ++$i) {
    $t = 1;
    foreach ($cnt as $k => $v)
        $t = modMul($t, modPow($k, $v - ($pfs[$i][$k] ?? 0)));
    $ans = modAdd($ans, $t);
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

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

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

// 最小公倍数（2つ）
function lcm($m, $n)
{
    return (int) ($m / gcd($m, $n) * $n); // オーバーフローしないように先に割り算
}

// 最小公倍数（3つ以上）
function lcmAll($arr)
{
    $lcm = array_pop($arr);
    foreach ($arr as $a) {
        $lcm = lcm($lcm, $a);
    }
    return $lcm;
}
// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

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

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

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

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

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return modMul($n, modFac($n - 1));
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return modMul(nPr($n, $r - 1), $n - $r + 1);
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modDiv(nPr($n, $r), modFac($r));
}

// 階乗、逆元を前処理
function init($n)
{
    global $fact, $ifact;
    $fact[0] = 1;
    for ($i = 1; $i <= $n; ++$i) $fact[$i] = modMul($fact[$i - 1], $i);
    $ifact[$n] = modDiv(1, $fact[$n]);
    for ($i = $n; $i >= 1; --$i)
        $ifact[$i - 1] = modMul($ifact[$i], $i);
}

// 順列（前処理）
function nPr2($n, $r)
{
    global $fact, $ifact;
    return modMul($fact[$n], $ifact[$n - $r]);
}

// 組み合わせ（前処理）
function nCr2($n, $r)
{
    global $fact, $ifact;
    return modMul(modMul($fact[$n], $ifact[$r]), $ifact[$n - $r]);
}
/**
 * 素数列挙（エラトステネスのふるい）
 * $max以下の素数を格納した配列を返す
 */
function primesArr($max)
{
    $arr = array_fill(2, $max - 1, true);
    $rmax = (int) floor(sqrt($max));
    for ($i = 2; $i <= $rmax; $i++) {
        if (!isset($arr[$i])) continue;
        for ($j = 2 * $i; $j <= $max; $j += $i) {
            unset($arr[$j]);
        }
    }
    return array_keys($arr);
}

/**
 * 素数判定（エラトステネスのふるい）
 * $max以下の整数が素数かどうかboolを格納した配列を返す
 */
function isPrimeArr($max)
{
    $arr = array_fill(0, $max + 1, true);
    $arr[0]  = $arr[1] = false;
    $rmax = (int) floor(sqrt($max));
    for ($i = 2; $i <= $rmax; $i++) {
        for ($j = 2 * $i; $j <= $max; $j += $i) {
            $arr[$j] = false;
        }
    }
    return $arr;
}

// 素因数分解（エラトステネスのふるい）
// インデックスに素数、値に数を格納した配列を返す
// （1は素数ではないので含まない）
function primeFactorization($n)
{
    global $primes;

    $res = [];
    if ($n === 1) return $res;

    if (is_null($primes)) $primes = primesArr((int) sqrt($n) + 1);

    foreach ($primes as $prime) {
        while ($n % $prime === 0) {
            if (isset($res[$prime])) {
                $res[$prime]++;
            } else {
                $res[$prime] = 1;
            }
            $n /= $prime;
        }
    }

    if ($n > 1) {
        if (isset($res[$n])) {
            $res[$n]++;
        } else {
            $res[$n] = 1;
        }
    }

    return $res;
}

// 素数列挙（試し割り）
function primes($max)
{
    $arr = [];
    for ($i = 2; $i <= $max; $i++) {
        if (isPrime($i)) $arr[] = $i;
    }
    return $arr;
}

// 素数判定（試し割り）
function isPrime($n)
{
    if ($n === 1) return false;
    $rmax = (int) floor(sqrt($n));
    for ($i = 2; $i <= $rmax; $i++) {
        if ($n % $i === 0) return false;
    }
    return true;
}

// 約数列挙
function divisors($max)
{
    $arr = [];
    $rmax = (int) floor(sqrt($max));
    for ($i = 1; $i <= $rmax; $i++) {
        if ($max % $i === 0) {
            $arr[] = $i;
            $arr[] = $max / $i;
        }
    }
    sort($arr);
    return array_unique($arr);
}

Score : 500 points

Problem Statement

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

Consider positive integers B_1, ..., B_N that satisfy the following condition.

Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.

Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.

Since the answer can be enormous, print the sum modulo (10^9 +7).

Constraints

1 \leq N \leq 10^4

1 \leq A_i \leq 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the minimum possible value of B_1 + ... + B_N for B_1,...,B_N that satisfy the condition, modulo (10^9 +7).

Sample Input 1

3
2 3 4

Sample Output 1

13

Let B_1=6, B_2=4, and B_3=3, and the condition will be satisfied.

Sample Input 2

5
12 12 12 12 12

Sample Output 2

5

We can let all B_i be 1.

Sample Input 3

3
1000000 999999 999998

Sample Output 3

996989508

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


<?php
  $mod = pow(10, 9) + 7;
  function gcd($a, $b) {
    if ($b > $a) list($a, $b) = [$b, $a];

      while($b > 0) {
        $tb = $b;
          $b = $a % $b;
          $a = $tb;
      }
      return $a;
  }

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

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

  $gcd = 1;
  for ($i = 0; $i < $n; $i++) {
    $gcd = lcm($gcd, $ne[$i]);
  }
  $sum = 0;
  for ($i = 0; $i < $n; $i++) {
    $sum += ($gcd / $ne[$i]);
      $sum = $sum % $mod;
  }
echo $sum;


<?php
fscanf(STDIN, '%d', $H);
fscanf(STDIN, '%d', $W);
fscanf(STDIN, '%d', $N);
echo ceil($N / max($H, $W));

Score : 100 points

Problem Statement

We have a grid with H rows and W columns, where all the squares are initially white.

You will perform some number of painting operations on the grid.
In one operation, you can do one of the following two actions:

Choose one row, then paint all the squares in that row black.

Choose one column, then paint all the squares in that column black.

At least how many operations do you need in order to have N or more black squares in the grid?
It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.

Constraints

1 \leq H \leq 100

1 \leq W \leq 100

1 \leq N \leq H \times W

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H
W
N

Output

Print the minimum number of operations needed.

Sample Input 1

3
7
10

Sample Output 1

2

You can have 14 black squares in the grid by performing the "row" operation twice, on different rows.

Sample Input 2

14
12
112

Sample Output 2

8

Sample Input 3

2
100
200

Sample Output 3

2


Score : 200 points

Problem Statement

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

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

Find the maximum number of robots that we can keep.

Constraints

1 \leq N \leq 100,000

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

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

If i \neq j, X_i \neq X_j.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 L_1
X_2 L_2
\vdots
X_N L_N

Output

Print the maximum number of robots that we can keep.

Sample Input 1

4
2 4
4 3
9 3
100 5

Sample Output 1

3

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

Sample Input 2

2
8 20
1 10

Sample Output 2

1

Sample Input 3

5
10 1
2 1
4 1
6 1
8 1

Sample Output 3

5


<?php
$n = int();
for($i = 0; $i < $n; $i++){
    list($x, $l) = ints();
    $a[] = $x-$l;
    $b[] = $x+$l;
}
$max = - 10**10;
$count = 0;
array_multisort($b, $a);
for($i = 0; $i < $n; $i++){
    if($a[$i] >= $max){
        $count++;
        $max = $b[$i];
    }
}
echo $count;

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}


<?php
$N = intval(trim(fgets(STDIN)));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$B = array_map("intval", explode(" ", trim(fgets(STDIN))));
$dp = array_fill(0, 1<<$N, array_fill(0,51,PHP_INT_MAX));
$dp[0][0] = 0;
for($bit = 0, $NN = 1<<$N; $bit < $NN; ++$bit){
    $con = countBits($bit);
    $ords = [];
    $iter = $con;
    for($i = 0; $i < $N; ++$i)
        if(!($bit & (1<<$i)))
            $ords[$i] = $iter++;
    for($s = 0; $s <= 50; ++$s){
        if($dp[$bit][$s] == PHP_INT_MAX)continue;
        foreach($ords as $p0 => $p1){
            $ns = ($p0-$con) & 1 ? $B[$p0] : $A[$p0];
            if($ns >= $s){
                $nb = $bit | (1<<$p0);
                $dp[$nb][$ns] = min($dp[$nb][$ns], $dp[$bit][$s] + abs($p1 - $con));
            }
        }
    }
}
$min = min($dp[(1<<$N)-1]);
if($min == PHP_INT_MAX){
    echo -1;
}else{
    echo $min;
}

function countBits($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}

Score : 700 points

Problem Statement

We have N cards numbered 1, 2, ..., N.
Card i (1 \leq i \leq N) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side.
Initially, these cards are arranged from left to right in the order from Card 1 to Card N, with the red numbers facing up.

Determine whether it is possible to have a non-decreasing sequence facing up from left to right (that is, for each i (1 \leq i \leq N - 1), the integer facing up on the (i+1)-th card from the left is not less than the integer facing up on the i-th card from the left) by repeating the operation below. If the answer is yes, find the minimum number of operations required to achieve it.

Choose an integer i (1 \leq i \leq N - 1).
Swap the i-th and (i+1)-th cards from the left, then flip these two cards.

Constraints

1 \leq N \leq 18

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N

Output

If it is impossible to have a non-decreasing sequence, print -1.
If it is possible, print the minimum number of operations required to achieve it.

Sample Input 1

3
3 4 3
3 2 3

Sample Output 1

1

By doing the operation once with i = 1, we have a sequence [2, 3, 3] facing up, which is non-decreasing.

Sample Input 2

2
2 1
1 2

Sample Output 2

-1

After any number of operations, we have the sequence [2, 1] facing up, which is not non-decreasing.

Sample Input 3

4
1 2 3 4
5 6 7 8

Sample Output 3

0

No operation may be required.

Sample Input 4

5
28 15 22 43 31
20 22 43 33 32

Sample Output 4

-1

Sample Input 5

5
4 46 6 38 43
33 15 18 27 37

Sample Output 5

3


<?php
$N = intval(trim(fgets(STDIN)));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$B = array_map("intval", explode(" ", trim(fgets(STDIN))));
echo solve();

function solve(){
    global $N, $A, $B;
    $dp = array_fill(0, 1<<$N, array_fill(0,51,PHP_INT_MAX));
    $dp[0][0] = 0;
    for($bit = 0, $NN = (1<<$N); $bit < $NN; ++$bit){
        $con = 0;
        for ($i = 0; $i < $N; ++$i) if ($bit & (1<<$i)) ++$con;
        $ords = [];
        $iter = $con;
        for($i = 0; $i < $N; ++$i)
            if(!($bit & (1<<$i)))
                $ords[] = [$i, $iter++];
        for($s = 0; $s<=50; $s++){
            if($dp[$bit][$s] == PHP_INT_MAX)continue;
            foreach($ords as $p){
                $ns = -1;
                if(($p[0]-$con) & 1){
                    $ns = $B[$p[0]];
                }else{
                    $ns = $A[$p[0]];
                }
                if($ns >= $s){
                    $dp[$bit | (1<<$p[0])][$ns] = min($dp[$bit|(1<<$p[0])][$ns], $dp[$bit][$s] + abs($p[1] - $con));
                }
            }
        }
    }
    $min = min($dp[(1<<$N)-1]);
    if($min == PHP_INT_MAX){
        return -1;
    }else{
        return $min;
    }
}


<?php
$N = intval(trim(fgets(STDIN)));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$B = array_map("intval", explode(" ", trim(fgets(STDIN))));
echo solve();

function solve(){
    global $N, $A, $B;
    $dp = array_fill(0, 1<<$N, array_fill(0,51,PHP_INT_MAX));
    $dp[0][0] = 0;
    for($bit = 0, $NN = (1<<$N); $bit < $NN; ++$bit){
        $con = 0;
        for ($i = 0; $i < $N; ++$i) if ($bit & (1<<$i)) ++$con;
        $ords = [];
        $iter = $con;
        for($i = 0; $i < $N; ++$i)
            if(!($bit & (1<<$i)))
                $ords[] = [$i, $iter++];
        for($s = 0; $s<=50; $s++){
            if($dp[$bit][$s] == PHP_INT_MAX)continue;
            foreach($ords as $p){
                $ns = -1;
                if(abs($p[0]-$con) % 2 == 0){
                    $ns = $A[$p[0]];
                }else{
                    $ns = $B[$p[0]];
                }
                if($ns >= $s){
                    $dp[$bit | (1<<$p[0])][$ns] = min($dp[$bit|(1<<$p[0])][$ns], $dp[$bit][$s] + abs($p[1] - $con));
                }
            }
        }
    }
    $min = min($dp[(1<<$N)-1]);
    if($min == PHP_INT_MAX){
        return -1;
    }else{
        return $min;
    }
}


<?php
fscanf(STDIN,'%s',$W);
echo(chr(ord($W)+1));
echo(\n)

 ?>

Score : 100 points

Problem Statement

Given is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order.

Constraints

C is a lowercase English letter that is not z.

Input

Input is given from Standard Input in the following format:

C

Output

Print the letter that follows C in alphabetical order.

Sample Input 1

a

Sample Output 1

b

a is followed by b.

Sample Input 2

y

Sample Output 2

z

y is followed by z.


Score : 300 points

Problem Statement

Takahashi participated in a contest on AtCoder.

The contest had N problems.

Takahashi made M submissions during the contest.

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

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

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

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

Constraints

N, M, and p_i are integers.

1 \leq N \leq 10^5

0 \leq M \leq 10^5

1 \leq p_i \leq N

S_i is AC or WA.

Input

Input is given from Standard Input in the following format:

N M
p_1 S_1
:
p_M S_M

Output

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

Sample Input 1

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

Sample Output 1

2 2

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

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

Thus, he has two correct answers and two penalties.

Sample Input 2

100000 3
7777 AC
7777 AC
7777 AC

Sample Output 2

1 0

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

Sample Input 3

6 0

Sample Output 3

0 0


<?php

list($problem_qty, $submit_num) = explode(' ', trim(fgets(STDIN)));

$correct_problem_list = [];
$penalty_counter_list = [];
$penalty_counter = 0;

for ($i = 0; $i < $submit_num; ++$i) {
    list($problem_num, $result) = explode(' ', trim(fgets(STDIN)));
    if (array_key_exists($problem_num, $correct_problem_list)) {
        continue;
    }

    if ($result === 'WA') {
        if (isset($penalty_counter_list[$problem_num])) {
            ++$penalty_counter_list[$problem_num];
        } else {
            $penalty_counter_list[$problem_num] = 1;
        }
    } elseif ($result === 'AC') {
        $correct_problem_list[$problem_num] = true;
        $penalty_counter += ($penalty_counter_list[$problem_num] ?? 0);
    }
}

echo count($correct_problem_list) . ' ' . $penalty_counter;


<?php

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

if ($m === 0) {
  echo '0 0';
  exit;
}

$ac = 0;
$wa = 0;
$result = array();
for ($i=0; $i < $m; $i++) {
  fscanf(STDIN, "%d %s", $ex['num'], $ex['result']);
  if ($ex['num'] > $n) {
    continue;
  }

  if (!isset($result[$ex['num']])) {
    $result[$ex['num']] = true;
  }

  if ($result[$ex['num']]) {
    if ($ex['result'] === 'WA') {
      $wa++;
    } elseif ($ex['result'] === 'AC') {
      $result[$ex['num']] = false;
      $ac++;
    }
  }
}

echo $ac . ' ' . $wa;


<?php
fscanf(STDIN,"%d%d",$N,$M);
$A=[];
$B=[];
$c=0;
for ($i=0; $i <$M ; $i++) {
  // code...
  fscanf(STDIN,"%d%s",$P,$S);
  if($S=="AC"){
    $A[]=$P;
  }else{
    if(in_array($P,$A)){
    }else{
      $c++;
    }
  }
}
$newA=array_unique($A);
echo count($newA);
echo " ";
echo $c;
echo "\n";
 ?>


<?php

const MAX_X = 1000;
const MAX_Y = 1000;
const COMPUTATIONAL_ERROR = 1E-9;

list($n) = explode(' ', trim(fgets(STDIN)));
$points = [];

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

$max_r = sqrt(MAX_X ** 2 + MAX_Y ** 2) / 2 + COMPUTATIONAL_ERROR;
$upper_r = $max_r;
$lower_r = 0;
$r_diff = COMPUTATIONAL_ERROR * 0.1;
while ($upper_r - $lower_r > $r_diff) {
    $radius = ($upper_r + $lower_r) / 2;
    $intersections = getIntersections($points, $radius);
    $filtered_intersections = filterIntersection($intersections, $points, $radius);
    if (empty($filtered_intersections)) {
        $lower_r = $radius;
    } else {
        $upper_r = $radius;
    }
}

echo $radius;

function getIntersections(array $points, float $radius): array
{
    $point_num = count($points);
    $intersections = [];
    for ($i = 0; $i < $point_num; ++$i) {
        for ($j = $i + 1; $j < $point_num; ++$j) {
            $x_diff = $points[$i][0] - $points[$j][0];
            $y_diff = $points[$i][1] - $points[$j][1];
            $distance = sqrt($x_diff ** 2 + $y_diff ** 2);
            if ($distance > ($radius + COMPUTATIONAL_ERROR) * 2) {
                continue;
            }

            $median = [($points[$i][0] + $points[$j][0]) / 2, ($points[$i][1] + $points[$j][1]) / 2];
            $h = sqrt($radius ** 2 - ($distance / 2) ** 2);
            if ($x_diff * $y_diff > 0) {
                $intersections[] = [$median[0] - $h * $y_diff / $distance, $median[1] + $h * $x_diff / $distance];
                $intersections[] = [$median[0] + $h * $y_diff / $distance, $median[1] - $h * $x_diff / $distance];
            } else {
                $intersections[] = [$median[0] - $h * $y_diff / $distance, $median[1] - $h * $x_diff / $distance];
                $intersections[] = [$median[0] + $h * $y_diff / $distance, $median[1] + $h * $x_diff / $distance];
            }
        }
    }

    return $intersections;
}

function filterIntersection(array $intersections, array $points, float $radius): array
{
    return array_filter($intersections, function ($intersection) use ($points, $radius) {
        foreach ($points as $point) {
            $distance = sqrt(($intersection[0] - $point[0]) ** 2 + ($intersection[1] - $point[1]) ** 2);
            if ($distance > $radius + COMPUTATIONAL_ERROR) {
                return false;
            }
        }

        return true;
    });
}

Score : 600 points

Problem Statement

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

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

Constraints

2 \leq N \leq 50

0 \leq x_i \leq 1000

0 \leq y_i \leq 1000

The given N points are all different.

The values in input are all integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

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

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

Sample Input 1

2
0 0
1 0

Sample Output 1

0.500000000000000000

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

Sample Input 2

3
0 0
0 1
1 0

Sample Output 2

0.707106781186497524

Sample Input 3

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

Sample Output 3

6.726812023536805158

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


<?php

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

echo $k * 500 >= $x ? 'Yes' : 'No';

Score : 100 points

Problem Statement

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

Constraints

1 \leq K \leq 100

1 \leq X \leq 10^5

Input

Input is given from Standard Input in the following format:

K X

Output

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

Sample Input 1

2 900

Sample Output 1

Yes

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

Sample Input 2

1 501

Sample Output 2

No

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

Sample Input 3

4 2000

Sample Output 3

Yes

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


<?php
fscanf(STDIN, "%d", $k);
fscanf(STDIN, "%d", $x);
$product = $k * 500;
if($product >= $x){
  echo 'Yes'."\m";
}else{
  echo 'No'."\m";
}


<?php

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

echo (500 * $k >= $x) ? "Yes" : "No";
echo "¥n";


Score : 200 points

Problem Statement

We have a string S of length N consisting of uppercase English letters.

How many times does ABC occur in S as contiguous subsequences (see Sample Inputs and Outputs)?

Constraints

3 \leq N \leq 50

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print number of occurrences of ABC in S as contiguous subsequences.

Sample Input 1

10
ZABCDBABCQ

Sample Output 1

2

Two contiguous subsequences of S are equal to ABC: the 2-nd through 4-th characters, and the 7-th through 9-th characters.

Sample Input 2

19
THREEONEFOURONEFIVE

Sample Output 2

0

No contiguous subsequences of S are equal to ABC.

Sample Input 3

33
ABCCABCBABCCABACBCBBABCBCBCBCABCB

Sample Output 3

5


<?php

$length=trim(fgets(STDIN));
$str=trim(fgets(STDIN));
$count=0;

for ($i=0;$i<$length-2;$i++){

    if($str[$i]=="A"&&$str[$i+1]=="B"&&$str[$i+2]=="C"){
        $count++;
    }
}
echo $count;
?>


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

  $cnt = 0;

  while(preg_match('/ABC/', $str)) {
    $cnt++;
    $str = strstr($str, 'ABC');
    $str = substr($str, 3);
  }

  echo $cnt;


<?php
// Your code here!
$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));
echo mb_substr_count($s, 'ABC');

?>


<?php
	fscanf(STDIN, "%d", $N);
	fscanf(STDIN, "%s", $S);
    $S = 'JJJJ' . $S . 'ASDASD';
    $array = explode('ABC', $S);
    echo count($array) - 1;


<?php
fscanf(STDIN, '%d %d', $n, $m);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$lcm = $a[0];
for ($i = 0; $i < $n; ++$i) {
    $lcm = lcm($lcm, $a[$i]);
    if ($lcm / $a[$i] % 2 === 0) {
        echo (0) . PHP_EOL;
        exit;
    }
}
$ans = floor((2 * $m + $lcm) / (2 * $lcm));
echo $ans . PHP_EOL;

// 最大公約数
function gcd($m, $n)
{
    if ($n > $m) list($m, $n) = [$n, $m];
    return ($m % $n === 0) ? $n : gcd($n, $m % $n);
}

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

Score : 400 points

Problem Statement

Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.

Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):

There exists a non-negative integer p such that X= a_k \times (p+0.5).

Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^9

2 \leq a_i \leq 10^9

a_i is an even number.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
a_1 a_2 ... a_N

Output

Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Sample Input 1

2 50
6 10

Sample Output 1

2

15 = 6 \times 2.5

15 = 10 \times 1.5

45 = 6 \times 7.5

45 = 10 \times 4.5

Thus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.

Sample Input 2

3 100
14 22 40

Sample Output 2

0

The answer can be 0.

Sample Input 3

5 1000000000
6 6 2 6 2

Sample Output 3

166666667


<?php
fscanf(STDIN, "%d%d", $n, $m);
$a = array_map("intval", explode(" ", trim(fgets(STDIN))));
foreach($a as $i => $dummy)$a[$i] /= 2;
$lcm = lcmAll($a);
if($lcm > $m){
    echo 0;
}else{
    echo intdiv($m, $lcm)-intdiv($m, $lcm*2);
}

//最大公約数
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]);
    }
    $lcm = min($lcm, 10**10);
    return $lcm;
}
//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}


Score : 200 points

Problem Statement

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

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

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

If they both have no cookies, do nothing.

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

Constraints

0 \leq A \leq 10^{12}

0 \leq B \leq 10^{12}

0 \leq K \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B K

Output

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

Sample Input 1

2 3 3

Sample Output 1

0 2

Takahashi will do the following:

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

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

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

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

Sample Input 2

500000000000 500000000000 1000000000000

Sample Output 2

0 0

Watch out for overflows.


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

$e = min($a, $k);
$a-=$e;
$k-=$e;
$f = min($b, $k);
$b-=$f;
echo "$a $b\n";

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


<?php
fscanf(STDIN, "%d %d", $N, $K);
fscanf(STDIN, "%d %d %d", $R, $S, $P);
fscanf(STDIN, "%s", $T);
$ans = 0;
for ($i = 0; $i < $K; $i++) {
    $prev = '';
    for ($j = $i; $j < $N; $j += $K) {
        //echo $T[$j] . " ";
        if ($prev === $T[$j]) {
            $prev = '';
        } else {
            switch($T[$j]) {
                case 'r':
                    $ans += $P;
                    break;
                case 's':
                    $ans += $R;
                    break;
                case 'p':
                    $ans += $S;
                    break;
            }
            //printf("%d\n", $ans);
            $prev = $T[$j];
        }
    }
    //echo PHP_EOL;
}
printf("%d", $ans);

Score : 400 points

Problem Statement

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

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

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

R points for winning with Rock;

S points for winning with Scissors;

P points for winning with Paper.

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

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

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

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

Notes

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

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

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

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

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

Constraints

2 \leq N \leq 10^5

1 \leq K \leq N-1

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

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

|T| = N

T consists of r, p, and s.

Input

Input is given from Standard Input in the following format:

N K
R S P
T

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

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

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

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996


<?php

  list($n, $k) = explode(' ', trim(fgets(STDIN)));
  list($r, $s, $p) = explode(' ', trim(fgets(STDIN)));
  $t = trim(fgets(STDIN));
  $w_table = [
    'r' => 'p',
    's' => 'r',
    'p' => 's',
  ];
  $p_table = [
    'r' => $r,
    's' => $s,
    'p' => $p,
  ];
$total = 0;
$before = '';
$history = '';
for ($i = 0; $i <$n; $i++) {
  $now = substr($t, $i, 1);
  if ($k <= $i) {
    $before = substr($history, ($i-$k), 1);
  }
  $win = $w_table[$now];
  if ($win !== $before) {
      $total += $p_table[$win];
      $history .= $win;
  } else {
    $history .= $now;
  }
}
echo $total . PHP_EOL;


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

$input = explode(' ', trim(fgets(STDIN)));
$r = (int)$input[0];
$s = (int)$input[1];
$p = (int)$input[2];

$t = trim(fgets(STDIN));

$counter = [
	"r" => $p,
	"s" => $r,
	"p" => $s,
];

$sum = 0;

for ($i=0; $i < $k; $i++) {
	$dup = false;
	for ($j=$i; $j < $n; $j+=$k) {
		if ($j == $i) {
			$sum += $counter[$t[$j]];
		}else{
			if ($prev != $t[$j] || $dup == true) {
				$sum += $counter[$t[$j]];
				$dup = false;
			}else{
				$dup = true;
			}
		}
		// echo $j . ": " . $t[$j] . PHP_EOL;
		// echo $sum . PHP_EOL;
		$prev = $t[$j];
	}
}
echo $sum;


Score : 500 points

Problem Statement

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

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

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

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

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

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

What is the maximum possible happiness after M handshakes?

Constraints

1 \leq N \leq 10^5

1 \leq M \leq N^2

1 \leq A_i \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_N

Output

Print the maximum possible happiness after M handshakes.

Sample Input 1

5 3
10 14 19 34 33

Sample Output 1

202

Let us say that Takahashi performs the following handshakes:

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

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

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

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

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

Sample Input 2

9 14
1 3 5 110 24 21 34 5 3

Sample Output 2

1837

Sample Input 3

9 73
67597 52981 5828 66249 75177 64141 40773 79105 16076

Sample Output 3

8128170


Score : 300 points

Problem Statement

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

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

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

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

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

Constraints

2 \leq N \leq 10^{18}

1 \leq A < B \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

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

Sample Input 1

5 2 4

Sample Output 1

1

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

Sample Input 2

5 2 3

Sample Output 2

2

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


Score : 200 points

Problem Statement

Given are strings s and t of length N each, both consisting of lowercase English letters.

Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.

Constraints

1 \leq N \leq 100

|S| = |T| = N

S and T are strings consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S T

Output

Print the string formed.

Sample Input 1

2
ip cc

Sample Output 1

icpc

Sample Input 2

8
hmhmnknk uuuuuuuu

Sample Output 2

humuhumunukunuku

Sample Input 3

5
aaaaa aaaaa

Sample Output 3

aaaaaaaaaa


<?php

$n = (int)trim(fgets(STDIN));
list($s, $t) = explode(" ", trim(fgets(STDIN)));
$sArr = str_split($s);
$tArr = str_split($t);

$str = '';
for ($i=0; $i<$n; $i++) {
    $str .= $sArr[$i].$tArr[$i];
}

echo $str."\n";


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

$s = $input[0];
$t = $input[1];

for ($i=0; $i < $n; $i++) {
	echo $s[$i];
	echo $t[$i];
}


Score : 300 points

Problem Statement

Takahashi is organizing a party.

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

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

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

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

Constraints

1 \leq A, B \leq 10^5

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

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

Sample Input 1

2 3

Sample Output 1

6

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

Sample Input 2

123 456

Sample Output 2

18696

Sample Input 3

100000 99999

Sample Output 3

9999900000


<?php
fscanf(STDIN, "%d %d", $a, $b);
$loop = 1;
$multi = 1;
while($loop === 1) {
    if(($a * $multi) % $b === 0) {
    $loop = 0;
    break;
    } else {
        $multi++;
    }
}
echo $multi * $a;


<?php
$answer = -1;
$tmp = 1;
fscanf(STDIN, '%d', $cnt);
$bricks = explode(' ', trim(fgets(STDIN)));
for ($i=0; $i < $cnt; $i++) {
    $target = min($tmp, $i + 1);
    if ($bricks[$i] == $target) {
        $tmp++;
        $answer++;
    }
    $bricks = array_values($bricks);
}

echo ($answer > -1 ? $cnt - $answer - 1 : -1) . "\n";

Score : 400 points

Problem Statement

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

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

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

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

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

Constraints

All values in input are integers.

1 \leq N \leq 200000

1 \leq a_i \leq N

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

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

Sample Input 1

3
2 1 2

Sample Output 1

1

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

Sample Input 2

3
2 2 2

Sample Output 2

-1

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

Sample Input 3

10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

7

Sample Input 4

1
1

Sample Output 4

0

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


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

function f($n) {
    if ($n < 2) return 1;
    return $n * f($n-2);
}

$m = str_split(f($n));
$cnt = 0;

for ($i=count($m)-1; 0<$i; $i--) {
    if ($m[$i] != 0) {
        break;
    }
    $cnt++;
}

echo $cnt."\n";

Score : 500 points

Problem Statement

For an integer n not less than 0, let us define f(n) as follows:

f(n) = 1 (if n < 2)

f(n) = n f(n-2) (if n \geq 2)

Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).

Constraints

0 \leq N \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of trailing zeros in the decimal notation of f(N).

Sample Input 1

12

Sample Output 1

1

f(12) = 12 × 10 × 8 × 6 × 4 × 2 = 46080, which has one trailing zero.

Sample Input 2

5

Sample Output 2

0

f(5) = 5 × 3 × 1 = 15, which has no trailing zeros.

Sample Input 3

1000000000000000000

Sample Output 3

124999999999999995


<?php

fscanf(STDIN, "%d", $n);
$k = 1;
$ans = [];
$sum = 0;
if ($n % 2 == 1) {
    echo 0;
    exit;
}
for ($i = 10; $i <= $n; $i *= 5) {
    $ans[] = intdiv($n, $i);
}
//rsort($ans);
//$count = count($ans);
//$buff = 0;
//foreach($ans as $value){
//    $sum += $value - $buff) * $count;
//}

echo array_sum($ans);


<?php

$a = fgets(STDIN);
$b = fgets(STDIN);
$c = fgets(STDIN);
if($a+$b+$c<=22)
    echo "bust";
else
    echo "win";
?>

Score : 100 points

Problem Statement

Given are three integers A_1, A_2, and A_3.

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

Constraints

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A_1 A_2 A_3

Output

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

Sample Input 1

5 7 9

Sample Output 1

win

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

Sample Input 2

13 7 2

Sample Output 2

bust

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


<?php
$nums = explode(' ', trim(fgets(STDIN)));
$ans = 0;
foreach($nums as $num){
$ans += $num;
}
if($ans >= 22){
echo 'bust';
}elseif($ans <= 21){
echo 'win';
}
?>


Score : 200 points

Problem Statement

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

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

Constraints

S is a string consisting of lowercase English letters.

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

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

redcoder

Sample Output 1

1

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

Sample Input 2

vvvvvv

Sample Output 2

0

We might need no hugs at all.

Sample Input 3

abcdabc

Sample Output 3

2


<?php
    $line = trim(fgets(STDIN));
    $arr1 = str_split($line);
    $arr2 = $arr1;
    krsort($arr1);
    foreach ($arr1 as $key => $val) {
        $arr3[] = $val;
    }
    $cnt = 0;
    for ($i=0;$i<count($arr1);$i++){
        if($arr2[$i] != $arr3[$i]){
            $cnt++;
        }
    }
    echo $cnt/2;


<?php

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

$first_half = array_slice($s, 0, floor(count($s) / 2));
$last_half = array_slice($s, ceil(count($s) / 2));

echo count(array_diff_assoc(array_reverse($last_half), $first_half));


Score : 300 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

1 \leq N \leq 15

0 \leq A_i \leq N - 1

1 \leq x_{ij} \leq N

x_{ij} \neq i

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

y_{ij} = 0, 1

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3
1
2 1
1
1 1
1
2 0

Sample Output 1

2

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

Sample Input 2

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

Sample Output 2

0

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

Sample Input 3

2
1
2 0
1
1 0

Sample Output 3

1


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

$comments = [];
for ($i=1; $i <= $n; $i++) {
	$comments[$i] = [];
	$a = (int)trim(fgets(STDIN));
	for ($j=0; $j < $a; $j++) {
		$input = explode(' ', trim(fgets(STDIN)));
		$x = (int)$input[0];
		$y = (int)$input[1];
		$comments[$i][] = [$x, $y];
	}
}
// 人nが正直者だとして、矛盾しない人々の集合をそれぞれ求める
$persons = [];
$honset_sums = [];
for ($i=1; $i <= $n; $i++) {

	$persons[$i] = [];
	$honset_sums[$i] = 0;
	$my_honest_cmt = 0;

	$list = [];
	foreach ($comments[$i] as $cmt) {
		$list[$cmt[0]] = $cmt[1];
		$my_honest_cmt += $cmt[1];
	}
	for ($j=1; $j <= $n; $j++) {
		$no_diff = true;
		if ($i == $j || (isset($list[$j]) && $list[$j] == 0)) {
			continue;
		}
		foreach ($comments[$j] as $cmt) {
			if (isset($list[$cmt[0]]) && $list[$cmt[0]] != $cmt[1]) {
				$no_diff = false;
				break;
			}
		}
		if ($no_diff) {
			$persons[$i][] = $j;
			foreach ($comments[$j] as $cmt) {
				$list[$cmt[0]] = $cmt[1];
			}
		}
	}
	if ((isset($list[$i]) && $list[$i] == 0) || count($persons[$i]) == 0) {
		$honset_sums[$i] = 0;
		//正直者に関する証言がない場合、自分は正直者として扱う
		if ($my_honest_cmt == 0) {
			$honset_sums[$i] = 1;
		}
	} else {
		foreach ($list as $k => $v) {
			// echo $i . ": " . $k . " => " . $v . PHP_EOL;
			$honset_sums[$i] += $v;
		}
		if (!isset($list[$i])) {
			$honset_sums[$i] += 1;
		}
	}
	// var_dump($persons[$i]);
	// var_dump($list);
}

echo max($honset_sums);


Score : 400 points

Problem Statement

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

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

What is \mbox{ XOR }?

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

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

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

Constraints

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

0 \leq A_i < 2^{60}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

3
1 2 3

Sample Output 1

6

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

Sample Input 2

10
3 1 4 1 5 9 2 6 5 3

Sample Output 2

237

Sample Input 3

10
3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820

Sample Output 3

103715602

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


Score: 100 points

Problem Statement

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

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

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

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

Constraints

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

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

Input

Input is given from Standard Input in the following format:

M_1 D_1
M_2 D_2

Output

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

Sample Input 1

11 16
11 17

Sample Output 1

0

November 16 is not the last day of a month.

Sample Input 2

11 30
12 1

Sample Output 2

1

November 30 is the last day of November.


Score: 500 points

Problem Statement

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

The person numbered i says:

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

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

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

Constraints

1 \leq N \leq 100000

0 \leq A_i \leq N-1

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_N

Output

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

Sample Input 1

6
0 1 2 3 4 5

Sample Output 1

3

We have three possible combinations, as follows:

Red, Red, Red, Red, Red, Red

Blue, Blue, Blue, Blue, Blue, Blue

Green, Green, Green, Green, Green, Green

Sample Input 2

3
0 0 0

Sample Output 2

6

Sample Input 3

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

Sample Output 3

115295190


Score : 100 points

Problem Statement

Given is a string S representing the day of the week today.

S is SUN, MON, TUE, WED, THU, FRI, or SAT, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.

After how many days is the next Sunday (tomorrow or later)?

Constraints

S is SUN, MON, TUE, WED, THU, FRI, or SAT.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of days before the next Sunday.

Sample Input 1

SAT

Sample Output 1

1

It is Saturday today, and tomorrow will be Sunday.

Sample Input 2

SUN

Sample Output 2

7

It is Sunday today, and seven days later, it will be Sunday again.


Score : 200 points

Problem Statement

We have a string S consisting of uppercase English letters. Additionally, an integer N will be given.

Shift each character of S by N in alphabetical order (see below), and print the resulting string.

We assume that A follows Z. For example, shifting A by 2 results in C (A \to B \to C), and shifting Y by 3 results in B (Y \to Z \to A \to B).

Constraints

0 \leq N \leq 26

1 \leq |S| \leq 10^4

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the string resulting from shifting each character of S by N in alphabetical order.

Sample Input 1

2
ABCXYZ

Sample Output 1

CDEZAB

Note that A follows Z.

Sample Input 2

0
ABCXYZ

Sample Output 2

ABCXYZ

Sample Input 3

13
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Sample Output 3

NOPQRSTUVWXYZABCDEFGHIJKLM


<?php

fscanf(STDIN, "%d", $num);
$array = str_split(trim(fgets(STDIN)));

$moji = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$mojiArray = str_split($moji);

$newArray = array();
foreach ($array as $k => $v) {
  $mojiNum = array_search($v, $mojiArray) + $num;

  if ($mojiNum >= 26 ) $mojiNum -= 26;

  $newArray[] = $mojiArray[$mojiNum];
}

foreach ($newArray as $key => $value) {
  echo $value;
}


<?php
fscanf(STDIN, "%d", $N);
$A = explode(" ", trim(fgets(STDIN)));
$total = array_sum($A);
$l = 0;
$ans = PHP_INT_MAX;
for ($i = 0; $i < $N; $i++) {
    $l += $A[$i];
    $ans = min($ans, abs($l - $total + $l));
}
echo $ans;

Score: 200 points

Problem Statement

Takahashi, who works at DISCO, is standing before an iron bar.
The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.

Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length.
However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:

Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).

Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.

Find the minimum amount of money needed before cutting the bar into two parts with the same length.

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 2020202020

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_N

Output

Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.

Sample Input 1

3
2 4 3

Sample Output 1

3

The initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi can cut the bar equally after doing the following operations for 3 yen:

Shrink the second section from the left. The lengths of the sections are now [2, 3, 3].

Shrink the first section from the left. The lengths of the sections are now [1, 3, 3].

Shrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.

Sample Input 2

12
100 104 102 105 103 103 101 105 104 102 104 101

Sample Output 2

0


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

$tot = array_sum($A);
$half = intdiv($tot,2);
$amari = 0;
if ($half *2 != $tot) $amari=1;

$sum = 0;
$left = 0;
$right = 0;
for($i=0;$i<$N;$i++) {
  $sum +=$A[$i];
  if ($half <= $sum) {
    $prev = $sum - $A[$i];
    if ($tot == $sum || abs($half-$prev)<abs($half-$sum)) {
      //最後まで行ったらひとつ前のから
      //ひとつ前のほうがhalfとの差が少ないときは？
      $sum-=$A[$i];
    }
    //半分超えてしまった
    $left=abs($sum-$half);
    break;
  }
}
printf("%d\n",$left+abs(($tot-$sum)-$half));


<?php
list($h, $w, $k) = ints();
$cnt = 1;
for ($i = 0; $i < $h; ++$i) {
    list($s) = strs();
    $t[$i] = [];
    $pos = 0;
    $npos = strpos($s, '#', $pos);
    while ($npos !== false) {
        $t[$i] = array_merge($t[$i], array_fill(0, $npos - $pos + 1, $cnt));
        $pos = $npos + 1;
        $npos = strpos($s, '#', $pos);
        if ($npos === false) $t[$i] = array_merge($t[$i], array_fill(0, $w - 1 - $pos + 1, $cnt));
        $cnt++;
    }
}
for ($i = 0; $i < $h - 1; ++$i)
    if (count($t[$i + 1]) === 0) $t[$i + 1] = $t[$i];
for ($i = $h - 1; $i >= 1; --$i)
    if (count($t[$i - 1]) === 0) $t[$i - 1] = $t[$i];
for ($i = 0; $i < $h; ++$i) echo implode(' ', $t[$i]) . PHP_EOL;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

Score: 400 points

Problem Statement

Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.

The cake has H - 1 horizontal notches and W - 1 vertical notches, which divide the cake into H \times W equal sections. K of these sections has a strawberry on top of each of them.

The positions of the strawberries are given to you as H \times W characters s_{i, j} (1 \leq i \leq H, 1 \leq j \leq W). If s_{i, j} is #, the section at the i-th row from the top and the j-th column from the left contains a strawberry; if s_{i, j} is ., the section does not contain one. There are exactly K occurrences of #s.

Takahashi wants to cut this cake into K pieces and serve them to the contestants. Each of these pieces must satisfy the following conditions:

Has a rectangular shape.

Contains exactly one strawberry.

One possible way to cut the cake is shown below:

Find one way to cut the cake and satisfy the condition. We can show that this is always possible, regardless of the number and positions of the strawberries.

Constraints

1 \leq H \leq 300

1 \leq W \leq 300

1 \leq K \leq H \times W

s_{i, j} is # or ..

There are exactly K occurrences of # in s.

Input

Input is given from Standard Input in the following format:

H W K
s_{1, 1} s_{1, 2} \cdots s_{1, W}
s_{2, 1} s_{2, 2} \cdots s_{2, W}
:
s_{H, 1} s_{H, 2} \cdots s_{H, W}

Output

Assign the numbers 1, 2, 3, \dots, K to the K pieces obtained after the cut, in any order. Then, let a_{i, j} be the number representing the piece containing the section at the i-th row from the top and the j-th column from the left of the cake. Output should be in the following format:

a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}
a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}
:
a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}

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

Sample Input 1

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

Sample Output 1

1 2 2
1 3 4
5 5 4

One way to cut this cake is shown below:

Sample Input 2

3 7 7
#...#.#
..#...#
.#..#..

Sample Output 2

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

One way to cut this cake is shown below:

Sample Input 3

13 21 106
.....................
.####.####.####.####.
..#.#..#.#.#....#....
..#.#..#.#.#....#....
..#.#..#.#.#....#....
.####.####.####.####.
.....................
.####.####.####.####.
....#.#..#....#.#..#.
.####.#..#.####.#..#.
.#....#..#.#....#..#.
.####.####.####.####.
.....................

Sample Output 3

12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50
12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50
12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50
12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72
12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83
16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21
16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21
32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85
32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74
14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63
25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52
36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41
36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41


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 intval($str) . PHP_EOL;
    }
}

$sc = new Scanner();
$n = $sc->nextInt();

$circle = 3;
$circle2 = $n * $n * 3;
$res = $circle2/$circle;

out::println($res);

Score : 100 points

Problem Statement

Given is an integer r.

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

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

Constraints

1 \leq r \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

r

Output

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

Sample Input 1

2

Sample Output 1

4

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

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

Sample Input 2

100

Sample Output 2

10000


$r = fgets(STDIN);
echo ($r * $r) . "\n";


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

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


<?php
    fscanf(STDIN, "%d", $n);
    fscanf(STDIN, "%s", $s);
    if($n % 2 === 0){
        $t = substr($s, 0, $n/2);
        if($t.$t === $s){
            echo 'Yes';
        }else{
            echo 'No';
        }
    }else{
        echo 'No';
    }
?>

Score : 200 points

Problem Statement

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

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

Constraints

1 \leq N \leq 100

S consists of lowercase English letters.

|S| = N

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Sample Input 1

6
abcabc

Sample Output 1

Yes

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

Sample Input 2

6
abcadc

Sample Output 2

No

Sample Input 3

1
z

Sample Output 3

No