Lenny is playing a game on a 3 × 3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.

The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The j-th number in the i-th row is the number of times the j-th light of the i-th row of the grid is pressed.

Print three lines, each containing three characters. The j-th character of the i-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".


Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction  is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button ( + ) instead of division button (÷) and got sum of numerator and denominator that was equal to n instead of the expected decimal notation. Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction  such that sum of its numerator and denominator equals n. Help Petya deal with this problem.

In the only line of input there is an integer n (3 ≤ n ≤ 1000), the sum of numerator and denominator of the fraction.

Output two space-separated positive integers a and b, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.

<?php

function gcd($a, $b) {
    while ($a <> 0 && $b <> 0) {
        if ($a > $b)
            $a = $a % $b;
        else
            $b = $b % $a;
    }
    return abs($a + $b);
}

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

$n = (int)$raw[0];

for ($i = (int)($n / 2); $i > 0; $i--) {
    $a = $i;
    $b = $n - $i;

    if ($a >= $b) {
        continue;
    }

    $gcd = gcd($a, $b);

    if ($gcd == 1) {
        echo $a . ' ' . $b . PHP_EOL;
        die;
    }
}


Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:  After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.

The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.

Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.

Note   To print the string from the first sample it would be optimal to perform the following sequence of rotations:   from 'a' to 'z' (1 rotation counterclockwise),  from 'z' to 'e' (5 clockwise rotations),  from 'e' to 'u' (10 rotations counterclockwise),  from 'u' to 's' (2 counterclockwise rotations).  In total, 1 + 5 + 10 + 2 = 18 rotations are required.

<?php

define("CHARACTER_LIST", ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']);

$word = trim(fgets(STDIN));

$wordLetters = str_split($word);

$prevPosition = 0;
$steps = 0;
foreach ($wordLetters as $letter) {
  $letterNumber = array_search($letter, CHARACTER_LIST);

  $stepsCount = abs($letterNumber - $prevPosition);

  if ($stepsCount >= 13) {
    $actualStepsCount = count(CHARACTER_LIST) - $stepsCount;
    $steps += $actualStepsCount;

    $prevPosition = $letterNumber;
  } else {
    $actualStepsCount = $stepsCount;
    $steps += $actualStepsCount;

    $prevPosition = $letterNumber;
  }
}

echo $steps;

<?php

	$string = readline("");
	$result = 0;

	$stringArr = str_split($string);
	$len = count($stringArr);
	$pointer = ord("a");
	foreach($stringArr as $ch) {
		$ch = ord($ch);
		$diff = abs($ch - $pointer);
		if($diff < 13) {
			$result += $diff;
		} else {
			$result += (26 - $diff);
		}
		$pointer = $ch;
	}
	echo $result;
?>

<?php

//=====================================
// link: https://codeforces.com/contest/731/problem/A
//=====================================

// get inputs
$string = trim(fgets(STDIN));

// solution
$alpha   = array_flip(range('a', 'z'));
$travel  = 0;
$pointer = 0;

for ($i = 0; $i < strlen($string); $i++) {
    $clockwise = abs($pointer - $alpha[$string[$i]]);

    $counterclockwise = 26 - $clockwise;

    $travel += min($clockwise, $counterclockwise);

    $pointer = $alpha[$string[$i]];
}

echo "$travel\n";

<?php

//=====================================
// link: https://codeforces.com/contest/731/problem/A
//=====================================

// get inputs
$string = trim(fgets(STDIN));

// solution
$alpha   = array_flip(range('a', 'z'));
$travel  = 0;
$pointer = 0;

for ($i = 0; $i < strlen($string); $i++) {
    $clockwise = abs($pointer - $alpha[$string[$i]]);

    $counterclockwise = 26 - abs($pointer - $alpha[$string[$i]]);

    $travel += min($clockwise, $counterclockwise);

    $pointer = $alpha[$string[$i]];
}

echo "$travel\n";

<?php

###### IO ######
error_reporting(E_ALL);
error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	if ($is_test)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	$aPos = str_split('qzawsxedcrfvtgpbyhnujmiklo');
	sort($aPos);
	$aPos = implode('', $aPos);
	$totalLen = strlen($aPos);

	$inputStr = readString($stream);
	$return = 0;
	while (!empty($inputStr)) {
		$char = $inputStr[0];
		$pos = strpos($aPos, $char);
		$left = $totalLen - $pos;
		if ($pos < $left) {
			$return+=$pos;
		} else {
			$return+=$left;
		}
		$aPos = substr($aPos, $pos) . substr($aPos, 0, $pos);

		$inputStr = substr($inputStr, 1);
	}
	echo $return;
	/* / end body */
}

if (empty($is_test))
	getAnswer();

<?php
# Alireza
# JAHANI
# PH_PY_LA
# Dont Repeat Your self ...

$input = str_split(trim(fgets(STDIN)));
$alpha = range('a','z');
$alpha = array_flip($alpha);
$s = 0 ;

for ($i=0;$i<count($input)-1;$i++) {
      $a = abs($alpha[$input[$i]] - $alpha[$input[$i+1]]);
      $b =26 - $a ;
      $s += min($a,$b);
}
$a = abs($alpha[$input[0]] - $alpha['a']);
$b =26 - $a ;
echo $s+min($a,$b);

<?php
$str=trim(fgets(STDIN));
$alpha='abcdefghijklmnopqrstuvwxyz';
$split=str_split($alpha,1);
//$revAlpha=strrev($alpha);

$concate='a'.$str;
//echo "$concate";
$count=0;
for($i=0;$i<strlen($concate)-1;$i++)
{
	$keyDistance=abs(ord($concate[$i])-ord($concate[$i+1]));
	//echo "$keyDistance\n";
	if($keyDistance>13)
   {
   	     $k1[$i]=array_keys($split,$concate[$i]);
   	    // print_r($k1);
   	     //$key1=$k1[$i];
   	    //
   	     $k2[$i]=array_keys($split,$concate[$i+1]);
   	    //print_r($k2);
   	     //$key2=$k2[$i];
   	     if($k1[$i]>$k2[$i]){

   	       $temp[$i]=$k1[$i];
   	       $k1[$i]=$k2[$i];
   	       $k2[$i]=$temp[$i];

   	   }

   $count+=($k1[$i][0]+26)-$k2[$i][0];
   //echo "plus=$count\n";
   }
   else
   {
   	   	  $k1[$i]=array_keys($split,$concate[$i]);
   	     //$key1=$k1[$i];
   	    //
   	     $k2[$i]=array_keys($split,$concate[$i+1]);
   	     //$key2=$k2[$i];

         $count+=abs($k1[$i][0]-$k2[$i][0]);
   //echo "minus=$count\n";

   }
   //print_r($k1);
  // print_r($k2);

}
echo "$count";

//print_r($keyDistance);

<?php
$line = trim(fgets(STDIN));
function dis($a,$b){
    if($a == $b) return 0;
    if(ord($a)> ord($b)){
        $tmp = $a;
        $a = $b;
        $b = $tmp;
    }
    $i = abs(intval(ord($a) - ord($b)));
    $j = abs(intval(ord($a) - ord('a'))) + abs(intval(ord('z')) - ord($b)) + 1;
//    echo "a: $a  b: $b" . PHP_EOL;
//    echo "i: $i  j: $j " . PHP_EOL;
    return min($i,$j);
}
$current = 'a';
$sum = 0;
foreach(str_split($line) as $c){
    $sum += dis($c,$current);
    $current = $c;
}
echo $sum . PHP_EOL;

<?php

$stdout = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");

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

$count = 0 ;
$temp = "a" ;

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

     if( abs( ord($s[$i]) - ord($temp)) <= abs( 26 - abs( ord($s[$i]) - ord($temp)) ) )
     {
          $count += abs( ord($s[$i]) - ord($temp)) ;
     }
     else
     {
          $count += abs( 26 - abs( ord($s[$i]) - ord($temp)) ) ;
     }
     $temp = $s[$i] ;
}
echo $count ;

fwrite($stdout);

fclose($stdin);
fclose($stdout);

?>

<?php

define("CHARACTER_LIST", ['a', 'b', 'c', 'd', 'f', 'e', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']);

$word = trim(fgets(STDIN));

$wordLetters = str_split($word);

$prevPosition = 0;
$steps = 0;
foreach ($wordLetters as $letter) {
  $letterNumber = array_search($letter, CHARACTER_LIST);

  $stepsCount = abs($letterNumber - $prevPosition);

  if ($stepsCount >= 13) {
    $actualStepsCount = count(CHARACTER_LIST) - $stepsCount;
    $steps += $actualStepsCount;

    $prevPosition = $letterNumber;
  } else {
    $actualStepsCount = $stepsCount;
    $steps += $actualStepsCount;

    $prevPosition = $letterNumber;
  }
}

echo $steps;

<?php

define("CHARACTER_LIST", ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']);

// $word = trim(fgets(STDIN));

$word = "zeus";

$wordLetters = str_split($word);

$prevPosition = 0;
$steps = 0;
foreach ($wordLetters as $letter) {
  $letterNumber = array_search($letter, CHARACTER_LIST);

  $stepsCount = abs($letterNumber - $prevPosition);

  if ($stepsCount >= 13) {
    $actualStepsCount = count(CHARACTER_LIST) - $stepsCount;
    $steps += $actualStepsCount;

    $prevPosition = $letterNumber;
  } else {
    $actualStepsCount = $stepsCount;
    $steps += $actualStepsCount;

    $prevPosition = $letterNumber;
  }
}

echo $steps;

<?php
$line = trim(fgets(STDIN));
function dis($a,$b){
    if(ord($a)> ord($b)){
        $tmp = $a;
        $a = $b;
        $b = $tmp;
    }
    $i = abs(intval(ord($a) - ord($b)));
    $j = abs(intval(ord($a) - ord('a'))) + abs(intval(ord('z')) - ord($b));
//    echo "a: $a  b: $b" . PHP_EOL;
//    echo "i: $i  j: $j " . PHP_EOL;
    return min($i,$j);
}
$current = 'a';
$sum = 0;
foreach(str_split($line) as $c){
    $sum += dis($c,$current);
    $current = $c;
}
echo $sum . PHP_EOL;
exit;


Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more. Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.

The first line contains a non-empty word s. The second line contains a non-empty word t. Words s and t are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.

In the single line print the answer to the problem. Print "need tree" (without the quotes) if word s cannot be transformed into word t even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem. It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.

NoteIn the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

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

$automat = false;
$array = false;

$r = str_split($t);
$pattern = '/.*'.implode('.*',$r).'.*/U';

//echo $pattern;

$result = preg_match($pattern,$s,$match);

if (isset($match[0])){
    echo ("automaton");
    exit;
}

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

$t = str_split($t);
sort($t);
$t = implode('',$t);

//var_dump($s,$t);

$r = str_split($t);
$pattern = '/.*'.implode('.*',$r).'.*/U';
$result = preg_match($pattern,$s,$match);

//var_dump($match);

if (isset($match[0])){
    if ($t==$s){
        echo "array";
    } else {
        echo "both";
    }
    exit;
}
echo "need tree";

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

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

$automat = false;
$array = false;

$r = str_split($t);
$pattern = '/.*'.implode('.*',$r).'.*/';
$result = preg_match($pattern,$s,$match);

if (isset($match[0])){
    echo ("automaton");
    exit;
}

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

$t = str_split($t);
sort($t);
$t = implode('',$t);

//var_dump($s,$t);

$r = str_split($t);
$pattern = '/.*'.implode('.*',$r).'.*/';
$result = preg_match($pattern,$s,$match);

//var_dump($match);

if (isset($match[0])){
    if ($t==$s){
        echo "array";
    } else {
        echo "both";
    }
    exit;
}
echo "need tree";

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

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

$automat = false;
$array = false;

if (strpos($s,$t)!==false){
    echo ("automaton");
    exit;
}

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

$t = str_split($t);
sort($t);
$t = implode('',$t);

//var_dump($s,$t);

if (strpos($s,$t)!==false){
    if ($t==$s){
        echo "array";
    } else {
        echo "both";
    }
    exit;
} else {
    echo "need tree";
}

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

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

$automat = false;
$array = false;

$r = str_split($t);
$pattern = '/.*'.implode('.*',$r).'.*/';
$result = preg_match($pattern,$s,$match);

if (isset($match[0])){
    echo ("automaton");
    exit;
}

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

$t = str_split($t);
sort($t);
$t = implode('',$t);

//var_dump($s,$t);

if (strpos($s,$t)!==false){
    if ($t==$s){
        echo "array";
    } else {
        echo "both";
    }
    exit;
} else {
    echo "need tree";
}


At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c1 schoolchildren got 1 point, c2 children got 2 points, ..., cm children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive. Help the university pick the passing rate in a way that meets these requirements.

The first line contains integer m (2 ≤ m ≤ 100). The second line contains m integers c1, c2, ..., cm, separated by single spaces (0 ≤ ci ≤ 100). The third line contains two space-separated integers x and y (1 ≤ x ≤ y ≤ 10000). At least one ci is greater than 0.

If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.

NoteIn the first sample the beginner group has 7 students, the intermediate group has 6 of them. In the second sample another correct answer is 3.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
list($c, $d) = explode(" ", trim(fgets(STDIN)));
$g = 0;
for($x = 1; $x <= $a; $x++)
{
    $e = array_sum(array_slice($b, 0, $x));
    $f = array_sum(array_slice($b, $x));
    if((($e >= $c) && ($e <= $d)) && (($f >= $c) && ($f <= $d)))
    {
        $g = 1;
        break;
    }
}
if($g == 0)
{
    print "0";
}
else
{
    print $x + 1;
}
?>

<?
$m = trim(fgets(STDIN));
$c = explode(' ', trim(fgets(STDIN)));
list($x,$y)=explode(' ', trim(fgets(STDIN)));
for($k=1; $k<=$m; $k++){
    $b = 0;
    $a = 0;
    foreach($c as $key=>$c1){
        if($k>$key+1){
            $b += $c1;
        }else{
            $a += $c1;
        }
    }
    if($b<$x || $b>$y || $a<$x || $a>$y){
        continue;
    }else{
        print $k;
        die();
    }
}
print 0;

<?php
$in = fopen('php://stdin', "r");
$chs=array();
fscanf($in, "%d", $m);
$chs = explode(" ",fgets($in));
fscanf($in, "%d %d", $x, $y);
$g1=$g2=$k=0;
foreach($chs as $key => $value){
    unset($chs[$key]);
    if($g1+$value<=$y && (array_sum($chs)>=$y||array_sum($chs)>=$x) && $g2==0) $g1+=$value;
    else {
        $g2+=$value;
        if($k==0) $k=$key+1;
    }
}
if(($g1<$x||$g1>$y)||($g2<$x||$g2>$y)) $k=0;
echo $k;
fclose($in);

<?php
$in = fopen('php://stdin', "r");
$chs=array();
fscanf($in, "%d", $m);
$chs = explode(" ",fgets($in));
fscanf($in, "%d %d", $x, $y);
$g1=$g2=$k=0;
foreach($chs as $key => $value){
    if($g1<$x) $g1+=$value;
    else {
        $g2+=$value;
        if($k==0) $k=$key+1;
    }
}
echo $k;
fclose($in);


The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to n - 1 in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from 2 to n in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house 1 is opposite house n, house 3 is opposite house n - 2, house 5 is opposite house n - 4 and so on.  Vasya needs to get to house number a as quickly as possible. He starts driving from the beginning of the street and drives his car to house a. To get from the beginning of the street to houses number 1 and n, he spends exactly 1 second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same.Your task is: find the minimum time Vasya needs to reach house a.

The first line of the input contains two integers, n and a (1 ≤ a ≤ n ≤ 100 000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number n is even.

Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house a.

NoteIn the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.The second sample corresponds to picture with n = 8. House 5 is the one before last at Vasya's left.

<?php

list($count, $a) = explode(" ", fgets(STDIN), 3);

if ($a % 2 == 0) {
    // четная сторона - убывание
    $time = 1 + $count / 2 - floor($a / 2);
} else {
    // нечетная сторона - возрастание
    $time = 1 + floor($a / 2);
}

echo $time;

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

$inp = explode(" ", $inp);

$street1[1] = 1;
$street2[1] = $inp[0];

for ($i=2; $i <= $inp[0]/2; $i++) {
  $street1[$i] = $street1[$i-1] + 2;
  $street2[$i] = $street2[$i-1] - 2;
}

if (($inp[1] % 2) != 0) {
  $result = array_search($inp[1], $street1);
} else {
  $result = array_search($inp[1], $street2);
}

echo $result;

<?
$stdin = fopen('php://stdin', 'r');
$a = fgets($stdin);
$t = explode(" ", $a);
$n = trim($t[0]);
$d = trim($t[1]);

if($d % 2 == 0){
    $stdout = fopen('php://stdout', 'w');
    fwrite($stdout, floor(($n - $d) / 2) + 1);
    fclose($stdout);
}else{
    $stdout = fopen('php://stdout', 'w');
    fwrite($stdout, floor($d / 2) + 1);
    fclose($stdout);
}

?>

<?php

function getnum(&$c = null)
{
    for ($c = fgetc(STDIN); false !== strpos(" \t\n\r\0\x0B", $c);$c = fgetc(STDIN));
    $result = ''; do { if (!is_numeric($c) && $c !== '.') break; $result .= $c; } while (null !== $c = fgetc(STDIN));

    return (float)$result;
}

$n = getnum();
$a = getnum();

if ($a % 2) {
    echo (++$a / 2) .PHP_EOL;
    return ;
}

echo (($n - $a) / 2 + 1) . PHP_EOL;


Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (x, y - 1). Vasiliy can move his pawn from (x, y) to one of cells: (x - 1, y), (x - 1, y - 1) and (x, y - 1). Both players are also allowed to skip move. There are some additional restrictions — a player is forbidden to move his pawn to a cell with negative x-coordinate or y-coordinate or to the cell containing opponent's pawn The winner is the first person to reach cell (0, 0). You are given the starting coordinates of both pawns. Determine who will win if both of them play optimally well.

The first line contains four integers: xp, yp, xv, yv (0 ≤ xp, yp, xv, yv ≤ 105) — Polycarp's and Vasiliy's starting coordinates. It is guaranteed that in the beginning the pawns are in different cells and none of them is in the cell (0, 0).

Output the name of the winner: "Polycarp" or "Vasiliy".

NoteIn the first sample test Polycarp starts in (2, 1) and will move to (1, 1) in the first turn. No matter what his opponent is doing, in the second turn Polycarp can move to (1, 0) and finally to (0, 0) in the third turn.

<?php
list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
if($a == 0)
{
    if(($d > $c) && ($d >= $b))
    {
        print "Polycarp";
    }
    elseif(($d > $c) && ($d < $b))
    {
        print "Vasiliy";
    }
    elseif(($d <= $c) && ($c >= $b))
    {
        print "Polycarp";
    }
    elseif(($d <= $c) && ($c < $b))
    {
        print "Vasiliy";
    }
}
elseif($b == 0)
{
    if(($d > $c) && ($d >= $a))
    {
        print "Polycarp";
    }
    elseif(($d > $c) && ($d < $a))
    {
        print "Vasiliy";
    }
    elseif(($d <= $c) && ($c >= $a))
    {
        print "Polycarp";
    }
    elseif(($d <= $c) && ($c < $a))
    {
        print "Vasiliy";
    }
}
elseif($c == 0)
{
    if(($a + $b) <= $d)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
elseif($d == 0)
{
    if(($a + $b) <= $c)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
elseif(($a <= $c) && ($b <= $d))
{
    print "Polycarp";
}
elseif(($a >= $c) && ($b >= $d))
{
    print "Vasiliy";
}
else
{
    if(($d > $c) && ($d >= $a + $b))
    {
        print "Polycarp";
    }
    elseif(($d > $c) && ($d < $a + $b))
    {
        print "Vasiliy";
    }
    elseif(($d <= $c) && ($c >= $a + $b))
    {
        print "Polycarp";
    }
    elseif(($d <= $c) && ($c < $a + $b))
    {
        print "Vasiliy";
    }
}
?>

<?php
list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
if($a == 0)
{
    if(($d > $c) && (($c + $d - $c) >= $b))
    {
        print "Polycarp";
    }
    elseif(($d > $c) && (($c + $d - $c) < $b))
    {
        print "Vasiliy";
    }
    elseif(($d <= $c) && ($c >= $b))
    {
        print "Polycarp";
    }
    elseif(($d <= $c) && ($c < $b))
    {
        print "Vasiliy";
    }
}
elseif($b == 0)
{
    if(($d > $c) && (($c + $d - $c) >= $a))
    {
        print "Polycarp";
    }
    elseif(($d > $c) && (($c + $d - $c) < $a))
    {
        print "Vasiliy";
    }
    elseif(($d <= $c) && ($c >= $a))
    {
        print "Polycarp";
    }
    elseif(($d <= $c) && ($c < $a))
    {
        print "Vasiliy";
    }
}
elseif(($a <= $c) && ($b <= $d))
{
    print "Polycarp";
}
elseif(($a >= $c) && ($b >= $d))
{
    print "Vasiliy";
}
else
{
    if(($a + $b) <= $c)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
?>

<?php
list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
if($a == 0)
{
    if(($c + $d - $c) >= $b)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
elseif($b == 0)
{
    if(($c + $d - $c) >= $a)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
elseif(($a <= $c) && ($b <= $d))
{
    print "Polycarp";
}
elseif(($a >= $c) && ($b >= $d))
{
    print "Vasiliy";
}
else
{
    if(($a + $b) <= $c)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
?>

<?php
list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
if($a == 0)
{
    if(($d > $c) && (($c + $d - $c) >= $b))
    {
        print "Polycarp";
    }
    elseif(($d > $c) && (($c + $d - $c) < $b))
    {
        print "Vasiliy";
    }
    elseif(($d <= $c) && ($c >= $b))
    {
        print "Polycarp";
    }
    elseif(($d <= $c) && ($c < $b))
    {
        print "Vasiliy";
    }
}
elseif($b == 0)
{
    if(($d > $c) && (($c + $d - $c) >= $a))
    {
        print "Polycarp";
    }
    elseif(($d > $c) && (($c + $d - $c) < $a))
    {
        print "Vasiliy";
    }
    elseif(($d <= $c) && ($c >= $a))
    {
        print "Polycarp";
    }
    elseif(($d <= $c) && ($c < $a))
    {
        print "Vasiliy";
    }
}
elseif(($a <= $c) && ($b <= $d))
{
    print "Polycarp";
}
elseif(($a >= $c) && ($b >= $d))
{
    print "Vasiliy";
}
else
{
    if(($a + $b) <= ($c + $d - $c))
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
?>

<?php
list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
if($a == 0)
{
    if(($d > $c) && ($d >= $b))
    {
        print "Polycarp";
    }
    elseif(($d > $c) && ($d < $b))
    {
        print "Vasiliy";
    }
    elseif(($d <= $c) && ($c >= $b))
    {
        print "Polycarp";
    }
    elseif(($d <= $c) && ($c < $b))
    {
        print "Vasiliy";
    }
}
elseif($b == 0)
{
    if(($d > $c) && ($d >= $a))
    {
        print "Polycarp";
    }
    elseif(($d > $c) && ($d < $a))
    {
        print "Vasiliy";
    }
    elseif(($d <= $c) && ($c >= $a))
    {
        print "Polycarp";
    }
    elseif(($d <= $c) && ($c < $a))
    {
        print "Vasiliy";
    }
}
elseif($c == 0)
{
    if(($a + $b) <= $d)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
elseif($d == 0)
{
    if(($a + $b) <= $c)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
elseif(($a <= $c) && ($b <= $d))
{
    print "Polycarp";
}
elseif(($a >= $c) && ($b >= $d))
{
    print "Vasiliy";
}
else
{
    if(($a + $b) <= $c)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
?>

<?php
list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
if($a == 0)
{
    if($c >= $b)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
elseif($b == 0)
{
    if($c >= $a)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
elseif(($a <= $c) && ($b <= $d))
{
    print "Polycarp";
}
elseif(($a >= $c) && ($b >= $d))
{
    print "Vasiliy";
}
else
{
    if(($a + $b) <= $c)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
?>

<?php
list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
if($a == 0)
{
    if(($d > $c) && (($c + $d - $c) >= $b))
    {
        print "Polycarp";
    }
    elseif(($d > $c) && (($c + $d - $c) < $b))
    {
        print "Vasiliy";
    }
    elseif(($d < $c) && ($c >= $b))
    {
        print "Polycarp";
    }
    elseif(($d < $c) && ($c < $b))
    {
        print "Vasiliy";
    }
}
elseif($b == 0)
{
    if(($d > $c) && (($c + $d - $c) >= $a))
    {
        print "Polycarp";
    }
    elseif(($d > $c) && (($c + $d - $c) < $a))
    {
        print "Vasiliy";
    }
    elseif(($d < $c) && ($c >= $a))
    {
        print "Polycarp";
    }
    elseif(($d < $c) && ($c < $a))
    {
        print "Vasiliy";
    }
}
elseif(($a <= $c) && ($b <= $d))
{
    print "Polycarp";
}
elseif(($a >= $c) && ($b >= $d))
{
    print "Vasiliy";
}
else
{
    if(($a + $b) <= $c)
    {
        print "Polycarp";
    }
    else
    {
        print "Vasiliy";
    }
}
?>


Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.

The only line of the input is in one of the following two formats:    "x of week" where x (1 ≤ x ≤ 7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday.  "x of month" where x (1 ≤ x ≤ 31) denotes the day of the month.

Print one integer — the number of candies Limak will save in the year 2016.

NotePolar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – https://en.wikipedia.org/wiki/Gregorian_calendar. The week starts with Monday.In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total.

<?php
list($x, $y, $wm) = explode(" ", trim(fgets(STDIN)));
$x = (int) $x;

switch ($wm) {
	case 'week':
		if ($x == 5 || $x == 6) $n = 53;
		else $n = 52;
		break;
	case 'month':
		if ($x == 31) $n = 7;
		else if ($x == 30) $n = 11;
		else $n = 12;
		break;
}
print $n;
?>

<?php
list($x, $y, $wm) = explode(" ", trim(fgets(STDIN)));
$x = (int) $x;

switch ($wm) {
	case 'week':
		if ($x == 3 || $x ==4) $n = 52;
		else $n = 53;
		break;
	case 'month':
		if ($x == 31) $n = 7;
		else if ($x == 30) $n = 11;
		else $n = 12;
		break;
}
print $n;
?>

<?php
list($x, $y, $wm) = explode(" ", trim(fgets(STDIN)));
$x = (int) $x;

switch ($wm) {
	case 'week':
		if ($x == 5 || $x == 6) $n = 53;
		else $n = 53;
		break;
	case 'month':
		if ($x == 31) $n = 7;
		else if ($x == 30) $n = 11;
		else $n = 12;
		break;
}
print $n;
?>


This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that they found p grams of salt.To make a toast, each friend needs nl milliliters of the drink, a slice of lime and np grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?

The first and only line contains positive integers n, k, l, c, d, p, nl, np, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.

Print a single integer — the number of toasts each friend can make.

NoteA comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is min(6, 80, 100) / 3 = 2.

<?
stream_set_blocking(STDIN, 0);
fscanf(STDIN, "%d %d %d %d %d %d %d %d", $n, $k, $l, $c, $d, $p, $nl, $np);

$gaz = (int)(($k*$l)/$nl);
$laims = (int)($c*$d);
$solt = (int)$p/$np;
echo (int)(min($gaz,$laims,$solt)/$n);
?>

<?php

function solve(){
	//$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	//$W_first = $Token->nextInt();
	//$B_first = $Token->nextInt();

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	//$inp_arr = $Token->nextIntArray(8);
	$inp_arr = $Token->nextIntArray();

	$inp_f = $inp_arr[0];
	$inp_k = $inp_arr[1];
	$inp_l = $inp_arr[2];
	$inp_c = $inp_arr[3];
	$inp_d = $inp_arr[4];
	$inp_p = $inp_arr[5];
	$inp_nl = $inp_arr[6];
	$inp_np = $inp_arr[7];

	$drink = (int)(($inp_k * $inp_l) / $inp_nl);
	$salt = (int)($inp_p / $inp_np);
	$lime = $inp_c * $inp_d;
	/*$arr[] = $drink;
	$arr[] = $salt;
	$arr[] = $lime;

	//$min = min($arr);
	if (asort(&$arr) === false) {
		print(-1);
		return;
	}
	$min = $arr[0];

	*/
	//�ŏ��l�����߂鏈��
	//�f�[�^�������Ƃ��A$min = min($arr);
	$min = min($drink, $salt, $lime);
	$ans = (int)($min / $inp_f);
	printf("%d", $ans);

}

function run(){
	solve();
}

ob_end_clean();
run();

//input -  $inp_
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $_

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

function num_printf($i){
	if (is_float($i)) {
		printf("%.10f", $i);
	}
	if (is_int($i)) {
		printf("%10d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}
?>

<?php
list($n, $k, $l, $c, $d, $p, $nl, $np) = explode(' ', fgets(STDIN));

$Gas = $k * $l;
$lime = $c * $d;

$MinGas = floor($Gas / ($n * $nl));
$MinLime = floor($lime / $n);
$MinSalt = floor($p / ($n * $np));

$Min = min($MinGas, $MinLime, $MinSalt);

echo $Min;
?>

<?php
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum= explode(" ",$n);
$n=$dum[0];
$k=$dum[1];
$l=$dum[2];
$c=$dum[3];
$d=$dum[4];
$p=$dum[5];
$nl=$dum[6];
$np=$dum[7];
$aa = floor($k*$l/$nl);
$bb = $c*$d;
$cc = floor($p/$np);
echo floor(min($aa,$bb,$cc)/$n);
?>

<?php
list($n, $k, $l, $c, $d, $p, $nl, $np) = explode(' ', trim(fgets(STDIN)));

$vsego_gaz = $k * $l;
$tost = floor($vsego_gaz / $nl);
$laim = $c * $d;
$sol = floor($p / $np);
$itog = floor(min($tost, $laim, $sol) / $n);
echo $itog;
?>

<?php
list($n, $k, $l, $c, $d, $p, $nl, $np) = explode(' ', fgets(STDIN));

$Gas = $k * $l;
$lime = $c * $d;

$MinGas = floor($Gas / ($n * $nl));
$MinLime = floor($lime / $n);
$MinSalt = floor($lime / ($n * $np));

$Min = min($MinGas, $MinLime, $MinSalt);

echo $Min;
?>

<?php
list($n, $k, $l, $c, $d, $p, $nl, $np) = explode(' ', trim(fgets(STDIN)));

$vsego_gaz = $k * $l;
$tost = floor($vsego_gaz / $n);
$laim = $c * $d;
$sol = floor($p / $np);
$itog = floor(min($tost, $laim, $sol) / $n);
echo $itog;
?>


In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.

The single line contains six integers a1, ..., a6 (0 ≤ ai ≤ 1000) — scores of the participants

Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise. You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").

NoteIn the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.In the second sample, score of participant number 6 is too high: his team score will be definitely greater.


The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now $$$n$$$ cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are $$$m$$$ cats who left the circle. This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?Could you help her with this curiosity?You can see the examples and their descriptions with pictures in the "Note" section.

The only line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 1000$$$, $$$0 \leq m \leq n$$$) — the initial number of cats at the party and the number of cats who left the circle at the moment Katie observes, respectively.

Print a single integer — the maximum number of groups of cats at the moment Katie observes.

NoteIn the first example, originally there are $$$7$$$ cats sitting as shown below, creating a single group:  At the observed moment, $$$4$$$ cats have left the table. Suppose the cats $$$2$$$, $$$3$$$, $$$5$$$ and $$$7$$$ have left, then there are $$$3$$$ groups remaining. It is possible to show that it is the maximum possible number of groups remaining.  In the second example, there are $$$6$$$ cats sitting as shown below:  At the observed moment, $$$2$$$ cats have left the table. Suppose the cats numbered $$$3$$$ and $$$6$$$ left, then there will be $$$2$$$ groups remaining ($$$\{1, 2\}$$$ and $$$\{4, 5\}$$$). It is impossible to have more than $$$2$$$ groups of cats remaining.  In the third example, no cats have left, so there is $$$1$$$ group consisting of all cats.In the fourth example, all cats have left the circle, so there are $$$0$$$ groups.

<?php
# 1163A
declare(strict_types=1);

[$n, $m] = fscanf(STDIN, '%u %u');

if ($n === $m) {
    echo 0;
} elseif($m < 2) {
    echo 1;
} elseif (floor($n / 2) < $m) {
    echo $n - $m;
} else {
    echo $m;
}

<?php
     $n = explode(" ", trim(fgets(STDIN)));
     echo min(max(1,$n[1]),$n[0]-$n[1]);
?>

<?php

$line = fgets(STDIN);

sscanf($line, '%d %d', $a, $b);

function f($a, $b) {
    if ($b == 0) {
        return 1;
    }
    $out = $a - $b;
    return min($out, $b);
}

echo f($a, $b);

<?php
    list($n, $m) = explode(" ", trim(fgets(STDIN)));
    if ($n/2 <= $m) {
        echo $n - $m;
    } else {
        if ($m == 0) {
            echo 1;
        } else {
            echo $m;
        }
    }
?>


PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number".Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any n.

The only number in the input is n (1 ≤ n ≤ 1000) — number from the PolandBall's hypothesis.

Output such m that n·m + 1 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1 ≤ m ≤ 103. It is guaranteed the the answer exists.

NoteA prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.For the first sample testcase, 3·1 + 1 = 4. We can output 1.In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, m = 2 is okay since 4·2 + 1 = 9, which is not a prime number.

<?php

$n = trim(fgets(STDIN));
foreach (range(1, 1000) as $i) {
    $res = $n*$i+1;
    if (!simple($res) && $i >= 1 && $i <= 1000) {
        echo $i;
        break;
    }
}

function simple($n)
{
   for($i = 2; $i <= sqrt($n); $i++) {
      if (!($n % $i)) {
          return false;
      }
   }
   return true;
}

<?php

$n = $argv[1];
if ($n > 1) {
    foreach (range(1, $n) as $i) {
        $res = $n*$i+1;
        if (!simple($res) && $i >= 1 && $i <= 1000) {
            //echo $res . "=" . $n . "*". $i . "+1"  . "\n";
            echo $i;
            break;
        }
    }
} else {
    echo $i;
}

function simple($n)
{
   for($i = 2; $i <= sqrt($n); $i++) {
      if (!($n % $i)) {
          return false;
      }
   }
   return true;
}

<?php

$n = trim(fgets(STDIN));

    foreach (range(1, $n) as $i) {
        $res = $n*$i+1;
        if (!simple($res) && $i >= 1 && $i <= 1000) {
            echo $i;
            break;
        }
    }

function simple($n)
{
   for($i = 2; $i <= sqrt($n); $i++) {
      if (!($n % $i)) {
          return false;
      }
   }
   return true;
}

<?php

$n = trim(fgets(STDIN));
if ($n > 1) {
    foreach (range(1, $n) as $i) {
        $res = $n*$i+1;
        if (!simple($res) && $i >= 1 && $i <= 1000) {
            echo $i;
            break;
        }
    }
} else {
    echo $i;
}

function simple($n)
{
   for($i = 2; $i <= sqrt($n); $i++) {
      if (!($n % $i)) {
          return false;
      }
   }
   return true;
}

<?php

$n = $argv[1];
foreach (range(1, $n) as $i) {
    $res = $n*$i+1;
    if (!simple($res) && $res >= 1 && $res <= 1000) {
        //echo $res . "=" . $n . "*". $i . "+1"  . "\n";
        echo $i;
        break;
    }
}

function simple($n)
{
   for($i = 2; $i <= sqrt($n); $i++) {
      if (!($n % $i)) {
          return false;
      }
   }
   return true;
}

<?php

$n = trim(fgets(STDIN));
if ($n > 2) {
    foreach (range(1, $n) as $i) {
        $res = $n*$i+1;
        if (!simple($res) && $i >= 1 && $i <= 1000) {
            echo $i;
            break;
        }
    }
} else {
    echo $i;
}
echo "\n";

function simple($n)
{
   for($i = 2; $i <= sqrt($n); $i++) {
      if (!($n % $i)) {
          return false;
      }
   }
   return true;
}

<?php

$n = trim(fgets(STDIN));
if ($n > 2) {
    foreach (range(1, $n) as $i) {
        $res = $n*$i+1;
        if (!simple($res) && $i >= 1 && $i <= 1000) {
//            echo $i;
            fwrite(STDOUT, $i);
            break;
        }
    }
} else {
    echo $i;
}

function simple($n)
{
   for($i = 2; $i <= sqrt($n); $i++) {
      if (!($n % $i)) {
          return false;
      }
   }
   return true;
}


A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?

The only line of the input contains five integers t1, t2, t3, t4 and t5 (1 ≤ ti ≤ 100) — numbers written on cards.

Print the minimum possible sum of numbers written on remaining cards.

NoteIn the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.  Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40.  Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26.  Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34. You are asked to minimize the sum so the answer is 26.In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$cards = explode(" ",$s);
$counts = array_count_values($cards);
$ar=[];
$max=0;
foreach($counts as $k=>$v){

	if($v>2){
		if(($k*3)>$max){
			$max=$k*3;
		}
	}elseif($v==2){
		if(($k*2)>$max){
			$max=$k*2;
		}
	}
}
echo (array_sum($cards)-$max);

<?php
error_reporting(0);
function process ($a) {
	/*cant solve 7 7 7 8 8
	rsort($a);
	$asum = array_sum($a);
	for ($i=0; $i<5; $i++)
		if(($a[$i]==$a[$i+1])&&($a[$i+1]==$a[$i+2])) {
			return $asum-$a[$i]*3;
		}elseif($a[$i]==$a[$i+1]) {
			return $asum-$a[$i]*2;
		}
	return $asum;
	*/
	$z = array_count_values($a);
	krsort($z);
	$max = 0;
	foreach ($z as $key => $value) {
		if ($value != 1) {
			if ($value > 3) $value = 3;
			if ($key * $value > $max) $max = $key * $value;
		}
	}
	$asum = array_sum($a);
	return $asum - $max;
}
$in = trim(fgets(STDIN));
$cards = explode(' ', $in);
echo process($cards);
?>

<?php

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

$allSum = array_sum($list);
$data = array_count_values($list);
$values = [];
foreach($data as $key => $count) {
    if ($count > 3) {
        $count = 3;
    }
    if($count >= 2) {
        $values[] = $key * $count;
    }
}

if(!empty($values)) {
    echo $allSum - max($values);
} else {
    echo $allSum;
}

<?php
error_reporting(0);
function process ($a) {
	rsort($a);
	$asum = array_sum($a);
	for ($i=0; $i<5; $i++)
		if(($a[$i]==$a[$i+1])&&($a[$i+1]==$a[$i+2])) {
			return $asum-$a[$i]*3;
		}elseif($a[$i]==$a[$i+1]) {
			return $asum-$a[$i]*2;
		}
	return $asum;
}
$in = trim(fgets(STDIN));
$cards = explode(' ', $in);
echo process($cards);
?>

<?php

$list= explode(' ', trim(fgets(stdin)));

$allSum = array_sum($list);
$data = array_count_values($list);
$values = [];
foreach($data as $key => $count) {
    if ($count > 3) {
        $count = 3;
    }
    if($count >= 2) {
        $values[] = $key * $count;
    }
}

if(!empty($values)) {
    echo $allSum - max($values);
} else {
    echo $allSum;
}


The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches .Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible.

The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).

Output the number of the highest suitable branch. If there are none, print -1 instead.

NoteIn the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.It immediately follows that there are no valid branches in second sample case.

<?php

fscanf(STDIN, '%d %d\n', $p, $y);
for($i = $y; $i >= $p + 1; $i--){
  $stop = FALSE;
  for($j = 2 ; $j <= min(sqrt($i), $p); $j++){
    if($i % $j == 0){
      $stop = TRUE;
      break;
    }
  }
  if(!$stop){
    echo $i;
    exit;
  }
}
echo '-1';

<?php
    list($p, $y) = explode(" ", fgets(STDIN));
    $p = (int)$p;
    $y = (int)$y;

    $k = '-1';
    for ($n=$y; $n > $p; $n--) {
        if (method($n, $p, $y)) {
            continue;
        } else {
            $k = $n;
            break;
        }
    }
    echo $k;

    function method($s, $p, $y) {
        if ($s%2 == 0) {
           return true;
        }
        for ($i = $p; $i >= 2; $i--) {
            if ($s%$i) {
                return false;
            } else {
                if ($p < $s/$i && $s/$i <$y/$i) {
                    return true;
                } else {
                    return false;
                }
            }
        }

        return false;
    }

?>


Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky.

The single line contains an integer n (1 ≤ n ≤ 1000) — the number that needs to be checked.

In the only line print "YES" (without the quotes), if number n is almost lucky. Otherwise, print "NO" (without the quotes).

NoteNote that all lucky numbers are almost lucky as any number is evenly divisible by itself.In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.

<?php
$string = trim(fgets(STDIN));
$values = str_split($string);
$contador = 0;
for ($x = 0; $x < count($values); $x++) {
    if ($values[$x] == '7' || $values[$x] == '4') {
        $contador++;
    }
}

if ($contador ==count($values) || $string  % 4 == 0 || $string  % 7 == 0  || $string  % 47 == 0 ) {
    echo "YES";
} else {
    echo "NO";
}

<?php
    function isnum($num)
    {
        if($num <= 0) return false;
        while((int)$num != 0)
        {
            if($num % 10 != '7' && $num % 10 != '4')
                return false;
            $num = (int)($num /= 10);
        }
        return true;
    }
    $unum = fgets(STDIN);
    if(isnum($unum))
        echo "YES\n";
    else
    {
        for($c = 1; $c < $unum; ++$c)
        {
            if(isnum($c) && $unum % $c == 0)
            {
                echo "YES";
                exit;
            }
        }
        echo "NO\n";
    }
    exit;
?>

<?php
$input = trim(fgets(STDIN));
$lucky = FALSE;
$arr_lucky = array(4,7,44,47,74,77,444,447,474,477,744,747,774,777);
foreach($arr_lucky as $value)
{
	if($input%$value==0)
		$lucky = TRUE;
}
echo $lucky?"YES":"NO";
?>

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

    fscanf($stdin, "%s", $n);

    $len = strlen($n);

    $lucky = false;
    for($i=0; $i<$len; $i++){
        if($n[$i] == '4' && $n[$i+1] == '7') $lucky = true;
    }
    $almostLucky = false;
    $n = (int)$n;
    if($n%4 == 0 || $n%7 == 0 || $n%47 == 0) $almostLucky = true;

    if($lucky == true || $almostLucky == true) echo "YES";
    else echo "NO";

    fclose($stdin);
?>

<?php

/**
 * Петя любит счастливые числа. Всем известно, что счастливыми являются положительные целые числа, в десятичной записи которых содержатся только счастливые цифры 4 и 7. Например, числа 47, 744, 4 являются счастливыми, а 5, 17, 467 — не являются.
 *
 * Петя называет число почти счастливым, если оно делится без остатка на какое-либо счастливое число. Помогите ему узнать, является ли заданное число n почти счастливым?
 * Входные данные
 *
 * В единственной строке задано целое число n (1 ≤ n ≤ 1000) — число, которое нужно проверить.
 * Выходные данные
 *
 * В единственной строке выведите «YES» (без кавычек), если число n почти счастливое, иначе выведите «NO» (без кавычек).
 */

define('DEBUG', 0);

define('LIMIT', 1000);

function doLog($log) {
	if (DEBUG) {
		echo "[" . microtime(true) ."] " . $log . "\n";
	}
}

function combinations($chars, $length)
{
	doLog("Length $length.");
	if ($length == 1) {
		return array_merge($chars);
	}

	$results = [];
	foreach ($chars as $char) {
		foreach (combinations($chars, $length-1) as $combination) {
			$results[$combination] = $combination;
			$results[$char . $combination] = $char . $combination;
		}
	}

	return array_keys($results);
}

function solve($n)
{
	$happyDigits = ['4', '7'];

	$happyNumbers = combinations($happyDigits, 3);

	// seeding happy numbers
	$seed = array_fill(1, LIMIT, false);

	foreach ($happyNumbers as $happyNumber) {
		doLog("Seeding $happyNumber.");
		$index = 2*$happyNumber;
		while ($index <= LIMIT) {
			$seed[$index] = true;
			$index+=$happyNumber;
		}
	}

	foreach ($happyNumbers as $happyNumber) {
		$seed[$happyNumber] = true;
	}

	return $seed[$n] ? 'YES' : 'NO';
}

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

$result = solve($n);

doLog($result . "\n");

echo $result;

<?php

$n = (int) readline();

$test_cases = [4, 7, 47, 74, 44, 77, 444, 447, 474, 477, 744, 747, 777];
$flag = false;
foreach($test_cases as $num){
    if($n % $num == 0){
        $flag= true;
        break;
    }
}

if($flag){
    echo "YES";
}else{
    echo "NO";
}

<?php
$num = intval(fgets(STDIN));
$bookmark=0;
$happy = array(4,7,44,47,74,77,444,447,474,477,744,747,774,777);
foreach ($happy as $key) {
    if ($num % $key == 0) {
        $bookmark++;
    }
}
if ($bookmark>0)echo "YES";
else echo "NO";

<?php

for ($i = 1; $i < 1001; $i++) {
    $str[$i] = $i;
}
$happy_numbers = preg_grep('/^[47]{1}[47]*$/', $str);
fscanf(STDIN, '%d', $number);
$ch = 0;
foreach ($happy_numbers as $value) {
    if (($number % $value) == 0) {
        $ch = $ch + 1;
        break;
    }
}

if ($ch > 0) {
    echo "YES";
} else {
    echo "NO";
}

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

$result = false;

$number = (int) $s;

$digit_array = str_split($s, 1);
$lucky_array = array(4, 7);

$is_lucky = false;
foreach ($digit_array as $digit) {
    if (!in_array($digit, $lucky_array)){
        $is_lucky = false;
        break;
    }
    $is_lucky = true;
}

$is_almost_lucky = false;

if (($number % 4 == 0) || ($number % 7 == 0) || ($number % 44 == 0) || ($number % 47 == 0) || ($number % 74 == 0) || ($number % 77 == 0)) {
    $is_almost_lucky = true;
}
else {
    $is_almost_luck = false;
}

if ($is_lucky || $is_almost_lucky) {
    $result = true;
}

echo $result ? "YES" : "NO";

?>

<?php
$n = trim(fgets(STDIN));
$arr = array(4, 7, 47, 74, 447, 474, 477);
$str = "NO";
foreach($arr as $value){
    if ($n % $value == 0){
        $str = "YES";
        break;
    }
}
echo $str;
?>

<?php
$input = explode("\n", trim(file_get_contents("php://stdin")));
$hns = array(4,7,44,47,74,77,444,474,477,744,774,777);
$n = $input[0];
$result = 'NO';
foreach($hns as $hn){
    if($n%$hn == 0){
        $result = 'YES';
        break;
    }
}
echo $result;

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

function lucky_number ($num) {

    //Find All The Lucky Number Under (1000).
    $lucky = array(4,7,47,74,44,77,444,744,774,777,477,447,474,747);

    //Loop Throw The (Lucky) Array.
    for($i = 0;$i < count($lucky);$i++) {

        //Check If It's Divisible By a Lucky Number.
        if($num % $lucky[$i] == 0) {

            return "YES";

        }

    }

    return "NO";

}

echo lucky_number($input);

?>

<?php
// 122A 	   Счастливое деление

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

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

$out = 'NO';

for ($i=4; $i <= $n; $i++) {
    $str = (string) $i;
    if ((substr_count($str, '4') + substr_count($str, '7')) == strlen($str)) {
        if (($n % $i) == 0) {
            $out = 'YES';
            break;
        }
    }
}

echo $out;

?>

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

$counter = 0;

for ($i=0; $i < strlen($number); $i++) {
	if(($number[$i] == "4") || ($number[$i] == "7")){
		$counter++;
	}

}

if($counter == strlen($number)){
		echo "YES";
		exit();
	} elseif(intval($number) % 4 == 0) {
		echo "YES";
		exit();
	} elseif(intval($number) % 7 == 0) {
		echo "YES";
		exit();
	} elseif(intval($number) % 47 == 0) {
		echo "YES";
	} elseif(intval($number) % 74 == 0) {
		echo "YES";
	} else {
		echo "NO";
		exit();
	}

<?php
//打表
//for ($i = 1; $i <= 1000; $i++){
//
//}

while (fscanf(STDIN, "%s", $string)){
    $length = strlen($string);
    $lucky = 0;
    for ($i = 0; $i < $length; ++$i){
        if (4 == $string[$i] || 7 == $string[$i]){
            ++$lucky;
        }
    }

    if ($length == $lucky){
        echo "YES\n";
    } else {
        $number = (int)$string;
        $flag = 0;
        for ($n = 1; $n < $number; $n++){
            if ($number % $n == 0){
                $lucky = 0;
                $n_str = (string)$n;
                $n_length = strlen($n);
                for ($m = 0; $m < $n_length; $m++){
                    if (4 == $n_str[$m] || 7 == $n_str[$m]){
                        ++$lucky;
                    }
                }
                if ($lucky == $n_length){
                    echo "YES\n";
                    $flag = 1;
                    break;
                }
            }
        }

        if (!$flag){
            echo "NO\n";
        }
    }
}

<?php
	$arr = [4,7,44,47,74,77,444,447,474,477,747,777];
	$input = trim(fgets(STDIN));
	if(in_array($input, $arr)){
		echo "YES"; die();
	}
	foreach ($arr as $key => $value) {
		if($input % $value == 0){
			echo "YES";die();
		}
	}
	echo "NO";
?>

<?php
	$flag = false;
	$lucky = array(4,7,44,47,74,77,444,447,474,477,744,747,774,777);
	$var = trim(fgets(STDIN));
	if ((strlen($var) - substr_count($var, '4') - substr_count($var, '7')) > 0) {
		foreach ($lucky as $l) {
			if ((int)$var % $l == 0) {
				echo 'YES';
				$flag = true;
				break;
			}
		}
		if ($flag == false) echo 'NO';
	}
	else echo 'YES';

<?php
	$flag = false;
	$lucky = array(4,7,44,47,74,77,444,447,474,477,744,747,774,777);
	$var = trim(fgets(STDIN));
	if (in_array((int)$var,$lucky)) {
		echo 'YES';
	} else {
		foreach ($lucky as $l) {
			if ((int)$var % $l == 0) {
				echo 'YES';
				$flag = true;
				break;
			}
		}
		if ($flag == false) echo 'NO';
	}

<?php
	$var = (string)fgets(STDIN);
	if ((strlen($var) - substr_count($var, '4') - substr_count($var, '7')) > 0) echo 'NO';
	else echo 'YES';

<?php
	$var = (string)fgets(STDIN);
	if (substr_count($var, '4') > 0 || substr_count($var, '7') > 0) echo 'YES';
	else echo 'NO';

<?php
	$var = (string)fgets(STDIN);
	if (strlen($var) - substr_count($var, '4') - substr_count($var, '7') > 0) echo 'NO';
	else echo 'YES';

<?php
	$var = trim(fgets(STDIN));
	if ((strlen($var) - substr_count($var, '4') - substr_count($var, '7')) > 0) {
		if ((int)$var % 4 == 0 || (int)$var % 7 == 0) echo 'YES';
		echo 'NO';
	}
	else echo 'YES';

<?php
$string = trim(fgets(STDIN));
$values = str_split($string);
$contador = 0;
for ($x = 0; $x < count($values); $x++) {
    if ($values[$x] == '7' || $values[$x] == '4') {
        $contador++;
    }
}

if ($contador ==count($values) || $string  % 4 == 0 || $string  % 7 == 0 ) {
    echo "YES";
} else {
    echo "NO";
}

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

    fscanf($stdin, "%s", $n);

    $len = strlen($n);

    $lucky = false;
    for($i=0; $i<$len; $i++){
        if($n[$i] == '4' && $n[$i+1] == '7') $lucky = true;
    }
    $almostLucky = false;
    $n = (int)$n;
    if($n%4 == 0 || $n%7 == 0) $almostLucky = true;

    if($lucky == true || $almostLucky == true) echo "YES";
    else echo "NO";

    fclose($stdin);
?>

<?php

/**
 * Петя любит счастливые числа. Всем известно, что счастливыми являются положительные целые числа, в десятичной записи которых содержатся только счастливые цифры 4 и 7. Например, числа 47, 744, 4 являются счастливыми, а 5, 17, 467 — не являются.
 *
 * Петя называет число почти счастливым, если оно делится без остатка на какое-либо счастливое число. Помогите ему узнать, является ли заданное число n почти счастливым?
 * Входные данные
 *
 * В единственной строке задано целое число n (1 ≤ n ≤ 1000) — число, которое нужно проверить.
 * Выходные данные
 *
 * В единственной строке выведите «YES» (без кавычек), если число n почти счастливое, иначе выведите «NO» (без кавычек).
 */

define('DEBUG', 0);

define('LIMIT', 1000);

function doLog($log) {
	if (DEBUG) {
		echo "[" . microtime(true) ."] " . $log . "\n";
	}
}

function combinations($chars, $length)
{
	doLog("Length $length.");
	if ($length == 1) {
		return array_merge($chars);
	}

	$results = [];
	foreach ($chars as $char) {
		foreach (combinations($chars, $length-1) as $combination) {
			$results[$combination] = $combination;
			$results[$char . $combination] = $char . $combination;
		}
	}

	return array_keys($results);
}

function solve($n)
{
	$happyDigits = ['4', '7'];

	$happyNumbers = combinations($happyDigits, 3);

	// seeding happy numbers
	$seed = array_fill(1, LIMIT, false);

	foreach ($happyNumbers as $happyNumber) {
		doLog("Seeding $happyNumber.");
		$index = 2*$happyNumber;
		while ($index <= LIMIT) {
			$seed[$index] = true;
			$index+=$happyNumber;
		}
	}

	foreach ($happyNumbers as $happyNumber) {
		$seed[$index] = false;
	}

	return $seed[$n] ? 'YES' : 'NO';
}

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

$result = solve($n);

doLog($result . "\n");

echo $result;

<?php

$nr = fgets(STDIN);

echo ($nr % 4 == 0 or $nr % 7 == 0) ? 'YES' : 'NO';

<?php
$num = trim(fgets(STDIN));
$bookmark=0;
if (($num%4==0)||($num%7==0))echo "YES";
else
{
    $num=str_split($num,1);
    for ($i=0;$i<count($num);$i++)
    {
        if (($num[$i]!="4") && ($num[$i]!="7")) $bookmark++;
    }
    if ($bookmark!=0)echo "NO";
    else echo "YES";
}

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

$result = false;

$number = (int) $s;

$digit_array = str_split($s, 1);
$lucky_array = array(4, 7);

$is_lucky = false;
foreach ($digit_array as $digit) {
    if (!in_array($digit, $lucky_array)){
        $is_lucky = false;
        break;
    }
    $is_lucky = true;
}

$is_almost_lucky = false;

if (($number % 4 == 0) || ($number % 7 == 0)) {
    $is_almost_lucky = true;
}
else {
    $is_almost_luck = false;
}

if ($is_lucky || $is_almost_lucky) {
    $result = true;
}

echo $result ? "YES" : "NO";

?>

<?php
$input = explode("\n", trim(file_get_contents("php://stdin")));
$n = $input[0];
echo $n % 4 == 0 || $n % 7 == 0 ? 'YES' : 'NO';

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

//Check If It's Divisible By (4) or (7).
if($input % 7 == 0 || $input % 4 == 0 || $input % 47 == 0 || $input % 74 == 0) {

    echo "YES";

}else {

    echo "NO";

}

?>

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

//Check If It's Divisible By (4) or (7).
if($input % 7 == 0 || $input % 4 == 0) {

    echo "YES";

}else {

    echo "NO";

}

?>

<?php
$ada=false;
$i=0;
$s = trim(fgets(STDIN));
if ($s % 4 == 0) {
	echo "YES";
}elseif ($s % 7 == 0) {
	echo "YES";
}else{
	$a=strval($s);
	while ($i < strlen($a)) {
		if ($a[$i] != "4" && $a[$i] != "7")
		{
			$ada=true;
			break;
		}else{
			$ada=false;
		}
		$i++;
	}
	if (!$ada) {
		echo "YES";
	}else{
		echo "NO";
	}
}
?>

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

$counter = 0;

for ($i=0; $i < strlen($number); $i++) {
	if(($number[$i] == "4") || ($number[$i] == "7")){
		$counter++;
	}

}

if($counter == strlen($number)){
		echo "YES";
		exit();
	} elseif(intval($number) % 4 == 0) {
		echo "YES";
		exit();
	} elseif(intval($number) % 7 == 0) {
		echo "YES";
		exit();
	} else {
		echo "NO";
		exit();
	}

<?php
function check($n) {
    $n = (string)$n;
    for($i = 0; $i < strlen($n); $i++) {
        if (intVal($n[$i]) != 4 AND intVal($n[$i]) != 7) return false;
    }
    return true;
}

fscanf(STDIN, '%d', $n);
echo (check($n) OR !($n % 4) OR !($n % 7)) ? 'YES' : 'NO';

<?php
//打表
//for ($i = 1; $i <= 1000; $i++){
//
//}

while (fscanf(STDIN, "%s", $string)){
    $length = strlen($string);
    $lucky = 0;
    for ($i = 0; $i < $length; ++$i){
        if (4 == $string[$i] || 7 == $string[$i]){
            ++$lucky;
        }
    }

    if ($length == $lucky){
        echo "YES\n";
    } else {
        $number = (int)$string;
        if ($number % 4 == 0 || $number % 7 == 0){
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }
}

<?php
	$arr = [4,7];
	for ($i=4; $i <= 1000 ; $i++) {
		if(strpos($i, '4')!==false && strpos($i, '7')!==false) $arr[] = $i;
	}
	$input = trim(fgets(STDIN));
	if(in_array($input, $arr)){
		echo "YES"; die();
	}
	foreach ($arr as $key => $value) {
		if($input % $value == 0){
			echo "YES";die();
		}
	}
	echo "NO";
?>

<?php
	$arr = [4,7,44,47,74,77,444,447,474,747,777];
	$input = trim(fgets(STDIN));
	if(in_array($input, $arr)){
		echo "YES"; die();
	}
	foreach ($arr as $key => $value) {
		if($input % $value == 0){
			echo "YES";die();
		}
	}
	echo "NO";
?>

<?php
	$arr = [4,7];
	for ($i=4; $i <= 1000 ; $i++) {
		if(preg_match('/[^47]{0}[47]+[^47]{0}/', $i)) $arr[] = $i;
	}
	$input = trim(fgets(STDIN));
	if(in_array($input, $arr)){
		echo "YES"; die();
	}
	foreach ($arr as $key => $value) {
		if($input % $value == 0){
			echo "YES";die();
		}
	}
	echo "NO";
?>

<?php
	$var = trim(fgets(STDIN));
	if ((strlen($var) - substr_count($var, '4') - substr_count($var, '7')) > 0) {
		if ((int)$var % 4 == 0 || (int)$var % 7 == 0) echo 'YES';
		else echo 'NO';
	}
	else echo 'YES';

<?php
	$var = trim(fgets(STDIN));
	if ((strlen($var) - substr_count($var, '4') - substr_count($var, '7')) > 0) echo 'NO';
	else echo 'YES';


There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.The game is played on a square field consisting of n × n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.

The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the size of the field.

Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.

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

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

if($n==0){
    print 2;
}else{
    print 1;
}

<?php

$n = trim(fgets(STDIN));

$ans = (int)bcmod($n,2);
if($ans == 0)
    printf("2");
    else printf("1");

?>

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

if($n%2==0){
    echo 2;
}else{
    echo 1;
}

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

if($n==0){
    print 2;
}else{
    print 1;
}

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

if($n/2==0){
    echo 2;
}else{
    echo 1;
}

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

if($n==0){
    echo 2;
}else{
    echo 1;
}

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

if($n%2==0){
    echo 2;
}else{
    echo 1;
}

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

if($n % 2 == 0)
    printf("2\n");
else printf("1\n");

?>


The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."Could you pass the interview in the machine vision company in IT City?

The only line of the input contains a single integer n (2 ≤ n ≤ 2·1018) — the power in which you need to raise number 5.

Output the last two digits of 5n without spaces between them.

<?php
/*
* $n = trim(fgets(STDIN));
* $res = pow(5, $n);
* $out = substr($res, -2);
*/
echo "25";
?>

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

echo 25;

<?php
$n = trim(fgets(STDIN));
$res = pow(5, $n);
$out = substr($res, -2);
echo $out;
//$len = strlen(trim($res));
//$res_arr = str_split($res);
?>

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
	int n;
	cin>>n;
	cout<<25;
	return 0;
}

<?php

$n = readline();

$number = pow(5, $n);
$num = strval($number);

if (strlen($num) > 2) {
    echo $num[strlen($num) - 2] . $num[strlen($num) - 1];
} elseif (strlen($num) == 2) {
    echo $num;
}

public class x{public static void main(String[] args){System.out.print(25);}}

public class x{public static void main(String[] args){System.out.print("25");}}


Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.Each command is one of the following two types:   Go 1 unit towards the positive direction, denoted as '+'  Go 1 unit towards the negative direction, denoted as '-' But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5). You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?

The first line contains a string s1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.  The second line contains a string s2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command. Lengths of two strings are equal and do not exceed 10.

Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9.

NoteFor the first sample, both s1 and s2 will lead Dreamoon to finish at the same position  + 1. For the second sample, s1 will lead Dreamoon to finish at position 0, while there are four possibilites for s2: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5. For the third sample, s2 could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position  + 3 is 0.

<?php
$str1 = trim(fgets(STDIN));
$str2 = trim(fgets(STDIN));
$correct = str_split($str1);
$correctPos = 0;
foreach ($correct as $c) {
	if ($c == '+') {
		$correctPos++;
	} else {
		$correctPos--;
	}
}
//print_r($correctPos);
$guessed = str_split($str2);
$guessedPos = array(0);
foreach ($guessed as $g) {
	$cnt = count($guessedPos);
	for($i = 0; $i < $cnt; $i++) {
		if($g == '+') {
			++$guessedPos[$i];
		} else if($g == '-') {
			--$guessedPos[$i];
		} else {
			$currVal = $guessedPos[$i];
			++$guessedPos[$i];
			$guessedPos[] = $currVal - 1;
		}
	}
}
$total = count($guessedPos);
$accu = 0;
foreach($guessedPos as $p) {
	if($p == $correctPos) ++$accu;
}
echo $accu/$total;
?>

<?php
$s = fopen("php://stdin", 'r');
$str1 = stream_get_contents($s);
$str2 = stream_get_contents($s);
fclose($s);
$correct = str_split($str1);
$correctPos = 0;
foreach ($correct as $c) {
	if ($c == '+') {
		$correctPos++;
	} else {
		$correctPos--;
	}
}
//print_r($correctPos);
$guessed = str_split($str2);
$guessedPos = array(0);
foreach ($guessed as $g) {
	$cnt = count($guessedPos);
	for($i = 0; $i < $cnt; $i++) {
		if($g == '+') {
			++$guessedPos[$i];
		} else if($g == '-') {
			--$guessedPos[$i];
		} else {
			$currVal = $guessedPos[$i];
			++$guessedPos[$i];
			$guessedPos[] = $currVal - 1;
		}
	}
}
$total = count($guessedPos);
$accu = 0;
foreach($guessedPos as $p) {
	if($p == $correctPos) ++$accu;
}
echo $accu/$total;
?>


Alice has a string $$$s$$$. She really likes the letter "a". She calls a string good if strictly more than half of the characters in that string are "a"s. For example "aaabb", "axaa" are good strings, and "baca", "awwwa", "" (empty string) are not.Alice can erase some characters from her string $$$s$$$. She would like to know what is the longest string remaining after erasing some characters (possibly zero) to get a good string. It is guaranteed that the string has at least one "a" in it, so the answer always exists.

The first line contains a string $$$s$$$ ($$$1 \leq |s| \leq 50$$$) consisting of lowercase English letters. It is guaranteed that there is at least one "a" in $$$s$$$.

Print a single integer, the length of the longest good string that Alice can get after erasing some characters from $$$s$$$.

NoteIn the first example, it's enough to erase any four of the "x"s. The answer is $$$3$$$ since that is the maximum number of characters that can remain.In the second example, we don't need to erase any characters.

<?php
$a = trim(fgets(STDIN));
$b = 0;
for($x = 0; $x < strlen($a); $x++)
{
     if($a[$x] == "a")
     {
          $b++;
     }
}
$c = strlen($a) - $b;
if($c < $b)
{
     print strlen($a);
}
elseif($c == $b)
{
     print strlen($a) - 1;
}
elseif($c > $b)
{
     print strlen($a) - ($c - $b + 1);
}
?>

<?php
$s = readline();
if (substr_count($s, 'a') > strlen($s)/2) {
  echo strlen($s);
}
else {
  $c = 0;
  for ($i = 0; $i < strlen($s); $i++) {
    if ($s[$i] == 'a') {
      $c++;
    }
  }
  echo $c*2 -1;
}

<?php
# 1146

$input = fopen('php://stdin', 'rb');
$str = trim(fgets($input));
$result = strlen($str);
$aCount = substr_count($str, 'a');
$half = ceil($result / 2);
if ($aCount <= $half) {
    $result = 2 * $aCount - 1;

}
echo $result;

<?php

$aa = readline();
$cnt = 0;
for($i=0; $i<strlen($aa); $i++)
	if($aa[$i] == 'a')
		$cnt++;
if($cnt+$cnt>strlen($aa))
	echo strlen($aa);
else echo $cnt+$cnt-1;

<?php

$aa = readline();
$cnt = 0;
for($i=0; $i<strlen($aa); $i++)
	if($aa[$i] == 'a')
		$cnt++;
echo min(strlen($aa), $cnt*2-1);

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

$len = strlen($s);

$arr = str_split($s);

$as = substr_count($s, "a");

if ($as <= $len/2) {
	if ($len % 2 == 0) {
		$notAs = $len - $as;
		$ans = ($notAs - $as) + 1;
		$ans = $len - $ans;
	}
	else {
		$notAs = $len - $as;
		$ans = ($notAs - $as) + 1;
		$ans = $len - $ans;
	}
}
else $ans = $len;
echo $ans;
?>

<?php
$s = fgets(STDIN);
$r = substr_count($s, 'a')*2 -1;
echo $r > strlen($s) ? strlen(trim($s)) : $r;

<?php
$stdin = fopen('php://stdin','r');
$line = fgets( $stdin );
fclose( $stdin );
$a=array(0,0);
$arr=str_split(trim($line));
foreach ($arr as $b) $a[$b == "a" ? 0 : 1]++;
echo ($a[0]>$a[1] ? $a[0]+$a[1] : $a[0] * 2 - 1);

<?php

while(!feof(STDIN)){
    $arr[]=fgets(STDIN);
}
preg_match_all("/[\w]/", $arr[0], $matches);
$a=array_count_values($matches[0]);

if(count($matches[0])-$a[a]<$a[a]){echo count($matches[0]);}
else{
    echo count($matches[0])-(count($matches[0])-2*$a[a]+1);
}
?>

<?php
$s = readline();
echo min(substr_count($s, 'a') * 2 - 1, strlen($s));

<?php
fscanf(STDIN,"%s",$str);
$count=0;
$others=0;
for($i=0;$i<strlen($str);$i++)
{
	if($str[$i]=='a')
		$count++;
	else $others++;

}
if($count>$others)
		echo strlen($str);
	else
		echo ($count*2)-1;

<?php

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

for($i = 0; $i<count($s); $i++) if($s[$i] == 'a') $c++;

echo min(count($s), 2*$c-1);

?>

<?php
    $str = str_split(trim(fgets(STDIN)));
    $c = 0;
    for($i=0 ; $i<count($str) ; $i++){
        if($str[$i] == 'a'){
            $c++;
        }
    }
    echo min(count($str),2*$c-1);
?>

<?php
# 1146

$input = fopen('php://stdin', 'rb');
$str = trim(fgets($input));
$result = strlen($str);
$aCount = substr_count($str, 'a');
$half = ceil($result / 2);
if ($aCount <= $half) {
    $result = $aCount + 1;

}
echo $result;

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

$len = strlen($s);

$arr = str_split($s);

$as = substr_count($s, "a");

if ($as <$len/2) {
	if ($len % 2 === 0) {
		$dif = ($len/2) + 1 - $as;
		$ans = $len - $dif;
	}
	else {
		$dif = ceil($len/2) - $as;
		$ans = $len - $dif - $as;
	}
}
else $ans = $len;
echo $ans;
?>

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

$len = strlen($s);

$arr = str_split($s);

$as = substr_count($s, "a");

if ($as <$len/2) {
	if ($len % 2 === 0) {
		$dif = ($len/2) + 1 - $as;
		$ans = $len - $dif;
	}
	else {
		$dif = ceil($len/2) - $as;
		$ans = $len - $dif - $as;
	}
}
else $ans = $as;
echo $ans;
?>

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

$len = strlen($s);

$arr = str_split($s);

$as = substr_count($s, "a");

if ($as > ($len/2)) {
	echo $len;
}
else {
	echo (ceil($len/2) - $as) + 1;
}

?>

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

$len = strlen($s);

$arr = str_split($s);

$as = substr_count($s, "a");

if ($as <= $len/2) {
	if ($len % 2 == 0) {
		$dif = ($len/2) + 1 - $as;
		$ans = $len - $dif;
	}
	else {
		$dif = ceil($len/2) - $as;
		$ans = $len - $dif - $as;
	}
}
else $ans = $len;
echo $ans;
?>

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

$len = strlen($s);

$arr = str_split($s);

$as = substr_count($s, "a");

if ($as > ($len/2)) {
	echo $len;
}
else {
	do {
	    $len--;
	}while ($as < ceil($len/2));
	echo $len;
}

?>

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

$len = strlen($s);

$arr = str_split($s);

$as = substr_count($s, "a");

if ($len % 2 === 0) {
	$dif = ($len/2) + 1 - $as;
	$ans = $len - $dif;
}
else {
	$dif = ceil($len/2) - $as;
	$ans = $len - $dif - $as;
}
echo $ans;
?>

<?php

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

for($i = 0; $i<count($s); $i++) if($s[$i] == 'a') $c++;

if($c <= count($s)/2){
    echo $c + floor((count($s)-$c)/2) - 1;
}else{
    echo count($s);
}

?>


When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number k. Moreover, petricium la petricium stands for number k2, petricium la petricium la petricium stands for k3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.Petya's invention brought on a challenge that needed to be solved quickly: does some number l belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.

The first input line contains integer number k, the second line contains integer number l (2 ≤ k, l ≤ 231 - 1).

You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number l.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$d = 0;
for($x = 1; $x <= 1000; $x++)
{
    $c = pow($a, $x);
    if($b == $c)
    {
        $d = 1;
        break;
    }
    elseif($b < $c)
    {
        break;
    }
}
if($d == 1)
{
    print "YES" . "\n";
    print $x - 1;
}
else
{
    print "NO";
}
?>

<?php

$flag = 1; //must be not zero for STDIN

$in = 'php://stdin';
if (!$flag)
{
    $in = "input.txt";
}
$fd = fopen($in, "r");
fscanf($fd, "%d\n", $k);
fscanf($fd, "%d\n", $l);
fclose($fd);

$r = (log($l, $k));
$s = strstr ( $r, '.' );
if (!$s)
{
    print "YES\n";
    $r--;
    print "$r\n";
} else
{
    print "NO\n";
}
?>

<?php
    $k = (int)readline();
    $l = (int)readline();
    $x = $k;
    $counter = 0;
    while($x < $l){
        $x *= $k;
        $counter ++;
    }
    if($x == $l){
        echo("YES"),("\n");
        echo($counter),("\n");
    } else{
        echo("NO"),("\n");
    }
?>

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

$k = trim(fgets($f));
$l = trim(fgets($f));

$result = $k;
$n = 0;
while($result<$l){
    $result*=$k;
    $n++;

}

if ($result==$l){
    echo "YES\n";
    echo $n;
    exit;
}

echo "NO";

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

    $k = log($l,$n);
    if ($k==floor($k)){
    echo "YES\n";
    echo $k-1;
    } else
    echo "NO";
?>

<?
$n=trim(fgets(STDIN));
$l=trim(fgets(STDIN));
$cnt=0;
$ss="YES";
while($l!=1){
    $tmp=false;
    if($l%$n==0){
        $l=$l/$n;
        $cnt++;
        $tmp=true;
    }
    if(!$tmp) {$ss="NO"; break;}
}
if($ss=='NO') {
    echo $ss;
} else {
    echo $ss."\n";
    echo $cnt-1;
}
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$d = 0;
for($x = 1; $x <= 1000; $x++)
{
    $c = pow($a, $x);
    if($b == $c)
    {
        $d = 1;
        break;
    }
    elseif($b < $c)
    {
        break;
    }
}
if($d == 1)
{
    print "YES" . "\n";
    print $x;
}
else
{
    print "NO";
}
?>

<?php

$flag = 1; //must be not zero for STDIN
$in = 'php://stdin';
if (!$flag)
{
    $in = "input.txt";
}
$fd = fopen($in, "r");
fscanf($fd, "%d\n", $k);
fscanf($fd, "%d\n", $l);
fclose($fd);

$r = log($l, $k);
$s = floor($r);
$r = floatval($r);
$s = floatval($s);
$r-=$s;
if (!($r))
{
    print "YES\n";
    $s--;
    print "$s\n";
} else
{
    print "NO\n";
}
?>

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

    $k = log($l,$n);
    if ($k==floor($k)){
    echo "YES\n";
    echo $k;
    } else
    echo "NO";
?>

<?php
    fscanf(STDIN, "%d %d",$n, $l);
    $k = log($l,$n);
    if ($k==floor($k)){
    echo "YES\n";
    echo $k;
    } else
    echo "NO";
?>


You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Your task is to determine if the rectangles form a square. In other words, determine if the set of points inside or on the border of at least one rectangle is precisely equal to the set of points inside or on the border of some square.

The first line contains a single integer n (1 ≤ n ≤ 5). Next n lines contain four integers each, describing a single rectangle: x1, y1, x2, y2 (0 ≤ x1 < x2 ≤ 31400, 0 ≤ y1 < y2 ≤ 31400) — x1 and x2 are x-coordinates of the left and right edges of the rectangle, and y1 and y2 are y-coordinates of the bottom and top edges of the rectangle.  No two rectangles overlap (that is, there are no points that belong to the interior of more than one rectangle).

In a single line print "YES", if the given rectangles form a square, or "NO" otherwise.

<?php
$a = trim(fgets(STDIN));
$f = array();
$g = array();
$o = 0;
for($x = 1; $x <= $a; $x++)
{
    list($b, $c, $d, $e) = explode(" ", trim(fgets(STDIN)));
    array_push($f, $b);
    array_push($g, $c);
    array_push($f, $d);
    array_push($g, $e);
    array_push($f, $d);
    array_push($g, $c);
    array_push($f, $b);
    array_push($g, $e);
    $o += ($d - $b) * ($e - $c);
}
$h = $f;
sort($h);
$i = $h[0];
$j = $h[count($h) - 1];
$k = $g;
sort($k);
$l = $k[0];
$m = $k[count($k) - 1];
$n = ($j - $i) * ($m - $l);
if($n == $o)
{
    print "YES";
}
else
{
    print "NO";
}
?>


Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color. For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.

The first line of input contains three integers: n (1 ≤ n ≤ 100), k (1 ≤ k ≤ 100) and x (1 ≤ x ≤ k). The next line contains n space-separated integers c1, c2, ..., cn (1 ≤ ci ≤ k). Number ci means that the i-th ball in the row has color ci. It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.

Print a single integer — the maximum number of balls Iahub can destroy.