<?php
fgets(STDIN);
while(($line = trim(fgets(STDIN))) != false) {
    //echo $line;

    $allParticipants = explode(" ", $line);
    $a = explode(" ", $line)[0];

    $i = 0;
    foreach ($allParticipants as $key => $value) {
        if ($key !== 0 && $a < $value) $i++;
    }

    echo "$i\n";
}

?>

<?php

fscanf(STDIN, "%d", $case);

for($i=0; $i < $case; $i++){
	$array = explode(" ", trim(fgets(STDIN)));

	$my = $array[0];

	$total = 0;

	for($j=1; $j < 4; $j++){
		if($array[$j] > $my){
			$total++;
		}
	}

	echo $total."\n";
}

<?php
$x=(int)readline();
for ($i=0; $i<$x;$i++)
{
    $tp=0;
    $tmp=(string)readline();
    $inp=explode(" ",$tmp);
    $first=$inp[0];
    for ($j=1;$j<count($inp);$j++)
    {
        if ($inp[$j]>$first){
            $tp+=1;
        }
    }
    echo $tp;
    echo "\n";
}

<?php

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

fscanf($inp, '%d', $t);

while ($t--) {
    $ar = fscanf($inp, str_repeat('%d ', 4));

    echo count(array_filter($ar, static fn($el) => $el > $ar[0])) . PHP_EOL;
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    $v = ($a = fgetcsv(STDIN, 0, ' '))[0];
    rsort($a);
    printf("%d\n", array_search($v, $a));
}

<?php

function process($a, $b, $c, $d){
 $f = array($b, $c, $d);
 $dem = 0;
 foreach($f as $i){
  if((int)($a) - (int)($i) < 0){
   $dem+=1;
  }
 }
 return $dem;
}

$_ = (int)(readline());

for ($i = 0; $i < $_; $i+=1){
  $s = readline();
  list($a, $b, $c, $d) = explode(" ", $s);
  echo process($a, $b, $c, $d);
  echo "\n";
}

?>

<?php
$testcases = readline();
for ($i = $testcases; $i > 0; $i--) {
    $a = readline();
    $count = 0;
    $arr = explode(" ", $a);

    for ($j = 1; $j < 4; $j++) {
        if ($arr[$j] > $arr[0]) {

            $count++;
        }
    }
    echo $count."\n";

}

?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $Marathon = explode(" ", trim(fgets(STDIN)));
    $num = 0;
    for ($i = 0; $i < count($Marathon); $i++) {
        // $t += $walk[$i];
        if ($Marathon[0] < $Marathon[$i]) {
            $num++;
        }
    }
    array_push($array, $num);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$iter = InOutPut::get();

for($i=0; $i <$iter; $i++) {
    $ans = 0;
    $a = InOutPut::getArr();
    $len = count($a);
    for($j = 1; $j < $len; $j++){
    	if($a[$j] > $a[0]){
    		$ans++;
    	}
    }
    InOutPut::print($ans);
}
class InOutPut {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArr()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function print($string)
    {
        echo $string . "\n";
    }
}
?>

От yoralbayev, соревнование: Codeforces Round #799 (Div. 4), задача: (A) Марафон, Неправильный ответ на тесте 1, #, Скопировать
<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

 $loop = true;
 $t = $loop ? IO::getInt() : 1;
 while($t--) {
      solve();
 }

 function solve()
 {
     $mod = 1000000007;
     $intMaxValue = 2147483646; //2147483647
     $alph = 'abcdefghijklmnopqrstuvwxyz';

     list($a, $b, $c, $d) = IO::getArray();
     $ans =0;
     if($b> $a){
          $ans++;
     }
     if($c> $a){
          $ans++;
     }
     if($d> $a){
          $ans++;
     }
          IO::pr($ans);

 }

 class IO {
      public static function getInt()
      {
          return trim(fgets(STDIN));
      }

     public static function getArray()
     {
         return explode(' ', trim(fgets(STDIN)));
     }
     public static function pr($s)
     {
          echo $s, PHP_EOL;
     }
     public static function prArray($s)
     {
          echo implode( ' ', $s), PHP_EOL;
     }
     public static function getMinValue($x, $y) {
         return $x > $y ? $y : $x;
     }
     public static function getMaxValue($x, $y) {
         return $x > $y ? $x : $y;
     }
 }

 class Algor {
     public static function efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    public static function isPrime($n) {
         $d = 2;
         while ($n % $d != 0) {
         $d += 1;
         }

        return $d == $n;
    }

     public static function fabicon($n, $a) {
         if($n <= 1) {
             return $a[$n];
         }
         for($i=2; $i<=$n; $i++) {
             $a[$i] = $a[$i-1] + $a[$i-2];
         }

         return $a[$n];
     }

     function getRotate($a, $s, $e, $ind) {
         $ar = [];
         for ($i= $s; $i<=$e; $i++) {
             $ar[$i] = $a[$i];
             $j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
             // echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
             $a[$i] = $j < $i ? $ar[$j] : $a[$j];
         }
         return $a;
     }

}

class bigOperation {
     public static function efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    public static function  isBigNumber($n)
    {
        return bccomp($n, INTMAXVALUE) == 1;
    }
    // bcadd — Сложить 2 числа произвольной точности
    public static function  bcAdd($x, $y)
    {
        return bcadd($x, $y);
    }
// bccomp — Сравнение двух чисел произвольной точности
//return 1 if x>y, 0= x==y, -1 x < y
    public static function  bcComp($x, $y)
    {
        return bccomp($x, $y);
    }
// bcdiv — Операция деления для чисел произвольной точности
    public static function  bcDiv($x, $y)
    {
        return bcdiv($x, $y);
    }
// bcmod — Получает остаток от деления чисел с произвольной точностью
    public static function  bcMod($x, $y)
    {
        return bcmod($x, $y);
    }
// bcmul — Умножение двух чисел с произвольной точностью
    public static function  bcMul($x, $y)
    {
        return bcmul($x, $y);
    }
// bcpow — Возведение в степень чисел с произвольной точностью
    public static function  bcPow($x, $y)
    {
        return bcpow($x, $y);
    }
// bcpowmod — Возводит одно число в степень другого и возвращает остаток от деления результата на третье число
// bcscale — Задает количество чисел после десятичной точки по умолчанию для всех bc math функций.
// bcsqrt — Извлекает квадратный корень из числа с произвольной точностью
    public static function  bcSqrt($x, $y)
    {
        return bcsqrt($x, $y);
    }
// bcsub — Вычитает одно число с произвольной точностью из другого
    public static function  bcSub($x, $y)
    {
        return bcsub($x, $y);
    }
    public static function getMaxValue($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    public static function getMinValue($x, $y) {
        return bccomp($x, $y) == 1 ? $y : $x;
    }

    public static function getDareje($n, $k) {
        if($k == 0) {
            return 1;
        }
        return bcmul($n, self::getDareje($n, $k-1));
    }
}

class Sorting
{
    public static function mergeSort($aArray) {
        if(count($aArray) <= 1) {
            return $aArray;
        }
        $aLeft = [];
        $aRight = [];
        $n =floor(count($aArray) / 2);
        for($i = 0; $i <$n; $i++) {
            $aLeft[] = $aArray[$i];
        }
        for($i = $n; $i <count($aArray); $i++) {
            $aRight[] = $aArray[$i];
        }

        return self::merge(self::mergeSort($aLeft), self::mergeSort($aRight));
    }

    public static function merge($aLeft, $aRight) {
        $aResult = [];
        $iL = 0;
        $iR = 0;

        while($iL < count($aLeft) && $iR < count($aRight)) {
            if($aLeft[$iL] <= $aRight[$iR]) {
                $aResult[] = $aLeft[$iL];
                $iL++;
            } else {
                $aResult[] = $aRight[$iR];
                $iR++;
            }
        }

        while($iL < count($aLeft)) {
            $aResult[] = $aLeft[$iL];
            $iL++;
        }
        while($iR < count($aRight)) {
            $aResult[] = $aRight[$iR];
            $iR++;
        }

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

 $loop = false;
 $t = $loop ? IO::getInt() : 1;
 while($t--) {
      solve();
 }

 function solve()
 {
     $mod = 1000000007;
     $intMaxValue = 2147483646; //2147483647
     $alph = 'abcdefghijklmnopqrstuvwxyz';

     list($a, $b, $c, $d) = IO::getArray();
     $ans =0;
     if($b> $a){
          $ans++;
     }
     if($c> $a){
          $ans++;
     }
     if($d> $a){
          $ans++;
     }
          IO::pr($ans);

 }

 class IO {
      public static function getInt()
      {
          return trim(fgets(STDIN));
      }

     public static function getArray()
     {
         return explode(' ', trim(fgets(STDIN)));
     }
     public static function pr($s)
     {
          echo $s, PHP_EOL;
     }
     public static function prArray($s)
     {
          echo implode( ' ', $s), PHP_EOL;
     }
     public static function getMinValue($x, $y) {
         return $x > $y ? $y : $x;
     }
     public static function getMaxValue($x, $y) {
         return $x > $y ? $x : $y;
     }
 }

 class Algor {
     public static function efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    public static function isPrime($n) {
         $d = 2;
         while ($n % $d != 0) {
         $d += 1;
         }

        return $d == $n;
    }

     public static function fabicon($n, $a) {
         if($n <= 1) {
             return $a[$n];
         }
         for($i=2; $i<=$n; $i++) {
             $a[$i] = $a[$i-1] + $a[$i-2];
         }

         return $a[$n];
     }

     function getRotate($a, $s, $e, $ind) {
         $ar = [];
         for ($i= $s; $i<=$e; $i++) {
             $ar[$i] = $a[$i];
             $j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
             // echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
             $a[$i] = $j < $i ? $ar[$j] : $a[$j];
         }
         return $a;
     }

}

class bigOperation {
     public static function efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    public static function  isBigNumber($n)
    {
        return bccomp($n, INTMAXVALUE) == 1;
    }
    // bcadd — Сложить 2 числа произвольной точности
    public static function  bcAdd($x, $y)
    {
        return bcadd($x, $y);
    }
// bccomp — Сравнение двух чисел произвольной точности
//return 1 if x>y, 0= x==y, -1 x < y
    public static function  bcComp($x, $y)
    {
        return bccomp($x, $y);
    }
// bcdiv — Операция деления для чисел произвольной точности
    public static function  bcDiv($x, $y)
    {
        return bcdiv($x, $y);
    }
// bcmod — Получает остаток от деления чисел с произвольной точностью
    public static function  bcMod($x, $y)
    {
        return bcmod($x, $y);
    }
// bcmul — Умножение двух чисел с произвольной точностью
    public static function  bcMul($x, $y)
    {
        return bcmul($x, $y);
    }
// bcpow — Возведение в степень чисел с произвольной точностью
    public static function  bcPow($x, $y)
    {
        return bcpow($x, $y);
    }
// bcpowmod — Возводит одно число в степень другого и возвращает остаток от деления результата на третье число
// bcscale — Задает количество чисел после десятичной точки по умолчанию для всех bc math функций.
// bcsqrt — Извлекает квадратный корень из числа с произвольной точностью
    public static function  bcSqrt($x, $y)
    {
        return bcsqrt($x, $y);
    }
// bcsub — Вычитает одно число с произвольной точностью из другого
    public static function  bcSub($x, $y)
    {
        return bcsub($x, $y);
    }
    public static function getMaxValue($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    public static function getMinValue($x, $y) {
        return bccomp($x, $y) == 1 ? $y : $x;
    }

    public static function getDareje($n, $k) {
        if($k == 0) {
            return 1;
        }
        return bcmul($n, self::getDareje($n, $k-1));
    }
}

class Sorting
{
    public static function mergeSort($aArray) {
        if(count($aArray) <= 1) {
            return $aArray;
        }
        $aLeft = [];
        $aRight = [];
        $n =floor(count($aArray) / 2);
        for($i = 0; $i <$n; $i++) {
            $aLeft[] = $aArray[$i];
        }
        for($i = $n; $i <count($aArray); $i++) {
            $aRight[] = $aArray[$i];
        }

        return self::merge(self::mergeSort($aLeft), self::mergeSort($aRight));
    }

    public static function merge($aLeft, $aRight) {
        $aResult = [];
        $iL = 0;
        $iR = 0;

        while($iL < count($aLeft) && $iR < count($aRight)) {
            if($aLeft[$iL] <= $aRight[$iR]) {
                $aResult[] = $aLeft[$iL];
                $iL++;
            } else {
                $aResult[] = $aRight[$iR];
                $iR++;
            }
        }

        while($iL < count($aLeft)) {
            $aResult[] = $aLeft[$iL];
            $iL++;
        }
        while($iR < count($aRight)) {
            $aResult[] = $aRight[$iR];
            $iR++;
        }

        return $aResult;

    }
}

class SolveArchive
{

}

<?php

$line = fgets(STDIN);
$allParticipants = explode(" ", $line);
$a = explode(" ", $line)[0];

$i = 0;
foreach ($allParticipants as $key => $value) {
    if ($key !== 0 && $a < $value) $i++;
}

echo $i;

?>

<?php
$x=(int)readline();
for ($i=0; $i<$x;$i++)
{
    $tp=0;
    $tmp=(string)readline();
    $inp=explode(" ",$tmp);
    $first=$inp[0];
    for ($j=1;$j<count($inp);$j++)
    {
        if ($inp[$j]>$first){
            $tp+=1;
        }
    }
    echo $tp;
}


<?php

	//$input = fopen("input.txt", "r");
	//fscanf($input, "%d\n", $t);

	fscanf(STDIN, "%d\n", $t);
	while($t--){
		fscanf(STDIN, "%d %d\n", $n, $m);
		$n = min($n-1, 2);
		echo ($n*$m) . "\n";
	}

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     if($b == 1)
     {
          print "0\n";
     }
     elseif($b == 2)
     {
          print $c . "\n";
     }
     else
     {
          print min(2, $b - 1) * $c . "\n";
     }
}
?>

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

   fscanf($stdin, "%d\n", $t);

   for($i=0; $i<$t; $i++){
        fscanf($stdin, "%d%d\n", $n,$m);
        if($n == 1){
            $ans = 0;
        }elseif($n == 2){
            $ans = $m;
        }else{
            $ans = $m*2;
        }

        echo $ans."\n";
   }

   fclose($stdin);
   //fclose($stdout);
?>

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

   fscanf($stdin, "%d\n", $t);

   for($i=0; $i<$t; $i++){
        fscanf($stdin, "%d%d\n", $n,$m);
        if($n == 1){
            $ans = 0;
        }elseif($n == 2){
            $ans = $m;
        }elseif($n < $m && $n%2 == 0){
            $ans = (int)($m/2) + $m;
        }elseif($n < $m && $n%2 != 0){
            $ans = $m;
        }else{
            $ans = $m*2;
        }

        echo $ans."\n";
   }

   fclose($stdin);
   //fclose($stdout);
?>


<?php

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

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

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

$result = 0;

$mapKeys = array();

for($i = 0; $i < 2 * $n - 2; $i += 2)
{
	$key = strtoupper($path[$i]);
	if(!isset($mapKeys[$key]))
	{
		$mapKeys[$key] = 0;
	}

	$mapKeys[$key] += 1;

	$door = $path[$i + 1];
	if(!isset($mapKeys[$door]) || !$mapKeys[$door])
	{
		$result++;
	}
	else
	{
		$mapKeys[$door]--;
	}
}

echo $result;

<?php

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

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

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

$r = 0;
$keys = [];

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

$c = 0;

for ($i = 0; $i < (2 * $n - 2); $i += 2) {
    $key = strtoupper($s[$i]);
    $door = $s[$i + 1];

    if (!isset($keys[$key])) {
        $keys[$key] = 0;
    }

    $keys[$key]++;

    if (!isset($keys[$door]) || !$keys[$door]) {
        $r++;
    } else {
        $keys[$door]--;
    }
}

fwrite($output, $r);

<?php

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

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

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

$r = 0;
$doors = $keys = [];

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

$c = 0;

for ($i = 0; $i < (2 * $n - 2); $i += 2) {
    $next = $s[$i + 1];
    $big = strtoupper($s[$i]);

    // ключ из текущей комнаты не подходит к следующей двери
    if ($big !== $next) {

        // у нас есть ключ для следующей двери из прошлых комнат
        if (isset($keys[$next]) && $keys[$next] > 0) {
            $keys[$next]--;
        }

        // у нас нет ключей для следующей комнаты, поэтому нужно увеличить список дверей.
        // это значит, что нам нужно купить ключ заранее для этой двери
        //
        // Также мы на этом этапе сохраняем ключ из текущей комнаты. вдруг дальше он пригодится
        else
        {
            $doors[$next] = isset($doors[$next]) ? ($doors[$next] + 1) : 1;
            $keys[$big] = isset($keys[$big]) ? ($keys[$big] + 1) : 1;
        }
    }
}

$r = array_sum($doors);

fwrite($output, $r);

// show 8 test

if ($n === 100000) {
    fwrite($output, PHP_EOL);

    for ($i = 0; $i < 200; $i++) {
        fwrite($output, substr($s, 500 * $i, 500) . PHP_EOL);
    }
}

<?php

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

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

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

$r = 0;
$doors = $keys = [];

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

$c = 0;

for ($i = 0; $i < (2 * $n - 2); $i += 2) {
    $next = $s[$i + 1];
    $big = strtoupper($s[$i]);

    if ($big !== $next) {
        if (isset($keys[$next]) && $keys[$next] > 0) {
            $keys[$next]--;
        } else {
            $doors[$next] = isset($doors[$next]) ? $doors[$next] + 1 : 1;
            $keys[$big] = isset($keys[$big]) ? $keys[$big] + 1 : 1;
        }
    }
}

$r = array_sum($doors);

fwrite($output, $r);

<?php

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

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

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

$r = 0;
$doors = $keys = [];

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

$c = 0;

for ($i = 0; $i < (2 * $n - 2); $i += 2) {
    $key = strtoupper($s[$i]);
    $door = $s[$i + 1];

    // ключ из текущей комнаты не подходит к следующей двери
    if ($key !== $door) {
        // у нас нет ключей для следующей комнаты, поэтому нужно увеличить список дверей.
        // это значит, что нам нужно купить ключ заранее для этой двери
        //
        // Также мы на этом этапе сохраняем ключ из текущей комнаты. вдруг дальше он пригодится
        if (!isset($keys[$door]) || !$keys[$door]) {
            $doors[$door] = isset($doors[$door]) ? ($doors[$door] + 1) : 1;
            $keys[$key] = isset($keys[$key]) ? ($keys[$key] + 1) : 1;
        }

        // у нас есть ключ для следующей двери из прошлых комнат
        else
        {
            $keys[$door]--;
        }
    }
}

$r = array_sum($doors);

fwrite($output, $r);

<?php

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

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

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

$r = 0;
$doors = $keys = [];

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

$c = 0;

for ($i = 0; $i < strlen($s) - 1; $i += 2) {
    $next = $s[$i + 1];
    $big = strtoupper($s[$i]);

    if ($i % 2 === 0) {
        if ($big !== $next) {
            if (isset($keys[$next]) && $keys[$next] > 0) {
                $keys[$next]--;
            } else {
                $doors[$next] = isset($doors[$next]) ? $doors[$next] + 1 : 1;
                $keys[$big] = isset($keys[$big]) ? $keys[$big] + 1 : 1;
            }
        }
    }
}

$r = array_sum($doors);

fwrite($output, $r);

<?php

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

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

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

$r = 0;
$doors = $keys = [];

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

$c = 0;

for ($i = 0; $i < (2 * $n - 2); $i += 2) {
    $next = $s[$i + 1];
    $big = strtoupper($s[$i]);

    // ключ из текущей комнаты не подходит к следующей двери
    if ($big !== $next) {

        // у нас есть ключ для следующей двери из прошлых комнат
        if (isset($keys[$next]) && $keys[$next] > 0) {
            $keys[$next]--;
        }

        // у нас нет ключей для следующей комнаты, поэтому нужно увеличить список дверей.
        // это значит, что нам нужно купить ключ заранее для этой двери
        //
        // Также мы на этом этапе сохраняем ключ из текущей комнаты. вдруг дальше он пригодится
        else
        {
            $doors[$next] = isset($doors[$next]) ? ($doors[$next] + 1) : 1;
            $keys[$big] = isset($keys[$big]) ? ($keys[$big] + 1) : 1;
        }
    }
}

$r = array_sum($doors);

fwrite($output, $r);

// show 8 test

if ($n === 100000) {
    fwrite($output, PHP_EOL);

    for ($i = 0; $i < 200; $i++) {
        fwrite($output, substr($s, (500 * $i - 1), 500) . PHP_EOL);
    }
}


<?php
error_reporting("off");
//334A: Candy Bags
$n = trim(fgets(STDIN)); //$n = 6;
$candyboxes = pow($n, 2);
$halfway = $candyboxes / 2;
$sections = $halfway / $n;
$curindex = 1;
$brothers = array(); //multidimen
$answer = "";

//assign sections from the first half
for ($i = 1; $i <= $n; $i++) {
    $endofsection = (int)$curindex + (int)$sections - 1;
    $brothers[$i] = range($curindex, $endofsection);
    $curindex += $sections;
}

//now add their other halfs from the top half
$onehundredplusone = $candyboxes + 1;
foreach ($brothers as $key => $valuearray) {
    foreach ($valuearray as $value) {
        $brothers[$key][] = $onehundredplusone - $value;
    }
    $answer .= implode(" ", $brothers[$key])."\n";
}

echo $answer;
?>

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	//for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/2); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo " ";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo PHP_EOL;
				}

	//}

}else{
	echo" Your input is not even";
	}

?>

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
    $bags = pow($brothers, 2); //bag==4

    $candies=0;
    //$acount=0;
    for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
         $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
         $array[]=$x;
        // $acount++;
         }

    //$bagcount=$brothers;
    $bcount=0;
    $ccount=sizeof($array)-1;

    for($y=0;$y<(sizeof($array)/2); $y++){ //this loop will run 4 times

        echo $array[$bcount];
        echo " ";
        echo $array[$ccount];
        $bcount++;
        $ccount--;
        echo PHP_EOL;
        }

}else{
    echo" Your input is not even";
    }
?>

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4
$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
     $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
     $array[]=$x;
     $acount++;
     }
    $bagcount=$brothers;
    $bcount=0;
    $ccount=sizeof($array)-1;
    //for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

            for($y=0;$y<(sizeof($array)/2); $y++){ //this loop will run 4 times

                $reverse=$array[$ccount];
                echo $array[$bcount];
                    echo " ";
                echo $reverse;
                $bcount++;
                $ccount--;
                    echo PHP_EOL;
                }
}else{
    echo" Your input is not even";
    }
?>

<?php
    // $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
    $bag = pow($input, 2);
    for($i=1; $i<=$bag; $i++)
        $total_candy = $i+$total_candy;
    $fair_distribute = $total_candy/$input;

    $round=0;
    for($j=1; $j<=$bag/2;){
        $round=$input/2;
        while($round!=0){
            echo $j.' '.($bag-$j+1).' ';
            $round--;
            $j++;
        }
        echo PHP_EOL;
    }

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	//for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/$bagcount); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo " ";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo PHP_EOL;
				}

	//}

}else{
	echo" Your input is not even";
	}

?>

<?php
$bothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/$bagcount); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo "\n";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo PHP_EOL;
				}

	}

}else{
	echo" Your input is not even";
	}

?>

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/$bagcount); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo " ";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo PHP_EOL;
				}

	}

}else{
	echo" Your input is not even";
	}

?>

<?php
$bothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/$bagcount); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo "\n";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo "\n";
				}

	}

}else{
	echo" Your input is not even";
	}

?>

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/$bagcount); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo "\n";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo PHP_EOL;
				}

	}

}else{
	echo" Your input is not even";
	}

?>

<?php
	// $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
	$bag = pow($input, 2);
	for($i=1; $i<=$bag; $i++)
		$total_candy = $i+$total_candy;
	$fair_distribute = $total_candy/$input;

	for($j=1; $j<$input; $j++){
		echo $j.' '.($fair_distribute-$j).PHP_EOL;
	}
	echo ($j).' '.($fair_distribute-$j);

<?php
    // $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
    $bag = pow($input, 2);
    for($i=1; $i<=$bag; $i++)
        $total_candy = $i+$total_candy;
    $fair_distribute = $total_candy/$input;

    $round=0;
    for($j=1; $j<=$input*2;){
        $round=$input/2;
        while($round!=0){
            echo $j.' '.($bag-$j+1).' ';
            $round--;
            $j++;
        }
        echo PHP_EOL;
    }

<?php
    // $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
    $bag = pow($input, 2);
    for($i=1; $i<=$bag; $i++)
        $total_candy = $i+$total_candy;
    $fair_distribute = $total_candy/$input;

    $round=0;
    for($j=1; $j<=$input*2; $j++){
        $round=$input/2;
        while($round!=0){
            echo $j.' '.($bag-$j+1).' ';
            $round--;
            $j++;
        }
        echo PHP_EOL;
    }

<?php
error_reporting("off");
//334A: Candy Bags
$n = trim(fgets(STDIN)); $n = 6;
$candyboxes = pow($n, 2);
$halfway = $candyboxes / 2;
$sections = $halfway / $n;
$curindex = 1;
$brothers = array(); //multidimen
$answer = "";

//assign sections from the first half
for ($i = 1; $i <= $n; $i++) {
    $endofsection = (int)$curindex + (int)$sections - 1;
    $brothers[$i] = range($curindex, $endofsection);
    $curindex += $sections;
}

//now add their other halfs from the top half
$onehundredplusone = $candyboxes + 1;
foreach ($brothers as $key => $valuearray) {
    foreach ($valuearray as $value) {
        $brothers[$key][] = $onehundredplusone - $value;
    }
    $answer .= implode(" ", $brothers[$key])."\n";
}

echo $answer;
?>


<?php
    $n   = fgets(STDIN);
    $arr = fgets(STDIN);
    $arr = explode(" ", trim($arr));
    $min = min($arr);
    $max = max($arr);
    $ans = 0;

    for ($i = 0; $i < $n; ++$i) {
        if ($arr[$i] > $min && $arr[$i] < $max) {
    		++$ans;
    	}
    }

    echo $ans . "\n";
?>

<?php

$num = fgets(STDIN);
$nums = fgets(STDIN);

$nums = explode(" ", trim($nums));

$min = min($nums);
$max = max($nums);

$s = 0;
foreach($nums as $n)
{
	if($n > $min && $n < $max)
	{
		$s++;
	}
}

echo $s . PHP_EOL;

<?php
fgets(STDIN);
$counts = array_count_values(explode(" ", trim(fgets(STDIN))));

ksort($counts);

array_pop($counts);
array_shift($counts);

$sum = 0;
$v = array_values($counts);
for ($i = 0; $i < count($v); $i++) {
    $sum += $v[$i];
}

echo $sum;

<?php
[$count, $forces] = explode(PHP_EOL, file_get_contents('php://stdin'));
$forces = explode(' ', $forces);
$result = 0;
$min = min($forces);
$max = max($forces);
foreach ($forces as $f) {
    if ($f > $min && $f < $max) {
        $result++;
    }
}
echo $result;

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

fgets(STDIN);
$counts = array_count_values(explode(" ", trim(fgets(STDIN))));

ksort($counts);

pop($counts);
shift($counts);

$sum = 0;
$v = array_values(counts);

for ($i = 0; $i < count($v); $i++) {
    $sum += $v[$i];
}

echo $sum;


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

<?php
    $parity = true;
    fscanf(STDIN, "%d %d", $b, $k);
    $line = fgets(STDIN);
    $values = explode(" ", $line);
    for($i = 0; $i < $k; $i++) {
    if($b % 2 == 0) {
        if((int)$values[$k - 1] % 2 == 1) {
        $parity = !$parity;
        }
        break;
    } else {
        if((int)$values[$i] % 2 == 1) {
        $parity = !$parity;
        }
    }
    }
    if($parity) {
    echo "even";
    } else {
    echo "odd";
    }
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = 0;
$e = $b - 1;
for($x = 0; $x < $b; $x++)
{
     $d = bcadd($d, bcmul($c[$x], pow($a, $e)));
     $e--;
}
$f = bcmod($d, 2);
if($f == 0)
{
     print "even";
}
else
{
     print "odd";
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = 0;
$e = $b - 1;
for($x = 0; $x < $b; $x++)
{
     $d += $c[$x] * pow($a, $e);
     $e--;
}
$f = $d % 2;
if($f == 0)
{
     print "even";
}
else
{
     print "odd";
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = 0;
$e = $b - 1;
for($x = 0; $x < $b; $x++)
{
     $d += $c[$x] * pow($a, $e);
     $e--;
}
$f = bcmod($d, 2);
if($f == 0)
{
     print "even";
}
else
{
     print "odd";
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = 0;
$e = $b - 1;
for($x = 0; $x < $b; $x++)
{
     $d += bcmul($c[$x], pow($a, $e));
     $e--;
}
$f = bcmod($d, 2);
if($f == 0)
{
     print "even";
}
else
{
     print "odd";
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array();
$e = $b;
for($x = 0; $x < $b; $x++)
{
     $e--;
     $f = ($c[$x] * pow($a, $e)) % 2;
     $d[$x] = $f;
}
$g = array_sum($d);
$h = $g % 2;
if($h == 0)
{
     print "even";
}
else
{
     print "odd";
}
?>

<?php
    $sum = 0;
    fscanf(STDIN, "%d %d", $b, $k);
    $line = fgets(STDIN);
    $values = explode(" ", $line);
    for($i = 0; $i < $k; $i++) {
      $sum += (int)$values[$i] * pow($b, $k - $i - 1);
    }
    if($sum % 2 == 0) {
      echo "even";
    } else {
      echo "odd";
    }
?>


<?php
    //error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
    //error_reporting(E_ALL ^ E_DEPRECATED);
    //$in = fopen("input.in", "r");
    $in = fopen("php://stdin", "r");
    $arr = split(" ", fgets($in));
    $n = fgets($in);
    $g = gcd($arr[0], $arr[1]);
    for($i = 1; $i * $i <= $g; $i++)
        if($g % $i == 0)
        {
            $j = $g / $i;
            $u[] = $i;
            if($i != $j) $u[] = $j;
        }
    sort($u);
    for($i = 0; $i < $n; $i++)
    {
        $array = split(" ", fgets($in));
        $low = 0; $high = count($u) - 1;
        while($low < $high)
        {
            $mid = ($low + $high + 1) / 2;
            if($u[$mid] <= $array[1]) $low = $mid;
            else $high = $mid - 1;
        }
        if($array[0] <= $u[$low] && $u[$low] <= $array[1]) echo $u[$low] . "\n";
        else echo "-1\n";
    }
    function gcd($a, $b)
    {
        return $b == 0 ? $a : gcd($b, $a % $b);
    }

<?php
    //error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
    error_reporting(E_ALL ^ E_DEPRECATED);
    //$in = fopen("input.in", "r");
    $in = fopen("php://stdin", "r");
    $arr = split(" ", fgets($in));
    $n = fgets($in);
    $g = gcd($arr[0], $arr[1]);
    for($i = 1; $i * $i <= $g; $i++)
        if($g % $i == 0)
        {
            $j = $g / $i;
            $u[] = $i;
            if($i != $j) $u[] = $j;
        }
    sort($u);
    for($i = 0; $i < $n; $i++)
    {
        $array = split(" ", fgets($in));
        $low = 0; $high = count($u) - 1;
        while($low < $high)
        {
            $mid = ($low + $high + 1) / 2;
            if($u[$mid] <= $array[1]) $low = $mid;
            else $high = $mid - 1;
        }
        if($array[0] <= $u[$low] && $u[$low] <= $array[1]) echo $u[$low] . "\n";
        else echo "-1\n";
    }
    function gcd($a, $b)
    {
        return $b == 0 ? $a : gcd($b, $a % $b);
    }


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

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

fscanf(STDIN, "%d", $n);
$p = explode(" ", trim(fgets(STDIN)));
if (DEBUG) {
	var_dump($p);
}

for ($i = 1; $i <= $n; $i++) {
	$array = array_pad(array(), $n + 1, 0);
	if (DEBUG) {
		var_dump($array);
	}

	$point = $i;
	while (true) {
		if (DEBUG) {
			echo "-----\n";
		}

		if (DEBUG) {
			echo $point . PHP_EOL;
		}

		$array[$point]++;
		if ($array[$point] == 2) {
			$answer[] = $point;
			break;
		}
		$point = $p[$point - 1];
	}
}
echo implode(" ", $answer);

<?php
$z = fopen('php://stdin','r');
$n = intval(fgets($z));
$a = array_map(function($v) {return intval($v);}, explode(' ', fgets($z)));
array_unshift($a,0);

for($i = 1; $i <= $n; $i++) {
    $b = array_pad(array(0), $n+1, 0);
    $j = $i;
    $b[$j]=1;
    do {
        $j = $a[$j];
        $b[$j]++;
    } while ($b[$j] < 2);
    echo $j . " ";
}

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


<?php
list($c, $p) = explode(" ", trim(fgets(STDIN)));
$s = explode(" ", trim(fgets(STDIN)));

sort($s);

$i = $c - $p;

echo $s[$i];

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
print $c[$b - 1];
?>

<?php
/*
 * Secdra @2020
 */

fscanf(STDIN, "%d %d", $n, $k);
$a = explode(' ', trim(fgets(STDIN)));
sort($a);
$a = array_slice($a, -$k);
printf("%d", $a[0]);


<?php

    $n = trim(fgets(STDIN));
    $segments = array();
    for ($i = 0; $i < $n; $i++) {
        list($center, $radius) = explode(" ", trim(fgets(STDIN)));
        $segments[$i] = (object) array('left' => $center - $radius, 'right' => $center + $radius);
    }

    usort($segments, function($seg1, $seg2) { return $seg1 -> right > $seg2 -> right; });

    $last = -2000000111;
    $ans = 0;
    for ($i = 0; $i <$n; $i++) {
        if ($segments[$i] -> left >= $last) {
            $ans++;
            $last = $segments[$i] -> right;
        }
    }

    echo $ans;

<?php

    $n = trim(fgets(STDIN));
    $segments = array();
    for ($i = 0; $i < $n; $i++) {
        list($center, $radius) = explode(" ", trim(fgets(STDIN)));
        $segments[$i] = new stdClass();
        $segments[$i] -> left = $center - $radius;
        $segments[$i] -> right = $center + $radius;
    }

    usort($segments, function($seg1, $seg2) { return $seg1 -> right > $seg2 -> right; });

    $last = -2000000111;
    $ans = 0;
    for ($i = 0; $i <$n; $i++) {
        if ($segments[$i] -> left >= $last) {
            $ans++;
            $last = $segments[$i] -> right;
        }
    }

    echo $ans;

<?php

    class Segment {
        public $left, $right;

        public function __construct() {}

        public function setLeft($left) {
            $this -> left = $left;
        }

        public function setRight($right) {
            $this -> right = $right;
        }
    }

    function cmp($seg1, $seg2) {
        return $seg1 -> right - $seg2 -> right;
    }

    $n = trim(fgets(STDIN));
    $segments = array();
    for ($i = 0; $i < $n; $i++) {
        list($center, $radius) = explode(" ", trim(fgets(STDIN)));
        $segments[$i] = new Segment();
        $segments[$i] -> setLeft($center - $radius);
        $segments[$i] -> setRight($center + $radius);
    }

    usort($segments, "cmp");

    $last = -2000000111;
    $ans = 0;
    for ($i = 0; $i <$n; $i++) {
        if ($segments[$i] -> left >= $last) {
            $ans++;
            $last = $segments[$i] -> right;
        }
    }

    echo $ans;

<?php

    class Segment {
        public $left, $right;

        public function __construct($left, $right) {
            $this -> left = $left;
            $this -> right = $right;
        }
    }

    function cmp($seg1, $seg2) {
        return $seg1 -> right - $seg2 -> right;
    }

    $n = trim(fgets(STDIN));
    $segments = array();
    for ($i = 0; $i < $n; $i++) {
        list($center, $radius) = explode(" ", trim(fgets(STDIN)));
        $segments[$i] = new Segment($center - $radius, $center + $radius);
    }

    usort($segments, "cmp");

    $last = -2000000111;
    $ans = 0;
    for ($i = 0; $i <$n; $i++) {
        if ($segments[$i] -> left >= $last) {
            $ans++;
            $last = $segments[$i] -> right;
        }
    }

    echo $ans;


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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $k1) = IO::arr();
    $h = IO::arr();
    $res = -1;
    $last = 0;
    for($i = 1; $i <= $k1; $i++) {
        for($k = 0; $k < count($h); $k++) {
            $b = false;
            if(isset($h[$k+1])) {
                if((int)$h[$k] < (int)$h[$k+1]) {
                    $h[$k] += 1;
                    $b = true;
                    $last = $k+1;
                    break;
                }
            }
        }
        if(!$b) {
            break;
        }
    }
    if($b) {
        IO::line($last);
    } else {
        IO::line($res);
    }

}

<?php

$times = (int) trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($ni[], $ki[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $hi[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $k = &$ki[$idx];
    $h = &$hi[$idx];
    for ($i = 0; $i < $k; ++$i) {
        for ($j = 0; $j < $n - 1; ++$j) {
            if ($h[$j] < $h[$j + 1]) {
                ++$h[$j];
                $pos = $j + 1;
                continue 2;
            }
        }
        echo -1 .PHP_EOL;
        continue 2;
    }
    echo $pos.PHP_EOL;
}

<?php
$t = trim(fgets(STDIN));
for ($o = 0; $o < $t; $o++) {
  list($n, $k) = explode(" ", trim(fgets(STDIN)));
  $h = explode(" ", trim(fgets(STDIN)));
  $wasted = false;
  for ($i = 0; $i < $k; $i++) {
    for ($j = 0; $j < $n; $j++) {
      if ($j === $n - 1) {
        $wasted = true;
        break;
      }
      if ($h[$j] < $h[$j + 1]) {
        if ($i === $k - 1) echo ($j + 1) . "\n";
        else $h[$j] += 1;
        break;
      }
    }
    if ($wasted) {
      echo (-1) . "\n";
      break;
    }
  }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($x,$y) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    $bFlag = false;
    $iPosition = 0;
    while ($y < 0 || !$bFlag) {
        if ($y == 0) {
            break;
        }
        $k = b($aList);
        if ($k >= 0) {
            $aList[$k] = $aList[$k] + 1;
            $iPosition = $k;
            $y--;
        } else {
            $bFlag = true;
        }
    }
    if ($bFlag) {
        echo "-1\n";
    } else {
        echo ($iPosition + 1)."\n";
    }
}

function b ($aList, $j = 0) {
    for ($i = $j; $i < count($aList) - 1; $i++) {
        if ($aList[$i] < $aList[$i+1]) {
            return $i;
        }
    }
    return -1;
}

<?php

$times = (int) trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($ni[], $ki[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $hi[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $k = &$ki[$idx];
    $h = &$hi[$idx];
    for ($i = 0; $i < $n - 1; ++$i) {
        if ($h[$i + 1] > $h[$i]) {
            for ($j = $i; $j >= 0; --$j) {
                if ($h[$i + 1] > $h[$j]) {
                    $k -= $h[$i + 1] - $h[$j];
                    $h[$j] = $h[$i + 1];
                    if ($k <= 0) {
                        echo ($j+1).PHP_EOL;
                        continue 3;
                    }
                } else {
                    break;
                }
            }
        }
    }
    echo -1 .PHP_EOL;
}

<?php
$t = trim(fgets(STDIN));
for ($o = 0; $o < $t; $o++) {
  list($n, $k) = explode(" ", trim(fgets(STDIN)));
  $h = explode(" ", trim(fgets(STDIN)));
  $wasted = false;
  for ($i = 0; $i < $k; $i++) {
    for ($j = 0; $j < $n; $j++) {
      if ($j === $n - 1) {
        $wasted = true;
        break;
      }
      if ($h[$j] < $h[$j + 1]) {
        if ($i === $k - 1) echo $j + 1;
        else $h[$j] += 1;
        break;
      }
    }
    if ($wasted) {
      echo -1;
      break;
    }
  }
}


<?php
define('LOCAL_ENV', false);
if (LOCAL_ENV) {
    error_reporting(E_ALL);
    $stdin = fopen('401bin.txt', 'r+');
} else {
    error_reporting(0);
    $stdin = STDIN;
}
list($x, $k) = explode(' ', trim(fgets($stdin)));
$a = array();
for ($i = 0; $i < $k; $i++) {
    $s = trim(fgets($stdin));
    $arr = explode(' ', $s);
    $a[$i] = array((int) $arr[1], isset($arr[2]) ? (int) $arr[2] : (int) $arr[1]);
}

usort($a, function($x, $y) {
    if ($x[0] == $y[0]) {
        return 0;
    }
    return $x[0] < $y[0] ? -1 : 1;
});

$min = 0; $max = 0;
array_unshift($a, array(0, 0));
array_push($a, array($x, $x));
for ($i = 1; $i < count($a); $i++) {
    $r = $a[$i][0] - $a[$i-1][1] - 1;
    if ($r > 0) {
        $max += $r;
        $min += floor($r * 0.5) + $r % 2;
    }
}

echo $min . ' ' . $max;


<?php
$a = trim(fgets(STDIN));
$b = range(1, $a);
$c = array_slice($b, 0, -1);
array_unshift($c, $a);
print implode(" ", $c);
?>


<?php
	$n = trim(fgets(STDIN));
	$a = explode(' ', trim(fgets(STDIN)));
	$sum = $c = 0;
	sort($a);
	for($i = 0; $i < $n; $i++)
		if($sum <= $a[$i])
		{
			$c++;
			$sum += $a[$i];
		}
	echo $c;
?>


<?php

$handle = fopen ("php://stdin", "r");
fscanf($handle, "%d %d", $radius, $k);
echo d($handle, (int)$radius, (int)$k);

function d($handle, $radius, $k){
    $j = (int)fgets($handle);
    $count = 0;
    for($i = 1; $i <= $j; $i++){
        fscanf($handle, "%d %d %d", $x, $y, $r);
        $min = sqrt(pow($x, 2) + pow($y, 2)) - $r;
        $max = sqrt(pow($x, 2) + pow($y, 2)) + $r;
        if($min >= ($radius - $k) & $max <= $radius){
            $count++;
        }
    }
    return $count;
}

<?php

$handle = fopen ("php://stdin", "r");
fscanf($handle, "%d %d", $radius, $k);
if($radius === 0 || $k === 0){
    echo 0;
    return;
}
$j = (int)fgets($handle);
$count = 0;
for($i = 1; $i <= $j; $i++){
    fscanf($handle, "%d %d %d", $x, $y, $r);
    $min = sqrt(pow($x, 2) + pow($y, 2)) - $r;
    $max = sqrt(pow($x, 2) + pow($y, 2)) + $r;
    if($min > $radius/2 & $max < ($radius/2 + $k)){
        $count++;
    }
}
echo $count;

<?php
//$handle = fopen ("php://stdin", "r");
//scanf($handle, "%d %d %d", $a, $b, $k);
//fgets($f);
//$a = array_map('intval', $a);
//$handle = fopen ("D:\input.txt", "r");

$handle = fopen ("php://stdin", "r");
fscanf($handle, "%d %d", $radius, $k);
if($k > 0){
    echo d($handle, $radius, $k);
}else{
    echo 0;
}

function d($handle, $radius, $k){
    $j = (int)fgets($handle);
    $count = 0;
    for($i = 1; $i <= $j; $i++){
        fscanf($handle, "%d %d %d", $x, $y, $r);
        $min = sqrt(pow($x, 2) + pow($y, 2)) - $r;
        $max = sqrt(pow($x, 2) + pow($y, 2)) + $r;
        if($min >= ($radius - $k) & $max <= $radius){
            $count++;
        }
    }
    return $count;
}

<?php

$handle = fopen ("php://stdin", "r");
fscanf($handle, "%d %d", $radius, $k);
$j = (int)fgets($handle);
$count = 0;
for($i = 1; $i <= $j; $i++){
    fscanf($handle, "%d %d %d", $x, $y, $r);
    $min = sqrt(pow($x, 2) + pow($y, 2)) - $r;
    $max = sqrt(pow($x, 2) + pow($y, 2)) + $r;
    if($min >= $radius/2 && $max <= ($radius/2 + $k)){
        $count++;
    }
}
echo $count;

<?php
$handle = fopen ("php://stdin", "r");
fscanf($handle, "%d %d", $radius, $k);
$j = (int)fgets($handle);
$count = 0;
for($i = 1; $i <= $j; $i++){
    fscanf($handle, "%d %d %d", $x, $y, $r);
    $min = sqrt(pow($x, 2) + pow($y, 2)) - $r;
    $max = sqrt(pow($x, 2) + pow($y, 2)) + $r;
    if($min > $radius/2 && $max < ($radius/2 + $k)){
        $count++;
    }
}
echo $count;


<?php
#1197A
$start = microtime(1);
$t = trim(fgets(STDIN));
while ($t--) {
    $n = trim(fgets(STDIN));
    $a = trim(fgets(STDIN));
    if ($n < 3) {
        fwrite(STDOUT, 0);
    } else {
        $a = explode(' ', $a);
        sort($a);
        $l = array_pop($a);
        $r = array_pop($a);
        fwrite(STDOUT, min($l - 1, $r - 1, count($a)));
    }
    fwrite(STDOUT,  PHP_EOL);
}
#echo PHP_EOL . (microtime(1) - $start);

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     rsort($c);
     $d = array_slice($c, 0, 2);
     $e = array_slice($c, 2);
     $f = min($d) - 1;
     print min($f, count($e)) . "\n";
}
?>

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $c; $i++){
    list($d) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    arsort($aArray);
    $iCount = 0;
    $aTest = [];
    foreach ($aArray as $sK => $sV){
        $aTest[] = $sV;
    }
    $iTotal = $aTest[1] - 1;
    if($d < 3){
        echo "0"."\n";
    } elseif($iTotal <= ($d - 2)){
        echo $iTotal."\n";
    } else if ($iTotal > ($d - 2)){
        echo ($d-2)."\n";
    }

}

<?php
$t = trim(fgets(STDIN));
while ($t--) {
    $n = trim(fgets(STDIN));
    $a = explode(' ', trim(fgets(STDIN)));
    rsort($a);
    fwrite(STDOUT, min($a[0] - 1, $a[1] - 1, count($a) - 2) . PHP_EOL);
}

<?php
$t = trim(fgets(STDIN));
while ($t--) {
    $n = trim(fgets(STDIN));
    $a = explode(' ', trim(fgets(STDIN)));
    sort($a);
    $l = array_pop($a);
    $r = array_pop($a);
    fwrite(STDOUT, min($l - 1, $r - 1, count($a)) . PHP_EOL);
}

<?php
    $n = trim(fgets(STDIN));
    for($i = 1; $i <= $n; $i++){
         $c = trim(fgets(STDIN));
         $a = explode(" ", trim(fgets(STDIN)));
         $count = 0;
         $arr = array();
         arsort($a);
         foreach($a as $v){
             $count+=1;
             if($count == 2){
                 $k = $v-1;
             }
         }
         if($c < 3){
             echo "0\n";
         } else if($k <= ($c - 2)){
             echo $k."\n";
         } else if ($k > ($c - 2)){
             echo ($c-2)."\n";
         }
    }

 ?>

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $c; $i++){
    list($d) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iMax1= max($aArray);
    $iMaxIndex = array_keys($aArray, max($aArray));
    unset($aArray[$iMaxIndex[0]]);
    $iMax2 = max($aArray);
    $iMaxIndex = array_keys($aArray, max($aArray));
    unset($aArray[$iMaxIndex[0]]);

    $iCount = 0;
    foreach ($aArray as $sK => $sV){
        if($sV + 1 <= $iMax1 && $sV + 1 <= $iMax2){
            $iCount++;
        }
    }
    if($iCount > $d - 2){
        echo ($d - 2) . "\n";
    } else {
        echo $iCount."\n";
    }
}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $c; $i++){
    list($d) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iMax1= max($aArray);
    $iMaxIndex = array_keys($aArray, max($aArray));
    unset($aArray[$iMaxIndex[0]]);
    $iMax2 = max($aArray);
    $iMaxIndex = array_keys($aArray, max($aArray));
    unset($aArray[$iMaxIndex[0]]);

    $iCount = 0;
    foreach ($aArray as $sK => $sV){
        if($sV + 1 <= $iMax1 && $sV + 1 <= $iMax2){
            $iCount++;
        }
    }
    if($iCount >= $d - 2){
        echo ($d - 2) . "\n";
    } else {
        echo $iCount."\n";
    }
}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $c; $i++){
    list($d) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iMax1= max($aArray);
    $iMaxIndex = array_keys($aArray, max($aArray));
    unset($aArray[$iMaxIndex[0]]);
    $iMax2 = max($aArray);
    $iMaxIndex = array_keys($aArray, max($aArray));
    unset($aArray[$iMaxIndex[0]]);
    $iCount = 0;
    foreach ($aArray as $sK => $sV){
        if($sV < $iMax1 && $sV < $iMax2){
            $iCount++;
        }
    }
    if($iCount > $d - 2){
        echo ($d - 2) . "\n";
    } else {
        echo $iCount."\n";
    }
}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $c; $i++){
    list($d) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    arsort($aArray);
    $iCount = 0;
    $aTest = [];
    foreach ($aArray as $sK => $sV){
        $aTest[] = $sV;
    }
    if(($aTest[0] >= ($d - 2)) && ($aTest[1] >= ($d - 2))){
        if($aTest[1] <= $d - 2){
            echo ($d - 2 - 1)."\n";
        } else {
            echo $d - 2 ."\n";
        }
    } else {
        echo "0"."\n";
    }

}

<?php
#1197A
$start = microtime(1);
$t = trim(fgets(STDIN));
while ($t--) {
    $n = trim(fgets(STDIN));
    if ($n < 3) {
        fwrite(STDOUT, 0);
    } else {
        $a = explode(' ', trim(fgets(STDIN)));
        sort($a);
        $l = array_pop($a);
        $r = array_pop($a);
        fwrite(STDOUT, min($l - 1, $r - 1, count($a)));
    }
    fwrite(STDOUT,  PHP_EOL);
}
#echo PHP_EOL . (microtime(1) - $start);


<?php

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

$n = (int)$n; // days
$m = (int)$m; // bowls
$k = (int)$k; // plates

$_m = $m;
$_k = $k;

$a = explode(' ', getLine());

$answer = 0;

for ($i = 0, $n = min($n, count($a)); $i < $n; $i ++) {
  if ($a[$i] == 1) {
    if ($m == 0) {
      $answer ++;
      $m = 1;
    }
    $m --;
  } else if ($a[$i] == 2) {
     if ($m == 0 && $k == 0) {
      $answer ++;
      $k = 1;
    }
    if ($k > 0) {
      $k --;
    } else if ($m > 0) {
      $m --;
    }
  }
}

print $answer;

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

<?php
list($n, $m, $k) = explode(" ", trim(fgets(STDIN)));
$a=explode(" ", trim(fgets(STDIN)));
$i=0;
$nofk=0;
$nofm=0;
while($n!==0){
if($a[$i]==1){
$nofm=$nofm+1;
              }else{
			  $nofk=$nofk+1;
			       }
$i++;
$n--;
              }

				 if($nofm>$m){
				 $s=$nofm-$m;
				 if($nofk>$k){
				 $j=$nofk-$k;
				 echo $j+$s;
				 }else{
				 echo $s ;
				 }
				 }else{
				 $s=$m-$nofm;
				 $mk=$s+$k;
				 if($nofk>$mk){
				 echo $nofk-$mk;
				 }else{
				 echo"0";
				 }
				 }

?>

<?php
$stdin = fopen('php://stdin', 'r');
$i = 1;
$wash_counter = 0;

while($i <= 2) {
    $line = trim(fgets($stdin));
    $temp_arr = explode(' ', $line);
    if($i == 1) {
        $n = $temp_arr[0];
        $m = $temp_arr[1];
        $k = $temp_arr[2];
    }
    if($i == 2) {
        $dish_arr = $temp_arr;
    }
    $i++;
}

fclose($stdin);
//echo $n."\n";
//echo $m."\n";
//echo $k."\n";

//print_r($dish_arr);
for($j=0;$j<$n;$j++) {
    switch($dish_arr[$j]) {
        case 1:
            if($m != 0) {
                $m--;
            }
            else {
                $wash_counter++;
            }
            break;
        case 2:
            if($k != 0) {
                $k--;
                break;
            }
            if($m != 0) {
                $m--;
                break;
            }

            $wash_counter++;
            break;
    }
}

echo $wash_counter."\n";
?>

<?php
$stdin = fopen('php://stdin', 'r');
$i = 1;
$wash_counter = 0;

while($i <= 2) {
    $line = trim(fgets($stdin));
    if($i == 1) {
        $n = $line[0];
        $m = $line[2];
        $k = $line[4];
    }
    if($i == 2) {
        $dishes = $line;
        $dish_arr = explode(' ', $dishes);
    }
    $i++;
}

fclose($stdin);
//echo $n."\n";
//echo $m."\n";
//echo $k."\n";

//print_r($dish_arr);
for($j=0;$j<$n;$j++) {
    switch($dish_arr[$j]) {
        case 1:
            if($m != 0) {
                $m--;
            }
            else {
                $wash_counter++;
            }
            break;
        case 2:
            if($k != 0) {
                $k--;
                break;
            }
            if($m != 0) {
                $m--;
                break;
            }

            $wash_counter++;
            break;
    }
}

echo $wash_counter."\n";
?>

<?php
$stdin = fopen('php://stdin', 'r');
$i = 1;
$wash_counter = 0;

while($i <= 2) {
    $line = trim(fgets($stdin));
    if($i == 1) {
        $n = $line[0];
        $m = $line[2];
        $k = $line[4];
    }
    if($i == 2) {
        $dishes = $line;
        $dish_arr = explode(' ', $dishes);
    }
    $i++;
}

fclose($stdin);
//echo $n."\n";
//echo $m."\n";
//echo $k."\n";

//print_r($dish_arr);
for($j=0;$j<$n;$j++) {
    switch($dish_arr[$j]) {
        case 1:
            if($m != 0) {
                $m--;
            }
            else {
                $wash_counter++;
            }
            break;
        case 2:
            if($m != 0) {
                $m--;
                break;
            }
            else if($k != 0) {
                $k--;
                break;
            }
            else if($m == 0 && $k == 0) {
                $wash_counter++;
            }
            break;
    }
}

echo $wash_counter."\n";
?>

<?php
$stdin = fopen('php://stdin', 'r');
$i = 1;
$wash_counter = 0;
$input_arr = array();

while($i <= 2) {
	$line = trim(fgets($stdin));
	if($i == 1) {
		$n = $line[0];
		$m = $line[2];
		$k = $line[4];
	}
	if($i == 2) {
		$dishes = $line;
		$dish_arr = explode(' ', $dishes);
	}
	$i++;
}

fclose($stdin);
//echo $n."\n";
//echo $m."\n";
//echo $k."\n";

//print_r($dish_arr);
for($j=0;$j<$n;$j++) {
	switch($dish_arr[$j]) {
		case 1:
			if($m != 0) {
				$m--;
			}
			else {
				$wash_counter++;
			}
			break;
		case 2:
			if($m != 0) {
				$m--;
				break;
			}
			else if($k != 0) {
				$k--;
				break;
			}
			else if($m == 0 && $k == 0) {
				$wash_counter++;
			}
			break;
	}
}

echo $wash_counter;

?>

<?php
$stdin = fopen('php://stdin', 'r');
$i = 1;
$wash_counter = 0;

while($i <= 2) {
    $line = trim(fgets($stdin));
    if($i == 1) {
        $n = $line[0];
        $m = $line[2];
        $k = $line[4];
    }
    if($i == 2) {
        $dishes = $line;
        $dish_arr = explode(' ', $dishes);
    }
    $i++;
}

fclose($stdin);
//echo $n."\n";
//echo $m."\n";
//echo $k."\n";

//print_r($dish_arr);
for($j=0;$j<$n;$j++) {
    switch($dish_arr[$j]) {
        case 1:
            if($m != 0) {
                $m--;
            }
            else {
                $wash_counter++;
            }
            break;
        case 2:
            if($m != 0) {
                $m--;
                break;
            }
            if($k != 0) {
                $k--;
                break;
            }

            $wash_counter++;
            break;
    }
}

echo $wash_counter."\n";
?>


<?php

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

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

$result = -1;

$map = [];

$vals = [
    'A' => 1,
    'B' => 2,
    'C' => 4,
];

$totalSum = array_sum($vals);

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

    fscanf($h, '%d %s', $price, $vits);

    $len = strlen($vits);

    $key = $vals[$vits[0]] + (isset($vits[1]) ? $vals[$vits[1]] : 0) + (isset($vits[2]) ? $vals[$vits[2]] : 0);

    if (!isset($map[$len])) {
        $map[$len] = [];
    }

    if (!isset($map[$len][$key]) || $map[$len][$key] > $price) {
        $map[$len][$key] = $price;
    }
}

$mins = [];

if (isset($map[1]) && count($map[1]) == 3) {
    $mins[] = array_sum($map[1]);
}

if (isset($map[3])) {
    $mins[] = min($map[3]);
}

if (isset($map[2])) {

    foreach ($map[2] as $key => $price) {

        if (isset($map[1]) && isset($map[1][$totalSum - $key])) {

            $mins[] = $price + $map[1][$totalSum - $key];
        }

        if ($key != 3 && isset($map[2][3])) {
            $mins[] = $price + $map[2][3];
        }

        if ($key != 6 && isset($map[2][6])) {
            $mins[] = $price + $map[2][6];
        }

        if ($key != 5 && isset($map[2][5])) {
            $mins[] = $price + $map[2][5];
        }
    }
}

echo $mins ? min($mins) : -1;


<?php
// I'm best and smarter human in the world :)

$n = readline();
$s = readline();
echo solve() . "\n";

function solve() {
	global $n, $s;
	$p_sum = 0;
	for ($i = 0; $i < $n; $i++) {
		$p_sum += ($s[$i] == '('? 1: -1);
		if ($p_sum < -1)
			return "No";
	}
	if ($p_sum != 0)
		return "No";
	return "Yes";
}


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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($q, $d) = IO::arr();
    $a = IO::arr();
    $ends = [];
    for($i = 1; $i <= 10; $i++){
        $j = $d * $i;
        $j = str_split($j);
        $ends[end($j)] = $i;
    }
    foreach ($a as $b) {
        $bool = false;
        for ($h = 0; $h <= 100; $h++) {
            $res = bcsub($b, ($h * $d));
            if($res < 0) {
                break;
            }
            $res = substr($res, -2);
            if (strpos($res, $d) !== false) {
                $bool = true;
                break;
            }
        }
        if($bool) {
            IO::yes();
        } else {
            IO::no();
        }
    }
}

<?php
$iCount = read();

for($i=0; $i < $iCount; $i++) {
    $aTest = explode(' ', read());
    $aTest2 = explode(' ', read());

    $iLuck = $aTest[1];
    foreach ($aTest2 AS $sTest) {
        $iTest = (int)$sTest;
        if(strpos($sTest, $iLuck . '') !== false) {
            write('YES');
            continue;
        } else {
            while ($iTest > $iLuck || strpos($iTest . '', $iLuck . '') !== false) {
                $iTest -= $iLuck;
                if (strpos($iTest . '', $iLuck . '') !== false) {
                    write('YES');
                    continue 2;
                }
            }
        }

        write('NO');

    }
}

function write($a) {
    echo $a . "\n";
}

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

  <?php
  $t = trim(fgets(STDIN));
   for($w=0; $w<$t; $w++) {

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

           for($i = 0; $i<$q; $i++) {
              $iN = $a[$i];
              if($iN >= $d) {
                  while($iN >= $d) {
                        if(goodNum($iN, $d)) {
                            echo "YES\n";
                            break;
                        } else {
                            $iN = $iN - $d;
                            if($iN < $d) {
                                echo "NO\n";
                            }
                        }
                    }
              } else {
                  echo "NO\n";
              }

          }

    }

   function goodNum($iNum, $d) {
        if($iNum < $d) {
            return false;
        }
        $sV = strval($iNum);
            for($i = 0; $i < strlen($sV); $i++) {
                if(intval($sV[$i]) == $d) {
                    return true;
                }
            }
            return false;
    }

<?php

$times = (int) trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($qi[], $di[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $q = &$qi[$idx];
    $d = &$di[$idx];
    $a = &$ai[$idx];
    for ($i = 0; $i < $q; ++$i) {
        $b = $a[$i];
        if ($b >= 10 * $d) {
            echo 'YES'.PHP_EOL;
            continue;
        }
        while ($b > 0) {
            if (0 == $b % $d) {
                echo 'YES'.PHP_EOL;
                continue 2;
            }
            $b -= 10;
        }
        echo 'NO'.PHP_EOL;
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        if ($sV > 100) {
            echo "YES\n";
            continue;
        } else {
            while ($sV > $d || strpos($sV , $d . '') !== false) {
                if (strpos($sV, $d . '') !== false) {
                    echo "YES\n";
                    continue 2;
                }
                $sV -= $d;
            }
        }
        echo "NO\n";
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        if ($sV > 100) {
            echo "YES\n";
            continue;
        } else {
            $iTemp = $sV;
            $iLength = strlen($iTemp);
            while ($iTemp > $d || $iTemp[($iLength - 1)] == $d) {
                //echo $iTemp . ' ' . "\n";
                if ($iTemp[($iLength - 1)] == $d) {
                    echo "YES\n";
                    continue 2;
                }
                $iTemp = strval($iTemp - $d);
                $iLength = strlen($iTemp);
            }
        }
        echo "NO\n";
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        if ($sV > 100) {
            echo "YES\n";
        } else {
            $bFlag = false;
            if ($sV[(strlen($sV) - 1)] == $d) {
                echo "YES\n";
            } else {
                while ($sV > $d) {
                    //echo $sV . "\n";
                    $sV = strval($sV - $d);
                    $iLength = strlen($sV);
                    if ($sV[($iLength - 1)] == $d) {
                        $bFlag = true;
                        break;
                    }
                }
                if ($bFlag) {
                    echo "YES\n";
                } else {
                    echo "NO\n";
                }
            }
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        if ($sV > 90) {
            echo "YES\n";
        } else {
            $bFlag = false;
            if ($sV[(strlen($sV) - 1)] == $d) {
                echo "YES\n";
            } else {
                while ($sV > $d) {
                    //echo $sV . "\n";
                    $sV = strval($sV - $d);
                    $iLength = strlen($sV);
                    if ($sV[($iLength - 1)] == $d) {
                        $bFlag = true;
                        break;
                    }
                }
                if ($bFlag) {
                    echo "YES\n";
                } else {
                    echo "NO\n";
                }
            }
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        $iLength = strlen($sV);
        if ($sV[$iLength - 1] == $d && $sV < 100) {
            echo "YES\n";
        } else {
            $iTemp = $sV;
            $bFlag = false;
            while ($iTemp > 9) {
                echo $iTemp . "\n";
                if (strlen($iTemp) > 2 && $iTemp > 170) {
                    $iTemp -= ($d * pow(10,(strlen($iTemp) - 2)));
                } else {
                    $iTemp = strval($iTemp - $d);
                    if ($iTemp < 110) {
                        $iLength = strlen($iTemp);
                        if ($iTemp[($iLength - 1)] == $d) {
                            $bFlag = true;
                            break;
                        }
                    }
                }
            }
            if ($bFlag) {
                echo "YES\n";
            } else {
                echo "NO\n";
            }
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        $iLength = strlen($sV);
        if ($sV[$iLength - 1] == '7' && $sV < 100) {
            echo "YES\n";
        } else {
            $iTemp = $sV;
            $bFlag = false;
            while ($iTemp > 9) {
                //echo $iTemp . "\n";
                if (strlen($iTemp) > 2 && $iTemp > 170) {
                    $iTemp -= (7 * pow(10,(strlen($iTemp) - 2)));
                } else {
                    $iTemp = strval($iTemp - 7);
                    if ($iTemp < 110) {
                        $iLength = strlen($iTemp);
                        if ($iTemp[($iLength - 1)] == 7) {
                            $bFlag = true;
                            break;
                        }
                    }
                }
            }
            if ($bFlag) {
                echo "YES\n";
            } else {
                echo "NO\n";
            }
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        $iLength = strlen($sV);
        if ($sV[$iLength - 1] == '7' && $sV < 100) {
            echo "YES\n";
        } else {
            $iTemp = $sV;
            $bFlag = false;
            while ($iTemp > 9) {
                //echo $iTemp . "\n";
                if (strlen($iTemp) > 2 && $iTemp > 170) {
                    $iTemp -= (7 * pow(10,(strlen($iTemp) - 2)));
                } else {
                    $iTemp = strval($iTemp - 7);
                    if ($iTemp < 100) {
                        $iLength = strlen($iTemp);
                        if ($iTemp[($iLength - 1)] == 7) {
                            $bFlag = true;
                            break;
                        }
                    }
                }
            }
            if ($bFlag) {
                echo "YES\n";
            } else {
                echo "NO\n";
            }
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        $iLength = strlen($sV);
        if ($sV[$iLength - 1] == '7') {
            echo "YES\n";
        } else {
            $iTemp = $sV;
            $bFlag = false;
            while ($iTemp > 9) {
                $iTemp = strval($iTemp - 7);
                $iLength = strlen($iTemp);
                if ($iTemp[($iLength - 1)] == 7) {
                    $bFlag = true;
                    break;
                }
            }
            if ($bFlag) {
                echo "YES\n";
            } else {
                echo "NO\n";
            }
        }
    }
}

<?php
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($q, $d) = IO::arr();
    $a = IO::arr();
    $ends = [];
    for($i = 1; $i <= 10; $i++){
        $j = $d * $i;
        $j = str_split($j);
        $ends[end($j)] = $i;
    }
    foreach ($a as $b) {
        $bool = false;
        for ($h = 0; $h <= 20; $h++) {
            $res = bcsub($b, ($h * $d));
            if($res < 0) {
                break;
            }
            $res = substr($res, -2);
            if (strpos($res, $d) !== false) {
                $bool = true;
                break;
            }
        }
        if($bool) {
            IO::yes();
        } else {
            IO::no();
        }
    }
}

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($q, $d) = IO::arr();
    $a = IO::arr();
    $ends = [];
    for($i = 1; $i <= 10; $i++){
        $j = $d * $i;
        $j = str_split($j);
        $ends[end($j)] = $i;
    }
    foreach ($a as $b) {
        if (strlen($b) > 3) {
            $b = substr($b, -3);
        } else {
            $b = $b;
        }
        $c = str_split($b);
        $count = count($c);

        $last = end($c);
        if(isset($last, $ends)) {
            $r = $b - (($ends[$last] - 1) * $d);
            if(strpos($r, $d) !== false) {
                IO::yes();
            } else {
                IO::no();
            }
        } else {
            if($count == 3) {
                $prev = $c[1];
                if(isset($prev, $ends)) {
                    IO::yes();
                } else {
                    IO::no();
                }
            } else {
                IO::no();
            }
        }
    }
}

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($q, $d) = IO::arr();
    $a = IO::arr();
    $ends = [];
    for($i = 1; $i <= 10; $i++){
        $j = $d * $i;
        $j = str_split($j);
        $ends[end($j)] = $i;
    }
    foreach ($a as $b) {
        if (strlen($b) > 3) {
            $b = substr($b, -3);
        } else {
            $b = $b;
        }
        $c = str_split($b);
        $last = end($c);
        if(isset($last, $ends)) {
            $r = $b - (($ends[$last] - 1) * $d);
            if(strpos($r, $d) !== false) {
                IO::yes();
            } else {
                IO::no();
            }
        } else {
            IO::no();
        }
    }
}

<?php
    $iCount = read();

    for($i=0; $i < $iCount; $i++) {
        $aTest = explode(' ', read());
        $aTest2 = explode(' ', read());

        $iLuck = $aTest[1];
        foreach ($aTest2 AS $sTest) {
            $iTest = (int)$sTest;
            if(strpos($sTest, '7') !== false) {
                write('YES');
                continue;
            } else if($iTest < 13) {
                write('NO');
                continue;
            } else {
                while ($iTest > 7 || strpos($iTest . '', '7') !== false) {
                    $iTest -= 7;
                    if (strpos($iTest . '', '7') !== false) {
                        write('YES');
                        continue 2;
                    }
                }
            }

            write('NO');

        }
    }

    function write($a) {
        echo $a . "\n";
    }

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


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

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

$res = 0;
for($i=1;$i<$n;$i++) if($a[$i] < $a[$i - 1]) $res -= $a[$i] - $a[$i - 1];

print $res;
?>


<?php

error_reporting(0);
ob_end_clean();

solve();

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

	$A = $Scanner->Scan();
	$B = $Scanner->Scan();

	$ADig = str_split($A);
	$BDig = str_split($B);
	rsort($BDig);
	$Alen = count($ADig);
	$Blen = count($BDig);
	$start = 0;
	for ($i = 0; $i < $Blen; $i++) {
		$REPLACE = false;
		for ($j = $start; $j < $Alen; $j++) {
			if ($BDig[$i] > $ADig[$j]) {
				$temp = $ADig[$j];
				$ADig[$j] = $BDig[$i];
				$BDig[$i] = $temp;
				$start = $j + 1;
				$REPLACE = true;
				break;
			}
		}
		if (!$REPLACE) break;
	}

	$a =implode($ADig);
	print($a);

	$Scanner->Close();
}

class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);
		$contents = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

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

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

?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = str_split($b);
rsort($c);
$d = 0;
for($x = 0; $x < strlen($a); $x++)
{
    if($c[$d] > $a[$x])
    {
        $a[$x] = $c[$d];
        $d++;
    }
}
print $a;
?>


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

$solve = function($n){

	$k = 1;
	$r = 1;
	do{

		$r *= 2;
		$k += $r;

		if($n % $k == 0){
			return $n / $k;
		}

	} while(true);

};

$t = intval(fgets(STDIN));
for(; $t > 0; $t--){

	$n = intval(fgets(STDIN));

	echo $solve($n) . "\n";
}

<?php
error_reporting(0);

main();

function main() {
	list($cases) = explode(" ", trim(fgets(STDIN)));

	for ($i = 0; $i < $cases; $i++) {
		$n = trim(fgets(STDIN));
		print run($n) . "\n";

	}
}

function run($n) {
	$res = [];

	$num = 0;

	for ($i = 0; $i < 100000; $i++) {
			$num += pow(2, $i);

			$res[$i] = $num;

			if ($num > pow(10, 9)) {
				break;
			}
	}
	foreach ($res as $r) {
		if ($r != 1) {
			if ($n % $r == 0) {
				return $n/$r;
			}
		}
	}

	return -1;

}

?>

<?php

for($t = intval(trim(fgets(STDIN))); $t > 0; $t --){
    //print pow(2, intval(fgets(STDIN)) - 1)."\n";
    $n = intval(fgets(STDIN));
    $limit = $n;
    $flag = 0;
    for($i = 2; $i < $n; $i++){
        $sum = pow(2, $i) - 1;
        if($n % $sum == 0){
            print $n / $sum."\n";
            break;

        }

    }
}

<?php

$t = (int)fgets(STDIN);
for ($i = 0; $i < $t; $i++) {
    $n = (int)fgets(STDIN);
    $k = 2;
    do {
        $x = $n / (pow(2, $k) - 1);
        $k++;
    } while (!is_int($x));

    fputs(STDOUT, $x.PHP_EOL);
}

<?php
    //phpinfo();
    // 输入
    function slove($n)
    {
        for($i = 2; $i <= 30; $i ++)
        {
            if($n % ((1 << $i) - 1) == 0) return $n / ((1 << $i) - 1) ;
        }
        return $n ;
    }

    $a = trim(fgets(STDIN));
    while($a --)
    {
        $n = trim(fgets(STDIN));

        echo slove($n) . "\n" ;
    }
?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = array();
for($x = 1; $x <= $b; $x++)
{
    $c = trim(fgets(STDIN));
    $d = $c % $a;
    array_push($e, $d);
    $f = count($e);
    $g = array_unique($e);
    if($f != count($g))
    {
        break;
    }
}
if($f != count($g))
{
    print $x;
}
else
{
    print "-1";
}
?>

<?php

$occ = [];
$res = -1;
$found = false;
fscanf(STDIN, "%d %d", $p, $n);
for ($i = 0; $i < $n; $i++) {
	$k = (int)fgets(STDIN);
	if (isset($occ[$k % $p]) && !$found) {
		$res = $i+1;
		$found = true;
	}
	else {
		$occ[$k % $p] = 1;
	}
}

echo $res."\n";

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

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

    list($p, $n) = explode(" ", trim(fgets($input)));
    $Flags = Array();

    for ($i=0;$i<$p;$i++)
        $Flags[$i] = 0;

    for ($i=1;$i<=$n;$i++) {
        $m = trim(fgets($input));

        if ($Flags[$m%$p]==1) die(''.$i);

        $Flags[$m%$p]=1;
    }

    echo '-1';

?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = array();
for($x = 1; $x <= $a; $x++)
{
    $c = trim(fgets(STDIN));
    $d = $c % $a;
    array_push($e, $d);
    $f = count($e);
    $g = array_unique($e);
    if($f != count($g))
    {
        break;
    }
}
if($f != count($g))
{
    print $x;
}
else
{
    print "-1";
}
?>


<?php

function readArrayInt($std)
{
    $str = fgets($std);
    $str = explode(' ', $str);
    $a = [];
    $n = count($str);
    for ($i = 0; $i < $n; ++$i)
    {
        $a[] = $str[$i] + 0;
    }
    return $a;
}

function addEdge(&$G, $u, $v, $w)
{
    if (isset($G[$u][$v]))
    {
        $G[$u][$v] = min($G[$u][$v], $w);
    }
    else
    {
        $G[$u][$v] = $w;
    }
}

$stdin = fopen("php://stdin", 'r');
fscanf($stdin, "%d%d%d\n", $n, $m, $k);
$G = [];
for ($i = 0; $i < $m; ++$i)
{
    fscanf($stdin, "%d%d%d\n", $u, $v, $w);
    addEdge($G, $u, $v, $w);
    addEdge($G, $v, $u, $w);
}
$a = array();
if ($k > 0)
{
    $a = readArrayInt($stdin);
}
fclose($stdin);
$used = [];
for ($i = 0; $i < count($a); ++$i)
{
    $used[$a[$i]] = true;
}
$result = -1;
for ($i = 0; $i < count($a); ++$i)
{
    if (isset($G[$a[$i]]))
    {
        $adj = $G[$a[$i]];
        foreach ($adj as $key => $value)
        {
            if (!isset($used[$key]) && ($result == -1 || $result > $value))
            {
                $result = $value;
            }
        }
    }
}
echo $result;
?>


<?php

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

$n--;
$sum=0;

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

for($i=0;$i<$n;$i++){
        $tm=($d-$item[$i]);
        $sum+=$tm;
}
echo $sum;

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

$r = 0;
foreach($a as $v){
 $r += $d - $v;
}

$r -= $d - $a[$n - 1];

print $r;
?>

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

<?

fscanf(STDIN,"%d%d",$d,$n);
while($n--){
    fscanf(STDIN,"%d",$x);
    $sum+=$d-$x;
}
fprintf(STDOUT,"%d",$sum);