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

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

for ($i = 0; $i < $n; $i++) {
  $str = trim(fgets($file));

  $a = str_split($str);
  $a = array_count_values($a);

  sort($a);
  $c = 0; $k = 0;
  for ($j = 0; $j < count($a); $j++) {
    if ($a[$j] == 1) { $c++; }
    if ($a[$j] > 1) { break; }
  }
  $k = count($a) - $c;
  $c = floor($c / 2);
  $ans = $c + $k;
  echo $ans.PHP_EOL;
}

?>

<?php

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

for ($j = 0; $j < $n; $j++) {
    list($line) = explode(' ', trim(fgets(STDIN)));
    $table = [];
    for ($i=0;$i<strlen($line);$i++) {
        if (!isset($table[$line[$i]])) {
            $table[$line[$i]] = 1;
        } else if($table[$line[$i]] == 1) {
            $table[$line[$i]] = 2;
        }
    }
    $cnt = array_sum($table);
    echo floor($cnt/2) . "\n";
}

?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($sSymbol) = explode(' ', trim(fgets(STDIN)));
    $aArray = [];
    for ($i = 0; $i < strlen($sSymbol); $i++) {
        if (!isset($aArray[$sSymbol[$i]])) {
            $aArray[$sSymbol[$i]] = 1;
        } else {
            if ($aArray[$sSymbol[$i]] == 1) {
                $aArray[$sSymbol[$i]] = 2;
            }
        }
    }
    $iCount = array_sum($aArray);
    echo floor($iCount/2) . "\n";
}

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    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 asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    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;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = [];
    $res = 0;
    foreach ($a as $v) {
        if (isset($b[$v])) {
            $b[$v] += 1;
        } else {
            $b[$v] = 1;
        }
    }
    $t = 0;
    foreach ($b as $k => $v) {
        if ($v >= 2) {
            $res++;
        } else {
            $t++;
        }
    }
    $res += floor($t / 2);
    IO::line($res);
}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    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 asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    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;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = [];
    $res = 0;
    foreach ($a as $v) {
        if (isset($b[$v])) {
            $b[$v] += 1;
        } else {
            $b[$v] = 1;
        }
    }
    $res = min(floor(count($a) / 2), count($b));
    if (count($b) == 1 && count($a) < 2) {
        $res = 0;
    }

    IO::line($res);
}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    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 asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    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;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = [];
    $res = 0;
    foreach ($a as $v) {
        if (isset($b[$v])) {
            $b[$v] += 1;
        } else {
            $b[$v] = 1;
        }
    }
    $res = min(floor(count($a) / 2), count($b));
    if (count($b) == 1) {
        $res = 0;
    }

    IO::line($res);
}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    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 asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    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;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = [];
    $res = 0;
    foreach ($a as $v) {
        if (isset($b[$v])) {
            $b[$v] += 1;
        } else {
            $b[$v] = 1;
        }
    }
    $res = min(floor(count($a) / 2), count($b));
    if (count($b) == 0) {
        $res = 0;
    }

    IO::line($res);
}

?>


<?php

###### IO ######

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

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

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

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

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

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

###### /IO ######
$n = readNum(STDIN);
	$nums = readStringExplodeNum(STDIN);
	sort($nums);

	$a = $b = array();
	$isError = false;
	for ($i = 0; $i <= $n / 2; $i++) {
		if (empty($nums)) {
			break;
		}
		$num = array_shift($nums);
		if (empty($a)) {
			$a[$i] = $num;
		} else {
			if ($a[$i - 1] > $num) {
				$isError = true;
				break;
			}
			$a[$i] = $num;
		}

		$num = array_pop($nums);
		if (empty($b)) {
			$b[$i] = $num;
		} else {
			if ($b[$i - 1] < $num) {
				$isError = true;
				break;
			}
			$b[$i] = $num;
		}
	}
	if ($isError) {
		echo 'Impossible';
	} else {
		foreach ($a as $i => $num) {
			echo $a[$i] . ' ' . $b[$i] . ' ';
		}
	}


<?php

$n = (int) fgets(STDIN);
$nums = array_map('intval', explode(' ', fgets(STDIN)));

rsort($nums);

$id = (int) (count($nums) / 2);

echo $nums[$id];

<?php
$board = array ();
$n  = null;          // Number of elements in board
$p1 = true;          // Wants to minimize the last number = select the maximum
                     // p2 Wants to maximize the last number = select the minimum

/* Input */
$n                = intval (readline ());
$string_of_values = readline ();
// Fill board
$board = explode (" ", $string_of_values);
unset ($string_of_values);

/* Process */
sort ($board);
while ($n > 1)
{
        if ($p1)
        {
                $p1 = false;
                array_pop ($board);
        }
        else
        {
                $p1 = true;
                array_shift ($board);
        }
        --$n;
}

/* Output */
echo $board[0];

<?php
  $w = fgets(STDIN);
  $s = explode(' ', trim(fgets(STDIN)));

  sort($s);
  if(!($w%2)) echo $s[$w/2 -1];
  else        echo $s[$w/2];
?>

<?php

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

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

$numbers = array_map('intval', explode(' ', trim(fgets($handle))));

sort($numbers);

echo $numbers[floor(($d - 1) / 2)];

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = 0;
for($x = 0; $x < $a - 1; $x++)
{
     $d = $c % 2;
     $c++;
     if($d == 0)
     {
          array_splice($b, -1);
     }
     else
     {
          array_splice($b, 0, 1);
     }
}
print $b[0]
?>

<?php

$n = readline();
$ara = explode(' ', readline());

rsort($ara);

echo (($n/2==0)?$ara[intval($n/2)-1]:$ara[floor($n/2)]);

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

$numbers = explode(' ', trim(fgets(STDIN)));

sort($numbers);

$m = floor(($n - 1)/2);

echo $numbers[$m];

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

$numbers = explode(' ', trim(fgets(STDIN)));

sort($numbers);

if (count($numbers) > 1) {
    echo $numbers[1];
} else {
    echo $numbers[0];
}

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

$numbers = explode(' ', trim(fgets(STDIN)));

sort($numbers);

$m = floor($n/2);

echo $numbers[$m];

<?php

$n = (int) fgets(STDIN);
$nums = array_map('intval', explode(' ', fgets(STDIN)));

sort($nums);

$middle = (int) ceil(count($nums) / 2);

echo $nums[$middle];

<?php

$n = (int) fgets(STDIN);
$nums = array_map('intval', explode(' ', fgets(STDIN)));

sort($nums);

$id = (int) (count($nums) / 2);

echo $nums[$id];

// 38 82 23 37 96 4 81 60 67 86
// 1 2 3 4

<?php

$n = (int) fgets(STDIN);
$nums = array_map('intval', explode(' ', fgets(STDIN)));

sort($nums);

$middle = (int) floor(count($nums) / 2);

echo $nums[$middle];

<?php

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

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

$numbers = array_map('intval', explode(' ', trim(fgets($handle))));

sort($numbers);

echo $numbers[floor($d / 2)];

<?php

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

fscanf($handle, "%i %i", $n, $m);

$field = [];
$bombs = [];

$totalSum = 0;

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

    $row = str_split(trim(fgets($handle)));

    for ($j = 0; $j < $m; $j++) {

        if ($row[$j] == '*') {

            if (!isset($bombs[$i])) {
                $bombs[$i] = [];
            }

            $bombs[$i][] = $j;
        } elseif ($row[$j] != '.') {

            $row[$j] = intval($row[$j]);;
            $totalSum += $row[$j];
        }
    }

    $field[] = $row;
}

$result = 'YES';

foreach ($bombs as $row => $cols) {

    foreach ($cols as $col) {

        $numCount = 0;

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

            for ($j = -1; $j < 2; $j++) {

                if ($i != 0 || $j != 0) {

                    if (isset($field[$row + $i][$col + $j])) {

                        $val = $field[$row + $i][$col + $j];

                        if ($val == '.' || ($val != '*' && $val == 0)) {

                            $result = 'NO';
                            break;
                        } elseif ($val != '*') {

                            $numCount++;
                            $field[$row + $i][$col + $j]--;
                            $totalSum--;
                        }
                    }
                }
            }
        }
    }

    if ($result == 'NO') {
        break;
    }
}

if ($totalSum != 0) {
    $result = 'NO';
}

echo $result;


<?php

$times = (int)trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($hi[], $mi[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    list($hhi[], $mmi[]) = array_map('intval', explode(':', trim(fgets(STDIN))));
}

$mirror = [0, 1, 5, -1, -1, 2, -1, -1, 8, -1];
for ($idx = 0; $idx < $times; ++$idx) {
    $h = &$hi[$idx];
    $m = &$mi[$idx];
    $hh = &$hhi[$idx];
    $mm = &$mmi[$idx];
    for ($i = 0; $i < $h * $m; ++$i) {
        $cur = $hh * $m + $mm + $i;
        $cur1 = sprintf('%02d', floor(($cur % ($h * $m)) / $m));
        $cur2 = sprintf('%02d', $cur % $m);
        $s = strrev($cur1 . $cur2);
        $t = '';
        for ($j = 0; $j < 4; ++$j) {
            if ($mirror[$s[$j]] < 0) {
                continue 2;
            } else {
                $t .= $mirror[$s[$j]];
            }
        }
        if (substr($t, 0, 2) < $h && substr($t, 2, 2) < $m) {
            echo $cur1 . ':' . $cur2 . PHP_EOL;
            continue 2;
        }
    }
}

<?php
	$t = trim(fgets(STDIN));
	function check_reversed_number_if_valid_please($str, $h, $m) {
		$str2 = "";
		$reversable = [0, 1, 2, 5, 8];
		for ($i = 4; $i >= 0; $i--) {
			if (in_array(intval($str[$i]), $reversable) || $str[$i] == ':') {
				$str2 .= (intval($str[$i]) == 2 ? '5' : (intval($str[$i]) == 5 ? '2' : $str[$i]));
			} else {
				return false;
			}
		}
		list($h2, $m2) = explode(":", $str2);
		if (intval($h2) >= $h || intval($m2) >= $m) {
			return false;
		}
		return true;
	}

	function increment_time_minutes_please($str, $h, $m) {
		list($h2, $m2) = explode(":", $str);
		$h2 = intval($h2);
		$m2 = intval($m2);
		if ($m2 + 1 == $m) {
			$h2++;
			$m2 = 0;
		} else {
			$m2++;
		}
		if ($h2 == $h) {
			$h2 = 0;
		}

		return ($h2 >= 10 ? $h2 : "0".$h2).":".($m2 >= 10 ? $m2 : "0".$m2);
	}

	for ($o = 0; $o < $t; $o++) {
		list($h, $m) = explode(" ", trim(fgets(STDIN)));
		$time = trim(fgets(STDIN));
		for ($i = 0; $i < $h*$m; $i++)
			if (check_reversed_number_if_valid_please($time, $h, $m)) {
				print $time."\n";
				break;
			} else {
				$time = increment_time_minutes_please($time, $h, $m);
			}
		}
?>


<?php
fscanf(STDIN, '%d %d', $n, $m);
$st=array();
for($i=0; $i<$n; $i++) $st[$i]=explode(" ", fgets(STDIN));

$count = 0;
$row = 0;
$zeros = 0;
$zeros_temp = 0;

for($i=0; $i<$n; $i++){
  for($j=0; $j<$m; $j++){
    if($st[$i][$j] == 0){
        if($row) $count++;
        $zeros_temp++;
    }
    else{
        $row = 1;
        $zeros += $zeros_temp;
        $zeros_temp = 0;
    }
  }
  $count += $zeros;
  $row = 0;
  $zeros = 0;
  $zeros_temp = 0;
}

for($j=0; $j<$m; $j++){
  for($i=0; $i<$n; $i++){
    if($st[$i][$j] == 0){
        if($row) $count++;
        $zeros_temp++;
    }
    else{
        $row = 1;
        $zeros += $zeros_temp;
        $zeros_temp = 0;
    }
  }
  $count += $zeros;
  $row = 0;
  $zeros = 0;
  $zeros_temp = 0;
}

print $count;
?>

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n, m, k, i, j, count=0;
    cin>>n>>m;

    int st[n][m];
    for(i = 0; i < n; i++)
		for(j = 0; j < m; j++)
		cin >> st[i][j];

	for(i=0; i<n; i++){
  for(j=0; j<m; j++){
    if(st[i][j] == 0){
      //top
      for(k=0; k<i; k++){
        if(st[k][j] == 1){
          count++;
          break;
        }
      }

      //bottom
      for(k=i+1; k<n; k++){
        if(st[k][j] == 1){
          count++;
          break;
        }
      }

      //left
      for(k=0; k<j; k++){
        if(st[i][k] == 1){
          count++;
          break;
        }
      }

      //right
      for(k=j+1; k<m; k++){
        if(st[i][k] == 1){
          count++;
          break;
        }
      }
    }
  }
}

cout<<count;

    return 0;
}


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = explode(" ", trim(fgets(STDIN)));
     $e = array_unique($d);
     sort($e);
     $f = array_fill(1, 1000, 0);
     for($y = 0; $y < count($e); $y++)
     {
          $f[$e[$y]] = 1;
     }
     for($y = 1; $y <= count($f); $y++)
     {
          if($f[$y] == TRUE)
          {
               continue;
          }
          else
          {
               $c--;
               if($c == 0)
               {
                    for($z = $y + 1; $z <= count($f); $z++)
                    {
                         if($f[$z] == FALSE)
                         {
                              break;
                         }
                    }
                    break;
               }
          }
     }
     print $z - 1 . "\n";
}
?>

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $in_str = explode(" ", trim(fgets(STDIN))) ;

        $n = intval($in_str[0]) ;
        $x = intval($in_str[1]) ;

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

        $f = array_fill(0, 201, false) ;
        for($i = 0; $i < $n; $i ++)
        {
            $in_str[$i] = intval($in_str[$i]) ;

            $f[$in_str[$i]] = true ;
        }

        $ans = 0 ;
        for($i = 1; $i <= 200; $i ++)
        {
            if($f[$i])
            {
                $ans = $i ;
                continue ;
            }

            if($x > 0) $x -- ;
            else break ;
            $ans = $i;
        }
        echo $ans + $x . "\n" ;
    }
?>

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $in_str = explode(" ", trim(fgets(STDIN))) ;

        $n = intval($in_str[0]) ;
        $x = intval($in_str[1]) ;

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

        $f = array_fill(0, 201, false) ;
        for($i = 0; $i < $n; $i ++)
        {
            $in_str[$i] = intval($in_str[$i]) ;

            $f[$in_str[$i]] = true ;
        }

        $ans = 0 ;
        for($i = 1; $i <= 200; $i ++)
        {
            if($f[$i]) continue ;

            if($x > 0) $x -- ;
            else
            {
                $ans = $i - 1 ;
                break ;
            }
        }
        echo $ans + $x . "\n" ;
    }
?>

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $in_str = explode(" ", trim(fgets(STDIN))) ;

        $n = intval($in_str[0]) ;
        $x = intval($in_str[1]) ;

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

        $f = array_fill(0, 201, false) ;
        for($i = 0; $i < $n; $i ++)
        {
            $in_str[$i] = intval($in_str[$i]) ;

            $f[$in_str[$i]] = true ;
        }

        $ans = 0 ;
        for($i = 1; $i <= 200; $i ++)
        {
            if($f[$i]) continue ;

            if($x > 0) $x -- ;
            else break ;
            $ans = $i;
        }
        echo $ans + $x . "\n" ;
    }
?>

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $in_str = explode(" ", trim(fgets(STDIN))) ;

        $n = intval($in_str[0]) ;
        $x = intval($in_str[1]) ;

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

        $f = array_fill(0, 201, false) ;
        for($i = 0; $i < $n; $i ++)
        {
            $in_str[$i] = intval($in_str[$i]) ;

            $f[$in_str[$i]] = true ;
        }

        $ans = 0 ;
        for($i = 1; $i <= 200; $i ++)
        {
            if($f[$i]) continue ;

            if($x > 0) $x -- ;
            else
            {
                $ans = $i - 1 ;
                break ;
            }
        }
        echo $ans . "\n" ;
    }
?>


<?php
$i = 1;

$handle = @fopen('input.txt', 'r');
list($hTotal, $hRead) = explode(' ', trim(fgets($handle)));
$hList = explode(' ', '101 '.fgets($handle));
fclose($handle);

arsort ($hList, SORT_NUMERIC);
$newhList = array_slice($hList, 1, $hRead, true );

$handle = @fopen('output.txt', 'w');
fputs($handle, end($newhList)."\n");
fputs($handle, implode(' ',array_keys($newhList)));
fclose($handle);

<?php
$i = 1;

$handle = @fopen('input.txt', 'r');
list($hTotal, $hRead) = explode(' ', trim(fgets($handle)));
$hList = explode(' ', '101 '.fgets($handle));
fclose($handle);

arsort ($hList);
$newhList = array_slice($hList, 1, $hRead, true );

$handle = @fopen('output.txt', 'w');

if (count($newhList)>3){
fputs($handle, var_export($hList, true)."\n");
fputs($handle, var_export($newhList, true)."\n");
}
fputs($handle, end($newhList)."\n");
fputs($handle, implode(' ',array_keys($newhList)));
fclose($handle);

<?php
$i = 1;

$handle = @fopen('input.txt', 'r');
list($hTotal, $hRead) = explode(' ', trim(fgets($handle)));
$hList = explode(' ', fgets($handle));
fclose($handle);

array_unshift($hList, PHP_INT_MAX);
arsort ($hList);
$newhList = array_slice($hList, 1, $hRead, true );

$handle = @fopen('output.txt', 'w');
fputs($handle, end($newhList)."\n");
fputs($handle, implode(' ',array_keys($newhList)));
fclose($handle);

<?php
$i = 1;

$handle = @fopen('input.txt', 'r');
list($hTotal, $hRead) = explode(' ', trim(fgets($handle)));
$hList = explode(' ', '101 '.fgets($handle));
fclose($handle);

arsort ($hList);
$newhList = array_slice($hList, 1, $hRead, true );

$handle = @fopen('output.txt', 'w');
fputs($handle, var_export($newhList, true)."\n");
fputs($handle, end($newhList)." your checker REALLY SUCKS! \n");
fputs($handle, implode(' ',array_keys($newhList)));
fclose($handle);

<?php
/*
$time_start = microtime(true);
$mem_start = memory_get_usage();
*/
$i = 1;

$handle = @fopen('c:/input.txt', 'r');
list($hTotal, $hRead) = explode(' ', trim(fgets($handle)));
$hList = explode(' ', fgets($handle));
fclose($handle);

array_unshift($hList, PHP_INT_MAX);
arsort ($hList);
$hList = array_slice($hList, 1, $hRead, true );

$handle = @fopen('c:/output.txt', 'w');
fputs($handle, end($hList)."\n");
fputs($handle, implode(' ',array_keys($hList)));
fclose($handle);

/*
$mem_end = memory_get_usage();
$time_end = microtime(true);
echo "Time: ", ($time_end - $time_start)*1000, " MSec\n";
echo "Memory: ", ($mem_end - $mem_start)/1024, " Kb\n";
*/

<?php
/*
$time_start = microtime(true);
$mem_start = memory_get_usage();
*/
$i = 1;

//$handle = @fopen('c:/input.txt', 'r');
$handle = @fopen('input.txt', 'r');
list($hTotal, $hRead) = explode(' ', trim(fgets($handle)));
$hList = explode(' ', fgets($handle));
fclose($handle);

array_unshift($hList, PHP_INT_MAX);
arsort ($hList);
$hList = array_slice($hList, 1, $hRead, true );

//$handle = @fopen('c:/output.txt', 'w');
$handle = @fopen('output.txt', 'w');
fputs($handle, end($hList)."\n");
fputs($handle, implode(' ',array_keys($hList)));
fclose($handle);

/*
$mem_end = memory_get_usage();
$time_end = microtime(true);
echo "Time: ", ($time_end - $time_start)*1000, " MSec\n";
echo "Memory: ", ($mem_end - $mem_start)/1024, " Kb\n";
*/

<?php
$i = 1;

$handle = @fopen('input.txt', 'r');
list($hTotal, $hRead) = explode(' ', trim(fgets($handle)));
$hList = explode(' ', '101 '.fgets($handle));
fclose($handle);

arsort ($hList);
$newhList = array_slice($hList, 1, $hRead, true );

$handle = @fopen('output.txt', 'w');

if (count($newhList)>3){
fputs($handle, var_export($newhList, true)."\n");
}
fputs($handle, end($newhList)."\n");
fputs($handle, implode(' ',array_keys($newhList)));
fclose($handle);

<?php
$i = 1;

$handle = @fopen('input.txt', 'r');
list($hTotal, $hRead) = explode(' ', trim(fgets($handle)));
$hList = explode(' ', '101 '.fgets($handle));
fclose($handle);

arsort ($hList);
$newhList = array_slice($hList, 1, $hRead, true );

$handle = @fopen('output.txt', 'w');
fputs($handle, end($newhList)."\n");
fputs($handle, implode(' ',array_keys($newhList)));
fclose($handle);

<?php
/*
$time_start = microtime(true);
$mem_start = memory_get_usage();
*/
$i = 1;

//$handle = @fopen('c:/input.txt', 'r');
$handle = @fopen('input.txt', 'r');
list($hTotal, $hRead) = explode(' ', trim(fgets($handle)));
$hList = explode(' ', fgets($handle));
fclose($handle);

array_unshift($hList, 101);
arsort ($hList);
$hList = array_slice($hList, 1, $hRead, true );

//$handle = @fopen('c:/output.txt', 'w');
$handle = @fopen('output.txt', 'w');
fputs($handle, end($hList)."\n");
fputs($handle, implode(' ',array_keys($hList)));
fclose($handle);

/*
$mem_end = memory_get_usage();
$time_end = microtime(true);
echo "Time: ", ($time_end - $time_start)*1000, " MSec\n";
echo "Memory: ", ($mem_end - $mem_start)/1024, " Kb\n";
*/


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$n = trim(fgets($file));
$pArray = array();
for ($i = 2; $i <= $n; $i++) {

    if (isPrime($i)) {
        $c = 0;
        $t = $n;
        while ($t>=$i) {
            $t /= $i;
            $c++;
        }
        if ($c>0) {
            $pArray[$i] = $c;
            $c = 0;
        }
    }
}
function isPrime($x)
{
    $k = floor(sqrt($x)) + 1;
    $result = true;
    for ($i = 2; $i < $k; $i++) {
        if ($x % $i ==0) {
            $result = false;
            break;
        }
    }
    return $result;
}

$r = array();
foreach ($pArray as $p => $q) {
    for ($i = 1; $i <= $q; $i++) {
        $r[] = pow($p, $i);
    }
}
echo count($r).PHP_EOL;
echo implode(" ", $r);


<?php
// input
$in = 'php://stdin';
$input = fopen($in, "r");
$temp = explode(" ", trim(fgets($input)));
$n = $temp[0];
$t = $temp[1];
$a = explode(" ", trim(fgets($input)));

$total = 0;
$count = 0;
$iStart = 0;

$cMax = 0;

for($i = $iStart; $i < $n; $i++){
    $tempTotal = $a[$i] + $total;
    if($tempTotal <= $t){
        $total = $tempTotal;
        $count++;
        continue;
    }

    if($cMax < $count){
        $cMax = $count;
    }

    $total-=$a[$iStart];
    $count--;
    $iStart++;
    $i--;
}

echo $cMax > $count ? $cMax : $count;

<?php
    $arr = explode(' ',  trim(fgets(STDIN)));
    $n = $arr[0];
    $t = $arr[1];
    $arr = explode(' ',  trim(fgets(STDIN)));
    $sum = $arr[0];
    $r = 0;
    $retInt = 0;
    for ($i=0; $i<$n; $i++)
    {
        $left = $i;
        while ($sum<=$t && $r<$n)
        {
            $r++;
            $sum+=$arr[$r];
        }
        $retInt = max($retInt, $r-$left);
        $sum -= $arr[$left];
    }
    echo $retInt;

?>

<?php
// Books

// input
$in = 'php://stdin';
$input = fopen($in, "r");
$temp = explode(" ", trim(fgets($input)));
$n = $temp[0];
$t = $temp[1];
$a = explode(" ", trim(fgets($input)));

// Solve
// Your code here

function test($n,$arr,$time){
    $max = 0;
    $temp = 0;
    $old = 0;
    $count = 0;
    for($i = 0; $i < $n;$i++) {
        $temp += $arr[$i];
        $count++;
        if ($temp > $time) {
            $max = $max > ($count -1) ? $max : ($count -1);
            $count -= 1;
            $old = $arr[$i - $count];
            $temp -=$old;
        }
        else if($i == $n-1){
            $max = $max > ($count) ? $max : ($count);
        }
    }
    echo $max;
}

test($n,$a,$t);

<?php
// Books

// input
$in = 'php://stdin';
$input = fopen($in, "r");
$temp = explode(" ", trim(fgets($input)));
$n = $temp[0];
$t = $temp[1];
$a = explode(" ", trim(fgets($input)));

// Solve
$left = 0;
$right = 0;
$sum = 0;
$maxBooks = 0;
while ($right < $n) {
    if ($sum + $a[$right] <= $t) {
        $sum += $a[$right];
        if ($right - $left + 1 > $maxBooks) {
            $maxBooks = $right - $left + 1;
        }
    } else {
        $sum -= $a[$left];
        $left++;
        $right--;
    }
    $right++;
}
echo ($maxBooks);

<?php
$in = 'php://stdin';

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

[$n, $t] = explode(" ", trim(fgets($input)));

$a = explode(" ", trim(fgets($input)));

$s = 0;
$start = 0;
$maxLength = 0;

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

    if ($s > $t) {

        $temp = $i - $start;

        if ($temp > $maxLength) {
            $maxLength = $temp;
        }

        $s -= (int) $a[$start];
        $start++;
    }
}

if ($s <= $t) {
    $temp = $n - $start;

    if ($temp > $maxLength) {
        $maxLength = $temp;
    }
}

echo $maxLength < 0 ? 0 : $maxLength;

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

<?php
    $arr = explode(' ',  trim(fgets(STDIN)));
    $n = $arr[0];
    $t = $arr[1];
    $arr = explode(' ',  trim(fgets(STDIN)));
    $sum = $arr[0];
    $r = 0;
    $retInt = 0;
    for ($i=0; $i<$n; $i++)
    {
        $left = $i;
        while ($sum<=$t && $r<$n)
        {
            $r++;
            $sum+=$arr[$r];
        }
        $retInt = max($retInt, $r-$left);
        $sum -= $arr[$left];
    }
    $retInt++;
    echo $retInt;

?>

<?php
// input
$in = 'php://stdin';
$input = fopen($in, "r");
$temp = explode(" ", trim(fgets($input)));
$n = $temp[0];
$t = $temp[1];
$a = explode(" ", trim(fgets($input)));

$total = 0;
$count = 0;
for($i = 0; $i < $n; $i++){
    $count++;
    $temp = $a[$i] + $total;
    if($temp > $t)
        break;
    $total = $temp;
}

echo $count;

<?php
// input
$in = 'php://stdin';
$input = fopen($in, "r");
$temp = explode(" ", trim(fgets($input)));
$n = $temp[0];
$t = $temp[1];
$a = explode(" ", trim(fgets($input)));

$total = 0;
for($i = 0; $i < $n; $i++){
    $temp = $a[$i] + $total;
    if($temp > $t)
        break;
    $total = $temp;
}

echo $total;

<?php
// input
$in = 'php://stdin';
$input = fopen($in, "r");
$temp = explode(" ", trim(fgets($input)));
$n = $temp[0];
$t = $temp[1];
$a = explode(" ", trim(fgets($input)));

$total = 0;
$count = 0;
for($i = 0; $i < $n; $i++){
    $count++;
    $temp = $a[$i] + $total;
    if($temp > $t)
        break;
    $total = $temp;
}

echo $total;

<?php
// input
$in = 'php://stdin';
$input = fopen($in, "r");
$temp = explode(" ", trim(fgets($input)));
$n = $temp[0];
$t = $temp[1];
$a = explode(" ", trim(fgets($input)));

$total = 0;
for($i = 0; $i < $n; $i++){
    $temp = $a[$i] + $total;
    if($temp > $t)
        break;
}

echo $total;

<?php
// input
$in = 'php://stdin';
$input = fopen($in, "r");
$temp = explode(" ", trim(fgets($input)));
$n = $temp[0];
$t = $temp[1];
$a = explode(" ", trim(fgets($input)));
sort($a);

$total = 0;
$count = 0;
for($i = 0; $i < $n; $i++){
    $temp = $a[$i] + $total;
    if($temp > $t)
        break;
    $total = $temp;
    $count++;
}

echo $count;

<?php
// Books

// input
$in = 'php://stdin';
$input = fopen($in, "r");
$n = fgets($input);
$t = fgets($input);
$a = explode(" ", trim(fgets($input)));

// Solve
$left = 0;
$right = 0;
$sum = 0;
$maxBooks = 0;
while ($right < $n) {
    if ($sum + $a[$right] <= $t) {
        $sum += $a[$right];
        if ($right - $left + 1 > $maxBooks) {
            $maxBooks = $right - $left + 1;
        }
    } else {
        $sum -= $a[$left];
        $left++;
        $right--;
    }
    $right++;
}
echo ($maxBooks);


<?php

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

if($a == $c)
{
  if($b == $d) print "YES";
  else print "NO";
}
elseif(array_sum($b) != array_sum($d))
{
  print "NO";
}
else
{
  $who = array();
  $k = 0;
  while(count($d) > 0){
    if($b[0] == $d[0]){
        $b = array_slice($b, 1);
        $d = array_slice($d, 1);
        $k++;
        continue;
    }
    for($i = 0; $i < count($b); $i++){
      if($i > 0 && $b[$i] > $b[$i-1]){
        if($i+1 < count($b) && $b[$i]+$b[$i-1] == $b[$i+1]) continue;
        $b[$i] += $b[$i-1];
        $who[] = ($i+1+$k).' L';
        unset($b[$i-1]);
        $b = array_values($b);
        break;
      }
      if($i+1 < count($b) && $b[$i] > $b[$i+1]){
        if($i+2 < count($b) && $b[$i]+$b[$i+1] == $b[$i+2]) continue;
        $b[$i] += $b[$i+1];
        $who[] = ($i+1+$k).' R';
        unset($b[$i+1]);
        $b = array_values($b);
        break;
      }
      if($i == count($b)-1) {
        break(2);
      }
    }
  }

  if($b == $d){
    print "YES\n";
    foreach($who as $w){
      print $w."\n";
    }
  }
  else print "NO";

}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
$d = explode(" ", trim(fgets(STDIN)));
if($a == $c)
{
     if($b == $d)
     {
          print "YES";
     }
     else
     {
          print "NO";
     }
}
else
{
     $e = array_sum($b);
     $f = array_sum($d);
     if($e != $f)
     {
          print "NO";
     }
     else
     {
          $g = array();
          for($x = 0; $x < $c; $x++)
          {
               $h = $d[$x];
               $i = array();
               for($y = 0; $y < count($b); $y++)
               {
                    array_push($i, $b[$y]);
                    $j = array_sum($i);
                    if($j == $h)
                    {
                         array_push($g, $i);
                         $b = array_slice($b, count($i));
                         break;
                    }
               }
          }
          if(count($g) != $c)
          {
               print "NO";
          }
          else
          {
               $k = 0;
               for($x = 0; $x < count($g); $x++)
               {
                    $l = array_unique($g[$x]);
                    if((count($l) == 1) && (count($g[$x]) != 1))
                    {
                         $k = 1;
                         break;
                    }
               }
               if($k == 1)
               {
                    print "NO";
               }
               else
               {
                    print "YES\n";
                    for($x = 0; $x < count($g); $x++)
                    {
                         $m = $g[$x];
                         if(count($m) == 1)
                         {
                              continue;
                         }
                         else
                         {
                              $n = max($m);
                              for($y = 0; $y < count($m); $y++)
                              {
                                   if(($m[$y - 1] < $n) && ($m[$y] == $n) && (($y - 1) >= 0))
                                   {
                                        while(TRUE)
                                        {
                                             if(($m[$y - 1] == FALSE) && ($m[$y + 1] == FALSE))
                                             {
                                                  break;
                                             }
                                             elseif((($m[$y - 1] < $m[$y]) && ($m[$y + 1] >= $m[$y]) && (($y - 1) >= 0)) || (($m[$y - 1] < $m[$y]) && ($m[$y + 1] < $m[$y]) && (($y - 1) >= 0)) || ($m[$y + 1] == FALSE))
                                             {
                                                  print ($y + $x + 1) . " L\n";
                                                  $m[$y - 1] += $m[$y];
                                                  $o = array_slice($m, 0, $y);
                                                  $p = array_slice($m, $y + 1);
                                                  $m = array_merge($o, $p);
                                                  $y--;
                                             }
                                             elseif((($m[$y - 1] >= $m[$y]) && ($m[$y + 1] < $m[$y]) && (($y + 1) >= 0)) || ($m[$y - 1] == FALSE))
                                             {
                                                  print ($y + $x + 1) . " R\n";
                                                  $m[$y + 1] += $m[$y];
                                                  $o = array_slice($m, 0, $y);
                                                  $p = array_slice($m, $y + 1);
                                                  $m = array_merge($o, $p);
                                             }
                                        }
                                        break;
                                   }
                                   elseif(($m[$y] == $n) && ($m[$y + 1] < $n))
                                   {
                                        while(TRUE)
                                        {
                                             if(($m[$y - 1] == FALSE) && ($m[$y + 1] == FALSE))
                                             {
                                                  break;
                                             }
                                             elseif((($m[$y - 1] < $m[$y]) && ($m[$y + 1] >= $m[$y]) && (($y - 1) >= 0)) || (($m[$y - 1] < $m[$y]) && ($m[$y + 1] < $m[$y]) && (($y - 1) >= 0)) || ($m[$y + 1] == FALSE))
                                             {
                                                  print ($y + $x + 1) . " L\n";
                                                  $m[$y - 1] += $m[$y];
                                                  $o = array_slice($m, 0, $y);
                                                  $p = array_slice($m, $y + 1);
                                                  $m = array_merge($o, $p);
                                                  $y--;
                                             }
                                             elseif((($m[$y - 1] >= $m[$y]) && ($m[$y + 1] < $m[$y]) && (($y + 1) >= 0)) || ($m[$y - 1] == FALSE))
                                             {
                                                  print ($y + $x + 1) . " R\n";
                                                  $m[$y + 1] += $m[$y];
                                                  $o = array_slice($m, 0, $y);
                                                  $p = array_slice($m, $y + 1);
                                                  $m = array_merge($o, $p);
                                             }
                                        }
                                        break;
                                   }
                              }

                         }
                    }
               }
          }
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
$d = explode(" ", trim(fgets(STDIN)));
if($a == $c)
{
     if($b == $d)
     {
          print "YES";
     }
     else
     {
          print "NO";
     }
}
else
{
     $e = array_sum($b);
     $f = array_sum($d);
     if($e != $f)
     {
          print "NO";
     }
     else
     {
          $g = array();
          for($x = 0; $x < $c; $x++)
          {
               $h = $d[$x];
               $i = array();
               for($y = 0; $y < count($b); $y++)
               {
                    array_push($i, $b[$y]);
                    $j = array_sum($i);
                    if($j == $h)
                    {
                         array_push($g, $i);
                         $b = array_slice($b, count($i));
                         break;
                    }
               }
          }
          if(count($g) != $c)
          {
               print "NO";
          }
          else
          {
               $k = 0;
               for($x = 0; $x < count($g); $x++)
               {
                    $l = array_unique($g[$x]);
                    if(count($l) == 1)
                    {
                         $k = 1;
                         break;
                    }
               }
               if($k == 1)
               {
                    print "NO";
               }
               else
               {
                    print "YES\n";
                    for($x = 0; $x < count($g); $x++)
                    {
                         $m = $g[$x];
                         if(count($m) == 1)
                         {
                              continue;
                         }
                         else
                         {
                              $n = max($m);
                              for($y = 0; $y < count($m); $y++)
                              {
                                   if(($m[$y - 1] < $n) && ($m[$y] == $n) && (($y - 1) >= 0))
                                   {
                                        while(TRUE)
                                        {
                                             if(($m[$y - 1] == FALSE) && ($m[$y + 1] == FALSE))
                                             {
                                                  break;
                                             }
                                             elseif((($m[$y - 1] < $m[$y]) && ($m[$y + 1] >= $m[$y]) && (($y - 1) >= 0)) || (($m[$y - 1] < $m[$y]) && ($m[$y + 1] < $m[$y]) && (($y - 1) >= 0)) || ($m[$y + 1] == FALSE))
                                             {
                                                  print ($y + $x + 1) . " L\n";
                                                  $m[$y - 1] += $m[$y];
                                                  $o = array_slice($m, 0, $y);
                                                  $p = array_slice($m, $y + 1);
                                                  $m = array_merge($o, $p);
                                                  $y--;
                                             }
                                             elseif((($m[$y - 1] >= $m[$y]) && ($m[$y + 1] < $m[$y]) && (($y + 1) >= 0)) || ($m[$y - 1] == FALSE))
                                             {
                                                  print ($y + $x + 1) . " R\n";
                                                  $m[$y + 1] += $m[$y];
                                                  $o = array_slice($m, 0, $y);
                                                  $p = array_slice($m, $y + 1);
                                                  $m = array_merge($o, $p);
                                             }
                                        }
                                        break;
                                   }
                                   elseif(($m[$y] == $n) && ($m[$y + 1] < $n))
                                   {
                                        while(TRUE)
                                        {
                                             if(($m[$y - 1] == FALSE) && ($m[$y + 1] == FALSE))
                                             {
                                                  break;
                                             }
                                             elseif((($m[$y - 1] < $m[$y]) && ($m[$y + 1] >= $m[$y]) && (($y - 1) >= 0)) || (($m[$y - 1] < $m[$y]) && ($m[$y + 1] < $m[$y]) && (($y - 1) >= 0)) || ($m[$y + 1] == FALSE))
                                             {
                                                  print ($y + $x + 1) . " L\n";
                                                  $m[$y - 1] += $m[$y];
                                                  $o = array_slice($m, 0, $y);
                                                  $p = array_slice($m, $y + 1);
                                                  $m = array_merge($o, $p);
                                                  $y--;
                                             }
                                             elseif((($m[$y - 1] >= $m[$y]) && ($m[$y + 1] < $m[$y]) && (($y + 1) >= 0)) || ($m[$y - 1] == FALSE))
                                             {
                                                  print ($y + $x + 1) . " R\n";
                                                  $m[$y + 1] += $m[$y];
                                                  $o = array_slice($m, 0, $y);
                                                  $p = array_slice($m, $y + 1);
                                                  $m = array_merge($o, $p);
                                             }
                                        }
                                        break;
                                   }
                              }

                         }
                    }
               }
          }
     }
}
?>

<?php

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

if($a == $c)
{
  if($b == $d) print "YES";
  else print "NO";
}
elseif(array_sum($b) != array_sum($d))
{
  print "NO";
}
else
{
  $who = array();
  $k = 0;
  while(count($d) > 0){
    if($b[0] == $d[0]){
        $b = array_slice($b, 1);
        $d = array_slice($d, 1);
        $k++;
        continue;
    }
    for($i = 0; $i < count($b); $i++){
      if($i > 0 && $b[$i] > $b[$i-1]){
        $b[$i] += $b[$i-1];
        $who[] = ($i+1+$k).' L';
        //$b = array_slice($b, $i);
        unset($b[$i-1]);
        $b = array_values($b);
        break;
      }
      if($i+1 < count($b) && $b[$i] > $b[$i+1]){
        $b[$i] += $b[$i+1];
        $who[] = ($i+1+$k).' R';
        //$b = array_slice($b, $i+1);
        unset($b[$i+1]);
        $b = array_values($b);
        break;
      }
      if($i == count($b)-1) {
        foreach($b as $bv) print $bv." ";
        print "\n";
        foreach($d as $dv) print $dv." ";
        print "\n------\n";
        break(2);
      }
    }
    foreach($b as $bv) print $bv." ";
    print "\n";
    foreach($d as $dv) print $dv." ";
    print "\n------\n";
  }

  if($b == $d){
    print "YES\n";
    foreach($who as $w){
      print $w."\n";
    }
  }
  else print "NO";

}
?>

<?php

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

if($a == $c)
{
  if($b == $d) print "YES";
  else print "NO";
}
elseif(array_sum($b) != array_sum($d))
{
  print "NO";
}
else
{
  $who = array();
  $k = 0;
  while(count($d) > 0){
    if($b[0] == $d[0]){
        $b = array_slice($b, 1);
        $d = array_slice($d, 1);
        $k++;
        continue;
    }
    for($i = 0; $i < count($b); $i++){
      if($i > 0 && $b[$i] > $b[$i-1]){
        $b[$i] += $b[$i-1];
        $who[] = ($i+1+$k).' L';
        //$b = array_slice($b, $i);
        unset($b[$i-1]);
        $b = array_values($b);
        break;
      }
      if($i+1 < count($b) && $b[$i] > $b[$i+1]){
        $b[$i] += $b[$i+1];
        $who[] = ($i+1+$k).' R';
        //$b = array_slice($b, $i+1);
        unset($b[$i+1]);
        $b = array_values($b);
        break;
      }
      if($i == count($b)-1) {
        break(2);
      }
    }
  }

  if($b == $d){
    print "YES\n";
    foreach($who as $w){
      print $w."\n";
    }
  }
  else print "NO";

}
?>

<?php

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

if($a == $c)
{
  if($b == $d) print "YES";
  else print "NO";
}
elseif(array_sum($b) != array_sum($d))
{
  print "NO";
}
else
{
  $who = array();
  $k = 0;
  while(count($d) > 0){
    if($b[0] == $d[0]){
        $b = array_slice($b, 1);
        $d = array_slice($d, 1);
        $k++;
    }
    for($i = 0; $i < count($b); $i++){
      if($i > 0 && $b[$i] > $b[$i-1]){
        $b[$i] += $b[$i-1];
        $who[] = ($i+1+$k).' L';
        //$b = array_slice($b, $i);
        unset($b[$i-1]);
        $b = array_values($b);
        break;
      }
      if($i+1 < count($b) && $b[$i] > $b[$i+1]){
        $b[$i] += $b[$i+1];
        $who[] = ($i+1+$k).' R';
        //$b = array_slice($b, $i+1);
        unset($b[$i+1]);
        $b = array_values($b);
        break;
      }
      if($i == count($b)-1) break(2);
    }
  }

  if(count($who) && $b == $d){
    print "YES\n";
    foreach($who as $w){
      print $w."\n";
    }
  }
  else print "NO";

}
?>


<?php

	$string = trim(file_get_contents('php://stdin'));

	$string = preg_replace("/\s*,\s*/", ', ', $string);
	$string = preg_replace("/\s*\.\.\.\s*/", ' ...', $string);
	$string = preg_replace("/\s+/", ' ', $string);

	echo trim($string, ' ');

<?
/*
$start_time = microtime();
$start_array = explode(" ",$start_time);
$time['start'] = $start_array[1] + $start_array[0];*/

$string = file_get_contents("php://stdin");

$patterns = array(
    "/(\s+),/",
    "/,/",
    "/(\.\.\.)(\s+)/",
    "/(\.\.\.)/",
    "/(\s+)/"
);

$replacements = array (
    ",",
    ", ",
    "...",
    " ...",
    " "
);

echo trim(preg_replace($patterns, $replacements, $string));
/*
$end_time = microtime();
$end_array = explode(" ",$end_time);
$time['gener_class'] = $end_array[1] + $end_array[0];
echo $time_gener['class'] = round($time['gener_class']-$time['start'],5);*/
?>

<?
$input = file_get_contents("php://stdin");

$len = strlen ($input);
$result = '';
$prew = '';
for($i = 0; $i < $len; $i++){
    if($input[$i] == '.'){
        if($prew){
            $result .= $prew . '...';
        } else {
            $result .= ' ...';
        }
        $i += 2;
        $prew = '';
    } else if($input[$i] == ','){
        if($prew == ', '){
            $result .= $prew;
        }
        $prew = ', ';
    } else if($input[$i] == ' '){
        if(!$prew){
            $prew = ' ';
        }
    } else {
       if($prew == ', ' || $result[strlen ($result) - 1] != '.'){
           $result .= $prew;
       }
       $result .= $input[$i];
       $prew = '';
    }
}
echo trim($result);
?>

<?php
$rx = array(
    '/\\.\\.\\./s' => ' ...',
    '/(\\s*,\\s*)/s' => ', ',
    '/\\s\\s/s' => ' ',
);
$str = fgets(STDIN);
$str = preg_replace(array_keys($rx), array_values($rx), $str);
fwrite(STDOUT, trim($str));

<?
/*
$start_time = microtime();
$start_array = explode(" ",$start_time);
$time['start'] = $start_array[1] + $start_array[0];*/

$input = file_get_contents("php://stdin");
$input = str_replace(" ", "", $input);

$len = strlen ($input);
$result = '';
for($i = 0; $i < $len; $i++){
    //echo $input[$i];
    if($input[$i] == '.'){
        //echo ' ���������';
        if($input[$i - 1] == ','){
            $result .= '...';
        } else {
            $result .= ' ...';
        }
        $i += 2;
        if($input[$i + 1] == ','){
            //echo ' ���';
            $i++;
            $result .= ', ';
        }
    } else if($input[$i] == ','){
        $result .= ', ';
    } else {
        $result .= $input[$i];
        //echo ' �����';
        if($input[$i + 1] == ','){
            //echo ' ���';
            $i++;
            $result .= ', ';
        }
    }

    //echo "\n";
}

echo $result;
/*
$end_time = microtime();
$end_array = explode(" ",$end_time);
$time['gener_class'] = $end_array[1] + $end_array[0];
echo $time_gener['class'] = round($time['gener_class']-$time['start'],5);*/
?>

<?
$input = file_get_contents("php://stdin");

$len = strlen ($input);
$result = '';
$prew = '';
for($i = 0; $i < $len; $i++){
    if($input[$i] == '.'){
        if($prew){
            $result .= $prew . '...';
        } else {
            $result .= ' ...';
        }
        $i += 2;
        $prew = '';
    } else if($input[$i] == ','){
        if($prew == ', '){
            $result .= $prew;
        }
        $prew = ', ';
    } else if($input[$i] == ' '){
        if(!$prew){
            $prew = ' ';
        }
    } else {
       if($prew && $result[strlen ($result) - 1] != '.'){
           $result .= $prew;
       }
       $result .= $input[$i];
       $prew = '';
    }
}
echo trim($result);
?>

<?
/*
$start_time = microtime();
$start_array = explode(" ",$start_time);
$time['start'] = $start_array[1] + $start_array[0];*/

$input = file_get_contents("php://stdin");
$input = str_replace(" ", "", $input);

$len = strlen ($input);
$result = '';
for($i = 0; $i < $len; $i++){
    //echo $input[$i];
    if($input[$i] == '.'){
        //echo ' ���������';
        if($i < 1 || $input[$i - 1] == ','){
            $result .= '...';
        } else {
            $result .= ' ...';
        }
        $i += 2;
        if($input[$i + 1] == ','){
            //echo ' ���';
            $i++;
            $result .= ', ';
        }
    } else if($input[$i] == ','){
        $result .= ', ';
    } else {
        $result .= $input[$i];
        //echo ' �����';
        if($input[$i + 1] == ','){
            //echo ' ���';
            $i++;
            $result .= ', ';
        }
    }

    //echo "\n";
}

echo $result;
/*
$end_time = microtime();
$end_array = explode(" ",$end_time);
$time['gener_class'] = $end_array[1] + $end_array[0];
echo $time_gener['class'] = round($time['gener_class']-$time['start'],5);*/
?>

<?
/*
$start_time = microtime();
$start_array = explode(" ",$start_time);
$time['start'] = $start_array[1] + $start_array[0];*/

$input = file_get_contents("php://stdin");
$input = str_replace(" ", "", $input);

$len = strlen ($input);
$result = '';
for($i = 0; $i < $len; $i++){
    //echo $input[$i];
    if($input[$i] == '.'){
        //echo ' ���������';
        if($i < 1 || $input[$i - 1] == ','){
            $result .= '...';
        } else {
            $result .= ' ...';
        }
        $i += 2;
        if($input[$i + 1] == ','){
            //echo ' ���';
            $i++;
            $result .= ', ';
        }
    } else if($input[$i] == ','){
        if(isset($input[$i + 1])){
			$result .= ', ';
		} else {
			$result .= ',';
		}
    } else {
        $result .= $input[$i];
        if($input[$i + 1] == ','){
            $i++;
            $result .= ', ';
        }
    }

    //echo "\n";
}

echo trim($result);
/*
$end_time = microtime();
$end_array = explode(" ",$end_time);
$time['gener_class'] = $end_array[1] + $end_array[0];
echo $time_gener['class'] = round($time['gener_class']-$time['start'],5);*/
?>

<?
/*
$start_time = microtime();
$start_array = explode(" ",$start_time);
$time['start'] = $start_array[1] + $start_array[0];*/

$input = file_get_contents("php://stdin");
$input = str_replace(" ", "", $input);

$len = strlen ($input);
$result = '';
for($i = 0; $i < $len; $i++){
    //echo $input[$i];
    if($input[$i] == '.'){
        //echo ' ���������';
        if($i > 1 && $input[$i - 1] == ','){
            $result .= '...';
        } else {
            $result .= ' ...';
        }
        $i += 2;
        if($input[$i + 1] == ','){
            //echo ' ���';
            $i++;
            $result .= ', ';
        }
    } else if($input[$i] == ','){
        $result .= ', ';
    } else {
        $result .= $input[$i];
        //echo ' �����';
        if($input[$i + 1] == ','){
            //echo ' ���';
            $i++;
            $result .= ', ';
        }
    }

    //echo "\n";
}

echo $result;
/*
$end_time = microtime();
$end_array = explode(" ",$end_time);
$time['gener_class'] = $end_array[1] + $end_array[0];
echo $time_gener['class'] = round($time['gener_class']-$time['start'],5);*/
?>

<?
$input = file_get_contents("php://stdin");

$len = strlen ($input);
$result = '';
$prew = '';
for($i = 0; $i < $len; $i++){
    if($input[$i] == '.'){
        if($prew){
            $result .= $prew . '...';
        } else {
            $result .= ' ...';
        }
        $i += 2;
        $prew = '';
    } else if($input[$i] == ','){
        if($prew == ', '){
            $result .= $prew;
        }
        $prew = ', ';
    } else if($input[$i] == ' '){
        if(!$prew){
            $prew = ' ';
        }
    } else {
       $result .= $prew . $input[$i];
       $prew = '';
    }
}
echo trim($result);
?>

<?
/*
$start_time = microtime();
$start_array = explode(" ",$start_time);
$time['start'] = $start_array[1] + $start_array[0];*/

$input = file_get_contents("php://stdin");
$input = str_replace(" ", "", $input);

$len = strlen ($input);
$result = '';
for($i = 0; $i < $len; $i++){
    //echo $input[$i];
    if($input[$i] == '.'){
        //echo ' ���������';
        if($input[$i - 1] == ','){
            $result .= '...';
        } else {
            $result .= ' ...';
        }
        $i += 2;
        if($i > 1 && $input[$i + 1] == ','){
            //echo ' ���';
            $i++;
            $result .= ', ';
        }
    } else if($input[$i] == ','){
        $result .= ', ';
    } else {
        $result .= $input[$i];
        //echo ' �����';
        if($input[$i + 1] == ','){
            //echo ' ���';
            $i++;
            $result .= ', ';
        }
    }

    //echo "\n";
}

echo $result;
/*
$end_time = microtime();
$end_array = explode(" ",$end_time);
$time['gener_class'] = $end_array[1] + $end_array[0];
echo $time_gener['class'] = round($time['gener_class']-$time['start'],5);*/
?>

<?
/*
$start_time = microtime();
$start_array = explode(" ",$start_time);
$time['start'] = $start_array[1] + $start_array[0];*/

$string = file_get_contents("php://stdin");

$patterns[0] = "/(\s+),/";
$patterns[1] = "/,/";
$patterns[2] = "/(\.\.\.)/";
$patterns[3] = "/(\s+)/";

$replacements[3] = ",";
$replacements[2] = ", ";
$replacements[1] = " ...";
$replacements[0] = " ";

echo trim(preg_replace($patterns, $replacements, $string));
/*
$end_time = microtime();
$end_array = explode(" ",$end_time);
$time['gener_class'] = $end_array[1] + $end_array[0];
echo $time_gener['class'] = round($time['gener_class']-$time['start'],5);*/
?>

<?
/*
$start_time = microtime();
$start_array = explode(" ",$start_time);
$time['start'] = $start_array[1] + $start_array[0];*/

$input = file_get_contents("php://stdin");
$input = str_replace(" ", "", $input);

$len = strlen ($input);
$result = '';
for($i = 0; $i < $len; $i++){
    //echo $input[$i];
    if($input[$i] == '.'){
        //echo ' ���������';
        if($i < 1 || $input[$i - 1] == ','){
            $result .= '...';
        } else {
            $result .= ' ...';
        }
        $i += 2;
        if($input[$i + 1] == ','){
            //echo ' ���';
            $i++;
            $result .= ', ';
        }
    } else if($input[$i] == ','){
        if(isset($input[$i + 1])){
			$result .= ', ';
		} else {
			$result .= ',';
		}
    } else {
        $result .= $input[$i];
        //echo ' �����';
        if($input[$i + 1] == ','){
            //echo ' ���';
            $i++;
            $result .= ', ';
        }
    }

    //echo "\n";
}

echo $result;
/*
$end_time = microtime();
$end_array = explode(" ",$end_time);
$time['gener_class'] = $end_array[1] + $end_array[0];
echo $time_gener['class'] = round($time['gener_class']-$time['start'],5);*/
?>


<?php

list($n, $k) = explode(" ", fgets(STDIN));
list($s) = explode(" ", fgets(STDIN));
$n = (int) $n;
$k = (int) $k;
$ansl = (int) 0;
$ansr = (int) $n - 2;

while($ansr > $ansl)
{
    $intv = (int) (($ansl + $ansr) / 2);
    $r = $k - 1;

    for($i = 0; $i < $n - 1;)
    {
        $pos = -1;

        for($j = min($i + $intv + 1, $n - 1); $j >= $i + 1; --$j)
        if($s[$j] == '0')
        {
            $pos = $j;
            break;
        }

        if($pos == -1 || $r == 0)
        {
            $pos = -1;
            break;
        }
        else
        {
            --$r;
            $i = $pos;
        }
    }

    if($pos != -1)
        $ansr = $intv;
    else
        $ansl = $intv + 1;
}

echo $ansr;

?>

<?php
  // ( $N, $K ) is not allowed........... claimed by compiler being parsing error
  list($N, $K) = explode(" ", fgets(STDIN));
  $N = (int) $N;
  $K = (int) $K - 2;
  $seq = fgets(STDIN);
  $rp = array(); // rp[ i ] : maximum j such that j ≤ i and seq[ j ] == 0
  for($i = 0, $prev = 0; $i < $N; ++$i) {
    if($seq[$i] == '0') {
      $prev = $i;
    }
    array_push($rp, $prev);
  }
  $lb = 0;
  $ub = $N - 2;
  $ans = $ub;
  while($lb <= $ub) {
    $mid = floor(($lb + $ub) / 2);
    $cost = 0;
    for($i = 1, $prev = 0; $i + 1 < $N; ++$i) {
      $lim = $prev + $mid + 1;
      if($lim >= $N - 1) break;
      if($seq[$i] == '1') {
        if($lim == $i) {
          $cost = $K + 1;
        }
      }
      if($rp[$lim] == $i) {
        ++$cost;
        $prev = $i;
      }
    }
    if($cost <= $K) {
      $ans = $mid;
      $ub = $mid - 1;
    } else {
      $lb = $mid + 1;
    }
  }
  echo $ans;
?>

<?php
 list($n, $k) = explode(" ", fgets(STDIN));
 $n = (int) $n;
 $k = (int) $k;
 $s = fgets(STDIN);
 $b = 0;
 $e = $n - 2;
 while ($b + 1 < $e) {
     $mm = floor(($b + $e) / 2);
     $q = true;
     $kk = $k - 2;
     $lastq = 0;
     $possible = -1;
     for ($i = 1; $i < strlen($s) - 1; $i++) {
         if ($s[$i] == '0') $possible = $i;
         if ($i - $lastq - 1 == $mm) {
             if ($kk > 0 && $possible != -1) {
                 $kk--;
                 $lastq = $possible;
                 $possible = -1;
             } else {
                 $q = false;
                 break;
             }
         }
     }
     if ($q && $n - $lastq - 2 > $mm) $q = false;
     if ($q) $e = $mm; else $b = $mm;
 }
 $qq = true;
 for ($i = 0; $i < $n; $i++) {
     if ($s[$i] == '1') {
         $qq = false;
     }
 }
 if ($qq && $n == $k) $e = 0;
 echo $e;
?>

<?php
 list($n, $k) = explode(" ", fgets(STDIN));
 $n = (int) $n;
 $k = (int) $k;
 $s = fgets(STDIN);
 $b = -1;
 $e = $n;
 while ($b + 1 < $e) {
     $mm = floor(($b + $e) / 2);
     $q = true;
     $kk = $k - 2;
     $lastq = 0;
     $possible = -1;
     for ($i = 1; $i < strlen($s) - 1; $i++) {
         if ($s[$i] == '0') $possible = $i;
         if ($i - $lastq > $mm) {
             if ($kk > 0 && $possible != -1) {
                 $kk--;
                 $lastq = $possible;
                 $possible = -1;
             } else {
                 $q = false;
                 break;
             }
         }
     }
     if ($q && $n - $lastq - 2 > $mm) $q = false;
     if ($q) $e = $mm; else $b = $mm;
 }
 echo $e;
?>

<?php
 list($n, $k) = explode(" ", fgets(STDIN));
 $n = (int) $n;
 $k = (int) $k;
 $s = fgets(STDIN);
 $b = 0;
 $e = $n - 2;
 while ($b + 1 < $e) {
     $mm = floor(($b + $e) / 2);
     $q = true;
     $kk = $k - 2;
     $lastq = 0;
     $possible = -1;
     for ($i = 1; $i < strlen($s) - 1; $i++) {
         if ($s[$i] == '0') $possible = $i;
         if ($i - $lastq - 1 > $mm) {
             if ($kk > 0 && $possible != -1) {
                 $kk--;
                 $lastq = $possible;
                 $possible = -1;
             } else {
                 $q = false;
                 break;
             }
         }
     }
     if ($q && $n - $lastq - 2 > $mm) $q = false;
     if ($q) $e = $mm; else $b = $mm;
 }
 $qq = true;
 for ($i = 0; $i < $n; $i++) {
     if ($s[$i] == '1') {
         $qq = false;
     }
 }
 if ($qq && $n == $k) $e = 0;
 echo $e;
?>

<?php
 list($n, $k) = explode(" ", fgets(STDIN));
 $n = (int) $n;
 $k = (int) $k;
 $s = fgets(STDIN);
 $b = 0;
 $e = $n - 2;
 while ($b + 1 < $e) {
     $mm = floor(($b + $e) / 2);
     $q = true;
     $kk = $k - 2;
     $lastq = 0;
     $possible = -1;
     for ($i = 1; $i < strlen($s) - 1; $i++) {
         if ($s[$i] == '0') $possible = $i;
         if ($i - $lastq - 1 > $mm) {
             if ($kk > 0 && $possible != -1) {
                 $kk--;
                 $lastq = $possible;
                 $possible = -1;
             } else {
                 $q = false;
                 break;
             }
         }
     }
     if ($q && $n - $lastq - 1 > $mm) $q = false;
     if ($q) $e = $mm; else $b = $mm;
 }
 $qq = true;
 for ($i = 0; $i < $n; $i++) {
     if ($s[$i] == '1') {
         $qq = false;
     }
 }
 if ($qq && $n == $k) $e = 0;
 echo $e;
?>

<?php
 list($n, $k) = explode(" ", fgets(STDIN));
 $n = (int) $n;
 $k = (int) $k;
 $s = fgets(STDIN);
 $b = 0;
 $e = $n - 2;
 while ($b + 1 < $e) {
     $mm = floor(($b + $e) / 2);
     $q = true;
     $kk = $k - 2;
     $lastq = 0;
     $possible = -1;
     for ($i = 1; $i < strlen($s) - 1; $i++) {
         if ($s[$i] == '0') $possible = $i;
         if ($i - $lastq > $mm) {
             if ($kk > 0 && $possible != -1) {
                 $kk--;
                 $lastq = $possible;
                 $possible = -1;
             } else {
                 $q = false;
                 break;
             }
         }
     }
     if ($q && $n - $lastq - 2 > $mm) $q = false;
     if ($q) $e = $mm; else $b = $mm;
 }
 $qq = true;
 for ($i = 0; $i < $n; $i++) {
     if ($s[$i] == '1') {
         $qq = false;
     }
 }
 if ($qq && $n == $k) $e = 0;
 echo $e;
?>


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

$data = trim(file_get_contents($src));

$i = 0;
while (strlen($data) > 1) {
$data = (string) array_sum(str_split($data));
	$i++;
}
echo $i;

<?php
$a = trim(fgets(STDIN));
$b = str_split($a);
$c = 0;
for($x = 1; $x <= count($b); $x++)
{
    if(count($b) > 1)
    {
        $c++;
        $b = str_split(array_sum($b));
        $x = 1;
    }
    else
    {
        break;
    }
}
print $c;
?>

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

$input = (string) $input;
if((int)$input < 10) die('0');
if((int)$input == 10) die('1');

function numsum($i)
{
    $i = (string)$i;
    $s = (double)0;
    for($a = 0; $a<strlen($i); $a++)
    {
        $s += (double)$i[$a];
    }
    return $s;
}
$c = 0;
while($input >= 10)
{
    $input = numsum($input);
    $c++;
}

echo $c;

<?php

function digitalRoot($str, $len){
    $sum = 0;
    for($i = 0; $i < $len; $i++){
        $sum += $str[$i];
    }
    return strval($sum);
}

while (FALSE !== ($line = fgets(STDIN))) {

    $tLine = trim($line);
    $count = 0;

    while(1){
        $len = strlen($tLine);
        if($len > 1){
            $count++;
            $tLine = digitalRoot($tLine, $len);
        }else{
            break;
        }
    }
    echo $count . PHP_EOL;
}

<?php
fscanf(STDIN, "%s",$s);
function sumstr($s){
for ($i=0;$i<strlen($s);$i++)
    $sum += (int)$s[$i];
  return $sum;
}

$cnt=0;

while (strlen($s)>1){
 $s = sumstr("".$s);
 $cnt++;
}

echo $cnt;

?>

<?
$str=trim(fgets(STDIN));
$sum=0;
if(strlen($str)==1) $cnt=0;
else $cnt=1;
for($i=0; $i<strlen($str); $i++)
    $sum+=$str[$i];
while($sum>9){
    $str=(string)$sum;
    $sum=0;
    for($i=0; $i<strlen($str); $i++)
        $sum+=$str[$i];
    $cnt++;
}
echo $cnt;
?>

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

$res=0;

while(strlen($lines)>1)
{
    $new=0;
    for ($i=0; $i<strlen($lines); $i++)
        $new+=$lines{$i};
    $lines=$new;
    $lines=(string)$lines;
    $res++;
}

echo $res;
?>

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

function numsum($i)
{
    $i = (string)$i;
    $s = (double)0;
    for($a = 0; $a<strlen($i); $a++)
    {
        $s += (double)$i[$a];
    }
    return $s;
}

$input = (string) $input;

if((int)$input < 10) die('0');

$sum = numsum($input);
$c = 1;

while($sum > 10)
{
    $sum = numsum($sum);
    $c++;
}

echo $c;

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

function numsum($i)
{
    $i = (string)$i;
    $s = (double)0;
    for($a = 0; $a<strlen($i); $a++)
    {
        $s += (double)$i[$a];
    }
    return $s;
}

$input = (string) $input;
$sum = numsum($input);
$c = 1;

if($sum <= 10) die('0');

while($sum >= 10)
{
    $sum = numsum($sum);
    $c++;
}

echo $c;

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

function numsum($i)
{
    $i = (string)$i;
    $s = (double)0;
    for($a = 0; $a<strlen($i); $a++)
    {
        $s += (double)$i[$a];
    }
    return $s;
}

$input = (string) $input;
$sum = numsum($input);
$c = 1;

if($sum < 10) die('0');

while($sum >= 10)
{
    $sum = numsum($sum);
    $c++;
}

echo $c;

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

function numsum($i)
{
    $i = (string)$i;
    $s = (double)0;
    for($a = 0; $a<strlen($i); $a++)
    {
        $s += (double)$i[$a];
    }
    return $s;
}

$input = (string) $input;
$sum = numsum($input);
$c = 1;

if($sum < 10) die('0');

while($sum > 10)
{
    $sum = numsum($sum);
    $c++;
}

echo $c;

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

function numsum($i)
{
    $i = (string)$i;
    $s = (double)0;
    for($a = 0; $a<strlen($i); $a++)
    {
        $s += (double)$i[$a];
    }
    return $s;
}

$input = (string) $input;
$sum = numsum($input);
$c = 1;

if($sum <= 10) die('1');

while($sum > 10)
{
    $sum = numsum($sum);
    $c++;
}

echo $c;

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

$input = (double) $input;
function numsum($i)
{
    $i = (string)$i;
    $s = (double)0;
    for($a = 0; $a<strlen($i); $a++)
    {
        $s += (double)$i[$a];
    }
    return $s;
}
$c = 0;
while($input >= 10)
{
    $input = numsum($input);
    $c++;
}

echo $c;

<?php

//$src = 'input.txt';
$src = 'php://input';

$data = trim(file_get_contents($src));

$i = 0;
while (strlen($data) > 1) {
	$sum = 0;
	for ($i = 0; $i < strlen($data); $i++) {
		$sum += (int) $data{$i};
	}
	$data = (string) $sum;
	$i++;
}

echo $i . "\n";

<?php

//$src = 'input.txt';
$src = 'php://input';

$h = fopen($src, 'r');

$data = 0;
$non_zero = false;
while ($c = fgetc($h)) {
	if ($data) {
		$non_zero = true;
	}
	$data += (int) $c;
}
fclose($h);
if (!$non_zero) {
	die('0');
}
$i = 1;
$data = (string) $data;
while (strlen($data) > 1) {
	$sum = 0;
	for ($i = 0; $i < strlen($data); $i++) {
		$sum += (int) $data{$i};
	}
	$data = (string) $sum;
	$i++;
}

echo $i . "\n";

<?php

//$src = 'input.txt';
$src = 'php://input';

$data = trim(file_get_contents($src));

$i = 0;
while (strlen($data) > 1) {
	$sum = 0;
	for ($i = 0; $i < strlen($data); $i++) {
		$sum += $data{$i};
	}
	$data = (string) $sum;
	$i++;
}

echo $i;

<?php

//$src = 'input.txt';
$src = 'php://input';

$data = trim(file_get_contents($src));

$i = 0;
while (strlen($data) > 1) {
	$data = (string) ((int) array_sum(str_split($data)));
	$i++;
}

echo $i;

<?php

//$src = 'input.txt';
$src = 'php://input';

$h = fopen($src, 'r');

$data = 0;
$non_zero = false;
while (($c = fgetc($h)) !== false) {
	if ($data) {
		$non_zero = true;
	}
	$data += (int) $c;
}
fclose($h);
if (!$non_zero) {
	die('0');
}
$i = 1;
$data = (string) $data;
while (strlen($data) > 1) {
	$sum = 0;
	for ($i = 0; $i < strlen($data); $i++) {
		$sum += (int) $data{$i};
	}
	$data = (string) $sum;
	$i++;
}

echo $i . "\n";

<?php

//$src = 'input.txt';
$src = 'php://input';

$data = trim(file_get_contents($src));

$i = 0;
while (strlen($data) > 1) {
	$sum = 0;
	for ($i = 0; $i < strlen($data); $i++) {
		$sum += (int) $data{$i};
	}
	$data = (string) $sum;
	$i++;
}

echo $i;
echo PHP_EOL;

<?php

//$src = 'input.txt';
$src = 'php://input';

$data = trim(file_get_contents($src));

$i = 0;
while (strlen($data) > 1) {
	$sum = 0;
	for ($i = 0; $i < strlen($data); $i++) {
		$sum += (int) $data{$i};
	}
	$data = (string) $sum;
	$i++;
}

echo $i . "\r\n";

<?php

//$src = 'input.txt';
$src = 'php://input';

$h = fopen($src, 'r');

$data = 0;
$non_zero = false;
while ($c = fgetc($h)) {
	if ($data) {
		$non_zero = true;
	}
	$data += (int) $c;
}
fclose($h);
if (!$non_zero) {
	die('0');
}
$i = 1;
while (strlen($data) > 1) {
	$sum = 0;
	for ($i = 0; $i < strlen($data); $i++) {
		$sum += (int) $data{$i};
	}
	$data = (string) $sum;
	$i++;
}

echo $i . "\n";

<?php

//$src = 'input.txt';
$src = 'php://input';

$data = trim(file_get_contents($src));

$i = 0;
while (strlen($data) > 1) {
	$data = (string) array_sum(str_split($data));
	$i++;
}

echo $i;


<?php

fscanf(STDIN, "%d %d", $hh, $mm);
fscanf(STDIN, "%d%d%d%d", $H, $D, $C, $N);

//first case
$c1 = ceil(1.0 * $H / $N) * $C;

//second case
$diff = 1200 - (($hh * 60) + $mm);
$current_price = $C - ($C*0.2);
if ($diff > 0) {
	$current_hunger = $H + ($diff * $D);
	$c2 = ceil($current_hunger / $N) * $current_price;
}
else {
	$c2 = ceil(1.0 * $H / $N) * $current_price;
}

echo min($c1, $c2)."\n";

<?php

fscanf(STDIN, "%d %d", $hh, $mm);
fscanf(STDIN, "%d%d%d%d", $H, $D, $C, $N);

//first case
$c1 = ceil(1.0 * $H / $N) * $C;

//second case
$diff = 1200 - (($hh * 60) + $mm);
$current_price = $C - ($C*0.2);
if ($diff > 0) {
	$current_hunger = $H + ($diff * $D);
	$c2 = ceil(1.0 * $current_hunger / $N) * $current_price;
}
else {
	$c2 = (1.0 * $H / $N) * $current_price;
}

echo min($c1, $c2)."\n";

<?php

fscanf(STDIN, "%d %d", $hh, $mm);
fscanf(STDIN, "%d%d%d%d", $H, $D, $C, $N);

//first case
$c1 = ceil(1.0 * $H / $N) * $C;

//second case
$diff = 1200 - (($hh * 60) + $mm);

if ($diff > 0) {
	$current_hunger = $H + ($diff * $D);
	$current_price = $C - ($C*0.2);
	$c2 = ceil(1.0 * $current_hunger / $N) * $current_price;
}
else {
	$c2 = (1.0 * $H / $N) * $current_price;
}

echo min($c1, $c2)."\n";


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

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

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

  $y = $m;
  $x = ($n - 1) * $y;
  $ans = $y + $x - 1;
  if ($ans == $k) { echo 'YES'.PHP_EOL; }
  else { echo 'NO'.PHP_EOL; }
}

?>


<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
fscanf(STDIN,"%s",$str);
$len=strlen($str);
$frstLeft=0;
$scndLeft=0;
$cnt1=0;
$cnt2=0;
for ($i=0; $i <$len ; $i++)
 {
	if($str[$i]=='(')
		$frstLeft++;
	elseif($str[$i]=='[')
		$scndLeft++;
	elseif($frstLeft>0&&$str[$i]==')')
	{
		$cnt1++;
		$frstLeft--;

	}
	elseif($scndLeft>0&&$str[$i]==']')
	{
		$cnt2++;
		$scndLeft--;
	}

 }
 echo $cnt1+$cnt2."\n";
}

<?php
fscanf(STDIN, "%d", $number);
$result = array();
for ($i = 0; $i < $number; $i++){
    fscanf(STDIN, "%s", $string);
    $j = 0;
    $turns = 0;
    $round = 0;
    $square = 0;
    while ($j < strlen($string)){
        if ($string[$j] == '[')
            $square++;
        else if ($string[$j] == ']' && $square > 0) {
            $square --;
            $turns++;
        }
        else if ($string[$j] == '(')
            $round++;
        else if ($string[$j] == ')' && $round > 0) {
            $round--;
            $turns++;
        }
        $j++;
    }
    array_push($result, $turns);
}

for ($i = 0; $i < $number; $i++){
    echo $result[$i];
    if ($i < $number - 1)
        echo "\n";
}
?>

<?php
fscanf(STDIN, "%d", $number);
$result = array();
for ($i = 0; $i < $number; $i++){
    fscanf(STDIN, "%s", $string);
    $j = 0;
    $turns = 0;
    $round = 0;
    $square = 0;
    while ($j < strlen($string)){
        if ($string[$j] == '[')
            $square = 1;
        else if ($string[$j] == ']' && $square == 1) {
            $square = 0;
            $turns++;
        }
        else if ($string[$j] == '(')
            $round = 1;
        else if ($string[$j] == ')' && $round == 1) {
            $round = 0;
            $turns++;
        }
        $j++;
    }
    array_push($result, $turns);
}

for ($i = 0; $i < $number; $i++){
    echo $result[$i];
    if ($i < $number - 1)
        echo "\n";
}
?>


<?php
    $f = fopen('php://stdin', 'r');
    fgets($f);
    $arr = explode(' ', str_replace("\r\n", '', fgets($f)));
    $arr = array_count_values($arr);

    echo count($arr) - (isset($arr[0]) ? 1 : 0);

?>

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


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = $a / ($b + $c);
$e = $b * $d;
print $e;
?>

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$l = trim(fgets($file));
$p = trim(fgets($file));
$q = trim(fgets($file));
echo $p * $l / ($p + $q);

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = $a / ($b + $c);
$e = $b * $d;
$f = $c * $d;
print max(round($e, 5), round($f, 5));
?>


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

fscanf(STDIN, "%d %d", $n, $d);
fscanf(STDIN, "%d", $m);

for ($i = 0; $i < $m; $i++) {
    fscanf(STDIN, "%d %d", $x, $y);
    // x+y が dより大きい 2n-dより小さい
    $con1 = ($x + $y) >= $d;
    $con2 = ($x + $y) <= 2 * $n - $d;
    $con3 = ($x - $y) >= -$d;
    $con4 = ($x - $y) <= $d;
    // printf("%d %d %d %d\n", $con1, $con2, $con3, $con4);
    echo ($con1 && $con2 && $con3 && $con4) ? "YES\n" : "NO\n";
}


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

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

function binary_search($list, $item) {
  $low = 0;
  $high = count($list) - 1; $s = $high;

  while ($low <= $high) {
    $mid = floor(($low + $high) / 2);
    $guess = $list[$mid];

    if ($guess >= $item) { $s = $mid; $high = $mid - 1; }
    else { $low = $mid + 1; }
  }
  return $s;
}

for ($i = 0; $i < $t; $i++) {
  list($n, $w) = explode(" ", trim(fgets($file)));
  $a = explode(" ", trim(fgets($file)));
  sort($a);
  $f = array();

  for ($j = 0; $j < $n; $j++) $f[$j] = $w;
  for ($j = $n - 1; $j >= 0; $j--) {
		$x = binary_search($f, $a[$j]);
		$f[$x] -= $a[$j];
	}
	$ans = 0;

	for ($j = 0; $j < $n; $j++) {
	  if ($f[$j] != $w) $ans++;
	}
	echo $ans.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;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $w) = IO::arr();
    $a = IO::arr();
    $arr = [];
    foreach ($a as $v) {
        if (isset($arr[$v])) {
            $arr[$v] += 1;
        } else {
            $arr[$v] = 1;
        }
    }
    $i = 0;
    $res = 0;
    krsort($arr);
    while($i < $n) {
        $base = $w;
        $b = [];
        foreach ($arr as $k => $ar) {
            $f = floor($base / $k);
            $f = min([$ar, $f]);
            $d = $f * $k;
            if ($base - $d >= 0) {
                $i += $f;
                $base -= $d;
            }
            $b[$k] = $ar - $f;
            if ($b[$k] < 1) {
                unset($b[$k]);
            }
        }
        $res++;
        $arr = $b;
    }
    IO::line($res);
}

?>

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

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

function binary_search($list, $item) {
  $low = 0;
  $high = count($list) - 1; $s = $high;

  while ($low <= $high) {
    $mid = (int) ($low + $high) / 2;
    $guess = $list[$mid];

    if ($guess >= $item) { $s = $mid; $high = $mid - 1; }
    else { $low = $mid + 1; }
  }
  return $s;
}

for ($i = 0; $i < $t; $i++) {
  list($n, $w) = explode(" ", trim(fgets($file)));
  $a = explode(" ", trim(fgets($file)));
  sort($a);
  $f = array();
  for ($j = 0; $j < $n; $j++) $f[$j] = $w;
  for ($j = $n - 1; $j >= 0; $j--) {
		$x = binary_search($f, $a[$j]);
		$f[$x] -= $a[$j];
	}
	$ans = 0;

	for ($j = 0; $j < $n; $j++) {
	  if ($f[$j] != $w) $ans++;
	}
	echo $ans.PHP_EOL;
}
?>

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

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

function binary_search($list, $item) {
  $low = 0;
  $high = count($list); $s = $high;

  while ($low <= $high) {
    $mid = floor(($low + $high) / 2);
    $guess = $list[$mid];

    if ($guess >= $item) { $s = $mid; $high = $mid - 1; }
    else { $low = $mid + 1; }
  }
  return $s;
}

for ($i = 0; $i < $t; $i++) {
  list($n, $w) = explode(" ", trim(fgets($file)));
  $a = explode(" ", trim(fgets($file)));
  sort($a);

  for ($j = 0; $j < $n; $j++) $f[$j] = $w;
  for ($j = $n - 1; $j >= 0; $j--) {
		$x = binary_search($f, $a[$j]);
		$f[$x] -= $a[$j];
	}
	$ans = 0;

	for ($j = 0; $j < $n; $j++) {
	  if ($f[$j] != $w) $ans++;
	}
	echo $ans.PHP_EOL;
}
?>

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

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

function binary_search($list, $item) {
  $low = 0;
  $high = count($list) - 1; $s = $high;

  while ($low <= $high) {
    $mid = floor(($low + $high) / 2);
    $guess = $list[$mid];

    if ($guess >= $item) { $s = $mid; $high = $mid - 1; }
    else { $low = $mid + 1; }
  }
  return $s;
}

for ($i = 0; $i < $t; $i++) {
  list($n, $w) = explode(" ", trim(fgets($file)));
  $a = explode(" ", trim(fgets($file)));
  sort($a);

  for ($j = 0; $j < $n; $j++) $f[$j] = $w;
  for ($j = $n - 1; $j >= 0; $j--) {
		$x = binary_search($f, $a[$j]);
		$f[$x] -= $a[$j];
	}
	$ans = 0;

	for ($j = 0; $j < $n; $j++) {
	  if ($f[$j] != $w) $ans++;
	}
	echo $ans.PHP_EOL;
}
?>

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

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

for ($i = 0; $i < $t; $i++) {
  list($n, $w) = explode(" ", trim(fgets($file)));
  $a = explode(" ", trim(fgets($file)));
  $sum = array_sum($a);

  $ans = ceil($sum / $w);
  echo $ans.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;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $w) = IO::arr();
    $a = IO::arr();
    $arr = [];
    foreach ($a as $v) {
        if (isset($arr[$v])) {
            $arr[$v] += 1;
        } else {
            $arr[$v] = 1;
        }
    }
    $i = 0;
    $res = 0;
    krsort($arr);
    while($i < $n) {
        $base = $w;
        $t = [];
        foreach ($arr as $k => $ar) {
            if ($base - $k >= 0) {
                $t[$k] = $ar;
                $base -= $k;
            }
        }
        $x = min($t);
        $res += $x;
        $i += $x * count($t);
        foreach ($t as $k => $f) {
            $arr[$k] -= $x;
            if($arr[$k] == 0) {
                unset($arr[$k]);
            }
        }
    }
    IO::line($res);
}

?>


<?php
$IN = STDIN;
fscanf($IN, "%d", $n);
$items = explode(" ",trim(fgets($IN)));

$curr = 0;
for ($i=0;$i<(count($items));$i++){
    if ($items[$i]!=$items[$i-1]){
        $normalized[$curr] = $items[$i];
        $curr++;
    } else {
        $cellweight[$curr-1] += 1;
    }
}

if (count($normalized)>1) {
    $locmin[] = 0;
    for ($i=1;$i<(count($normalized)-1);$i++)
        if (($normalized[$i]<$normalized[$i+1])&&($normalized[$i]<$normalized[$i-1]))
            $locmin[] = $i;
    $locmin[] = count($normalized)-1;
} else {
    $locmin = Array(0,0);
}

for ($i=1;$i<count($locmin);$i++){
    $len = 0;
    for ($j=$locmin[$i-1];$j<=$locmin[$i];$j++)
        $len = $len + 1 + (int)$cellweight[$j];
        $lenarr[] = $len;
}

echo (count($lenarr)>1)?max($lenarr):$lenarr[0];

?>


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
$e = explode(" ", trim(fgets(STDIN)));
$f = 0;
for($x = 0; $x < $a; $x++)
{
     $g = explode(" ", trim(fgets(STDIN)));
     for($y = 0; $y < $b; $y++)
     {
          if($g[$y] == 1)
          {
               $g[$y] = min($d[$y], $e[$f]);
          }
     }
     $f++;
     print implode(" ", $g) . "\n";
}
?>

<?php

$ser = explode(' ', trim(fgets(STDIN)));

$n = $ser[0];
$m = $ser[1];
$h = $ser[2];

$front = explode(' ', trim(fgets(STDIN)));
$left = explode(' ', trim(fgets(STDIN)));

$top = [];

for($i = 0; $i<$n; $i++){
	$top[] = explode(' ', trim(fgets(STDIN)));
}

for($i = 0; $i<$n; $i++){
	for($j = 0; $j<$m; $j++){
		if($top[$i][$j] == 1){
			$top[$i][$j] = min($front[$j], $left[$i]);
		}
	}
}

for($i = 0; $i<$n; $i++){
	fwrite(STDOUT, implode(' ', $top[$i])."\n");
}


<?php

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

$n = (int)$n;
$s = (int)$s;

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

if (intval($a[0]) == 0) {
	echo 'NO';
} else {
	if (intval($a[$s-1])==1) {
		echo 'YES';
	} else {
		if (intval($b[$s-1]) == 1) {
			$l = 0;
			for($i=$s; $i<=$n-1; $i++) {
				if (intval($a[$i])==1 && intval($b[$i])==1) {
					$l = $i;
					break;
				}
			}

			if ($l>0) {
				echo 'YES';
			} else {
				echo 'NO';
			}
		} else {
			echo 'NO';
		}
	}
}


<?php

ob_start(null, 65536);

$__ln = explode("\n", file_get_contents("php://stdin"));
$__lc = 0;

function nl() {
    global $__ln, $__lc;
    return $__ln[$__lc++];
}

function nla() {
    global $__ln, $__lc;
    return explode(" ", $__ln[$__lc++]);
}

function asInt($x) {
    return (int)$x;
}

function asDouble($x) {
    return (double)$x;
}

$tc = asInt(nl());
for($cc=0; $cc<$tc; $cc++) {
    $n = asInt(nl());
    $buf = array_map(asInt::class, nla());
    $a = new SplFixedArray($n+2);
    $x = 0;
    foreach($buf as $v) {
        $a[$x++] = $v;
    }
    $q = new SplFixedArray($n+2);
    $s = 0; $e = 0;
    $q[$e++] = [1, 0];
    for($i=1; $i<$n; $i++) {
        if($a[$i-1] < $a[$i]) {
            $q[$e++] = [$a[$i], $q[$s][1]+1];
        } else {
            $s++;
            $q[$e++] = [$a[$i], $q[$s][1]+1];
        }
    }
    echo $q[$n-1][1] . "\n";
}

<?php

ob_start(null, 65536);

$__ln = explode("\n", file_get_contents("php://stdin"));
$__lc = 0;

function nl() {
    global $__ln, $__lc;
    return $__ln[$__lc++];
}

function nla() {
    global $__ln, $__lc;
    return explode(" ", $__ln[$__lc++]);
}

function asInt($x) {
    return (int)$x;
}

function asDouble($x) {
    return (double)$x;
}

$tc = asInt(nl());
for($cc=0; $cc<$tc; $cc++) {
    $n = asInt(nl());
    $buf = array_map(asInt::class, nla());
    $a = new SplFixedArray($n+2);
    $x = 0;
    foreach($buf as $v) {
        $a[$x++] = $v;
    }
    $q = new SplFixedArray($n+2);
    $s = 0; $e = 0;
    $q[$e++] = 0;
    for($i=1; $i<$n; $i++) {
        if($a[$i-1] < $a[$i]) {
            $q[$e++] = $q[$s]+1;
        } else {
            $s++;
            $q[$e++] = $q[$s]+1;
        }
    }
    echo $q[$n-1] . "\n";
}


<?php
    $s1 = trim(fgets(STDIN));
    $s2 = trim(fgets(STDIN));

    $ret = "NO";
    if (strlen($s1) != strlen($s2))
    {

    }
    else
    {
        $k1 = strpos($s1, "1");
        $k2 = strpos($s2, "1");
        if (($k1 === false && $k2 !== false)||
            ($k1 !== false && $k2 === false)
            )
        {

        }
        else
        {
            $ret = "YES";
        }

    }

    echo $ret;
?>

<?php
	$str1 = trim(fgets(STDIN), "\r\n");
	$str2 = trim(fgets(STDIN), "\r\n");
	$str = $str1 . $str2;
	$ans1 = false;
	$ans2 = false;
	if(strlen($str1) == 1 && strlen($str2) == 1)
		echo $str1 == $str2 ? "YES" : "NO";
	elseif(strlen($str1) != strlen($str2))
		echo "NO";
	else
	{
		for($i = 0; $i < strlen($str1); ++$i)
		{
			$ans1 |= $str1[$i];
			$ans2 |= $str2[$i];
		}
		echo !($ans1 ^ $ans2) ? "YES" : "NO";
	}


<?php
list($n, $k, $m) = explode(" ", trim(fgets(STDIN)));
$v = explode(" ", trim(fgets(STDIN)));
sort($v);
$total=$ans=0;
for($i=0;$i<$n;$i++)
$total+=$v[$i];
//print $total."\n";
for($i=0;$i<=min($m,$n-1);$i++)
    {
        $baki=$n-$i;
        $temp=$total+min($m-$i,$baki*$k);
        $ans=max($ans,$temp/$baki);
        $total-=$v[$i];
       // print $total."\n";
    }
print number_format($ans, 15, ".", "") . "\n";
?>

<?php
list($n, $k, $m) = explode(" ", trim(fgets(STDIN)));
$v = explode(" ", trim(fgets(STDIN)));
sort($v);
$total=$ans=0;
for($i=0;$i<$n;$i++)
$total+=$v[$i];
//print $total."\n";
for($i=0;$i<=min($m,$n-1);$i++)
    {
        $baki=$n-$i;
        $temp=$total+min($m-$i,$baki*$k);
        $ans=max($ans,$temp/$baki);
        $total-=$v[$i];
       // print $total."\n";
    }
print number_format($ans, 6, ".", "") . "\n";
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
rsort($d);
$e = 0;
for($x = 0; $x < $a; $x++)
{
     $f = $d[$x] + $b;
     if($f < $e)
     {
          break;
     }
     else
     {
          $e = $f;
     }
}
print number_format($e, 6, ".", "");
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
rsort($d);
if($c < $a)
{
    $e = array_slice($d, 0, $a - $c);
    $g = array_sum($e) / count($e);
    $d[0]++;
    $h = array_sum($d) / $a;
    $f = max($g, $h);
}
elseif($c == $a)
{
     $f = $d[0] + 1;
}
elseif($c > $a)
{
     $c -= $a;
     $c++;
     $f = $d[0] + min($b, $c);
}
print number_format($f, 6, ".", "") . "\n";
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
rsort($d);
if($c < $a)
{
    $e = array_slice($d, 0, $a - $c);
    $f = array_sum($e) / count($e);
}
elseif($c == $a)
{
     $f = $d[0] + 1;
}
elseif($c > $a)
{
     $c -= $a;
     $c++;
     $f = $d[0] + min($b, $c);
}
print number_format($f, 6, ".", "") . "\n";
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
rsort($d);
if($c <= $a)
{
    $e = array_slice($d, 0, $a - $c);
    $f = array_sum($e) / count($e);
}
else
{
     $c -= $a;
     $f = $d[0] + min($b, $c);
}
print number_format($f, 6, ".", "") . "\n";
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
rsort($d);
if($c < $a)
{
    $e = array_slice($d, 0, $a - $c);
    $f = array_sum($e) / count($e);
}
elseif($c == $a)
{
     $f = $d[0] + 1;
}
elseif($c > $a)
{
     $c -= $a;
     $f = $d[0] + min($b, $c);
}
print number_format($f, 6, ".", "") . "\n";
?>

<?php
	fscanf(STDIN, "%d %d %d", $n,$k,$m);
	$a = fscanf(STDIN, str_pad("",2*$n,"%d"));
	//print_r($a);
	rsort($a, SORT_NUMERIC);
	$m = $a[0]+min($k,$m);
	echo $m;
?>

<?php
	fscanf(STDIN, "%d %d %d", $n,$k,$m);
	$a = fscanf(STDIN, str_pad("",2*$n,"%d"));
	//print_r($a);
	rsort($a, SORT_NUMERIC);
	$m = $a[0]+$k;
	echo $m;
?>

<?php
list($n, $k, $m) = explode(" ", trim(fgets(STDIN)));
$v = explode(" ", trim(fgets(STDIN)));
sort($v);
$total=$ans=0;
for($i=0;$i<$n;$i++)
$total+=$v[$i];
//print $total."\n";
for($i=0;$i<=min($m,$n-1);$i++)
    {
        $baki=$n-$i;
        $temp=$total+min($m-$i,$baki*$k);
        $ans=max($ans,$temp/$baki);
        $total-=$v[$i];
       // print $total."\n";
    }
print number_format($ans, 5, ".", "") . "\n";
?>