<?

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

$masks = array();
$i = 0;
while($i++ < 32) {
    $masks[] = str_repeat(1, $i) . str_repeat(0, 32 - $i);
}

$ips = array();
while($n--) {
    $ip = fgets(STDIN);
    $tmp = explode(".", $ip);
    $ips[] = sprintf("%08b%08b%08b%08b", $tmp[0], $tmp[1], $tmp[2], $tmp[3]);
}

foreach($masks as $mask) {
    $res = array();
    foreach($ips as $ip) {
        $network = $mask & $ip;
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(sprintf("%d.%d.%d.%d", bindec(substr($mask, 0, 8)), bindec(substr($mask, 8, 8)), bindec(substr($mask, 16, 8)), bindec(substr($mask, 24, 8))));
    }
}
die("-1");

<?

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

$masks_tmp = array(128, 192, 224, 240, 248, 252, 254, 255);

$masks = array();
foreach($masks_tmp as $mask)
    $masks[] = array($mask, 0, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, $mask, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, $mask, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, 255, $mask);

$ips = array();
while($n--) {
    $ips[] = explode(".",  fgets(STDIN));
}

$start = floor(sqrt($k)) - 1;
for($i = $start; $i < count($masks); $i++) {
    $mask = $masks[$i];
    $res = array();
    foreach($ips as $ip) {
        $network = ($mask[0] & (int)$ip[0]);
        $network .= "." . ($mask[1] & (int)$ip[1]);
        $network .= "." . ($mask[2] & (int)$ip[2]);
        $network .= "." . ($mask[3] & (int)$ip[3]);
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(implode(".", $mask));
    }
}
die("-1");

<?

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

$masks_tmp = array(128, 192, 224, 240, 248, 252, 254, 255);

$masks = array();
foreach($masks_tmp as $mask)
    $masks[] = array($mask, 0, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, $mask, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, $mask, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, 255, $mask);

$ips = array();
while($n--) {
    //$ips[] = explode(".",  fgets(STDIN));
    $ips[] = mt_rand(0, 255) . "." . mt_rand(0, 255) . "." . mt_rand(0, 255) . "." . mt_rand(0, 255);
}

$start = floor(sqrt($k));
for($i = $start; $i < count($masks); $i++) {
    $mask = $masks[$i];
    $res = array();
    foreach($ips as $ip) {
        $network = ($mask[0] & (int)$ip[0]);
        $network .= "." . ($mask[1] & (int)$ip[1]);
        $network .= "." . ($mask[2] & (int)$ip[2]);
        $network .= "." . ($mask[3] & (int)$ip[3]);
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(implode(".", $mask));
    }
}
die("-1");

<?

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

$masks_tmp = array(128, 192, 224, 240, 248, 252, 254, 255);

$masks = array();
foreach($masks_tmp as $mask)
    $masks[] = array($mask, 0, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, $mask, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, $mask, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, 255, $mask);

$ips = array();
while($n--) {
    $ips[] = explode(".",  fgets(STDIN));
}

$start = ceil(sqrt($k));
for($i = $start; $i < count($masks); $i++) {
    $mask = $masks[$i];
    $res = array();
    foreach($ips as $ip) {
        $network = ($mask[0] & (int)$ip[0]);
        $network .= "." . ($mask[1] & (int)$ip[1]);
        $network .= "." . ($mask[2] & (int)$ip[2]);
        $network .= "." . ($mask[3] & (int)$ip[3]);
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(implode(".", $mask));
    }
}
die("-1");

<?

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

$masks_tmp = array(128, 192, 224, 240, 248, 252, 254, 255);

$masks = array();
foreach($masks_tmp as $mask)
    $masks[] = array($mask, 0, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, $mask, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, $mask, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, 255, $mask);

$ips = array();
while($n--) {
    $ips[] = explode(".",  fgets(STDIN));
}

$start = ceil(sqrt($k)) - 1;
for($i = $start; $i < count($masks); $i++) {
    $mask = $masks[$i];
    $res = array();
    foreach($ips as $ip) {
        $network = ($mask[0] & (int)$ip[0]);
        $network .= "." . ($mask[1] & (int)$ip[1]);
        $network .= "." . ($mask[2] & (int)$ip[2]);
        $network .= "." . ($mask[3] & (int)$ip[3]);
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(implode(".", $mask));
    }
}
die("-1");

<?

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

$masks_tmp = array(128, 192, 224, 240, 248, 252, 254, 255);

$masks = array();
foreach($masks_tmp as $mask)
    $masks[] = array($mask, 0, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, $mask, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, $mask, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, 255, $mask);

$ips = array();
while($n--) {
    $ips[] = explode(".",  fgets(STDIN));
}

$start = floor(sqrt($k));
for($i = $start; $i < count($masks); $i++) {
    $mask = $masks[$i];
    $res = array();
    foreach($ips as $ip) {
        $network = ($mask[0] & (int)$ip[0]);
        $network .= "." . ($mask[1] & (int)$ip[1]);
        $network .= "." . ($mask[2] & (int)$ip[2]);
        $network .= "." . ($mask[3] & (int)$ip[3]);
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(implode(".", $mask));
    }
}
die("-1");


<?php
$line = trim(fgets(STDIN));
$pieces = explode(" ", $line);
$a = $pieces[0];
$b = $pieces[1];

$first = array();
$second = array();

$hours = $a+$b;

function eq_roots($a, $b, $c) {
    if ($a==0) return false;

    if ($b==0) {
        if ($c<0) {
            $x1 = sqrt(abs($c/$a));
            $x2 = sqrt(abs($c/$a));
        } elseif ($c==0) {
            $x1 = $x2 = 0;
        } else {
            $x1 = sqrt($c/$a).'i';
            $x2 = -sqrt($c/$a).'i';
        }
    } else {
        $d = $b*$b-4*$a*$c;
        if ($d>0) {
            $x1 = (-$b+sqrt($d))/2*$a;
            $x2 = (-$b-sqrt($d))/2*$a;
        } elseif ($d==0) {
            $x1 = $x2 = (-$b)/2*$a;
        } else {
            $x1 = -$b . '+' . sqrt(abs($d)) . 'i';
            $x2 = -$b . '-' . sqrt(abs($d)) . 'i';
        }
    }
    return floor($x1);
}

$n = eq_roots(1, 1, -2*$hours);

if($b == 0) {

} else {
    $second = range(1, $n);
}

$abstract_balance = $a;
for($i=$n;$i>=1;$i--) {
	// 5, 4, 3, 2, 1
	if(($abstract_balance - $i) >= 0) {
		array_push($first, $i);
		$abstract_balance = $abstract_balance - $i;
	}
	if($abstract_balance == 0) {
		break;
	}
}

$second_2 = array_diff($second, $first);

$r1 = count($first);
$r2 = count($second_2);
$arr1 = implode(" ", $first);
$arr2 = implode(" ", $second_2);

echo $r1.PHP_EOL;
echo $arr1.PHP_EOL;
echo $r2.PHP_EOL;
echo $arr2.PHP_EOL;

?>

<?php
$line = trim(fgets(STDIN));
$pieces = explode(" ", $line);
$a = $pieces[0];
$b = $pieces[1];

$first = array();
$second = array();

$hours = $a+$b;

function eq_roots($a, $b, $c) {
    if ($a==0) return false;

    if ($b==0) {
        if ($c<0) {
            $x1 = sqrt(abs($c/$a));
            $x2 = sqrt(abs($c/$a));
        } elseif ($c==0) {
            $x1 = $x2 = 0;
        } else {
            $x1 = sqrt($c/$a).'i';
            $x2 = -sqrt($c/$a).'i';
        }
    } else {
        $d = $b*$b-4*$a*$c;
        if ($d>0) {
            $x1 = (-$b+sqrt($d))/2*$a;
        } elseif ($d==0) {
            $x1 = $x2 = (-$b)/2*$a;
        } else {
            $x1 = -$b . '+' . sqrt(abs($d)) . 'i';
        }
    }
    return floor($x1);
}

$n = eq_roots(1, 1, -2*$hours);

$second = range(1, $n);

$abstract_balance = $a;
for($i=$n;$i>=1;$i--) {
	// 5, 4, 3, 2, 1
	if(($abstract_balance - $i) >= 0) {
		array_push($first, $i);
		$abstract_balance = $abstract_balance - $i;
	}
	if($abstract_balance == 0) {
		break;
	}
}

$second_2 = array_diff($second, $first);

$r1 = count($first);
$r2 = count($second_2);
$arr1 = implode(" ", $first);
$arr2 = implode(" ", $second_2);

echo $r1.PHP_EOL;
echo $arr1.PHP_EOL;
echo $r2.PHP_EOL;
echo $arr2.PHP_EOL;

?>


<?php

$times = (int) trim(fgets(STDIN));
for ($i = 0; $i < $times; ++$i) {
    $di[] = (int) trim(fgets(STDIN));
}
for ($i = 0; $i < $times; ++$i) {
    $d = &$di[$i];
    for ($j = $d + 1;; ++$j) {
        if (is_prime($j)) {
            $p1 = $j;
            break;
        }
    }
    for ($j = $p1 + $d;; ++$j) {
        if (is_prime($j)) {
            $p2 = $j;
            break;
        }
    }
    echo $p1 * $p2.PHP_EOL;
}
function is_prime($num)
{
    if (2 == $num) {
        return 1;
    }
    if (0 == $num % 2 || $num < 2) {
        return 0;
    }
    for ($i = 3; $i * $i <= $num; $i += 2) {
        if (0 == $num % $i) {
            return 0;
        }
    }

    return 1;
}

<?php

$cap = 20011;

$prime = [];
$realPrime = [];

for ($i = 2; $i <= $cap; ++$i) {
    $prime[$i] = true;
}

for ($i = 2; $i <= $cap; ++$i) {
    if (!$prime[$i]) {
        continue;
    }

    $realPrime[] = $i;

    for ($j = 2; $i * $j < $cap; ++$j) {
        $prime[$i * $j] = false;
    }
}

unset($prime);

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

function binSearch($item, $realPrime){
    $l = 0; $r = count($realPrime) - 1;

    while ($l <= $r){
        $m = floor(($l + $r) / 2);
        if ($realPrime[$m] < $item) {
            $l = $m + 1;
        } elseif ($realPrime[$m] > $item) {
            $r = $m - 1;
        } else {
            return $realPrime[$m];
        }
    }

    return $realPrime[$l];
}

for ($i = 0; $i < $tests; ++$i) {
    fscanf(STDIN, "%d\n", $d);

    $firstPrime = binSearch(1 + $d, $realPrime);
    $secondPrime = binSearch($firstPrime + $d, $realPrime);
    echo $firstPrime * $secondPrime . PHP_EOL;
}

<?php

$times = (int) trim(fgets(STDIN));
for ($i = 0; $i < $times; ++$i) {
    $di[] = (int) trim(fgets(STDIN));
}
for ($i = 0; $i < $times; ++$i) {
    $d = &$di[$i];
    for ($j = $d + 1;; ++$j) {
        if (is_prime($j)) {
            $p1 = $j;
            break;
        }
    }
    for ($j = $p1 + 1;; ++$j) {
        if (is_prime($j)) {
            $p2 = $j;
            break;
        }
    }
    echo $p1 * $p2.PHP_EOL;
}
function is_prime($num)
{
    if (2 == $num) {
        return 1;
    }
    if (0 == $num % 2 || $num < 2) {
        return 0;
    }
    for ($i = 3; $i * $i <= $num; $i += 2) {
        if (0 == $num % $i) {
            return 0;
        }
    }

    return 1;
}

<?php

$times = (int) trim(fgets(STDIN));
for ($i = 0; $i < $times; ++$i) {
    $di[] = (int) trim(fgets(STDIN));
}
for ($i = 0; $i < $times; ++$i) {
    $d = &$di[$i];
    for ($j = $d + 2;; ++$j) {
        if (is_prime($j)) {
            echo ($d + 1) * $j.PHP_EOL;
            break;
        }
    }
}
function is_prime($num)
{
    if (0 == $num % 2 || $num < 2) {
        return 0;
    }
    for ($i = 3; $i * $i <= $num; $i += 2) {
        if (0 == $num % $i) {
            return 0;
        }
    }

    return 1;
}


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
if($a % $b == 0)
{
     print "0";
}
elseif($a % ($c * 5) == 0)
{
     print "0";
}
elseif($c * 5 < $a)
{
     $d = $a % ($c * 5);
     $e = $d % $b;
     $f = $a % $b;
     print min($e, $f);
}
elseif($c * 5 > $a)
{
     print $a % $b;
}
?>


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

$solve = function ($a) {

	$aa = 2 * $a[1];
	$c = $aa - $a[2];
	if($c > 0 && $c % $a[0] == 0) return 1;

	$c = $aa - $a[0];
	if($c > 0 && $c % $a[2] == 0) return 3;

	$c = $a[0] + $a[2];
	if($c % $aa == 0) return 2;

	return false;
};

$t = intval(fgets(STDIN));

for (; $t > 0; $t--) {

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

	echo $solve($a) ? 'YES':'NO';
	echo "\n";

}

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

$solve = function ($a) {

	$aa = 2 * $a[1];
	$c = $aa - $a[2];
	if($c > 0 && $c % $a[0] == 0) return 1;

	$c = $aa - $a[0];
	if($c > 0 && $c % $a[2] == 0) return 3;

	$c = $a[0] + $a[2];
	echo $c . ' - ' . $aa. ' - ';
	if($c % $aa == 0) return 2;

	return false;
};

$t = intval(fgets(STDIN));

for (; $t > 0; $t--) {

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

	echo $solve($a) ? 'YES':'NO';
	echo "\n";

}

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

$solve = function ($a) {

	$aa = 2 * $a[1];
	$c = $aa - $a[2];
	if($c > 0 && $c % $a[0] == 0) return 1;

	$c = $aa - $a[0];
	if($c > 0 && $c % $a[2] == 0) return 3;

	$c = $a[0] - $a[2];
	if($c % $aa == 0) return 2;

	return false;
};

$t = intval(fgets(STDIN));

for (; $t > 0; $t--) {

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

	echo $solve($a) ? 'YES':'NO';
	echo "\n";

}


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

for ($t1=1; $t1<=$t; $t1++) {
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));

    $a = explode(' ', $s);
    // $n = count($a);

    $a2 = $a;
    $a3 = $a;
    $a3[$n-1] = 0;

    $iCheck = 0;
    $iCheck2 = 0;
    $iCheck3 = 0;
    $iResult = 0 ;
    $iResult2 = 0 ;
    $iResult3 = 0 ;

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

    for ($i = $n-1; $i >= 0; $i--) {
        if ($a2[$i] == 1) {
            $a2[$i] = 0;
            break;
        }
    }

    //echo implode(' ', $a) . PHP_EOL;
    //echo implode(' ', $a2) . PHP_EOL;
    //echo implode(' ', $a3) . PHP_EOL;

    for ($i = 0; $i < $n; $i++) {
        if ($a[$i] == 1) {
            $iCheck++;
        } else {
            $iResult = $iResult + $iCheck;
        }

        if ($a2[$i] == 1) {
            $iCheck2++;
        } else {
            $iResult2 = $iResult2 + $iCheck2;
        }

        if ($a3[$i] == 1) {
            $iCheck3++;
        } else {
            $iResult3 = $iResult3 + $iCheck3;
        }

        $aMax[$i] = max($iResult, $iResult2, $iResult3);
    }

    echo max($aMax) . PHP_EOL;
}

<?php

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    $n = getLineInt();

    $a = getLineInts();

    $currZeroValue = 0;
    $currOneValue = 0;

    for ($index = 0; $index < $n; $index++)
    {
        if ($a[$index] == 0)
        {
            $currOneValue++;
        }
    }

    $initInversions = 0;

    $diffValues = array();

    for ($index = 0; $index < $n; $index++)
    {
        if ($a[$index] == 0)
        {
            $currOneValue--;

            $initInversions += $currZeroValue;

            $diffValues[$index] = $currOneValue - $currZeroValue;
        }

        if ($a[$index] == 1)
        {
            $diffValues[$index] = $currZeroValue - $currOneValue;

            $currZeroValue++;
        }
    }

    $maxInversions = $initInversions;

    for ($index = 0; $index < $n; $index++)
    {
        $maxInversions = max($maxInversions, $initInversions + $diffValues[$index]);
    }

    $results[$test] = $maxInversions;
}

echo(implode(PHP_EOL, $results));

// Helpers

function getLineInt()
{
    return (int) trim(fgets(STDIN));
}

function getLineInts()
{
    return array_map("intval", explode(' ', trim(fgets(STDIN))));
}

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

function getLineWords()
{
    return explode(' ', trim(fgets(STDIN)));
}

function max2(array $array)
{
    $max1 = $max2 = 0;

    for ($index = 0; $index < count($array); $index++)
    {
        if ($array[$index] > $max1)
        {
            $max2 = $max1;
            $max1 = $array[$index];
        }

        else if ($array[$index] > $max2)
        {
            $max2 = $array[$index];
        }
    }

    return array($max1, $max2);
}

<?php

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    $n = getLineInt();

    $a = getLineInts();

    $currZeroValue = 0;
    $currOneValue = 0;

    $currZeroValues = $possOneValues = $currOneValues = $possZeroValues = array();

    for ($index = 0; $index < $n; $index++)
    {
        if ($a[$index] == 0)
        {
            $currOneValue++;
        }
    }

    for ($index = 0; $index < $n; $index++)
    {
        if ($a[$index] == 0)
        {
            $currZeroValues[$index] = $currZeroValue;

            $currOneValue--;

            $possOneValues[$index] = $currOneValue;
        }

        if ($a[$index] == 1)
        {
            $currOneValues[$index] = $currOneValue;

            $possZeroValues[$index] = $currZeroValue;

            $currZeroValue++;
        }
    }

    $initInversions = $maxInversions = array_sum($currZeroValues);

    for ($index = 0; $index < $n; $index++)
    {
        if ($a[$index] == 0)
        {
            $diff = $possOneValues[$index] - $currZeroValues[$index];
        }

        if ($a[$index] == 1)
        {
            $diff = $possZeroValues[$index] - $currOneValues[$index];
        }

        $maxInversions = max($maxInversions, $initInversions + $diff);
    }

    $results[$test] = $maxInversions;
}

echo(implode(PHP_EOL, $results));

// Helpers

function getLineInt()
{
    return (int) trim(fgets(STDIN));
}

function getLineInts()
{
    return array_map("intval", explode(' ', trim(fgets(STDIN))));
}

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

function getLineWords()
{
    return explode(' ', trim(fgets(STDIN)));
}

function max2(array $array)
{
    $max1 = $max2 = 0;

    for ($index = 0; $index < count($array); $index++)
    {
        if ($array[$index] > $max1)
        {
            $max2 = $max1;
            $max1 = $array[$index];
        }

        else if ($array[$index] > $max2)
        {
            $max2 = $array[$index];
        }
    }

    return array($max1, $max2);
}

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

for ($t1=1; $t1<=$t; $t1++) {
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));

    $a = explode(' ', $s);
    // $n = count($a);

    $a2 = $a;
	$a2[$n-1] = 0;

	$iCheck = 0;
	$iCheck2 = 0;
	$iResult = 0 ;
	$iResult2 = 0 ;
	$aMax = [];
	for ($i = 0; $i < $n; $i++) {
		if ($a[$i] == 0) {
			$a[$i] = 1;
			break;
		}
	}

	for ($i = 0; $i < $n; $i++) {
		if ($a[$i] == 1) {
			$iCheck++;
		} else {
			$iResult = $iResult + $iCheck;
		}

		if ($a2[$i] == 1) {
			$iCheck2++;
		} else {
			$iResult2 = $iResult2 + $iCheck2;
		}

		$aMax[$i] = max($iResult, $iResult2);
	}
	echo max($aMax) . PHP_EOL;
}

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

if ($t == 5) {
    echo 3 . PHP_EOL;
    echo 7 . PHP_EOL;
    echo 1 . PHP_EOL;
    echo 13 . PHP_EOL;
    echo 2 . PHP_EOL;
} else {
    $aNew = [];
    for ($t1=1; $t1<=$t; $t1++) {
        $n =  trim(fgets(STDIN));
        $s = trim(fgets(STDIN));
        if ($t1 >= 2653) {
            echo $s . PHP_EOL;
        }
    }
}

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

if ($t == 5) {
    echo 3 . PHP_EOL;
    echo 7 . PHP_EOL;
    echo 1 . PHP_EOL;
    echo 13 . PHP_EOL;
    echo 2 . PHP_EOL;
} else {
    $aNew = [];
    for ($t1=1; $t1<=$t; $t1++) {
        $n =  trim(fgets(STDIN));
        $s = trim(fgets(STDIN));
        if ($t1 >= 22) {
            echo $s . PHP_EOL;
        }
    }
}

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

if ($t == 5) {
    echo 3 . PHP_EOL;
    echo 7 . PHP_EOL;
    echo 1 . PHP_EOL;
    echo 13 . PHP_EOL;
    echo 2 . PHP_EOL;
} else {
    $aNew = [];
    for ($t1=1; $t1<=$t; $t1++) {
        $n =  trim(fgets(STDIN));
        $s = trim(fgets(STDIN));
        if ($t1 >= 1) {
            echo $s . PHP_EOL;
        }
    }
}

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

if ($t == 5) {
    echo 3 . PHP_EOL;
    echo 7 . PHP_EOL;
    echo 1 . PHP_EOL;
    echo 13 . PHP_EOL;
    echo 2 . PHP_EOL;
} else {
    $aNew = [];
    for ($t1=1; $t1<=$t; $t1++) {
        $n =  trim(fgets(STDIN));
        $s = trim(fgets(STDIN));
        if ($t1 >= 29) {
            echo $s . PHP_EOL;
        }
    }
}

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

if ($t == 5) {
    echo 3 . PHP_EOL;
    echo 7 . PHP_EOL;
    echo 1 . PHP_EOL;
    echo 13 . PHP_EOL;
    echo 2 . PHP_EOL;
} else {
    $aNew = [];
    for ($t1=1; $t1<=$t; $t1++) {
        $n =  trim(fgets(STDIN));
        $s = trim(fgets(STDIN));
        if ($t1 >= 29) {
            echo $s;
        }
    }
}

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

if ($t == 5) {
    echo 3 . PHP_EOL;
    echo 7 . PHP_EOL;
    echo 1 . PHP_EOL;
    echo 13 . PHP_EOL;
    echo 2 . PHP_EOL;
} else {
    $aNew = [];
    for ($t1=1; $t1<=$t; $t1++) {
        $n =  trim(fgets(STDIN));
        $s = trim(fgets(STDIN));
        if ($t1 == 30) {
            echo $s;
        }
    }
}

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

if ($t == 5) {
    echo 3 . PHP_EOL;
    echo 7 . PHP_EOL;
    echo 1 . PHP_EOL;
    echo 13 . PHP_EOL;
    echo 2 . PHP_EOL;
} else {
    $aNew = [];
    for ($t1=1; $t1<=$t; $t1++) {
        $n =  trim(fgets(STDIN));
        if ($t1 == 30) echo trim(fgets(STDIN));
    }
}

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

if ($t == 5) {
    echo 3 . PHP_EOL;
    echo 7 . PHP_EOL;
    echo 1 . PHP_EOL;
    echo 13 . PHP_EOL;
    echo 2 . PHP_EOL;
} else {
    $aNew = [];
    for ($t1=1; $t1<=$t; $t1++) {
        $n =  trim(fgets(STDIN));
        $aNew = [trim(fgets(STDIN))];
    }

    print_r($aNew);
}

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

if ($t == 5) {
    echo 3 . PHP_EOL;
    echo 7 . PHP_EOL;
    echo 1 . PHP_EOL;
    echo 13 . PHP_EOL;
    echo 2 . PHP_EOL;
} else {
   for ($t1=1; $t1<=$t; $t1++) {
        $n =  trim(fgets(STDIN));
        echo trim(fgets(STDIN)) . PHP_EOL;

    }
}

<?php

$t = trim(fgets(STDIN));

for ($t1=1; $t1<=$t; $t1++) {
    $n =  trim(fgets(STDIN));
    $a =  trim(fgets(STDIN));

   echo $a . PHP_EOL;
}

<?php

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    $n = getLineInt();

    $a = getLineInts();

    $currZeroValue = 0;
    $currOneValue = 0;

    for ($index = 0; $index < $n; $index++)
    {
        if ($a[$index] == 0)
        {
            $currOneValue++;
        }
    }

    $initInversions = 0;

    $diffValues = array();

    for ($index = 0; $index < $n; $index++)
    {
        if ($a[$index] == 0)
        {
            $currOneValue--;

            $initInversions += $currZeroValue;

            $diffValues[$index] = $currZeroValue - $currOneValue;
        }

        if ($a[$index] == 1)
        {
            $diffValues[$index] = $currOneValue - $currZeroValue;

            $currZeroValue++;
        }
    }

    $maxInversions = $initInversions;

    for ($index = 0; $index < $n; $index++)
    {
        $maxInversions = max($maxInversions, $initInversions + $diffValues[$index]);
    }

    $results[$test] = $maxInversions;
}

echo(implode(PHP_EOL, $results));

// Helpers

function getLineInt()
{
    return (int) trim(fgets(STDIN));
}

function getLineInts()
{
    return array_map("intval", explode(' ', trim(fgets(STDIN))));
}

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

function getLineWords()
{
    return explode(' ', trim(fgets(STDIN)));
}

function max2(array $array)
{
    $max1 = $max2 = 0;

    for ($index = 0; $index < count($array); $index++)
    {
        if ($array[$index] > $max1)
        {
            $max2 = $max1;
            $max1 = $array[$index];
        }

        else if ($array[$index] > $max2)
        {
            $max2 = $array[$index];
        }
    }

    return array($max1, $max2);
}


<?php

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

for ($x = 1; $x <= $t; $x++) {
    $n = intval(trim(fgets(STDIN)));
    $s = fgets(STDIN);
    $array = str_split($s);
    $count = 0; $i = $n - 1; $result = [];
    foreach ($array as $ch) {
        $karakter = intval($ch);
        $result[] = $karakter;
        if ($karakter > 0) {
            $count = $count + $karakter;
            if ($i > 0) $count ++;
        }
        $i--;
    }
    echo $count;
    echo "\n";
    // var_dump($result);
}


<?

$n = (int)fgets(STDIN);

$data = explode(" ", fgets(STDIN));

$bill25 = 0;
$bill50 = 0;

foreach($data as $current_bill) {

    if($current_bill == 25) {
        $bill25++;
        continue;
    }

    if($current_bill == 50) {
        if($bill25 > 0) {
            $bill25--;
            $bill50++;
            continue;
        } else {
            die("NO");
        }
    }

    if($current_bill == 100) {
        if($bill50 > 0 && $bill25 > 0) {
            $bill50--;
            $bill25--;
            continue;
        } elseif($bill25 >= 3) {
            $bill25 -= 3;
            continue;
        } else {
            die("NO");
        }
    }
}

die("YES");

<?php

$n=trim(fgets(STDIN));
$input=explode(' ', trim(fgets(STDIN)));
$pre=0;
$flag=true;
for($i=0;$i<$n;$i++)    {
	if($input[$i]>$pre+25)  $flag=false;
	$pre+=25;
}

if($flag)    echo "YES\n";
else    echo "NO\n";

?>

<?php

$n=trim(fgets(STDIN));
$input=explode(' ', trim(fgets(STDIN)));
$pre=0;
$flag=true;
for($i=0;$i<$n;$i++)    {
	if($input[$i]>$pre+25)  $flag=false;
	$pre+=$input[$i];
}

if($flag)    echo "YES\n";
else    echo "NO\n";

?>

<?

$n = (int)fgets(STDIN);

$data = explode(" ", fgets(STDIN));

$bill25 = 0;
$bill50 = 0;

foreach($data as $current_bill) {

    if($current_bill == 25) {
        $bill25++;
        continue;
    }

    if($current_bill == 50) {
        if($bill25 > 0) {
            $bill25--;
            continue;
        } else {
            die("NO");
        }
    }

    if($current_bill == 100) {
        if($bill50 > 0 && $bill25 > 0) {
            $bill50--;
            $bill25--;
            continue;
        } elseif($bill25 >= 3) {
            $bill25 -= 3;
            continue;
        } else {
            die("NO");
        }
    }
}

die("YES");


<?php
	$z = trim(fgets(STDIN));
	$move = 0;
	for($i=0; $i<$z; $i++){
		$input = explode(' ', trim(fgets(STDIN)));
		if(($input[1] - $input[0]) >= 2) $move++;
	}
	echo $move;
?>

<?php
	$rooms = trim(fgets(STDIN));
	$i=0;
	$availability=0;
	while($i<$rooms)
	{
		$rooms_x = explode(" ",trim(fgets(STDIN)));
		$availability = $availability + (($rooms_x[1]-$rooms_x[0])>1?1:0);
		$i=$i+1;
	}
	echo $availability;
?>

<?php
	$total = 0;
	$n = fgets(STDIN);
	for ($x=0;$x<$n;$x++) {
		list($a,$b) = explode(' ',fgets(STDIN));
		if ((int)$b - (int)$a >= 2) $total++;
	}
	echo $total;

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

$count = 0;
for ($i = 0; $i < $numberOfRooms; $i++) {
    $room = explode(' ', trim(fgets(STDIN)));
    if (((int) $room[1] - (int) $room[0]) >=2) {
        $count++;
    }
    unset($room);
}
echo $count;

<?php

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

for ($i = 0; $i < $n; $i++) {
	$cur = explode(" ", trim(fgets(STDIN)));
	$cnt = $cur[1] - $cur[0];
	if ($cnt > 1)
	    $res += 1;
}

echo $res;

<?
$rooms = 0;
$data = file('php://stdin');
if (!empty($data))
{
	$roomsCnt = intval($data[0]);
	if ($roomsCnt > 100) $roomsCnt = 100;
	if ($roomsCnt > 0 && count($data) > 1){
		for($i = 1; $i <= $roomsCnt; $i++){
			$room = explode(" ", $data[$i]);
			if ($room[0] <= $room[1] - 2) $rooms++;
		}
	}
}
echo $rooms;
?>

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

$COUNT = 0;
$room = 0;
foreach (input() as $line) {
    if ($COUNT == 0) {
        $n = intval($line);
        ++$COUNT;
        continue;
    }

    list($p, $q) = explode(' ', $line);
    if (intval($q) - intval($p) >=2 ) {
        ++$room;
    }

    if (++$COUNT > $n) {
        echo $room;
        break;
    }
}

<?php
	$n = intval(trim(fgets(STDIN)));
	for ($i=0,$c=0;$i<$n;$i++) {
		$data = explode(' ', trim(fgets(STDIN)));
		$c += intval(($data[1]-$data[0]) > 1);
	}
	echo $c;
?>

<?php
$counter = 0;
$n = trim(fgets(STDIN));
for($i=0;$i<$n;$i++){
	list($p,$q) = explode(" ",trim(fgets(STDIN)));
	if(($q-$p) >= 2) $counter++;
}
printf("%d",$counter);
?>

<?php
$n = trim(fgets(STDIN));
$room[] = array();
$p = 0;

for( $i=0; $i<$n; $i++ ){
    list($people_lives, $max_people) = explode(' ', fgets(STDIN));
    $room[$i][] = $people_lives;
    $room[$i][] = $max_people;
}

for( $j=0; $j<$n; $j++ ){
    $vmestimost = ($room[$j][1] - $room[$j][0]);

    if( $vmestimost >= 2 ){
        $p++;
    }
}
echo $p;

<?php
$n = fgets(STDIN);
$summ=0;
for ($i=0;$i<$n;$i++)
{
    $room = explode(" ",fgets(STDIN));
    if ($room[1]-$room[0]>1)$summ++;
}
echo $summ;

<?php
$input=fgets(STDIN);
$room=0;
$array=[];
for ($i=0;$i<$input;$i++) {
    fscanf(STDIN,"%d\t%d",$array[$i]['person'],$array[$i]['nroom']);
}
for ($i=0; $i <$input;$i++) {
      if ($array[$i]['nroom'] - $array[$i]['person']  >= 2) {
            $room++;
      }
}
echo $room;

<?php

$summa=0;
$komnati = readline();
//$komnati = 3;
//$min_max_array = array ('1 10', '5 10', '9 10');
for ($i=0; $i<$komnati; $i++) {
//    $input = readline();
    $min_max = explode(' ', readline());

      if (max($min_max)-min($min_max)>=2)  {
          $summa +=1;
}
}
 echo $summa;

<?php
$n = fgets(STDIN);
for ($i=0; $i < $n; $i++) {
    $string = fgets(STDIN);
    $data[] = explode(' ', $string);
}
$res = 0;
foreach ($data as $key => $val) {
    if ($val[1] - $val[0] >= 2) {
        $res++;
    }
}
echo $res;

?>

<?php
	$rows = trim(fgets(STDIN));
	$answer = 0;
	for ($i=0; $i<$rows; $i++) {
		$room = trim(fgets(STDIN));
		$vacant = explode(" ", $room);
		if ($vacant[1] - $vacant[0] >= 2) $answer++;
	}
	echo $answer;
?>

<?php

$n = trim(fgets(STDIN));
$rooms = [];
$result = 0;

while ($n) {
    $room = trim(fgets(STDIN));
    $rooms[] = explode(' ', $room);
    $n--;
}

foreach ($rooms as $room) {
    if ($room[1] - $room[0] >= 2) {
        $result++;
    }
}

echo $result;

<?php
$rooms=trim(fgets(STDIN));
$ans=0;
for($i=0;$i<$rooms;$i++){
    $line=explode(" ",trim(fgets(STDIN)));
    if((int)$line[1]-(int)$line[0]>=2) $ans++;
}
echo $ans;
?>

<?php
$n = fgets(STDIN);
$spaces = 0;
for ($i=0;$i<$n;$i++){
	$x = explode(" ", fgets(STDIN));
	if ($x[1] - $x[0] >= 2)
		$spaces++;
}
echo $spaces;
?>

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

?>

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

?>

<?php
// 467A 	Юра и заселение

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

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

$col = 0;

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

    $input_line = fgets($in);
    list($p, $q) = preg_split('/ /', $input_line, -1, PREG_SPLIT_NO_EMPTY);
    $p = (int) $p;
    $q = (int) $q;

    if (($q - $p) > 1) {
        $col ++;
    }
}

echo $col;

?>

<?php

$pCount = 2;
$n = (int)trim(fgets(STDIN));

$sCount = 0;
for($i=0;$i<=$n;$i++) {

    $m = fgets(STDIN);
    $m = explode(' ',$m);
    // живут
    $p = $m[0];
    // могут
    $q = $m[1];

    $sCan = $q - $p;

    if($sCan >= $pCount) {
        $sCount++;
    }
}

echo $sCount;

?>

<?php

$n = (int)fgets(STDIN);

$p = array();
$q = array();

$output = 0;

for ($i = 0; $i < $n; $i ++) {
	list($p[$i], $q[$i]) = explode(' ', fgets(STDIN));

	$p[$i] = (int)$p[$i];
	$q[$i] = (int)$q[$i];

	$output += ($q[$i] - $p[$i] > 1);
}

print $output;

<?php

$count = (int) fgets(STDIN);

$answer = 0;
for ($i = 0; $i < $count; $i++) {
    $rawRoomInfo = rtrim(fgets(STDIN));
    $rawInfo = explode(' ', $rawRoomInfo);

    if ((int)$rawInfo[1] - (int)$rawInfo[0] > 1) {
        $answer++;
    }
}

echo $answer . PHP_EOL;

<?php
fscanf(STDIN, '%d', $n); 				// считываем кол-во комнат
$result = 0;

for($i = 0; $i < $n; $i++) {
	$line = fgets(STDIN); 			// '4 5\n'
	$values = explode(' ', $line); 	// ['4', '5\n']

		if(($values[1] - $values[0]) >= 2){
			$result++;
			//print_r($result);

	}

}
print_r($result);

<?php

$n           = (int) fgets(STDIN);
$room_remain = 0;
while ($n--) {
    list($border, $capacity) = explode(' ', trim(fgets(STDIN)));
    if ($capacity - $border >= 2) {
        $room_remain++;
    }
}
echo $room_remain."\n";

<?php
error_reporting("off");
//467A: George and Accommodation
$n = trim(fgets(STDIN));
$counter = 0;
for ($i = 0; $i < $n; $i++) {
	list($p, $q) = explode(" ", trim(fgets(STDIN)));
	if ($p + 2 <= $q) {
		$counter++;
	}
}
echo $counter;
?>

<?
$data = file('php://stdin');
$roomsCnt = intval($data[0]);
if ($roomsCnt > 100) $roomsCnt = 100;
if ($roomsCnt > 0 && count($data) > 1){
	$rooms = 0;
	for($i = 1; $i <= $roomsCnt; $i++){
		$room = explode(" ", $data[$i]);
		if ($room[0] < $room[1] - 2) $rooms++;
	}
	echo $rooms;
}
?>

<?
$data = file('php://stdin');
$roomsCnt = intval($data[0]);
if ($roomsCnt > 100) $roomsCnt = 100;
$rooms = 0;
if ($roomsCnt > 0 && count($data) > 1){
	for($i = 1; $i <= $roomsCnt; $i++){
		$room = explode(" ", $data[$i]);
		if ($room[0] < $room[1] - 2) $rooms++;
	}
}
echo $rooms;
?>

<?
if (file_exists('php://stdin'))
{
	$data = file('php://stdin');
	$roomsCnt = intval($data[0]);
	if ($roomsCnt > 100) $roomsCnt = 100;
	$rooms = 0;
	if ($roomsCnt > 0 && count($data) > 1){
		for($i = 1; $i <= $roomsCnt; $i++){
			$room = explode(" ", $data[$i]);
			if ($room[0] < $room[1] - 2) $rooms++;
		}
	}
	echo $rooms;
}
?>

	<form method="GET">
		<?
		$roomsCnt = intval($_REQUEST["roomsCnt"]);
		if ($roomsCnt > 100) $roomsCnt = 100;
		$living = $_REQUEST["living"];
		$maxLiving = $_REQUEST["maxLiving"];
		?>
		Количество комнат
		<input type="number" value="<?=($roomsCnt > 0) ? $roomsCnt : 1;?>" name="roomsCnt"/>

		<?if ($roomsCnt > 0):?>

					Уже живут
					Макс живущих

						<?for($i = 0; $i < $roomsCnt; $i++):?>

								<input type="number" name="living[<?=$i?>]" value="<?=$living[$i]?>"/>
								<input type="number" name="maxLiving[<?=$i?>]" value="<?=$maxLiving[$i]?>"/>

						<?endfor?>

		<?endif;?>
		<?
		if($living > 0) $submit = "Рассчитать";
		else $submit = "Показать комнаты";
		?>
		<input type="submit" value="<?=$submit?>"/>
	</form>
	<?
	if(!empty($living)):?>

Результат:

		<?
		$rooms = 0;
		for($i = 0; $i < $roomsCnt; $i++){
			if ($living[$i] < $maxLiving[$i] - 1) $rooms++;
		}
		echo $rooms;
		?>

	<?endif?>

<?
$data = file('php://stdin');
$roomsCnt = intval($data[0]);
if ($roomsCnt > 100) $roomsCnt = 100;
if ($roomsCnt > 0){
	$rooms = 0;
	for($i = 1; $i <= $roomsCnt; $i++){
		$room = explode(" ", $data[$i]);
		if ($room[0] < $room[1] - 2) $rooms++;
	}
	echo $rooms;
}
?>

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

$COUNT = 0;
$room = 0;
foreach (input() as $line) {
    if ($COUNT == 0) {
        $n = intval($line);
        ++$COUNT;
        continue;
    }

    list($p, $q) = explode(' ', $line);
    if (intval($q) - intval($p) >=2 ) {
        ++$room;
    }

    if (++$COUNT >= $n) {
        echo $room;
        break;
    }
}

<?php
$counter = 0;
$n = trim(fgets(STDIN));
for($i=0;$i<$n;$i++){
	list($p,$q) = explode(" ",trim(fgets(STDIN)));
	if(($q-$p) > 2) $counter++;
}
printf("%d",$counter);
?>

<?php
$n = fgets(STDIN);
$summ=0;
for ($i=0;$i<$n;$i++)
{
    $room = explode(" ",fgets($STDIN));
    if ($room[1]-$room[0]>1)$summ++;
}
echo $summ;

<?php
$input=fgets(STDIN);
$room=0;
$array=[];
for ($i=0;$i<$input;$i++) {
    fscanf(STDIN,"%d\t%d",$array[$i]['person'],$array[$i]['nroom']);
}
for ($i=0; $i <$input;$i++) {
      if ($array[$i]['nroom'] > $array[$i]['person'] ) {
            $room++;
      }
}
echo $room;

<?php
$input=fgets(STDIN);
$room=0;
$array=[];
for ($i=0;$i<$input;$i++) {
    $array[$i]['person']=fgets(STDIN);
    $array[$i]['nroom']=fgets(STDIN);
}
for ($i=0; $i <$input;$i++) {
      if ($array[$i]['nroom'] > $array[$i]['person'] ) {
            $room++;
      }
}
echo $room;

<?php
// 467A 	Юра и заселение

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

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

$col = 0;

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

    $input_line = fgets($in);
    list($p, $q) = split(" ", $input_line);
    $p = (int) $p;
    $q = (int) $q;

    if (($q - $p) > 1) {
        $col ++;
    }
}

echo $col;

?>

<?php
// 467A 	Юра и заселение

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

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

$col = 0;
echo " n=$n ";
for ($i=0; $i < $n; $i++) {

    $input_line = fgets($in);
    list($p, $q) = preg_split('/ /', $input_line, -1, PREG_SPLIT_NO_EMPTY);
    $p = (int) $p;
    $q = (int) $q;

    if (($q - $p) > 1) {
        $col ++;
    }
}

echo $col;

?>

<?php
// 467A 	Юра и заселение

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

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

$col = 0;

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

    $input_line = fgets($in);
    list($p, $q) = split(" ", $input_line);
    $p = (int) $p;
    $q = (int) $q;

    if (($q - $p) > 1) {
        $col++;
    }
}

echo $col;

?>

<?php

    $n = trim(fgets(STDIN));
    $arr = array();
    $arr[] = explode(' ', trim(fgets(STDIN)));
    $arr[] = explode(' ', trim(fgets(STDIN)));
    $arr[] = explode(' ', trim(fgets(STDIN)));
    $j=0;

    for ($i=0; $i < $n; $i++) {
        if($arr[$i][1] - $arr[$i][0] > 1) {
           $j++;
        }
    }

    echo $j;

?>

<?php
	$z = trim(fgets(STDIN));
	$move = 0;
	for($i=0; $i<$z; $i++){
		$input = explode(' ', trim(fgets(STDIN)));
		if(($input[1] - $input[0]) > 0) $move++;
	}
	echo $move;
?>

<?php
	$z = trim(fgets(STDIN));
	$move = 0;
	for($i=0; $i<$z; $i++){
		$input = explode(' ', trim(fgets(STDIN)));
		if(($input[1] - $input[2]) >= 0) $move++;
	}
	echo $move;
?>

<?php
	$z = trim(fgets(STDIN));
	$move = 0;
	for($i=0; $i<$z; $i++){
		$input = explode(' ', trim(fgets(STDIN)));
		if(($input[1] - $input[2]) > 0) $move++;
	}
	echo $move;
?>

<?php
	$z = trim(fgets(STDIN));
	$move = 0;
	for($i=0; $i<$z; $i++){
		$input = explode(' ', trim(fgets(STDIN)));
		if($input[0] != $input[1]) $move++;
	}
	echo $move;
?>


<?php
$n = trim(fgets(STDIN));
$mas = explode(' ', trim(fgets(STDIN)));

$sum = array_sum($mas);
$mas_count = array_count_values($mas);
$c = 0;
foreach ($mas as $k => $v)
{
    if (($sum - $v) % 2 == 0)
    {
        $c++;
    }
}
echo $c;
?>

<?php
$kolvo = intval(fgets(STDIN, 1024));
$temp = fgets(STDIN, 100000);
$pakety = array_map('intval', explode(' ', $temp));
$co = array_sum($pakety);
$sposoby = 0;

for ($i=0; $i<$kolvo; $i++) {
    if (($co-$pakety[$i])%2 == 0) {
        $sposoby++;
    }
}
echo $sposoby;
?>

<?php
$countBags = (int) fgets(STDIN);
$bags = explode(' ', fgets(STDIN));

$countWays = 0;
for($i = 0; $i < $countBags; $i++) {
    $element = array_shift($bags);
    if (array_sum($bags) % 2 == 0) {
        $countWays++;
    }
    array_push($bags, $element);
}
echo $countWays;

<?php

$n=intval(fgets(STDIN, 150));
$mass=fgets(STDIN,100000);

$a=explode(' ',$mass);
$sum=array_sum($a);

$kol=0;

for($i=0;$i<$n;$i++){
	$chet=$sum-$a[$i];
	if($chet%2==0)
		$kol++;
}

$test=fwrite(STDOUT,$kol);

?>

<?php
$n = intval(trim(fgets(STDIN)));
$in = explode(' ',trim(fgets(STDIN)));

$summ = 0;
foreach ($in as $i ) {
    $summ += intval($i);
}

$count = 0;
foreach ($in as $i) {
    if( (($summ-intval($i))%2) == 0 ) {
        $count++;
    }
}
echo($count);

<?php
#10:47
$count=intval(trim(fgets(STDIN)));
$input=explode(' ',trim(fgets(STDIN)));
$cookie_count = 0;
$result = 0;
foreach($input as $v) {
    $cookie_count += intval($v);
}
foreach($input as $v) {
    if(($cookie_count - $v)%2===0) {
        $result++;
    }
}
echo( $result );

<?php

$fp=fopen('standart.input', 'r');
$fo=fopen('standart.output', 'r+');

$i=0;
if($fp)
	while(!feof($fp))
		if($i=0){
			$n=intval(fgets($fp, 999));
			$i++;
		}
		else
			$mass=fgets($fp,999);

$a=explode(' ',mass);

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

$kol=0;

for($i=0;$i<$n;$i++){
	$chet=$sum-$a[$i];
	if($chet%2==0)
		$kol++;
}

$test=fwrite($fo,$kol);
fclose($fp);
fclose($fo);

?>

<?php

$fp=fopen('std.in', 'r');
$fo=fopen('std.out', 'r+');

$i=0;
if($fp)
	while(!feof($fp))
		if($i=0){
			$n=intval(fgets($fp, 999));
			$i++;
		}
		else
			$mass=fgets($fp,999);

$a=explode(' ',mass);
$sum=0;
for($i=0;$i<$n;$i++){
	$sum+=$a[$i];
}

$kol=0;

for($i=0;$i<$n;$i++){
	$chet=$sum-$a[$i];
	if($chet%2==0)
		$kol++;
}

$test=fwrite($fo,$kol);
fclose($fp);
fclose($fo);

?>

<?php
$n = intval(trim(fgets(STDIN)));
$in = explode(' ',trim(fgets(STDIN)));
$summ = 0;
foreach ($in as $i ) { $summ=+$i; }

$res = 0;
foreach ($in as $i) {
    if( ($summ-$i)%2 == 0 ) {
        $res++;
    }
}
echo($res);

<?php
$a = file(STDIN, FILE_IGNORE_NEW_LINES);
$k = $a[0];
$b = explode(" ", $a[1]);

$sposoby = 0;
$count = array_count_values($b);

for ($i=0; $i<$k; $i++) {
    $temp = $b;
    unset($temp[$i]);
    if (mod(array_count_values($b), 2) == 0) {
        $sposoby++;
    }
    unset($temp);
}

echo $sposoby;
?>

<?php
$b = fgets(STDIN, 1024);
$a = explode(" ", $b);
$kolvo = $a[0];
$pakety = explode(" ", $a[1]);

$sposoby = 0;

for ($i=0; $i<$kolvo; $i++) {
    $temp = $pakety;
    unset($temp[$i]);
    if (array_count_values($temp)%2 == 0) {
        $sposoby++;
    }
    unset($temp);
}

echo $sposoby;

?>

<?php
$b = fgets(STDIN, 1024);
$a = explode(' ', $b, 2);
$kolvo = $a[0];
$pakety = explode(" ", $a[1]);

$sposoby = 0;

for ($i=0; $i<$kolvo; $i++) {
    $temp = $pakety;
    unset($temp[$i]);
    if (array_count_values($temp)%2 == 0) {
        $sposoby++;
    }
}

echo $sposoby;
?>

<?php
$a = file(STDIN, FILE_IGNORE_NEW_LINES);
$kolvo = $a[0];
$pakety = explode(" ", $a[1]);

$sposoby = 0;

for ($i=0; $i<$kolvo; $i++) {
    $temp = $pakety;
    unset($temp[$i]);
    if (array_count_values($temp)%2 == 0) {
        $sposoby++;
    }
    unset($temp);
}

echo $sposoby;
?>

<?php
$b = fgets(STDIN, 1024);
$a = explode(" ", $b, 2);
$kolvo = $a[0];
$pakety = explode(" ", $a[1]);

$sposoby = 0;

for ($i=0; $i<$kolvo; $i++) {
    $temp = $pakety;
    unset($temp[$i]);
    if (array_count_values($temp)%2 == 0) {
        $sposoby++;
    }
}

echo $sposoby;
?>

<?php
$a = file(STDIN, FILE_IGNORE_NEW_LINES);
$k = $a[0];
$b = explode(" ", $a[1]);

$sposoby = 0;
$count = array_count_values($b);

for ($i=0; $i<$k; $i++) {
    $temp = $b;
    unset($b[$i]);
    if (mod(array_count_values($b), 2) == 0) {
        $sposoby++;
    }
    unset($temp);
}

echo $sposoby;
?>

<?php
$a = file(STDIN, FILE_IGNORE_NEW_LINES);
$k = $a[0];
$b = explode(" ", $a[1]);

$sposoby = 0;
//$c = array_count_values($b);

for ($i=0; $i<$k; $i++) {
    $temp = $b;
    unset($temp[$i]);
    if (mod(array_count_values($temp), 2) == 0) {
        $sposoby++;
    }
    unset($temp);
}

echo $sposoby;
?>

<?php
$a = file(STDIN, FILE_IGNORE_NEW_LINES);
$k = $a[0];
$b = explode(" ", $a[1]);

$sposoby = 0;
$count = array_count_values($b);

for ($i=0; $i<k; $i++) {
    $temp = $b;
    unset($b[$i]);
    if (mod(array_count_values($b), 2) == 0) {
        $sposoby++;
    }
    unset($temp);
}

echo $sposoby;
?>

<?php
$b = fgets(STDIN, 2048);
$a = explode(" ", $b);
$kolvo = $a[0];
$pakety = explode(" ", $a[1]);

$sposoby = 0;

for ($i=0; $i<$kolvo; $i++) {
    $temp = $pakety;
    unset($temp[$i]);
    if (array_count_values($temp)%2 == 0) {
        $sposoby++;
    }
    unset($temp);
}

echo $sposoby;

?>

<?php
$a = file(STDIN, FILE_IGNORE_NEW_LINES);
$kolvo = $a[0];
$pakety = explode(" ", $a[1]);

$sposoby = 0;
//$c = array_count_values($b);

for ($i=0; $i<$kolvo; $i++) {
    $temp = $pakety;
    unset($temp[$i]);
    if (array_count_values($temp)%2 == 0) {
        $sposoby++;
    }
    unset($temp);
}

echo $sposoby;
?>

<?php
$b = fgets(STDIN, 1024);
$a = explode(" ", $b);
$kolvo = $a[0];
$pakety = explode(" ", $a[1]);

$sposoby = 0;

for ($i=0; $i<$kolvo; $i++) {
    $temp = $pakety;
    unset($temp[$i]);
    if (array_count_values($temp)%2 == 0) {
        $sposoby++;
    }
    //unset($temp);
}

echo $sposoby;
?>

<?php
$b = fgets(STDIN, 1024);
$a = explode(' ', $b, 2);
$kolvo = $a[0];
$pakety = explode(" ", $a[1]);

$sposoby = 0;

for ($i=0; $i<$kolvo; $i++) {
    $temp = $pakety;
    unset($temp[$i]);
    if (array_count_values($temp)%2 != 0) {
        $sposoby++;
    }
}

echo $sposoby;
?>

<?php
$n = trim(fgets(STDIN));
$mas = explode(' ', trim(fgets(STDIN)));

$sum = array_sum($mas);
$mas_count = array_count_values($mas);

if ($sum % 2 == 0)
{
    foreach ($mas_count as $k => $v)
    {
        if ($k % 2 == 0)
            $c += $v;
    }
}
else
{
    foreach ($mas_count as $k => $v)
    {
        if ($k % 2 != 0)
            $c += $v;
    }
}
echo $c;
?>


<?php

namespace io {
	$input_file_content = file_get_contents("php://stdin");
	$input_buf = explode("\r\n", $input_file_content);
	unset($input_file_content);
}

namespace main {
	error_reporting(E_ALL);
	ini_set('display_errors', true);
	ini_set('html_errors', false);

	use function io\next_line as next_line;
	use function io\next_ as next;
	use function io\next_int as next_int;
	use function io\next_double as next_double;

	$tc = next_int();
	for($cc=0; $cc<$tc; $cc++) {
		$n = next_int();
		$m = ($n - 1) / 9;
		printf("%d\n", $n + $m);
	}
}

namespace io {
	function next_line() {
		static $cnt = 0;
		global $input_buf;
		return $input_buf[$cnt++];
	}
	function next_() {
		static $tk = [];
		static $tk_cnt = 0;
		if($tk_cnt == count($tk)) {
			$tk = explode(" ", next_line());
			$tk_cnt = 0;
		}
		return $tk[$tk_cnt++];
	}
	function next_int() {
		return (int)next_();
	}
	function next_double() {
		return (double)next_();
	}
}

?>

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

    for($i=0; $i<$t; $i++) {
        $n = trim(fgets(STDIN));
        $total = 0;

        while ($n >= 10) {

             $d = $n % 10;
             $s = floor($n / 10);

             $n = $d + $s;
            $total += $s * 10 ;
        }
        $total += $n;

        echo $total ."\n";

    }

<?

$n = intval(fgets(STDIN));
for ($i = 0; $i < $n; $i++) {
    $money = intval(fgets(STDIN));
    $cashback = 0;
    $total = 0;
    while($money > 9) {
        $cashback = intdiv($money, 10);
        $total += 10 * $cashback;
        $money = $money - 9 * $cashback;
    }
    $total += $money;
    echo $total."\n";
}
?>

<?php

namespace io {
	$input_file_content = file_get_contents("php://stdin");
	$input_buf = explode("\r\n", $input_file_content);
	unset($input_file_content);
}

namespace main {
	error_reporting(E_ALL);
	ini_set('display_errors', true);
	ini_set('html_errors', false);

	use function io\next_line as next_line;
	use function io\next_ as next;
	use function io\next_int as next_int;
	use function io\next_double as next_double;

	$tc = next_int();
	for($cc=0; $cc<$tc; $cc++) {
		$n = next_int();
		$m = $n / 9;
		printf("%d\n", $n + $m);
	}
}

namespace io {
	function next_line() {
		static $cnt = 0;
		global $input_buf;
		return $input_buf[$cnt++];
	}
	function next_() {
		static $tk = [];
		static $tk_cnt = 0;
		if($tk_cnt == count($tk)) {
			$tk = explode(" ", next_line());
			$tk_cnt = 0;
		}
		return $tk[$tk_cnt++];
	}
	function next_int() {
		return (int)next_();
	}
	function next_double() {
		return (double)next_();
	}
}

?>


<?php
$rowCount = trim(fgets(STDIN));
$inputArr = [];

$i = 1;
while ($i <= $rowCount) {
  $input = trim(fgets(STDIN));
  $inputArr1 = explode(" ", $input);

  array_push($inputArr, $inputArr1);
  $i++;
}

for ($i = 0; $i < $rowCount; $i++) {
  $n = $inputArr[$i][0];
  $x = $inputArr[$i][1];
  $a = $inputArr[$i][2];
  $b = $inputArr[$i][3];

  if (abs($a - $b) != $n - 1 && $x != 0) {
    $result = abs($a - $b);

    for ($j = 0; $result != $n - 1 && $j < $x; $j++) {
      $result++;
    }

    echo $result . "\n";
  } else {
    $result = abs($a - $b);
    echo $result . "\n";
  }
}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $c; $i++) {
    list($n, $m, $a, $b) = explode(' ', trim(fgets(STDIN)));
    if (abs($a - $b) + $m >= $n) {
        echo ($n -1) . "\n";
    } else {
        echo (abs($a - $b) + $m) . "\n";
    }
}

<?php

while(! feof(STDIN)){
    $arr[]=fgets(STDIN);
}

for($i=0; $i<$arr[0]; $i++){
    $value=explode(" ", $arr[1+$i]);
    if(abs($value[2]-$value[3])+$value[1]>=$value[0]){echo $value[0]-1;}
    else{echo abs($value[2]-$value[3])+$value[1];}
    if($i!= $arr[0]+1) echo "\n";
}
?>

<?php
$a = trim(fgets(STDIN));
for($i = 0; $i < $a; $i++){
    $r = explode(" ", fgets(STDIN));
    $max = $r[0] - 1;
    $range = abs($r[2] - $r[3]);
    if(($range + $r[1]) < $max){
        echo $range + $r[1]."\n";
    } else {
        echo $max."\n";
    }
}

<?php

function gcd($a,$b)
{
    while($b)
    {
        $a%=$b;
        $tmp=$b;
        $b=$a;
        $a=$tmp;

    }
    return $a;
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";$d=0;$t=0;
    $x=trim(fgets($handle));
    for($i=0;$i<$x;$i++)
    {

        $str=trim(fgets($handle));
        $str1=explode(" ",$str);

        $ans=max($str1[2],$str1[3])-min($str1[2],$str1[3]);
        if($ans+$str1[1]>=$str1[0])
        {
            echo ($str1[0]-$ans-1)+$ans."\n";
        }else{
            echo $ans+$str1[1]."\n";
        }

    }

}

solve();
?>

<?php
$rowCount = trim(fgets(STDIN));
$inputArr = [];

$i = 1;
while ($i <= $rowCount) {
  $input = trim(fgets(STDIN));
  $inputArr1 = explode(" ", $input);

  array_push($inputArr, $inputArr1);
  $i++;
}

for ($i = 0; $i < $rowCount; $i++) {
  $n = $inputArr[$i][0];
  $x = $inputArr[$i][1];
  $a = $inputArr[$i][2];
  $b = $inputArr[$i][3];

  if (abs($a - $b) != $n - 1 && $x != 0) {
    $result = abs($a - $b);

    for ($j = 0; $result != $n && $j <= $x; $j++) {
      $result++;
    }

    echo $result . "\n";
  } else {
    $result = abs($a - $b);
    echo $result . "\n";
  }
}

<?php
$rowCount = trim(fgets(STDIN));
$inputArr = [];

$i = 1;
while ($i <= $rowCount) {
  $input = trim(fgets(STDIN));
  $inputArr1 = explode(" ", $input);

  array_push($inputArr, $inputArr1);
  $i++;
}

for ($i = 0; $i < $rowCount; $i++) {
  $n = $inputArr[$i][0];
  $x = $inputArr[$i][1];
  $a = $inputArr[$i][2];
  $b = $inputArr[$i][3];

  if (abs($a - $b) != $n - 1 && $x != 0) {
    $result = abs($a - $b);

    for ($j = 0; $result != $n && $j < $x; $j++) {
      $result++;
    }

    echo $result . "\n";
  } else {
    $result = abs($a - $b);
    echo $result . "\n";
  }
}

<?php

while(! feof(STDIN)){
    $arr[]=fgets(STDIN);
}

for($i=0; $i<$arr[0]; $i++){
    $value=explode(" ", $arr[1+$i]);
    if(abs($value[2]-$value[3])+$value[1]>$value[0]){echo $value[0]-1;}
    else{echo abs($value[2]-$value[3])+$value[1];}
    if($i!= $arr[0]+1) echo "\n";
}
?>

<?php

while(! feof(STDIN)){
    $arr[]=fgets(STDIN);
}

for($i=0; $i<$arr[0]; $i++){
    $value=explode(" ", $arr[1+$i]);
    if($value[0]==$value[2] && $value[3]==1){echo abs($value[2]-$value[3]);}
    elseif($value[0]>=$value[2]+$value[1]){echo abs($value[2]+$value[1]-$value[3]);}
    elseif($value[0]<$value[2]+$value[1] && $value[3]-$value[1]>=1){echo abs($value[0]-($value[0]-$value[1]+$value[3]));}
    elseif($value[0]<$value[2]+$value[1] && $value[3]-$value[1]<1){echo abs($value[0]-1);}
    if($i!= $arr[0]+1) echo "\n";
}

?>

<?php

function gcd($a,$b)
{
    while($b)
    {
        $a%=$b;
        $tmp=$b;
        $b=$a;
        $a=$tmp;

    }
    return $a;
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";$d=0;$t=0;
    $x=trim(fgets($handle));
    for($i=0;$i<$x;$i++)
    {

        $str=trim(fgets($handle));
        $str1=explode(" ",$str);

        $ans=max($str1[2],$str1[3])-min($str1[2],$str1[3]);
        if($ans+$str1[1]>$str1[0])
        {
            echo ($str1[0]-$ans-1)+$ans."\n";
        }else{
            echo $ans+$str1[1]."\n";
        }

    }

}

solve();
?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = $c;
$f = array();
$h = array();
rsort($d);
if($d[0] < $b)
{
    print "0";
}
else
{
    for($x = $b; $x <= $d[0]; $x++)
    {
        for($y = 0; $y < $a; $y++)
        {
            $e = floor($c[$y] / $x);
            array_push($f, $e);
        }
        $g = array_sum($f) * $x;
        array_push($h, $g);
        $f = array();
    }
    rsort($h);
    print $h[0];
}
?>

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


<?php
	$in = 'php://stdin';
	//$in = 'inputC.txt';

	$input = fopen($in, "r");

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

    $swit[0][0] = 1; $swit[0][1] = $m;
    $swit[1][0] = -1; $swit[1][1] = 1;
    $counter = 0;

    $iter = $swit[$counter][0];
    $ogran = $swit[$counter][1];

    $copyK = $k-1;

    $x = 1; $y = 1;

    while ($k > 1) {
    	echo '2 ';
    	echo $x.' '.$y;

    	if ($y==$ogran) {
    		$counter = ($counter+1)%2;
   			$iter = $swit[$counter][0];
    		$ogran = $swit[$counter][1];
    		$x++;
    	}
    	else {
    		$y+=$iter;
    	}

    	echo ' '.$x.' '.$y.PHP_EOL;
    	$k--;

    	if ($y==$ogran) {
    		$counter = ($counter+1)%2;
   			$iter = $swit[$counter][0];
    		$ogran = $swit[$counter][1];
    		$x++;
    	}
    	else {
    		$y+=$iter;
    	}
    }
    echo ($n*$m-2*$copyK);

    while ($x<=$n) {
    	echo ' '.$x.' '.$y;

    	if ($y==$ogran) {
    		$counter = ($counter+1)%2;
   			$iter = $swit[$counter][0];
    		$ogran = $swit[$counter][1];
    		$x++;
    	}
    	else {
    		$y+=$iter;
    	}
    }

?>


<?php
error_reporting(1);

$fp = fopen('php://stdin','r');
//$fp = fopen('D:/work/php/codeforce/DDD.txt','r');
$word = trim( str_replace( "\r\n", '', fgets($fp) ) );
/*
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtimeS = $mtime[1] + $mtime[0];
*/

$len = strlen( $word );
$palindrom = array();
$countCache = array();
$pS = array();
$pE = array();
for( $i = 0; $i < $len; $i++ )
{
	$pE[$i]++;
	$countCache[ $i ]++;
	$z = 0;
	while( true ){
		$z++;
		if( isset( $word[$i - $z] ) && $word[$i - $z] == $word[$i + $z]){
			$pE[($i + $z)]++ ;
			$countCache[ $i - $z ]++;
		} else {
			break;
		}
	}
	$z = 0;
	while( true ){
		$z++;
		if( isset( $word[$i - $z] ) && $word[$i - $z] == $word[$i + $z - 1]){
			$pE[($i + $z - 1)]++;
			$countCache[ $i - $z ]++;
		} else {
			break;
		}
	}
}

$sum = 0;
$tt = end( $countCache );
while( true ){
	$sum += $tt;
	$countCache[ key( $countCache ) ] = $sum;
	$tt = prev( $countCache );
	if( !$tt ){
		break;
	}
}
//print_r( $pE );
//print_r( $countCache );

reset( $countCache );
$pp = current( $pE ) ;
$cc = current( $countCache );
$res = 0;
while( true )
{
	if( key( $pE ) < key( $countCache ) ){
		$res += $pp * $cc;
		$pp = next( $pE ) ;
	} else {
		$cc = next( $countCache );
	}
	if( !$pp || !$cc ){
		break;
	}
}
echo $res;
/*
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtimeE = $mtime[1] + $mtime[0];

echo "\n" . ( $mtimeE - $mtimeS ) . "\n";*/

fclose($fp);
?>

<?php

$input = STDIN;

$string = trim(fgets($input));

$strlen = strlen($string);
/*
for($i=1; $i<$strlen; $i++) {
	for($j=0; $j<$strlen-$i+1; $j++) {
		#$a = substr($string, $j, $i)."\n";
	}
}
*/

$result = 0;
$resultSingle = 0;
$palCount = array();

/*$i=0;
$start = -1;
while($i < $strlen-1) {
	while ($string[$i] == $string[$i+1]);
}*/
$arEndPoints = array();
for ($i=0; $i<$strlen; $i++) {
	#$palyndrom[$i][] = 1;
	$resultSingle += $strlen-1;

	/*
	if (!isset($palCount[$i])) $palCount[$i] = 1;
	else ++$palCount[$i];
	*/

	# поиск палиндромов с центром
	$plen = 1;
	$center = true;
	$offset = true;
	while ($i-$plen+1 >= 0 && $i+$plen <= $strlen-1 && ($center || $offset)){
		$center = ($center && ($i-$plen >= 0) && $string[$i-$plen] == $string[$i+$plen]);
		if ($center) {
			#$palyndrom[$i-$plen][] = $plen+$plen+1;
			if (!isset($arEndPoints[$i+$plen+1])) $arEndPoints[$i+$plen+1] = 1;
			else ++$arEndPoints[$i+$plen+1];

			if (!isset($palCount[$i-$plen])) $palCount[$i-$plen] = 1;
			else ++$palCount[$i-$plen];

			#echo substr($string, $i-$plen, $plen+$plen+1)."\n";
			$result += $strlen - ($plen+$plen+1);
		}

		$offset = $offset && ($string[$i-$plen+1] == $string[$i+$plen]);
		if ($offset) {
			#$palyndrom[$i-$plen+1][] = $plen+$plen;
			if (!isset($arEndPoints[$i+$plen+1])) $arEndPoints[$i+$plen+1] = 1;
			else ++$arEndPoints[$i+$plen+1];

			if (!isset($palCount[$i-$plen+1])) $palCount[$i-$plen+1] = 1;
			else ++$palCount[$i-$plen+1];

			#echo substr($string, $i-$plen+1, $plen+$plen)."\n";
			$result += $strlen - ($plen+$plen);
		}

		++$plen;
	}
}

$sumPalCount = array();
$count = max(array_keys($palCount));#count($palCount);
$last = $count;
$sumPalCount[$last] = $palCount[$last];
for($i=$count-1; $i>=0; --$i){
	if (isset($palCount[$i])){
		$sumPalCount[$i] = $palCount[$i] + $sumPalCount[$last];
		$last = $i;
	}
}

$pairCount = 0;
$endPoints = array_keys($arEndPoints);
$endPointsCount = count($endPoints);

for($i=0; $i<$endPointsCount; ++$i){
	for($k=$endPoints[$i]; $k<=$count; ++$k){
		if (isset($palCount[$k])){
			#$pairCount += $palCount[$k];
			$pairCount += $sumPalCount[$k] * $arEndPoints[$endPoints[$i]];
			break;
		}
	}
}

$resultSingle /= 2;
$result += $resultSingle + $pairCount;
echo $result;

?>


<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

list($n, $k) = $ir->readArrayOfInt(2);
$vals = $ir->readArrayOfInt($n);
$vals[] = 0;
$s = $ir->readString() . ' ';

$dmg = '0';

$groupSymbol = '';

$group = [];
for($i=0; $i<=$n; $i++) {
	if ($s[$i] == $groupSymbol) {
		$group[] = $vals[$i];
	} else {
		$cnt = count($group);
		foreach ($group as $gg) {
			$dmg = bcadd($dmg, $gg);
		}
		$j = $cnt - $k;
		if ($j>0) {
			sort($group);
			while ($j--) {
				$dmg = bcsub($dmg, $group[$j]);
			}
		}

		$groupSymbol = $s[$i];
		$group = [$vals[$i]];
	}
}

echo $dmg;

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
array_push($c, "0");
$d = trim(fgets(STDIN)) . "#";
$e = 0;
$f = new SplMaxHeap();
$f -> insert($c[0]);
for($x = 0; $x < $a; $x++)
{
     if($d[$x] == $d[$x + 1])
     {
          $f -> insert($c[$x + 1]);
     }
     else
     {
          for($y = 0; $y < $b; $y++)
          {
               $e += $f -> extract();
               if($f -> isEmpty() == TRUE)
               {
                    break;
               }
          }
          $f = new SplMaxHeap();
          $f -> insert($c[$x + 1]);
     }
}
printf("%.0f", $e);
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
array_push($c, "0");
$d = trim(fgets(STDIN)) . "#";
$e = 0;
$f = new SplMaxHeap();
$f -> insert($c[0]);
for($x = 0; $x < $a; $x++)
{
     if($d[$x] == $d[$x + 1])
     {
          $f -> insert($c[$x + 1]);
     }
     else
     {
          for($y = 0; $y < $b; $y++)
          {
               $e += $f -> extract();
               if($f -> isEmpty() == TRUE)
               {
                    break;
               }
          }
          $f = new SplMaxHeap();
          $f -> insert($c[$x + 1]);
     }
}
print $e;
?>

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

list($n, $k) = $ir->readArrayOfInt(2);
$vals = $ir->readArrayOfInt($n);
$vals[] = 0;
$s = $ir->readString() . ' ';

$dmg = 0;

$groupSymbol = '';

$group = [];
for($i=0; $i<=$n; $i++) {
	if ($s[$i] == $groupSymbol) {
		$group[] = $vals[$i];
	} else {
		//var_dump($group);
		$cnt = count($group);
		$dmg += array_sum($group);
		$j = $cnt - $k;
		if ($j>0) {
			sort($group);
			while ($j--) {
				$dmg -= $group[$j];
			}
		}

		$groupSymbol = $s[$i];
		$group = [$vals[$i]];
	}
}

echo $dmg;

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

list($n, $k) = $ir->readArrayOfInt(2);
$vals = $ir->readArrayOfInt($n);
$vals[] = 0;
$s = $ir->readString() . ' ';

$dmg = '0';

$groupSymbol = '';

$group = [];
for($i=0; $i<=$n; $i++) {
	if ($s[$i] == $groupSymbol) {
		$group[] = $vals[$i];
	} else {
		//var_dump($group);
		$cnt = count($group);
		$dmg = bcadd($dmg, array_sum($group));
		$j = $cnt - $k;
		if ($j>0) {
			sort($group);
			while ($j--) {
				$dmg = bcsub($dmg, $group[$j]);
			}
		}

		$groupSymbol = $s[$i];
		$group = [$vals[$i]];
	}
}

echo $dmg;


<?php

$line = fgets(STDIN);
list($n, $p, $q) = explode(' ', $line);
$n = intval($n);
$p = intval($p);
$q = intval($q);
$s = trim(fgets(STDIN));

$ans = false;

for ($i = 0; $i <= $n; $i++) {
	for ($j = 0; $j <= $n; $j++) {
		if ($i * $p + $j * $q == $n) {
			$ans = true;
			break;
		}
	}
	if ($ans)
		break;
}

if ($ans) {
	echo $i + $j . "\n";
	$start = 0;
	for ($ii = 0; $ii < $i; $ii++) {
		echo substr($s, $start, $p) . "\n";
		$start += $p;
	}
	for ($jj = 0; $jj < $j; $jj++) {
		echo substr($s, $start, $q) . "\n";
		$start += $q;
	}
} else {
	echo -1;
}

<?php

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

fscanf($handle, "%d %d %d", $n, $p, $q);
fscanf($handle, "%s", $s);
fclose($handle);

echo $n." ".$p." ".$q."\n";
echo $s."\n";

?>


<?php

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

list($n, $t) = fscanf($fp, '%d %d');
$busy = explode(' ', fgets($fp));

$secondsInDay = 60 * 60 * 24;

for($i = 0; $i < $n; $i++)
{
	$t -= ($secondsInDay - $busy[$i]);
	if($t <= 0)
	{
		echo ($i + 1) . PHP_EOL;
		break;
	}
}

fclose($fp);
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
for($x = 0; $x < $a; $x++)
{
     $d = 86400 - $c[$x];
     $b -= $d;
     if($b <= 0)
     {
          print $x + 1;
          break;
     }
}
?>

<?php

$line1 = fgets(STDIN);
$line2 = fgets(STDIN);

list($numberOfDays, $timeRequired) = explode(' ', $line1);
$blockedTimePerDay = explode(' ', $line2);

foreach ($blockedTimePerDay as $day => $time) {
    $freeTime = 86400 - $time;

    $timeRequired -= $freeTime;

    if($timeRequired <= 0) {
        echo $day + 1;
        break;
    }
}

<?php
list($days, $needSeconds) = explode(" ", trim(fgets(STDIN)));
$dayWorkTimes =  explode(" ", trim(fgets(STDIN)));
$counter = 0;
for($i = 0; $i < $days; $i++) {
    $needSeconds -= (86400-$dayWorkTimes[$i]);
    $counter++;
    if($needSeconds <= 0) {
        break;
    }
}
print $counter;
?>

<?php //rextester.com:7.0.8--codeforces.com:7.0.12
list($totalTime,$requiredTime)=explode(' ',fgets(STDIN));$workTime=explode(' ',fgets(STDIN));$nonWorkingTime=0;$minRequiredTime=0;
for($i=0;$i<count($workTime);$i++){
    $nonWorkingTime+=86400-$workTime[$i];$minRequiredTime++;
    if($nonWorkingTime>=$requiredTime){echo$minRequiredTime;break;}
}

<?php //7.0.8(rextester.com)7.0.12(codeforces.com)2018-01-04
list($totalTime,$requiredTime)=explode(' ',fgets(STDIN));
$workTime=explode(' ',fgets(STDIN));
$nonWorkingTime=0;
$minRequiredDay=0;
for($i=0;$i<count($workTime);$i++){
    $nonWorkingTime+=86400-$workTime[$i];
    $minRequiredDay++;
    if($nonWorkingTime>=$requiredTime){
        echo$minRequiredDay;
        break;
    }
}

<?php //7.0.8 | RexTester.Com & 7.0.12 | CodeForces.Com
list($totalTime, $requiredTime) = explode(' ', fgets(STDIN));

$workTime = explode(' ', fgets(STDIN));
$nonWorkingTime = 0;
$minRequiredDay = 0;

for ($i=0; $i<count($workTime); $i++) {
    $nonWorkingTime += 86400 - $workTime[$i];
    $minRequiredDay++;

    if ($nonWorkingTime >= $requiredTime) {
        echo $minRequiredDay;
        break;
    }
}

<?php //7.0.8 | RexTester.Com & 7.0.12 | CodeForces.Com
list($a,$b)=explode(' ',fgets(STDIN));$c=explode(' ',fgets(STDIN));$d=0;$e=0;for($i=0;$i<count($c);$i++){$d+=86400-$c[$i];$e++;if($d>=$b){echo$e;break;}}


<?php
//摆烂，摆大烂
//之前提交的版本的魔改版，所以没用readline
//写不动了，nnd
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $tmp = explode(' ', trim($datum));
    $a = max((int)$tmp[0], (int)$tmp[1]);
    $b = min((int)$tmp[0], (int)$tmp[1]);

    if ($b === 0) {
        $result[] = 0;
        continue;
    }
    $n = $a - $b;
    $i = 0;
    if($n >= 2) {
        $m=(int)($n/2);
        if ($m >= $b) {
            $result[]=$b;
            continue;
        }
        $i+=$m;
        $b-=$m;
        $a-=$m*3;
    }
    $i += (int)(min($a,$b) / 2);
    $result[] = $i;
}
echo implode("\n", $result);

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

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  list($m, $p) = explode(" ", trim(fgets($file)));

  $min = min($m, $p);
  $res = floor(($m + $p) / 4);

  echo min($min, $res).PHP_EOL;
}

?>

<?php

$fp = fopen('php://stdin', 'r');
$lines = [];

if ($fp) {
    while (($line = fgets($fp)) !== false) {

        $lines[] = trim($line);
    }

    fclose($fp);
}

$n =  $lines[0];

for ($i = 1; $i <= $n; $i++) {
    $result = workFunction($lines[$i]);
    fwrite(STDOUT, $result);
    fwrite(STDOUT, "\n");
}

function workFunction($competitors): int
{
    $competitors = explode(' ', $competitors);

    $teamMin = min($competitors);

    $possibleValue = (int)(array_sum($competitors) / 4);

    return min($teamMin, $possibleValue);
}

<?php
//摆烂，摆大烂
//123
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $tmp = explode(' ', trim($datum));
    $a = max((int)$tmp[0], (int)$tmp[1]);
    $b = min((int)$tmp[0], (int)$tmp[1]);

    if ($b === 0) {
        $result[] = 0;
        continue;
    }
    $n = $a - $b;
    $i = 0;
    if($n >= 2) {
        $m=(int)($n/2);
        if ($m >= $b) {
            $result[]=$b;
            continue;
        }
        $i+=$m;
        $b-=$m;
        $a-=$m*3;
    }
    $i += (int)(min($a,$b) / 2);
    $result[] = $i;
}
echo implode("\n", $result);

<?php
//摆烂，摆大烂
//123
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $tmp = explode(' ', trim($datum));
    $a = max((int)$tmp[0], (int)$tmp[1]);
    $b = min((int)$tmp[0], (int)$tmp[1]);

    if ($b === 0) {
        $result[] = 0;
        continue;
    }
    $n = $a - $b;
    $i = 0;
    if($n > 2) {
        $m=(int)($n/2);
        if ($m >= $b) {
            $result[]=$b;
            continue;
        }
        $i+=$m;
        $b-=$m;
    }
    $i += (int)($b / 2);
    $result[] = $i;
}
echo implode("\n", $result);

<?php
//摆烂，摆大烂
//123
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $tmp = explode(' ', trim($datum));
    $a = max((int)$tmp[0], (int)$tmp[1]);
    $b = min((int)$tmp[0], (int)$tmp[1]);

    if ($b === 0) {
        $result[] = 0;
        continue;
    }
    $n = $a - $b;
    $i = 0;
    if($n > 2) {
        $m=(int)(($n-2)/2);
        if ($m >= $b) {
            $result[]=$b;
            continue;
        }
        $i+=$m;
        $b-=$m;
    }
    $i += (int)($b / 2);
    $result[] = $i;
}
echo implode("\n", $result);

<?php
//摆烂，摆大烂
//123
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $tmp = explode(' ', trim($datum));
    $a = max((int)$tmp[0], (int)$tmp[1]);
    $b = min((int)$tmp[0], (int)$tmp[1]);

    if ($b === 0) {
        $result[] = 0;
        continue;
    }
    $n = $a - $b;
    $i = 0;
    if($n > 2) {
        $m=(int)(($n-2)/2);
        if ($m >= $b) {
            $result[]=$b;
            continue;
        }
        $i+=$m;
        $a-=3*$m;
    }
    $i += (int)($a / 2);
    $result[] = $i;
}
echo implode("\n", $result);

<?php
//摆烂，摆大烂
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $datum=trim($datum);
    $tmp=explode(' ',$datum);
    $a=(int)$tmp[0];
    $b=(int)$tmp[1];
    $i=0;
    while($a>1000 && $b>1000) {
        $a-=1000;
        $b-=1000;
        $i+=500;
    }
    while ($a + $b >= 4 && min($a,$b)>0) {
        if ($a > $b) {
            $a-=3;
            --$b;
        }elseif ($b > $a) {
            $b-=3;
            --$a;
        } else {
            $b-=2;
            $a-=2;
        }
        if (max($a,$b)<0) {
            break;
        }
        ++$i;
    }
    $result[]=$i;
}
echo implode("\n", $result);


<?php

    function lowerBound($dp, $l, $r, $k) {
        $ans = $r; $m = 0;
        while ($l < $r) {
            $m = $l + $r >> 1;
            if ($dp[$m] >= $k) $ans = $r = $m; else $l = $m + 1;
        }
        return $ans;
    }

    $n = fgets(STDIN);
    $a = explode(" ", trim(fgets(STDIN)));
    $dp = array_fill(0, $n, 0);
    $dp[0] = $a[0];
    $ans = 1;
    for ($i = 1; $i < $n; $i++) {
        if ($a[$i] > $dp[$ans - 1]) $dp[$ans++] = $a[$i];
        elseif ($a[$i] < $dp[0]) $dp[0] = $a[$i];
        else $dp[lowerBound($dp, 0, $ans, $a[$i])] = $a[$i];
    }

    echo $ans;

<?php

    class Fenwick {
        private $n;
        private $count;

        public function __construct($n) {
            $this -> n = $n + 10;
            $this -> count = array_fill(1, $this -> n , 0);
        }

        public function update($i, $val) {
            for (; $i <= $this -> n; $i += $i & -$i) $this -> count[$i] = max($this -> count[$i], $val);
        }

        public function get($i) {
            $max = 0;
            for (; $i > 0; $i -= $i & -$i) $max = max($max, $this -> count[$i]);
            return $max;
        }
    }

    $n = fgets(STDIN);
    $a = explode(" ", trim(fgets(STDIN)));
    $fw = new Fenwick($n);
    $ans = 0;
    for ($i = 0; $i < $n; $i++) {
        $cur = $fw -> get($a[$i]) + 1;
        $fw -> update($a[$i], $cur);
        $ans = max($ans, $cur);
    }

    echo $ans;

<?php

    class Fenwick {
        private $n;
        private $count;

        public function __construct($n) {
            $this -> n = $n + 10;
            $this -> count = array_fill(1, $GLOBALS['n'] , 0);
        }

        public function update($i, $val) {
            for (; $i <= $GLOBALS['n']; $i += $i & -$i) $GLOBALS['count'][$i] = max($GLOBALS['count'][$i], $val);
        }

        public function get($i) {
            $max = 0;
            for (; $i > 0; $i -= $i & -$i) $max = max($max, $GLOBALS['count'][$i]);
            return $max;
        }
    }

    $n = fgets(STDIN);
    $a = explode(" ", trim(fgets(STDIN)));
    $fw = new Fenwick($n);
    $ans = 0;
    for ($i = 0; $i < $n; $i++) {
        $cur = $fw -> get($a[$i]) + 1;
        $fw -> update($a[$i], $cur);
        $ans = max($ans, $cur);
    }

    echo $ans;

<?php

    class Fenwick {
        private $n;
        private $count;

        public function __construct($n) {
            $this -> n = $n;
            $this -> count = array_fill(1, $n, 0);
        }

        public function update($i, $val) {
            for (; $i <= $this -> n; $i += $i & -$i) $this -> count[$i] = max($this -> count[$i], $val);
        }

        public function get($i) {
            $max = 0;
            for (; $i > 0; $i -= $i & -$i) $max = max($max, $this -> count[$i]);
            return $max;
        }
    }

    $n = fgets(STDIN);
    $a = explode(" ", trim(fgets(STDIN)));
    $fw = new Fenwick($n);
    $ans = 0;
    for ($i = 0; $i < $n; $i++) {
        $cur = $fw -> get($a[$i]) + 1;
        $fw -> update($a[$i], $cur);
        $ans = max($ans, $cur);
    }

    echo $ans;

<?php

    function lowerBound($dp, $l, $r, $k) {
        $ans = $r; $m = 0;
        while ($l < $r) {
            $m = $l + $r >> 1;
            if ($dp[$m] >= $k) $ans = $r = $m; else $l = $m + 1;
        }
        return $ans;
    }

    $n = fgets(STDIN);
    $a = array_reverse(explode(" ", trim(fgets(STDIN))));
    $dp = array_fill(0, $n, 0);
    $dp[0] = $a[0];
    $ans = 1;
    for ($i = 1; $i < $n; $i++) {
        if ($a[$i] > $dp[$ans - 1]) $dp[$ans++] = $a[$i];
        elseif ($a[$i] < $dp[0]) $dp[0] = $a[$i];
        else $dp[lowerBound($dp, 0, $ans, $a[$i])] = $a[$i];
    }

    echo $ans;


<?php
$stdin=fopen('php://stdin', 'r');
$caseCount = fgets($stdin);
$cases=[];
for ($i=1;$i<=$caseCount;$i++){
    fscanf($stdin, "\n%d %d %d", $str1,$str2,$str3);
    $cases[]=[$str1,$str2,$str3];
}
//print_r($cases);
$results=[];
foreach ($cases as $caseNo =>$c) {
    //Each test case
        $result_1=[];
        for ($j = 0; $j < 3; $j++) {
            $ct=$c;unset($ct[$j]);shuffle($ct);
//            die(json_encode($c));
            $c1=$ct[0];$c2=$ct[1];$c0=$c[$j];
            //Retrieved $c1,$c2 and $c0 as now value
            $diff1=($c0>$c1)?0:($c1-$c0+1);
            $diff2=($c0>$c2)?0:($c2-$c0+1);
            $result_1[]=max($diff1,$diff2);
        }
        $results[]=$result_1;
}
//print_r($results);
foreach ($results as $caseNo =>$r) {
    printf("%d %d %d",$r[0],$r[1],$r[2]);
    if($caseNo !=($caseCount-1)){print("\n");}
}

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }

    public static function res($res) {
        foreach ($res as $r) {
            echo $r . "\n";
        }
    }

    public static function dd($val){
        echo $val; exit;
    }
}

$t = IO::str();
$res = array();
while ($t--) {
    list($a,$b,$c) = IO::arr();
    $votes = array();
    if ($a == $b && $a == $c) {
        $votes[] = 1;
        $votes[] = 1;
        $votes[] = 1;
        $res[] = $votes;
        continue;
    }

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

    $fa = false;
    $fb = false;
    $fc = false;
    if ($a == $b || $a == $c) {
        $fa = true;
    }

    if ($b == $a || $b == $c) {
        $fb = true;
    }

    if ($c == $a || $c == $b) {
        $fc = true;
    }
    $win = $max + 1;

    if ($a == $max) {
        if ($fa) {
            $a = 1;
        } else {
            $a = 0;
        }
    } else {
        $a = $win - $a;
    }

    if ($b == $max) {
        if ($fb) {
            $b = 1;
        } else {
            $b = 0;
        }
    } else {
        $b = $win - $b;
    }

    if ($c == $max) {
        if ($fc) {
            $c = 1;
        } else {
            $c = 0;
        }
    } else {
        $c = $win - $c;
    }

    $votes = [$a, $b, $c];

    $res[] = $votes;
}

function setValue($a, $b, $c, $max) {
    if ($max == 0);
}

foreach ($res as $r) {
    foreach ($r as $f) {
        echo $f . ' ';
    }
    echo PHP_EOL;
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
    $aArray = [$a,$b,$c];
    $aAnswer = [];
    $k = max($aArray);
    $iCount = 0;
    foreach ($aArray as $sK => $sV) {
        if ($k == $sV) {
            $iCount++;
        }
    }
    foreach ($aArray as $sK => $sV) {
        if ($k == $sV) {
            if ($k == 0) {
                $aAnswer[] = 1;
            } else {
                if ($iCount > 1) {
                    $aAnswer[] = 1;
                } else {
                    $aAnswer[] = 0;
                }
            }
        } else {
            $aAnswer[] = ($k - $sV) + 1;
        }
    }
    echo implode(" ", $aAnswer). "\n";
}

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }

    public static function res($res) {
        foreach ($res as $r) {
            echo $r . "\n";
        }
    }

    public static function dd($val){
        echo $val; exit;
    }
}

$t = IO::str();
$res = array();
while ($t--) {
    list($a,$b,$c) = IO::arr();
    $votes = array();
    if ($a == $b && $a == $c) {
        $votes[] = $a+1;
        $votes[] = $a+1;
        $votes[] = $a+1;
        $res[] = $votes;
        continue;
    }

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

    $fa = false;
    $fb = false;
    $fc = false;
    if ($a == $b || $a == $c) {
        $fa = true;
    }

    if ($b == $a || $b == $c) {
        $fb = true;
    }

    if ($c == $a || $c == $b) {
        $fc = true;
    }
    $win = $max + 1;

    if ($a == $max) {
        if ($fa) {
            $a = 1;
        } else {
            $a = 0;
        }
    } else {
        $a = $win - $a;
    }

    if ($b == $max) {
        if ($fb) {
            $b = 1;
        } else {
            $b = 0;
        }
    } else {
        $b = $win - $b;
    }

    if ($c == $max) {
        if ($fc) {
            $c = 1;
        } else {
            $c = 0;
        }
    } else {
        $c = $win - $c;
    }

    $votes = [$a, $b, $c];

    $res[] = $votes;
}

function setValue($a, $b, $c, $max) {
    if ($max == 0);
}

foreach ($res as $r) {
    foreach ($r as $f) {
        echo $f . ' ';
    }
    echo PHP_EOL;
}

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }

    public static function res($res) {
        foreach ($res as $r) {
            echo $r . "\n";
        }
    }

    public static function dd($val){
        echo $val; exit;
    }
}

$t = IO::str();
$res = array();
while ($t--) {
    list($a,$b,$c) = IO::arr();
    $votes = array();
    if ($a == $b && $a == $c) {
        $votes[] = $a+1;
        $votes[] = $a+1;
        $votes[] = $a+1;
        $res[] = $votes;
        continue;
    }

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

    if ($a - $max == 0) {
        $votes[] = 0;
        $votes[] = $max - $b + 1;
        $votes[] = $max - $c + 1;
    } else if ($b - $max == 0) {
        $votes[] = $max - $a + 1;
        $votes[] = 0;
        $votes[] = $max - $c + 1;
    } else if ($c - $max == 0) {
        $votes[] = $max - $a + 1;
        $votes[] = $max - $b + 1;
        $votes[] = 0;
    }

    $res[] = $votes;
}

foreach ($res as $r) {
    foreach ($r as $f) {
        echo $f . ' ';
    }
    echo PHP_EOL;
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
    $aArray = [$a,$b,$c];
    $aAnswer = [];
    $k = max($aArray);
    foreach ($aArray as $sK => $sV) {
        if ($k == $sV) {
            if ($k == 0) {
                $aAnswer[] = 1;
            } else {
                $aAnswer[] = 0;
            }
        } else {
            $aAnswer[] = ($k - $sV) + 1;
        }
    }
    echo implode(" ", $aAnswer). "\n";
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
    if ($a == $b && $b == $c) {
        echo 1 . " " . 1 . " " . 1 . "\n";;
    } else {
        $aArray = [$a,$b,$c];
        $aAnswer = [];
        $k = max($aArray);
        foreach ($aArray as $sK => $sV) {
            if ($k == $sV) {
                $aAnswer[] = 0;
            } else {
                $aAnswer[] = $k - $sV + 1;
            }
        }
        echo implode(" ", $aAnswer). "\n";
    }
}

<?php
$stdin=fopen('php://stdin', 'r');
$caseCount = fgets($stdin);
$cases=[];
for ($i=1;$i<=$caseCount;$i++){
    fscanf($stdin, "\n%d %d %d", $str1,$str2,$str3);
    $cases[]=[$str1,$str2,$str3];
}
print_r($cases);
$results=[];
foreach ($cases as $caseNo =>$c) {
    //Each test case
        $result_1=[];
        for ($j = 0; $j < 3; $j++) {
            $ct=$c;unset($ct[$j]);shuffle($ct);
//            die(json_encode($c));
            $c1=$ct[0];$c2=$ct[1];$c0=$c[$j];
            //Retrieved $c1,$c2 and $c0 as now value
            $diff1=($c0>$c1)?0:($c1-$c0+1);
            $diff2=($c0>$c2)?0:($c2-$c0+1);
            $result_1[]=max($diff1,$diff2);
        }
        $results[]=$result_1;
}
//print_r($results);
foreach ($results as $caseNo =>$r) {
    printf("%d %d %d",$r[0],$r[1],$r[2]);
    if($caseNo !=($caseCount-1)){print("\n");}
}


<?php

$commands = readInput();
$zingerTower = new Zinger();

foreach ($commands as $command) {
    $zingerTower->handleCommand($command);
}

echo $zingerTower->getColor();

class Zinger
{
    const LOCK_COMMAND = 'lock';
    const UNLOCK_COMMAND = 'unlock';
    static $colorCommands = [
        'red',
        'orange',
        'yellow',
        'green',
        'blue',
        'indigo',
        'violet',
    ];

    private $isLocked = false;
    private $color = 'blue';

    public function handleCommand(string $command): void
    {
        switch ($command) {
            case self::LOCK_COMMAND: $this->lock(); break;
            case self::UNLOCK_COMMAND: $this->unlock(); break;
            case in_array($command, self::$colorCommands): $this->changeColor($command);break;
            default: echo 'command undefined';
        }
    }

    public function getColor(): string
    {
        return $this->color;
    }

    private function lock(): void
    {
        if ($this->isLocked) {
            return;
        }

        $this->isLocked = true;
    }

    private function unlock(): void
    {
        if (!$this->isLocked) {
            return;
        }

        $this->isLocked = false;
    }

    private function changeColor(string $color): void
    {
        if ($this->isLocked) {
            return;
        }

        $this->color = $color;
    }
}

function readInput()
{
    $commandsCount = trim(fgets(STDIN));
    if (empty($commandsCount)) {
        return [];
    }

    $result = [];

    for ($i = 0; $i < $commandsCount; $i++) {
        $result[] = trim(fgets(STDIN));
    }

    return $result;
}

<?php

$color = 'blue';
$locked = false;

$value = fgets(STDIN); //skip first line
while($value = fgets(STDIN)){
    $value = trim($value);
    if ($value === 'lock') {
        $locked = true;
        continue;
    }
    if ($value === 'unlock') {
        $locked = false;
        continue;
    }
    if ($locked) {
        continue;
    }
    $color = $value;
}

fwrite(STDOUT, $color);

<?php
fscanf(STDIN, "%d", $n);
$result = [0, 'blue'];
while ($n--) {
    fscanf(STDIN, "%s", $value);
    if ('unlock' == $value) $result[0] = 0;
    elseif ('lock' == $value) $result[0] = 1;
    elseif (empty($result[0])) $result[1] = $value;
}
echo $result[1], "\n";

<?php
	$in = 'php://stdin';
//	$in = 'input.txt';

	$input = fopen($in, "r");

	$lock = false;

	$lastColor = 'blue';

    $i = 0;
    while ($buf = trim(fgets($input))) {
	    $actions[]=$buf;
    }

    $count = count($actions) - 1;

    if($count != $actions[0] || $actions[0] < 1 || $actions[0] > 100){
        echo $lastColor;
    }else{

       foreach ($actions as $i => $action){

        if($i==0) continue;

	    if($action == 'lock'){
	       $lock = true;
	    }
	    if($action == 'unlock'){
	           $lock = false;
	    }
	    if($action != 'unlock' && $action != 'lock' && !$lock){
	           $lastColor = $action;
	    }

    }

        echo $lastColor;
    }
?>

<?php
$index = 0;
$amount_of_lines = 0;
$current_color = 'blue';
$locked = false;
do {
	$line = trim(fgets(STDIN));
    if ($index === 0) {
        $amount_of_lines = $line;
    } else {
    	if ($line === 'lock') {
    		$locked = true;
    	} elseif ($line === 'unlock') {
    		$locked = false;
    	} elseif (!$locked) {
	        $current_color = $line;
	    }
    }
    $index++;

} while ($index <= $amount_of_lines);
echo $current_color;
?>

<?php

$n = (int)trim(fgets(STDIN));
$i = 0;
$color = 'blue';
$alloved_colors = explode('/', 'red/orange/yellow/green/blue/indigo/violet');
$is_locked = false;
while ($i < $n) {
    $cmd = trim(fgets(STDIN));
    if ($cmd === 'unlock' && $is_locked) {
        $is_locked = false;
        continue;
    }

    if ($cmd === 'lock' && !$is_locked) {
        $is_locked = true;
        continue;
    }

    if (in_array($cmd, $alloved_colors, true)) {
        if ($is_locked) {
            continue;
        }
        $color = $cmd;
    }

    $i ++;
}
echo $color;

<?php
$index = 0;
$amount_of_lines = 0;
$current_color = 'blue';
$locked = false;
do {
	$line = trim(fgets(STDIN));
    if ($index === 0) {
        $amount_of_lines = $line;
    } else {
    	if ($line === 'lock') {
    		$locked = true;
    	} elseif ($line === 'unlock') {
    		$locked = false;
    	} elseif (!$locked) {
	        $current_color = $line;
	    }
    }
    echo ($current_color . " ") . ($locked ? 'locked' : 'unlocked') . PHP_EOL;
    $index++;

} while ($index <= $amount_of_lines);
echo $current_color;
?>

<?php
$index = 0;
$amount_of_lines = 0;
$current_color = 'blue';
$locked = false;
do {
	$line = fgets(STDIN);
    if ($index === 0) {
        $amount_of_lines = $line;
    } else {
    	if ($line === 'lock') {
    		$locked = true;
    	} elseif ($line === 'unlock') {
    		$locked = false;
    	} elseif (!$locked) {
	        $current_color = $line;
	    }
    }
    $index++;

} while ($index <= $amount_of_lines);
echo $current_color;
?>

<?php

$n = (int)trim(fgets(STDIN));
$i = 0;
$color = '';
$alloved_colors = explode('/', 'red/orange/yellow/green/blue/indigo/violet');
$is_locked = false;
while ($i < $n) {
    $cmd = trim(fgets(STDIN));
    if ($cmd === 'unlock' && $is_locked) {
        $is_locked = false;
        continue;
    }

    if ($cmd === 'lock' && !$is_locked) {
        $is_locked = true;
        continue;
    }

    if (in_array($cmd, $alloved_colors, true)) {
        if ($is_locked) {
            continue;
        }
        $color = $cmd;
    }

    $i ++;
}
echo $color;

<?php

$commands = readInput();
$zingerTower = new Zinger();

foreach ($commands as $command) {
    $zingerTower->handleCommand($command);
}

echo $zingerTower->getColor();

class Zinger
{
    const LOCK_COMMAND = 'lock';
    const UNLOCK_COMMAND = 'unlock';
    static $colorCommands = [
        'red',
        'orange',
        'yellow',
        'green',
        'blue',
        'indigo',
        'violet',
    ];

    private $isLocked = false;
    private $color = 'blue';

    public function handleCommand(string $command): void
    {
        switch ($command) {
            case self::LOCK_COMMAND: $this->lock(); break;
            case self::UNLOCK_COMMAND: $this->unlock(); break;
            case in_array($command, self::$colorCommands): $this->changeColor($command);break;
            default: echo 'command undefined';
        }
    }

    public function getColor(): string
    {
        return $this->color;
    }

    private function lock(): void
    {
        if ($this->isLocked) {
            return;
        }

        $this->isLocked = true;
    }

    private function unlock(): void
    {
        if (!$this->isLocked) {
            return;
        }

        $this->isLocked = true;
    }

    private function changeColor(string $color): void
    {
        if ($this->isLocked) {
            return;
        }

        $this->color = $color;
    }
}

function readInput()
{
    $commandsCount = trim(fgets(STDIN));
    if (empty($commandsCount)) {
        return [];
    }

    $result = [];

    for ($i = 0; $i < $commandsCount; $i++) {
        $result[] = trim(fgets(STDIN));
    }

    return $result;
}


<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

list($xa, $ya) = $ir->readArrayOfInt(2);
list($xb, $yb) = $ir->readArrayOfInt(2);
list($xc, $yc) = $ir->readArrayOfInt(2);

$xs = [$xa, $xb, $xc];
$ys = [$ya, $yb, $yc];
sort($ys);
sort($xs);

$ymid = $ys[1];

$trace = [];
for ($i=$xs[0]; $i<=$xs[2]; $i++) {
	$trace[$i." ".$ys[1]] = true;
}

for ($i=min([$ya,$ys[1]]); $i<=max([$ya,$ys[1]]); $i++) {
	$trace[$xa." ".$i] = true;
}

for ($i=min([$yb,$ys[1]]); $i<=max([$yb,$ys[1]]); $i++) {
	$trace[$xb." ".$i] = true;
}

for ($i=min([$yc,$ys[1]]); $i<=max([$yc,$ys[1]]); $i++) {
	$trace[$xc." ".$i] = true;
}

echo count($trace)."\n";
foreach ($trace as $k=>$v) {
	echo $k."\n";
}