<?php

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

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

?>


<?php

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

$count_4=substr_count($number,"4");
$count_7=substr_count($number,"7");

//echo $count_4.",".$count_7;
if( ($count_4 + $count_7) == $length)
{
    $half= $length/2;
    $sum1=0;$sum2=0;

    for($loop=0;$loop<$half; $loop++)
    {//echo $number[$loop];
        $sum1+=(string)$number[$loop];
    }
    for($loop=$half;$loop<$length; $loop++)
        $sum2+=$number[$loop];
    if($sum1==$sum2)
        print("YES\n");
    else
     print ("NO\n");
//   echo $sum1.",.".$sum2;
}
else
print ("NO\n");

?>


<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_LEN = (int)$Scanner->Scan();
	$inp_N = $Scanner->Scan();
	$nums = str_split($inp_N);

	$LUCY = true;
	for ($i = 0; $i < $inp_LEN; $i++) {
		if ($nums[$i] !== '4' && $nums[$i] !== '7') {
			$LUCY = false;
			break;
		}
	}

	for ($i = 0; $i < $inp_LEN; $i++) {
		if ($i < $inp_LEN / 2) $first_sum += $nums[$i];
		elseif ($i >= $inp_LEN / 2) $second_sum += $nums[$i];
	}
	if ($first_sum !== $second_sum) $LUCY = false;

	if ($LUCY) print("YES");
	elseif (!$LUCY) print("NO");

	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

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

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

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

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

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

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

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

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

== function end ======
*/

?>


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

function readNumArray($f) {
	return readStringExplodeNum($f, ' ', true);
}

function readArray($f) {
	return readStringExplodeNum($f, ' ');
}

function readTrimString($f) {
	return trim(readString($f));
}

###### /IO ######
# for($i=0;$i<$n;$i++)

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	$first = readString($f);
	$second = readString($f);

	$dayCount = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	$days = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
	$firstIndex = array_search($first, $days);
	for ($m = 0; $m < 11; $m++) {
		$diff = $dayCount[$m] % 7;
		$next = ($firstIndex + $diff) % 7;
		if ($second == $days[$next]) {
			echo 'YES';
			return;
		}
	}
	echo 'NO';
	/* / end body */
}

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


<?php
    //$line = "8 6 4 5";
    //$line = "8 6 4 6";
    //$line = "10 3 11 4";
    //$line = "4 2 1 4";
    $line = readline();
    list($n, $t, $k, $d) = explode(' ', $line);

    $duration1 = ceil($n/$k)*$t;

    $times1 = floor($d/$t); //before build oven, how many times first oven makes cakes

    $t1 = $times1 * $t;
    $minutes1 = $d - $t1;

    $n2 = $n - $times1 * $k;

    $times2 = ceil($n2 / $k);

    if ($times2 % 2 == 0) {  //even
        $duration2 = $d + ceil($n2/($k*2))*$t;
    } else { //odd
        $duration2 = $d + ceil($n2/($k*2))*$t - $minutes1;
    }

    if ($duration2 < $duration1) {
        echo "Yes";
    } else {
        echo "No";
    }

    //echo "$line ---- $duration1, $duration2, -----  $minutes1, $t1, $n2, $times2";


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$a *= 4;
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     $e = ceil($c[$x] / 2);
     $d[$x] = $e;
}
$f = array_sum($d);
if($a == $b)
{
     $g = $b / 4;
     $h = $b * 2 - $g;
     $i = array_sum($c);
     if(($i <= $h) && ($c[0] < 3))
     {
          print "YES";
     }
     else
     {
          print "NO";
     }
}
else
{
     if($f <= $a)
     {
          print "YES";
     }
     else
     {
          print "NO";
     }
}
?>


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
$e = trim(fgets(STDIN));
$f = trim(fgets(STDIN));
$g = (min($a, $d) * $e) + (min(($d - min($a, $d)), $b, $c) * $f);
$h = (min($b, $c, $d) * $f) + (min($d - min($b, $c, $d), $a)* $e);
print max($g, $h);
?>


<?php
function solve()
{
    $server = "php://stdin";
    $local = "input.txt";
    $handle = fopen($server, "r");
    $t= trim(fgets($handle));
    $v = trim(fgets($handle));
    $c = trim(fgets($handle));
    $j = trim(fgets($handle));
    $s1 = trim(fgets($handle));
    $s2 = trim(fgets($handle));

    if($s2>=$s1)
    {
        $range=min($v,min($j,$c));
        $left=min($v,min($j,$c))*$s2;
        $right=min(($j-$range),$t)*$s1;
        echo $left+$right;
    }else
    {
        $range=min($j,$t);
        $left=$range*$s1;
        $right=min(($j-$range),min($v,min($j,$c)))*$s2;
        echo $left+$right;
    }

}

solve();
?>


<?php
$str=trim(fgets(STDIN));
$length=strlen($str);
if($length==1)
  echo "$str";
else
{

$fChar=(int)(ceil($length/2)-1);
$resultStr="";
$inc=$fChar;
$dec=$fChar;
$resultStr.=$str[$fChar];

for ($i=0; $i <$length-1 ; $i++)
{
	if($i%2==0)

		$resultStr.=$str[++$inc];
	else
		$resultStr.=$str[--$dec];
}
echo "$resultStr";
}


<?php

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

fscanf($stdin, "%d%d", $Ax, $Ay);
fscanf($stdin, "%d%d", $Bx, $By);
fscanf($stdin, "%d%d", $Cx, $Cy);

$Cx -= $Bx;
$Cy -= $By;
$Bx -= $Ax;
$By -= $Ay;

$a = $Bx*$Cy - $By*$Cx;

if ($a > 0)
{
    fwrite($stdout, "LEFT");
}
else if ($a < 0)
{
    fwrite($stdout, "RIGHT");
}
else
{
    fwrite($stdout, "TOWARDS");
}


<?php
$a = trim(fgets(STDIN));
$b = array(" ", "1");
unset($b[0]);
$c = 1;
for($x = 2; $x <= 100; $x++)
{
    $c += $x;
    array_push($b, $c);
    if($c >= 500)
    {
        break;
    }
}
$d = array_search($a, $b);
if($d == TRUE)
{
    print "YES";
}
else
{
    print "NO";
}
?>


<?php
error_reporting(0);
$input = file_get_contents("php://stdin");
$nums = array();
for($i=1;$i<=500;$i++) {
    $num = ($i*($i+1))/2;
    if($input == $num) {
        echo "YES";exit();
    }
    if($num > $input) {
        echo "NO";exit();
    }
}


<?php
list($a,$b)=explode(' ',trim(fgets(STDIN)));
function findtt($a,$b,&$out) {
	$out[]=$b;
	if($a>$b) return 0;
	if($b==$a) return $b;
	if($b%2==0) return findtt($a,$b/2,$out);
	if(strrpos($b,'1')==(strlen($b)-1)&&$b!=1) return findtt($a,(($b-1)/10),$out);
}
if(findtt($a,$b,$out)) echo("YES\n"); else exit("NO\n");
echo count($out)."\n".implode(' ',array_reverse($out))."\n";


<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	$n = readNum($f);
	$str = '';
	for ($i = 1; $i <= 1001; $i++) {
		$str.=$i;
	}
	echo $str[$n-1];
	/* / end body */
}

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


<?php
    $n = trim(fgets(STDIN));
    $a = explode(" ",trim(fgets(STDIN)));
    $sum = array_sum($a);
    if ($sum == 0)
    {
        echo("0");

    }
    else
    {
        $res = 1;
        $pre = -1;
        for ($i = 0 ; $i < $n ; $i ++)
        {
            if ($a[$i] == 1)
            {
                if ($pre != -1)
                {
                    $res *= $i - $pre;
                }
                $pre = $i ;
            }
        }

        echo(number_format($res,0,'',''));
    }

?>


<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/26  9:13
 */
//组合数学问题。
fscanf(STDIN,"%d",$n);
$bans = array();
$line = stream_get_line(STDIN,1000000,"\n");
$line = rtrim($line);//去除右边的换行符。
$bans = explode(" ",$line);

//var_dump($bans);
$result = 0;
$prev = -1;
//连续的的找1，只有出现1的时候才能产生新组合。
//遇到一个1，就是前面的1的方案数，乘上到这个1的区间切割方案，也就是posi - posi-1
for($i = 0 ; $i < $n;$i++){
    if($bans[$i] == 1){
        if($prev == -1){
            $result = 1;
        }else{
            $result *= $i - $prev;
        }
        $prev = $i;
    }
}
fprintf(STDOUT,"%.0f",$result);


<?php
$n = intval(fgets(STDIN)); //0 ≤ n < 1000000000

function soroban09($int)
{

    if ($int == 0) {
        $int = 'O-|-OOOO';
    }
    if ($int == 1) {
        $int = 'O-|O-OOO';
    }
    if ($int == 2) {
        $int = 'O-|OO-OO';
    }
    if ($int == 3) {
        $int = 'O-|OOO-O';
    }
    if ($int == 4) {
        $int = 'O-|OOOO-';
    }
    if ($int == 5) {
        $int = '-O|-OOOO';
    }
    if ($int == 6) {
        $int = '-O|O-OOO';
    }
    if ($int == 7) {
        $int = '-O|OO-OO';
    }
    if ($int == 8) {
        $int = '-O|OOO-O';
    }
    if ($int == 9) {
        $int = '-O|OOOO-';
    }
    return $int;

}

$n = intval($n);

if ($n < 0) {
    die('n must be positive integer value');
} elseif ($n >= 1000000000) {
    die('n must be <1000000000');
}

$n = array_reverse(array_map('intval', str_split($n)));

foreach ($n as $srb) {
    echo soroban09($srb) . "\n";
}


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


<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	$n = readNum($stream);
	$nums = readStringExplodeNum($stream, ' ', true);
	if ($n == 1) {
		$num = array_pop($nums);
		if ($num == 15) {
			echo 'DOWN';
		} elseif ($num == 0) {
			echo 'UP';
		} else {
			echo -1;
		}
	} else {

		$nums = array_slice($nums, count($nums) - 2);
		$isDec = true;
		if ($nums[0] < $nums[1]) {
			$isDec = false;
		}
		$nums[2] = $nums[1] + 1;
		if ($isDec && $nums[1] > 0) {
			$nums[2] = $nums[1] - 1;
		}
		if ($nums[2] > 15) {
			$nums[2] = $nums[1] - 1;
		}

		if ($nums[2] > $nums[1]) {
			echo 'UP';
		} else {
			echo 'DOWN';
		}
	}
	/* / end body */
}

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


<?php
$num=trim(fgets(STDIN));
for ($i=0; $i < $num; $i++) {
   $moon[]=explode(" ",trim(fgets(STDIN)));
    }
if ($num == 1 and $moon[0][$num - 1] != 15 and $moon[0][$num - 1] != 0) {
     echo "-1";
}elseif ($moon[0][$num - 1] == 15 or  $moon[0][$num - 1] < $moon[0][$num - 2] and $moon[0][$num - 1] != 0) {
    echo "DOWN";
}elseif ($moon[0][$num - 1] > $moon[0][$num - 2] or $moon[0][$num - 1] == 0) {
    echo "UP";
}else echo -1;
?>


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_unique($b);
sort($c);
if($c[0] == 0)
{
     print count($c) - 1;
}
else
{
     print count($c);
}
?>


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

$friends = array("Danil", "Olya", "Slava", "Ann", "Nikita");

$c = 0;
foreach($friends as $friend)
{
  $c += substr_count($in, $friend);

  if($c > 1)
  {
    break;
  }
}

echo ($c == 1) ? "YES" : "NO";


<?php
$str=trim(readline());
$names=array();
$names=[
	        "Danil",
	        "Olya",
	        "Slava",
	        "Ann",
	        "Nikita"
       ];
$count=0;
 for ($i=0; $i <count($names) ; $i++)
 {
 		$name=$names[$i];
 		$count+=substr_count($str,$name);
 			//$count++;

}
if($count==1)
  echo "YES";
  else
  echo "NO";


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


<?php

list($maxSections, $numberOfNuts, $numberOfDivisors, $sectionCapacity) = explode(" ", trim(fgets(STDIN)));

$numberOfBoxes = 1;
$divisorsInBox = 0;
$nutsInBox = 0;
while($numberOfNuts > 0)
{
	if($nutsInBox < $sectionCapacity)
	{
		++$nutsInBox;
		--$numberOfNuts;
		continue;
	}

	//echo "Reached section capacity at $nutsInBox" . PHP_EOL;

	if($divisorsInBox < ($maxSections - 1) && $numberOfDivisors > 0)
	{
		$nutsInBox = 0;

		++$divisorsInBox;
		--$numberOfDivisors;
		continue;
	}

	//echo "reached divisional capacity with $divisorsInBox" . PHP_EOL;

	++$numberOfBoxes;
	$divisorsInBox = 0;
	$nutsInBox = 0;
}

echo $numberOfBoxes . PHP_EOL;


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


<?PHP
$fileIN = fopen("php://stdin", "r");
$fileOUT = fopen("php://stdout", "w");

$line = trim(fgets($fileIN));
$line = explode(" ", $line);
$n = $line[0];
$k = $line[1];

$line = trim(fgets($fileIN));
$line = explode(" ", $line);

$a = array();

for ($i = 0; $i <= $n; ++$i) {
    $a[$i] = 0;
}

for ($i = 0; $i < $k; ++$i) {
    for ($j = $line[$i]; $j <= $n; ++$j) {
        if ($a[$j] == 0) {
            $a[$j] = $line[$i];
        }
    }
}

for ($i = 1; $i <= $n; ++$i) {
    fprintf($fileOUT, $a[$i] . " ");
}

fclose($fileIN);
fclose($fileOUT);
?>


<?php
define('LOCAL_ENV', false);
if (LOCAL_ENV) {
    error_reporting(E_ALL & !E_NOTICE);
    $test = <<<INPUT
5 4
4 3 1 2
INPUT;
    $stdin = fopen('php://temp/in', 'rw');
    fwrite($stdin, $test);
    rewind($stdin);
} else {
    error_reporting(0);
    $stdin = STDIN;
}
define('MY_STDIN', $stdin);

list($n,$m) = explode(' ', trim(fgets(MY_STDIN)));
$a = explode(' ', trim(fgets(MY_STDIN)));
$aa = array_fill(1, $n, 0);
foreach ($a as $k) {
    for ($i = $k; $i <= $n; $i++) {
        if ($aa[$i] == 0) {
            $aa[$i] = $k;
        }
    }
}
echo join(' ', $aa);


<?php
$x = trim(fgets(STDIN));
switch ($x % 4) {
    case 0:
        echo '1 A';
        break;
    case 1:
        echo '0 A';
        break;
    case 2:
        echo '1 B';
        break;
    case 3:
        echo '2 A';
        break;
}


<?php
    $n = trim(fgets(STDIN));
    $i = $n % 4;
    if($i == 0) {
        echo "1 A";
    } else if($i == 1) {
        echo "0 A";
    } else if($i == 2) {
        echo "1 B";
    } else {
        echo "2 A";
    }

 ?>


<?php

error_reporting(0);

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

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

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

$k=$explode[0];
$a=$explode[1];
$b=$explode[2];

$max = max($a,$b);
$min = min($a,$b);

$set1 = $max/$k;
$set2 = $min/$k;

$sum = intval($set1)+intval($set2);

$sum+=0;

$resto1=$max%$k;
$resto2=$min%$k;

if($resto1!=0 && $max>=$k) {

	if($min >= $k) {

		echo $sum;
		die();

	}

}

else if(($resto1==0) && ($max>=$k)) {
	echo $sum; die(); }

	// var_dump($resto1==0,$max>=$k);

echo "-1";

?>


<?php
$a = trim(fgets(STDIN));
if($a[0] == "9")
{
     $b = strlen($a);
     $c = array_fill(0, $b, 0);
     $d = 1 . implode($c);
     print $d - $a;
}
else
{
     $b = strlen($a) - 1;
     $c = array_fill(0, $b, 0);
     $d = ($a[0] + 1) . implode($c);
     print $d - $a;
}
?>


<?php
# 1155A
$start = microtime(1);
$types = [0, 1, 2, 0, 2, 1, 0];
$input = fopen('php://stdin', 'rb');
[$fish, $rabbit, $chicken] = explode(' ', fgets($input));
$fish = (int) $fish;
$rabbit = (int) $rabbit;
$chicken = (int) $chicken;
$daysResult = [];
$weeks = min([
    (int)floor($fish / 3),
    (int)floor($rabbit / 2),
    (int)floor($chicken / 2),
]);

$fish -= $weeks * 3;
$rabbit -= $weeks * 2;
$chicken -= $weeks * 2;

for ($i = 0; $i < 7; $i++) {
    $backpack = [$fish, $rabbit, $chicken];
    $days = 0;
    for ($j = $i; true; $j++) {
        $type = $types[$j % 7];
        if ($backpack[$type] === 0) {
            break;
        }
        $backpack[$type]--;
        $days++;
    }
    $daysResult[$i] = $days;
}
echo $weeks * 7 + max($daysResult);


<?php

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

$tam = strlen($neck);

$perl = 0; $link = 0;
for($i  = 0; $i < $tam; $i++){
    if($neck[$i] === 'o'){
        $perl++;
    }else if($neck[$i] ==='-'){
        $link++;
    }
}

if($link === 0 || $perl === 0){
    die('YES');
}else {
    $result = $link % $perl;
    if (!$result) die("YES");
    die("NO");
}


<?php

function canRejoin($str)
{
    $links  = 0;
    $pearls = 0;
    foreach (str_split($str, 1) as $ch){
        if($ch === '-'){
            $links++;
        }
        elseif($ch === 'o'){
            $pearls++;
        }
    }
    if(intval($pearls) === 0) return true;
    return intval($links) % intval($pearls) == 0;
}

function main()
{
    $str = fread(STDIN, 4096);
    echo canRejoin($str)? 'YES':'NO';
}

main();


<?php
fscanf(STDIN, "%s", $str);
echo preg_match_all("/(C{1,5})|(P{1,5})/", $str, $matchesarray);


   <?php
fscanf(STDIN, "%s", $str);
echo preg_match_all("/(C{1,5})|(P{1,5})/", $str, $matchesarray);


<?php
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
list($start, $end) = explode(" ", $line);
$start = trim($start);
$end = trim($end);

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

$clockwise_stats = ["^",">","v", "<"];
$counter_clockwise_stats = array_reverse($clockwise_stats);

$is_cw  = false;
$is_ccw = false;

$mod = $n%4;
$start_pos = array_search($start, $clockwise_stats);
if($start_pos!==false){
    	$end_pos = ($start_pos+$mod)%4;
	if($end == $clockwise_stats[$end_pos]){
	   $is_cw = true;
	}
}

$start_pos_ccw = array_search($start, $counter_clockwise_stats);
if($start_pos_ccw!==false){

	$end_pos_ccw = ($start_pos_ccw + $mod)%4;
	if($end == $counter_clockwise_stats[$end_pos_ccw]){
	   $is_ccw = true;
	}
}

if($is_cw && $is_ccw)
{
  echo "undefined";
}elseif($is_cw){
  echo "cw";
}elseif($is_ccw){
  echo "ccw";
}else{
  echo "undefined";
}


<?php

$batch = readline();
for($a = 0;$a < $batch; $a++){

    $serial_info = readline();

    $serial_info_array = explode(' ', $serial_info);
    $n = $serial_info_array[0];
    $k = $serial_info_array[1];
    $d = $serial_info_array[2];

    $serial_data = readline();

    $serial_array = explode(' ', $serial_data);

    $min = $k;

    for($day = 0; $day <= $n - $d; $day++){
        $sub = array_slice($serial_array, $day, $d);
        $unique_count = count(array_unique($sub));
        if($unique_count < $min){
            $min = $unique_count;
        }
    }

    print_r($min);
    if($a+1 != $batch){
         print_r(PHP_EOL);
    }
}

return 0;


<?php
$a = trim(fgets(STDIN));
$b = str_split(trim(fgets(STDIN)));
$c = str_split(trim(fgets(STDIN)));
$d = str_split(trim(fgets(STDIN)));
$e = str_split(trim(fgets(STDIN)));
$f = array_merge($b, $c, $d, $e);
$g = $a * 2;
$i = array();
for($x = 0; $x < count($f); $x++)
{
    $h = 1;
    for($y = 0; $y < count($f); $y++)
    {
        if($x == $y)
        {
            continue;
        }
        else
        {
            if(($f[$x] == $f[$y]) && ($f[$x] != "."))
            {
                $h++;
            }
        }
    }
    array_push($i, $h);
}
rsort($i);
if($i[0] > $g)
{
    print "NO";
}
else
{
    print "YES";
}
?>


<?php
    $line = trim(fgets(STDIN));
    $arr = str_split($line);
    $cons = array();
    $ptr = 0;

    for($i=0; $i<sizeof($arr); $i++)
    {
        if($arr[$i]!='!')
            $cons[$ptr] = $arr[$i];
        $ptr++;
        if($ptr==4)
            $ptr=0;
    }
    $buffer = array();
    for($i=0; $i<4; $i++)
        array_push($buffer, $cons[$i]);
    unset($cons);
    $cons = implode('', $buffer);
    $cnt = array();
    for($i=0; $i<strlen($line); $i++)
    {
        if($line[$i]=='!')
            $cnt[$i%4]++;
        if(!$cnt[$i%4])
            $cnt[$i%4]=0;
    }
    $vals = array(
        'R' => 0,
        'B' => 0,
        'Y' => 0,
        'G' => 0
        );

    for($i=0; $i<4; $i++)
        $vals[$cons[$i]] = $cnt[$i];

    foreach($vals as $x)
        echo $x . " ";
?>


<?php

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

$dead=array(0,0,0,0);

$sequence=array("_","_","_","_");

$i=0;

while (FALSE !== ($char = fgetc($f))) {

    if(($char!='!') && ($sequence[$i]=="_")) {

        $sequence[$i]=$char;

    }

    else if($char=='!') {
        $dead[$i]+=1;

    }

    $i++;

    $i = $i == 4 ? 0 : $i;

}

$deadByColors = array ($sequence[0] => $dead[0]
                       ,$sequence[1] => $dead[1]
                       ,$sequence[2] => $dead[2]
                       ,$sequence[3] => $dead[3]);

fclose($f);

echo $deadByColors["R"]." ".$deadByColors["B"]." ".$deadByColors["Y"]." ".$deadByColors["G"];


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


<?php
list($a, $b, $c, $d, $e) = explode(" ", trim(fgets(STDIN)));
$f = 1;
$g = $b;
if($g >= $a)
{
     print $f;
}
else
{
     while(TRUE)
     {
          $g += min($c - $e, $b + ($f * $d) - $e);
          $f++;
          if($g >= $a)
          {
               break;
          }
     }
     print $f;
}
?>


<?php

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

$moves = 0;

if (abs($pos - $l) < abs($r - $pos)) {
    if ($l != 1) {
        $moves += abs($pos - $l) + 1;
        $pos = $l;
    }

    if ($r != $n) {
        $moves += abs($r - $pos) + 1;
    }
} else {
    if ($r != $n) {
        $moves += abs($r - $pos) + 1;
        $pos = $r;
    }

    if ($l != 1) {
        $moves += abs($pos - $l) + 1;
    }
}

echo $moves;


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e, $f) = explode(" ", trim(fgets(STDIN)));
if(($a != $d) && ($b != $e) && ($c != $f))
{
    print "NO";
}
else
{
    print "YES";
}
?>


<?php
/*
By Tianyi Chen
*/
$s;$ans=0;$ci=0;$cj=0;
fscanf(STDIN,"%d",$len);
fscanf(STDIN,"%s",$str);
++$s[0][0];
for($i=0;$i<$len;++$i){
    switch($str[$i]){
        case 'L':--$ci;break;
        case 'R':++$ci;break;
        case 'U':++$cj;break;
        case 'D':--$cj;
    };
    $ans+=$s[$ci][$cj];
    ++$s[$ci][$cj];
}
print($ans);


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

$n = trim(fgets(STDIN)) + 0;
echo calc($n);

function calc($n){
	if($n == 1){
		return 1;
	} else {

		$check = function($div){
			$s = floor(sqrt($div));
			for($j = 2; $j <= $s; $j++){
				if(fmod($div, $j) == 0){
					return false;
				}
			}
			return true;
		};
		$primeDivs = [];

		$s = floor(sqrt($n));
		for($div = 2; $div <= $s; $div++){
			if(fmod($n, $div) == 0) {
				if ($check($div)){
					$primeDivs[] = $div;
					if(count($primeDivs) == 2) {break;}
				}
				$div2 = $n / $div;
				if ($div2 != $div && $check($div2)){
					$primeDivs[] = $div2;
					if(count($primeDivs) == 2) {break;}
				}
			}
		}
		// echo "\n".$n.' ['.implode(' ', $primeDivs).'] ';
	}
	if(count($primeDivs) == 0){
		return $n;
	} else if(count($primeDivs) == 1){
		return $primeDivs[0];
	} else {
		return 1;
	}
}


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

$data=trim(fgets($h));
$data_arr=explode(' ', $data);
$n=$data_arr[0];
$k=$data_arr[1];

$mess=0;
$rem=$n;

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

    if($i>=$n-$i+1) {
        break;
    }

    $mess+=2*($rem-1)-1;
    $rem=$rem-2;

}

echo $mess;


<?php
$powers = [];
for($i = 1; $i <= 8; ++$i) {
	$powers[] = pow(7, $i);
}
function set_bits($n, $dn, &$a) {
	if ($n == 0) {
		$a[0] += $dn;
		return ($a[0] < 2);
	}
	global $powers;
	$i = 0;
	for($i = 0; $i < $dn; ++$i) {
		$d = $n%7;
		//echo "$n%$powers[$i] = $d\n";
		if (++$a[$d] > 1) {
			return false;
		}
		$n = floor($n/7);
	}
	return true;
}

$fp = fopen('php://stdin', 'r');
list($n, $m) = array_map('intval', explode(' ', fgets($fp)));
$dn = max(1, ceil(log($n, 7)));
$dm = max(1, ceil(log($m, 7)));
if ($dn + $dm > 7) {
	die('0');
}

$zeros = array_fill(0, 7, 0);

$result = 0;
for($i = 0; $i < $n; ++$i) {
	$bits = $zeros;
	if (!set_bits($i, $dn, $bits)) {
		continue;
	}
	for($j = 0; $j < $m; ++$j) {
		$bits2 = $bits;
		if (set_bits($j, $dm, $bits2)) {
			++$result;
		}
		//echo "$i:$j ".implode(' ', $bits2)."\n";
	}
}
echo $result;


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


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = 0;
while(TRUE)
{
     $d = round(array_sum($b) / $a);
     if($d == 5)
     {
          break;
     }
     else
     {
          $b[$c] = 5;
          $c++;
     }
}
print $c;
?>


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


<?php
$a = str_split(trim(fgets(STDIN)));
for($x = 0; $x < count($a); $x++)
{
     if($a[$x] == ".")
     {
          $b = array_slice($a, 0, $x);
          $c = array_slice($a, $x + 1);
          break;
     }
}
for($x = 0; $x < count($c); $x++)
{
     if($c[$x] == "e")
     {
          $d = array_slice($c, 0, $x);
          $e = array_slice($c, $x + 1);
     }
}
$f = implode($e);
if(count($d) < $f)
{
     $g = $f - count($d);
     for($x = 1; $x <= $g; $x++)
     {
          array_push($d, 0);
     }
     $h = array_merge($b, $d);
     $i = count($h);
     for($x = 0; $x < $i; $x++)
     {
          if($h[$x] == 0)
          {
               unset($h[$x]);
          }
          else
          {
               break;
          }
     }
     print implode($h);
}
elseif(count($d) == $f)
{
     $g = array_merge($b, $d);
     $h = count($g);
     for($x = 0; $x < $h; $x++)
     {
          if($g[$x] == 0)
          {
               unset($g[$x]);
          }
          else
          {
               break;
          }
     }
     print implode($g);
}
elseif(count($d) > $f)
{
     $g = array_slice($d, 0, $f);
     $h = array_slice($d, $f);
     $i = array_merge($b, $g);
     $h2 = array_unique($h);
     sort($h2);
     if((count($h2) == 1) && ($h2[0] == 0))
     {
          $j = $i;
          if(count($j) == 1)
          {
               print implode($j);
          }
          else
          {
               $k = count($j);
               for($x = 0; $x < $k; $x++)
               {
                    if($j[$x] == 0)
                    {
                         unset($j[$x]);
                    }
                    else
                    {
                         break;
                    }
               }
               print implode($j);
          }
     }
     else
     {
          array_push($i, ".");
          $j = array_merge($i, $h);
          if($j[1] == ".")
          {
               print implode($j);
          }
          else
          {
               $k = count($j);
               for($x = 0; $x < $k; $x++)
               {
                    if($j[$x] == 0)
                    {
                         unset($j[$x]);
                    }
                    else
                    {
                         break;
                    }
               }
               print implode($j);
          }
     }
}
?>


<?php
// define('DEBUG', true);
define('DEBUG', false);

ini_set('error_reporting', E_ALL & ~E_NOTICE);

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

$array = array();
$prev = null;
$string = "";
$bool = false;

for ($i = 0; $i < strlen($s); $i++) {
	$cd = ord($s[$i]) - 96;
	$array[$cd] = 1;
}
ksort($array);

if (DEBUG) {
	var_dump($array);
}

foreach ($array as $key => $val) {
	if (DEBUG) {
		echo $prev + 1 . "-" . $key . "\n";
	}

	if (is_null($prev) || $prev + 1 < $key) {
		$prev = $key;
		$answer += $key;
		$string .= chr($key + 96);
		if (strlen($string) === $k) {
			$bool = true;
			break;
		}
	}
	if (DEBUG) {
		echo $string . PHP_EOL;
	}

}

if ($bool === false) {
	echo "-1";
} else {
	if (DEBUG) {
		echo $string . PHP_EOL;
	}

	echo $answer;
}


<?php
list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
$e = explode(" ", trim(fgets(STDIN)));
$j = $e;
sort($j);
array_unshift($e, " ");
unset($e[0]);
$f = array_search($c, $e);
$g = array_search($d, $e);
$h = $a - $b;
$i = 0;
if($f == TRUE)
{
    $i++;
}
if($g == TRUE)
{
    $i++;
}
$i += $h;
if(($i >= 2) && ($j[0] >= $c) && ($j[count($j) - 1] <= $d))
{
    print "Correct";
}
else
{
    print "Incorrect";
}
?>


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


<?php
/** chaotic_iak's solution in PHP 5.4 to the problem 322B (Round 190 Div 2 Problem B) 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();
$r = $raw[0];
$g = $raw[1];
$b = $raw[2];

$min = ($r < $g) ? $r : $g;
$min = ($min < $b) ? $min : $b;

$r -= $min;
$g -= $min;
$b -= $min;
$res = $min;
$max = 0;

for ($i = 0; $i < 3; $i++) {
	$r += $i;
	$g += $i;
	$b += $i;
	if ($res >= $i) {$res += (($r - ($r % 3)) / 3) + (($g - ($g % 3)) / 3) + (($b - ($b % 3)) / 3) - $i;}
	$max = ($max < $res) ? $res : $max;
	$res = $min;
	$r -= $i;
	$g -= $i;
	$b -= $i;
}

echo $max;


<?php
$a = trim(fgets(STDIN));
if(strlen($a) == 1)
{
     print $a;
}
else
{
     $b = strlen($a) - 1;
     $c = implode(array_fill(0, $b, 9));
     $d = $a - $c;
     $e = str_split($d);
     $f = $b * 9 + array_sum($e);
     print $f;
}
?>


<?php
	$a = (int)fgets(STDIN) - 1;
	$one = fgets(STDIN);
	$b = [];
	$c = [];
	$d = explode(' ', $one);

	while ($a >= 0) {
		if ($d[$a] >= 0) {
			array_push($b, $d[$a]);
		} else {
			array_push($c, $d[$a]);
		}
		$a--;
	}
	echo (array_sum($b) - array_sum($c));
?>


<?php
$STDIN = fopen('./data.txt', 'r');
define('STDIN', $STDIN);
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
function gcd($a, $b) {
  if ($b != 0) {
    return gcd($b, $a % $b);
  }
  return $a;
}
$ans = 1;
foreach ($arr as $key => $val) {
  $cont = 1;
  $temp = $val;
  while ($temp != ($key + 1)) {
    ++$cont;
    if ($cont > 100) {
      exit('-1');
    }
    $temp = $arr[$temp - 1];
  }
  if ($cont % 2 == 0) {
    $cont /= 2;
  }
  $ans = $ans * $cont / gcd($ans, $cont);
}
echo $ans;
?>


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


<?php

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

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

$a = [];

$c = 0;

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

$a = array_unique($a);

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


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

fscanf(STDIN, "%d %d", $n, $B);
$a = explode(" ", trim(fgets(STDIN)));
$sum = array();
$cost = array();
for ($i = 0; $i < $n - 1; $i++) {
    $sum[$a[$i] % 2]++;
    if ($sum[0] == $sum[1]) {
        $cost[] = abs($a[$i+1] - $a[$i]);
    }
}
sort($cost);
$ans = 0;
while (count($cost) > 0) {
    $x = array_shift($cost);
    $B -= $x;
    if ($B >= 0) {
        $ans++;
    } else {
        break;
    }
}
echo $ans;


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = 0;
while(TRUE)
{
     $c++;
     sort($b);
     $d = count($b);
     $e = $b[0];
     unset($b[0]);
     for($x = 1; $x < $d; $x++)
     {
          if($b[$x] % $e == 0)
          {
               unset($b[$x]);
          }
     }
     if(count($b) == 0)
     {
          break;
     }
}
print $c;
?>