<?php

list($a, $b) = explode(' ', readline());

$count = 0;
$left = 0;

while($a){
    $count += $a;

    if($left >= $b){
        $a += $left;
        $left = 0;
    }

    $left += $a % $b;
    $a = intdiv($a, $b);
//    echo $a . "\n";

}
if($left >= $b){
    $count++;
}
echo $count;


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = floor($a / 2);
print $b[$c];
?>


<?php
//$handle = fopen('test2.txt', 'r');
$n = fgets(STDIN);
$years = explode(' ', fgets(STDIN));
//$n = fgets($handle);
//$years = explode(' ', fgets($handle));
$year = array_sum($years)/$n;
echo $year;


<?php
define('SUBMIT', true);
if(SUBMIT){
    $stdin = STDIN;
}else {
    $file = 'sample';
    $stdin = fopen($file, 'r');
}

$t = intval(trim(fgets($stdin)));
$line = trim(fgets($stdin));
$years = array_filter(explode(' ', $line));
asort($years);
$years = array_values($years);

$mid = floor(count($years)/2);

print($years[$mid]);


<?php

$n = intval(fgets(STDIN));
$years = array_map('intval', explode(" ", fgets(STDIN)));

function getResult($result){
    echo $result;
    exit(false);
}

function solveTask($n, $years){
    if($n == 1) getResult($years[0]);
    else{
        sort($years);
        if($n == 3) getResult($years[1]);
        if($n == 5) getResult($years[2]);
    }
}

solveTask($n, $years);


<?php
    $n = (int) fgets(STDIN);
    $s = 0;
    foreach(explode(" ", fgets(STDIN)) as $y){
        $s += $y;
    }
    echo $s/$n;
?>


<?php
$f = (int)fgets(STDIN);
$line = fgets(STDIN);
$explode = explode(" ", $line);
$sum = 0;
foreach ($explode as $i){
	$sum += $i;
}
echo $sum / $f;
?>


<?php
    $n = trim(fgets(STDIN));
    $res = ($n + 4)/5;
    echo(floor($res));

?>


<?php
function input()
{
    while (($line = trim(fgets(STDIN))) != PHP_EOL) {
        yield $line;
    }
}

function put($r)
{
    echo $r . PHP_EOL;
}

$count = 1;
foreach (input() as $line) {
    $dis = $line;
    $w = 0;
    function walk($dis,$w) {
       if ($dis == 0) {
           put($w);
           die();
       }

       $i = 0;
       if ($dis > 4) $i=5;
       elseif ($dis > 3) $i=4;
       elseif ($dis > 2) $i=3;
       elseif ($dis > 1) $i=2;
       else $i=1;

       walk($dis-$i, $w+1);
    }
    walk($dis,$w);

    if ((--$count) == 0) {
        break;
    }
}


<?php
function input()
{
    while (($line = trim(fgets(STDIN))) != PHP_EOL) {
        yield $line;
    }
}

function put($r)
{
    echo $r . PHP_EOL;
}

$count = 1;
foreach (input() as $line) {
    $dis = $line;
    $w = 0;
    function walk($dis,$w) {
       if ($dis == 0) {
           return $w;
       }

       $i = 0;
       if ($dis > 4) $i=5;
       elseif ($dis > 3) $i=4;
       elseif ($dis > 2) $i=3;
       elseif ($dis > 1) $i=2;
       else $i=1;

       return walk($dis-$i, $w+1);
    }
    put(walk($dis,$w));

    if ((--$count) == 0) {
        break;
    }
}


<?php
$a = trim(fgets(STDIN));
$b = ceil($a / 5);
print $b;


<?php

$nr = trim(fgets(STDIN));
$walk = 0;
for ($i = 5; $i >= 1; $i--) {
    $walk += floor($nr / $i);
    $nr = $nr % $i;
}

echo $walk;


<?php

fscanf(STDIN, '%d', $x);
$div = (int) ($x / 5);
$mod = $x % 5;
printf('%d' . PHP_EOL, $div + ($mod ? 1 : 0));


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

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

$stdin = fopen('php://stdin','r');
fscanf($stdin, "%d\n", $number);

$string = "$number";
$max = $number;
if (intval(substr($string, 0, strlen($string)-1)) > $max) {
    $max = intval(substr($string, 0, strlen($string)-1));
}
$lastChar = $string[strlen($string)-1];
$temp_string = substr($string, 0, strlen($string)-2);
if (intval($temp_string.$lastChar) > $max) {
    $max = intval($temp_string.$lastChar);
}

echo $max."\n";


<?php
$account = trim(fgets(STDIN));
if ($account<0)
{
    if ((substr($account,0,-2).substr($account,-1))>(substr($account,0,-1)))$account = substr($account,0,-2).substr($account,-1);
    else $account = substr($account,0,-1);
}
if ($account==-0)$account=0;
echo $account;


<?php

$input = trim(fgets(STDIN));
if ($input[0] == "-") {
    $ch = strlen($input);
    if ($input[$ch - 1] >= $input[$ch - 2]) {
        print(substr($input, 0, $ch - 1));
    } else {
        $res = str_split($input);
        if ($ch == 3 && $res[$ch-1] == 0) {
        $res[0] = "";
        } else {
            //
        }
        $res[$ch - 2] = "";
        print(implode($res));
    }
} else {
    print($input);
}


<?php
	$deposite = fgets(STDIN);
	echo max($deposite, ceil($deposite / 10), ceil($deposite / 100) * 10 + $deposite % 10);


<?php
// 313А -
$deposit = fgets(STDIN);
if ($deposit >= 0) {
    echo $deposit;
} else {
    if (abs($deposit) >= 100) {
        $deposit_without_to = floor(abs($deposit) / 100);
    } else {
        $deposit_without_to = "";
    }
    $tens_ones = abs($deposit) % 100;
    $tens = floor($tens_ones / 10);
    $ones = $tens_ones % 10;
    if ($tens >= $ones) {
        $tens = "";
    } else {
        $ones = "";
    }
    if ("-" . $deposit_without_to . $tens . $ones == "-0")
    {
        echo "0";
    } else {
        echo "-" . $deposit_without_to . $tens . $ones;
    }
}

?>


<?php

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

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

if ($x<-9){
    $a = str_split($x);

    $y = $x;
    $z = $x;

    $temp = $a;

    if (isset($temp[count($a)-1]) && $temp[count($a)-1]!='-')
        unset($temp[count($a)-1]);
    $y = implode('',$temp);

    $temp = $a;
    if (isset($temp[count($a)-2]) && $temp[count($a)-2]!='-')
        unset($temp[count($a)-2]);
    $z = implode('',$temp);

    if ($y>=$x && $y>=$z) $x = $y;
    if ($z>=$x && $z>=$y) $x = $z;

}

if ($x!='-0')
echo $x;
else echo 0;


<?php
function getResult($item)
{
	$item = array_map('intval', explode(' ', trim($item)));
	$currentPage = $item[1];
	$totalPages = $item[0];
	$shift = $item[2];
	$result = "($currentPage)";

	# making left
	if ($currentPage > 1)
	{
		$needArrow = true;
		for ($j = 1; $j <= $shift; $j++)
		{
			$leftPage = $currentPage - $j;
			$result = "$leftPage " . $result;
			if ($leftPage === 1)
			{
				$needArrow = false;
				break;
			}
		}
		if ($needArrow)
		{
			$result = '<< ' . $result;
		}
	}

	# making right
	if ($currentPage < $totalPages)
	{
		$needArrow = true;
		for ($j = 1; $j <= $shift; $j++)
		{
			$nextPage = $currentPage + $j;
			$result .= " $nextPage";
			if ($nextPage === $totalPages)
			{
				$needArrow = false;
				break;
			}
		}
		if ($needArrow)
		{
			$result .= ' >>';
		}
	}
	return $result;
}

fwrite(STDOUT, getResult(fgets(STDIN)));


<?php

list($n, $p, $k) = array_map('intval', explode(' ', fgets(STDIN)));
$result = array();
if($p - $k > 1){
    array_push($result, '<<');
    for($i=$p-$k; $i<$p; $i++){
        array_push($result, $i);
    }
}else{
    for($i=$p-$k; $i<$p; $i++){
        if($i > 0)
        array_push($result, $i);
    }
}
array_push($result, "($p)");
if($p + $k < $n){
    for($i=$p+1; $i<=$p + $k; $i++){
        array_push($result, $i);
    }
    array_push($result, '>>');
}else{
    for($i=$p+1; $i<=$p + $k; $i++){
        if($i <=$n)
        array_push($result, $i);
    }
}

print(implode(' ', $result));


<?php

/**
 * Пользователь ainta занимается созданием веб-сайта.
 * Сегодня он разрабатывает навигацию по страницам сайта.
 * Сайт ainta состоит из n страниц, пронумерованных целыми числами от 1 до n.
 * Предположим, что сейчас посетитель сайта находится на p-ой странице,
 * тогда навигация будет выглядеть следующим образом:
 * << p - k p - k + 1 ... p - 1 (p) p + 1 ... p + k - 1 p + k >>
 * Когда посетитель кликает кнопку "<<", он переходит на страницу 1;
 * когда посетитель кликает кнопку ">>", он переходит на страницу n.
 * Если посетитель кликает некоторое число, он переходит на соответствующую страницу.
 *
 * Чтобы навигация по сайту выглядела более презентабельно, требуется, чтобы выполнялись условия:
 *     Если страница номер 1 отображается в навигации, то кнопку "<<" отображать не надо.
 *     Если страница номер n отображается в навигации, то кнопку ">>" отображать не надо.
 *     Если номер страницы меньше 1 или больше n, ее в навигации отображать не надо.
 *
 * Вам заданы числа n, k, p. Помогите ainta, напишите программу,
 * которая выведет строку навигации по заданным параметрам.
 * Обратите внимание на тестовые примеры для лучшего понимания условия.
 *
 * Входные данные
 * В первой и единственной строке содержатся три целых числа n, p, k (3 ≤ n ≤ 100; 1 ≤ p ≤ n; 1 ≤ k ≤ n)
 *
 * Выходные данные
 * Выведите надлежащую строку навигации. Следуйте формату вывода из тестовых примеров.
*/

define('DEBUG', 0);

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

function solve($n, $p, $k)
{
	$leftPagesCount = min($k, $p-1);
	$rightPagesCount = min($k, $n-$p);
	$leftTags = ($leftPagesCount < $p-1);
	$rightTags = ($rightPagesCount < $n-$p);

	$elements = [];

	// fill elements list
	if ($leftTags) {
		$elements[] = '<<';
	}

	if ($leftPagesCount > 0) {
		for ($i = $leftPagesCount; $i>0; $i--) {
			$elements[] = $p-$i;
		}
	}

	$elements[] = "($p)";

	if ($rightPagesCount > 0) {
		for ($i = 1; $i<=$rightPagesCount; $i++) {
			$elements[] = $p+$i;
		}
	}

	if ($rightTags) {
		$elements[] = '>>';
	}

	return implode(' ', $elements);
}

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

$result = solve($n, $p, $k);

doLog($result . "\n");

echo $result;


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

$nv = explode(" ", rtrim(fgets($in)));
$m = explode(" ", rtrim(fgets($in)));
sort($m);
$sum = array_sum($m)-$m[$nv[0]-1];

if($sum<=$nv[1])
    echo "YES";
else
    echo "NO";


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
unset($c[0]);
$d = array_sum($c);
if($d > $b)
{
    print "NO";
}
else
{
    print "YES";
}
?>


<?php

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

$line = '';

while (!feof(STDIN)) {
	$line .= fgets(STDIN);
}

$line = trim($line);

$mugs = explode(' ', $line);

$response = 'NO';

foreach ($mugs as $mug_taken_off) {
	if (array_sum($mugs) - $mug_taken_off <= $s) {
		$response = 'YES';
		break;
	}
}

echo $response;


#!/usr/bin/env php
<?php
$line1 = trim(fgets(STDIN));
$lineArray1 = explode(' ', $line1);
$line2 = trim(fgets(STDIN));
$lineArray2 = explode(' ', $line2);

$count = isset($lineArray1[0]) ? $lineArray1[0] : 0;
$size = isset($lineArray1[1]) ? $lineArray1[1] : 0;
$volumes = array_slice($lineArray2, 0, $count);
$max = max($volumes);
if ((array_sum($volumes) - $max) <= $size) {
	echo 'YES';
} else {
	echo 'NO';
}


<?php

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

list($n, $s) = explode( " ", trim(fgets(STDIN)) );
$A = explode( " ", trim(fgets(STDIN)) );

$sum = array_sum($A);
$max = max($A);

if ($sum - $max <= $s) {
	echo "YES";
} else {
	echo "NO";
}

echo "\n";


<?php

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

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

	sort($m);

	$mm = 0;
	for($i = 0; $i < ($n - 1); $i++)
	{
		$mm += $m[$i];
	}

	//echo $mm;

	echo ($mm <= $s) ? "YES" : "NO";
	echo PHP_EOL;


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

$line = trim(fgets($h));
$line_arr = explode(' ', $line);
$n = intval($line_arr[0]);
$k = intval($line_arr[1]);

$time = 0;
$nr = 0;
for ($i = 0; $i < $n; $i++) {
	$time += ($i+1) * 5;
	if ($time + $k <= 240) {
		$nr = $i + 1;
	} else {
		break;
	}
}

echo $nr;


<?php
$str = trim(fgets(STDIN));
$mass = str_split($str,1);
$len = count($mass);
$cntH = 0;
$cntL = 0;
for($i=0;$i<$len;$i++)
{
    if (preg_match("/[A-Z]/",$mass[$i]))$cntH++;
    else $cntL++;
}
if ($cntH>$cntL)echo strtoupper($str);
else echo strtolower($str);


<?php
    $str = trim(fgets(STDIN));
    $upper = preg_match_all("/[A-Z]{1}/", $str, $matches);
    echo ($upper > (strlen($str) - $upper) ? strtoupper($str) : strtolower($str));
?>


<?php

$up="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$lo="abcdefghijklmnopqrstuvwxyz";
$str=trim(fgets(STDIN));
  $cnt1=0;
  $cnt2=0;
for($i=0;$i<strlen($str);$i++)
{
  for($j=0;$j<26;$j++)
  {
  	if($str[$i]==$up[$j])
  		$cnt1++;
  	if($str[$i]==$lo[$j])
  		$cnt2++;
  }
}

if($cnt2>=$cnt1)
	echo strtolower($str);
else
   echo	strtoupper($str);


<?php
$s = trim(fgets(STDIN));
$cnt=0;
for ($i=0;$i<strlen($s);$i++)
    ord($s[$i])>=ord("a")?$cnt++:"";
echo $cnt>=(strlen($s)-$cnt)?strtolower($s):strtoupper($s);
?>


<?php
$dir= fopen('php://stdin','r');
$file= file('php://stdin');
$str= trim($file[0]);
$l=0;
$u=0;
for ($i=0,$c=strlen($str);$i<$c;$i++){
    if (ctype_upper($str[$i])){
        $u ++;
    }else{
        $l ++;
    }
}
if ($u <$l || $u == $l){
    $str=strtolower($str);
}else{
    $str =strtoupper($str);
}
echo $str;


<?php

$f = fopen( 'php://stdin', 'r' );
$str = trim(fgets($f));
$mask = array();
$toLower = 0;
$toUpper = 0;
for($i=0;$i<strlen($str);$i++){
    if(preg_match("#[A-Z]#",$str[$i])){
        $toLower+=1;
        $mask[$i]=-1;
    }
    elseif(preg_match("#[a-z]#",$str[$i])){
        $toUpper+=1;
        $mask[$i]=1;
    }
    else{
        $mask[$i]=0;
    }
}
if($toLower > $toUpper){
    $str = strtoupper($str);
}
else{
    $str = strtolower($str);
}
echo($str);

?>


<?php
$line = trim(fgets(STDIN));
$count_lower = 0;
foreach(str_split($line) as $c){
    if( $c>='a' && $c <= 'z') $count_lower++;
}
$count_upper = strlen($line) - $count_lower;
if($count_lower >= $count_upper){
    echo strtolower($line);
}else{
    echo strtoupper($line);
}


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

for ($i = 0; $i < strlen($str); $i++)
{
    if (ctype_upper($str[$i]))
        $k++;
}
if ($k == strlen($str) / 2)
    $str = strtolower($str);
else if ($k > strlen($str) / 2)
    $str = strtoupper($str);
else
    $str = strtolower($str);

echo $str
?>


<?php
$inp = fopen("php://stdin", 'r');
$line = stream_get_contents($inp);
$str = str_split($line);
$cntl=0;
$cntr=0;
foreach($str as $c){
    if(ctype_lower($c)) $cntl++;
    if(ctype_upper($c)) $cntu++;
}
if($cntu <= $cntl) echo strtolower($line);
else echo strtoupper($line);
?>


<?php
$fp=fopen('php://stdin', 'r');
$lines=stream_get_contents($fp);
$lines=trim($lines);
/*
    $lines =
        '100
         15 20 20 15 10 30 45';

   $lines =
        '2
         1 0 0 0 0 0 0';
*/
list($totalPages , $days) = explode("\n",trim($lines));
$eachDay = explode(" ", trim($days));
$totalRead = 0;
while($totalRead < $totalPages)
{
    for($i = 0 ; $i < count($eachDay) ; $i++)
    {
        $totalRead += $eachDay[$i];
        if($totalRead >= $totalPages ) {
            echo $i+1;break;
        }
    }
}

?>


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

$mas = explode(' ', trim(fgets(STDIN)));
$i = 0;
while ($n > 0)
{
    $n -= $mas[$i];
    $k = $i + 1;
    if ($i + 1 == count($mas))
        $i = -1;

    $i++;

}
echo $k;
?>


<?php
    $file = file('php://stdin');
    $pages_cnt = $file[0];
    $page_reading_speed = explode(' ', $file[1]);

    $pages_cnt = (int)$pages_cnt;
    if ($pages_cnt<0)
        exit;

    //check array()
    if (!$page_reading_speed)
        exit;

    foreach ($page_reading_speed as $value) {
        if (!preg_match("/\d/", $value))
            exit;
    }

    if (count($page_reading_speed)!=7)
        exit;

    if (array_sum($page_reading_speed)<=0)
        exit;

    $i = 0;
    $counter = (int)$page_reading_speed[0];
    while ($counter<$pages_cnt) {
        $i++;
        if ($i>6)
            $i = 0;
        $counter += (int)$page_reading_speed[$i];
    }
    echo ($i+1);
    exit;
?>


<?php
$n = intval(trim(fgets(STDIN)));
$w = explode(' ' ,trim(fgets(STDIN)));
$i =0;
while($n > 0){
    if($i == 7) $i = 0;
    $n = $n - $w[$i];
    $i++;
}
echo $i . PHP_EOL;
exit;


<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt = "433
// 109 58 77 10 39 125 15";
$text = explode("\n",$datatxt);
$pages = intval($text[0]);
$day = explode(" ",$text[1]);
$total = 0;
$page_in_week = 0;
foreach($day as $value) {
$page_in_week+=intval($value);
}
$du = $pages%$page_in_week;
$res = 0;
if ($du == 0) {
foreach($day as $key => $value) {
    $total+=$value;
    if($total>=$page_in_week){
    $res = $key+1;
    $check=true;
    break;
    }
    }
}else {
    foreach($day as $key => $value) {
    $total+=$value;
    if($total>=$du){
    $res = $key+1;
    break;
    }
    }
}
echo $res;


<?php
$fr = fopen("php://stdin", "r");
$n = (int) fgets($fr);
$arr = fgets($fr);
fclose($fr);
$arr = explode(' ', $arr);
$sum = 0;
for ($i = 0; $i < 7; $i+= 1) {
    $arr[$i] = (int) $arr[$i];
    $sum+=$arr[$i];
}
$mod = $n % $sum;
if($mod==0)
    $mod=$sum;
$sum2=0;
//echo $mod;
for ($i = 0; $i < 7; $i+= 1) {
    $sum2+=$arr[$i];
    if($sum2>=$mod)
        break;
}
echo $i+1;
?>


<?php
fscanf(STDIN, '%d%d', $n, $m);
$puzzles_sets = explode(" ", trim(fgets(STDIN)));
$buf = 0;
for ($i = 0; $i < $m - 1; $i++) {
    for ($j = 0; $j < $m - $i - 1; $j++) {
        if ($puzzles_sets[$j] > $puzzles_sets[$j+1]) {
            $buf = $puzzles_sets[$j+1];
            $puzzles_sets[$j+1] = $puzzles_sets[$j];
            $puzzles_sets[$j] = $buf;
        }
    }
}
$arr_min = array();
for ($i = 0; $i < $m - $n + 1; $i++) {
    $arr_min[$i]['difference'] = $puzzles_sets[$i+$n-1] - $puzzles_sets[$i];
    $arr_min[$i]['first'] = $i;
}
$min = min($arr_min);
$res = $min['difference'];
print($res);


<?php

function getLine() {
  $line = trim(fgets(STDIN));
  return $line;
}

list($n, $m) = explode(' ', getLine());

$n = intval($n);
$m = intval($m);

$f = explode(' ', getLine());
for ($i = 0, $m = min($m, count($f)); $i < $m; $i ++) {
  $f[$i] = intval($f[$i]);
}

sort($f);
$answer = $f[$n-1] - $f[0];

for ($i = 1; $i + $n <= $m; $i ++) {
  $answer = min($answer, $f[$i + $n - 1] - $f[$i]);
}

print $answer;


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$iArray = explode(" ", trim(fgets($file)));

sort($iArray);

$min = $iArray[$n - 1] - $iArray[0];

for ($i = 1; $i <= $m - $n; $i++) {

    if ($iArray[$i + $n - 1] - $iArray[$i] < $min) {
        $min = $iArray[$i + $n - 1] - $iArray[$i];
    }

}

echo $min;


<?php
    fscanf(STDIN, "%d %d", $m, $n);
    // echo "{$m} {$n}\n";
    $f = explode(" ", trim(fgets(STDIN)));

    sort($f);
    // var_dump($f);
    $ans = PHP_INT_MAX;
    for ($i = 0; $i < $n - $m + 1; $i++) {
    	$ans = min($ans, $f[$m + $i - 1] - $f[$i]);
    	// echo "{$i} {$ans}" . PHP_EOL;
    }

    echo $ans;


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
sort($c);
$d = array();
$f = 0;
for($x = 0; $x < $b - $a + 1; $x++)
{
    $e = $c[$a - 1 + $f] - $c[$f];
    array_push($d, $e);
    $f++;
}
sort($d);
print $d[0];
?>


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$iArray = explode(" ", trim(fgets($file)));

asort($iArray);
array_unshift($iArray, "TDS");
array_shift($iArray);
$min = $iArray[$n - 1] - $iArray[0];

for ($i = 1; $i <= $m - $n; $i++) {

    if ($iArray[$i + $n - 1] - $iArray[$i] < $min) {
        $min = $iArray[$i + $n - 1] - $iArray[$i];
    }
}
echo $min;


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

    $numbers = array_map('intval', explode(' ', fgets(STDIN)));
    sort($numbers);

    $best = 10000;

    for ($i = $n - 1; $i < $m; ++$i)    {
        if ($numbers[$i] - $numbers[$i - $n +1] < $best)    {
            $best = $numbers[$i] - $numbers[$i - $n +1];
        }
    }

    printf("%d\n", $best);

?>


<?php
$n=explode(" ", trim(fgets(STDIN)));
$f=explode(" ", trim(fgets(STDIN)));
sort($f);
$selisih=$n[1]-$n[0];
$arr=array();
for ($i=0; $i <= $selisih ; $i++) {
	$temp1=$f[$i];
	$temp2=$f[$i+$n[0]-1];
	$arr[]=$temp2-$temp1;
}
sort($arr);
echo (int)$arr[0];

?>


<?php
// Retrieve input
$stdin = fopen('php://stdin', 'r');
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Contest 176 Div 2 Problem A
for ($i = 0; $i < 4; $i++) {
	$raw = g();
	for ($j = 0; $j < 4; $j++) {
		$x[$i][$j] = ((substr($raw[0], $j, 1) == "#") ? 1 : 0);
	}
}

function square($i,$j) {
	global $x;
	return $x[$i][$j] + $x[$i][$j+1] + $x[$i+1][$j] + $x[$i+1][$j+1];
}

for ($i = 0; $i < 3; $i++) {
	for ($j = 0; $j < 3; $j++) {
		if (square($i, $j) != 2) {echo "YES"; exit;}
	}
}

echo "NO";

// End of submission file
// Submission by chaotic_iak
?>


<?php
define("_DEBUG", 0);

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

if (!_DEBUG) $str = fgets($fp);
else
	$str = '9';

$n = (int)$str;

if (!_DEBUG)
{
	$str = fgets($fp);
}
else
{
	$str = '110011101';
}

$str = trim($str);

$mas = explode('0', $str);
//var_export($mas);
$res = '';
for ($i = 0; $i < sizeof($mas); $i++)
{
	$res .= strlen($mas[$i]);
}

echo $res;
?>


<?php

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

echo array_reduce(array_map(function ($ones) {
    return strlen($ones);
}, explode('0', trim($s))), function ($number, $digit) {
    $number *= 10;
    return $number + $digit;
}, 0);


<?php
$a=intval(trim(fgets(STDIN)));
$b=explode('0',trim(fgets(STDIN)));
$c='';
for ($i=0;$i<count($b);$i++){
    $c.=strlen($b[$i]);
}
echo $c;
?>


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

$left = $right = $n;

$first = floor($n / 2);
$second = $right - $first;
$therd = $right - $second;

echo $first + $second + $therd;
?>


<?php

$str = file_get_contents('php://stdin');

printf('%s', $str * 3 / 2);


<?php
fscanf(STDIN, "%d",$n);
echo floor(1.5*$n);
?>


<?php
$num=trim(fgets(STDIN));
$input=trim(fgets(STDIN));
preg_match_all("/\(([^\)]*)\)/", $input, $aMatches);
$sResult = $aMatches[1];
$countword1=implode(" ", $sResult);
$countword2=str_word_count($countword1);
$lenthword1=preg_replace("/\([^)]+\)/"," ",$input);
$lenthword2=str_ireplace("_", " ", $lenthword1);
$lenthword3=str_ireplace("( )", " ", $lenthword2);
$lenthword4=str_ireplace("()", " ", $lenthword3);
$ex= explode(" ", $lenthword4);
$longestWordLength = 0;
foreach ($ex as $word) {
   if (strlen($word) > $longestWordLength) {
      $longestWordLength = strlen($word);

   }
}
echo $longestWordLength." ".$countword2;
?>


<?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 pass_compare($p1, $p2) {
	$l1 = strlen($p1);
	$l2 = strlen($p2);
	if ($l1 > $l2) {
		return 1;
	} elseif ($l1 < $l2) {
		return -1;
	}
	return 0;
}

function getAnswer($is_test = false, $f = false) {
	if ($is_test)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	readString($stream);
	$baseStr = readString($stream) . '_';
	$len = strlen($baseStr);

	$isInS = false;
	$maxWord = '';
	$wordsInS = array();
	$isDoingWord = false;
	$currentWord = '';
	for ($i = 0; $i < $len; $i++) {
		if (in_array($baseStr[$i], array('(', ')', '_'))) {

			if (!empty($currentWord)) {
				if ($isInS) {
					$wordsInS[] = $currentWord;
				} elseif (strlen($currentWord) > strlen($maxWord)) {
					$maxWord = $currentWord;
				}
			}
			$isDoingWord = false;
			$currentWord = '';
			if ($baseStr[$i] == '(') {
				$isInS = true;
			} elseif ($baseStr[$i] == ')') {
				$isInS = false;
			}
		} else {
			$isDoingWord = true;
			$currentWord.=$baseStr[$i];
		}
	}
	echo strlen($maxWord) . ' ' . count($wordsInS);
	/* / end body */
}

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


<?php
    list( $n, $m ) = explode(" ", trim(fgets(STDIN)));
    $arr = explode(" ", trim(fgets(STDIN)));
    $used = array();
    $flag = true;
    while($flag)
    {
        $flag = false;
        for($i=0; $i<$n; $i++)
        {
            if(!$used[$i])
            {
                $last = $i + 1;
                $flag = true;
                $arr[$i] = max(0, $arr[$i] - $m);
                if(!$arr[$i])
                    $used[$i] = true;
            }
        }
    }
    echo $last . PHP_EOL;
?>


<?php

function expression($a, $b, $c) {
    $res = array();
    $res[] = $a * $b * $c;
    $res[] = $a + $b * $c;
    $res[] = ($a + $b) * $c;
    $res[] = $a * $b + $c;
    $res[] = $a * ($b + $c);
    $res[] = $a + $b + $c;
    return $res;
}
for ($i = 0; $i < 3; $i++) {
    fscanf(STDIN, '%d\n', $arg[]);
}
$result = max(expression($arg[0], $arg[1], $arg[2]));
print($result);


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$output = array();
$max = 0;

$output[] = $a+$b+$c;
$output[] = $a*$b*$c;
$output[] = $a*$b+$c;
$output[] = $a+$b*$c;
$output[] = $a*($b+$c);
$output[] = ($a+$b)*$c;

for( $i=0; $i<sizeof($output); $i++ ){
    if( $max < $output[$i] ){
        $max = $output[$i];
    }
}
echo $max;


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$res = array();
$res[] = $a*$b+$c;
$res[] = $a+$b*$c;
$res[] = $a+$b+$c;
$res[] = $a*$b*$c;
$res[] = ($a+$b)*$c;
$res[] = $a*($b+$c);
echo max($res);
?>


<?php
fscanf(STDIN, "%d\n", $one);
fscanf(STDIN, "%d\n", $two);
fscanf(STDIN, "%d\n", $three);

$variants = [];

$variant[0] = $one + $two * $three;
$variant[1] = $one * ($two + $three);
$variant[2] = $one * $two * $three;
$variant[3] = ($one + $two) * $three;
$variant[4] = $one + $two + $three;

print_r(max($variant));


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
echo max($a*$b*$c, $a+$b+$c, ($a+$b)*$c, $a*($b+$c));
?>


<?php
$a=trim(fgets(STDIN));
$b=trim(fgets(STDIN));
$c=trim(fgets(STDIN));
$arr=array();
$arr[0]=$a + $b * $c;
$arr[1]=$a * ($b + $c);
$arr[2]=$a * $b * $c;
$arr[3]=($a + $b) * $c;
$arr[4]=$a + $b + $c;

echo max($arr);

?>


<?php
	$a = trim(fgets(STDIN));
	$b = trim(fgets(STDIN));
	$c = trim(fgets(STDIN));
	$data[] = $a+$b*$c;
	$data[] = ($a+$b)*$c;
	$data[] = $a*$b+$c;
	$data[] = $a*($b+$c);
	$data[] = $a+$b+$c;
	$data[] = $a*$b*$c;
	echo max($data);
?>


<?php
$in_a = trim(fgets(STDIN));
$in_b = trim(fgets(STDIN));
$in_c = trim(fgets(STDIN));
$res[] = $in_a*$in_b+$in_c;
$res[] = $in_a+$in_b*$in_c;
$res[] = $in_a+$in_b+$in_c;
$res[] = $in_a*$in_b*$in_c;
$res[] = ($in_a+$in_b)*$in_c;
$res[] = $in_a*($in_b+$in_c);
echo max($res);
?>


<?php

if (getenv('APPLICATION_ENV') == 'development') {
    $inputStream = fopen('82A.txt', 'r');
    $outputStream = STDOUT;
} else {
    $inputStream = STDIN;
    $outputStream = STDOUT;
}
function f($n) {
    $it = 0;
    if ($n < 5) {
        return $n;
    }
    $i = 0;
    while ($i + $i + 5 < $n) {
        $i = $i + $i + 5;
        $it++;
    }
    $eachCnt = pow(2, $it);
    return intval( ($n - $i - 1) / $eachCnt + 0.000001 ) + 1;
}
$ret = array(1 => "Sheldon", 2 => "Leonard", 3 => "Penny", 4 => "Rajesh", 5 => "Howard");

$n = (int) fgets($inputStream);

$out = $ret[f($n)];
fwrite($outputStream, $out);

if (getenv('APPLICATION_ENV') == 'development') {
    fclose($inputStream);
    fclose($outputStream);
}


<?php

$in = fopen('php://stdin', 'r');
/*$out = fopen('php://stdout', 'w');
$in = fopen('a.in', 'r');
$out = fopen('php://stdout', 'w');*/

$persons = array(
	"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"
);
$pos = (int)fgets($in) - 1;
$c = floor($pos/5) + 1;
$len = floor(log($c, 2));

$sl = pow(2, $len);
$rs = (int) (($sl - 1) * 5);
$rl = ($pos - $rs);
$p = (int)floor($rl / $sl);

//echo $c . ' ' . $len . ' ' . $rs . ' ' . $rl . ' ' . $p;
echo $persons[$p] . "\n";


<?php
$a = trim(fgets(STDIN));
$mas = array("Sheldon", "Leonard", "Penny", "Rajesh", "Howard");
$a--;
while ($a >= 5)
{
    $a -= 5;
    $a /= 2;
}

echo $mas[$a];
?>


<?php
$n=trim(fgets(STDIN));
$a=array("Sheldon","Leonard","Penny","Rajesh","Howard");
while($n>5) { $n -= 5; $n /= 2; }
print $a[ceil($n)-1];


<?php
    define('DEBUG', 0);

    if(DEBUG) $GLOBALS['file'] = fopen('input.txt', 'r');
    function debug($var){echo '<pre>';print_r($var);echo '</pre>';}
    function read_line()
    {
        if(DEBUG) { $file = $GLOBALS['file'];$line = trim(fgets($file));}
        else $line = trim(fgets(STDIN));
        return $line;
    }
    function get_array($line){return explode(' ', $line);}
    function read_array(){return get_array(read_line());}
    //echo "$s\n";
    /*****************************************************************/

    $n = read_line();
    //$n = 1802;

    $people[] = 'Sheldon';
    $people[] = 'Leonard';
    $people[] = 'Penny';
    $people[] = 'Rajesh';
    $people[] = 'Howard';

    if($n<=5)
    {
        echo $people[$n-1];
        die;
    }

    $k=1;
    $sum = 5;
    $sum_next = 15;

    while($sum_next<$n)
    {
        $k++;
        $sum = $sum_next;
        $sum_next = $sum + 5*pow(2,$k);
    }

    $o = $n-$sum;

    $k = pow(2,$k);

    $a = ceil($o/$k);
    echo $people[$a-1];
?>


<?php
$stdin = fopen('php://stdin', 'r');
$c = fgets($stdin);
$i_d = 5;

while(1){
	if ($c > $i_d){
		$c = $c - $i_d;
		$i_d = $i_d * 2;
	}
	else{

		$where = ($c / ($i_d/5));
		if($where <= 1){echo "Sheldon";}
		elseif($where <= 2){echo "Leonard";}
		elseif($where <= 3){echo "Penny";}
		elseif($where <= 4){echo "Rajesh";}
		elseif($where <= 5){echo "Howard";}
		else{echo "erorrr";}
		goto end;
	}

}
end:
?>


<?php

$in = trim(fgets(STDIN));
$names = ["", "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];
$result = 5;
$min = 0;
$pow = 1;
$level = 0;

if ($in <= 5) {
    echo $names[$in];
    exit;
}

while ($in > $min) {
    if ($level) {
        $pow *= 2;
    }

    $min = 10 * $pow - 5;
    $level++;
}

while ($in + $pow <= $min) {
    $min -= $pow;
    $result--;
}

echo($names[$result]);


<?php

$in = trim(fgets(STDIN));
$names = ["", "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"];
$result = 5;
$min = 0;
$level = 0;

while ($in > $min) {
    $min = 10 * pow(2, $level) - 5;
    $level++;
}

$range = pow(2, $level - 1);

while ($in + $range <= $min) {
    $min -= $range;
    $result--;
}

echo($names[$result]);


<?php
/**
 * Created by PhpStorm.
 * User: User
 * Date: 8/13/2017
 * Time: 8:48 PM
 */

$val = explode(' ', fgets(STDIN));
$arr = explode(' ', fgets(STDIN));
$sum = 0;
$status = 0;
$hold = -1;
$temp = 0;
for($i=0;$i<$val[0];$i++){

	if($arr[$i]>8){
		$sum+=8;
		$arr[$i+1]+=($arr[$i] - 8);
	}
	else{
		$sum+=$arr[$i];
	}
	//print $sum . ' ';
	if($sum>=$val[1]){
		$hold = $i+1;
		break;
	}

}
print $hold;
?>


<?php
$file = fopen('php://stdin', 'rt');
$c = fgets($file);
$str = fgets($file);
fclose($file);
$a = 0;
for ($i=0; $i<strlen($str)-1; $i++) {
	if ($str[$i]==$str[$i+1]) $a++;
}
$file = fopen('php://stdout', 'w+');
fwrite($file, $a);
fclose($file);
?>


<?php

fscanf(STDIN, "%d\n", $n);
fscanf(STDIN, "%s\n", $stones_str);

$stones = str_split($stones_str);

$prevStone = "";
$nextStone = "";
$currentStone = "";
$newStones = "";
$removedStones = 0;
for ($i = 0; $i < $n; $i++) {
    $prevStone = $currentStone;
    $currentStone = $stones[$i];
    if ($i != 0) {
        $prevStone = $stones[$i - 1];
    }
    else {
        $newStones .= $currentStone;
    }

    if ($currentStone != $prevStone){
        $newStones .= $currentStone;
    }
    else {
        if ($i != 0) {
            $removedStones++;
        }
    }
}

echo $removedStones;
?>


<?php
$n = rtrim(fgets(STDIN));
$stones = str_split(rtrim(fgets(STDIN)));
$r = 0;
for($i=0; $i<$n; $i++)
{
    if(array_key_exists($i+1, $stones) && ($stones[$i] == $stones[$i+1])){
        $r++;
    }
}
echo($r);


<?php
/**
 * Secdra @2020
 */

fscanf(STDIN, "%d", $word_len);
$word = trim(fgets(STDIN));
$new_word = $word[0];
for ($i = 0; $i < $word_len; $i++) {
    if ($word[$i] != $new_word[-1])
        $new_word .= $word[$i];
}
printf("%d", $word_len - strlen($new_word));


<?php
$len = trim(fgets(STDIN)) - 1;
$s = trim(fgets(STDIN));
$remove = 0;
for($i=0;$i<$len;$i++){
    if ($s[$i] === $s[$i+1])
        $remove++;
}
print $remove;
?>


<?php
define('endl',PHP_EOL);// PHP end of line

$c=0;
fscanf(STDIN,"%d",$n);
fscanf(STDIN,"%s",$st);

for($i=1;$i<strlen($st);$i++)
    if($st[$i]==$st[$i-1])$c++;

fprintf(STDOUT,"%d",$c);

?>


<?php
$n = trim(fgets(STDIN));
$stone = str_split(trim(fgets(STDIN)),1);
$tik = $n;
for ($i=1;$i<$n;$i++)
{
    if ($stone[$i-1]==$stone[$i])$tik--;
}
echo $n-$tik;


<?php

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

$count = 0;
for($i = 1; $i<$n; ++$i) {
    if($str[$i] == $str[$i-1]) {
        ++$count;
    }
}
fprintf(STDOUT,$count);

?>


<?php

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

fscanf($stdin, '%d', $n);

$str = str_split(trim(fgets($stdin)));

$result = array();
$prev = null;
for($i = 0; $i < $n; $i++)
{
	if($prev == null || $prev != $str[$i])
	{
		$result[] = $str[$i];
		$prev = $str[$i];
	}
}

echo $n - count($result);


<?php
// 513A     Игра
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
list($n1, $n2, $k1, $k2) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$n1 = (int) $n1;
$n2 = (int) $n2;
$k1 = (int) $k1;
$k2 = (int) $k2;

if (($n1 - $n2) > 0) {
    $out = 'First';
} else {
    $out = 'Second';
}

echo $out;

?>


<?php
$line = trim(fgets(STDIN));
$in = explode(" ", $line);
$n1 = intval($in[0]);
$n2 = intval($in[1]);
$k1 = intval($in[2]);
$k2 = intval($in[3]);

do {
	$n1 -= 1;
	$n2 -= 1;
} while ($n1 > 0 && $n2 > 0);

if ($n1 == 0)
	$result = 'Second';
else
	$result = 'First';

fprintf(STDOUT, $result);


<?php
list ($n1, $n2, $k1, $k2) = explode(' ', trim(fgets(STDIN)));

if ($n2 >= $n1) {
  echo "Second\n";
} else {
  echo "First\n";
}


<?php
list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
if($b >= $a)
{
    print "Second";
}
else
{
    print "First";
}
?>


<?php

list($n1, $n2, ,) = explode(" ", getLine());
echo ($n1>$n2 ? "First" : "Second") . PHP_EOL;

function getLine()
{
    return trim(fgets(STDIN));
}


<?php

$line = readline();
$prompt = explode(' ', $line);
if ($prompt[0] > $prompt[1]) {
    echo "First";
}else{
    echo "Second";
}


<?php
list($a,$b,$n)=explode(' ',trim(fgets(STDIN)));
function HOD($a,$n) {
    while ($a*$n != 0) !($a < $n) ? $a %= $n : $n %= $a;
    return ($a + $n);
}
while(true) {
    $n -= HOD($a,$n);
    if($n<=0) { echo '0'; break; }
    $n -= HOD($b,$n);
    if($n<=0) { echo '1'; break; }
}


<?php
function gcd($i, $j){
 if($i == 0) return $j;
 if($j == 0) return $i;
 if($i == $j) return $i;
 if($i > $j) return gcd($i % $j, $j); else return gcd($i, $j % $i);
}

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

$r = 1;
while($n > 0){
 if($r == 1) $n -= gcd($n, $a); else $n -= gcd($n, $b);
 $r = 1 - $r;
}

print $r;

?>


<?php
function NWD($a, $b) {
    while ($b != 0) {
        $c = $a % $b;
        $a = $b;
        $b = $c;
    }
    return $a;
}

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

$player = 0;
while($n > 0) {
    if(!$player) {
        $c = $a;
    } else {
        $c = $b;
    }
    $n -= NWD($c, $n);
    $player = !$player;
}

echo intVal(!$player);


<?php
list($a,$b,$n)=explode(" ", trim(fgets(STDIN)));
function nod($a, $b) {
    while ($a != $b)
        if ($a>$b)
            $a -= $b;
        else
            $b -= $a;
    return $a;
}
function lite($a,$b,$n){
   $f=nod($a,$n);
   if (($n-$f)==0) return 0;
   $f1=nod($b,$n-$f);
   if (($n-$f-$f1)==0) return 1;
   return lite($a,$b,$n-=($f+$f1));
}
print lite($a, $b, $n);
?>


<?php
while($s = fgets(STDIN)){
$input .= $s;
}

function NOD($a, $b) {
    if($a == 0) return $b;
    if($b == 0) return $a;
    $max = max($a, $b);
    for ($i=1; $i <= $max; $i++) {
        if((($a % $i) == 0) && (($b % $i) == 0)) {
            $delitels[] = $i;
        }
    }

    return max($delitels);
}

$input = explode(' ', $input);
$semen = (int)$input[0];
$anti = (int)$input[1];
$stones = (int)$input[2];

$status = 0;
$winner = 0;
while(true) {

    if($status == 0) {
        $take = NOD($semen, $stones);
        $stones = $stones - $take;
        if($stones < $take) {
            $winner = 0;
            break;
        }

        $status = 1;
    }

    if($status == 1) {
        $take = NOD($stones, $anti);
        $stones = $stones - $take;
        if($stones < $take) {
            $winner = 1;
            break;
        }

        $status = 0;
    }

}

echo $winner;


<?php
list($a,$b,$n) = explode(" ",trim(fgets(STDIN)));
function gcd($a,$b)
{
    return ($a % $b) ? gcd($b,$a % $b) : $b;
}
while (true)
{
    if ($n==0){echo "1";break;}
    $n -= gcd($a,$n);
    if ($n==0){echo "0";break;}
    $n -= gcd($b,$n);
}


<?php
  $fr = fopen("php://stdin", "r");
  $fw = fopen("php://stdout", "w");

  fscanf($fr, "%d", $n);
  $n *= 2;
  $k = (int)sqrt($n);
  $found = false;
  for ($i = 1; $i < $k; $i ++)
  {
    $r = $n - $i * $i - $i;
    $x = (int)sqrt($r);
    if ($x * ($x + 1) == $r)
    {
      $found = true;
      break;
    }
  }
  if ($found)
  {
    fprintf($fw, "YES");
  }
  else
  {
    fprintf($fw, "NO");
  }
  fclose($fr);
  fclose($fw);
?>


<?php
$num = trim(fgets(STDIN)) * 2;
$Endk1 = (int)sqrt($num);
$res = false;

for ($Startk1 = 1; $Startk1 < $Endk1; $Startk1++) {
    $If = $num - $Startk1 * $Startk1 - $Startk1;
    $k2 = (int)sqrt($If);
    if ($k2 * ($k2 + 1) == $If) {
        $res = true;
        break;
    }
}

if ($res)
    echo 'YES';
else
    echo 'NO';


<?php
  $fr = fopen("php://stdin", "r");
  //$fw = fopen("php://stdout", "w");

  fscanf($fr, "%d", $n);
  $n *= 2;
  $k = (int)sqrt($n);
  $found = false;
  for ($i = 1; $i < $k; $i ++)
  {
    $r = $n - $i * $i - $i;
    $x = (int)sqrt($r);
    if ($x * ($x + 1) == $r)
    {
      $found = true;
      break;
    }
  }
  if ($found)
  {
    //fprintf($fw, "YES");
    echo "YES";
  }
  else
  {
    //fprintf($fw, "NO");
    echo "NO";
  }
  fclose($fr);
  //fclose($fw);
?>


<?php
$num = trim(fgets(STDIN)) * 2;
$Endk1 = (int)sqrt($num);
$res = false;

for ($Startk1 = 1; $Startk1 < $Endk1; $Startk1++) {
    $If = $num - $Startk1 * $Startk1 - $Startk1;
    $k2 = (int)sqrt($If);
    if ($k2 * ($k2 + 1) == $If) {
        $res = true;
        break;
    }
}

if ($res)
    echo 'YES';
else
    echo 'NO';
?>


<?php //rextester.com:7.0.8--codeforces.com:7.0.12
$a=fgets(STDIN)*2;$b=false;
for($i=1;$i<(int)sqrt($a);$i++){
    $c=$a-$i*$i-$i;$d=(int)sqrt($c);
    if($d*($d+1)==$c)$b=true;
}
if($b)echo'YES';else echo'NO';


<?php
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%d", $b);
$c = $a + $b;
$a = str_replace('0', '', $a);
$b = str_replace('0', '', $b);
$c = str_replace('0', '', $c);
if ($a + $b == $c) {
    echo "YES\n";
} else {
    echo "NO\n";
}


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

        if( str_replace('0', '', $m) + str_replace('0', '', $n) == str_replace('0', '', $n + $m) )
            echo 'YES';
        else
            echo 'NO';

?>


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = str_split($a);
$d = str_split($b);
$e = $a + $b;
$f = str_split($e);
for($x = 0; $x < strlen($a); $x++)
{
    if($c[$x] == "0")
    {
        unset($c[$x]);
    }
}
for($x = 0; $x < strlen($b); $x++)
{
    if($d[$x] == "0")
    {
        unset($d[$x]);
    }
}
for($x = 0; $x < strlen($e); $x++)
{
    if($f[$x] == "0")
    {
        unset($f[$x]);
    }
}
if(implode($c) + implode($d) == implode($f))
{
    print "YES";
}
else
{
    print "NO";
}
?>


<?php

    function f($x)
    {
        $res = 0;
        $pow = 1;
        while($x > 0)
        {
            $q = $x % 10;
            $x /= 10;
            if($q == 0) continue;
            $res += $q * $pow;
            $pow *= 10;
        }
        return $res;
    }
    //$in = fopen("input.in", "r");
    $in = fopen("php://stdin", "r");
    $x = fgets($in);
    $y = fgets($in);

    if(f($x) + f($y) == f($x + $y)) echo "YES";
    else echo "NO";

    fclose($in);
?>


#!/usr/bin/php
<?php

$string = trim(fgets(STDIN));
$current = 0;

for ($i = 0; $i < strlen($string); $i++) {
	if (ord($string[$i]) <= ($current + ord('a') - 1)) {

	} else if (ord($string[$i]) == ($current + ord('a'))) {
		$current++;
	} else {
		echo "NO";
		exit();
	}
}

echo "YES";
exit();


<?php

error_reporting(0);

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

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

$alfabeto = array("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");

$str=$linhas[0];

$l=sizeof($alfabeto);

for($i=0;$i<$l;$i++) {

$firstLetter = $alfabeto[$i];

if($str[0]==$firstLetter) {

	$str = str_replace($firstLetter, "", $str);

	if(strlen($str) == 0) {
		die("YES");
	}

	continue;

}

else die("NO");

}

?>


<?php
$s1 = trim(fgets(STDIN));
$s2 = trim(fgets(STDIN));
$keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./";
for ($i = 0; $i < strlen($s2); $i++)
	printf("%s",$keyboard[strpos($keyboard,$s2[$i]) - ($s1 == "R") + ($s1 == "L")]);
?>


<?php
    $dir = trim(fgets(STDIN));
    fscanf(STDIN, "%s", $word);
    $keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./";
    $length = strlen($word);

    for($i=0; $i<$length; $i++)
    {
        $pos = strpos($keyboard, $word[$i]);
        echo $keyboard[ $pos -1 * ($dir=="R") + 1 * ($dir=="L") ];
    }

    echo PHP_EOL;
?>


<?php
error_reporting(0);
$lines = explode("\n", file_get_contents("php://stdin"));

$shift = trim($lines[0]);
$str = trim($lines[1]);

$keysraw = str_split("qwertyuiopasdfghjkl;zxcvbnm,./'");
$keysindex = array();

foreach($keysraw as $index=>$key) {
    $keysindex[$key] = $index;
}

if($shift == "L") {
    foreach(str_split($str) as $char) {
        echo $keysraw[$keysindex[$char]+1];
    }
}

if($shift == "R") {
    foreach(str_split($str) as $char) {
        echo $keysraw[$keysindex[$char]-1];
    }
}
echo "\n";
?>


<?php
    $keysstr = 'qwertyuiopasdfghjkl;zxcvbnm,./';

    $keys = str_split($keysstr);

    $t = (strpos(fgets(STDIN), "L")) === false ? -1 : 1;

    for ($i = 0; $i < count($keys); ++$i)    {
        if ($i + $t >= 0 && $i + $t < count($keys))
        $mapp[$keys[$i]] = $keys[$i + $t];
    }

    $in = str_split(fgets(STDIN));

    $out = "";

    for ($i = 0; $i < count($in); ++$i)    {
        $out .= $mapp[$in[$i]];
    }

    echo $out;

?>


<?php
$dir                = fopen("php://stdin", 'r');
$contents           = stream_get_contents($dir);
$inputs             = explode("\n",$contents);
$stringLength       = explode(' ', $inputs[0])[0];
$encryptedString    = $inputs[1];
echo getOriginalWord($stringLength, $encryptedString);

function getOriginalWord($stringLength, $encryptedString)
{
    $originalString = $encryptedString;
    for($d = 2; $d <= $stringLength; $d++)
    {
        if(($stringLength % $d) == 0)
        {
            $string = substr($originalString, 0, $d);
            $newString = strrev($string);
            $originalString =  preg_replace('/'.$string.'/', $newString, $originalString, 1);
        }

    }

    return $originalString;
}
?>


<?php
fscanf(STDIN,"%d",$lenOfStr);
fscanf(STDIN,"%s",$str);
$j=0;
$rslt=array();
for ($i=1; $i <=ceil($lenOfStr/2) ; $i++)
 {
	$divisor=$lenOfStr/$i;
	if($divisor==floor($divisor))
     {
     	$rslt[$j++]=$divisor;
     }
 }
 if(count($rslt)==1)
 	echo strrev($str);
 else
 {
 	$str2="";
 	$str3="";
    $rev=strrev($str);
    $start=0;
     $last=substr($rev,strlen($str)-$rslt[count($rslt)-1],$rslt[count($rslt)-1]);
    // echo "last=$last";

    for ($i=0; $i <count($rslt)-1 ; $i++)
     {
    	$diff=$rslt[$i]-$rslt[$i+1];
    	$str1=substr($rev,$start,$diff);
    	if($i%2==0)
    	{
          $str2.=$str1;
        }
        else
        	$str3.=$str1;

    	$start+=$diff;
     }
     if(count($rslt)%2==0)
     echo $str2.strrev($last).strrev($str3);
     else
     echo $str2.$last.strrev($str3);

 }


<?php
fscanf(STDIN, '%s', $line);
$line = str_split($line);
$line = count(array_unique($line));

if(($line % 2) == 0){
	print_r("CHAT WITH HER!");
}else{
	print_r("IGNORE HIM!");
}


<?php
$name = fgets(STDIN);

$chars = array_fill(0, 26, 0);

for ($i=0; $i < strlen($name); $i++) {
	$chars[ord($name[$i])-97] = 1;
}
for ($i=0; $i < 26; $i++) {
	$sum += $chars[$i];
}

echo ($sum%2==0)?"CHAT WITH HER!":"IGNORE HIM!";

?>


<?php
$s = trim(fgets(STDIN));
$newS = array();
for ($i=0;$i<strlen($s);$i++){
    if (! in_array($s[$i], $newS))
        array_push($newS, $s[$i]);
}
echo (count($newS) % 2 == 0 ? "CHAT WITH HER!" : "IGNORE HIM!");
?>


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

$used = array();

for ($i = 0; $i < strlen($s); $i ++) {
	$used[ord($s[$i]) - 97] = true;
}

$count = 0;
for ($i = 0; $i < 26; $i ++) {
	$count += isset($used[$i]);
}

printf("%s", $count&1 ? "IGNORE HIM!" : "CHAT WITH HER!");
?>


<?php

$name = readline("Command: ");

	$arr = str_split($name);
	$lenght_arr_one = sizeof($arr);

	$arr2 = (array_unique($arr));
	$lenght_arr_two = sizeof($arr2);

	if($lenght_arr_two % 2 == 0){
		echo 'CHAT WITH HER!';

	}else{
		echo 'IGNORE HIM!';

	}


<?php

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

     $v = array();

     for ($i = 0; $i < strlen($a); $i++)
        $v[$a[$i]] = 1;

     if  (count($v) % 2 == 0)
     echo ("CHAT WITH HER!");
     else
     echo ("IGNORE HIM!");

 ?>


<?php

$input1 =  count(array_unique(str_split(readline())));

echo ($input1 % 2) == 0 ? 'CHAT WITH HER!' : 'IGNORE HIM!';


<?php

   $input = strlen(count_chars(trim(fgets(STDIN,100)),3))%2==0? 'CHAT WITH HER!' : 'IGNORE HIM!';

   	echo $input;

?>


<?php
$s = trim(fgets(STDIN));
$arr=str_split($s);
$arr=array_unique($arr);
if (count($arr) % 2 == 0) {
	echo "CHAT WITH HER!";
}else{
	echo "IGNORE HIM!";
}

?>


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

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

?>


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


<?php

$values = array_map('intval', explode(' ',trim(fgets(STDIN))));
$k = $values[0];
$n = $values[1];
$s = $values[2];
$p = $values[3];

$spp = ceil($n / $s);
$s = $spp * $k;
$packs = ceil($s / $p);

echo $packs."\n";


<?php
list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
$e = ceil($b / $c);
$f = $a * $e;
$g = ceil($f / $d);
print $g;
?>


<?php
$a = explode(" ", trim(fgets(STDIN)));
$b = array_sum($a);
$c = $b % 5;
$d = $b / 5;
if($b == 0)
{
    print "-1";
}
elseif($c == 0)
{
    print $d;
}
else
{
    print "-1";
}
?>


<?php
	$input = explode(" ",trim(fgets(STDIN)));
	$sum = array_sum($input);
	if($sum%5==0 && $sum>0){
		echo $sum/5;
	}
	else{
		echo "-1";
	}
?>


<?php

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

$a = (int)$raw[0];
$b = (int)$raw[1];
$c = (int)$raw[2];
$d = (int)$raw[3];
$e = (int)$raw[4];

$count = $a + $b + $c + $d + $e;

if ($count % 5 != 0 || $count == 0) {
    echo -1 . PHP_EOL;
} else {
    echo $count / 5 . PHP_EOL;
}


<?php
$player = explode(" ",trim(fgets(STDIN)));
$summ =0;
for ($i=0;$i<count($player);$i++)
{
    $summ+=$player[$i];
}
if ($summ%5==0&&$summ!=0)echo $summ/5;
else echo -1;


<?php
$input = explode(" ", trim(fgets(STDIN)));
$sum = array_sum($input);
echo (($sum%5!=0 || $sum==0) ? -1 : ($sum/5));
?>


<?php
	$s = fscanf(STDIN, "%d %d %d");
	$location = Array((int)$s[0]/2, (int)$s[0]/2+1);
    echo (in_array($s[1], $location)&&in_array($s[2], $location))?"NO":"YES";
?>


<?php
$longitud = fgets(STDIN);
$string = fgets(STDIN);
$values = str_split($string);
$contador = 0;
$aux = 0;
for ($x = 0; $x < $longitud; $x++) {
    if ($values[$x] == 'x') {
        $aux++;
        $contador++;
    }

    if (($values[$x] != "x")   && ($aux >= 3)) {
        $contador = $contador - 2;
    }

    if (($values[$x] != "x")  &&   $aux < 3) {
        $contador = $contador - $aux;
    }
    if (($values[$x] != "x")) {
        $aux = 0;
    }

}
if ($aux < 3 && $values[$longitud - 1] == "x") {
    $contador = $contador - $aux;
}

if ($aux >= 3 && $values[$longitud - 1] == "x") {
    $contador = $contador - 2;
}

echo $contador;


<?php
$n=fgets(STDIN);
$input=str_split(fgets(STDIN));
$r=0;
for ($i=0; $i < $n ; $i++) {
      if($input[$i] == 'x' and $input[$i+1] == 'x' and $input[$i+2] == 'x'){
            $r++;
      }
}
echo $r;


<?php

fscanf(STDIN, "%d", $data1);
fscanf(STDIN, "%s", $data2);

$main = new MainClass;

echo $main->solution($data1, $data2);

// End of interface

class MainClass {
	// 978В.File name
	//public $problemLink = 'https://codeforces.com/problemset/problem/978/B';
	//public $submissionLink = '';

	public function solution($n, $string)
	{
		$res=0;
		$counter=0;
		for ($i=0; $i<$n; $i++){
			if ($string[$i] === 'x'){
				$counter++;
			} else {
				$counter=0;
			}
			if($counter>2){
				$res++;
			}
		}
		return $res;
	}
}


<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $s);
$o = $s;
while (strpos($o, "xxx") !== false){
	$o = str_replace("xxx", "xx", $o);
}

echo strlen($s) - strlen($o);
?>


<?php

$data1 = (int) trim(fgets(STDIN));
$data2 = str_split(trim(fgets(STDIN)), 1);

$main = new MainClass;

echo $main->solution($data1, $data2);

// End of interface

class MainClass {
	// 978В.File name
	//public $problemLink = 'https://codeforces.com/problemset/problem/978/B';
	//public $submissionLink = '';

	public function solution($n, $arrayOfStrings)
	{
		$res=0;
		$counter=0;
		foreach ($arrayOfStrings as $value){
			if ($value === 'x'){
				$counter++;
			} else {
				$counter=0;
			}
			if($counter>2){
				$res++;
			}
		}
		return $res;
	}
}


<?php

$data1 = (int) trim(fgets(STDIN));
$data2 = trim(fgets(STDIN));

$main = new MainClass;

echo $main->solution($data1, $data2);

// End of interface

class MainClass {
	// 978В.File name
	//public $problemLink = 'https://codeforces.com/problemset/problem/978/B';
	//public $submissionLink = '';

	public function solution($n, $string)
	{
		$res=0;
		for ($i=0; $i<$n; $i++){
			if (substr($string, $i-1, 3) === 'xxx'){
				$res++;
			}
		}
		return $res;
	}
}


<?php
$n = intval(trim(fgets(STDIN)));
$line = trim(fgets(STDIN));
$orig = $line;
while(strpos($line,"xxx") !== false){
    $line = str_replace("xxx","xx",$line);
}
echo abs(strlen($line) - strlen($orig)) . PHP_EOL;
exit;


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

$result = [];
$sum = 0;
$total = 0;
for ($i = 0; $i < $count; $i++) {
    if ($string[$i] == 'x') {
        $sum++;
    } else {
        if ($sum > 2) {
            $total += $sum - 2;
        }
        $sum = 0;
    }
}
if ($sum > 2) {
    $total += $sum - 2;
}

echo $total;


<?php
$a = trim(fgets(STDIN));
$b = " " . trim(fgets(STDIN));
$c = 0;
while(TRUE)
{
     $d = strpos($b, "xxx");
     if($d == TRUE)
     {
          $c++;
          $b = str_split($b);
          unset($b[$d]);
          $b = implode($b);
     }
     else
     {
          break;
     }
}
print $c;
?>


<?php //http://rextester.com php 7.0.8
list($grown_ups,$children)=explode(' ',trim(fgets(STDIN)));
if($grown_ups<1&$children>0){echo'Impossible';return;}
$max=$grown_ups+$children-1;
if($children==0)$max=$grown_ups;
echo max($grown_ups,$children).' '.$max;


<?php //http://rextester.com php 7.0.8
list($Parent,$Childs)=explode(' ',trim(fgets(STDIN)));
if($Parent<1&$Childs>0){echo'Impossible';return;}
$min=$Parent;
if($Childs>$Parent){$min=$Childs;}
$max=$Parent;
if($Childs>0)$max+=$Childs-1;
echo $min.' '.$max;


<?php //http://rextester.com php 7.0.8
list($a,$b)=explode(' ',trim(fgets(STDIN)));
if($a<1&$b>0){echo'Impossible';return;}
$d=$a+$b-1;
if($b==0)$d=$a;
echo max($a,$b).' '.$d;


<?php

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

if ($Parent < 1 && $Childs > 0) {
    echo 'Impossible';
    return;
}

$min = $Parent;
if ($Childs - $Parent > 0) $min += $Childs - $Parent;

$max = $Parent;
if ($Childs > 0) $max += $Childs - 1;

echo $min . ' ' . $max;


<?php

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

if ($Childs == 0)
    $max = $Parent;
else
    $max = $Parent + $Childs - 1;
if ($Childs >= $Parent)
    $min = $Parent + ($Childs - $Parent);
else
    $min = $Parent;

if ($Parent == 0 && $Childs != 0)
    echo "Impossible";
else
    print $min . ' ' . $max;


<?php //http://rextester.com php 7.0.8
list($a,$b)=explode(' ',trim(fgets(STDIN)));
if($a<1&$b>0){echo'Impossible';return;}
$d=$a;
if($b>0)$d+=$b-1;
echo max($a,$b).' '.$d;


<?php //rextester.com:7.0.8--codeforces:7.0.12
list($a,$b)=explode(' ',trim(fgets(STDIN)));
if($a<1&$b>0){echo'Impossible';return;}
if($b!=0)$d=$a+$b-1;else$d=$a;echo max($a,$b).' '.$d;


<?php //http://rextester.com php 7.0.8
list($a,$b)=explode(' ',trim(fgets(STDIN)));
if($a<1&$b>0){echo'Impossible';return;}
$c=$a;
if($b>$a){$c=$b;}
$d=$a;
if($b>0)$d+=$b-1;
echo$c.' '.$d;


<?php
    list( $n, $x ) = explode(" ", trim(fgets(STDIN)));
    $arr = array();
    for($i=1; $i<=$x && $i<=sqrt($x); $i++)
        if( $x % $i == 0 )
            array_push($arr, $i);
    $buffer = $used = array();
    foreach($arr as $t)
        array_push($buffer, $t, $x / $t);
    unset($arr);
    sort($buffer);
    $arr = array();
    foreach($buffer as $t)
    {
        if(!$used[$t])
            array_push($arr, $t);
        $used[$t]++;
    }
    $cnt = 0;
    for($i=0; $i<sizeof($arr)/2; $i++)
        if( $arr[$i] <= $n && $x / $arr[$i] <= $n )
            $cnt += 1 + ($x / $arr[$i] != $arr[$i]);
    echo $cnt . PHP_EOL;
?>


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

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

fscanf($stdin, "%d%d%d", $k, $n, $w);
//fscanf($stdin, "%d", $n);
//fscanf($stdin, "%d", $w);

/*echo $k."\n";
echo $n;
echo $w;
*/
$sum = 0;

for($i=1; $i<=$w ;$i++){
	$sum += $i*$k;
}

if($n > $sum){
    fwrite($stdout, 0);
}else{
    fwrite($stdout,$sum - $n);
}

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

 ?>


<?php
list($k, $n, $w) = sscanf(fgets(STDIN), '%d %d %d');

$s = ($k + $w*$k) * $w / 2;

if ($s > $n) {
	echo $s - $n;
} else {
	echo 0;
}


<?php

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

function find_how_much ($k,$m,$a) {

    $sum = 0;
    for($i = 1;$i <= $a;$i++) {

        $sum += ($k * $i);

    }

    if($sum - $m >= 0) {

        return ($sum - $m);

    }else {

        return 0;

    }

}

//Explode The Given Input.
$input = explode(" ",$input);

echo find_how_much($input[0],$input[1],$input[2]);

?>


<?php
$input = explode(" ",rtrim(fgets(STDIN)));
$k=$input[0];
$n=$input[1];
$w=$input[2];
$total=0;
for($x=1; $x<=$w; $x++){
   $total=$total+($k*$x);
}
if($total>$n){
  echo $total-$n;
}else{
  echo "0";
}


<?php
class SolierAndBananas{
    public function index($k, $n, $w){
        $sum = 0;
        for ($i = 1; $i <= $w; $i++){
            $sum += $k * $i;
        }
        $borrow = $sum - $n;
        if ($borrow >= 0){
            return $sum - $n . "\n";
        } else {
            return "0\n";
        }

    }
}

$obj = new SolierAndBananas();
fscanf(STDIN, "%d %d %d", $k, $n, $w);
echo $obj->index($k, $n, $w);


<?php
$i=1;
$hitung=0;
$a = explode(" ", trim(fgets(STDIN)));
while ($i <= $a[2]) {
	$hitung=$hitung+($i * $a[0]);
	$i++;
}
if($hitung > $a[1]){
	echo $hitung-$a[1];
}else{
	echo 0;
}

?>


<?php
$nr = explode(" ",trim(fgets(STDIN)));
$sum=0;

for($i=1;$i<=$nr[2];$i++){
  $sum += $nr[0] * $i;
}
if($sum > $nr[1])
  echo $sum - $nr[1];
else
  echo 0;


<?php
$input = explode(' ', readline());
$price = 0;
for($i = 1; $i <= $input[2]; $i++)
    $price += ($i * $input[0]);
echo $price > $input[1] ? $price - $input[1] : 0;


<?php

$input = readline();
$input_new = explode(' ', $input);
$price_banan = $input_new[0];
$have_many = $input_new[1];
$max_banan = $input_new[2];
$potracheno=0;

for ($i=0; $i<$max_banan; $i++) {
       $potracheno = $potracheno + $price_banan * ($i+1);
}      $need_many = $potracheno - $have_many;
     if ($need_many <=0) {
         echo '0';
     }
     else {
         echo $need_many;
     }


<?php
$a = trim(fgets(STDIN));
$b = range(1, $a);
$b = array_merge($b, $b);
$b = array_merge($b, $b);
$c = array();
$d = array();
$e = 0;
for($x = 1; $x <= 64; $x++)
{
    $c = array_merge($c, $b);
}
for($x = 0; $x < count($c); $x++)
{
    $e += $x;
    if($c[$e] == "")
    {
        break;
    }
    else
    {
        $d[$x] = $c[$e];
    }
}
$f = array_unique($d);
if(count($f) == $a)
{
    print "YES";
}
else
{
    print "NO";
}
?>


<?php
function findCanJump($nk,$nchar){
    $nk = explode(" ",$nk);
   // $nchar = explode('',$nchar);
    $n = $nk[0];
    $k = $nk[1];
    //echo $n;
    $len =$n;
    $pos_T = strpos($nchar,'T');
    $pos_G = strpos($nchar,'G');
    $canJump = 0;
    if($pos_G<$pos_T){
        while($pos_G<=$pos_T){

            if($pos_G==$pos_T){
                $canJump =1;
                echo 'YES';
                break;
            }
            $pos_G = $pos_G+$k;
            if(($pos_G>$pos_T && $canJump==0) ||($pos_G<$len && $nchar[$pos_G]=='#'))
              {
                  echo 'NO';break;
              }
        }

    }else{
        while($pos_G>=$pos_T){

            if($pos_G==$pos_T){
                $canJump =1;
                echo 'YES';
                break;
            }
            $pos_G = $pos_G-$k;
            if(($pos_G<$pos_T && $canJump==0) ||($pos_G>-1 && $nchar[$pos_G]=='#'))
              {
                  echo 'NO';break;
              }

        }
    }
}

$nk = trim(fgets(STDIN));
$nchar = trim(fgets(STDIN));

findCanJump($nk,$nchar);


<?php

$line1=fgets(STDIN);
$line2=fgets(STDIN);
$line3=fgets(STDIN);
$line4=fgets(STDIN);
$line5=fgets(STDIN);

$line1=explode(" ",$line1);
$line2=explode(" ",$line2);
$line3=explode(" ",$line3);
$line4=explode(" ",$line4);
$line5=explode(" ",$line5);

$i=0;

while($i<5)
{
if($line1[$i]==1)
{
$flag1=1;
$flag2=$i;
}
$i++;
}

$i=0;
while($i<5)
{
if($line2[$i]==1)
{
$flag1=2;
$flag2=$i;
}
$i++;
}

$i=0;
while($i<5)
{
if($line3[$i]==1)
{
$flag1=3;
$flag2=$i;
}
$i++;
}

$i=0;
while($i<5)
{
if($line4[$i]==1)
{
$flag1=4;
$flag2=$i;
}
$i++;
}

$i=0;
while($i<5)
{
if($line5[$i]==1)
{
$flag1=5;
$flag2=$i;
}
$i++;
}
$flag2++;

$result=(abs(3-$flag1)+abs(3-$flag2));

fputs(STDOUT, $result);
?>


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

    while(($char = fgetc($f)) !== FALSE) {
        if (is_numeric($char)) {
            $cnt++;
        }
        if ($char == 1) break;

    }
    $row = ceil($cnt / 5);
    $cell = ceil($cnt % 5);
    $cell = $cell ? $cell : 5;
    echo abs(3- $row) + abs(3 - $cell);
?>


<?php
for($y_num = 0; $y_num < 5; $y_num++) {
	$x_array = explode(" ", fgets(STDIN));
	$x_num = array_search(1, $x_array);
	if(strlen($x_num) > 0) {
		$result = abs(2-$y_num) + abs(2-$x_num);
		echo $result;
	}
}


<?php
	$matrix = array();
	array_push($matrix,explode(' ',fgets(STDIN)));
	array_push($matrix,explode(' ',fgets(STDIN)));
	array_push($matrix,explode(' ',fgets(STDIN)));
	array_push($matrix,explode(' ',fgets(STDIN)));
	array_push($matrix,explode(' ',fgets(STDIN)));
	for ($x = 0; $x < 5; $x++) {
		for ($y = 0; $y < 5; $y++) {
			if ($matrix[$x][$y] == 1) {
				echo abs(2 - $x) + abs(2 - $y);
				break;
			}
		}
		if ($matrix[$x][$y] == 1) {
			break;
		}
	}


<?php

fscanf(STDIN, "%s\n", $word);

if (preg_match("/^[A-Z]+$/", $word)) {
    $word = strtolower($word);
}
else {
    $firstLetter = substr($word, 0, 1);
    $restLetters = substr($word, 1);

    if (preg_match("/^[a-z]$/", $firstLetter) && (preg_match("/^[A-Z]+$/", $restLetters) || $restLetters == "")){
        $newFirst = strtoupper($firstLetter);
        $newRest = strtolower($restLetters);
        $word = $newFirst . $newRest;
    }
}

echo $word;

?>


<?php
$line = trim(fgets(STDIN));
if (preg_match("/^([A-Z]+)$/",$line))
{
    echo strtolower($line);
}
elseif (preg_match("/^([a-z]{1})([A-Z]*)$/",$line))
{
    echo strtoupper($line[0]).strtolower(substr($line,1));
}
else
{
    echo $line;
}


<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function foo($s)
{
    // @cases: h / hELLO
    if ($s[0] === strtolower($s[0])) {
        $ss = substr($s, 1);

        if (
            // @case: h
            $ss === false ||
            // @case: hELLO
            $ss === strtoupper($ss)
        ) {
            return ucfirst(strtolower($s));
        }
    }

    // @case: HTTP
    if ($s === strtoupper($s)) {
        return strtolower($s);
    }

    // other cases
    return $s;
}

$r = 0;

list($s) = fscanf($input, "%s");

$r = foo(trim($s));

fwrite($output, $r);


<?php

$string = fgets(STDIN);

if ($string == strtoupper($string)){
	printf(strtolower($string));
}
else if(substr($string,1,strlen($string)) == strtoupper(substr($string,1,strlen($string))) ){
printf(ucfirst(strtolower($string)));}
else {
	print($string);
}

?>


<?php
$input = trim(fgets(STDIN));
if(preg_match('/^([A-Z]+)$/', $input)){
    echo strtolower($input);
}
else if (preg_match('/^([a-z]{1})([A-Z]*)$/', $input)) {
    echo strtoupper($input[0]).strtolower(substr($input, 1));
}
else {
    echo $input;
}


<?php
	$in = trim(fgets(STDIN));
	$var = str_split($in);
	$n = 0; $m = strlen($in);
	foreach ($var as $v) {
		if ($v >= 'A' && $v <= 'Z') $n++;
	}
	if ($var[0] >= 'a' && $var[0] <= 'z') {
		if (/*$n == 1 ||*/$n == $m - 1) {
			echo ucwords(strtolower($in));
		} else {
			echo $in;
		}
	} else if ($n == $m) {
		echo strtolower($in);
	} else {
		echo $in;
	}


<?php

function Capslock($input){
    $output =   "";
    $string_length = strlen($input);
    $string_except_first_letter =   substr($input, 1, $string_length);

    if($string_length==1){
        if(ctype_lower($input)){
            $output = strtoupper($input);
        }
        else {
            $output = strtolower($input);
        }

    }
    elseif (ctype_upper($input)){
        $output = strtolower($input);
    }
    else{
        if( ctype_upper($string_except_first_letter)){
                $output     = strtoupper($input[0]).strtolower($string_except_first_letter);
        }
        else {
            $output =   $input;
        }
    }

    return $output;
}

$line = trim(fgets(STDIN));
echo Capslock($line)."\n";


<?php
	$text = trim(fgets(STDIN));
	$sub = substr($text,1,strlen($text)-1);

	if (ctype_upper($text))
		$text = strtolower($text);
	elseif (ctype_lower($text[0]) && strcmp(strtoupper($sub),$sub)==0)
		$text = strtoupper($text[0]).strtolower($sub);
	fwrite(STDOUT,$text);


<?php

list($n, $m, $k) = explode(" ", trim(fgets(STDIN)));
$prices = explode(" ", trim(fgets(STDIN)));
$min = $n*10;

array_walk($prices, function ($value, $key) use ($k, $m, &$min){
    if ($value > 0 && $value <= $k && abs($key - $m + 1)*10 < $min) {
        $min = abs($key - $m + 1)*10;
    }
}, ARRAY_FILTER_USE_BOTH);

echo $min;


<?php
// Retrieve input and show output
$stream = fopen("php://stdin", "r");
$input = stream_get_contents($stream);
$inputs = preg_split("/[\s]+/", $input);
echo func($inputs);

// Actual function for problem
function func($in) {
if (($in[0] < 2 * $in[2]) || ($in[1] < 2 * $in[2])) {return "Second";} else {return "First";}
}

// End of submission file
// Submission by chaotic_iak
?>


<?php
while($s = fgets(STDIN)){
        $input .= $s;
}
$input = explode("\r\n", $input);
$digits = explode (" ", $input[0]);
unset ($input);
$a=$digits[0];
$b=$digits[1];
$r=$digits[2];
$s=min($a,$b);
if ($r*2>$s) {
echo "Second";
}
else echo "First";
?>


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

if(2 * $r > min($a, $b)) print 'Second'; else print 'First';
?>


<?php
	$input = trim(fgets(STDIN));
	if (preg_match('/^(1|14|144)+$/',$input)) echo "YES";
	else echo "NO";
	echo "\n";

?>


<?php

$line = trim(fgets(STDIN));
$digitLen = strlen($line);
if (0 == $digitLen || $line[0] != 1) {
	echo 'NO';
	return;
}

$count4 = 0;
for ($i = 0; $i < $digitLen; $i++) {
	if ($count4 > 2) {
		echo 'NO';
		return;
	}

	$c = $line[$i];
	if ($c == 1) {
		$count4 = 0;
		continue;
	}

	if ($c == 4) {
		$count4++;
		continue;
	}

	echo 'NO';
	return;
}

echo ($count4 > 2) ? 'NO' : 'YES';


<?php
	function check($x)
	{
		$n = strlen($x);
		for ($i = 0; $i < $n; ++$i)
		{
			if ($x[$i] == 1) continue;
			if ($x[$i] == 4)
			{
				if ($i > 0 && $x[$i - 1] == 1) continue;
				if ($i - 1 > 0 && $x[$i - 1] == 4 && $x[$i - 2] == 1) continue;
			}
			return false;
		}
		return true;
	}

	$input = trim(fgets(STDIN));
	if (check($input)) echo "YES";
	else echo "NO";
	echo "\n";

?>


<?php
$a=trim(fgets(STDIN));
if( preg_match('/^(1|14|144)+$/',$a) ) echo "YES"; else echo "NO";

?>


<?php
$a=trim(fgets(STDIN));
if(preg_match('/^(14|1|144)+$/',$a))echo "YES";
else echo "NO";
?>


<?php

error_reporting(-1);

$s = fopen("php://stdin", 'r');
$input = fgets($s);
$input = trim($input);

function valid($string) {
    $a = 1;
    $b = 14;
    $c = 144;
    if ($string == $a || $string == $b || $string == $c)
        return true;
}

$currentSequence = "";
$condition = true;
foreach (str_split($input) as $key => $value) {
    if ($value != "1" && $value != "4")
        $condition = false;

    if (empty($currentSequence) || valid($currentSequence)) {
        $currentSequence = $currentSequence . $value;
    } elseif (strlen($currentSequence) >= 1) {
        $currentSequence = $value;
    } else {
        $condition = false;
    }

    if (!valid($currentSequence)) {
        $currentSequence = $value;
        if (!valid($currentSequence)) {
            $condition = false;
        }
    }
}

echo $condition === true ? "YES\n" : "NO\n";


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$q = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
$b = $aArray[0];
unset($aArray[0]);
$result = 0;
rsort($aArray);
while ($b<=$aArray[0]) {
    $b++;
    $result++;
    $aArray[0]--;
    rsort($aArray);
}
echo $result;


<?php
$n = trim(fgets(STDIN));
$arr = explode(" ",trim(fgets(STDIN)));
$lum = $arr[0];
$arr = array_slice($arr,1);
rsort($arr);
$count=0;
while($lum<=$arr[0])
{
    $lum+=1;
    $arr[0]-=1;
    $count+=1;
    rsort($arr);
}
print $count;
?>


<?php
        $n = trim(fgets(STDIN));
        $a = explode(" ", trim(fgets(STDIN)));
        //print_r($a);
         $x = $a[0];
         $b = array_slice($a,1);
         rsort($b);
         $count = 0;
         while($x <= $b[0]){
             $b[0]--;
             $x++;
             $count++;
             rsort($b);
         }
         echo $count."\n";


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$q = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
$b = $aArray[0];
unset($aArray[0]);
$result = 0;
sort($aArray);
while ($b<=$aArray[$q-2]) {
    $b++;
    $result++;
    $aArray[$q-2]--;
    sort($aArray);
}
echo $result;


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = $b[0];
$d = array_slice($b, 1);
rsort($d);
$e = 0;
while(TRUE)
{
    if($c > $d[0])
    {
        break;
    }
    else
    {
        $c++;
        $d[0]--;
        $e++;
        rsort($d);
    }
}
print $e;
?>


        <?php
            //$file = fopen('C:\\Users\\mohamed adel\\Desktop\\input.txt', 'r');
            $file = STDIN;
            $n = trim(fgets($file));
            $arr = explode(" ", trim(fgets($file)));
            function max_($n, &$arr){
                $id = 0; $m = $arr[0];
                for($i = 1; $i<$n; $i++){
                    if($arr[$i] >= $m){
                         $m = $arr[$i];
                         $id = $i;
                    }
                }
                return $id;
            }

            $x = $arr[0];
            $id = max_($n, $arr);
            while($id != 0){
                $arr[$id]--;
                $arr[0]++;
                $id = max_($n, $arr);

            }
            print $arr[$id]-$x;
            //print_r($arr);
        ?>


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$q = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
$b = $aArray[0];
unset($aArray[0]);
$result = 0;
$aArray = array_count_values($aArray);
krsort($aArray);
$max = 0;

foreach ($aArray as $n => $q) {
    $max = $n;
    break;
}
while ($b - $max <=0) {
    $t = floor($max - $b) + 1;
    if ($t<=$aArray[$max]) {
        $result = $result + $t;
        break;
    } else {
        $b += $aArray[$max];
        $result += $aArray[$max];
        if (isset($aArray[$max-1])) {
            $aArray[$max - 1] += $aArray[$max];
            unset($aArray[$max]);
        } else {
            $aArray[$max - 1] = $aArray[$max];
        }
        $max--;
    }
}

echo $result;


<?php
        $n = trim(fgets(STDIN));
        $a = explode(" ", trim(fgets(STDIN)));
         $x = $a[0];
         $b = array_slice($a,1);
         rsort($b);
         $count = 0;
         while($x <= $b[0]){
             $b[0]--;
             $x++;
             $count++;
             rsort($b);
         }
         echo $count."\n";


<?php

$input = rtrim(fgets(STDIN));
$raw = explode(' ', $input);
$firstSocks = (int)$raw[0];
$secondSocks = (int)$raw[1];

echo min($firstSocks, $secondSocks) . ' ' . (int) (abs($firstSocks - $secondSocks) / 2) . PHP_EOL;


<?php
fscanf(STDIN, '%d %d', $a, $b);
print ($a<$b?$a:$b).' '.intval(abs($a-$b)/2);


<?php
fscanf(STDIN, "%d %d", $l, $r);
// $input = explode(' ', trim(fgets(STDIN)));
// $input = array_map('intval',  $input);

$max = max($l, $r);
$min = min($l, $r);
echo $min . ' ' . floor(($max-$min) / 2);


<?php
$p = explode(' ', readline());
$a = floor(abs($p[0]-$p[1])/2);
echo min($p).' '.$a;


<?php
list($a, $b) = explode(' ', readline());
echo min($a, $b) . " " . floor((max($a, $b)-min($a, $b))/2). "\n";


<?php
  $numbers = explode(' ', trim(fgets(STDIN)));
  echo min($numbers[0], $numbers[1]) . ' ' . abs(intval(($numbers[0] - $numbers[1])/2));
?>


<?php
$fi=@fopen('test.inp',"r");
list($a,$b)=explode(" ",trim(fgets(STDIN)));
$c=min($a,$b);$a-=$c;$b-=$c;
echo $c . " ";
$c=floor(($a+$b)/2);
echo $c;
?>


<?php

class InputReader {
	protected $_fh;

	public function __construct($fileHandler = STDIN)
	{
		$this->_fh = $fileHandler;
	}

	public function readInt()
	{
		$d = trim(fgets($this->_fh));

		return (int)$d;
	}

	public function readArrayOfInt($size, $indexFrom = 0)
	{
		$a = [];
		$ind = $indexFrom;
		foreach (explode(' ', fgets($this->_fh)) as $item) {
			$a[$ind++] = (int)$item;
		}

		return $a;
	}

	public function readArrayOfString($size, $indexFrom = 0)
	{
		$a = [];
		$ind = $indexFrom;
		foreach (explode(' ', fgets($this->_fh)) as $item) {
			$a[$ind++] = $item;
		}

		return $a;
	}
}

function ntimes($n, $func, $returnResults = false) {
	$a = [];
	for ($i=1; $i<=$n; $i++) {
		$result = $func();

		if ($returnResults) {
			$a[$i] = $result;
		}
	}

	return $a;
}

$ir = new InputReader();

$n = $ir->readInt();
$a = $ir->readArrayOfInt($n,1);
$a[0] = 0;
$a[$n+1] = 1001;

$max = 0;
$total = 0;
for ($i = 1; $i<=$n; $i++) {
	if (($a[$i+1] - $a[$i-1]) == 2) {
		$total++;
	}
	else {
		$max = max([$max, $total]);
		$total = 0;
	}
}

$max = max([$max, $total]);
echo $max;


 <?php

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

if($n==2){
	echo 3;
}elseif($n==1){
	echo 1;
}elseif($n==0){
	echo 0;
}else{
	echo $n*2+1+dem($n, $n-1);
}

function dem($n, $l){
	if($l<=2)
		return 0;
	return ($l+($n-$l)*($l-1))+dem($n,$l-1);
}


<?php
// 268B Кнопки
$in = fopen("php://stdin", 'r');

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

$out = 0;

for ($i=1; $i <= $n; $i++) {
    $out += $i + ($n - $i) * ($i - 1);
}
echo $out;

?>


 <?php

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

echo dem($n,1,0);

function dem($n, $l, $r){
	if($n==0)
		return 0;
	return ($n*$l-$r)+dem($n-1,$l+1,$r+1);
}


<?php

//  In the name of Allah, the most Gracious, the most Merciful

//  Copyright(c) 2009-2013, all rights reserved.
//  written by ZHUMAZHANOV ADLET.

fscanf(STDIN, "%d", $n);
$answer = 0;

for ($i = 1; $i <= $n; $i ++) {
	$answer += 1 + ($n - $i) * $i;
}

printf("%d", $answer);

?>


<?php

$inputLine = fgets(STDIN);

$input = explode(' ', $inputLine);

$n = (float) $input[0];

$k = (float) $input[1];

$pr = $n / 2.0;

$nParts = $k + 1;

$partSize = $pr / $nParts;

$dipF = $partSize;

$dip1 = ceil($dipF);

$gr1 = $dip1 * $k;

if ($gr1 + $dip1 <= $pr) {
    echo $dip1 . ' ' . $gr1 . ' ' . ($n - $dip1 - $gr1);
    exit;
}

$dip2 = floor($dipF);

$gr2 = $dip2 * $k;

echo $dip2 . ' ' . $gr2 . ' ' . ($n - $dip2 - $gr2);


<?php
    fscanf(STDIN, "%d", $a);
    echo ceil($a / 2) - 1;
    echo PHP_EOL;


<?php
  $a = trim(fgets(STDIN));
  $a--;
  print floor($a/2);
?>


<?php
$a = trim(fgets(STDIN));
$a--;
$b = floor($a / 2);
print $b;
?>


<?php
$a=fgets (STDIN);
$cnt=substr_count($a,"VK");
$a=str_replace("VK","T",$a);

$vcnt= substr_count($a,"VV");
$kcnt= substr_count($a,"KK");

if($vcnt>0 OR $kcnt>0) $cnt = $cnt+1;

echo $cnt

?>


<?php
$s = file_get_contents('php://stdin');

$sArr = str_split(trim($s));

$candidates = [];
$candidates[] = trim($s);

foreach ($sArr as $key => $char) {
	$newArr = $sArr;
	if ($char == "V") {
		$newChar = "K";
	} else {
		$newChar = "V";
	}
	$newArr[$key] = $newChar;
	$candidates[] = implode($newArr);
}

$candidateCount = [];
foreach($candidates as $candidate) {
	$candidateCount[] = substr_count($candidate, "VK");
}

echo max($candidateCount);


<?php

$stdin = fopen('php://stdin', 'r');
$v = trim(fgets($stdin));

    $counter = preg_match_all("/VK/", $v);
    $v = str_replace("VK", "I", $v);
    $end = false;
    for ($i = 0; $i < strlen($v) - 1; $i++) {
        if ($v[$i] == "V" && $v[$i + 1] == "V") {
            $counter++;
            $end = true;
            break;
        }
    }
    if (!$end) {
        for ($i = 0; $i < strlen($v) - 1; $i++) {
            if ($v[$i] == "K" && $v[$i + 1] == "K") {
                $counter++;
                break;
            }
        }
    }
    echo $counter;


<?php
$a=fgets (STDIN);
$c=substr_count($a,"VK");
$r=str_replace("VK","Y",$a);

$v= substr_count($r,"VV");
$k= substr_count($r,"KK");

if($v>0 OR $k>0) echo "".($c+1);
    else
    echo "".$c;
?>


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

    echo pow($n, 2) + pow($n-1, 2);

?>


<?php
$input=trim(fgets(STDIN));
$sum=0;
$array=range(1,1000,2);
for ($i=0;$i<$input;$i++) {
      $sum+=$array[$i];
}
$sum=$sum*2-$array[$input-1];
echo $sum;


<?php
$n = trim(fgets(STDIN));
echo $n ** 2 + ($n - 1) ** 2;


<?php
# 1180A
$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$quarter = 0;
$quarterLimit = $n - 1;
for ($i = 1; $i <= $quarterLimit; $i++) {
    $quarter += $i;
}
echo $quarter * 4 + 1;


<?php
	$data = file_get_contents('php://stdin');

	$input = explode(PHP_EOL, $data);

	$K = $input[0];

	$months = explode(' ', $input[1]);

	sort($months);
	$months = array_reverse($months);

	$result = 0;
	$resultHeight = 0;

	foreach ($months as $monthWeight) {
		if ($K <= $resultHeight)
			break;

		$resultHeight += $monthWeight;
		$result++;
	}

	if ($K > $resultHeight)
		$result = -1;

	echo $result;
?>


<?php

$k = trim(fgets(STDIN)); if($k==0) {print 0; exit(0);}
$a = explode(' ',trim(fgets(STDIN)));
if(array_sum($a)<$k) {print -1; exit(0);}
rsort($a);

for($i=0;$i<=11;$i++) {$s+=$a[$i]; if($s>=$k) break;}

print $i+1;
?>


<?php

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

$k = trim(fgets($f));
$a = explode(" ",trim(fgets($f)));

rsort($a);

$count = 0;

$x = 0;

while($k>0 && isset($a[$x])){
    $count++;
    $k-=$a[$x];
    $x++;
}

if ($k>0){
    $count = -1;
}

echo $count;


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

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

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

rsort($a);

$count = 0;
foreach ($a as $item) {
    if ($n <= 0) {
        break;
    }
    $n -= $item;
    $count++;
}
if ($n <= 0) {
    echo $count;
} else {
    echo '-1';
}


<?php

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

fscanf($handle, "%i %i", $d, $e);

$exs = [];
$req = [];
$open = [];

for ($i = 0; $i < $e; $i++) {

    list($o, $s, $r) = array_map('intval', explode(' ', trim(fgets($handle))));

    $exs[$s] = $i;
    $req[$s] = $r;
    $open[$s] = $o;
}

if (array_sum($req) > $d - $e) {
    echo -1;
    exit;
}

ksort($exs);

$schedule = [];

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

    if (isset($req[$i])) {

        if ($req[$i] != 0) {
            echo -1;
            exit;
        }

        $schedule[] = $e + 1;
    } else {

        $needBrake = true;

        foreach ($exs as $ex => $p) {

            if ($req[$ex] != 0 && $open[$ex] <= $i) {

                $needBrake = false;

                $req[$ex]--;
                $schedule[] = $p + 1;
                break;
            }
        }

        if ($needBrake) {
            $schedule[] = 0;
        }
    }
}

echo implode(' ', $schedule);


<?php
fscanf(STDIN,"%d",$sizeOfArr);
$arr=explode(' ',trim(fgets(STDIN)));
$targetArr=array();
$targetArr[0]=$arr[$sizeOfArr-1];
$k=1;
for ($i=$sizeOfArr-2; $i>=0 ; $i--)
 {
 	   $count=0;

	  for ($j=0; $j <count($targetArr) ; $j++)
	   {
		   	if($targetArr[$j]!=$arr[$i])
	   	    {
	   	    	$count++;

	   	    	if($count==count($targetArr))
	   	    	{

	   	    	  $targetArr[$k++]=$arr[$i];
	   	    	}
	   	    }
       }
 }
 echo count($targetArr)."\n";
for ($i=count($targetArr)-1; $i>=0 ; $i--)
{
	if($i==0)
		echo "$targetArr[$i]";

    else
    	echo $targetArr[$i].' ';
}


<?php

$handle = fopen("php://stdin", "r");
function removeDuplicates($array)
{
    $new = [];

    for ($i = count($array) - 1; $i >= 0; $i--) {
        if (!isset($new[$array[$i]])) {
            $new[$array[$i]] = 1;
        }
    }

    echo count($new), PHP_EOL, implode(' ', array_reverse(array_keys($new))), PHP_EOL;
}

fscanf($handle, "%i", $n);
$expenditure_temp = fgets($handle);
$expenditure = explode(" ", $expenditure_temp);
$expenditure = array_map('intval', $expenditure);
removeDuplicates($expenditure);


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_reverse($b);
$d = array_unique($c);
$e = array_reverse($d);
print count($e) . "\n";
print implode(" ", $e);
?>


<?php

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

$n1 = explode(" ",$input)[0];
$n2 = explode(" ",$input)[1];

$x1 = (int)$n1;
$x2 = (int)$n2;

$i = 0;

while($x1 <= $x2) {

    $x1 *= 3;
    $x2 *= 2;

    $i++;

}

echo $i;


<?php

$str = readline();

$arr = explode(' ', $str);

$counter = 0;

while($arr[0] <= $arr[1]) {
    $arr[0] = $arr[0]*3;
    $arr[1] = $arr[1]*2;
    $counter++;
}

echo $counter;


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

$counter = 0;
while ($a <= $b) {
    $a *= 3;
    $b *= 2;
    $counter++;
}
echo $counter;
?>


<?php
error_reporting(0);
$arr = explode(' ',readline());
$a=$arr[0];
$b=$arr[1];
while($a<=$b)
{
    $a*=3;
    $b*=2;
    $i++;
}
echo $i;
?>


<?php

list($a, $b) = explode(' ', trim(fgets(STDIN)));
$c=0;
while($a <= $b){ $a*=3; $b*=2; $c++; }
echo $c;


<?php
$a = explode(" ", trim(fgets(STDIN)));
$b = array_unique($a);
$c = count($a) - count($b);
print $c;
?>


<?php
$line = explode(" ",trim(fgets(STDIN)));
echo 4 - count(array_unique($line));


<?php
//228A: Is your horseshoe on the other hoof?
$colors = explode(" ", trim(fgets(STDIN)));
$nodoubles = array_unique($colors);
$howmanycolors = count($nodoubles);
echo 4 - $howmanycolors;
?>


<?php

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

// get inputs
$colors = explode(' ', trim(fgets(STDIN)));

// solution
$unique_colors = count(array_unique($colors));

echo 4 - $unique_colors . "\n";


<?php
$n = explode(" ", trim(fgets(STDIN)));
$has = array_unique($n);
print (4 - count($has));
?>


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

$s = trim(fgets($f));
$a = explode(" ",$s);
$b = array();
foreach($a as $x){
    $b[$x]=1;
}

echo(4 - count($b));


<?php
$horseshoes = fgets(STDIN);

$horseshoes = trim($horseshoes);
$horseshoes = explode(' ', $horseshoes);

if(count($horseshoes) == count(array_unique($horseshoes))){
	// если массив изначально содержит только уникальные значения
	echo 0;
} else {
	if (count(array_unique($horseshoes)) == 3) {
		echo 1;
	} elseif(count(array_unique($horseshoes)) == 2) {
		echo 2;
	} elseif (count(array_unique($horseshoes)) == 1) {
		echo 3;
	}
}


<?php
function check($arr, $elem) {
    for ($i = 0; $i < count($arr); $i++) {
        if (intVal($arr[$i]) == intVal($elem)) return true;
    }
    return false;
}

$in = fgets(STDIN);
$in = explode(' ', $in);
$arr = array();
$count = 0;
for ($i = 0; $i < 4; $i++) {
    if (!check($arr, $in[$i])) $arr[] = $in[$i];
    else $count++;
}

echo $count;


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

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


<?php
$in = trim(fgets(STDIN));
//$in = 'httprruewrwer';

//��������
if(strpos($in,'http')===0){
	$w = 'http';
}else{
	$w = 'ftp';
}
$in = substr($in,strlen($w));
$w .= '://';

//�����
$r = strpos(substr($in,1),'ru');
if($r >= 0){
	$w .= substr($in,0,$r+1);
}
$w .= '.ru';
$in = substr($in,($r+3));

if($in<>''){
	$w .= '/'.$in;
}

echo $w;

?>


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

if(strpos($cin,'http')===0)
    $ans = 'http';
else
    $ans = 'ftp';
$idx = strlen($ans);

$cin = substr($cin,$idx);
$ans .= '://';

$ru = strpos(substr($cin,1),'ru');
if($ru >= 0){
    $ans .= substr($cin,0,$ru+1);
}
$ans .= '.ru';
$cin = substr($cin,($ru+3));

if($cin<>''){
    $ans .= '/'.$cin;
}

echo $ans;

?>


<?php
# 1143B
$start = microtime(true);
$arrayMultiply = function(array $arr){
    $res = 1;
    array_walk($arr, function($i) use (&$res){$res *= $i;});
    return $res;
};

$n = trim(fgets(STDIN));
$nLength = strlen($n);
if ($nLength === 1) {
    die($n);
}
if (substr($n, 1, $nLength - 1) === str_repeat('9', $nLength - 1)) {
    die((string)$arrayMultiply(str_split($n)));
}
$n = str_split($n);
$max = $arrayMultiply($n);
for ($i = 0; $i < $nLength - 1; $i++) {
    $arr = $n;
    $arr[$i] = ((int)$arr[$i]) - 1;
    for ($j = $i + 1; $j < $nLength; $j++) {
        $arr[$j] = 9;
    }
    $arr = array_reverse($arr);
    for ($j = 0; $j < $nLength - 1; $j++) {
        if ($arr[$j] === 0) {
            $arr[$j] = 9;
            $arr[$j + 1]--;
        }
        if ($arr[$j] === -1) {
            $arr[$j] = 9;
            $arr[$j + 1]--;
        }
    }
    if ($arr[$nLength-1] === 0) {
        unset($arr[$nLength-1]);
    }
    $arr = array_reverse($arr);
    $max = max($max, $arrayMultiply($arr));
}

echo $max;


<?php
function tri($i,$j,$k){
 return $i+$j>$k && $i+$k>$j && $j+$k>$i;
}

function seg($i,$j,$k){
 return $i+$j==$k || $i+$k==$j || $j+$k==$i;
}

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

if(tri($a,$b,$c) or tri($a,$b,$d) or tri($a,$c,$d) or tri($b,$c,$d)){
 print 'TRIANGLE';
 exit(0);
}

if(seg($a,$b,$c) or seg($a,$b,$d) or seg($a,$c,$d) or seg($b,$c,$d)){
 print 'SEGMENT';
 exit(0);
}

print 'IMPOSSIBLE';
?>


<?php

    $stdin = fopen('php://stdin', 'r');
    $string = trim(fgets($stdin));
    $arr = explode(" ", $string);
    sort($arr);
    $triang = is_triangle($arr[0], $arr[1], $arr[2]) || is_triangle($arr[1], $arr[2], $arr[3]);
    $segment = is_segment($arr[0], $arr[1], $arr[2]) || is_segment($arr[1], $arr[2], $arr[3]);
    if ($triang) {
        echo 'TRIANGLE';
    } elseif ($segment) {
        echo 'SEGMENT';
    } else {
        echo 'IMPOSSIBLE';
    }

function is_triangle($a, $b, $c) {
    return $a + $b > $c;
}

function is_segment($a, $b, $c) {
    return $a + $b == $c;
}


<?php
	define('TRI', 3);
	define('SEG', 2);
	define('IMP', 1);
	$fr = fopen("php://stdin","r");
	$input = fgets($fr);
	$t = array(0, 0, 0, 0);
	sscanf($input, '%d %d %d %d', $t[0], $t[1], $t[2], $t[3]);
	fclose ($fr);
	$sol = 0;
	for ( $i = 0; $i < 4; $i+= 1 )
	{
		$tri = array();
		for ( $j = 0; $j < 4; $j+= 1 )
		{
			if ( $i != $j )
				$tri[] = $t[$j];
		}
		sort($tri, SORT_NUMERIC);
		if ( ($tri[0] + $tri[1]) > $tri[2] )
		{
			die('TRIANGLE');
			$sol = max($sol, TRI);
		}
		elseif ( ($tri[0] + $tri[1]) == $tri[2] )
			$sol = max($sol, SEG);
		else
			$sol = max($sol, IMP);
	}
	switch ($sol)
	{
		case TRI:
			echo 'TRIANGLE';
			break;
		case SEG:
			echo 'SEGMENT';
			break;
		default:
			echo 'IMPOSSIBLE';
			break;
	}
?>


<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	//$d = explode(" ",rtrim(fgets($handle)));

	$d = explode(" ",rtrim(fgets(STDIN)));
	$len = count($d);

	$tri = false;
	$seg = false;
	for ($i = 0; $i < $len - 2; $i++)
	{
		for ($j = $i + 1; $j < $len - 1; $j++)
		{
			for ($k = $j + 1; $k < $len; $k++)
			{

				if (abs($d[$j] - $d[$k]) < $d[$i] && $d[$j] + $d[$k] > $d[$i])
				{

					$tri = true;
					break;

				} else if ($d[$j] + $d[$k] == $d[$i] || $d[$j] + $d[$i] == $d[$k] || $d[$i] + $d[$k] == $d[$j])
				{
					$seg = true;
				}
			}
		}
	}

	if ($tri) print("TRIANGLE");
	else if ($seg) print("SEGMENT");
	else print("IMPOSSIBLE");
}

?>


<?php

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

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

    if ($die) {
        die();
    }

    echo '</pre>';
}

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

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

/****************************************************** Solving block *****************************************************/
$sticks = explode(' ', g());
sort($sticks);
list($a, $b, $c, $d) = $sticks;

function triangle($a, $b, $c) {
    return $a + $b > $c;
}

function segment ($a, $b, $c) {
    return $a + $b == $c;
}

$triangle = triangle($a, $b, $c) || triangle($b, $c, $d);
$segment = segment($a, $b, $c) || segment($b, $c, $d);

if($triangle) {
    echo 'TRIANGLE';
} else if($segment) {
    echo 'SEGMENT';
} else {
    echo 'IMPOSSIBLE';
}

?>


<?php
$months = array(1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June", 7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December");
fscanf(STDIN, "%s", $name);
fscanf(STDIN, "%d", $plus);
$current = array_search($name, $months);
$current += $plus;
while($current>12) $current -= 12;
echo $months[$current];
?>


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = array(" ", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
unset($c[0]);
$d = array_search($a, $c);
$b += $d;
$e = $b % 12;
if($e == 0)
{
    $e = 12;
}
print $c[$e];
?>


<?php
function cin()
{
	$row = explode(" ", trim(fgets(STDIN)));
	return $row[0];
}
$row1 = cin();
$row2 = cin();
$total = strlen($row2);
for($a = 0, $b = 0; $b < $total; ++$b)
{
	if($row1[$a] == $row2[$b]) $a++;
}
$a++;
echo $a."\n";
?>


<?php

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

// get inputs
$stons       = trim(fgets(STDIN));
$instructions = trim(fgets(STDIN));

// solution
$position = 0;

for ($i=0; $i < strlen($instructions); $i++) {
    if($stons[$position] == $instructions[$i]) {
        $position++;
    }
}

echo $position + 1 . "\n";


<?php

//ზოგი აფთარსა დააბამს, კაცი მისაგან კლულია.

//                               მედა რუსთაველი

$first = trim(fgets(STDIN));
$second = trim(fgets(STDIN));

$vezirmaMomakhsena = 0;

for($i= 0; $i < strlen($second);$i++)
    if($first[$vezirmaMomakhsena]==$second[$i])
        $vezirmaMomakhsena++;

echo ++$vezirmaMomakhsena;

?>


<?php
$a = str_split(trim(fgets(STDIN)));
array_unshift($a, " ");
unset($a[0]);
$b = str_split(trim(fgets(STDIN)));
array_unshift($b, " ");
unset($b[0]);
$c = 1;
for($x = 1; $x <= count($b); $x++)
{
    if($a[$c] == $b[$x])
    {
        $c++;
    }
}
print $c;
?>


<?php
error_reporting(0);
$lines = explode("\n", file_get_contents("php://stdin"));

$lines[0] = explode(" ", $lines[0]);

$horiz = str_split(trim($lines[1]));
$vert = str_split(trim($lines[2]));

if($horiz[0]=="<" && $vert[0]=="^") {
    echo "NO";exit();
}
if($horiz[count($horiz)-1]==">" && $vert[count($vert)-1]=="v") {
    echo "NO";exit();
}

if($horiz[0]==">" && $vert[count($vert)-1]=="^") {
    echo "NO";exit();
}
if($horiz[count($horiz)-1]=="<" && $vert[0]=="v") {
    echo "NO";exit();
}

echo "YES";
?>


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($m, $n) = explode(" ", trim(fgets($file)));
$x = trim(fgets($file));
$y = trim(fgets($file));

$t = $x[0] . $y[0] . $x[$m - 1] . $y[$n - 1];
if ($t == '<v>^' || $t == '>^<v') {
    echo "YES";
}else{
    echo "NO";
}


<?php
$n = trim(fgets(STDIN));
if ($n == 1 or $n == 2) {
    print "1";
} else {
    $mod = $n % 3;
    if ($mod) {
        $res = floor($n / 3) * 2 + 1;
    } else {
        $res = ($n / 3) * 2;
    }
    print $res;
}
?>


<?php

fscanf(STDIN, "%d\n", $number); // reads number from STDIN

$count = (($number - $number % 3) / 3) * 2 + (($number % 3) ? 1 : 0);

echo "$count\n";


<?php
fscanf(STDIN, "%d %d", $n, $m);
if($n >= $m){
    $result = $n - $m;
}else{
    $result = 0;
    while($m != $n){
        if($m % 2 == 1 || $m < $n){
            $m++;
        }else{
            $m = $m/2;
        }
        $result++;
    }
}
echo $result;


<?php
ini_set("xdebug.max_nesting_level", 100000);
$a = explode(" ", fgets(STDIN));
$from = trim($a[0]);
$to = trim($a[1]);
$s = array();
function calc($p, $v) {
	if ($p < 0 || $p > 10000) return;
	global $s;
	if (isset($s[$p]) && $s[$p] <= $v) return;
	$s[$p] = $v;
	calc($p - 1, $v + 1);
	calc($p * 2, $v + 1);
}
calc($from, 0);
echo $s[$to];


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$n = trim(fgets($file));
$result = 0;
while ($n >= 2) {
    $r = $n % 2;
    if ($r == 1) {
        $result++;
    }
    $n -= $r;
    $n /= 2;
}
$result++;
echo $result;


<?php

$str = trim(fgets(STDIN));
$max= 0;
$current = 1;

for($i=0;$i<strlen($str);$i++){
    if($str[$i]==='A'||$str[$i]==='E'||$str[$i]==='O'||$str[$i]==='I'||$str[$i]==='U'||$str[$i]==='Y'){
        if($current > $max){
            $max= $current;
        }
        $current=1;
    }
    else{
        $current++;
    }
}

if($current > $max){
    $max = $current;
}
echo $max;


<?php

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

$s = [];
$i = 0;
$j = 1;

while($i < $n) {
    $s[] = $t[$i];
    $i += $j;
    $j++;
}

echo implode($s);

?>


<?php
$length=(int)fgets(STDIN) + 1;
$strin=fgets(STDIN);
$strout = '';
$i = 1;

while ($length > 0) {
    $strout .= substr($strin, 0, 1);
    $strin = substr($strin, $i, $length - $i);
    $length -= $i;
    $i++;
}

echo $strout;


<?php
$n=fgets(STDIN);
$input=str_split(fgets(STDIN));
$res=null;
$b=0;
for ($i=0;$i<$n; $i+=$b) {
      $b++;
      $res.=$input[$i];
}
echo $res;


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

   $hello = "hello";
   $n = 0;

   for($i = 0; $i < strlen($str); $i++)
      if($str[$i] == $hello[$n]) $n++;

   if ($n == 5) echo("YES");
   else echo("NO");
?>


<?php
error_reporting(-1);

if (preg_match('/h.*e.*l.*l.*o/', file_get_contents('php://stdin')))
	echo 'YES', PHP_EOL;
else
	echo 'NO', PHP_EOL;


<?php
$str=trim(fgets(STDIN));
function hellow($str){
    preg_match("/h.*?e.*?l.*?l.*?o/",$str,$m);
    if(!empty($m)) return "YES";
    return "NO";
}
echo hellow($str);
?>


<?php echo preg_match('/h.*e.*l.*l.*o/si', fgets(STDIN)) ? 'YES' : 'NO';


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

print preg_match('/h.*e.*l.*l.*o/',$s,$o)?'YES':'NO';
?>


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

    $h = strpos($str, 'h');
    $e = strpos($str, 'e', $h+1);
    $l = strpos($str, 'l', $e+1);
    $l2 = strpos($str, 'l', $l+1);
    $o = strpos($str, 'o', $l2+1);

    if($h < $e && $e < $l && $l < $l2 && $l2 < $o) echo "YES";
    else echo "NO";

?>


<?php

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

function func ($input) {

    //"hello" Word.
    $word = "hello";

    //Current Index.
    $current_index = 0;

    //Loop Inside The Given String.
    for($i = 0;$i < strlen($input);$i++) {

        if($word[$current_index] == $input[$i]) {

            $current_index++;

        }

    }

    if($current_index >= strlen($word)) {

        return "YES";

    }else {

        return "NO";

    }

}

echo func($input);

?>


<?php
    $input = trim(fgets(STDIN));
    //$arr = explode(' ', $input);

    if (strlen($input) < 5) {
        echo 'NO';exit;
    }

    $a = ['h','e','l','l','o'];
    $b = str_split($input);

    foreach ($b as $v) {
        if ($v == current($a)) {
            array_shift($a);
            if (count($a) === 0) {
                echo 'YES';exit;
            }
        }
    }

    echo 'NO';exit;


<?php
$bases1 = explode(" ",trim(fgets(STDIN)));
$digits1 = explode(" ",trim(fgets(STDIN)));
$bases2 = explode(" ",trim(fgets(STDIN)));
$digits2 = explode(" ",trim(fgets(STDIN)));

$val1 = 0;
$c1 = count($digits1);
$base1 = intval($bases1[1]);
for($i=0;$i<$c1; $i++){
    $val1 += intval($digits1[$c1-$i-1]) * pow($base1,$i);
}

$val2 = 0;
$c2 = count($digits2);
$base2 = intval($bases2[1]);
for($i=0;$i<$c2; $i++){
    $val2 += intval($digits2[$c2-$i-1]) * pow($base2,$i);
}

$res = "";
if($val1 == $val2){
    $res =  "=";
}else if($val1 > $val2){
    $res =  ">";
}else{
    $res = "<";
}

fwrite(STDOUT, $res);


<?php
function f() {
    list($n, $base) = explode(' ', fgets(STDIN));

    $number = 0;
    $pow = 1;
    foreach (array_reverse(explode(' ', fgets(STDIN))) as $in) {
        $number += $pow*$in;
        $pow *= $base;
    }
    return $number;
}

$number1 = f();
$number2 = f();

if ($number1 == $number2) {
    $sign = '=';
} else if ($number1 > $number2) {
    $sign = '>';
} else {
    $sign = '<';
}
echo $sign;
//echo "$number1$sign$number2";
?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = array_reverse(explode(" ", trim(fgets(STDIN))));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = array_reverse(explode(" ", trim(fgets(STDIN))));
$g = 0;
for($x = 0; $x < $a; $x++)
{
     $g += $c[$x] * pow($b, $x);
}
$h = 0;
for($x = 0; $x < $d; $x++)
{
     $h += $f[$x] * pow($e, $x);
}
if($g < $h)
{
     print "<";
}
elseif($g == $h)
{
     print "=";
}
elseif($g > $h)
{
     print ">";
}
?>


<?php

function pw3up($d)
{
	$cnt = 0;
	while($d > 0)
	{
		$d = intdiv($d, 3);
		$cnt++;
	}
	return $cnt;
}

function pw3bet($l, $r)
{
	return (pw3up($r) - pw3up($l - 1));
}

function f($l, $r)
{
	if($r < $l)
		return 0;
	if($l == $r && $l % 2 == 1)
		return pw3bet($l, $r);
	return (pw3bet($l, $r) + f(intdiv(($l + 1),2), intdiv($r,2)));
}

$fl = STDIN;
list($l, $r) = explode(" ", fgets(STDIN));
$l = (int) $l;
$r = (int) $r;

printf("%d\n", f($l, $r))

?>


<?php
$temp = fopen("php://stdin","r");
$line = fgets($temp);
$y=strval($line);
$y=strrev($y);
$y=intval($y);
if($line==$y)
	echo "YES";
else{
	for($i=10;$i<=1e9;$i*=10){
		if($line/$y==$i){
			echo "YES";
			return 0;
		}
	}
	echo "NO";
}

?>


<?php

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

list($n,$m,$a,$b) = explode(" ",trim(fgets($f)));

if (($a*$m)<=$b){
    echo $a*$n;
    exit;
}

$sum = floor($n/$m)*$b;
$x = $n%$m;

if ($x*$a <= $b ){
    $sum+=($x*$a);
} else $sum+=$b;

echo $sum;