For a positive integer n let's define a function f:f(n) =  - 1 + 2 - 3 + .. + ( - 1)nn Your task is to calculate f(n) for a given integer n.

The single line contains the positive integer n (1 ≤ n ≤ 1015).

Notef(4) =  - 1 + 2 - 3 + 4 = 2f(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3

<?php
$a = trim(fgets(STDIN));
$b = bcmod($a, 2);
$c = floor(bcdiv($a, 2));
if($b == 0)
{
    print bcdiv($a, 2);
}
else
{
    print "-" . bcsub(bcdiv($a, 2), -1);
}
?>

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

	if (bcmod($n, "2")!=0) {
		echo "-";
		echo bcadd(bcdiv($n,2,0), "1");
	}else{
		echo bcdiv($n,"2",0);
	}
?>

<?php
    fscanf(STDIN,"%s",$n);
    if (bcmod($n, '2') != 0) {
        echo '-';
        echo bcadd(bcdiv($n, 2, 0), '1', 0);
    }
    else
        echo bcdiv($n, '2', 0);

<?php
$n = trim(fgets(STDIN));
if (bcmod($n,'2')!=0)echo '-'.bcdiv(bcadd($n,'1'),'2');
else echo bcdiv($n,'2');

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

if(bcmod($n,2)==0)
	echo bcdiv($n, 2);
else
echo "-".bcdiv(bcadd($n,1), 2);

<?php
$n = trim(fgets(STDIN));
$ans = (bcmod($n, 2) != 0 ? bcadd(bcdiv($n, -2), -1) : bcdiv($n, 2));
echo $ans;
?>

<?php
// 486A     Подсчёт функции
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$input_line = substr($input_line, 0, strlen($input_line)-2);
//list($n, $m) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$len = strlen($input_line);
$char = $input_line[$len-1];
$k = (int) $char;

if (($k % 2) == 0) {
    echo bcdiv($input_line, '2');
} else {
    for ($i=$len-1; $i >= 0 ; $i--) {
        $char = $input_line[$i];
        if ($char === '9') {
            $input_line[$i] = '0';
        } else {
            $k = (int) $char;
            $k ++;
            $input_line[$i] = (string) $k;
            break;
        }
    }
    if ($i < 0) {
        echo '-' . bcdiv('1'.$input_line, '2');
    } else {
        echo '-' . bcdiv($input_line, '2');
    }
}

?>

<?php

/**
 * @author Sunwarul Islam
 */

$n = trim(fgets(STDIN));
$lastDigit = $n[strlen($n) - 1];
if ($lastDigit % 2 == 0) {
    echo sprintf("%.0f", ($n / 2));
}
if ($lastDigit % 2 != 0) {
    echo sprintf("%.0f", (- ($n + 1) / 2));
}

echo "\n";

<?php
$a = trim(fgets(STDIN));
$b = bcmod($a, 2);
$c = floor(bcdiv($a, 2));
if($b == 0)
{
    print bcdiv($a, 2);
}
else
{
    print "-" . bcsub(bcdiv($a, 2), 1);
}
?>

<?php
$a = trim(fgets(STDIN));
$b = bcmod($a, 2);
$c = floor(bcdiv($a, 2));
if($b == 0)
{
    print bcdiv($a, 2);
}
else
{
    print bcsub($c, $a);
}
?>

<?php
$a = trim(fgets(STDIN));
$b = bcmod($a, 2);
$c = floor(bcdiv($a, 2));
if($b == 0)
{
    print bcdiv($a, 2);
}
else
{
    print "-" . ceil(bcdiv($a, 2));
}
?>

<?php
$a = trim(fgets(STDIN));
$b = $a % 2;
$c = floor($a / 2);
if($b == 0)
{
    print $a / 2;
}
else
{
    print $c - $a;
}
?>

<?php
$a = trim(fgets(STDIN));
$b = $a % 2;
if($b == 0)
{
    print $a / 2;
}
else
{
    print "-" . ceil($a / 2);
}
?>

<?php
$a = trim(fgets(STDIN));
$b = bcmod($a, 2);
if($b == 0)
{
    print bcdiv($a, 2);
}
else
{
    $c = bcdiv($a, 2);
    print "-" . ($c + 1);
}
?>

<?php
$a = trim(fgets(STDIN));
$b = bcmod($a, 2);
$c = floor(bcdiv($a, 2));
if($b == 0)
{
    print bcdiv($a, 2);
}
else
{
    print "-" . bcdiv($a, 2) - 1;
}
?>

<?php
	$input = trim(fgets(STDIN));
	echo ($input%2==0)?number_format(($input/2),16):number_format(floor($input/2*-1),16);
?>

<?php
	$input = trim(fgets(STDIN));
	echo ($input%2==0)?($input/2):($input/2*-1);
?>

<?php
	$input = trim(fgets(STDIN));
	$sum = 0;
	for($i=1;$i<$input;$i++)
	{
		$multiplier = ($i%2==1)?-1:1;
		$sum = $sum + ($multiplier * $i);
	}
	echo $sum;
?>

<?php
	$input = trim(fgets(STDIN));
	echo ($input%2==0)?($input/2):floor($input/2*-1);
?>

<?php
	$input = trim(fgets(STDIN));
	echo ($input%2==0)?sprintf('%.0f',($input/2)):sprintf('%.0f',floor($input/2*-1));
?>

<?php
    fscanf(STDIN,"%d",$n);
    if ($n % 2 != 0)
        echo '-';
    echo ceil($n / 2);

<?php
$n = fgets(STDIN);
if (($n%2)==0) echo bcdiv($n,2);
else echo bcdiv(-($n+1),2);

<?php
$n = trim(fgets(STDIN));
if (bcmod($n,2)==0) echo bcdiv($n,2);
else echo bcdiv(-($n+1),2);

<?php
$n = trim(fgets(STDIN));
if (($n%2)==0) echo bcdiv($n,2);
else echo bcdiv(-($n+1),2);

<?php
$n = trim(fgets(STDIN));
if ($n%2==0) echo ($n/2);
else echo -1*($n+1)/2;

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

if(bcmod($n,2)==0)
	echo bcdiv($n, 2);
else
echo "-".bcdiv($n+1, 2);

<?php
$str=trim(fgets(STDIN));
if($str%2==0)
{
	echo bcdiv($str,2);
}
else
    echo ceil(bcdiv($str,2,2))*(-1);

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

if($n%2==0)
	echo bcdiv($n, 2);
else
echo "-".bcdiv($n, 2)-1;

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

if($n%2==0)
	echo $n/2;
else
echo "-".ceil($n/2);

<?php
$n = trim(fgets(STDIN));
$ans = ($n % 2 == 0 ? bcdiv($n, 2) : bcadd(bcdiv($n, -2), -1));
echo $ans;
?>

<?php
$n = trim(fgets(STDIN));
$ans = ($n % 2 == 0 ? bcdiv($n, 2) : bcadd(bcdiv($n, -3), -1));
echo $ans;
?>

<?php
$n = trim(fgets(STDIN));
$ans = ($n % 2 != 0 ? bcadd(bcdiv($n, -2), -1) : bcdiv($n, 2));
echo $ans;
?>

<?php
// 486A     Подсчёт функции
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$input_line = substr($input_line, 0, strlen($input_line)-2);
//list($n, $m) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$char = substr($input_line, strlen($input_line)-1, 1);
$k = (int) $char;

$n = (int) $input_line;

if (($k % 2) == 0) {
    echo $n / 2;
} else {
    echo ($n + 1) / (-2);

}

?>

<?php

/**
 * @author Sunwarul Islam
 */

$n = trim(fgets(STDIN));

if ($n % 2 == 0) {
    echo sprintf("%.0f", ($n / 2));
}
if ($n % 2 != 0) {
    echo sprintf("%.0f", (- ($n + 1) / 2));
}

echo "\n";

<?php

/**
 * @author Sunwarul Islam
 */
error_reporting(0);
$n = fgets(STDIN);
if ($n % 2 === 0) echo sprintf("%.0f", ($n / 2));
if ($n % 2 !== 0) echo sprintf("%.0f", (- ($n + 1) / 2));

echo "\n";

<?php

/**
 * @author Sunwarul Islam
 */

$n = fgets(STDIN);
if ($n % 2 == 0) echo sprintf("%.0f", ($n / 2));
if ($n % 2 != 0) echo sprintf("%.0f", (- ($n + 1) / 2));

echo "\n";

<?php

/**
 * @author Sunwarul Islam
 */

$n = fgets(STDIN);
if ($n % 2 === 0) echo sprintf("%.0f", ($n / 2));
if ($n % 2 !== 0) echo sprintf("%.0f", (- ($n + 1) / 2));

echo "\n";


Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length d3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.  Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.

The first line of the input contains three integers d1, d2, d3 (1 ≤ d1, d2, d3 ≤ 108) — the lengths of the paths.    d1 is the length of the path connecting Patrick's house and the first shop;  d2 is the length of the path connecting Patrick's house and the second shop;  d3 is the length of the path connecting both shops.

Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.

NoteThe first sample is shown on the picture in the problem statement. One of the optimal routes is: house  first shop  second shop  house.In the second sample one of the optimal routes is: house  first shop  house  second shop  house.

<?php
fscanf(STDIN,"%s %s %s",$d1,$d2,$d3);
echo min(bcmul(2,bcadd($d1,$d2)),bcadd($d3,bcadd($d1,$d2)),bcmul(2,bcadd($d1,$d3)),bcmul(2,bcadd($d2,$d3)));


Let's denote a function $$$f(x)$$$ in such a way: we add $$$1$$$ to $$$x$$$, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example,   $$$f(599) = 6$$$: $$$599 + 1 = 600 \rightarrow 60 \rightarrow 6$$$;  $$$f(7) = 8$$$: $$$7 + 1 = 8$$$;  $$$f(9) = 1$$$: $$$9 + 1 = 10 \rightarrow 1$$$;  $$$f(10099) = 101$$$: $$$10099 + 1 = 10100 \rightarrow 1010 \rightarrow 101$$$. We say that some number $$$y$$$ is reachable from $$$x$$$ if we can apply function $$$f$$$ to $$$x$$$ some (possibly zero) times so that we get $$$y$$$ as a result. For example, $$$102$$$ is reachable from $$$10098$$$ because $$$f(f(f(10098))) = f(f(10099)) = f(101) = 102$$$; and any number is reachable from itself.You are given a number $$$n$$$; your task is to count how many different numbers are reachable from $$$n$$$.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$).

Print one integer: the number of different numbers that are reachable from $$$n$$$.

<?php
$a = trim(fgets(STDIN));
$b = 1;
$c = array($a => 1);
while(TRUE)
{
     $a = intval($a);
     $a += 1;
     while(TRUE)
     {
          $a = strval($a);
          if($a[strlen($a) - 1] == 0)
          {
               $a = substr($a, 0, -1);
          }
          else
          {
               break;
          }
     }
     if($c[$a] == 1)
     {
          break;
     }
     else
     {
          $b++;
          $c[$a] = 1;
     }
}
print $b;
?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$iCount = strlen($n) == 1 ? 9 : 10;
$bFlag = strlen($n) == 1 ? true : false;
if(!$bFlag){
    foreach (str_split($n) as $sK => $sV){
        if($sK != 0){
            $iCount += 9 - $sV;
        }
    }
}

echo $iCount;

<?php

function f($n){
	$n++;
	while($n % 10 == 0) { $n /= 10; }
	return $n;
}

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

$a = [];

$c = 0;

while($c < 10000) { $n = f($n); $a[] = $n; $c++; }

$a = array_unique($a);

if(in_array($n0, $a)) echo count($a); else echo count($a)+1;

<?php

function f($n){
	$n++;
	while($n % 10 == 0) $n /= 10;
	return $n;
}

$n = trim(fgets(STDIN));

$c = 1;

while($n > 1) { $n = f($n); $c++; }

echo $c;

<?php
    $n = trim(fgets(STDIN));
    $a = str_split($n);
    print_r($a);
    $i = 2;
    foreach ($a AS $v) {
            $i += 9 - $v;
    }
    echo $i;
?>

<?php
    $n = trim(fgets(STDIN));
    $a = str_split($n);
    $i = count($a) == 1 ? 1 : 2;
    foreach ($a AS $v) {
            $i += 9 - $v;
    }
    echo $i;
?>

<?php
    $n = trim(fgets(STDIN));
    $a = str_split($n);
    $i = 2;
    foreach ($a AS $v) {
            $i += 9 - $v;
    }
    echo $i;
?>


Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.Kolya remembers that at the beginning of the game his game-coin score was equal to n and that he have bought only some houses (for 1 234 567 game-coins each), cars (for 123 456 game-coins each) and computers (for 1 234 game-coins each).Kolya is now interested, whether he could have spent all of his initial n game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers a, b and c such that a × 1 234 567 + b × 123 456 + c × 1 234 = n?Please help Kolya answer this question.

The first line of the input contains a single integer n (1 ≤ n ≤ 109) — Kolya's initial game-coin score.

Print "YES" (without quotes) if it's possible that Kolya spent all of his initial n coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).

NoteIn the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.


We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1, 3, 2, 1} is 2.Diameter of multiset consisting of one point is 0.You are given n points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed d?

The first line contains two integers n and d (1 ≤ n ≤ 100, 0 ≤ d ≤ 100) — the amount of points and the maximum allowed diameter respectively. The second line contains n space separated integers (1 ≤ xi ≤ 100) — the coordinates of the points.

Output a single integer — the minimum number of points you have to remove.

NoteIn the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.In the second test case the diameter is equal to 0, so its is unnecessary to remove any points. In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.


Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of them to form a non-degenerate triangle.Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle with positive area.

The first line contains single integer n (3 ≤ n ≤ 105) — the number of line segments Mahmoud has. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the lengths of line segments Mahmoud has.

In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO" otherwise.

NoteFor the first example, he can use line segments with lengths 2, 4 and 5 to form a non-degenerate triangle.

<?php
	$n = trim(fgets(STDIN)) ;
	$arr = explode(" " , trim(fgets(STDIN))) ;
	$check = false;
	sort($arr) ;
	for ($i=2; $i < count($arr); $i++) {
		if($arr[$i] < $arr[$i-1] +  $arr[$i-2])
			$check = true ;
	}
	if($check)
		echo "YES\n" ;
	else
		echo "NO\n";

?>

<?php

error_reporting(0);

while($line = trim(fgets(STDIN))){

$linhas[]=$line;
if($a==1) break;
$a++;
}

$arrayValores=explode(" ",$linhas[1]);
$n=$linhas[0];

rsort($arrayValores);

$i=0;

$alvo = $arrayValores[sizeof($arrayValores) - 1];

while($i<$n) {

$max=$arrayValores[$i];
$secMax = $arrayValores[$i+1];

$arrayValores = array_slice($arrayValores,1,null,TRUE);
$a=0;

foreach($arrayValores as $valor){

	if($a==0) {$a=1; continue;}

	if(($valor+$secMax>$max)) {
		echo "YES";
		die();	}

}

$i++;

}

echo "NO";

?>

<?php
    $stdin = fopen("php://stdin", "r");
    $n = trim(fgets(STDIN));
    $arr = explode(" ", trim(fgets(STDIN)));
    fclose($stdin);

    $flag = false;

    sort($arr);

    for($i=0; $i<$n-2; $i++)
    {
        if(
            $arr[$i] + $arr[$i+1]>$arr[$i+2] &&
            $arr[$i+2] + $arr[$i+1]>$arr[$i] &&
            $arr[$i] + $arr[$i+2]>$arr[$i+1])
        {
            $flag = true;
            break;
        }
    }
    echo ($flag ? "YES" : "NO") . PHP_EOL;
?>

<?php

error_reporting(0);

while($line = trim(fgets(STDIN))){

$linhas[]=$line;
if($a==1) break;
$a++;
}

$arrayValores=explode(" ",$linhas[1]);

rsort($arrayValores);

$i=0;

$alvo = $arrayValores[sizeof($arrayValores) - 2];

while(TRUE) {

$max=$arrayValores[$i];
$secMax = $arrayValores[$i+1];

if($max==$alvo) {echo "NO"; break;}

$arrayValores = array_slice($arrayValores,1,null,TRUE);
$a=0;

foreach($arrayValores as $valor){

	if($a==0) {$a=1; continue;}

	if(($valor+$secMax>$max)) {
		echo "YES";
		break 2;
	}

}

$i++;

}

?>

<?php

error_reporting(0);

while($line = trim(fgets(STDIN))){

$linhas[]=$line;
if($a==1) break;
$a++;
}

$arrayValores=explode(" ",$linhas[1]);

rsort($arrayValores);

$i=0;

$alvo = $arrayValores[sizeof($arrayValores) - 2];

while(TRUE) {

$max=$arrayValores[$i];
$secMax = $arrayValores[$i+1];

if($max==$alvo) {echo "NO"; break;}

$arrayValores = array_slice($arrayValores,1,null,TRUE);
$a=0;

foreach($arrayValores as $valor){

	if($a==0) {$a=1; continue;}

	if($valor+$secMax>=$max) {
		echo "YES";
		break 2;
	}

}

$i++;

}

?>

<?php

error_reporting(0);

while($line = trim(fgets(STDIN))){

$linhas[]=$line;
if($a==1) break;
$a++;
}

$arrayValores=explode(" ",$linhas[1]);

rsort($arrayValores);

$i=0;

$alvo = $arrayValores[sizeof($arrayValores) - 1];

while(TRUE) {

$max=$arrayValores[$i];
$secMax = $arrayValores[$i+1];

if($max==$alvo) {echo "NO"; break;}

$arrayValores = array_slice($arrayValores,1,null,TRUE);
$a=0;

foreach($arrayValores as $valor){

	if($a==0) {$a=1; continue;}

	if(($valor+$secMax>$max)) {
		echo "YES";
		break 2;
	}

}

$i++;

}

?>

<?php
    $stdin = fopen("php://stdin", "r");
    $n = trim(fgets(STDIN));
    $arr = explode(" ", trim(fgets(STDIN)));
    fclose($stdin);

    $flag = false;

    for($i=0; $i<$n-2; $i++)
    {
        if(
            $arr[$i] + $arr[$i+1]>$arr[$i+2] &&
            $arr[$i+2] + $arr[$i+1]>$arr[$i] &&
            $arr[$i] + $arr[$i+2]>$arr[$i+1])
        {
            $flag = true;
            break;
        }
    }
    echo ($flag ? "YES" : "NO") . PHP_EOL;
?>


Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him tj minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.Polycarp has M minutes of time. What is the maximum number of points he can earn?

The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·109). The second line contains k integer numbers, values tj (1 ≤ tj ≤ 1000000), where tj is the time in minutes required to solve j-th subtask of any task.

Print the maximum amount of points Polycarp can earn in M minutes.

NoteIn the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.


One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point (x1, y1, z1). The six faces of the box contain some numbers a1, a2, ..., a6, exactly one number right in the center of each face.  The numbers are located on the box like that:   number a1 is written on the face that lies on the ZOX plane;  a2 is written on the face, parallel to the plane from the previous point;  a3 is written on the face that lies on the XOY plane;  a4 is written on the face, parallel to the plane from the previous point;  a5 is written on the face that lies on the YOZ plane;  a6 is written on the face, parallel to the plane from the previous point. At the moment Vasya is looking at the box from point (x, y, z). Find the sum of numbers that Vasya sees. Note that all faces of the box are not transparent and Vasya can't see the numbers through the box. The picture contains transparent faces just to make it easier to perceive. You can consider that if Vasya is looking from point, lying on the plane of some face, than he can not see the number that is written on this face. It is enough to see the center of a face to see the corresponding number for Vasya. Also note that Vasya always reads correctly the ai numbers that he sees, independently of their rotation, angle and other factors (that is, for example, if Vasya sees some ai = 6, then he can't mistake this number for 9 and so on).

The fist input line contains three space-separated integers x, y and z (|x|, |y|, |z| ≤ 106) — the coordinates of Vasya's position in space. The second line contains three space-separated integers x1, y1, z1 (1 ≤ x1, y1, z1 ≤ 106) — the coordinates of the box's vertex that is opposite to the vertex at point (0, 0, 0). The third line contains six space-separated integers a1, a2, ..., a6 (1 ≤ ai ≤ 106) — the numbers that are written on the box faces.  It is guaranteed that point (x, y, z) is located strictly outside the box.

Print a single integer — the sum of all numbers on the box faces that Vasya sees.

NoteThe first sample corresponds to perspective, depicted on the picture. Vasya sees numbers a2 (on the top face that is the darkest), a6 (on the right face that is the lightest) and a4 (on the left visible face).In the second sample Vasya can only see number a4.

<?php
	// God & me
	// I found myself in Love empire !
	$INPUTS = preg_split("/[\s]+/", file_get_contents('php://stdin'));
	function in(){
	    static $i = 0;
	    global $INPUTS;
	    return $INPUTS[$i++];
	}
	$vx = in(); $vy = in(); $vz = in(); $x = in(); $y = in(); $z = in();
	$ans = 0;
	$cur = in();
	if($vy < 0)  $ans += $cur;
	$cur = in();
	if($vy > $y)  $ans += $cur;
	$cur = in();
	if($vz < 0)  $ans += $cur;
	$cur = in();
	if($vz > $z)  $ans += $cur;
	$cur = in();
	if($vx < 0)  $ans += $cur;
	$cur = in();
	if($vx > $x)  $ans += $cur;
	echo $ans;
?>


A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert a grams of sand into b grams of lead, the second one allows you to convert c grams of lead into d grams of gold and third one allows you to convert e grams of gold into f grams of sand. When Harry told his friends about these spells, Ron Weasley was amazed. After all, if they succeed in turning sand into lead, lead into gold, and then turning part of the gold into sand again and so on, then it will be possible to start with a small amount of sand and get huge amounts of gold! Even an infinite amount of gold! Hermione Granger, by contrast, was skeptical about that idea. She argues that according to the law of conservation of matter getting an infinite amount of matter, even using magic, is impossible. On the contrary, the amount of matter may even decrease during transformation, being converted to magical energy. Though Hermione's theory seems convincing, Ron won't believe her. As far as Ron is concerned, Hermione made up her law of conservation of matter to stop Harry and Ron wasting their time with this nonsense, and to make them go and do homework instead. That's why Ron has already collected a certain amount of sand for the experiments. A quarrel between the friends seems unavoidable...Help Harry to determine which one of his friends is right, and avoid the quarrel after all. To do this you have to figure out whether it is possible to get the amount of gold greater than any preassigned number from some finite amount of sand.

The first line contains 6 integers a, b, c, d, e, f (0 ≤ a, b, c, d, e, f ≤ 1000).

Print "Ron", if it is possible to get an infinitely large amount of gold having a certain finite amount of sand (and not having any gold and lead at all), i.e., Ron is right. Otherwise, print "Hermione".

Ron Hermione Hermione Hermione Ron Hermione Ron

NoteConsider the first sample. Let's start with the 500 grams of sand. Apply the first spell 5 times and turn the sand into 1000 grams of lead. Then apply the second spell 4 times to get 600 grams of gold. Let’s take 400 grams from the resulting amount of gold turn them back into sand. We get 500 grams of sand and 200 grams of gold. If we apply the same operations to 500 grams of sand again, we can get extra 200 grams of gold every time. Thus, you can get 200, 400, 600 etc. grams of gold, i.e., starting with a finite amount of sand (500 grams), you can get the amount of gold which is greater than any preassigned number.In the forth sample it is impossible to get sand, or lead, or gold, applying the spells.In the fifth sample an infinitely large amount of gold can be obtained by using only the second spell, which allows you to receive 1 gram of gold out of nothing. Note that if such a second spell is available, then the first and the third one do not affect the answer at all.The seventh sample is more interesting. We can also start with a zero amount of sand there. With the aid of the third spell you can get sand out of nothing. We get 10000 grams of sand in this manner. Let's get 100 grams of lead using the first spell 100 times. Then make 1 gram of gold from them. We managed to receive 1 gram of gold, starting with a zero amount of sand! Clearly, in this manner you can get an infinitely large amount of gold.


Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $$$1$$$ to $$$9$$$). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, $$$\ldots$$$, 9m, 1p, 2p, $$$\ldots$$$, 9p, 1s, 2s, $$$\ldots$$$, 9s.In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.Do you know the minimum number of extra suited tiles she needs to draw so that she can win?Here are some useful definitions in this game:  A mentsu, also known as meld, is formed by a koutsu or a shuntsu;  A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu;  A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples:   [2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu;  [4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu;  [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.

The only line contains three strings — the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from $$$1$$$ to $$$9$$$ and the second character is m, p or s.

Print a single integer — the minimum number of extra suited tiles she needs to draw.

NoteIn the first example, Tokitsukaze already has a shuntsu.In the second example, Tokitsukaze already has a koutsu.In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].

<?php
    $n = explode(" ", trim(fgets(STDIN)));
    $arr = array('m' => 0, 'p' => 0, 's' => 0);
    foreach($n as $k => $v){
        $arr[$v[1]] += 1;
    }
    arsort($arr);
  if(reset($arr) == 1){
      echo 2;
  } else if (reset($arr) == 2) {
      foreach($n as $sk => $sv){
          if($sv[1] == array_keys($arr)[0]) {
              $a[] = $sv[0];
          }
      }
      if(abs($a[0] - $a[1]) <= 2) {
          echo 1;
      } else {
          echo 2;
      }
  } else if(reset($arr) == 3) {
      foreach($n as $sk => $sv){
          if($sv[1] == array_keys($arr)[0]) {
              $a[] = $sv[0];
          }
      }
      $b = array_count_values($a);
      arsort($b);
      if(max($a) - min($a) == 0) {
          echo 0;
      } else if (max($a) - min($a) == 2) {
          if(reset($b) < 2) {
              echo 0;
          }else{
              echo 1;
          }
      } else if (max($a) - min($a) > 2){
          $b = array_count_values($a);
          arsort($b);
          $d = array_keys($b);
          sort($d);
          $m1 = $d[0]+1;
          $m2 = $d[2]-1;
          $m3 = $d[1]+1;
          $m4 = $d[1]-1;
          if(reset($b) < 2) {
                if(in_array($m1, $d) || in_array($m2, $d) || in_array($m3, $d) || in_array($m4, $d) || ($m1 == $m4) || ($m3 == $m2)){
                    echo 1;
                } else {
                    echo 2;
                }
          } else {
              echo 1;
          }
      } else {
          echo 1;
      }
  }

 ?>

<?php
    $n = explode(" ", trim(fgets(STDIN)));
    $arr = array('m' => 0, 'p' => 0, 's' => 0);
    foreach($n as $k => $v){
        $arr[$v[1]] += 1;
    }
    arsort($arr);
  if(reset($arr) == 1){
      echo 2;
  } else if (reset($arr) == 2) {
      foreach($n as $sk => $sv){
          if($sv[1] == array_keys($arr)[0]) {
              $a[] = $sv[0];
          }
      }
      if(abs($a[0] - $a[1]) <= 2) {
          echo 1;
      } else {
          echo 2;
      }
  } else if(reset($arr) == 3) {
      foreach($n as $sk => $sv){
          if($sv[1] == array_keys($arr)[0]) {
              $a[] = $sv[0];
          }
      }
      $b = array_count_values($a);
      arsort($b);
      if(max($a) - min($a) == 0) {
          echo 0;
      } else if (max($a) - min($a) == 2) {
          if(reset($b) < 2) {
              echo 0;
          }else{
              echo 1;
          }
      } else if (max($a) - min($a) > 2){
          $b = array_count_values($a);
          $d = array_keys($b);

          $max = max($d)-1;
          $min = min($d)+1;
          if(reset($b) < 2) {
                if(in_array($max, $d) || in_array($min, $d)){
                    echo 1;
                } else {
                    echo 2;
                }
          } else {
              echo 1;
          }
      }
  }

 ?>

<?php
    $n = explode(" ", trim(fgets(STDIN)));
    $arr = array('m' => 0, 'p' => 0, 's' => 0);
    foreach($n as $k => $v){
        $arr[$v[1]] += 1;
    }
    arsort($arr);
  if(reset($arr) == 1){
      echo 2;
  } else if (reset($arr) == 2) {
      foreach($n as $sk => $sv){
          if($sv[1] == array_keys($arr)[0]) {
              $a[] = $sv[0];
          }
      }
      if(abs($a[0] - $a[1]) <= 2) {
          echo 1;
      } else {
          echo 2;
      }
  } else if(reset($arr) == 3) {
      foreach($n as $sk => $sv){
          if($sv[1] == array_keys($arr)[0]) {
              $a[] = $sv[0];
          }
      }
      $b = array_count_values($a);
      arsort($b);
      if(max($a) - min($a) == 0) {
          echo 0;
      } else if (max($a) - min($a) == 2) {
          if(reset($b) < 2) {
              echo 0;
          }else{
              echo 1;
          }
      } else if (max($a) - min($a) > 2){
          $b = array_count_values($a);
          arsort($b);
          $d = array_keys($b);

          $max = max($d)-1;
          $min = min($d)+1;
          if(reset($b) < 2) {
                if(in_array($max, $d) || in_array($min, $d)){
                    echo 1;
                } else {
                    echo 2;
                }
          } else {
              echo 1;
          }
      }
  }

 ?>

<?php
    $n = explode(" ", trim(fgets(STDIN)));
    $arr = array('m' => 0, 'p' => 0, 's' => 0);
    foreach($n as $k => $v){
        $arr[$v[1]] += 1;
    }
    arsort($arr);
  if(reset($arr) == 1){
      echo 2;
  } else if (reset($arr) == 2) {
      foreach($n as $sk => $sv){
          if($sv[1] == array_keys($arr)[0]) {
              $a[] = $sv[0];
          }
      }
      if(abs($a[0] - $a[1]) <= 2) {
          echo 1;
      } else {
          echo 2;
      }
  } else if(reset($arr) == 3) {
      foreach($n as $sk => $sv){
          if($sv[1] == array_keys($arr)[0]) {
              $a[] = $sv[0];
          }
      }
      if(max($a) - min($a) == 0) {
          echo 0;
      } else if (max($a) - min($a) == 2) {
          echo 1;
      } else if (max($a) - min($a) > 2){
          $b = array_count_values($a);
          if($b[0] < 2) {
              echo 2;
          } else {
              echo 1;
          }
      }
  }

 ?>


Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y violet and z orange spheres. Can he get them (possible, in multiple actions)?

The first line of the input contains three integers a, b and c (0 ≤ a, b, c ≤ 1 000 000) — the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, x, y and z (0 ≤ x, y, z ≤ 1 000 000) — the number of blue, violet and orange spheres that he needs to get.

If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".

NoteIn the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs.

<?php

    function gao($a, $b) {
        if($a > $b) return ($a-$b-($a-$b)%2)/2;
        else
            return $a-$b;
    }

    fscanf(STDIN, "%d%d%d", $a, $b, $c);
    fscanf(STDIN, "%d%d%d", $x, $y, $z);
    //echo $a, $b, $c;
    //echo $x, $y, $z;
    $ans = 0;
    $ans = $ans + gao($a, $x);// echo $ans , "\n";
    $ans += gao($b, $y);// echo $ans , '\n';
    $ans += gao($c, $z);// echo $ans , '\n';
    echo $ans >= 0 ? "Yes" : "No";

?>

<?php

$handle = fopen("php://stdin", "r");
fscanf($handle, "%d %d %d %d %d %d", $a, $b, $c, $x, $y, $z);
echo $a, $b, $c;
echo $x, $y, $z;

?>

<?php

$dir = fopen("php://stdin", "r");
echo stream_get_contents($dir);

?>

<?php

    function gao($a, $b) {
        if($a > $b) return intdiv($a-$b, 2);
        else return $b-$a;
    }

    fscanf(STDIN, "%d%d%d", $a, $b, $c);
    fscanf(STDIN, "%d%d%d", $x, $y, $z);
    $ans = 0;
    $ans += gao(a, x);
    $ans += gao(b, y);
    $ans += gao(c, z);
    echo $ans >= 0 ? "Yes" : "No";

?>

<?php

    function gao($a, $b) {
        if($a > $b) return ($a-$b-$a%$b)/2;
        else
            return $a-$b;
    }

    fscanf(STDIN, "%d%d%d", $a, $b, $c);
    fscanf(STDIN, "%d%d%d", $x, $y, $z);
    //echo $a, $b, $c;
    //echo $x, $y, $z;
    $ans = 0;
    $ans = $ans + gao($a, $x);
    $ans += gao($b, $y);
    $ans += gao($c, $z);
    echo $ans >= 0 ? "Yes" : "No";

?>


A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.

The first line contains three integers r, g and b (0 ≤ r, g, b ≤ 100). It is guaranteed that r + g + b > 0, it means that the group consists of at least one student.

Print a single number — the minimal time the students need for the whole group to ascend to the top of the mountain.

NoteLet's analyze the first sample.At the moment of time 0 a red cablecar comes and one student from the r group get on it and ascends to the top at the moment of time 30.At the moment of time 1 a green cablecar arrives and two students from the g group get on it; they get to the top at the moment of time 31.At the moment of time 2 comes the blue cablecar and two students from the b group get on it. They ascend to the top at the moment of time 32.At the moment of time 3 a red cablecar arrives but the only student who is left doesn't like red and the cablecar leaves empty.At the moment of time 4 a green cablecar arrives and one student from the g group gets on it. He ascends to top at the moment of time 34.Thus, all the students are on the top, overall the ascension took exactly 34 minutes.

<?
$arr=explode(' ',trim(fgets(STDIN)));
foreach ($arr as $val){
    $newarr[]=ceil($val/2);
}
$max=max($newarr);
$res=30+($max*3-1);
for($i=2;$i>0;$i--){
    if($newarr[$i]==$max) {
        $pos=$i;
        break;
    }
}
switch($pos){
    case 2: $minus=0; break;
    case 1: $minus=1; break;
    case 0: $minus=2; break;
}
echo $res-$minus;
?>


Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t. Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.

The first line contains a single integer x (1 ≤ x ≤ 1018) — the number that Luke Skywalker gave to Chewbacca.

Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.

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

$res = '';

foreach (str_split($s) as $i => $ch) {
  $ch = (int)$ch;
  if ($ch >= 5) {
    if ($i != 0 || $ch != 9) {
      $ch = 9 - $ch;
    }
  }
  $res .= $ch;
}

echo "$res\n";

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');

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

$result = '';

for($i=0;$i<strlen($s);$i++){

    if ($i==0 && $s[$i]=='9'){
        $result.=$s[$i];
        continue;
    }

    if ($s[$i]>4){
        $t = (9 - $s[$i]);
        $result=$result.$t;
    } else $result.=$s[$i];
}

if ($result=='0') exit($s);

echo $result;

<?php
// 514A     Чубакка и число
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
//$n = (int) $input_line;

//list($x1, $y1, $x2, $y2) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$str = substr($input_line, 0, strlen($input_line)-2);
$len = strlen($str);

for ($i=0; $i < $len; $i++) {
    if ($str[$i] > '4') {
        $str[$i] = (string) (9 - (int) $str[$i]);
    }
}

for ($i=0; $i < $len; $i++) {
    if ($str[$i] !== '0') {
        break;
    } else {
        $str[$i] = '9';
        break;
    }
}

echo $str;

?>

<?php
// 514A     Чубакка и число
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
//$n = (int) $input_line;

//list($x1, $y1, $x2, $y2) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$str = substr($input_line, 0, strlen($input_line)-2);
$len = strlen($str);

for ($i=0; $i < $len; $i++) {
    if ($str[$i] > '4') {
        $str[$i] = (string) (9 - (int) $str[$i]);
    }
}

for ($i=0; $i < $len; $i++) {
    if ($str[$i] !== '0') break;
}

if ($i == $len) {
    echo "0";
} else {
    echo substr($str, $i);
}

?>

<?php
// 514A     Чубакка и число
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
//$n = (int) $input_line;

//list($x1, $y1, $x2, $y2) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$str = substr($input_line, 0, strlen($input_line)-2);
$strold = $str;
$len = strlen($str);

for ($i=0; $i < $len; $i++) {
    if ($str[$i] > '4') {
        $str[$i] = (string) (9 - (int) $str[$i]);
    }
}

for ($i=0; $i < $len; $i++) {
    if ($str[$i] !== '0') break;
}

if ($i == $len) {
    echo $strold;
} else {
    echo substr($str, $i);
}

?>

<?php
// 514A     Чубакка и число
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
//$n = (int) $input_line;

//list($x1, $y1, $x2, $y2) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$str = substr($input_line, 0, strlen($input_line)-2);
$len = strlen($str);

for ($i=0; $i < $len; $i++) {
    if ($str[$i] > '4') {
        $str[$i] = (string) (9 - (int) $str[$i]);
    }
}

for ($i=0; $i < $len; $i++) {
    if ($str[$i] !== '0') {
        break;
    } else {
        $str[$i] = '9';
    }
}

echo $str;

?>

<?php
// 514A     Чубакка и число
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
//$n = (int) $input_line;

//list($x1, $y1, $x2, $y2) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$str = substr($input_line, 0, strlen($input_line)-2);
$len = strlen($input_line);

for ($i=0; $i < $len; $i++) {
    if ($str[$i] > '4') {
        $str[$i] = (string) (9 - (int) $str[$i]);
    }
}

for ($i=0; $i < $len; $i++) {
    if ($str[$i] !== '0') break;
}

if ($i == $len) {
    echo "0";
} else {
    echo substr($str, $i);
}

?>

<?php
// 514A     Чубакка и число
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
//$n = (int) $input_line;

//list($x1, $y1, $x2, $y2) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$str = substr($input_line, 0, strlen($input_line)-2);
$len = strlen($input_line);

for ($i=0; $i < $len; $i++) {
    if ($str[$i] > '4') {
        $str[$i] = (string) (9 - (int) $str[$i]);
    }
}

for ($i=0; $i < $len; $i++) {
    if ($str[$i] !== '0') break;
}

if ($i == $len) {
    echo "0";
} else {
    echo substr($str, $i - 1);
}

?>


Consider an array $$$a$$$ of length $$$n$$$ with elements numbered from $$$1$$$ to $$$n$$$. It is possible to remove the $$$i$$$-th element of $$$a$$$ if $$$gcd(a_i, i) = 1$$$, where $$$gcd$$$ denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.An array $$$b$$$ with $$$n$$$ integers such that $$$1 \le b_i \le n - i + 1$$$ is a removal sequence for the array $$$a$$$ if it is possible to remove all elements of $$$a$$$, if you remove the $$$b_1$$$-th element, then the $$$b_2$$$-th, ..., then the $$$b_n$$$-th element. For example, let $$$a = [42, 314]$$$:  $$$[1, 1]$$$ is a removal sequence: when you remove the $$$1$$$-st element of the array, the condition $$$gcd(42, 1) = 1$$$ holds, and the array becomes $$$[314]$$$; when you remove the $$$1$$$-st element again, the condition $$$gcd(314, 1) = 1$$$ holds, and the array becomes empty.  $$$[2, 1]$$$ is not a removal sequence: when you try to remove the $$$2$$$-nd element, the condition $$$gcd(314, 2) = 1$$$ is false. An array is ambiguous if it has at least two removal sequences. For example, the array $$$[1, 2, 5]$$$ is ambiguous: it has removal sequences $$$[3, 1, 1]$$$ and $$$[1, 2, 1]$$$. The array $$$[42, 314]$$$ is not ambiguous: the only removal sequence it has is $$$[1, 1]$$$.You are given two integers $$$n$$$ and $$$m$$$. You have to calculate the number of ambiguous arrays $$$a$$$ such that the length of $$$a$$$ is from $$$1$$$ to $$$n$$$ and each $$$a_i$$$ is an integer from $$$1$$$ to $$$m$$$.

The only line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 3 \cdot 10^5$$$; $$$1 \le m \le 10^{12}$$$).

Print one integer — the number of ambiguous arrays $$$a$$$ such that the length of $$$a$$$ is from $$$1$$$ to $$$n$$$ and each $$$a_i$$$ is an integer from $$$1$$$ to $$$m$$$. Since the answer can be very large, print it modulo $$$998244353$$$.


Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that.Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them.The English alphabet vowels are: A, E, I, O, U, YThe English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z

The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter.

Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No". Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters.

Is   it an apple  and a  banana   simultaneouSLY?

<?php
    $input = readline();
    $input = str_replace(' ', '', $input);
    $input = strtolower($input);
    $inputArray = str_split($input);
    $sizeArray = count($inputArray);
    $array = array("a", "e", "i", "o", "u", "y");
    $ban = false;
    foreach ($array as $key=>$valor) {
        if ($valor == $inputArray[$sizeArray-2]) {
            $ban = true;
            break;
        }
    }
    if ($ban) {
        echo "YES";
    }else{
        echo "NO";
    }
?>

<?
$g=array('A', 'E', 'I', 'O', 'U', 'Y');
$str=trim(fgets(STDIN));
$str=strtoupper(preg_replace('/(\s+)|\?/','',$str));
$len=strlen($str)-1;
for($i=0,$n=sizeof($g);$i<$n;$i++){
    if($g[$i]==$str[$len]) {
        $res="YES";
        break;
    }
}
if($res=="") $res="NO";
echo $res;
?>

<?
$fp=fopen('php://stdin', 'r');
$lines=stream_get_contents($fp);

$lines=trim($lines);

$lines=rtrim($lines, "?");
$lines=trim($lines);
$n=strlen($lines)-1;

if (in_array(strtolower($lines{$n}), array("a", "e", "i", "o", "u", "y")))
    echo 'YES';
else
    echo 'NO';
?>

<?php
    $input = fgets(STDIN);
    $input = str_replace(' ', '', $input);
    $input = strtolower($input);
    $inputArray = str_split($input);
    $sizeArray = count($inputArray);
    $array = array("a", "e", "i", "o", "u", "y");
    $ban = false;
    foreach ($array as $key=>$valor) {
        if ($valor == $inputArray[$sizeArray-2]) {
            $ban = true;
            break;
        }
    }
    if ($ban) {
        echo "YES";
    }else{
        echo "NO";
    }
?>

<?php
    $input = trim(fgets(STDIN));
    $input = strtolower($input);
    $inputArray = str_split($input);
    $sizeArray = count($inputArray);
    $array = array("a", "e", "i", "o", "u", "y");
    $ban = false;
    foreach ($array as $key=>$valor) {
        if ($valor == $inputArray[$sizeArray-2]) {
            $ban = true;
            break;
        }
    }
    if ($ban) {
        echo "YES";
    }else{
        echo "NO";
    }
?>

<?php
    $input = str_replace(' ', '', fgets(STDIN));
    $input = strtolower($input);
    $inputArray = str_split($input);
    $sizeArray = count($inputArray);
    $array = array("a", "e", "i", "o", "u", "y");
    $ban = false;
    foreach ($array as $key=>$valor) {
        if ($valor == $inputArray[$sizeArray-2]) {
            $ban = true;
            break;
        }
    }
    if ($ban) {
        echo "YES";
    }else{
        echo "NO";
    }
?>


One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals n, then the player wins, otherwise the player loses.The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals n.

The only line contains n (1 ≤ n ≤ 25) — the required sum of points.

Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.

NoteIn the first sample only four two's of different suits can earn the required sum of points.In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.In the third sample there is no card, that would add a zero to the current ten points.

<?php
$IN = STDIN;
fscanf($IN, "%d", $n);
$needval = $n-10;

if ($needval==10)
  echo 15;
elseif ((0<$needval)&&($needval<12))
  echo 4;
else
  echo 0;

?>

<?php
$IN = STDIN;
fscanf($IN, "%d", $n);
$needval = $n-10;

if ($needval==10)
  echo 15;
elseif ((0<$needval)&&($needval<22))
  echo 4;
else
  echo 0;

?>


There are three doors in front of you, numbered from $$$1$$$ to $$$3$$$ from left to right. Each door has a lock on it, which can only be opened with a key with the same number on it as the number on the door.There are three keys — one for each door. Two of them are hidden behind the doors, so that there is no more than one key behind each door. So two doors have one key behind them, one door doesn't have a key behind it. To obtain a key hidden behind a door, you should first unlock that door. The remaining key is in your hands.Can you open all the doors?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 18$$$) — the number of testcases. The first line of each testcase contains a single integer $$$x$$$ ($$$1 \le x \le 3$$$) — the number on the key in your hands. The second line contains three integers $$$a, b$$$ and $$$c$$$ ($$$0 \le a, b, c \le 3$$$) — the number on the key behind each of the doors. If there is no key behind the door, the number is equal to $$$0$$$. Values $$$1, 2$$$ and $$$3$$$ appear exactly once among $$$x, a, b$$$ and $$$c$$$.

For each testcase, print "YES" if you can open all the doors. Otherwise, print "NO".

<?php

$testCases = fgets(STDIN);

$answers = [];
for ($i=0; $i < $testCases; $i++) {
    $key = (int) fgets(STDIN);
    $keysBehind = array_map('intval', explode(' ', fgets(STDIN)));

    if (
        $keysBehind[$key - 1] !== 0
        && isset($keysBehind[$keysBehind[$key - 1] - 1])
        && $keysBehind[$keysBehind[$key - 1] - 1] !== 0
    ) {
        $answers[] = 'YES';
    } else {
        $answers[] = 'NO';
    }
}

foreach ($answers as $item) {
    echo $item . PHP_EOL;
}

<?php

function allDoorPossibleToOpen($input)
{
    $line = explode("\n", $input);
    $testCase = $line[0];

    for ($i = 1; $i <= $testCase; $i++) {

        $keyOnHand = $line[$i*2-1];
        $keyBehindDoor = explode(" ",$line[$i*2]);
        for($openedDoor = 1; $openedDoor <= 3; $openedDoor++){
            $keyOnHand = $keyBehindDoor[$keyOnHand-1];
            if($keyOnHand == 0){
                break;
            }
        }
        if($openedDoor == 3){
            echo "YES\n";
        }else{
            echo "NO\n";
        }
    }
}

allDoorPossibleToOpen(file_get_contents('php://stdin'));

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
//101
//101
//001
function solve()
{
     $x = IO::get();
    $a = IO::getArray();

 $ans = 'YES';

 if($a[$x-1] != 0) {
      $x = $a[$x-1];
      if($a[$x-1] != 0) {
           $x = $a[$x-1];
      } else {
           $ans = 'NO';
      }

 } else {
      $ans = 'NO';
 }

   IO::pr($ans);

}

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}


Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where   <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive.  <hostname> — is a sequence of word separated by periods (characters «.»), where each word should contain only characters allowed for <username>, the length of each word is between 1 and 16, inclusive. The length of <hostname> is between 1 and 32, inclusive.  <resource> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <resource> is between 1 and 16, inclusive. The content of square brackets is optional — it can be present or can be absent.There are the samples of correct Jabber IDs: mike@codeforces.com, 007@en.codeforces.com/contest.Your task is to write program which checks if given string is a correct Jabber ID.

The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.

<?php

function debug($data, $die = true) {
    echo '<pre>';

    if (is_array($data)) {
        print_r($data);
    } else {
        var_dump($data);
    }

    if ($die) {
        die();
    }

    echo '</pre>';
}

function stdin() {
    $stdin = @fopen('data.txt', 'r');
    if (!$stdin) {
        $stdin = fopen('php://stdin', 'r');
    }

    return $stdin;
}

function g() {
    global $stdin;
    return trim(fgets($stdin));
}

$stdin = stdin();
/****************************************************** Solving block *****************************************************/
$id = g();

$word = "[a-z0-9_]{1,16}";
$correct = preg_match("/^$word@(($word\.)*$word)(\/$word)?$/i", $id, $matches);
$correct = $correct && strlen($matches[1]) && strlen($matches[1]) < 33;

echo $correct ? 'YES' : 'NO';

?>

<?php

function debug($data, $die = true) {
    echo '<pre>';

    if (is_array($data)) {
        print_r($data);
    } else {
        var_dump($data);
    }

    if ($die) {
        die();
    }

    echo '</pre>';
}

function stdin() {
    $stdin = @fopen('data.txt', 'r');
    if (!$stdin) {
        $stdin = fopen('php://stdin', 'r');
    }

    return $stdin;
}

function g() {
    global $stdin;
    return trim(fgets($stdin));
}

$stdin = stdin();
/****************************************************** Solving block *****************************************************/
$id = g();

$word = "[a-z0-9_]{1,16}";
$correct = preg_match("/^$word@(($word\.)+$word)(\/$word)?$/i", $id, $matches);
$correct = $correct && strlen($matches[1]) && strlen($matches[1]) < 33;

echo $correct ? 'YES' : 'NO';

?>


Polycarp is going to participate in the contest. It starts at $$$h_1:m_1$$$ and ends at $$$h_2:m_2$$$. It is guaranteed that the contest lasts an even number of minutes (i.e. $$$m_1 \% 2 = m_2 \% 2$$$, where $$$x \% y$$$ is $$$x$$$ modulo $$$y$$$). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from $$$10:00$$$ to $$$11:00$$$ then the answer is $$$10:30$$$, if the contest lasts from $$$11:10$$$ to $$$11:12$$$ then the answer is $$$11:11$$$.

The first line of the input contains two integers $$$h_1$$$ and $$$m_1$$$ in the format hh:mm. The second line of the input contains two integers $$$h_2$$$ and $$$m_2$$$ in the same format (hh:mm). It is guaranteed that $$$0 \le h_1, h_2 \le 23$$$ and $$$0 \le m_1, m_2 \le 59$$$. It is guaranteed that the contest lasts an even number of minutes (i.e. $$$m_1 \% 2 = m_2 \% 2$$$, where $$$x \% y$$$ is $$$x$$$ modulo $$$y$$$). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.

Print two integers $$$h_3$$$ and $$$m_3$$$ ($$$0 \le h_3 \le 23, 0 \le m_3 \le 59$$$) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.


A single line contains a single integer x (1 ≤ x ≤ 109).

<?php
/*
http://www.codeforces.com/problemset/problem/221/B
The Little Elephant loves numbers.

He has a positive integer x. The Little Elephant wants to find the number of
positive integers d, such that d is the divisor of x, and x and d have at least
one common (the same) digit in their decimal representations.

Help the Little Elephant to find the described number.
Input: A single line contains a single integer x (1 ? x ? 109).
Output: In a single line print an integer — the answer to the problem.
*/
$num = fgets(STDIN);
//echo $num;
//$arr = str_split($num);
//print_r($arr);
/*
foreach( $arr as $i => $val){
    echo "Id: $i, Val: $val\n";
}
*/
$r = 0;
for ($i = 1; $i <= sqrt($num); $i += 1) {
    if ($num % $i == 0) {
        $k = $num / $i;
        //echo "probando $i $k \n";
        $f_i = 0;
        $f_j = 0;
        for ($j = 0; $j <= 9; $j += 1) {
            if (substr_count((string)$num, (string)$j) > 0){
                if (substr_count((string)$i, (string)$j) > 0  and $f_i == 0){
                    //echo "$i\n";
                    $r++;
                    $f_i = 1;
                }
                if (substr_count((string)$k, (string)$j) > 0 and $f_j == 0 and $i != $k) {
                    //echo "$k\n";
                    $f_j = 1;
                    $r++;
                }
            }
        }
    }
}
echo $r;
?>

<?php
/*
http://www.codeforces.com/problemset/problem/221/B
The Little Elephant loves numbers.

He has a positive integer x. The Little Elephant wants to find the number of
positive integers d, such that d is the divisor of x, and x and d have at least
one common (the same) digit in their decimal representations.

Help the Little Elephant to find the described number.
Input: A single line contains a single integer x (1 ? x ? 109).
Output: In a single line print an integer — the answer to the problem.
*/
$num = fgets(STDIN);
//echo $num;
//$arr = str_split($num);
//print_r($arr);
/*
foreach( $arr as $i => $val){
    echo "Id: $i, Val: $val\n";
}
*/
for ($i = 2; $i <= sqrt($num); $i += 1) {
    if ($num % $i == 0) {
        $k = $num / $i;
        //echo "probando $i $k \n";
        $f_i = 0;
        $f_j = 0;
        for ($j = 0; $j <= 9; $j += 1) {
            if (substr_count((string)$num, (string)$j) > 0){
                if (substr_count((string)$i, (string)$j) > 0  and $f_i == 0){
                    echo "$i\n";
                    $f_i = 1;
                }
                if (substr_count((string)$k, (string)$j) > 0 and $f_j == 0 and $i != $k) {
                    echo "$k\n";
                    $f_j = 1;
                }
            }
        }
    }
}
?>

<?php
/*
http://www.codeforces.com/problemset/problem/221/B
The Little Elephant loves numbers.

He has a positive integer x. The Little Elephant wants to find the number of
positive integers d, such that d is the divisor of x, and x and d have at least
one common (the same) digit in their decimal representations.

Help the Little Elephant to find the described number.
Input: A single line contains a single integer x (1 ? x ? 109).
Output: In a single line print an integer — the answer to the problem.
*/
$num = fgets(STDIN);
//echo $num;
//$arr = str_split($num);
//print_r($arr);
/*
foreach( $arr as $i => $val){
    echo "Id: $i, Val: $val\n";
}
*/
for ($i = 1; $i <= $num / 2; $i += 1) {
    if ($num % $i == 0) {
        $f_i = 0;
        for ($j = 0; $j <= 9; $j += 1) {
            if (substr_count((string)$num, (string)$j) > 0){
                if (substr_count((string)$i, (string)$j) > 0  and $f_i == 0){
                    echo "$i\n";
                    $f_i = 1;
                }
            }
        }
    }
}
?>

<?php
/*
http://www.codeforces.com/problemset/problem/221/B
The Little Elephant loves numbers.

He has a positive integer x. The Little Elephant wants to find the number of
positive integers d, such that d is the divisor of x, and x and d have at least
one common (the same) digit in their decimal representations.

Help the Little Elephant to find the described number.
Input: A single line contains a single integer x (1 ? x ? 109).
Output: In a single line print an integer — the answer to the problem.
*/
$num = fgets(STDIN);
//echo $num;
//$arr = str_split($num);
//print_r($arr);
/*
foreach( $arr as $i => $val){
    echo "Id: $i, Val: $val\n";
}
*/
for ($i = 1; $i <= sqrt($num); $i += 1) {
    if ($num % $i == 0) {
        $k = $num / $i;
        //echo "probando $i $k \n";
        $f_i = 0;
        $f_j = 0;
        for ($j = 0; $j <= 9; $j += 1) {
            if (substr_count((string)$num, (string)$j) > 0){
                if (substr_count((string)$i, (string)$j) > 0  and $f_i == 0){
                    echo "$i\n";
                    $f_i = 1;
                }
                if (substr_count((string)$k, (string)$j) > 0 and $f_j == 0 and $i != $k) {
                    echo "$k\n";
                    $f_j = 1;
                }
            }
        }
    }
}
?>

<?php
/*
http://www.codeforces.com/problemset/problem/221/B
The Little Elephant loves numbers.

He has a positive integer x. The Little Elephant wants to find the number of
positive integers d, such that d is the divisor of x, and x and d have at least
one common (the same) digit in their decimal representations.

Help the Little Elephant to find the described number.
Input: A single line contains a single integer x (1 ? x ? 109).
Output: In a single line print an integer — the answer to the problem.
*/
$num = fgets(STDIN);
//echo $num;
//$arr = str_split($num);
//print_r($arr);
/*
foreach( $arr as $i => $val){
    echo "Id: $i, Val: $val\n";
}
*/
for ($i = 1; $i <= $num / 2 + 1; $i += 1) {
    if ($num % $i == 0) {
        $f_i = 0;
        for ($j = 0; $j <= 9; $j += 1) {
            if (substr_count((string)$num, (string)$j) > 0){
                if (substr_count((string)$i, (string)$j) > 0  and $f_i == 0){
                    echo "$i\n";
                    $f_i = 1;
                }
            }
        }
    }
}
?>


— Thanks a lot for today.— I experienced so many great things.— You gave me memories like dreams... But I have to leave now...— One last request, can you...— Help me solve a Codeforces problem?— ......— What?Chtholly has been thinking about a problem for days:If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!

The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).

Output single integer — answer to the problem.

NoteIn the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.In the second example, .

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = 0;
for($x = 1; $x <= $a; $x++)
{
     $d = $x . strrev($x);
     $c = bcadd($c, $d);
}
$e = bcmod($c, $b);
print $e;
?>

<?php

$input = fopen('php://stdin', 'r');

fscanf($input, '%d%d', $request, $modulus);
$result = [];
$number = 0;

while (count($result) < $request) {
    $number++;
    $palindrome = $number . strrev($number);
    $result[$palindrome] = true;
}

$sum = 0;

foreach (array_keys($result) as $item) {
    $sum = bcadd($sum, $item);
}

echo bcmod($sum, $modulus), PHP_EOL;


Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number.  Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible.

The single line of the input contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 106) — the valence numbers of the given atoms.

If such a molecule can be built, print three space-separated integers — the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print "Impossible" (without the quotes).

NoteThe first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case.The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms.The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds with itself.The configuration in the fourth figure is impossible as each atom must have at least one atomic bond.


The king's birthday dinner was attended by $$$k$$$ guests. The dinner was quite a success: every person has eaten several dishes (though the number of dishes was the same for every person) and every dish was served alongside with a new set of kitchen utensils.All types of utensils in the kingdom are numbered from $$$1$$$ to $$$100$$$. It is known that every set of utensils is the same and consist of different types of utensils, although every particular type may appear in the set at most once. For example, a valid set of utensils can be composed of one fork, one spoon and one knife.After the dinner was over and the guests were dismissed, the king wondered what minimum possible number of utensils could be stolen. Unfortunately, the king has forgotten how many dishes have been served for every guest but he knows the list of all the utensils left after the dinner. Your task is to find the minimum possible number of stolen utensils.

The first line contains two integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 100$$$)  — the number of kitchen utensils remaining after the dinner and the number of guests correspondingly. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 100$$$)  — the types of the utensils remaining. Equal values stand for identical utensils while different values stand for different utensils.

Output a single value — the minimum number of utensils that could be stolen by the guests.

NoteIn the first example it is clear that at least one utensil of type $$$3$$$ has been stolen, since there are two guests and only one such utensil. But it is also possible that every person received only one dish and there were only six utensils in total, when every person got a set $$$(1, 2, 3)$$$ of utensils. Therefore, the answer is $$$1$$$.One can show that in the second example at least $$$2$$$ dishes should have been served for every guest, so the number of utensils should be at least $$$24$$$: every set contains $$$4$$$ utensils and every one of the $$$3$$$ guests gets two such sets. Therefore, at least $$$14$$$ objects have been stolen. Please note that utensils of some types (for example, of types $$$2$$$ and $$$4$$$ in this example) may be not present in the set served for dishes.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array();
for($x = 0; $x < $a; $x++)
{
     $d[$c[$x]]++;
}
$e = max($d);
$f = ceil($e / $b) * $b;
$g = count(array_unique($c)) * $f;
print $g - $a;
?>

<?php
//define('STDIN', fopen('input.txt', 'r'));

function array_value_to_integer(&$arr) {
	foreach ($arr as &$value)
		$value = (int)$value;
	unset($value);
	return $arr;
}

$arrCounts = explode(' ', trim(fgets(STDIN)));
list($countTablewareAfter, $countGuest) = array_value_to_integer( $arrCounts );

$arrTableware = explode(' ', trim(fgets(STDIN)));
array_value_to_integer($arrTableware);

$arrCountTablewareByType = [];
for ($i = 0; $i < $countTablewareAfter; $i++) {
	$arrCountTablewareByType[ $arrTableware[$i] ]++;
}

$minDishes = (int)ceil( max($arrCountTablewareByType) / $countGuest ); //минимальное количество блюд
$minCountTablewareType = count( $arrCountTablewareByType );

echo( $minDishes * $minCountTablewareType * $countGuest - $countTablewareAfter );

fclose(STDIN);

?>

<?php
$fl = STDIN;//fopen("input.txt","r");

$nAndKArray = explode(" ", fgets($fl));
$n = $nAndKArray[0];
$k = $nAndKArray[1];

$typesOfDevices = explode(" ", trim(fgets($fl)));
$resultTypeOfDevices = [];
$numberOfMeals = 1;

for($i = 0; $i < count($typesOfDevices); $i++){
    if(array_key_exists($typesOfDevices[$i], $resultTypeOfDevices)){
        $resultTypeOfDevices[$typesOfDevices[$i]]++;
        if(($resultTypeOfDevices[$typesOfDevices[$i]]/$k) > $numberOfMeals){
            $numberOfMeals++;
        }
    } else {
        $resultTypeOfDevices[$typesOfDevices[$i]] = 1;
    }
}
$result = $numberOfMeals * $k * count($resultTypeOfDevices) - $n;

print($result);

<?php
$fl = STDIN;//fopen("input.txt","r");

$nAndKArray = explode(" ", fgets($fl));
$n = $nAndKArray[0];
$k = $nAndKArray[1];

$typesOfDevices = explode(" ", fgets($fl));
$resultTypeOfDevices = [];
$numberOfMeals = 1;

for($i = 0; $i < count($typesOfDevices); $i++){
    if(array_key_exists($typesOfDevices[$i], $resultTypeOfDevices)){
        $resultTypeOfDevices[$typesOfDevices[$i]]++;
        if(($resultTypeOfDevices[$typesOfDevices[$i]]/$k) > $numberOfMeals){
            $numberOfMeals++;
        }
    } else {
        $resultTypeOfDevices[$typesOfDevices[$i]] = 1;
    }
}
$result = $numberOfMeals * $k * count($resultTypeOfDevices) - $n;
print($result);


Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:   Four sticks represent the animal's legs, these sticks should have the same length.  Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.

The single line contains six space-separated integers li (1 ≤ li ≤ 9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.

If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).

NoteIf you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.

<?php
	$data = explode(' ', trim(fgets(STDIN)));
	$counts = array();
	foreach ($data as $el){
		$counts[$el]++;
	}
	$hasFoot = $head = $body = 0;
	foreach ($counts as $k => $el){
		if ($el >= 4){
			$hasFoot = true;
			if ($el >= 5) $head = $k;
			if ($el == 6) $body = $k;
		}else{
			if ($el == 2){
				$head = $body = $k;
			}else{
				if ($head == 0) $head = $k;
				else $body = $k;
			}

		}
	}
	echo $hasFoot ? $body == $head ? 'Elephant' : 'Bear' : 'Alien';
?>

<?php
$a = explode(' ', trim(fgets(STDIN)));
sort($a);

if ($a[0] == $a[3]) {
    echo $a[4] == $a[5] ? 'Elephant' : 'Bear';
} elseif ($a[1] == $a[4]) {
    echo $a[0] == $a[5] ? 'Elephant' : 'Bear';
} elseif ($a[2] == $a[5]) {
    echo $a[0] == $a[1] ? 'Elephant' : 'Bear';
} else {
    echo 'Alien';
}

<?php
// 471A     МУХ и палочки
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$arr = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

sort($arr);

for ($i=0; $i < 6; $i++) {
    $count = substr_count($input_line, $arr[$i]);
    if ($count> 3) {
        for ($j=0; $j < 4 ; $j++) {
            unset($arr[$i+$j]);
        }
        break;
    }
}

$str = '';
foreach ($arr as $key => $value) {
    $str .= $value;
}

if ($count > 3) {
    if ($str[0] === $str[1]) {
        echo "Elephant";
    } else {
        echo "Bear";
    }
} else {
    echo "Alien";
}

?>

<?php
error_reporting("off");
//471A: MUH and Sticks
$array = explode(" ", trim(fgets(STDIN)));
$count = array_count_values($array);
sort($count);
$string = implode($count);
if ($string == "114" || $string == "15") {
	echo "Bear";
} elseif ($string == "24" || $string == "6") {
	echo "Elephant";
} else {
	echo "Alien";
}
?>

<?php
$a = explode(" ", trim(fgets(STDIN)));
sort($a);
$b = array_unique($a);
sort($b);
if(count($b) == 2)
{
    print "Elephant";
}
elseif(count($b) == 3)
{
    print "Bear";
}
else
{
    print "Alien";
}
?>

<?php
$a = explode(" ", trim(fgets(STDIN)));
sort($a);
$b = array_unique($a);
sort($b);
if((count($b) == 1) || (count($b) == 2))
{
    print "Elephant";
}
elseif(count($b) == 3)
{
    print "Bear";
}
else
{
    print "Alien";
}
?>

<?php
	$data = explode(' ', trim(fgets(STDIN)));
	$counts = array();
	foreach ($data as $el){
		$counts[$el]++;
	}
	$hasFoot = $head = $body = 0;
	foreach ($counts as $k => $el){
		if ($el >= 4){
			$hasFoot = true;
			if ($el == 5) $head = $k;
			if ($el == 6) $body = $k;
		}else{
			if ($el == 2){
				$head = $body = $k;
			}else{
				if ($head == 0) $head = $k;
				else $body = $k;
			}

		}
	}
	echo $hasFoot ? $body == $head ? 'Elephant' : 'Bear' : 'Alien';
?>

<?php
$a = explode(' ', fgets(STDIN));
sort($a);
$c = 0;
for ($i = 0; $i < 5; $i++) {
    if ($a[$i] != $a[$i + 1]) {
        $c++;
    }
}
if ($c < 2) {
    echo 'Elephant';
} elseif ($c == 2) {
    echo 'Bear';
} else {
    echo 'Alien';
}

<?php
$a = explode(' ', trim(fgets(STDIN)));
sort($a);

if ($a[0] == $a[3]) {
    echo $a[4] == $a[5] ? 'Elephant' : 'Bear';
} elseif ($a[1] == $a[3]) {
    echo $a[0] == $a[5] ? 'Elephant' : 'Bear';
} elseif ($a[2] == $a[4]) {
    echo $a[0] == $a[1] ? 'Elephant' : 'Bear';
} else {
    echo 'Alien';
}

<?php
// 471A     МУХ и палочки
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$arr = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

sort($arr);

for ($i=0; $i < 6; $i++) {
    $count = substr_count($input_line, $arr[$i]);
    if ($count> 3) {
        for ($j=0; $j < 4 ; $j++) {
            unset($arr[$i+$j]);
        }
        break;
    }
}

if ($count > 3) {
    if ($arr[0] === $arr[1]) {
        echo "Elephant";
    } else {
        echo "Bear";
    }
} else {
    echo "Alien";
}

?>