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


<?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

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


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


<?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
$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){
    if($g1<$x) $g1+=$value;
    else {
        $g2+=$value;
        if($k==0) $k=$key+1;
    }
}
echo $k;
fclose($in);


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


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


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


<?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
# 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
    list($n, $m) = explode(" ", trim(fgets(STDIN)));
    if ($n/2 <= $m) {
        echo $n - $m;
    } else {
        if ($m == 0) {
            echo 1;
        } else {
            echo $m;
        }
    }
?>


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


<?

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


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

?>


<?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
//打表
//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
$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
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
	$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
$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
	$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
$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
	$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';


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

<?php

$n = trim(fgets(STDIN));

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

?>

<?php
$n = trim(fgets(STDIN));
$n = bcmod($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){
    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");

?>


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

echo 25;

<?php
/*
* $n = trim(fgets(STDIN));
* $res = pow(5, $n);
* $out = substr($res, -2);
*/
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");}}


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


<?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

$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
$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

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

?>


<?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";
?>

<?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";

<?
$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 - 1;
}
else
{
    print "NO";
}
?>

<?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";
?>


<?php

function debug($msg)
{
    $debug = false;
    // $debug = true;

    if ($debug)
    {
        echo $msg . PHP_EOL;
    }
}

$ts = 5 * 60;
$te = 24 * 60;

define ('FREQ', 0);
define ('DURING', 1);

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 1,
//     DURING => 1
//     );
// $tb_arr = array(
//     FREQ   => 1,
//     DURING => 1
//     );
// $ta_start = 23 * 60 + 59;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);

    debug(" check between time $tb_start and $ta_end. Initial count: $count" );

    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $count--;
    }

    return intval($count);
}

// get the most recent meetable bus start time
function get_start($start, $t_arr)
{
    global $ts;

    if ($start - $t_arr[DURING] > $ts)
    {
        $start_time = $start - $t_arr[DURING];

        if ( (($start_time - $ts) % $t_arr[FREQ]) == 0)
        {
            return $start_time;
        }
        else
        {
            return $ts + ceil(($start_time - $ts) / $t_arr[FREQ]) * $t_arr[FREQ];
        }
    }
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        debug("meet in station at time: $t, freq: $freq");
        return true;
    }
    else
        return false;
}

<?php

function debug($msg)
{
    $debug = false;
    // $debug = true;

    if ($debug)
    {
        echo $msg . PHP_EOL;
    }
}

$ts = 5 * 60;
$te = 23 * 60 + 59;

define ('FREQ', 0);
define ('DURING', 1);

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 1,
//     DURING => 1
//     );
// $tb_arr = array(
//     FREQ   => 1,
//     DURING => 1
//     );
// $ta_start = 23 * 60 + 59;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);

    debug(" check between time $tb_start and $ta_end. Initial count: $count" );

    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $count--;
    }

    return intval($count);
}

// get the most recent meetable bus start time
function get_start($start, $t_arr)
{
    global $ts;

    if ($start - $t_arr[DURING] > $ts)
    {
        $start_time = $start - $t_arr[DURING];

        if ( (($start_time - $ts) % $t_arr[FREQ]) == 0)
        {
            return $start_time;
        }
        else
        {
            return $ts + ceil(($start_time - $ts) / $t_arr[FREQ]) * $t_arr[FREQ];
        }
    }
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during <= $te)
        return $start + $during;
    else
        return $te + 1;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        debug("meet in station at time: $t, freq: $freq");
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

// freq, travel_time
$ta_arr = array(
    'freq'   => 60,
    'during' => 120
    );
$tb_arr = array(
    'freq'   => 24,
    'during' => 100
    );
$ta_start = 13 * 60 + 0;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr['during']);

    $ta_end = get_end($ta_start, $ta_arr['during']);

    $count = ceil(($ta_end - $tb_start) / $tb_arr['freq']);
    if ( (($ta_end - $tb_start) % $tb_arr['freq']) == 0)
        $count++;

    echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    if (is_station($ta_start-$tb_arr['during'], $tb_arr['freq']))
        $count--;

    if (is_station($ta_start+$ta_arr['during'], $tb_arr['freq']))
        $count--;

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

define ('FREQ', 0);
define ('DURING', 1);

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 30,
//     DURING => 60
//     );
// $tb_arr = array(
//     FREQ   => 60,
//     DURING => 60
//     );
// $ta_start = 22 * 60 + 30;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr[DURING]);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = intval(($ta_end - $tb_start) / $tb_arr[FREQ]);

    // echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    $b_station = false;
    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    // meet at arrived station
    if (is_station($ta_start+$ta_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    if ( (($ta_end - $tb_start) % $tb_arr[FREQ]) == 0 && $b_station == true)
    {
        // echo 'add 1' . PHP_EOL;
        $count++;
    }

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        // echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

define ('FREQ', 0);
define ('DURING', 1);

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 30,
//     DURING => 60
//     );
// $tb_arr = array(
//     FREQ   => 60,
//     DURING => 60
//     );
// $ta_start = 22 * 60 + 30;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr[DURING]);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);

    // echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    $b_station = false;
    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    // meet at arrived station
    if (is_station($ta_start+$ta_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    if ( (($ta_end - $tb_start) % $tb_arr[FREQ]) == 0 && $b_station == true)
    {
        // echo 'add 1' . PHP_EOL;
        $count++;
    }

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        // echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}

<?php

function debug($msg)
{
    $debug = false;

    if ($debug)
    {
        echo $msg . PHP_EOL;
    }
}

$ts = 5 * 60;
$te = 23 * 60 + 59;

define ('FREQ', 0);
define ('DURING', 1);

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 30,
//     DURING => 60
//     );
// $tb_arr = array(
//     FREQ   => 60,
//     DURING => 60
//     );
// $ta_start = 22 * 60 + 30;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);

    debug(" check between time $tb_start and $ta_end. Initial count: $count" );

    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $count--;
    }

    return intval($count);
}

// get the most recent meetable bus start time
function get_start($start, $t_arr)
{
    global $ts;

    if ($start - $t_arr[DURING] > $ts)
    {
        $start_time = $start - $t_arr[DURING];

        if ( (($start_time - $ts) % $t_arr[FREQ]) == 0)
        {
            return $start_time;
        }
        else
        {
            return $ts + ceil(($start_time - $ts) / $t_arr[FREQ]) * $t_arr[FREQ];
        }
    }
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        debug("meet in station at time: $t, freq: $freq");
        return true;
    }
    else
        return false;
}

<?php

function debug($msg)
{
    $debug = false;

    if ($debug)
    {
        echo $msg . PHP_EOL;
    }
}

$ts = 5 * 60;
$te = 23 * 60 + 59;

define ('FREQ', 0);
define ('DURING', 1);

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 30,
//     DURING => 60
//     );
// $tb_arr = array(
//     FREQ   => 60,
//     DURING => 60
//     );
// $ta_start = 22 * 60 + 30;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);

    debug(" check between time $tb_start and $ta_end. Initial count: $count" );

    $b_station = false;
    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    // // meet at arrived station
    // if (is_station($ta_start+$ta_arr[DURING], $tb_arr[FREQ]))
    // {
    //     $b_station = true;
    //     $count--;
    // }

    return $count;
}

// get the most recent meetable bus start time
function get_start($start, $t_arr)
{
    global $ts;

    if ($start - $t_arr[DURING] > $ts)
    {
        $start_time = $start - $t_arr[DURING];

        if ( (($start_time - $ts) % $t_arr[FREQ]) == 0)
        {
            return $start_time;
        }
        else
        {
            return $ts + ceil(($start_time - $ts) / $t_arr[FREQ]) * $t_arr[FREQ];
        }
    }
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        debug("meet in station at time: $t, freq: $freq");
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

// freq, travel_time
$ta_arr = array(
    'freq'   => 60,
    'during' => 120
    );
$tb_arr = array(
    'freq'   => 24,
    'during' => 100
    );
$ta_start = 13 * 60 + 0;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr['during']);

    $ta_end = get_end($ta_start, $ta_arr['during']);

    $count = ceil(($ta_end - $tb_start) / $tb_arr['freq']);
    if ( (($ta_end - $tb_start) % $tb_arr['freq']) == 0)
        $count++;

    // echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    if (is_station($ta_start-$tb_arr['during'], $tb_arr['freq']))
        $count--;

    if (is_station($ta_start+$ta_arr['during'], $tb_arr['freq']))
        $count--;

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        // echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

define ('FREQ', 0);
define ('DURING', 1);
// freq, travel_time
// $ta_arr = array(
//     FREQ   => 60,
//     DURING => 120
//     );
// $tb_arr = array(
//     FREQ   => 24,
//     DURING => 100
//     );
// $ta_start = 13 * 60 + 0;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr[DURING]);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);
    if ( (($ta_end - $tb_start) % $tb_arr[FREQ]) == 0)
        $count++;

    // echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
        $count--;

    if (is_station($ta_start+$ta_arr[DURING], $tb_arr[FREQ]))
        $count--;

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        // echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

define ('FREQ', 0);
define ('DURING', 1);

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 30,
//     DURING => 60
//     );
// $tb_arr = array(
//     FREQ   => 60,
//     DURING => 60
//     );
// $ta_start = 22 * 60 + 30;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr[DURING]);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = intval(($ta_end - $tb_start) / $tb_arr[FREQ]);

    // echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    $b_station = false;
    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    // meet at arrived station
    if (is_station($ta_start+$ta_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    if ( (($ta_end - $tb_start) % $tb_arr[FREQ]) == 0)
    {
        // echo 'add 1' . PHP_EOL;
        $count++;
    }

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        // echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}


<?php
$str=trim(fgets(STDIN));
$len=strlen($str);
$vowel='aeioun';
$decision=false;
if (substr_count($vowel,$str[$len-1])==1)
{
	for ($i=0; $i <$len ; $i++)
	{
		if (substr_count($vowel,$str[$i])=='0'&&(substr_count($vowel,$str[$i+1])=='0'||$str[$i+1]=='n'))
		{
			$decision=false;
			break;
		}
		$decision=true;
	}
	//$decision=true;
}
echo $decision==true?'YES':'NO';

<?php

$a = trim(fgets(STDIN));
//$a = "codeforces";

$input = $a;
$input = str_split($input);
$ok = true;

for($i = 0; $i < sizeof($input); $i++){
    $value = $input[$i];
     if(!isVowel($value) && $value != 'n'){
         //if not n or vowel, have to check the next char
         if($i + 1 >= sizeof($input)){
             $ok = false;
             break;
         }else if(!isVowel($input[$i+1])){
             $ok = false;
             break;
         }
     }
}

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

function isVowel($character){
    return $character == 'a'
    || $character == 'i'
    || $character == 'u'
    || $character == 'e'
    || $character == 'o';
}
?>

<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

$group = array("a", "i", "u", "e", "o");
fscanf(STDIN, "%s", $S);
$arrayS = str_split($S);
$countS = count($arrayS);

$answer = "YES";
for ($i = 0; $i < $countS; $i++) {
	if ($arrayS[$i] == "n") {
		continue;
	}

	if (in_array($arrayS[$i], $group) === false) {
		if (in_array($arrayS[$i + 1], $group) === false) {
			$answer = "NO";
		}
	}
}

echo $answer;

<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

$group1 = array("a", "i", "u", "e", "o");
$group2 = array("a", "i", "u", "e", "o", "n");
fscanf(STDIN, "%s", $S);
$arrayS = str_split($S);
$countS = count($arrayS);

$answer = "YES";
for ($i = 0; $i < $countS; $i++) {
	if (in_array($arrayS[$i], $group2) === false) {
		if (in_array($arrayS[$i + 1], $group2) === false) {
			$answer = "NO";
		}
	}
}

echo $answer;

<?php
$str=trim(fgets(STDIN));
$len=strlen($str);
$vowel='aeioun';
$decision=false;
if (substr_count($vowel,$str[$len-1])==1)
{
	for ($i=0; $i <$len ; $i++)
	{
		if (substr_count($vowel,$str[$i])=='0'&&substr_count($vowel,$str[$i+1])=='0')
		{
			$decision=false;
			break;
		}
		$decision=true;
	}
	//$decision=true;
}
echo $decision==true?'YES':'NO';


<?php

$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));

if($a == $d && $a > 0){
	fwrite(STDOUT, 1);
}else{
	if($a == 0 && $c == 0 && $d == 0){
		fwrite(STDOUT, 1);
	}else{
		fwrite(STDOUT, 0);
	}
}

?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
if($a == $d)
{
     if(($a == 0) && ($d == 0))
     {
          if($c == 0)
          {
               print "1";
          }
          else
          {
               print "0";
          }
     }
     else
     {
          print "1";
     }
}
else
{
     print "0";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
if($a == $d)
{
     print "1";
}
else
{
     print "0";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
if($a == $d)
{
     if($c == 0)
     {
          print "1";
     }
     else
     {
          print "0";
     }
}
else
{
     print "0";
}
?>


<?php

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

$mod = ceil($n/2);

//echo("$k $mod\n");

if ($k<=$mod){
    echo ($k-1)*2+1;
    exit;
} else {
    echo ($k-$mod)*2;
}

<?php
$localtest = false;

/* Module for retrieving input */

// If this is a local test (variable toggled above), open from localtest.txt instead of php://stdin (because I'm too lazy to supply the arguments by stdin)
if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

/* Imported functions from chaotic_iak's library */
// none

/* chaotic_iak's solution */
$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = bcmod($n, 2);
$middle = bcdiv(bcadd($n, $parity), 2);

if (bccomp($k, $middle) != 1) {echo bcsub(bcmul(2, $k), 1);} else {echo bcmul(2, bcsub($k, $middle));}
?>

<?php
list ($k,$n) = explode(" ",trim(fgets(STDIN)));
$n=$n-1;
if ($n<$k/2) echo intval($k/($k/2))*$n+1;
else echo 2+2*($n-round($k/2));

<?php
$count_even = $count_odds = $n = $k = $value = 0;
fscanf(STDIN, "%f%f", $n, $k);
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = ($n - 1)/2;
    $count_odds = ($n - 1)/2 + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?

error_reporting(false);
//error_reporting(E_ALL);

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

if (file_exists("in.txt")) {
    $handle = fopen('in.txt', 'r');
    set_time_limit(2);
};

list($n, $k) = explode(" ", trim(fgets($handle)));

$nums =  ceil($n/2);

if ($k <= $nums) {

    printf("%.0f", $k * 2 - 1);
} else {
    printf("%.0f", ($k - $nums) * 2);
}

<?php
// 318A     Чет и нечет
$in = fopen("php://stdin", 'r');

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

$x = substr($n, strlen($n)-1, 1);
$countNech = bcdiv($n, '2', 0);

if (($x % 2) !== 0) {
    $countNech = bcadd($countNech, '1', 0);
}

if (bccomp($k, $countNech) == 1) {
    $k = bcsub($k, $countNech, 0);
    $out = bcmul($k, '2', 0);
} else {
    $out = bcmul($k, '2', 0);
    $out = bcsub($out, '1', 0);
}

echo $out;

?>

<?php

$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);

$arr=explode(" ", $n);
$n=$arr[0]; //max n
$k=$arr[1]; //position k

$tempArr=array();

$median=ceil($n/2);

if ($k<=$median)
{
print($k*2-1);
}
else{
print (($k-$median)*2);
}

?>

<?php

$stdin = fopen('php://stdin', 'r');
$data = explode(" ", trim(fgets($stdin)));
$n = $data[0]; $k = $data[1];
$part = ceil($n/2);
if($k > $part)
{
    echo 2 * ($k-$part);
}
 else {
    echo 2*($k-1)+1;
}

<?php
// Hi chaotic
$localtest = ini_get("display_errors"); // normally true, codeforces sets to false
if ($localtest) {echo "derp";}

if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = bcmod($n, 2);
$middle = bcdiv(bcadd($n, $parity), 2);

if (bccomp($k, $middle) != 1) {echo bcsub(bcmul(2, $k), 1);} else {echo bcmul(2, bcsub($k, $middle));}
?>

<?php
error_reporting("off");
//318A: Even Odds
list($n, $k) = explode(" ", trim(fgets(STDIN))); //$n = 7; $k = 7;
$oddnums = ceil($n / 2);

//first find out if $k lands in the even places or the odd places.
if ($k > $oddnums) {
    //if so, it's even. ith even number is 2i.
    $i = $k - $oddnums;
    echo 2 * $i;
} else {
    //it's odd. the ith odd number is 2(i-1) + 1.
    echo 2 * ($k - 1) + 1;
}
?>

<?php
	$input = trim(fgets(STDIN));
	$x = explode(" ", $input);
	$n = $x[0];
	$k = $x[1];
	$mid = ceil($n/2);
	if($k <= $mid)
		$result = (2*$k)-1;
	else
	{
		$y = $k - $mid;
		$result = 2 * $y;
	}
	echo $result;
?>

<?php

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

$mod = ceil($n/2);

//echo("$k $mod\n");

if ($k<=$mod){
    echo ($k-1)*2+1;
    exit;
} else {
    echo ($k-$mod)*2;
}

<?php

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

$mod = ceil($n/2);

echo("$k $mod\n");

if ($k<=$mod){
    echo ($k-1)*2+1;
    exit;
} else {
    echo ($k-$mod)*2;
}

<?php

#fscanf(STDIN , "%lld%lld" , $n,$k);
list($n,$k) = explode(" " , trim(fgets(STDIN)));
if($n % 2 == 1) $n ++;
if($k <= $n / 2) echo 2* $k - 1;
else {
	$k -= $n / 2;
	echo 2 *  $k;
}

?>

<?

error_reporting(false);
//error_reporting(E_ALL);

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

if (file_exists("in.txt")) {
    $handle = fopen('in.txt', 'r');
    set_time_limit(2);
};

list($n, $k) = explode(" ", trim(fgets($handle)));

$nums =  intval(($n + 1)/2);

if ($k <= $nums) {

    $rtn =  $k * 2 - 1;
} else {
    $rtn = ($k - $nums) * 2;
}

printf("%u", $rtn);
//%u

?>

<?

error_reporting(false);
//error_reporting(E_ALL);

$handle = fopen('php://stdin', 'r');
//$handle = fopen('in.txt', 'r');

list($n, $k) = explode(" ", trim(fgets($handle)));

$nums =  intval(($n + 1)/2);

if ($k <= $nums) {

    echo  $k * 2 - 1;
} else {
    echo ($k - $nums) * 2;
}

?>

<?php
// 318A     Чет и нечет
$in = fopen("php://stdin", 'r');

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

$x = substr($n, strlen($n)-1, 1);
$countNech = bcdiv($n, '2', 0);

if (($x % 2) !== 0) {
    $countNech = bcadd($countNech, '1', 0);
}

if (bccomp($k, $countNech) >= 0) {
    $k = bcsub($k, $countNech, 0);
    $out = bcmul($k, '2', 0);
} else {
    $out = bcmul($k, '2', 0);
    $out = bcsub($out, '1', 0);
}

echo $out;

?>

<?php

$stdin = fopen('php://stdin', 'r');
$data = explode(" ", trim(fgets($stdin)));
$n = $data[0]; $k = $data[1];
$part = ceil($n/2);
if($k > $part)
{
    echo 2 * ($part-$k);
}
 else {
    echo 2*($k-1)+1;
}

<?php
// derp does this work the same as in Custom Test?
var_dump(ini_get("ONLINE_JUDGE"));
?>

<?php
	$input = trim(fgets(STDIN));
	$x = explode(" ", $input);
	$n = intval($x[0]);
	$k = intval($x[1]);
	$mid = ceil($n/2);
	if($k <= $mid)
		$result = (2*$k)-1;
	else
	{
		$y = $k - $mid;
		$result = 2 * $y;
	}
	echo $result;
?>

<?php
if (ONLINE_JUDGE !== true) {echo "derp";}

/* Module for retrieving input */

// If this is a local test (variable toggled above),
if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

/* Imported functions from chaotic_iak's library */
// none

/* chaotic_iak's solution */
$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = $n % 2;
$middle = ($n + $parity) / 2;

if ($k <= $middle) {echo 2*$k - 1;} else {echo 2*$k - $n - $parity;}
?>

<?php
if ((ONLINE_JUDGE !== "true") && (ONLINE_JUDGE !== true)) {echo "derp";}

$localtest = false;

/* Module for retrieving input */

// If this is a local test (variable toggled above), open from localtest.txt instead of php://stdin (because I'm too lazy to supply the arguments by stdin)
if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

/* Imported functions from chaotic_iak's library */
// none

/* chaotic_iak's solution */
$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = bcmod($n, 2);
$middle = bcdiv(bcadd($n, $parity), 2);

if (bccomp($k, $middle) != 1) {echo bcsub(bcmul(2, $k), 1);} else {echo bcmul(2, bcsub($k, $middle));}
?>

<?php
if (!(defined(ONLINE_JUDGE))) {echo "derp";}

/* Module for retrieving input */

// If this is a local test (variable toggled above),
if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

/* Imported functions from chaotic_iak's library */
// none

/* chaotic_iak's solution */
$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = $n % 2;
$middle = ($n + $parity) / 2;

if ($k <= $middle) {echo 2*$k - 1;} else {echo 2*$k - $n - $parity;}
?>

<?php
$localtest = false;

/* Module for retrieving input */

// If this is a local test (variable toggled above),
if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

/* Imported functions from chaotic_iak's library */
// none

/* chaotic_iak's solution */
$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = $n % 2;
$middle = ($n + $parity) / 2;

if ($k <= $middle) {echo 2*$k - 1;} else {echo 2*$k - $n - $parity;}
?>

<?php
list ($k,$n) = explode(" ",trim(fgets(STDIN)));
$n=$n-1;
if ($n<$k/2) echo intval($k/($k/2))*$n+1;
else echo 2+2*(round($k/2)-$n);

<?php

fscanf(STDIN, "%d%d", $n, $k);
$even = range(2,$n, 2);
$odd = range(1,$n, 2);
print_r($even);
print_r($odd);
for ($i = count($odd)-1; $i >= 0; $i--) {
    array_unshift($even, $odd[$i]);
}
print($even[$k-1]);

<?php
$input = array();
$count_even = $count_odds = $n = $k = $value = 0;
$input = explode(" ", (trim(fgets(STDIN))));
$n = $input[0];
$k = $input[1];
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php
$input = array();
$count_even = $count_odds = $n = $k = $value = 0;
$input = explode(" ", (trim(fgets(STDIN, 4096))));
$n = $input[0];
$k = $input[1];
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php

fscanf(STDIN, "%d%d", $n, $k);
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php
$count_even = $count_odds = $n = $k = $value = 0;
fscanf(STDIN, "%d%d", $n, $k);
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php
$count_even = $count_odds = $n = $k = $value = 0;
fscanf(STDIN, "%f%f", $n, $k);
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php

fscanf(STDIN, "%d%d", $n, $k);
$even = range(2,$n, 2);
$odd = range(1,$n, 2);
for ($i = count($odd)-1; $i >= 0; $i--) {
    array_unshift($even, $odd[$i]);
}
print($even[$k-1]);

<?php
$count_even = $count_odds = $n = $k = $value = 0;
fscanf(STDIN, "%F%F", $n, $k);
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php

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

$mod = ceil($n/2);

//echo("$k $mod\n");

if ($k<$mod){
    echo ($k-1)*2+1;
    exit;
} else {
    echo ($k-$mod)*2;
}


<?php
        //Enter your code here, enjoy!
    list($a, $b) = explode(" ", trim(fgets(STDIN)));
    list($c, $d) = explode(" ", trim(fgets(STDIN)));

    $aa = array();
    $cc = array();
    for($i = 0; $i < 5000; $i++)
    {
        $aa[$i] = $b + ($a * $i);
        $cc[$i] = $d + ($c * $i);
    }

    $ee = array_intersect($aa, $cc);
    if( sizeof($ee) > 0)
    {
        reset($ee);
        echo current($ee);
    } else {
        echo "-1";
    }

    echo PHP_EOL;

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
list($c, $d) = explode(" ", trim(fgets(STDIN)));
$e = $b;
$f = $d;
$g = array($e);
$h = array($f);
for($x = 1; $x <= 10000; $x++)
{
     $e = $b + ($a * $x);
     $f = $d + ($c * $x);
     $g[$x] = $e;
     $h[$x] = $f;
}
$i = array_intersect($g, $h);
if(count($i) > 0)
{
     $j = current($i);
     print $j;
}
else
{
     print "-1";
}
?>

<?php
list($a, $b) = explode(' ', trim(fgets(STDIN)));
list($c, $d) = explode(' ', trim(fgets(STDIN)));

$i = 0;
while($i < 1000) {
    if($b == $d) {
        echo $b;
        exit;
    }
    else if($b > $d) {
        $d += $c;
    }
    else {
        $b += $a;
    }
    $i++;
}
echo -1;


<?php

// ურბან მეორე, ეს იყო ღვთაება. მე მაგისი.. ჯვაროსნების ლაშქრობას მაგან მისცა ბიძგი. თან დიდი.

$urbanTheSecond = 0;

list($a,$b) = explode(" ",trim(fgets(STDIN)));
list($yellow,$green,$blue) = explode(" ", trim(fgets(STDIN)));

$a1 = 2*$yellow + $green;
$b1 = $green + 3*$blue;

if($a - $a1 < 0)
    $urbanTheSecond+=$a1-$a;

if($b - $b1 < 0)
    $urbanTheSecond+= $b1 - $b;

echo $urbanTheSecond;

?>


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = 0;
for($x = 0; $x < $a; $x++)
{
    $d = array_sum(array_slice($b, 0, $x + 1));
    $e = array_sum(array_slice($b, $x + 1));
    if($d == $e)
    {
        $c = 1;
        break;
    }
    elseif($d > $e)
    {
        $f = $d - $e;
        if(($f == 200) && ($b[0] == 100))
        {
            $c = 1;
        }
        break;
    }
}
if($c == 1)
{
    print "YES";
}
else
{
    print "NO";
}
?>

<?php
error_reporting("off");
//433A: Kitahara Haruki's Gift
$n = trim(fgets(STDIN)); //$n = 4;
$apples = explode(" ", trim(fgets(STDIN))); //$apples = explode(" ", "100 100 100 200");
$count = array_count_values($apples);
$totalweight = $count[100] * 100 + $count[200] * 200;
$half = $totalweight / 100; //getting rid of two zeros for the number of hundreds
if ($half % 2 !== 0) {
    echo "NO";
} else {
    $halfreally = $half / 2;
    if ($halfreally % 2 == 0) {
        echo "YES";
    } else {
        if ($count[100] == 0) {
            echo "NO";
        } else {
            echo "YES";
        }
    }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
array_unshift($d, " ");
unset($d[0]);
$e = array_search("5", $d);
$f = array_unique($b);
if(($e == TRUE) || ($a == 1) || ((count($f) == 1) && ((count($b) % 2) != 0)))
{
    print "NO";
}
else
{
    print "YES";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
array_unshift($d, " ");
unset($d[0]);
$e = array_search("5", $d);
if(($e == TRUE) || ($a == 1))
{
    print "NO";
}
else
{
    print "YES";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
array_unshift($d, " ");
unset($d[0]);
$e = array_search("5", $d);
$f = array_unique($b);
if(($e == TRUE) || ($a == 1) || (count($f) == 1))
{
    print "NO";
}
else
{
    print "YES";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
if($d[1] != 0)
{
    print "NO";
}
else
{
    print "YES";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
array_unshift($d, " ");
unset($d[0]);
$e = array_search("5", $d);
$f = array_unique($d);
if(($e == TRUE) || ($a == 1) || (count($f) == 1))
{
    print "NO";
}
else
{
    print "YES";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
array_unshift($d, " ");
unset($d[0]);
$e = array_search("5", $d);
if($e == TRUE)
{
    print "NO";
}
else
{
    print "YES";
}
?>

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

<?php
error_reporting("off");
//433A: Kitahara Haruki's Gift
$n = trim(fgets(STDIN)); //$n = 4;
$apples = explode(" ", trim(fgets(STDIN))); //$apples = explode(" ", "100 100 100 200");
$count = array_count_values($apples);
$totalweight = $count[100] * 100 + $count[200] * 200;
$half = $totalweight / 100; //getting rid of two zeros for the number of hundreds
if ($half % 2 !== 0) {
    echo "NO";
} else {
    echo "YES";
}
?>

<?php
error_reporting("off");
//433A: Kitahara Haruki's Gift
$n = trim(fgets(STDIN)); $n = 4;
$apples = explode(" ", trim(fgets(STDIN))); $apples = explode(" ", "100 100 100 200");
$count = array_count_values($apples);
$totalweight = $count[100] * 100 + $count[200] * 200;
$half = $totalweight / 100; //getting rid of two zeros for the number of hundreds
if ($half % 2 !== 0) {
    echo "NO";
} else {
    echo "YES";
}
?>


<?php

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

sort($arr);
$s=0;
for($i=0;$i<$n;$i++){
    if($s*$arr[$i]+$s<=$i)$s++;

}

echo $s.PHP_EOL;

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
for($x = 1; $x <= 100; $x++)
{
    sort($b);
    $c = array();
    array_push($c, $b[0]);
    unset($b[0]);
    for($y = 1; $y <= 100; $y++)
    {
        if($b[$y] == 0)
        {
            continue;
        }
        elseif($b[$y] >= count($c))
        {
            array_push($c, $b[$y]);
            unset($b[$y]);
        }
        elseif($b[$y] < count($c))
        {
            continue;
        }
    }
    if(count($b) == 0)
    {
        break;
    }
}
print $x;
?>


#!/usr/bin/php
<?php

$s = fopen("php://stdin", 'r');
$n = fgets($s);
$dum = explode(" " , $n);
$candiesNum = $dum[0];
$friendsNum = $dum[1];

$division = intval($candiesNum / $friendsNum);
$difference = $candiesNum % $friendsNum;
$result = NULL;
for($n = 0; $n < $friendsNum - $difference; $n++)
{
     $result .= $division . ' ';
}
for($n = 0; $n < $difference; $n++)
{
     $result .= $division+1 . ' ';
}
echo substr($result , 0 , -1);

#!/usr/bin/php
<?php

$candiesNum = $argv[1];
$friendsNum = $argv[2];

$division = intval($candiesNum / $friendsNum);
$difference = $candiesNum % $friendsNum;
$result = NULL;
for($n = 0; $n < $friendsNum - $difference; $n++)
{
     $result .= $division . ' ';
}
for($n = 0; $n < $difference; $n++)
{
     $result .= $division+1 . ' ';
}
echo substr($result , 0 , -1);


<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite($f, $data);
	fclose($f);
}
function dividable($n){
	$s = (string) $n;
	if(substr($s, strlen($s)-1) == "0") return true;
	return false;
}
function calculate_min($k, $n){
	$allow = true;
	$c = 0;
	$num = $k-$n;
	if(dividable($num)) return "1";
	for($i=0;$i<=10; $i++){
		$c++;
		if(dividable(($c)*$k - $n)) return $c;
		if(dividable(($c)*$k)) return $c;
	}
	return "undefined";
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
$data = fgets(STDIN);
//$gestor = @fopen("data.in", "r");
//$data = fgets($gestor);
$data = explode(" ", $data);
$n = $data[0];
$k = $data[1];
$c = 1;
$flag = true;
while ($flag) {
    $aux = ($n * $c);
    if ($aux % 10 == 0 || ($aux - $k) % 10 == 0) {
        echo $c;
        $flag = false;
    }
    $c++;
}
?>

<?php
function shovel(int $cost, int $coin): int
{
    for ($i = 1; $i < 10; $i++) {
        $result = (int)((string)($cost * $i))[-1];
        if ($result === 0 || $result === $coin) {
            break;
        }
    }
    return $i;
}
[$cost, $coin] = explode(' ', file_get_contents('php://stdin'));
echo shovel($cost, $coin);

<?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 */
	list($price, $r) = readStringExplodeNum($stream, ' ', true);
	for ($i = 1; $i <= 10; $i++) {
		$amount = $i * $price;

		if ($amount % 10 == $r || $amount % 10 == 0) {
			echo $i;
			break;
		}
	}

	/* / end body */
}

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

<?php
list($oneshovel, $coin)=explode(" ", trim(fgets(STDIN)));
$x=1;
while (TRUE) {

     if (($oneshovel * $x) % 10 == 0 or (($oneshovel * $x) - $coin) % 10 == 0) {

          break;
     }else $x++;

}
echo $x;
?>

<?php

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

fscanf($stdin, "%d %d", $k , $r ) ;

$count = 1 ;
$temp = $k ;

while( true )
{
     if( $k % 10 == 0 )
     {
          break ;
     }
     if( $k % 10 == $r )
     {
          break ;
     }
     $count++ ;
     $k = $count * $temp ;
}
echo $count ;

fwrite($stdout);

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

?>

<?php

$stdin = fopen('php://stdin', 'r');
$string = explode(" ", trim(fgets($stdin)));
$value = $string[0];
$coin = $string[1];
$count = 1;
$summ = $value;
while ($summ % 10 != 0 && $summ % 10 != $coin) {
    $summ = $summ + $value;
    $count++;
}
printf('%.0f', $count);

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite( $handle, $data );
	fclose( $handle );
}

function calculate_min($k, $n){
	$allow = true;
	$c = 1;
	$s = $k;
	$coin = $n;
	while($allow){
		if(($s-$n)%10 == 0){
			$allow = false;
			break;
		}
		$s += $k;
		$c++;
	}
	return $c;
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite($f, $data);
	fclose($f);
}
function dividable($n){
	$s = (string) $n;
	if(substr($s, strlen($s)-1) == "0" && strlen($s)>1) return true;
	return false;
}
function calculate_min($k, $n){
	$allow = true;
	$c = 1;
	$num = $k-$n;
	if(dividable($num)) return $c;
	for($i=0;$i<=10; $i++){
		$c++;
		if(dividable(($c-1)*$k - $n)) return $c-1;
		if(dividable(($c-1)*$k)) return $c-1;
	}
	return "undefined";
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite($f, $data);
	fclose($f);
}
function dividable($n){
	$s = (string) $n;
	if(substr($n, strlen($n)-1) == "0" && strlen($n)>1) return true;
	return false;
}
function calculate_min($k, $n){
	$allow = true;
	$c = 1;
	$num = $k-$n;
	if(dividable($num)) return $c;
	for($i=0;$i<=10; $i++){
		$c++;
		if(dividable(($c-1)*$k)) return $c-1;
		if(dividable(($c-1)*$k - $n)) return $c-1;
	}
	return "undefined";
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite($f, $data);
	fclose($f);
}
function dividable($n){
	$s = (string) $n;
	if(substr($n, strlen($n)-1) == "0" && strlen($n)>1) return true;
	return false;
}
function calculate_min($k, $n){
	$allow = true;
	$c = 1;
	$num = $k-$n;
	if(dividable($num)) return $c;
	for($i=0;$i<=10; $i++){
		$c++;
		if(dividable(($c-1)*$k - $n)) return $c-1;
		if(dividable(($c-1)*$k)) return $c-1;
	}
	return "undefined";
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
function read(){
	return readfile('php://stdin');
}
function put($data){
	file_put_contents('php://stdout', $data);
}

function calculate_min($k, $n){
	$allow = true;
	$c = 1;
	$s = $k;
	$coin = $n;
	while($allow){
		if(($s-$n)%10 == 0){
			$allow = false;
			break;
		}
		$s += $k;
		$c++;
	}
	echo $c;
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite($f, $data);
	fclose($f);
}
function dividable($n){
	$s = (string) $n;
	if(substr($s, strlen($s)-1) == "0") return true;
	return false;
}
function calculate_min($k, $n){
	$allow = true;
	$c = 0;
	$num = $k-$n;
	if(dividable($num)) return "1";
	for($i=0;$i<=10; $i++){
		$c++;
		if(dividable(($c)*$k - $n)) return $c;
		if(dividable(($c)*$k)) return $c;
	}
	return "undefined";
}
echo(calculate_min(1, 1));
die();
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>