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

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

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

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

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

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

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

fclose(STDIN);

?>

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

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

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

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

print($result);

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

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

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

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

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


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

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

sort($arr);

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

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

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

?>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

sort($arr);

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

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

?>


<?php
$line = fgets(STDIN);
echo (preg_match('/^.*h.*e.*l.*l.*o.*$/i', $line)) ? 'YES' : 'NO';
?>

<?php
error_reporting(0);
fscanf(STDIN, "%s", $type);
$base = "hello";
$count = 0;
$a = 0;
for ($i = 0; $i < strlen($type); $i++) {
    if ($type[$i] == $base[$a]) {
        $a++;
        $count++;
    }
}
if ($count == 5) {
    echo "YES\n";
} else {
    echo "NO\n";
}

<?php
fscanf(STDIN,'%s', $s);
$a = 'hello';
$count = 0;
for ($i=0;$i<strlen($s);$i++){
    if ($s[$i] == $a[$count]){
        $count++;
        if($count == 5)
            break;
    }
}
if ($count == 5)
    echo 'YES';
else
    echo 'NO';
?>

<?
$s=trim(fgets(STDIN));
$h= stripos($s,"h");
$e= stripos(substr($s,$h),"e");
$l= stripos(substr($s,$h+$e),"l");
$l2= stripos(substr($s,$h+$e+$l+1),"l");
$o= stripos(substr($s,$h+$e+$l+$l2+1),"o");
If($h === false or $e === false or $l === false or $l2 === false or $o === false)echo "NO";
else echo "YES";
?>

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

print preg_match('/h.*e.*l.*l.*o/',$s,$o)?'YES':'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
while(fscanf(STDIN,"%s",$str)){
    $len = strlen($str);
    $key = "hello";
    $k = 0;
    $a = 0;
    for($i = 0; $i < $len; ++$i){
        if($str[$i] == $key[$k])
            ++$k;
        if($k == 5){
            echo "YES\n";
            break;
        }
    }
    if($k != 5)
      echo "NO\n";
}

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

fscanf($cin, "%s", $str);

$hello = "hello";
$idx = 0; $i = 0;

while($idx < strlen($hello) && $i < strlen($str)){
    if($hello[$idx] == $str[$i]) $idx++;
    $i++;
}

echo ($idx >= strlen($hello) ? "YES" : "NO");

?>

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

$lines=trim($lines);

$tpl="hello";

$ok=true;
$i=-1;
$n=0;
while (++$i<strlen($lines))
{
    $char=$lines{$i};
    if ($char==$tpl{$n})
        $n++;
    if ($n==strlen($tpl))
    {
        echo 'YES';
        die;
        break;
    }
}

echo 'NO';
?>

<?php
$hello = trim(fgets(STDIN));
echo preg_match("/.*h.*e.*l.*l.*o.*/",$hello) ? "YES": "NO";
?>

<?
	define("_", PHP_EOL);
	$MAX_N = PHP_INT_MAX;
	$L = trim(fgets(STDIN));
	echo preg_match("/.*h.*e.*l.*l.*o.*/", $L) ? "YES" : "NO";
?>

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

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

<?php

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

$search = 'hello';
$searchArray = str_split($search);

$inputArray = str_split($input);
$dump = array();
foreach($inputArray as $item)
{
    if($item == $searchArray[count($dump)])
        array_push($dump, $item);
}

$diff1 = count(array_diff($dump, $searchArray));
$diff2 = count(array_diff($searchArray, $dump));

if($diff1 == 0 AND $diff2 == 0)
    echo 'YES';
else
    echo 'NO';

<?php
	$input_line = trim(fgets(STDIN));
	echo preg_match('/h.*e.*l.*l.*o/', $input_line)?"YES":"NO";
?>

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

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)
{
    $h = $e = $l1 = $l2 = $o = false;

    for ($i = 0; $i < strlen($s); $i++) {
        if ($s[$i] === 'h' && !$h) {
            $h = true;
            continue;
        }

        if ($s[$i] === 'e' && !$e && $h) {
            $e = true;
            continue;
        }

        if ($s[$i] === 'l' && !$l1 && $h && $e) {
            $l1 = true;
            continue;
        }

        if ($s[$i] === 'l' && !$l2 && $h && $e && $l1) {
            $l2 = true;
            continue;
        }

        if ($s[$i] === 'o' && !$o && $h && $e && $l1 && $l2) {
            $o = true;
            continue;
        }
    }

//    dd($h, $e, $l1, $l2, $o);
    return $h && $e && $l1 && $l2 && $o;
}

$r = 0;

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

$r = foo($s) ? 'YES' : 'NO';

fwrite($output, $r);

<?php
$line = fgets(STDIN);
echo preg_match("/.*h.*e.*l.*l.*o.*/",$line)?"YES":"NO";
?>

<?
$word = fopen("php://stdin", 'r');
$str = fread($word, 100);
$pattern = "/.*h.*e.*l.*l.*o/";

if (preg_match($pattern, $str) > 0){
        echo "YES";
} else {
        echo "NO";
}
?>

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

<?php
$a=trim(fgets(STDIN));
$b="hello";
$j=0;
for($i=0;$i<strlen($a);++$i)
    if ($a[$i]==$b[$j])
    {
        $j++;
        if ($j==5)
            break;
    }
if ($j==5)
    printf("YES\n");
else
    printf("NO\n");
?>

<?php
$s = str_split(readline());
$test = ['h', 'e', 'l', 'l', 'o'];
$i= 0;
foreach($s as $letter){
    if($letter == $test[$i]){
        $i++;
        if($i == 5){
            break;
        }
    }
}

if($i == 5){
    echo "YES";
}else{
    echo "NO";
}

<?php
$line = str_split(strtolower(fgets(STDIN)),1);
$hello = array("h","e","l","l","o");
$j=0;
for ($i=0;$i<count($line);$i++)
{
    if ($line[$i]==$hello[$j])
    {
        $j++;
    }
    if ($j==5)break;
}
if ($j<5)echo "NO";
else echo "YES";

<?php

$str = fgets(STDIN);
$str_arr = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
$word = array('h','e','l','l','o');
$i = 0;
$j = 0;
$k = 0;
$ch = 0;
for ($i = 0; $i < count($word); $i++) {
    for ($j = $k; $j < count($str_arr); $j++) {
        if ($word[$i] == $str_arr[$j]) {
            $k = $j + 1;
            $ch = $ch + 1;
            break;
        } else {
            //
        }
    }
}
if ($ch == count($word)) {
    print("YES");
} else {
    print("NO");
}

<?php
$input=str_split(fgets(STDIN));
$count=count($input);
for ($i=0; $i <$count;$i++) {
      if($input[$i] == 'h'){
            for ($j=$i+1; $j<$count;$j++) {
                  if ($input[$j] == 'e') {
                        for ($t=$j+1; $t <$count;$t++) {
                              if ($input[$t] == 'l') {
                                    for ($d=$t+1; $d <$count ; $d++) {
                                          if ($input[$d] == 'l') {
                                                for ($f=$d+1; $f <$count; $f++) {
                                                      if ($input[$f] == 'o') {
                                                            echo "YES";
                                                            return false;
                                                      }
                                                }
                                          }
                                    }
                              }
                        }
                  }
            }
      }
}
echo "NO";
?>

<?php
	$var = str_split(fgets(STDIN));
	$flag = 0;
	$comp = array('h','e','l','l','o');
	foreach ($var as $v) {
		if ($v == $comp[$flag]) {
			$flag++;
		}
		if ($flag == 5) break;
	}
	if ($flag == 5) echo 'YES';
	else echo 'NO';

<?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
$str=trim(fgets(STDIN));
$word="hello";
$j=0;
for ($i=0; $i <strlen($str) ; $i++)
{
	if($str[$i]==$word[$j])
    {
		//echo "$str[$i] $word[$j]\n";
		$j++;
     if($j==5)
     	break;

	}
}
echo $j==5?"YES":"NO";

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

$s = trim(fgets($f));
preg_match("/.*h.*e.*l.*l.*o.*/",$s,$match);

if (count($match)>0) echo "YES";
else echo "NO";

<?php

fscanf(STDIN, "%s\n", $s);
$s = strtolower($s);
$chars = str_split($s, 1);

$got_h = 0;
$got_e = 0;
$got_l = 0;
$got_l2 = 0;
$got_o = 0;

$word_arr = array('h', 'e', 'l', 'l', 'o');
$parsed_str = "";

foreach ($chars as $char) {
   if (in_array($char, $word_arr)){
      $parsed_str .= $char;
   }
}
# get rid of repeating h
$parsed_str = preg_replace('/[h][h]*/', 'h', $parsed_str);
# get rid of repeating e
$parsed_str = preg_replace('/[e][e]*/', 'e', $parsed_str);
# get rid of repeating l (more than 2)
$parsed_str = preg_replace('/[l][l][l]*/', 'll', $parsed_str);
# get rid of repeating o
$parsed_str = preg_replace('/[o][o]*/', 'o', $parsed_str);

//echo $parsed_str . "\n";

if ($parsed_str == 'hello') {
   echo "YES";
}
else {
   $parsed_chars = str_split($parsed_str, 1);
   $pword_arr = array("h" => 0, "e" => 0, "l" => 0, "o" => 0);
   foreach ($parsed_chars as $pchar) {
      if ($pchar == 'h' && $got_h == 0) {
         //echo "found first h\n";
         $got_h = 1;
         $got_e = 0;
         $got_l = 0;
         $got_l2 = 0;
         $got_o = 0;
        continue;
      }

      if ($pchar == 'e' && $got_h && !$got_e) {
         //echo "found first e\n";
         $got_e = 1;
        continue;
      }

      if ($pchar == 'l' && $got_h && $got_e && !$got_l){
         //echo "found first l\n";
         $got_l = 1;
        continue;
      }

      if ($pchar == 'l' && $got_h && $got_e && $got_l && !$got_l2) {
         //echo "found second l\n";
         $got_l2 = 1;
        continue;
      }

      if ($pchar == 'o' && $got_h && $got_e && $got_l && $got_l2 && !$got_o) {
         //echo "found first o\n";
         $got_o = 1;
        continue;
      }
   }

   if ($got_h && $got_e && $got_l && $got_l2 && $got_o) {
      echo "YES";
   }
   else {
      echo "NO";
   }
}
?>

<?php
$text = file_get_contents("php://stdin");
echo preg_match("/h.*e.*l[^l]*l.*o/", $text)?"YES":"NO";

<?php
$str = fgets(STDIN);

if (preg_match('/h.*e.*l.*l.*o/', $str))
{
    echo 'YES';
}
else
{
    echo 'NO';
}

<?php
$s = trim(fgets(STDIN));
echo (preg_match("/h.*e.*l.*l.*o/", $s) ? "YES" : "NO");
?>

<?php
$a=trim(fgets(STDIN));
if( preg_match('/.*h.*e.*l.*l.*o.*/',$a) ) echo "YES"; else echo "NO";

?>

<?php
    echo preg_match('/h.*e.*l.*l.*o/', file_get_contents('php://stdin')) ? 'YES' : '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
$s = trim(fgets(STDIN));
echo (preg_match("/h.*e.*l.*l.*o/", $s) ? "YES" : "NO");

?>

<?php
// 58A Чат

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

$input_line = fgets($in);

if (preg_match("/.*h.*e.*l.*l.*o.*/i", $input_line)) {
//if (preg_match("/[.]*h[.]*e[.]*l[.]*l[.]*o[.]*/U", $input_line)) {
    echo "YES";
} else {
    echo "NO";
}

?>

<?php
// 58A Чат

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

$input_line = fgets($in);

if (preg_match("/.*?h.*?e.*?l.*?l.*?o.*?/i", $input_line)) {
//if (preg_match("/[.]*h[.]*e[.]*l[.]*l[.]*o[.]*/U", $input_line)) {
    echo "YES";
} else {
    echo "NO";
}

?>

<?php
while (fscanf(STDIN, "%s", $string)){
    $length = strlen($string);
    $s = 'hello';
    $s_i = 0;
    for ($i = 0; $i < $length; ++$i){
        if ($s[$s_i] == $string[$i]){
            if ($s[$s_i] == 'o'){
                echo "YES\n";
                $s_i = -1;
                break;
            }
            ++$s_i;
        }
    }

    if ($s_i != -1){
        echo "NO\n";
    }
}

<?php
error_reporting("off");
//58A: Chat room
//I guess I'm bruteforcing. haha.
$echoed = FALSE;
$input = trim(fgets(STDIN)); //$input = "o";
if (strpos($input, "h") === FALSE) {
    echo "NO";
    $echoed = TRUE;
}
$input = substr($input, strpos($input, "h"));
if (strpos($input, "e") === FALSE) {
    if ($echoed == FALSE) {
        echo "NO";
        $echoed = TRUE;
    }
}
$input = substr($input, strpos($input, "e"));
if (strpos($input, "l") === FALSE) {
    if ($echoed == FALSE) {
        echo "NO";
        $echoed = TRUE;
    }
}
$input = substr($input, strpos($input, "l") + 1); //doing it differently (not semantic (actually this whole program is not semantic)) by taking off that l too.
if (strpos($input, "l") === FALSE) {
    if ($echoed == FALSE) {
        echo "NO";
        $echoed = TRUE;
    }
}
$input = substr($input, strpos($input, "l"));
if (strpos($input, "o") === FALSE) {
    if ($echoed == FALSE) {
        echo "NO";
        $echoed = TRUE;
    }
}

if ($echoed === FALSE) {
    echo "YES";
}
?>

<?php
    $str = trim(fgets(STDIN));
    echo (preg_match("/[a-z]*h[a-z]*e[a-z]*l[a-z]*l[a-z]*o[a-z]*/", $str) ? "YES" : "NO");
?>

<?php

fscanf(STDIN, '%s\n', $s);
$line = str_split($s);
$counter = 0;

$wordToFind = 'hello';
$letterToFind = $wordToFind[0];

for($i = 0; $i < count($line); $i++) {
	if($line[$i] == $letterToFind) {
		$counter++;
		$letterToFind = $wordToFind[$counter];
	}
}

if ($counter == 5) {
	printf('YES');
} else {
	printf('NO');
}

<?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
while (fscanf(STDIN, "%s", $string)){
    $length = strlen($string);
    $s = 'hello';
    $s_i = 0;
    for ($i = 0; $i < $length; ++$i){
        if ($s[$s_i] == $string[$i]){
            if ($s[$s_i] == 'o'){
                echo "YES\n";
                break;
            }
            ++$s_i;
        }
    }
    if ($s_i != 4){
        echo "NO\n";
    }
}

<?php
error_reporting("off");
//58A: Chat room
//I guess I'm bruteforcing. haha.
$echoed = FALSE;
$input = trim(fgets(STDIN)); //$input = "hlelo";
if (strpos($input, "h") === FALSE) {
    echo "NO";
    $echoed = TRUE;
}
$input = substr($input, strpos($input, "h"));
if (strpos($input, "e") === FALSE) {
    echo "NO";
    $echoed = TRUE;
}
$input = substr($input, strpos($input, "e"));
if (strpos($input, "l") === FALSE) {
    echo "NO";
    $echoed = TRUE;
}
$input = substr($input, strpos($input, "l") + 1); //doing it differently (not semantic (actually this whole program is not semantic)) by taking off that l too.
if (strpos($input, "l") === FALSE) {
    echo "NO";
    $echoed = TRUE;
}
$input = substr($input, strpos($input, "l"));
if (strpos($input, "o") === FALSE) {
    echo "NO";
    $echoed = TRUE;
}

if ($echoed === FALSE) {
    echo "YES";
}
?>

<?php
error_reporting("off");
//58A: Chat room
//I guess I'm bruteforcing. haha.
$no = FALSE;

$input = trim(fgets(STDIN)); //$input = "hlelo";
if (strpos($input, "h") === FALSE) {
    $no == TRUE;
}
$input = substr($input, strpos($input, "h"));
if (strpos($input, "e") === FALSE) {
    $no == TRUE;
}
$input = substr($input, strpos($input, "e"));
if (strpos($input, "l") === FALSE) {
    $no == TRUE;
}
$input = substr($input, strpos($input, "l") + 1); //doing it differently (not semantic (actually this whole program is not semantic)) by taking off that l too.
if (strpos($input, "l") === FALSE) {
    $no == TRUE;
}
$input = substr($input, strpos($input, "l"));
if (strpos($input, "o") === FALSE) {
    $no == TRUE;
}

if ($no === TRUE) {
    echo "NO";
} else {
    echo "YES";
}
?>

<?php
	$input_line = trim(fgets(STDIN));
	echo preg_match('/h*e*l*l*o/', $input_line)?"YES":"NO";
?>

<?php
	$input_line = trim(fgets(STDIN));
	echo preg_match('/.h*.e*.l*.l*.o/', $input_line)?"YES":"NO";
?>

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

    $h = strpos($str, 'h');
    $e = strpos($str, 'e');
    $ll = strpos($str, 'll');
    $o = strpos($str, 'o');

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

?>

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

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

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

?>

<?php
$s = trim(fgets(STDIN));
while(1) {
    $s1 = preg_replace(array('/hh/','/ee/','/lll/','/oo/') , array('h','e','ll','o'), $s);
    if(strcmp($s, $s1)===0) {
        $s = $s1;
        unset($s1);
        break;
    }
    $s = $s1;
}
if(strlen(str_replace('hello', '', $s)) != strlen($s)) {
    echo('YES');
    exit(0);
}
else {
    echo('NO');
}

$word = fopen("php://stdin", 'r');
$pattern = "/.*h.*e.*l.*l.*o/";

if (preg_match($pattern, $word) > 0){
    echo "YES";
} else {
    echo "NO";
}

<?php
$line = fgets(STDIN);
echo (preg_match('/^.*h.*e.*l.*l.*o.*$/i')) ? 'YES' : 'NO';
?>

<?php
$str=trim(fgets(STDIN));
$hello="hello";
for($i=0;$i<strlen($hello);$i++)
{
	for($j=0;$j<strlen($str);$j++)
	{
		if($hello[$i]==$str[$j])
		{
			$count[$i]=$j;
			break;
		}

	}
}

$cnt=0;
for($i=0;$i<count($count)-1;$i++)
{
 if($count[$i]>$count[$i+1]){
 	echo "NO";
 	break;
 }
 else $cnt++;

}
if($cnt==4)
	echo "YES";

<?php
$str=trim(fgets(STDIN));
for($i=0;$i<strlen($str)-1;$i++)
{
	$str4[$i]=$str[$i].$str[$i+1];
}
//print_r($str4);

$str3="hello";
$accumulate="";
for($i=0;$i<strlen($str3)-1;$i++)
{
	$str5[$i]=$str3[$i].$str3[$i+1];
	$accumulate.=$str5[$i];
}
//echo "$accumulate\n";
//print_r($str5);

$str6="";
for($i=0;$i<count($str5);$i++)
{
	for($j=0;$j<count($str4);$j++)
	{
		if($str5[$i]==$str4[$j])
		{
          $str6.=$str4[$j];
          break;
		}
	}
}

if($accumulate==$str6)
	echo "YES";
else
	echo "NO";

<?php

fscanf(STDIN, "%s\n", $s);
$s = strtolower($s);
$chars = str_split($s, 1);

$got_h = 0;
$got_e = 0;
$got_l = 0;
$got_l2 = 0;
$got_o = 0;

$word_arr = array('h', 'e', 'l', 'l', 'o');
$parsed_str = "";

foreach ($chars as $char) {
   if (in_array($char, $word_arr)){
      $parsed_str .= $char;
   }
}
# get rid of repeating h
$parsed_str = preg_replace('/[h][h]*/', 'h', $parsed_str);
# get rid of repeating e
$parsed_str = preg_replace('/[e][e]*/', 'e', $parsed_str);
# get rid of repeating l (more than 2)
$parsed_str = preg_replace('/[l][l][l]*/', 'll', $parsed_str);
# get rid of repeating o
$parsed_str = preg_replace('/[o][o]*/', 'o', $parsed_str);

if ($parsed_str == 'hello') {
   echo "YES";
}
else {
   echo "NO";
}
?>

<?php

fscanf(STDIN, "%s\n", $s);
$s = strtolower($s);
$chars = str_split($s, 1);

$got_h = 0;
$got_e = 0;
$got_l = 0;
$got_l2 = 0;
$got_o = 0;

$word_arr = array('h', 'e', 'l', 'l', 'o');
$parsed_str = "";

foreach ($chars as $char) {
   if (in_array($char, $word_arr)){
      $parsed_str .= $char;
   }
}
# get rid of repeating h
$parsed_str = preg_replace('/[h][h]*/', 'h', $parsed_str);
# get rid of repeating e
$parsed_str = preg_replace('/[e][e]*/', 'e', $parsed_str);
# get rid of repeating l (more than 2)
$parsed_str = preg_replace('/[l][l][l]*/', 'll', $parsed_str);
# get rid of repeating o
$parsed_str = preg_replace('/[o][o]*/', 'o', $parsed_str);

//echo $parsed_str . "\n";

if ($parsed_str == 'hello') {
   echo "YES";
}
else {
   $parsed_chars = str_split($parsed_str, 1);
   $pword_arr = array("h" => 0, "e" => 0, "l" => 0, "o" => 0);
   foreach ($parsed_chars as $pchar) {
      if ($pchar == 'h' && $got_h == 0) {
         //echo "found first h\n";
         $got_h = 1;
         $got_e = 0;
         $got_l = 0;
         $got_l2 = 0;
         $got_o = 0;
      }

      if ($pchar == 'e' && $got_h && !$got_e) {
         //echo "found first e\n";
         $got_e = 1;
      }

      if ($pchar == 'l' && $got_h && $got_e && !$got_l){
         //echo "found first l\n";
         $got_l = 1;
      }

      if ($pchar == 'l' && $got_h && $got_e && $got_l && !$got_l2) {
         //echo "found second l\n";
         $got_l2 = 1;
      }

      if ($pchar == 'o' && $got_h && $got_e && $got_l && $got_l2 && !$got_o) {
         //echo "found first o\n";
         $got_o = 1;
      }
   }

   if ($got_h && $got_e && $got_l && $got_l2 && $got_o) {
      echo "YES";
   }
   else {
      echo "NO";
   }
}
?>

<?php
$text = file_get_contents("php://stdin");
preg_match("/h.*e.*l[^l]*l.*o/", $text);

<?php
$h = fopen("php://input");
echo fgets($h);

<?php
$stdin = file_get_contents('php://stdin');
echo preg_match('/h+.*e+.*(:?ll+)|(:?l+.*l+).*o+.*u+/', $stdin) ? "YES" : "NO";

<?php
$str = file_get_contents("php://input");
if(preg_match('/h+e+l+o+u+/', $str)) print("YES");
else print("NO");

<?php
$stdin = file_get_contents('php://stdin');
echo preg_match('/h+.*e+.*(:?(:?ll+)|(:?l+.*l+)).*o+.*u+/', $stdin) ? "YES" : "NO";

<?php
$stdin = file_get_contents('php://stdin');
echo preg_match('/h+e+l+l+o+u+/', $stdin) ? "YES" : "NO";

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

<?php
$n = trim(fgets(STDIN));
echo (preg_match("/h.*e.*l.*l.*o/", $s) ? "YES" : "NO");
?>

<?php
$input = explode("\n", trim(file_get_contents("php://stdin")));
echo preg_match('/h{1,}e{1,}l{2,}o{1,}/', $input[0]) ? 'YES' : 'NO';

<?php
$s = trim(fgets(STDIN));
echo preg_match("/h . *e . *l . *l. *o/", $s) ? "YES" : "NO";

?>

<?php
// 58A Чат

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

$input_line = fgets($in);

if (preg_match("/[.]*h[.]*e[.]*l[.]*l[.]*o[.]*/iU", $input_line)) {
    echo "YES";
} else {
    echo "NO";
}

?>

<?php
// 58A Чат

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

$input_line = fgets($in);

if (preg_match("/[.]*h[.]*e[.]*l[.]*l[.]*o[.]*/i", $input_line)) {
    echo "YES";
} else {
    echo "NO";
}

?>

<?php
// 58A Чат

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

$input_line = fgets($in);

if (preg_match("/[.]*h[.]*e[.]*l[.]*l[.]*o[.]*/", $input_line)) {
    echo "YES";
} else {
    echo "NO";
}

?>

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

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

$arr = array('h', 'e', 'l', 'o');
for ($i = 0; $i < strlen($s); $i++) {
    $flag = false;
    for ($j = 0; $j < count($arr); $j++) {
        if ($s[$i] == $arr[$j]) $flag = !$flag;
    }

    if (!$flag) {
        echo 'YES';
        return;
    }
}

echo 'NO';

<?php
error_reporting(0);
fscanf(STDIN, "%s", $str);
if (strlen($str) > 0) {
    $arr = str_split($str);
    $unique_arr = array_unique($arr);
    $unique_str = implode('', $unique_arr);
    if (preg_match('/helo/', $unique_str)) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

<?php
while(fscanf(STDIN,"%s",$str)){
    $len = strlen($str);
    $key = "hello ";
    $k = 0;
    $a = 0;
    for($i = 0; $i < $len; ++$i){
        if(!$a && $str[$i] == $key[$k]){
                $a = 1;
            }
        elseif($a && $str[$i] == $key[$k+1]){
            ++$k;
            }
        elseif($a && $str[$i] != $key[$k])
            break;
    }
    if($k == 4)
        echo "YES\n";
    else
        echo "NO\n";

}

<?php
while (fscanf(STDIN, "%s", $string)){
    $length = strlen($string);
    $s = 'hello';
    $s_i = 0;
    for ($i = 0; $i < $length; ++$i){
        if ($s[$s_i] == $string[$i]){
            if ($s[$s_i] == 'o'){
                echo "YES\n";
                $s_i = -1;
                break;
            }
            ++$s_i;
        }
    }
    echo $s_i;

    if ($s_i != -1){
        echo "NO\n";
    }
}

<?php
while (fscanf(STDIN, "%s", $string)){
    $length = strlen($string);
    $s = 'hello';
    $s_i = 0;
    for ($i = 0; $i < $length; ++$i){
        if ($s[$s_i] == $string[$i]){
            if ($s[$s_i] == 'o'){
                echo "YES\n";
                $s_i = -1;
                break;
            }
            ++$s_i;
        }
    }
    if ($s_i != 4 && $s_i != -1){
        echo "NO\n";
    }
}

<?php
	$var = implode('',array_unique(str_split(fgets(STDIN))));
	if (substr_count($var, 'helo')) echo 'YES';
	else echo 'NO';

<?php

$_trans = array(
    'e{1,}' => 'e',
    'h{1,}' => 'h',
    'l{2,}' => 'll',
    'o{1,}' => 'o',
);
$str = fgets(STDIN);
foreach ($_trans as $p => $r) {
    $str = preg_replace('/' . $p . '/i', $r, $str);
}
if (strpos($str, 'hello') !== false) {
    $str = 'YES';
} else {
    $str = 'NO';
}
fwrite(STDOUT, $str);


<?php declare(strict_types=1);

$fp = fopen('php://stdin', 'r');
[$d, $sumTime] = array_filter(explode(' ', fgets($fp)), 'intval');

$totalMinTime = $totalMaxTime = 0;
$times = [];
for ($i = 0; $i < $d; ++$i) {
    [$minTime, $maxTime] = array_filter(explode(' ', fgets($fp)), 'intval');
    $totalMinTime += $minTime;
    $totalMaxTime += $maxTime;
    $times[] = [$minTime, $maxTime];
}
fclose($fp);

if ($totalMinTime <= $sumTime && $sumTime <= $totalMaxTime) {
    echo "YES\n";
    $days = [];
    foreach ($times as [$minTime, $maxTime]) {
        $totalMinTime -= $minTime;
        $totalMaxTime -= $maxTime;

        $min = max($sumTime - $totalMaxTime, 0);
        //$max = $sumTime - $totalMinTime;

        $hours = max($min, $minTime);
        $days[] = $hours;

        $sumTime -= $hours;
    }

    echo join(' ', $days);
} else {
    echo 'NO';
}

<?php

list($d, $sumTime)  = explode(' ', readline());

$days = [];
$minTimeS = 0;
$maxTimeS = 0;

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

    $days[$i] = explode(' ', readline());
    $minTimeS += $days[$i][0];
    $maxTimeS += $days[$i][1];

}
if($maxTimeS < $sumTime){
    echo 'NO';
    die();
}

if($minTimeS <= $sumTime){
    echo "YES\n";
    foreach ($days as $key => $day){
        if($minTimeS == $sumTime){
            echo $day[0] . ' ';
            continue;
        }else{
            if($minTimeS + ($day[1] - $day[0]) > $sumTime){
                echo ($day[0] + ($sumTime - $minTimeS)) . ' ';
                $minTimeS = $sumTime;
                continue;
            }
            $minTimeS += ($day[1] - $day[0]);
            echo $day[1] . ' ';
        }
    }
}else{
    echo 'NO';
    die();
}

<?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 === false) {
		$f = STDIN;
	}
	/* begin body */
	list($d, $sum) = readStringExplodeNum($f, ' ', true);

	$days = array();
	$canMin = $canMax = array();
	for ($i = 0; $i < $d; $i++) {
		list($canMin[$i], $canMax[$i]) = readStringExplodeNum($f, ' ', true);
		$days[$i] = $canMin[$i];
	}

	$_sum = array_sum($days);
	do {
		$diff = $sum - $_sum;
		if ($diff < 0)
			break;
		$success = false;
		foreach ($days as $i => $cnt) {
			$minMaxDiff = $canMax[$i] - $canMin[$i];
			if ($cnt < $canMax[$i]) {
				$success = true;
				$days[$i]+=min($diff, $minMaxDiff);
				break;
			}
		}
		if (!$success) {
			break;
		}
		$_sum = array_sum($days);
	} while ($_sum < $sum);
	if ($_sum != $sum) {
		echo 'NO';
	} else {
		echo 'YES' . "\r\n";
		echo implode(" ", $days);
	}
	/* / end body */
}

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

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = 0;
$f = 0;
$h = array();
$i = array();
$k = array();
$l = array();
for($x = 1; $x <= $a; $x++)
{
    list($c, $d) = explode(" ", trim(fgets(STDIN)));
    $e += $c;
    $f += $d;
    $g = range($c, $d);
    array_push($h, ceil(array_sum($g) / count($g)));
    array_push($l, floor(array_sum($g) / count($g)));
    array_push($i, $c);
    array_push($k, $d);
}
if(($b < $e) || ($b > $f))
{
    print "NO";
}
else
{
    print "YES" . "\n";
    if(array_sum($h) < $b)
    {
        $j = 0;
        for($x = 0; $x < count($h) * 10; $x++)
        {
            if(array_sum($h) < $b)
            {
                $h[$x] = $k[$x];
                $j++;
            }
            elseif(array_sum($h) > $b)
            {
                $h[$j] -= 1;
            }
            else
            {
                print implode(" ", $h);
                break;
            }
        }
    }
    elseif(array_sum($h) > $b)
    {
        $j = 0;
        for($x = 0; $x < count($l) * 10; $x++)
        {
            if(array_sum($l) > $b)
            {
                $l[$x] = $i[$x];
                $j++;
            }
            elseif(array_sum($l) < $b)
            {
                $l[$j] += 1;
            }
            else
            {
                print implode(" ", $l);
                break;
            }
        }
    }
    elseif(array_sum($h) == $b)
    {
        print implode(" ", $h);
    }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = 0;
$f = 0;
$h = array();
$i = array();
$k = array();
for($x = 1; $x <= $a; $x++)
{
    list($c, $d) = explode(" ", trim(fgets(STDIN)));
    $e += $c;
    $f += $d;
    $g = range($c, $d);
    array_push($h, ceil(array_sum($g) / count($g)));
    array_push($i, $c);
    array_push($k, $d);
}
if(($b < $e) || ($b > $f))
{
    print "NO";
}
else
{
    print "YES" . "\n";
    if(array_sum($h) < $b)
    {
        $j = 0;
        for($x = 0; $x < count($h) * 10; $x++)
        {
            if(array_sum($h) < $b)
            {
                $h[$x] = $k[$x];
                $j++;
            }
            elseif(array_sum($h) > $b)
            {
                $h[$j] -= $j;
            }
            else
            {
                print implode(" ", $h);
                break;
            }
        }
    }
    elseif(array_sum($h) > $b)
    {
        $j = 0;
        for($x = 0; $x < count($h) * 10; $x++)
        {
            if(array_sum($h) > $b)
            {
                $h[$x] = $i[$x];
                $j++;
            }
            elseif(array_sum($h) < $b)
            {
                $h[$j] += $j;
            }
            else
            {
                print implode(" ", $h);
                break;
            }
        }
    }
    elseif(array_sum($h) == $b)
    {
        print implode(" ", $h);
    }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = array();
$f = array();
$g = array();
$h = array();
for($x = 1; $x <= $a; $x++)
{
    list($c, $d) = explode(" ", trim(fgets(STDIN)));
    array_push($e, $c);
    array_push($f, $d);
}
for($x = 0; $x < $a; $x++)
{
    if($b >= $e[$x])
    {
        array_push($g, $f[$x]);
    }
}
for($x = 0; $x < count($g); $x++)
{
    $b -= $g[$x];
    if($b > 0)
    {
        array_push($h, $g[$x]);
    }
    elseif($b == 0)
    {
        array_push($h, $g[$x]);
        $b = -1;
        break;
    }
    elseif($b < 0)
    {
        array_push($h, $g[$x] + $b);
        break;
    }
}
if($b < 0)
{
    print "YES" . "\n";
}
else
{
    print "NO";
}
if($b < 0)
{
    print implode(" ", $h);
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = 0;
$f = 0;
$h = array();
$i = array();
$k = array();
for($x = 1; $x <= $a; $x++)
{
    list($c, $d) = explode(" ", trim(fgets(STDIN)));
    $e += $c;
    $f += $d;
    $g = range($c, $d);
    array_push($h, ceil(array_sum($g) / count($g)));
    array_push($i, $c);
    array_push($k, $d);
}
if(($b < $e) || ($b > $f))
{
    print "NO";
}
else
{
    print "YES" . "\n";
    if(array_sum($h) < $b)
    {
        $j = 0;
        for($x = 0; $x < count($h) * 10; $x++)
        {
            if(array_sum($h) < $b)
            {
                $h[$x] = $k[$x];
                $j++;
            }
            elseif(array_sum($h) > $b)
            {
                $h[$j] -= 1;
            }
            else
            {
                print implode(" ", $h);
                break;
            }
        }
    }
    elseif(array_sum($h) > $b)
    {
        $j = 0;
        for($x = 0; $x < count($h) * 10; $x++)
        {
            if(array_sum($h) > $b)
            {
                $h[$x] = $i[$x];
                $j++;
            }
            elseif(array_sum($h) < $b)
            {
                $h[$j] += 1;
            }
            else
            {
                print implode(" ", $h);
                break;
            }
        }
    }
    elseif(array_sum($h) == $b)
    {
        print implode(" ", $h);
    }
}
?>

<?php

list($d, $sumTime)  = explode(' ', readline());

$days = [];
$minTimeS = 0;
$maxTimeS = 0;

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

    $days[$i] = explode(' ', readline());
    $minTimeS += $days[$i][0];
    $maxTimeS += $days[$i][1];

}
if($maxTimeS < $sumTime){
    echo 'NO';
    die();
}

if($minTimeS < $sumTime){
    echo "YES \n";
    foreach ($days as $key => $day){
        $minTimeS += ($day[1] - $day[0]);
        if($minTimeS < $sumTime){
            echo $day[0] . ' ';
            continue;
        }else{
            echo $day[1] . ' ';
        }
    }
}else{
    echo "YES \n";
    foreach ($days as $key => $day){
        echo $day[0] . ' ';
    }
}

<?php

list($d, $sumTime)  = explode(' ', readline());

$days = [];
$minTimeS = 0;
$maxTimeS = 0;

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

    $days[$i] = explode(' ', readline());
    $minTimeS += $days[$i][0];
    $maxTimeS += $days[$i][1];

}
if($maxTimeS < $sumTime){
    echo 'NO';
    die();
}

if($minTimeS <= $sumTime){
    echo "YES\n";
    foreach ($days as $key => $day){
        $minTimeS += ($day[1] - $day[0]);
        if($minTimeS < $sumTime){
            echo $day[0] . ' ';
            continue;
        }else{
            echo $day[1] . ' ';
        }
    }
}else{
    echo 'NO';
    die();
}

<?php

list($d, $sumTime)  = explode(' ', readline());

$days = [];
$minTimeS = 0;
$maxTimeS = 0;

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

    $days[$i] = explode(' ', readline());
    $minTimeS += $days[$i][0];
    $maxTimeS += $days[$i][1];

}
if($maxTimeS < $sumTime){
    echo 'NO';
    die();
}

if($minTimeS < $sumTime){
    echo "YES\n";
    foreach ($days as $key => $day){
        $minTimeS += ($day[1] - $day[0]);
        if($minTimeS < $sumTime){
            echo $day[0] . ' ';
            continue;
        }else{
            echo $day[1] . ' ';
        }
    }
}else{
    echo "YES\n";
    foreach ($days as $key => $day){
        echo $day[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 === false) {
		$f = STDIN;
	}
	/* begin body */
	list($d, $sum) = readStringExplodeNum($f, ' ', true);

	$days = array();
	$canMin = $canMax = array();
	for ($i = 0; $i < $d; $i++) {
		list($canMin[$i], $canMax[$i]) = readStringExplodeNum($f, ' ', true);
		$days[$i] = $canMin[$i];
	}

	$_sum = array_sum($days);
	do {
		$diff = $sum - $_sum;
		$success = false;
		foreach ($days as $i => $cnt) {
			$minMaxDiff = $canMax[$i] - $canMin[$i];
			if ($cnt < $canMax[$i]) {
				$success = true;
				$days[$i]+=min($diff, $minMaxDiff);
				break;
			}
		}
		if (!$success) {
			break;
		}
		$_sum = array_sum($days);
	} while ($_sum < $sum);
	if ($_sum != $sum) {
		echo 'NO';
	} else {
		echo 'YES' . "\r\n";
		echo implode(" ", $days);
	}
	/* / end body */
}

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


<?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
$in=explode("\r\n",file_get_contents("php://stdin"))[0];
$in=str_replace('144','.',$in);
$in=str_replace('14','.',$in);
$in=str_replace('1','.',$in);
for($i=0;$i<strlen($in);$i++){
    if($in[$i]!='.'){
        echo("NO\n");
        return false;
    }
}
echo("YES\n");

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

?>

<?php
// for example, the input is '5 9'
$input = trim(fgets(STDIN));

function magicNumber($input){
	$numbers = str_split($input);
	foreach($numbers as $key => $number){
		if(!in_array($number, [1,4])){
			return false;
		}
		if($number == 4){
			if($key == 0){
				return false;
			}
			if($numbers[$key-1] == 1){
				continue;
			}elseif($numbers[$key-1] == 4){
				if($numbers[$key-2] == 1)
					continue;
				else
					return false;
			}

		}
	}
	return true;
}
if(magicNumber($input)){
	echo "YES";
}else{
	echo "NO";
}

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

?>

<?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('/^(14|1|144)+$/',$a))echo "YES";
else echo "NO";
?>

<?php
$input=trim(fgets(STDIN));
settype($input,'string');
$a=0;
$input2=[];
$y=0;$ccy=0;$c=0;
$input2=str_split($input);
for ($i=0;$i<strlen($input); $i++) {

  if($i<strlen($input)-2 and $input2[$i] == 1 and $input2[$i+1] == 4 and $input2[$i+2] == 4 ){
      $ccy+=3;
      $i+=2;
  }else if($i<strlen($input)-1 and $input2[$i] == 1 and $input2[$i+1] == 4){
       $c+=2;
       $i+=1;
  }else if($input2[$i] == 1 ){
       $y++;
  }
}
$k=$ccy + $c+$y  ;
if(count($input2) == $k){
     echo "YES";
}else{
     echo "NO";
}

<?php
	function check($x)
	{
		$n = strlen($x) - 1;
		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 = fgets(STDIN);
	if (check($input)) echo "YES";
	else echo "NO";
	echo "\n";

?>

<?php
	function check($x)
	{
		$n = count($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] == 1) continue;
			}
			return false;
		}
		return true;
	}

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

?>

<?php

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

?>

<?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 = fgets(STDIN);
	if (check($input)) echo "YES";
	else echo "NO";
	echo "\n";

?>

<?php
	function check($x)
	{
		$n = count($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 = fgets(STDIN);
	if (check($input)) echo "YES";
	else echo "NO";
	echo "\n";

?>

<?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 = fgets(STDIN);
		$regex = '/^(1|14|144)+$/';
		if (preg_match($regex, $input)) echo "YES";
		else echo "NO";
		echo "\n";

?>

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

<?php
$in=explode("\r\n",file_get_contents("php://stdin"))[0];
$in=str_replace('144','',$in);
$in=str_replace('14','',$in);
$in=str_replace('1','',$in);
if(strlen($in)==0){
    echo("YES\n");
}else{
    echo("NO\n");
}

<?php
// for example, the input is '5 9'
$input = trim(fgets(STDIN));

function magicNumber($input){
	$numbers = str_split($input);
	foreach($numbers as $key => $number){
		if(!in_array($number, [1,4])){
			return false;
		}
		if($number == 4){
			if($numbers[$key-1] == 1){
				continue;
			}elseif($numbers[$key-1] == 4){
				if($numbers[$key-2] == 1)
					continue;
				else
					return false;
			}

		}
	}
	return true;
}
if(magicNumber($input)){
	echo "YES";
}else{
	echo "NO";
}


<?php
// Входящее число: [0 < s < 99]
$s = trim(fgets(STDIN));
// Список числе от 1 до 19, 20, 30, 40, 50, 60, 70, 80, 90
$numbers = array('0' => 'zero', '1' => 'one', '2' => 'two', '3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six', '7' => 'seven', '8' => 'eight', '9' => 'nine', '10' => 'ten', '11' => 'eleven', '12' => 'twelve', '13' => 'thirteen', '14' => 'fourteen', '15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen', '18' => 'eighteen', '19' => 'nineteen', '20' => 'twenty', '30' => 'thirty', '40' => 'forty', '50' => 'fifty', '60' => 'sixty', '70' => 'seventy', '80' => 'eighty', '90' => 'ninety');
// Если число меньше или равно 19
if ($s <= 19) {
	$result = $numbers[$s];
} else {
	// Проверяем второй символ введенного числа
	if($s[1]==0) {
		// Если 0, то выводим из массива
		$result = $numbers[$s];
	} else {
		// Если нет, то собираем число
		$first_number = $numbers[$s[0].'0'];
		$second_number = $numbers[$s[1]];
		$result = $first_number.'-'.$second_number;
	}
}
print($result);
?>

<?php

$number = readline();

$stringNumbers = array(
    1 => 'one',
    2 => 'two',
    3 => 'three',
    4 => 'four',
    5 => 'five',
    6 => 'six',
    7 => 'seven',
    8 => 'eight',
    9 => 'nine',
    10 => 'ten',
    11 => 'eleven',
    12 => 'twelve',
    13 => 'thirteen',
    15 => 'fifteen',
    18 => 'eighteen',
);

$stringFirstNumbers = array(
    1 => '',
    2 => 'twenty',
    3 => 'thirty',
    4 => 'forty',
    5 => 'fifty',
    6 => 'sixty',
    7 => 'seventy',
    8 => 'eighty',
    9 => 'ninety',
);

if ($number <= 13 || $number == 15 || $number == 18)
    echo $number == 0 ? 'zero' : $stringNumbers[$number];

else {
    $firstNumber = $number / 10;
    $secondNumber = $number % 10;

    if ((int)$firstNumber == 1) echo $stringNumbers[(int)$secondNumber].'teen';

    else echo $stringNumbers[(int)$secondNumber] ? $stringFirstNumbers[(int)$firstNumber].'-'.$stringNumbers[(int)$secondNumber] : $stringFirstNumbers[(int)$firstNumber];
}

<?php

$number = readline();

$stringNumbers = array(
    1 => 'one',
    2 => 'two',
    3 => 'three',
    4 => 'four',
    5 => 'five',
    6 => 'six',
    7 => 'seven',
    8 => 'eight',
    9 => 'nine',
    10 => 'ten',
    11 => 'eleven',
    12 => 'twelve',
    13 => 'thirteen',
    15 => 'fifteen'
);

$stringFirstNumbers = array(
    1 => '',
    2 => 'twenty',
    3 => 'thirty',
    4 => 'forty',
    5 => 'fifty',
    6 => 'sixty',
    7 => 'seventy',
    8 => 'eighty',
    9 => 'ninety',
);

if ($number <= 13 || $number == 15)
    echo $number == 0 ? 'zero' : $stringNumbers[$number];

else {
    $firstNumber = $number / 10;
    $secondNumber = $number % 10;

    if ((int)$firstNumber == 1) echo $stringNumbers[(int)$secondNumber].'teen';

    else echo $stringNumbers[(int)$secondNumber] ? $stringFirstNumbers[(int)$firstNumber].'-'.$stringNumbers[(int)$secondNumber] : $stringFirstNumbers[(int)$firstNumber];
}

<?php

$number = readline();

$stringNumbers = array(
    1 => 'one',
    2 => 'two',
    3 => 'three',
    4 => 'four',
    5 => 'five',
    6 => 'six',
    7 => 'seven',
    8 => 'eight',
    9 => 'nine',
    10 => 'ten',
    11 => 'eleven',
    12 => 'twelve',
    13 => 'thirteen',
    15 => 'fifteen'
);

$stringFirstNumbers = array(
    1 => '',
    2 => 'twenty',
    3 => 'thirty',
    4 => 'forty',
    5 => 'fifty',
    6 => 'sixty',
    7 => 'seventy',
    8 => 'eighty',
    9 => 'ninety',
);

if ($number <= 13 || $number === 15)
    echo $number == 0 ? 'zero' : $stringNumbers[$number];

else {
    $firstNumber = $number / 10;
    $secondNumber = $number % 10;

    if ((int)$firstNumber == 1) echo $stringNumbers[(int)$secondNumber].'teen';

    else echo $stringNumbers[(int)$secondNumber] ? $stringFirstNumbers[(int)$firstNumber].'-'.$stringNumbers[(int)$secondNumber] : $stringFirstNumbers[(int)$firstNumber];
}

<?php

$number = readline();

$stringNumbers = array(
    1 => 'one',
    2 => 'two',
    3 => 'three',
    4 => 'four',
    5 => 'five',
    6 => 'six',
    7 => 'seven',
    8 => 'eight',
    9 => 'nine',
    10 => 'ten',
    11 => 'eleven',
    12 => 'twelve',
    13 => 'thirteen',
    15 => 'fifteen'
);

$stringFirstNumbers = array(
    1 => '',
    2 => 'twenty',
    3 => 'thirty',
    4 => 'forty',
    5 => 'fifty',
    6 => 'sixty',
    7 => 'seventy',
    8 => 'eighty',
    9 => 'ninety',
);

if ($number <= 13 || $number === 15)
    echo $number == 0 ? 'zero' : $stringNumbers[$number];

else {
    $firstNumber = $number / 10;
    $secondNumber = $number % 10;

    if ((int)$firstNumber == 1) echo $stringNumbers[(int)$secondNumber].'teen';

    else echo $stringFirstNumbers[(int)$firstNumber].$stringNumbers[(int)$secondNumber];
}

<?php

$number = readline();

$stringNumbers = array(
    1 => 'one',
    2 => 'two',
    3 => 'three',
    4 => 'four',
    5 => 'five',
    6 => 'six',
    7 => 'seven',
    8 => 'eight',
    9 => 'nine',
    10 => 'ten',
    11 => 'eleven',
    12 => 'twelve',
    13 => 'thirteen',
    15 => 'fifteen'
);

$stringFirstNumbers = array(
    1 => '',
    2 => 'twenty',
    3 => 'thirty',
    4 => 'forty',
    5 => 'fifty',
    6 => 'sixty',
    7 => 'seventy',
    8 => 'eighty',
    9 => 'ninety',
);

if ($number <= 13 || $number === 15)
    echo $number == 0 ? 'zero' : $stringNumbers[$number];

else {
    $firstNumber = $number / 10;
    $secondNumber = $number % 10;

    if ((int)$firstNumber == 1) echo $stringNumbers[(int)$secondNumber].'teen';

    else echo $stringFirstNumbers[(int)$firstNumber].'-'.$stringNumbers[(int)$secondNumber];
}

<?php
// Входящее число: [0 < s < 99]
$s = fgets(STDIN);
// Список числе от 1 до 19, 20, 30, 40, 50, 60, 70, 80, 90
$numbers = array('0' => 'zero', '1' => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', '8' => 'eight', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen', 16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen', 19 => 'nineteen', 20 => 'twenty', 30 => 'thirty', 40 => 'forty', 50 => 'fifty', 60 => 'sixty', 70 => 'seventy', 80 => 'eighty', 90 => 'ninety');
// Если число меньше или равно 19
if ($s <= 19) {
	$result = $numbers[$s];
} else {
	// Проверяем второй символ введенного числа
	if($s[1]==0) {
		// Если 0, то выводим из массива
		$result = $numbers[$s];
	} else {
		// Если нет, то собираем число
		$first_number = $numbers[$s[0].'0'];
		$second_number = $numbers[$s[1]];
		$result = $first_number.'-'.$second_number;
	}
}
printf($result);
?>


<?php
$IN = STDIN;
fscanf($IN, "%d %d %d %d %d %d", $k1, $k2, $k3, $k4, $a, $b);
$min = min(array($k1, $k2, $k3, $k4));
if ($min>$b)
   echo $b-$a+1;
elseif (($min>$a)&&($min<$b))
  echo $min - $a;
else
    echo 0;
?>

<?php
$IN = STDIN;
fscanf($IN, "%d %d %d %d %d %d", $k1, $k2, $k3, $k4, $a, $b);
$min = min(array($k1, $k2, $k3, $k4));
if ($min>$b)
   echo $b-$a;
elseif (($min>$a)&&($min<$b))
  echo $min - $a;
else
    echo 0;
?>


<?php
//input
$s = fopen("php://stdin", 'r');
$x = stream_get_contents($s);

//data

//calc
$x = strtoupper($x[0]).substr($x,1);

//output
$stdout = fopen('php://stdout', 'w');
fputs ($stdout, $x);

?>

<?php
fscanf(STDIN,"%s",$s);
$a=strtoupper(substr($s,0,1));
$b=$a.substr($s,1,(strlen($s)-1));
echo $b;

<?php
$a = trim(fgets(STDIN));
$b = str_split($a);
$b[0] = strtoupper($b[0]);
$c = implode($b);
print $c;
?>

<?php
$word = fgets(STDIN);
$word = str_split($word);
if (!ctype_upper($word[0])) {
    $word[0] = strtoupper($word[0]);
}
echo implode($word);
?>

<?php
    $fp = fopen('php://stdin', 'r');
    echo ucfirst(rtrim(fgets($fp)));
?>

<?php
	$in = fgets(STDIN);
	$len = strlen($in);
	echo strtoupper(substr($in,0,1)).substr($in,1,$len-1);

<?php
    $dir = explode(' ',stream_get_contents(fopen("php://stdin", 'r')));
    for($i = 0; $i < count($dir); $i++){
        echo ucfirst($dir[$i]);
    }
?>

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

echo strtoupper(substr($string, 0 , 1)) .substr($string, 1);

<?php
    function islower($c) {
        return ($c >= 'a' && $c <= 'z');
    }

    $s = trim(fgets(STDIN));

    if (islower($s[0])) {
        $char = ord($s[0]) + ord("A") - ord("a");
        $s[0] = chr($char);
    }

    echo $s;
?>

<?php

    $word = fgets(STDIN);
    if(ctype_lower($word[0])){
    	$word = ucfirst($word);
    }
    echo $word;

?>

#!/usr/bin/php
<?php
$s = fopen("php://stdin", 'r');
$word = fgets($s);
echo ucfirst($word);

<?php
$s=trim(fgets(STDIN));
$s[0]=strtoupper($s[0]);
echo $s;
?>

<?php

$s =  str_split(readline());
$s[0] = strtoupper($s[0]);

echo implode('',$s);

<?php
$str = readline();
if($str[0]>='a') $str[0] = chr(ord($str[0]) - 32);
echo $str;

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

$word = trim(fgets(STDIN));
$word[0] = strtoupper($word[0]);
printf("%s", $word);

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

<?php

$a = trim(fgets(STDIN));
for($i=1 ; $a[$i] ; $i++)
   $b = $b.$a[$i];

echo strtoupper($a[0]).$b;
?>

<?php
    $n = trim(fgets(STDIN));
    $n[0] = strtoupper($n[0]);
    fwrite(STDOUT, $n);

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

$input = (string) $input;
$input[0] = strtoupper($input[0]);
echo $input;

<?php
	echo ucfirst(trim(fgets(STDIN)));
?>

<?php

$w =  fgets(STDIN);

$stri = (string)$w;
$n = strlen($stri);

$a = $stri[0];
if(ord($a)>96 && ord($a)<123) {  $stri[0] = chr((ord($a)-32));
		//for($i=0;$i<$n;$i++){echo $stri[$i];}
		}
//echo ord($a);

echo $stri;

<?php
 $arr=fgets(STDIN);

  echo(ucfirst($arr));

 ?>

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

$N = input();
$N[0] = strtoupper($N[0]);
echo $N;
echo "\n";

?>

<?php
	$n = trim(fgets(STDIN));
	$res = ucfirst($n);
	fwrite(STDOUT,"$res");
?>

<?php
$fp = fopen("php://STDIN", "r");
$s = fgets($fp);
$s2 = substr($s, 1);
echo strtoupper($s[0]).$s2;
?>

<?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)
{
    $newS0 = strtoupper($s[0]);
    $s[0] = $newS0;

    return $s;
}

$r = 0;

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

if ($s === null) {
    $r = '';
} else {
    $r = foo($s);
}

fwrite($output, $r);

<?php
$w = trim(fgets(STDIN));
echo ucfirst($w);

<?php
$word = trim(fgets(STDIN));
echo strtoupper($word[0]).substr($word,1);

<?php

function getStdIn(bool $asInt = false): array
{
    $stdIn = explode(' ', trim(fgets(STDIN)));

    if ($asInt) {
        foreach ($stdIn as $key => $value) {
            $stdIn[$key] = (int)$value;
        }
    }

    return $stdIn;
}

function stdOut($output)
{
    fwrite(STDOUT, $output);
}

function solve(): void
{
    [$word] = getStdIn();
    stdOut(ucfirst($word));
}

solve();

<?php

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

echo ucfirst($s);
?>

<?php
$ip     = fopen('php://stdin', "r");
$op     = fopen('php://stdout',"w");

fwrite($op, sprintf("%s", ucwords(trim(fgets($ip)))));
?>

<?php
$str=trim(fgets(STDIN));
$len=strlen($str);
$rest="";
for($i=1;$i<$len;$i++)
	$rest.=$str[$i];
//$j=json_encode($rest);
echo strtoupper($str[0]).$rest;

<?php

$fi = fopen('php://stdin', 'r');
$a=fgets($fi);
//$address=fgets($fi)*1;
//$time=fgets($fi)*1;
//$address = 'Python';

//$a = 'ApPLe';
echo ucfirst($a);

<?php
$string = trim(fgets(STDIN));
echo ucfirst($string);
?>

<?php
    $f = fopen('php://stdin', 'r');
    //$f = fopen('1q.txt', 'r');
    $s = trim(fgets($f));

    echo strtoupper($s[0]).substr($s,1);

<?php

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

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

if( ord( $s[0] ) >= 97 )
{
     $s[0] = strtoupper( $s[0] ) ;
}
echo $s ;

fwrite($stdout);

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

?>

<?php
$word = rtrim(fgets(STDIN));

if(ctype_upper($word[0])){
    echo($word);
}else{
    echo(ucfirst($word));
}

<?php

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

echo ucfirst($str);

?>

<?php

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

$str_chars = str_split($str);

$oldOrd = ord($str_chars[0]);

if ($oldOrd >= 97 && $oldOrd <= 122) {
    $newOrd = ord($str_chars[0]) - 32;
    $str_chars[0] = chr($newOrd);
}

$new_str = implode("", $str_chars);

echo $new_str;

?>

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

<?php
  $f = fopen('php://stdin', 'r');
  echo strtoupper(fgetc($f)) . fgets($f);
?>

<?php

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

$the_word = $input;

$lower = "abcdefghijklmnopqrstuvwxyz";

$upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//Transfer $upper & $lower Into Array.
$lower = str_split($lower);

$upper = str_split($upper);

//Combine.
$words = array_combine($lower,$upper);

//Transfer The First Letter From The Input.
$the_word[0] = $words[$the_word[0]];

echo $the_word;

?>

<?php
echo ucfirst(trim(fgets(STDIN)));
?>

<?php
// 281A 	    Капитализация слова

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

$char = fgetc($in);
$char = strtoupper($char);

$line = fgets($in);

echo $char . $line;

?>

<?php
$n =rtrim(fgets(STDIN));
$n[0] = strtoupper($n[0]);

echo $n;

<?php
    fscanf(STDIN, "%s\n",$str1);
    echo ucfirst($str1);
?>

<?php

$string = fgets(STDIN);

$string[0] = strtoupper($string[0]);

echo $string;

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

$line = str_split($line, 1); 		// разбиваем строку на массив букв

if($line[0] != ctype_upper($line[0])){
	$line[0] = strtoupper($line[0]);
}

foreach($line as $v){
	printf($v);
}

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

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

  fscanf($fr, "%s", $str);

$arr0 = str_split($str);

$arr0[0]=  strtoupper($arr0[0]);

$comma_separated = implode("", $arr0);

echo $comma_separated;

fclose($fr);

?>

<?php

$std = fopen("php://stdin", "r");
fscanf($std, "%s",$str);
echo ucwords($str)."\n";

<?
$a = trim(fgets(STDIN));
$ar = str_split($a);
$x = strtoupper($ar[0]);
for($i=1;$i<count($ar);$i++)
    {
        $x .= $ar[$i];
    }
   echo $x;
?>

<?php
$line = fgets(STDIN);

$line[0] = strtoupper($line[0]);
echo $line;

<?php
//281A: Word Capitalization
$word = trim(fgets(STDIN)); //$word = "ApPLe";
$explode = str_split($word);
$explode[0] = strtoupper($explode[0]);
$implode = implode($explode);
echo $implode;
?>

<?php
	$input = trim(fgets(STDIN));
	echo ucfirst($input);
?>

<?php
//281A: Word Capitalization
$word = trim(fgets(STDIN)); $word = "ApPLe";
$explode = str_split($word);
$explode[0] = strtoupper($explode[0]);
$implode = implode($explode);
echo $implode;
?>

<?php
fscanf(STDIN,"%s",$s);
$x=substr($s,0,1);
$a=strtoupper(substr($s,0,1));
$b=explode("$x",$s);
$c=$a.implode("",$b);
echo $c;

<?php
	$in = fgets(STDIN);
	$len = strlen($in);
	$flag = true;
	for ($x = 0; $x < $len; $x++) {
		if ($in[$x] >= 'A' && $in[$x] <= 'Z') {
			$flag = false;
			break;
		}
	}
	if ($flag) {
		echo strtoupper(substr($in,0,1)).substr($in,1,$len-1);
	} else echo $in;

<?php

$a = 'aasdDkjKBJk';
for($i=1 ; $a[$i] ; $i++)
   $b = $b.$a[$i];

echo strtoupper($a[0]).$b;

<?php
 $arr=fgets(STDIN);
 $a=strtoupper($arr[0]);
 echo($a . $arr);

 ?>

<?php
$string = $argv[1];
echo ucfirst($string);

<?php
$word = trim(fgets(stdin));
echo strtoupper($word[0]).substr($word,1);

<?php

function getStdIn(bool $asInt = false): array
{
    $stdIn = explode(' ', trim(fgets(STDIN)));

    if ($asInt) {
        foreach ($stdIn as $key => $value) {
            $stdIn[$key] = (int)$value;
        }
    }

    return $stdIn;
}

function stdOut($output)
{
    fwrite(STDOUT, $output);
}

function solve(): void
{
    [$word] = getStdIn(true);
    stdOut(ucfirst($word));
}

solve();

<?php
    sscanf(STDIN, "%s\n",$str1);
    echo ucfirst($str1);

?>


<?php
/** chaotic_iak's solution in PHP 5.4 to the problem 321A (Round 190 Div 2 Problem C) in Codeforces **/

/** Module for retrieving input **/

// If this is a local test (a variable declared in a specialized page to open this script), open from localtest.txt instead of php://stdin (because I'm too lazy to supply the arguments by stdin)
if (isset($localtest)) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}

// A function to retrieve the next line. Takes one optional argument $single, which should be true if the next line (based on problem's specification) has only one number/string/whatever, so I don't have to do silly things like $raw = g(); $num = $raw[0];
function g($single = false) {

	// Take the global $stdin variable aka the file handler so we can access it from this function
	global $stdin;

	// Take the input from the handler, trim it, and explode it based on space (" 1 2 3 " becomes array("1", "2", "3")); trim is usually to remove trailing \r
	$input = explode(" ", trim(fgets($stdin)));

	// If the line is not a single number, return the whole array, otherwise simply return the single string that we exploded for nothing
	if (!$single) {return $input;} else {return $input[0];}
}

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

/** chaotic_iak's solution **/
// This is a competitive programming solution. The code is not remarked (because I want speed).

$raw = g();
$a = $raw[0];
$b = $raw[1];
$s = g(true);
$len = strlen($s);

$xpass = array(0);
$ypass = array(0);
$x = 0;
$y = 0;
for ($i = 0; $i < $len; $i++) {
	switch (substr($s, $i, 1)) {
		case "U":
			$y++;
			break;
		case "R":
			$x++;
			break;
		case "L":
			$x--;
			break;
		case "D":
			$y--;
			break;
	}
	$xpass[] = $x;
	$ypass[] = $y;
}

$xmax = $xpass[$len];
$ymax = $ypass[$len];

for ($i = 0; $i < $len; $i++) {
	$diffx = -1;
	$diffy = -1;
	if ($xmax == 0) {
		if ($xpass[$i] == $a) {$diffx = 1234567890;}
	} else {
		$temp = ($a - $xpass[$i]) % $xmax;
		if (!$temp) {$diffx = ($a - $xpass[$i]) / $xmax;}
	}
	if ($ymax == 0) {
		if ($ypass[$i] == $b) {$diffy = 1234567890;}
	} else {
		$temp = ($b - $ypass[$i]) % $ymax;
		if (!$temp) {$diffy = ($b - $ypass[$i]) / $ymax;}
	}
	if ((($diffx == 1234567890) || ($diffy == 1234567890) || ($diffx == $diffy)) && ($diffx >= 0) && ($diffy >= 0)) {
		echo "Yes"; return 0;
	}
}
echo "No";

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];

/*$a=-2;
$b=-2;
$path='UURR';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$min_x=9999999;
$max_x=-10000000;
$min_y=9999999;
$max_y=-10000000;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }

    if ($i<$length)
    {
        if ($min_x>$c_posx) $min_x=$c_posx;
        if ($min_y>$c_posy) $min_y=$c_posy;

        if ($max_x<$c_posx) $max_x=$c_posx;
        if ($max_y<$c_posy) $max_y=$c_posy;
    }

    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$plav_x=$max_x-$min_x;
$plav_y=$max_y-$min_y;

if ($plav_x>$plav_y) $plav=$plav_x; else $plav=$plav_y;

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=abs($a)/abs($itog_x);
$num_y_cycles=abs($b)/abs($itog_y);

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=ceil($num_cycles)-$plav;

$c_posx=$itog_x*$go_iterations;
$c_posy=$itog_y*$go_iterations;

$i=0;
$cur_pos=0;
while($i<$length*($plav+1))
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];
    if ($c_posx==$a && $c_posy==$b && $plav==0) die('Yes');

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    //echo $current_word.' '.$c_posx.' '.$c_posy.'
';

    $i++;

    //if (($i % $length) == 0  && $i!=0) echo '
';

    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];

/*$a=4;
$b=3;
$path='UURRDL';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=abs($a)/abs($itog_x);
$num_y_cycles=abs($b)/abs($itog_y);

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=$num_cycles-2;

$c_posx=$itog_x*$go_iterations;
$c_posy=$itog_y*$go_iterations;

$i=0;
$cur_pos=0;
while($i<$length*3)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];

/*$a=-1;
$b=-1;
$path='UR';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=$a/$itog_x;
$num_y_cycles=$b/$itog_y;

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=$num_cycles-2;

$c_posx=$itog_x*abs($go_iterations);
$c_posy=$itog_y*abs($go_iterations);

$i=0;
$cur_pos=0;
while($i<$length*3)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];

/*$a=2;
$b=2;
$path='RU';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=abs($a)/abs($itog_x);
$num_y_cycles=abs($b)/abs($itog_y);

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=ceil($num_cycles)-5;

$c_posx=$itog_x*$go_iterations;
$c_posy=$itog_y*$go_iterations;

$i=0;
$cur_pos=0;
while($i<$length*7)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }

    $i++;

    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];

/*$a=-1;
$b=1000000000;
$path='LRRLU';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$min_x=9999999;
$max_x=-10000000;
$min_y=9999999;
$max_y=-10000000;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }

    if ($i<$length)
    {
        if ($min_x>$c_posx) $min_x=$c_posx;
        if ($min_y>$c_posy) $min_y=$c_posy;

        if ($max_x<$c_posx) $max_x=$c_posx;
        if ($max_y<$c_posy) $max_y=$c_posy;
    }

    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$plav_x=$max_x-$min_x;
$plav_y=$max_y-$min_y;

if ($plav_x>$plav_y) $plav=$plav_x; else $plav=$plav_y;

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=abs($a)/abs($itog_x);
$num_y_cycles=abs($b)/abs($itog_y);

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=ceil($num_cycles)-$plav;

$c_posx=$itog_x*$go_iterations;
$c_posy=$itog_y*$go_iterations;

$i=0;
$cur_pos=0;
while($i<$length*($plav+1))
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];
    if ($c_posx==$a && $c_posy==$b) die('Yes');

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    //echo $current_word.' '.$c_posx.' '.$c_posy.'
';

    $i++;

    //if (($i % $length) == 0  && $i!=0) echo '
';

    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];

/*$a=0;
$b=0;
$path='D';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$max_x=$a-105;
$max_y=$b+105;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    if ($c_posx==$a && $c_posy==$b) die('Yes');
    if ($c_posx<$max_x || $c_posx>$max_y || $c_posy>$max_y || $c_posy<$max_x)   die('No');

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=$a/$itog_x;
$num_y_cycles=$b/$itog_y;

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=$num_cycles-1;

$c_posx=$itog_x*$go_iterations;
$c_posy=$itog_y*$go_iterations;

$i=0;
$cur_pos=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];

/*$a=0;
$b=0;
$path='D';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$max_x=$a-105;
$max_y=$b+105;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=$a/$itog_x;
$num_y_cycles=$b/$itog_y;

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=$num_cycles-1;

$c_posx=$itog_x*$go_iterations;
$c_posy=$itog_y*$go_iterations;

$i=0;
$cur_pos=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];

/*$a=4;
$b=3;
$path='UURRDL';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$max_x=$a-105;
$max_y=$b+105;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=$a/$itog_x;
$num_y_cycles=$b/$itog_y;

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=$num_cycles-2;

$c_posx=$itog_x*$go_iterations;
$c_posy=$itog_y*$go_iterations;

$i=0;
$cur_pos=0;
while($i<$length*3)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];

/*$a=1000000000;
$b=1000000000;
$path='UURRDL';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=$a/$itog_x;
$num_y_cycles=$b/$itog_y;

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=$num_cycles-2;
if ($go_iterations<0) $go_iterations=1;

$c_posx=$itog_x*$go_iterations;
$c_posy=$itog_y*$go_iterations;

$i=0;
$cur_pos=0;
while($i<$length*3)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];

/*$a=2;
$b=6;
$path='RUUUURLDDDL';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=abs($a)/abs($itog_x);
$num_y_cycles=abs($b)/abs($itog_y);

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=ceil($num_cycles)-5;

$c_posx=$itog_x*$go_iterations;
$c_posy=$itog_y*$go_iterations;

$i=0;
$cur_pos=0;
while($i<$length*3)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }

    $i++;

    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];
/*
$a=2;
$b=2;
$path='RU';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$min_x=9999999;
$max_x=-10000000;
$min_y=9999999;
$max_y=-10000000;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }

    if ($i<$length)
    {
        if ($min_x>$c_posx) $min_x=$c_posx;
        if ($min_y>$c_posy) $min_y=$c_posy;

        if ($max_x<$c_posx) $max_x=$c_posx;
        if ($max_y<$c_posy) $max_y=$c_posy;
    }

    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$plav_x=$max_x-$min_x;
$plav_y=$max_y-$min_y;

if ($plav_x>$plav_y) $plav=$plav_x; else $plav=$plav_y;

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=abs($a)/abs($itog_x);
$num_y_cycles=abs($b)/abs($itog_y);

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=ceil($num_cycles)-$plav;

$c_posx=$itog_x*$go_iterations;
$c_posy=$itog_y*$go_iterations;

//echo $num_cycles.' '.$itog_x.' '.$itog_y.'
';

$i=0;
$cur_pos=0;
while($i<$length*($plav+1))
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    //echo $current_word.' '.$c_posx.' '.$c_posy.'
';

    $i++;

    //if (($i % $length) == 0  && $i!=0) echo '
';

    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>

<?
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode("\n",$n);

$arr = explode(' ', $dum[0]);
$a = (int) $arr[0];
$b = (int) $arr[1];
$path = $dum[1];
/*
$a=-261597957;
$b=418556728;
$path='LLLDLUDUULLRDDULLRRUDRDLULRLRLLRRUUDRRLRUDLRRLUDRDLLUUDUULRURLDLULUUULDDUURLRUDURRL';*/

$c_posx=0;
$c_posy=0;

$length=strlen($path);
$cur_pos=0;

$i=0;
while($i<$length*2)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    if ($i==$length)
    {
        $change_x=$c_posx;
        $change_y=$c_posy;
    }
    if ($i==$length*2)
    {
        $change_x_2=$c_posx;
        $change_y_2=$c_posy;
    }
    $cur_pos++;
}

$itog_x=$change_x_2-$change_x;
$itog_y=$change_y_2-$change_y;

$num_x_cycles=abs($a)/abs($itog_x);
$num_y_cycles=abs($b)/abs($itog_y);

if ($num_x_cycles>$num_y_cycles) $num_cycles=$num_x_cycles; else $num_cycles=$num_y_cycles;

$go_iterations=ceil($num_cycles)-2;

$c_posx=$itog_x*$go_iterations;
$c_posy=$itog_y*$go_iterations;

$i=0;
$cur_pos=0;
while($i<$length*3)
{
    if ($cur_pos>=$length) $cur_pos=0;
    $current_word=$path[$cur_pos];

    switch ($current_word)
    {
        case 'U':
        $c_posy=$c_posy+1;
        break;
        case 'D':
        $c_posy=$c_posy-1;
        break;
        case 'L':
        $c_posx=$c_posx-1;
        break;
        case 'R':
        $c_posx=$c_posx+1;
        break;
    }
    $i++;
    $cur_pos++;
    if ($c_posx==$a && $c_posy==$b) die('Yes');
}
die('No');
?>


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

// Codeforces Contest 176 Div 2 Problem B
$raw = g();
$n = bcsub($raw[0], 1);
$k = bcsub($raw[1], 1);

$c = bcsub(bcmul($k,$k+1), bcmul(2,$n));
if (bccomp(0, $c) == 1) {echo "-1"; exit;}

$sqrt = bcsqrt(bcmul(4,$c), 10);
$raw = explode(".", $sqrt);
$trunc = $raw[0];

if (bcmod($trunc, 2) == 0) {$trunc = bcsub($trunc, 1);}

$m = bcdiv(bcadd($trunc, 1), 2);

if (bcadd(bcmul(4,$c),1) == bcpow(bcadd(bcmul(2,$m),1),2)) {echo bcsub($k, $m);} else {echo bcsub(bcadd($k,1), $m);}

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

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

// Codeforces Contest 176 Div 2 Problem B
$raw = g();
$n = $raw[0] - 1;
$k = $raw[1] - 1;

$c = bcsub(bcmul($k,$k+1), bcmul(2,$n));
if (bccomp(0, $c) == 1) {echo "-1"; exit;}
if (bccomp(0, $c) == 0) {echo $k; exit;}

$min = -1;
$max = bcsub(bcpow(2,30), 1);

while ( (!((bccomp(0, t()) == -1) && (bccomp(t(), bcmul(2,m())) != 1)))
	&& (bccomp(bcsub($max, $min), 1) == 1)) {
	if (bccomp(0, t()) == -1) {
		$min = m();
	} else {
		$max = m();
	}
}

if (bccomp($c, bcmul(m(), bcadd(m(), 1))) == 0) {echo bcsub($k, m());} else {echo bcsub(bcadd($k,1), m());}

function t() {
	global $c, $min, $max;
	$m = m();
	return bcsub($c, bcmul($m, $m-1));
}

function m() {
	global $min, $max;
	return bcdiv(bcadd($min, $max), 2, 0);
}

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

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

// Codeforces Contest 176 Div 2 Problem B
$raw = g();
$n = $raw[0] - 1;
$k = $raw[1] - 1;

$c = bcsub(bcmul($k,$k+1), bcmul(2,$n));
if (bccomp(0, $c) == 1) {echo "-1"; exit;}

$sqrt = bcsqrt(bcmul(4,$c), 10);
$raw = explode(".", $sqrt);
$trunc = $raw[0];

if (bcmod($trunc, 2) == 0) {$trunc = bcsub($trunc, 1);}

$m = bcdiv(bcadd($trunc, 1), 2);

if (bcadd(bcmul(4,$c),1) == bcpow(bcadd(bcmul(2,$m),1),2)) {echo bcsub($k, $m);} else {echo bcsub(bcadd($k,1), $m);}

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


<?php
// 527A     Игра с бумагой
$in = fopen("php://stdin", 'r');

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

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

$col = '0';
while ((bccomp($a, $b) === 1) and ($b !== '0')) {
    $n = bcdiv($a, $b);
    $col = bcadd($col, $n);
    $a = bcsub($a, bcmul($b, $n));
    if (bccomp($a, $b) === -1) {
        $tmp = $a;
        $a = $b;
        $b = $tmp;
    }
}

echo "$col";

?>


<?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
list($a, $b, $n) = explode(' ', trim(fgets(STDIN)));

$k = $a;
$nn = $n;
$sem = true;

while ($n > 0)
{
    while ($k != $n)
    {
        if ($k > $n)
            $k -= $n;
        else
            $n -= $k;
    }

    if ($sem)
    {
        $sem = false;
        $k = $b;
    }
    else
    {
        $sem = true;
        $k = $a;
    }

    $n = $nn - $n;
    $nn = $n;
    if ($n <= 0)
    {
        switch ($sem)
        {
            case true:
                echo "1";
                break;
            case false:
                echo "0";
                break;
        }
        break;
    }
}
?>

<?php
// 119A Эпическая игра

// Наибольший общий делитель НОД
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}

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

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

$flag = true;
while (true) {
    if ($flag) {
        $c = $a;
    } else {
        $c = $b;
    }

    $cc = max(abs($c), abs($n));
    $nn = min(abs($c), abs($n));

    $gcd = gcd ($cc, $nn);
//echo "c=$c gcd=$gcd n=$n flag=$flag \n";
    if (($gcd <= $n) and ($n > 0)) {
        $n -= $gcd;
        $flag = $flag ^ true;
    } else {
        break;
    }
}

if ($flag) {
    echo '1';
} else {
    echo '0';
}

?>

<?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
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
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
list($a, $b, $n) = explode(' ', trim(fgets(STDIN)));

$k = $a;
$nn = $n;
$sem = true;

while ($n > 0)
{
    while ($k != $n)
    {
        if ($k > $n)
            $k -= $n;
        else
            $n -= $k;
    }

    if ($sem)
    {
        $sem = false;
        $k = $b;
        $m++;
    }
    else
    {
        $sem = true;
        $k = $a;
        $l++;
    }

    $n = $nn - $n;
    $nn = $n;
}
if ($k == max($k, $l))
    echo "0";
else
    echo "1";
?>

<?php
// 119A Эпическая игра

// Наибольший общий делитель НОД
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}

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

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

$flag = true;
while (true) {
    if ($flag) {
        $sum = $a + $n;
        $c = $a;
    } else {
        $sum = $b + $n;
        $c = $b;
    }

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

echo " c=$c sum=$sum gcd=$gcd \n";
    if ($gcd <= $n) {
        $n -= $gcd;
        $flag = $flag ^ true;
    } else {
        break;
    }
}

if ($flag) {
    echo '1';
} else {
    echo '0';
}

?>

<?php
// 119A Эпическая игра

// Наибольший общий делитель НОД
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}

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

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

$flag = true;
while (true) {
    if ($flag) {
        $c = $a;
    } else {
        $c = $b;
    }

    $cc = max(abs($c), abs($n));
    $nn = min(abs($c), abs($n));

    $gcd = gcd ($cc, $nn);
echo "c=$c gcd=$gcd n=$n flag=$flag \n";
    if (($gcd <= $n) and ($n > 0)) {
        $n -= $gcd;
        $flag = $flag ^ true;
    } else {
        break;
    }
}

if ($flag) {
    echo '1';
} else {
    echo '0';
}

?>

<?php
// 119A Эпическая игра

// Наибольший общий делитель НОД
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}

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

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

$flag = true;
while (true) {
    if ($flag) {
        $sum = $a + $n;
        $c = $a;
    } else {
        $sum = $b + $n;
        $c = $b;
    }

    $gcd = gcd($с, $sum);

    if ($gcd <= $n) {
        $n -= $gcd;
        $flag = $flag ^ true;
    } else {
        break;
    }
}

if ($flag) {
    echo '1';
} else {
    echo '0';
}

?>

<?php
// 119A Эпическая игра

// Наибольший общий делитель НОД
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}

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

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

$flag = true;
while (true) {
    if ($flag) {
        $sum = $a + $n;
        $c = $a;
    } else {
        $sum = $b + $n;
        $c = $b;
    }

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

    if ($gcd <= $n) {
        $n -= $gcd;
        $flag = $flag ^ true;
    } else {
        break;
    }
}

if ($flag) {
    echo '1';
} else {
    echo '0';
}

?>