<?php

list($si, $p) = explode(" ", trim(fgets(STDIN)));
$sl = str_split(trim(fgets(STDIN)));

$m = ($p > ($si / 2)) ? 1 : -1;
while($p != 1 && $p != $si)
{
	echo ($m == -1) ? "LEFT" : "RIGHT";
	echo PHP_EOL;

	$p += $m;
}

$m = ($m == -1) ? 1 : -1;
while ($si > 0)
{
	echo "PRINT " . $sl[($p - 1)] . PHP_EOL;
	$si--;
	$p += $m;
	if($si > 0)
	{
		echo ($m == -1) ? "LEFT" : "RIGHT";
		echo PHP_EOL;
	}
}

<?php

list($si, $p) = explode(" ", trim(fgets(STDIN)));
$sl = str_split(trim(fgets(STDIN)));

$m = ($p > ($si / 2)) ? 1 : -1;
while($p != 0 && $p != $si)
{
	echo ($m == -1) ? "LEFT" : "RIGHT";
	echo PHP_EOL;

	$p += $m;
}

$m = ($m == -1) ? 1 : -1;
while ($si > 0)
{
	echo "PRINT " . $sl[($p - 1)] . PHP_EOL;
	$si--;
	$p += $m;
	if($si > 0)
	{
		echo ($m == -1) ? "LEFT" : "RIGHT";
		echo PHP_EOL;
	}
}


<?php
ini_set("display_errors", "Off");
error_reporting(0);
$stdin = fopen('php://stdin', 'r');
fscanf($stdin, "%d\n", $caseCount);
$caseResult=[];
for($caseNo=0;$caseNo<$caseCount;$caseNo++){
    fscanf($stdin, "%d %d %d %d\n", $n,$l,$r,$k);
    $an=array();$str="";
    for ($i=0;$i<$n;$i++){$str.="%d ";}
    $an=fscanf($stdin, rtrim($str));
//    var_dump($an);
//    echo "-------------------";
    asort($an);
//    echo 3;
//    foreach ($an as $ark=>$arval){
//        if($arval<$l){}
//    }
    $an1=array_filter($an,function($var)use($l,$r){
//        echo $var.".($l,$r)";
        //        var_dump($rt);
        return ($var>=$l)? ($var<=$r?true:false):false;});
//    print_r($an1);
    $total=0;$count=0;
    foreach ($an1 as $ak=>$aval){
        if(($total+=$aval) >$k){break;}else{$count++;}
//        echo "[$total][$aval]\n";
    }
//    echo "[$count]";
    $caseResult[]=$count;
}
//print_r($caseResult);
$co=0;
foreach ($caseResult as $item) {
    echo "$item";if($co++<$caseCount-1){echo "\n";}
}

<?php

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

function solve()
{
    global $file;

    list($n, $l, $r, $k) = array_map('intval', explode(' ', trim(fgets($file))));

    $chocos = array_map('intval', explode(' ', trim(fgets($file))));

    $buyables = [];

    foreach($chocos as $choco)
    {
        if($choco >= $l && $choco <= $r)
        {
            $buyables []= $choco;
        }
    }

    sort($buyables);

    $canBuy = 0;
    $price = 0;

    for($i=0; $i < count($buyables); $i++)
    {
        if($price + $buyables[$i] > $k)
        {
            break;
        }
        else
        {
            $price+= $buyables[$i];
            $canBuy++;
        }
    }

    echo $canBuy . PHP_EOL;
}

$t = + fgets($file);

while($t--) solve();


<?

$r = fopen('php://stdin','r');
$s = '';
while (!feof($r))
{
    $s .= fgets($r);
}
$s = trim($s);

function getEmails($s)
{
    if(substr($s,0,1) == '@')
    {
        echo 'No solution';
        exit;
    }

    if(substr($s,-1) == '@')
    {
        echo 'No solution';
        exit;
    }

    $aOut = array();
    if(strpos($s, '@') === false)
    {
        echo 'No solution';
        exit;
    }

    $iPos = strpos($s, '@');
    $iL = strlen($s);
    $sNew = substr($s, 0,($iPos+2));
    if(substr($sNew,-1) == '@')
    {
        echo 'No solution';
        exit;
    }
    $s = substr($s, ($iPos+2),$iL);

    if(strpos($s, '@') === false)
    {
        $sNew .= $s;
        $s = '';
    }

    $aOut[] = $sNew;
    if(strlen($s))
    {
        $aOut[] = getEmails($s);
    }
    return implode(',',$aOut);
}

echo getEmails($s);

<?php

$r = '/^([^@]+@[^@]+)*$/';
$s = trim(fgets(STDIN));
preg_match($r, $s, $matches);
if (count($matches) == 0) {
	print("No solution\n");
} else {
	$res = array();
	while (strlen($s) > 0) {
		preg_match($r, $s, $matches);
		$x = $matches[1];
		array_push($res, $x);
		$s = substr($s, 0, strlen($s) - strlen($x));
	}
	print(implode(',',array_reverse($res))."\n");
}

?>

<?php
$a = trim(fgets(STDIN));
$b = str_split($a);
$c = array();
$d = 0;
$f = array();
if($b[0] == "@")
{
    print "No solution";
}
else
{
    for($x = 0; $x < count($b); $x++)
    {
        if($b[$x] == "@")
        {
            array_push($c, $x);
        }
    }
    for($x = count($c) - 1; $x > 0; $x--)
    {
        if(($c[$x] - $c[$x - 1]) <= 2)
        {
            $d = 1;
            break;
        }
    }
    if($d == 1)
    {
        print "No solution";
    }
    else
    {
        for($x = 0; $x < count($c); $x++)
        {
            $e = implode(array_slice($b, 0, $c[$x] + 2)) . ",";
            array_push($f, $e);
            array_splice($b, 0, $c[$x] + 2);
        }
    }
    print substr(implode($f), 0, strlen(implode($f)) - 1);
}
?>

<?php

$r = '/^([^@]+@[^@]+)*$/';
$s = fgets(STDIN);
preg_match($r, $s, $matches);
if (count($matches) == 0) {
	print("No solution\n");
} else {
	$res = array();
	while (strlen($s) > 0) {
		preg_match($r, $s, $matches);
		$x = $matches[1];
		array_push($res, $x);
		$s = substr($s, 0, strlen($s) - strlen($x));
	}
	print(implode(',',array_reverse($res))."\n");
}

?>

<?

$r = fopen('php://stdin','r');
$s = '';
while (!feof($r))
{
    $s .= fgets($r);
}

function getEmails($s)
{
    if(substr($s,0,1) == '@')
    {
        echo 'No solution';
        exit;
    }

    if(substr($s,-1) == '@')
    {
        echo 'No solution';
        exit;
    }

    $aOut = array();
    if(strpos($s, '@') === false)
    {
        echo 'No solution';
        exit;
    }

    $iPos = strpos($s, '@');
    $sNew = substr($s, ($iPos+2));
    $s = substr($s, -1*strlen($sNew));
    if(strpos($sNew, '@') === false)
    {
        $s .= $sNew;
        $sNew = '';
    }
    $aOut[] = $s;
    if(strlen($sNew))
    {
        $aOut[] = getEmails($sNew);
    }
    return implode(',',$aOut);
}

echo getEmails($s);

<?

$r = fopen('php://stdin','r');
$s = '';
while (!feof($r))
{
    $s .= fgets($r);
}
$s = trim($s);

function getEmails($s)
{
    if(substr($s,0,1) == '@')
    {
        echo 'No solution';
        exit;
    }

    if(substr($s,-1) == '@')
    {
        echo 'No solution';
        exit;
    }

    $aOut = array();
    if(strpos($s, '@') === false)
    {
        echo 'No solution';
        exit;
    }

    $iPos = strpos($s, '@');
    $sNew = substr($s, ($iPos+2));
    $s = substr($s, -1*strlen($sNew));
    if(strpos($sNew, '@') === false)
    {
        $s .= $sNew;
        $sNew = '';
    }
    $aOut[] = $s;
    if(strlen($sNew))
    {
        $aOut[] = getEmails($sNew);
    }
    return implode(',',$aOut);
}

echo getEmails($s);


<?php
    $str =fgets(STDIN);

    $str = explode(' ',$str);
    $n = (int)$str[0];
    $r = (int)$str[1];
    $r--;

    $str=fgets(STDIN);
    $str = explode(' ',$str);
    $elm = [];
    $i = 0;

    $s = '';
    while($i<$n) {
        $elm[$i]=(int)$str[$i];
        $s.=$str[$i]; //вся строка
        $i++;
    }

    //недопустимая строка
    $i=0;
    $nstr = '';
    while($i++<$r) {
        $nstr.='00';
    }
    $nstr.='0';

    //не допустимо в середине строки
    if (strstr($s, $nstr) || !strstr($s, '1')) {
        echo '-1';
        die();
    }

    //не допустимо в начале и в конце строки
    $i=0;
    $nstr = '';
    while($i++<$r) {
        $nstr.='0';
    }
    $nstr.='0';

    $start = substr($s, 0, ($r+1));
    $fin = substr($s, $n-($r+1), ($r+1));

    if ($nstr==$start || $fin == $nstr) {
        echo '-1';
        die();
    }

    $count = 0;

    //смотрим с чего начинать первый отрезок
    $i=$r;
    while ($elm[$i]!=1) {
        $i--;
    }
    $start = $i;

    $count++;

    //начинаем искать, идти пошагово
    while ( ($i+$r) <= ($n-2)) {

        $i+=($r*2+1);
        while (!isset($elm[$i]) || $elm[$i]!=1) {
            $i--;
        }
        $count++;
    }
    echo $count;
?>


<?php
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $m = str_split($s);
    $b = true;
    $s = substr($s, 0, strlen($s) - 10);
    preg_match_all("/8/", $s, $a);
    if (count($a[0]) >= strlen($s)/2) {
        echo 'YES';
    } else {
        echo 'NO';
    }

?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$sWord = trim(fgets(STDIN));
$i = $j = 0;
foreach (str_split(substr($sWord, 0,$n - 10)) as $sK => $sV){
    if($sV == '8'){
        $i++;
    } else {
        $j++;
    }
}
if($i >= $j){
    echo 'YES';
} else {
    echo 'NO';
}

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$s = $ir->readString();

$cnt = 0;
for ($i=0; $i<$n-10; $i++) {
	if ($s[$i] == '8') {
		$cnt++;
	} else {
		$cnt--;
	}
}

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

<?php
  $n = trim(fgets(STDIN));
  $m = trim(fgets(STDIN));
  $m = substr($m, 0, -10);
  $arr = str_split($m, 1);
  $hod = ($n-11)/2;
  $i = 0;
  foreach ($arr as $sK => $sV) {
      if($sV == 8){
          $i++;
      }
      if($i > $hod) {
              echo "YES";
              exit;
        }
  }
  echo "NO";
?>

<?php

$n = trim(fgets(STDIN));
$s = str_split(trim(fgets(STDIN)));
$c = 0;
for ($i=0; $i<$n-10; $i++) if ($s[$i] == '8') $c++; else $c--;
echo ($cnt > 0 ? "YES" : "NO");

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$sWord = trim(fgets(STDIN));
$i = 0;
foreach (str_split(substr($sWord, 0,$n -11)) as $sK => $sV){
    if($sV == '8'){
        $i++;
    }
}
if($i >= ($n - 11)/2){
    echo 'YES';
} else {
    echo 'NO';
}


<?php
$s = file_get_contents('php://stdin');
$init = explode("\n", $s);
$n = $init[0];
$s = $init[1];

function merge_sort($my_array){
	if(count($my_array) == 1 ) return $my_array;
	$mid = count($my_array) / 2;
    $left = array_slice($my_array, 0, $mid);
    $right = array_slice($my_array, $mid);
	$left = merge_sort($left);
	$right = merge_sort($right);
	return merge($left, $right);
}

function merge($left, $right){
	$res = array();
	while (count($left) > 0 && count($right) > 0){
		if($left[0] > $right[0]){
			$res[] = $right[0];
			$right = array_slice($right , 1);
		}else{
			$res[] = $left[0];
			$left = array_slice($left, 1);
		}
	}
	while (count($left) > 0){
		$res[] = $left[0];
		$left = array_slice($left, 1);
	}
	while (count($right) > 0){
		$res[] = $right[0];
		$right = array_slice($right, 1);
	}
	return $res;
}

$a = explode(' ', $s);
$sorted = merge_sort($a);
if (array_sum($sorted)/$sorted[0] == 2 * $n) {
    echo '-1';
} else {
    echo implode(' ', $sorted);
}

<?php

$fp = fopen('php://stdin', 'r');
$n = trim(fgets($fp)) + 0;
$numbers = explode(" ", trim(fgets($fp)));
foreach ($numbers as $key => $number) {
    $numbers[$key] = $number + 0;
}
sort($numbers, SORT_NUMERIC);
$check = $numbers[0];
$check_flg = false;
foreach ($numbers as $number) {
    if ($check != $number) {
        $check_flg = true;
        break;
    }
}
if ($check_flg) {
    foreach ($numbers as $number) {
        echo "$number ";
    }
} else {
    echo "-1";
}

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = array_sum(array_slice($b, 0, $a));
$d = array_sum(array_slice($b, $a));
if($c == $d)
{
     print "-1";
}
else
{
     print implode(" ", $b);
}
?>

<?php
list($k) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));

list($aArray1,$aArray2) = array_chunk($aArray, ceil(count($aArray) / 2));
$iMin = min($aArray1);
$iMinIndex = array_keys($aArray1, min($aArray1));
$iMax = max($aArray2);
$iMaxIndex = array_keys($aArray2, max($aArray2));
if(array_sum($aArray1) != array_sum($aArray2) && $iMin != $iMax){
    echo implode(' ', $aArray);
} elseif(array_sum($aArray1) == array_sum($aArray2) && $iMin == $iMax){
    echo '-1';
} else {
    $aArray1[$iMinIndex[0]] = $iMax;
    $aArray2[$iMaxIndex[0]] = $iMin;
    echo implode(' ',$aArray1) . ' ' . implode(' ',$aArray2);

}

<?php
# 1174A
$stdin = STDIN;

$n = trim(fgets($stdin));
$a = explode(' ', trim(fgets($stdin)));
sort($a);

if (array_sum(array_slice($a, 0, $n)) === array_sum(array_slice($a, $n, $n))) {
    echo '-1';
} else {
    echo implode(' ', $a);
}

<?php

$fp = fopen('php://stdin', 'r');
//$fp = fopen('input.txt', 'r');
$n = trim(fgets($fp)) + 0;
$numbers = explode(" ", trim(fgets($fp)));
$left = [
    "max" => 0,
    "sum" => 0,
    "numbers" => [],
    "count" => 0

];
$right = [
    "sum" => 0,
    "numbers" => [],
    "count" => 0
];
foreach ($numbers as $number) {
    $number += 0;
    if (!$left["sum"]) {
        $left["max"] = $number;
        $left["sum"] = $number;
        array_push($left["numbers"], $number);
        $left["count"]++;
        continue;
    }

    if (!$right["sum"]) {
        $right["sum"] = $number;
        array_push($right["numbers"], $number);
        $right["count"]++;
        continue;
    }

    if (($number >= $left["max"] || $right["count"] == $n ) && $left["count"] < $n) {
        $left["max"] = $number;
        $left["sum"] += $number;
        array_push($left["numbers"], $number);
        $left["count"]++;
    } else {
        $right["sum"] += $number;
        array_push($right["numbers"], $number);
        $right["count"]++;
    }

}

if ($left["sum"] == $right["sum"]) {
    echo "-1";
} else {
    foreach($left["numbers"] as $number) {
        echo "$number ";
    }
    foreach($right["numbers"] as $number) {
        echo "$number ";
    }
}


<?php
list($n) = explode(' ', trim(fgets(STDIN)));
list($a) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));
$b = true;
$g = false;
$k = [];
foreach(str_split($a) as $sK => &$sV){

    if($sV == $aArray[$sV - 1]){
        $k[] = $sV;
    } elseif($sV < $aArray[$sV - 1] && $b){
        $k[] = $aArray[$sV - 1];
        $g = true;
    } else {
        if ($g){
            $b = false;
        }
        $k[] = $sV;
    }
}
echo implode('',$k);

<?php
    $n = trim(fgets(STDIN));
    $a = str_split(trim(fgets(STDIN)));
    $f = explode(" ", trim(fgets(STDIN)));
    $s = '';
    $b = true;
    $g = false;
    foreach ($a AS $k => $v) {
        if ($v == $f[$v-1]) {
            $s.= $v;
        } else if ($b && $f[$v-1] > $v) {
            $s.= $f[$v-1];
            $g = true;
        } else {
            if ($g) {
                $b = false;
            }
            $s.= $v;
        }
    }
    echo $s;
?>

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

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

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

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
list($a) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));
$bFlag = false;
$k = [];
foreach(str_split($a) as $sK => &$sV){

    if($sV == $aArray[$sV - 1] && !$bFlag){
        $k[] = $sV;
    } elseif($sV < $aArray[$sV - 1] && !$bFlag){
        $k[] = $aArray[$sV - 1];
    } else {
        $k[] = $sV;
        $bFlag = true;
    }
}
echo implode('',$k);

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
list($a) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));
$k = [];
//foreach(str_split($a) as $sK => &$sV){
//    if($sV < $aArray[$sV - 1]){
//        $k[] = $aArray[$sV - 1];
//    } else {
//        $k[] = $sV;
//    }
//}

$iA = strlen($a) < 50 ? $a : 50;
for($i = 0; $i < $iA; $i++){
    if($a[$i] < $aArray[$a[$i]- 1]){
        $a[$i] = $aArray[$a[$i]- 1];
    }
}
echo $a;
//var_dump($k);

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
list($a) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));
$k = [];
foreach(str_split($a) as $sK => &$sV){
    if($sV < $aArray[$sV - 1]){
        $k[] = $aArray[$sV - 1];
    } else {
        $k[] = $sV;
    }
}
echo implode('',$k);

<?php
    $n = trim(fgets(STDIN));
    $a = str_split(trim(fgets(STDIN)));
    $f = explode(" ", trim(fgets(STDIN)));
    $s = '';
    $b = true;
    foreach ($a AS $k => $v) {
        if ($b && $f[$v-1] > $v) {
            $s.= $f[$v-1];
        } else {
            if (!empty($s)) {
                $b = false;
            }
            $s.= $v;
        }
    }
    echo $s;
?>

<?php
    $n = trim(fgets(STDIN));
    $a = str_split(trim(fgets(STDIN)));
    $f = explode(" ", trim(fgets(STDIN)));
    $s = '';
    $b = true;
    foreach ($a AS $k => $v) {
        if ($b && $f[$v-1] >= $v) {
            $s.= $f[$v-1];
        } else {
            if (!empty($s)) {
                $b = false;
            }
            $s.= $v;
        }
    }
    echo $s;
?>

<?php
    $n = trim(fgets(STDIN));
    $a = str_split(trim(fgets(STDIN)));
    $f = explode(" ", trim(fgets(STDIN)));
    $s = '';
    $b = true;
    foreach ($a AS $v) {
        if ($b && $f[$v-1] > $v) {
            $s.= $f[$v-1];
        } else {
            if (!empty($s)) {
                $b = false;
            }
            $s.= $v;
        }
    }
    echo $s;
?>

<?php
    $n = trim(fgets(STDIN));
    $a = str_split(trim(fgets(STDIN)));
    $f = explode(" ", trim(fgets(STDIN)));$s = '';
    foreach ($a AS $v) {
        $s.= $f[$v-1];
    }
    echo $s;
?>

<?php
    $n = trim(fgets(STDIN));
    $a = str_split(trim(fgets(STDIN)));
    $f = explode(" ", trim(fgets(STDIN)));
    $s = '';
    $b = true;
    $g = false;
    foreach ($a AS $k => $v) {
        if ($b && $f[$v-1] > $v) {
            $s.= $f[$v-1];
            $g = true;
        } else {
            if ($g) {
                $b = false;
            }
            $s.= $v;
        }
    }
    echo $s;
?>

<?php
    $n = trim(fgets(STDIN));
    $a = str_split(trim(fgets(STDIN)));
    $f = explode(" ", trim(fgets(STDIN)));$s = '';
    foreach ($a AS $v) {
        if ($f[$v-1] > $v) {
            $s.= $f[$v-1];
        } else {
            $s.= $v;
        }
    }
    echo $s;
?>

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

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


<?php
$num = (int) trim(fgets(STDIN));
$seq = array_map('intval', explode(' ', trim(fgets(STDIN))));

$slicePos = $prev = 0;
foreach ($seq as $pos => $cur) {
	if ($cur < $prev) {
		if ($slicePos) {
			echo -1;
			exit();
		} else {
			$slicePos = $pos;
		}
	}

	$prev = $cur;
}

if ($slicePos) {
	if ($seq[0] >= $seq[$num - 1]) {
		echo $num - $slicePos;
	} else {
		echo -1;
	}
} else {
	echo 0;
}

<?php
error_reporting("off");
//454B: Little Pony and Sort by Shift
$n = trim(fgets(STDIN)); //$n = 3;
$array = explode(" ", trim(fgets(STDIN))); //$array = explode(" ", "1 3 2");
$biggest = max($array);
$finding = array_keys($array, $biggest);
if ($finding == range(0, $n - 1)) {
  echo 0;
} else {
  $groups = array();

  for($i = 0; $i < count($finding); $i++) {
   if($i > 0 && ($finding[$i - 1] == $finding[$i] - 1)) {
       array_push($groups[count($groups) - 1], $finding[$i]);
    } else { // First value or no match, create a new group
      array_push($groups, array($finding[$i]));
    }
  }

  if (count($groups) > 2) {
    echo -1;
  } elseif (count($groups) == 2) {
    if (in_array(0, $groups[0]) && in_array($n - 1, $groups[1])) {
      $key = max($groups[0]) + 1;
      $go = TRUE;
    } else {
      echo -1;
    }
  } else {
    $lastone = end($finding);
    if ($lastone + 1 == $n) {
      $key = 0;
      $go = TRUE;
    } else {
      $key = $lastone + 1;
      $go = TRUE;
    }
  }
  if ($go == TRUE) {
    $next = $array[$key];
    if ($next !== min($array)) {
      echo -1;
    } else {
      $clone = $array;
      sort($clone);
      $splice = array_splice($clone, 0, $n - $key);
      $frankenstein = array_merge($clone, $splice);
      if ($array === $frankenstein) {
        if ($key == 0) {
          echo 0;
        } else {
          echo $n - $key;
        }
      } else {
        echo -1;
      }
    }
  }
}
?>

<?php
$num = (int) trim(fgets(STDIN));
$array = array_map('intval', explode(' ', trim(fgets(STDIN))));
$maxNumbers = 105;

function twilightSort($array)
{
    $item = array_pop($array);
    array_unshift($array, $item);

    return $array;
}

$result = $array;
$target = $array;
sort($target, SORT_ASC);

for ($i = 0; $i < $maxNumbers; $i++) {
    if ($result === $target) {
        echo "" . $i;
        break;
    }

    $result = twilightSort($result);
}

if ($result !== $target) {
    echo "-1";
}

echo "\n";

<?php
$num = fgets(STDIN);
$seq = explode(' ', fgets(STDIN));

$slicePos = $prev = 0;
foreach ($seq as $pos => $cur) {
	if ($cur < $prev) {
		if (!$slicePos) {
			$slicePos = $pos;
		} else {
			echo -1;
			exit();
		}
	}

	$prev = $cur;
}

if ($slicePos) {
	if ($seq[0] >= $seq[$num - 1]) {
		echo $num - $slicePos;
	} else {
		echo -1;
	}
} else {
	echo 0;
}

<?php
$num = (int) trim(fgets(STDIN));
$seq = array_map('intval', explode(' ', trim(fgets(STDIN))));

$input = [
    'count' => $num,
    'numbers' => $seq,
];

for ($prev = end($input['numbers']), $current = reset($input['numbers']), $spokes = 0, $position = -1; false !== $current; $prev = $current, $current = next($input['numbers'])) {
	if ($prev > $current) {
		$position = key($input['numbers']);
		++$spokes;
	}
}

if (1 != $spokes) {
	$iterations = -1;
} else {
	$iterations = 0 == $position ? 0 : $input['count'] - $position;
}

echo $iterations . "\n";

<?php

$handle = fopen("php://stdin", "r");
$num = fgets($handle);
$maxNumbers = 105;
$array = [];

for ($i = 0; $i < $num; $i++) {
    $array[] = rand(1, $maxNumbers);
}

function twilightSort($array)
{
    $item = array_pop($array);
    array_unshift($array, $item);

    return $array;
}

$result = $array;
$target = $array;
sort($target, SORT_ASC);

for ($i = 0; $i < $maxNumbers; $i++) {
    if ($result === $target) {
        echo "" . $i;
        break;
    }

    $result = twilightSort($result);
}

if ($result !== $target) {
    echo "-1";
}

echo "\n";

<?php
$num = (int) trim(fgets(STDIN));
$seq = array_map('intval', explode(' ', trim(fgets(STDIN))));

$input = [
    'numbers' => $seq,
];

for ($prev = end($input['numbers']), $current = reset($input['numbers']), $spokes = 0, $position = -1; false !== $current; $prev = $current, $current = next($input['numbers'])) {
	if ($prev > $current) {
		$position = key($input['numbers']);
		++$spokes;
	}
}

if (1 != $spokes) {
	$iterations = -1;
} else {
	$iterations = 0 == $position ? 0 : $input['count'] - $position;
}

echo $iterations . "\n";

<?php

$num = fgets(STDIN);
$seq = explode(' ', fgets(STDIN));

$slicePos = $prev = 0;
foreach ($seq as $pos => $cur) {
	if ($cur < $prev) {
		if (!$slicePos) {
			$slicePos = $pos;
		} else {
			echo -1;
			exit();
		}
	}

	$prev = $cur;
}

if ($slicePos) {
	if ($seq[0] > $seq[$num - 1]) {
		echo $num - $slicePos;
	} else {
		echo -1;
	}
} else {
	echo 0;
}

<?php
$num = fgets(STDIN);
$seq = explode(' ', fgets(STDIN));

$isDebug = $seq[0] == 99997;

$slicePos = $prev = 0;
foreach ($seq as $pos => $cur) {
	if ($cur < $prev) {
		if ($slicePos) {
			if ($isDebug) {
				echo $slicePos . ' | ';
			}
			echo -1;
			exit();
		} else {
			$slicePos = $pos;
		}
	}

	$prev = $cur;
}

if ($slicePos) {
	if ($seq[0] >= $seq[$num - 1]) {
		echo $num - $slicePos;
	} else {
		if ($isDebug) {
			echo $slicePos . ' | ' . $seq[0] . ' | ' . $seq[$num - 1] . ' | ';
		}
		echo -1;
	}
} else {
	echo 0;
}

<?php
error_reporting("off");
//454B: Little Pony and Sort by Shift
$n = trim(fgets(STDIN)); //$n = 6;
$array = explode(" ", trim(fgets(STDIN))); //$array = explode(" ", "1 1 1 1 1 1");
$biggest = max($array);
$finding = array_keys($array, $biggest);
$lastone = end($finding);
if ($lastone + 1 == $n) {
  $key = 0;
} else {
  $key = $lastone + 1;
}
$next = $array[$key];
if ($next !== min($array)) {
  echo -1;
} else {
  $clone = $array;
  sort($clone);
  $splice = array_splice($clone, 0, $n - $key);
  $frankenstein = array_merge($clone, $splice);
  if ($array === $frankenstein) {
    if ($key == 0) {
      echo 0;
    } else {
      echo $n - $key;
    }
  } else {
    echo -1;
  }
}
?>

<?php
error_reporting("off");
//454B: Little Pony and Sort by Shift
$n = trim(fgets(STDIN)); //$n = 10;
$array = explode(" ", trim(fgets(STDIN))); //$array = explode(" ", "6 7 8 9 10 1 2 3 4 55");
$biggest = max($array);
$finding = array_keys($array, $biggest);
$lastone = end($finding);
if ($lastone + 1 == $n) {
  $key = 0;
} else {
  $key = $lastone + 1;
}
$next = $array[$key];
$clone = $array;
sort($clone);
$splice = array_splice($clone, 0, $n - $key);
$frankenstein = array_merge($clone, $splice);
if ($array === $frankenstein) {
  echo $key;
} else {
  echo -1;
}
?>

<?php
error_reporting("off");
//454B: Little Pony and Sort by Shift
$n = trim(fgets(STDIN)); //$n = 4;
$array = explode(" ", trim(fgets(STDIN))); //$array = explode(" ", "4 1 2 3");
$biggest = max($array);
$finding = array_keys($array, $biggest);
$lastone = end($finding);
if ($lastone + 1 == $n) {
  $key = 0;
} else {
  $key = $lastone + 1;
}
$next = $array[$key];
if ($next !== min($array)) {
  echo -1;
} else {
  $clone = $array;
  sort($clone);
  $splice = array_splice($clone, 0, $n - $key);
  $frankenstein = array_merge($clone, $splice);
  if ($array === $frankenstein) {
    echo $n - $key;
  } else {
    echo -1;
  }
}
?>


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

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

 function solve()
 {
     list($n, $k) = IO::getArray();
     $s = IO::getInt();
     $ans = 0;
    $a[] = 0;
    for ($j = 0; $j < $n; $j++){
      $a[$j + 1] = $a[$j];
      if ($s[$j] == 'W'){
        $a[$j + 1]++;
      }
    }
    $ans = $n;
    for ($i = 0; $i <= $n - $k; $i++){
      $ans = IO::getMinValue($ans, $a[$i + $k] - $a[$i]);
    }
    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

$testCases = (int) fgets(STDIN);

$answers = [];

for ($i=0; $i < $testCases; $i++) {
    $fistLine = explode(' ', fgets(STDIN));

    $length = (int) $fistLine[0];
    $target = (int) $fistLine[1];

    $string = fgets(STDIN);
    $cells = str_split($string);

    $firstArrayValue = array_count_values(str_split(substr($string, 0, $target)));
    $current = !empty($firstArrayValue['W']) ? $firstArrayValue['W'] : 0;
    $min = $current;

    for ($j=$target; $j < $length; $j++) {
        // Remove First
        if ($cells[$j - $target] === 'W') {
            $current--;
        }
        // Add to the End
        if ($cells[$j] === 'W') {
            $current++;
        }
        // Check Min Value
        if ($min > $current) {
            $min = $current;
        }
    }

    $answers[] = $min;
}

foreach ($answers as $item) {
    echo $item . PHP_EOL;
}

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

$answers = [];

for ($i=0; $i < $testCases; $i++) {
    $fistLine = explode(' ', fgets(STDIN));

    $length = (int) $fistLine[0];
    $target = (int) $fistLine[1];

    $string = fgets(STDIN);
    $cells = str_split($string);

    $current = array_count_values(str_split(substr($string, 0, $target)))['W'] ?? 0;
    $min = $current;

    for ($j=$target; $j < $length - $target + 1; $j++) {
        // Remove First
        if ($cells[$j - $target] === 'W') {
            $current--;
        }
        // Add to the End
        if ($cells[$j] === 'W') {
            $current++;
        }
        // Check Min Value
        if ($min > $current) {
            $min = $current;
        }
    }

    $answers[] = $min;
}

foreach ($answers as $item) {
    echo $item . PHP_EOL;
}

<?php

$testCases = (int) fgets(STDIN);

$answers = [];

for ($i=0; $i < $testCases; $i++) {
    $fistLine = explode(' ', fgets(STDIN));

    $length = (int) $fistLine[0];
    $target = (int) $fistLine[1];

    $cells = fgets(STDIN);

    $length = 9;
    $target = 1;
    $cells = 'WWWWWBWWW';

    $cases = [];

    for ($j=0; $j < $length - $target + 1; $j++) {
        $cases[] = str_split(substr($cells, $j, $target));
    }

    $answers[] = min(array_map('getWhite', array_map('array_count_values', $cases)));
}

function getWhite($value)
{
    return !empty($value['W']) ? $value['W'] : 0;
}

foreach ($answers as $item) {
    echo $item . PHP_EOL;
}

<?php

$testCases = (int) fgets(STDIN);

$answers = [];

for ($i=0; $i < $testCases; $i++) {
    $fistLine = explode(' ', fgets(STDIN));

    $length = (int) $fistLine[0];
    $target = (int) $fistLine[1];

    $cells = fgets(STDIN);

    $cases = [];

    for ($j=0; $j < $length - $target + 1; $j++) {
        $add = $j === 0 ? 0 : -1;
        $cases[] = str_split(substr($cells, $j, $j+$target + $add));
    }

    $answers[] = min(array_map('getWhite', array_map('array_count_values', $cases)));
}

function getWhite($value)
{
    return !empty($value['W']) ? $value['W'] : 0;
}

foreach ($answers as $item) {
    echo $item . PHP_EOL;
}

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

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

 function solve()
 {
     list($n, $k) = IO::getArray();
     $s = IO::getInt();
     $ans = 0;
     $bMax = 0;
     $temp = 0;
     $count = 0;
          for($i=0; $i<$n; $i++) {
             if($s[$i] == 'B')  {
                 $temp ++;
                 $count++;
             } else {
                 $bMax = IO::getMaxValue($bMax, $temp);
                 $temp = 0;

             }
          }

     //   $ans = $bMax > $k ? 0 : $bMax

          if($bMax > $k) {
               $ans = 0;
          } else {
               $ans = $k - $bMax;
               if($ans > $n - $count) {
                  $ans =  $n - $count;
               }
          }

      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
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     list($n, $k) = IO::getArray();
     $s = IO::getInt();
     $ans = 0;

     $temp = 0;
     if($n == 1 && $s == 'W') {
          $ans = 1;
     } else {
          for($i=0; $i<$n; $i++) {
             if($s[$i] == 'B')  {
                  $temp++;
                  if($temp == $k) {
                       $temp = 0;
                       if($i > $n - 1 - $k) {
                            break;
                       }
                  }
             } else {
                  if($i <= $n-$k + $temp) {
                       if($temp > 0) {
                           $ans++;
                            $temp++;
                            if($temp == $k) {
                                 $temp = 0;
                            }
                       }
                  } else {
                       break;
                  }

             }
          }
     }

      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
$n = intval(trim(fgets(STDIN)));

$sLine = trim( fgets( STDIN ));
$aType = explode(' ',$sLine);
$ans = 0;

$aMap = array();
$res = array();
$pre = -1;

for($i = 0;$i < $n;$i++){
    $aType[ $i ] = intval($aType[ $i ]);
    if(!isset($aMap[ $aType[ $i ] ]) || $aMap[ $aType[ $i ] ] <= intval($pre) ){
        $aMap[ $aType[ $i ] ]  = $i;
    } else {
        $pre = $i;
        $res[] = $i+1;
        $ans ++;
    }
}

if($ans == 0){
    echo -1;
    exit;
}
if($res[$ans - 1] < $n){
    $res[$ans - 1] = $n;
}
printf("%d\n",$ans);
printf("%d %d\n",1,$res[0]);
for($i = 1; $i < $ans ;$i++ ){
    printf("%d %d\n",$res[ $i - 1 ] + 1,$res[$i]);
}


<?php

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

list($n, $m) = fscanf($stdin, "%d %d");

$l = 1;
$r = $n;

for ($i=0; $i<$m; $i++) {
    list($dir, $x) = fscanf($stdin, "To the %s of %d");
    if ($dir == "left") {
        if ($x <= $r) {
            $r = $x-1;
        }
    } else {
        if ($x >= $l) {
            $l = $x+1;
        }
    }
}

$razn = $r - $l + 1;
if ($razn <= 0) {
    echo "-1\n";
} else {
    echo "$razn\n";
}

exit;


<?php
# 1143A
$input = fopen('php://stdin', 'rb');
$doorsCount = (int)fgets($input);
$doors = [];
for ($i = 1; $i <= $doorsCount; $i++) {
    $type = fgetc($input);
    fgetc($input);
    $doors[$type] = $i;
}

echo min($doors);

<?php
$n = fgets(STDIN);
$x = array_map('intval', explode(' ', trim(fgets(STDIN))));
for ($i = $n - 1; $x[$i] == $x[$n - 1]; $i--);
echo $i + 1;

<?php

$n = trim(fgets(STDIN));
$arr = explode(" ", trim(fgets(STDIN)));

$cnt = array_count_values($arr);

for($i = 0; $i < count($arr); $i++) {
    $arr[$i] ? $cnt[1]-- : $cnt[0]--;
    if (!($cnt[0] and $cnt[1])) {
        $out = $i;
        break;
    }
}

echo  $out+1;


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

$data_arr = explode(PHP_EOL,$data);
$time_format = $data_arr[0];
$time = $data_arr[1];
$time_arr = explode(':',$time);
$hours = $time_arr[0];
$minutes = $time_arr[1];

function correct_hours()
{
    global $hours;
    global $time_format;
    $h_1 = $hours[0];
    $h_2 = $hours[1];
    if ($time_format==12)
    {
        if ($h_2==0) {
            if ($h_1!==1) {
                $h_1 = 1;
            }
        }
        else {
            if (!in_array($h_1,[0,1])) {
                $h_1 = 0;
            }
            if ($h_1==1) {
                if (!in_array($h_2,[0,1,2]))
                {
                    $h_2 = 0;
                }
            }
        }
    }
    else {
        if ($h_1 > 2) {
            $h_1 = 1;
        }
        elseif ($h_1==2) {
            if ($h_2 > 3) {
                $h_2 = 2;
            }
        }
    }
    return $h_1.$h_2;
}

function correct_minutes()
{
    global $minutes;
    $m_1 = $minutes[0];
    $m_2 = $minutes[1];

    if ($m_1 > 5) {
        $m_1 = 3;
    }
    return $m_1.$m_2;
}

$out_hours = correct_hours();
$out_minutes = correct_minutes();
echo $out_hours.':'.$out_minutes;

<?php

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

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

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

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

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

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

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

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

function diffCnt($baseTime, $time) {
	$return = 0;
	for ($i = 0; $i < 5; $i++) {
		if ($baseTime[$i] != $time[$i]) {
			$return++;
		}
	}
	return $return;
}

function getAnswer($is_test = false, $f = false) {
	$stream = STDIN;
	if ($is_test)
		$stream = $f;
	/* begin body */
	$format = readNum($stream);
	$baseTime = readString($stream);
	$answer = array(
		'res' => '',
		'diff' => 55,
	);
	$minHour = 0;
	$maxHour = 23;
	if ($format == 12) {
		$minHour = 1;
		$maxHour = 12;
	}
	for ($hour = $minHour; $hour <= $maxHour; $hour++) {
		for ($minute = 0; $minute < 60; $minute++) {
			$checkHour = $hour;
			while (strlen($checkHour) < 2)
				$checkHour = '0' . $checkHour;
			$checkMinute = $minute;
			while (strlen($checkMinute) < 2)
				$checkMinute = '0' . $checkMinute;
			$checkTime = "{$checkHour}:{$checkMinute}";

			$diff = diffCnt($baseTime, $checkTime);
			if ($diff < $answer['diff']) {
				$answer['diff'] = $diff;
				$answer['res'] = $checkTime;
			}
		}
	}
	echo $answer['res'];
	/* / end body */
}

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

<?php
$format=trim(fgets(STDIN));
$input=trim(fgets(STDIN));
$l=preg_split('//',$input,-1,PREG_SPLIT_NO_EMPTY);
$hh='';$mm='';
list($hh,$mm)=explode(':',$input);
if($format=='12'){
	if($hh>12)
		if($hh{0}>1){
			if($hh{1}>0) $l[0]='0';
			else $l[0]='1';
		}else $l[1]='2';
}else
	if($hh>23) $l[0]='0';
if($mm>59)
	$l[3]='0';
fwrite(STDOUT,implode('',$l));
fwrite(STDOUT,PHP_EOL.'Press "Enter" to exit...'); exit(fgets(STDIN)); //Остановка
?>

<?php
$format=trim(fgets(STDIN));
$input=trim(fgets(STDIN));
$l=preg_split('//',$input,-1,PREG_SPLIT_NO_EMPTY);
$hh='';$mm='';
list($hh,$mm)=explode(':',$input);
if($format=='12'){
	if($hh>12)
		if($hh{1}>0) $l[0]='0';
		else $l[1]='1';
	if($hh<1)
		$l[1]='1';
}else
	if($hh>23) $l[0]='0';
if($mm>59)
	$l[3]='0';
fwrite(STDOUT,implode('',$l));
?>

<?php
$format=trim(fgets(STDIN));
$input=trim(fgets(STDIN));
$l=preg_split('//',$input,-1,PREG_SPLIT_NO_EMPTY);
$hh='';$mm='';
list($hh,$mm)=explode(':',$input);
if($format=='12'){
	if($hh>12)
		if($hh{0}>1) $l[0]='0';
		else $l[1]='1';
	if($hh<1)
		$l[1]='1';
}else
	if($hh>23) $l[0]='0';
if($mm>59)
	$l[3]='0';
fwrite(STDOUT,implode('',$l));
?>

<?php
$format=trim(fgets(STDIN));
$input=trim(fgets(STDIN));
$l=preg_split('//',$input,-1,PREG_SPLIT_NO_EMPTY);
$hh='';$mm='';
list($hh,$mm)=explode(':',$input);
if($format=='12'){
	if($hh>12)
		if($hh{1}>0) $l[0]='0';
		else $l[1]='1';
}else
	if($hh>23) $l[0]='0';
if($mm>59)
	$l[3]='0';
fwrite(STDOUT,implode('',$l));
?>

<?php

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

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

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

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

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

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

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

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

function diffCnt($baseTime, $time) {
	$return = 0;
	for ($i = 0; $i < 5; $i++) {
		if ($baseTime[$i] != $time[$i]) {
			$return++;
		}
	}
	return $return;
}

function getAnswer($is_test = false, $f = false) {
	$stream = STDIN;
	if ($is_test)
		$stream = $f;
	/* begin body */
	$format = readNum($stream);
	$baseTime = readString($stream);
	$answer = array(
		'res' => '',
		'diff' => 55,
	);
	$minHour = 0;
	$maxHour = 23;
	if ($format == 12) {
		$minHour = 1;
		$maxHour = 12;
	}
	for ($hour = $minHour; $hour < $maxHour; $hour++) {
		for ($minute = 0; $minute < 60; $minute++) {
			$checkHour = $hour;
			while (strlen($checkHour) < 2)
				$checkHour = '0' . $checkHour;
			$checkMinute = $minute;
			while (strlen($checkMinute) < 2)
				$checkMinute = '0' . $checkMinute;
			$checkTime = "{$checkHour}:{$checkMinute}";
			$diff = diffCnt($baseTime, $checkTime);
			if ($diff < $answer['diff']) {
				$answer['diff'] = $diff;
				$answer['res'] = $checkTime;
			}
		}
	}
	echo $answer['res'];
	/* / end body */
}

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

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	$stream = STDIN;
	if ($is_test)
		$stream = $f;
	/* begin body */
	$format = readNum($stream);
	$time = readString($stream);
	list($hour, $minute) = explode(':', $time);
	if ($minute >= 60) {
		$minute = '0' . ($minute % 10);
	}
	if ($format == 24) {
		if ($hour >= 24) {
			$hour = '0' . ($hour % 10);
		}
	} else {
		if ($hour > 12) {
			$hour = '0' . ($hour % 10);
		}
		if ($hour == '00') {
			$hour = '01';
		}
	}
	echo "{$hour}:{$minute}";
	/* / end body */
}

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

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	$stream = STDIN;
	if ($is_test)
		$stream = $f;
	/* begin body */
	$format = readNum($stream);
	$time = readString($stream);
	list($hour, $minute) = explode(':', $time);
	if ($minute >= 60) {
		$minute = '0' . ($minute % 10);
	}
	if ($format == 24) {
		if ($hour >= 24) {
			$hour = '0' . ($hour % 10);
		}
	} else {
		if ($hour >= 12) {
			$hour = '0' . ($hour % 10);
		}
		if ($hour == '00') {
			$hour = '01';
		}
	}
	echo "{$hour}:{$minute}";
	/* / end body */
}

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

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	$stream = STDIN;
	if ($is_test)
		$stream = $f;

	/* begin body */
	$type = readNum($stream);
	$baseTime = readString($stream);

    $clock = explode(":", $baseTime);
    $hour = $clock[0];
    $minutes = $clock[1];
    if ($minutes >= 60) {
        $minutes -= 60;
        $hour + 1;
    }
    if ($minutes < 10) {
        $minutes = '0' . $minutes;
    }
    if ($type == 12) {
        $hour %= $type;
        if ($hour < 10) {
            echo '0' . $hour . ":" . $minutes;
        }
    }
    if ($type == 24) {
        $hour %= $type;
        if ($hour < 10) {
            echo '0' . $hour . ":" . $minutes;
        }
    }
	/* / end body */
}

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


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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();

$smax = 0;
$dmax = 0;
$wmin = 0;
for ($i=0; $i<$n; $i++) {
	list($q, $a, $b) = $ir->readArrayOfString(3);
	$a = (int)$a;
	$b = (int)$b;
	//echo "============ $q $a $b\n";
	if ($q=='+') {
		$smax = max([$smax, $a*$b]);
		$dmax = max([$dmax, $a, $b]);
		$wmin = max([$wmin, min([$a, $b])]);
		//echo "SM $smax : DM $dmax\n";
	} else {
		$s = $a*$b;
		$d = $a>$b ? $a : $b;
		$w = $a>$b ? $b : $a;
		//echo "S  $s : D  $d\n";
		if ($s>=$smax && $d>=$dmax && $w>=$wmin) {
			echo "YES\n";
		} else {
			echo "NO\n";
		}
		flush();
	}
}

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();

$smax = 0;
$dmax = 0;
$wmax = 0;
for ($i=0; $i<$n; $i++) {
	list($q, $a, $b) = $ir->readArrayOfString(3);
	$a = (int)$a;
	$b = (int)$b;
	//echo "============ $q $a $b\n";
	if ($q=='+') {
		$smax = max([$smax, $a*$b]);
		$dmax = max([$dmax, $a, $b]);
		$wmin = max([$wmax, intval($smax/$dmax)]);
		//echo "SM $smax : DM $dmax\n";
	} else {
		$s = $a*$b;
		$d = $a>$b ? $a : $b;
		$w = $a>$b ? $b : $a;
		//echo "S  $s : D  $d\n";
		if ($s>=$smax && $d>=$dmax && $w>=$wmin) {
			echo "YES\n";
		} else {
			echo "NO\n";
		}
		flush();
	}
}

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();

$smax = 0;
$dmax = 0;
$wmax = 0;
for ($i=0; $i<=$n; $i++) {
	list($q, $a, $b) = $ir->readArrayOfString(3);
	$a = (int)$a;
	$b = (int)$b;
	//echo "============ $q $a $b\n";
	if ($q=='+') {
		$smax = max([$smax, $a*$b]);
		$dmax = max([$dmax, $a, $b]);
		$wmin = max([$wmax, intval($smax/$dmax)]);
		//echo "SM $smax : DM $dmax\n";
	} else {
		$s = $a*$b;
		$d = $a>$b ? $a : $b;
		$w = $a>$b ? $b : $a;
		//echo "S  $s : D  $d\n";
		if ($s>=$smax && $d>=$dmax && $w>=$wmin) {
			echo "YES\n";
		} else {
			echo "NO\n";
		}
		flush();
	}
}

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();

$smax = 0;
$dmax = 0;
$wmax = 0;
for ($i=0; $i<$n; $i++) {
	list($q, $a, $b) = $ir->readArrayOfString(3);
	$a = (int)$a;
	$b = (int)$b;
	//echo "============ $q $a $b\n";
	if ($q=='+') {
		$smax = max([$smax, $a*$b]);
		$dmin = max([$dmax, max([$a, $b])]);
		$wmin = max([$wmax, min([$a, $b])]);
		//echo "SM $smax : DM $dmax\n";
	} else {
		$s = $a*$b;
		$d = $a>$b ? $a : $b;
		$w = $a>$b ? $b : $a;
		//echo "S  $s : D  $d\n";
		if ($s>=$smax && $d>=$dmin && $w>=$wmin) {
			echo "YES\n";
		} else {
			echo "NO\n";
		}
		flush();
	}
}

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();

$smax = 0;
$dmax = 0;
$wmax = 0;
for ($i=0; $i<$n; $i++) {
	list($q, $a, $b) = $ir->readArrayOfString(3);
	$a = (int)$a;
	$b = (int)$b;
	//echo "============ $q $a $b\n";
	if ($q=='+') {
		$smax = max([$smax, $a*$b]);
		$dmax = max([$dmax, $a, $b]);
		$wmin = max([$wmax, min([$a, $b])]);
		//echo "SM $smax : DM $dmax\n";
	} else {
		$s = $a*$b;
		$d = $a>$b ? $a : $b;
		$w = $a>$b ? $b : $a;
		//echo "S  $s : D  $d\n";
		if ($s>=$smax && $d>=$dmax && $w>=$wmin) {
			echo "YES\n";
		} else {
			echo "NO\n";
		}
		flush();
	}
}


<?php

$t = trim(fgets(STDIN));
while ($t--) {
    $n = trim(fgets(STDIN));
    $a = explode(' ', trim(fgets(STDIN)));
    $zeroz=0; $onez=0; $twoz=0; $cizi=0;
    foreach ($a as $e) {
        if(bcmod($e,3)==0) $zeroz++;
        else if(bcmod($e,3)==1) $onez++;
        else if(bcmod($e,3)==2) $twoz++;
    }
    if($onez>=$twoz)
    {
        $cizi+=$twoz;
        $onez-=$twoz;
        $twoz=0;
    }
    else if($twoz>$onez)
    {
        $cizi+=$onez;
        $twoz-=$onez;
        $onez=0;
    }
    if($onez>=3) $cizi+=floor($onez/3);
    else if($twoz>=3) $cizi+=floor($twoz/3);

    echo $zeroz+$cizi. PHP_EOL;
}

<?php

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

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

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

    fgets($__fp);
    $nums = array_map('intval', explode(' ', fgets($__fp)));

    $map = [0 => 0, 1 => 0, 2 => 0];
    foreach ($nums as $num) {
        $map[$num % 3]++;
    }

    $min = min($map[1], $map[2]);
    $map[1] -= $min;
    $map[2] -= $min;

    $res[] = $map[0] + $min + floor($map[1] / 3)+ floor($map[2] / 3);
}

echo join(PHP_EOL, $res), PHP_EOL;

<?php
#1176B
$m = trim(fgets(STDIN));
while ($m--) {
    $n = trim(fgets(STDIN));
    $arr = explode(' ', trim(fgets(STDIN)));
    $mods = [0, 0, 0];
    foreach ($arr as $value) {
        $mods[bcmod($value, 3)]++;
    }
    echo $mods[0] + min($mods[1], $mods[2]) + floor(abs($mods[1] - $mods[2]) / 3) . PHP_EOL;
}

<?php
#1176B
$m = trim(fgets(STDIN));
while ($m--) {
    $n = trim(fgets(STDIN));
    $arr = explode(' ', trim(fgets(STDIN)));
    $mods = [0, 0, 0];
    foreach ($arr as $value) {
        $mods[$value % 3]++;
    }
    echo $mods[0] + min($mods[1], $mods[2]) + floor(abs($mods[1] - $mods[2]) / 3) . PHP_EOL;
}

<?php
#1176B
$m = trim(fgets(STDIN));
while ($m--) {
    $n = trim(fgets(STDIN));
    $arr = explode(' ', trim(fgets(STDIN)));
    $amount = 0;
    for ($i = 0; $i < $n; $i++) {
        if ($arr[$i] % 3 === 0) {
            $amount++;
            unset($arr[$i]);
        }
    }
    while (count($arr) > 1) {
        $item = array_pop($arr);
        foreach ($arr as $i => $value) {
            if (($item + $value) % 3 === 0) {
                $item = null;
                $amount++;
                unset($arr[$i]);
                break;
            }
        }
        sort($arr);
        if ($item !== null) {
            $arr[0] += $item;
            sort($arr);
        }
    }

    echo $amount . PHP_EOL;
}

<?php

$t = trim(fgets(STDIN));
while ($t--) {
    $n = trim(fgets(STDIN));
    $a = explode(' ', trim(fgets(STDIN)));
    $zeroz=0; $onez=0; $twoz=0; $cizi=0;
    foreach ($a as $e) {
        if(bcmod($e,3)==0) $zeroz++;
        else if(bcmod($e,3)==1) $onez++;
        else if(bcmod($e,3)==2) $twoz++;
    }
    if($onez>=$twoz)
    {
        $cizi+=$twoz;
        $onez-=$twoz;
        $twoz=0;
    }
    else if($twoz>$onez)
    {
        $cizi+=$onez;
        $twoz-=$onez;
        $onez=0;
    }
    if($onez>=3) $cizi+=$onez/3;
    else if($twoz>=3) $cizi+=$twoz/3;

    echo $zeroz+$cizi. PHP_EOL;
}


<?php

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

$n1 = intval(fgets($__fp));

$res = [];

$map = [
    'R' => 'S',
    'P' => 'R',
    'S' => 'P',
];

$back_map = array_flip($map);

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

    $n = intval(trim(fgets($__fp)));

    list($r, $p, $s) = explode(' ', trim(fgets($__fp)));
    $tries = [
        'R' => $r,
        'P' => $p,
        'S' => $s
    ];

    $moves = str_split(trim(fgets($__fp)));

    $success = 0;
    $seq = [];

    foreach ($moves as $q) {

        $k = $back_map[$q];
        if ($tries[$k] > 0) {
            $tries[$k]--;
            $success++;
            $seq[] = $back_map[$q];
        } else {
            $seq[] = null;
        }
    }

    if ($success >= ceil($n / 2)) {
        foreach ($seq as $i123 => $n2) {
            if ($n2 === null) {
                foreach ($tries as $k3 => $nums) {
                    if($nums > 0)
                    {
                        $tries[$k3]--;
                        $seq[$i123] = $k3;
                        break;
                    }
                }
            }
        }

        $res[] = 'YES';
        $res[] = join('', $seq);

    } else {

        $res[] = 'NO';
    }

}

echo implode(PHP_EOL, $res);


<?php

//$file = fopen('input.in', 'r');
$file = STDIN;
list($candidatesNumber, $citiesNumber) = explode(" ", trim(fgets($file)));
$cityWinners = array();
for ($i = 0; $i<$citiesNumber; $i++) {
    $x = explode(" ", trim(fgets($file)));
    $cityWinnerCandidate = array_search(max($x), $x);
    $cityWinners[$cityWinnerCandidate] = isset($cityWinners[$cityWinnerCandidate]) ? $cityWinners[$cityWinnerCandidate] + 1 : 1;
}
$winner = min(array_keys($cityWinners, max($cityWinners)));
echo $winner+1;

<?php

//$file = fopen('input.in', 'r');
$file = STDIN;
list($candidatesNumber, $citiesNumber) = explode(" ", trim(fgets($file)));
$cityWinners = array();
for ($i = 0; $i<$citiesNumber; $i++) {
    $x = explode(" ", trim(fgets($file)));
    $cityWinnerCandidate = array_search(max($x), $x);
    $cityWinners[$cityWinnerCandidate] = isset($cityWinners[$cityWinnerCandidate]) ? $cityWinners[$cityWinnerCandidate] + 1 : 1;
}
$winner = array_search(max($cityWinners), $cityWinners);
echo $winner+1;

<?php
//$file = 'input.in';
$file = STDIN;
$input = file($file, FILE_IGNORE_NEW_LINES);
list($candidatesNumber, $citiesNumber) = explode(" ", $input[0]);
$cityWinners = array();
for ($i = 0; $i<$citiesNumber; $i++) {
    $x = explode(" ", $input[$i+1]);
    $cityWinnerCandidate = array_search(max($x), $x);
    $cityWinners[$cityWinnerCandidate] = isset($cityWinners[$cityWinnerCandidate]) ? $cityWinners[$cityWinnerCandidate] + 1 : 1;
}
$winner = min(array_keys($cityWinners, max($cityWinners)));
echo $winner+1;

<?php
    $a = explode(" ", trim(fgets(STDIN)));
   function max_($arr){
       global $a;
       //echo "---------\n";
       //print_r($arr);
       $max_can = 0;
       $max_vot = -1;
       for($i = count($arr)-1;$i>=0;$i-- ){
           if(isset($arr[$i]) && $arr[$i] >= $max_vot){
               $max_can = $i;
               $max_vot = $arr[$i];
           }
       }
       return $max_can;
   }
   //print_r($a);
    for($i = 1; $i<=$a[1]; $i++){
        $c = explode(" ", trim(fgets(STDIN)));
        //print_r($c);
        $n = max_($c);
        //echo $n."\n";
        $s[$n] = 0;
        $s[$n] += 1 ;
    }
    //print_r($s);
    echo 1+max_($s)."\n";


<?php
$kostil = 0;
$ishod = str_ireplace('o','0',fgets(STDIN));
$ishod = str_ireplace('l','1',$ishod);
$ishod = str_ireplace('i','1',$ishod);
$ishod = strtolower($ishod);
$ishod = trim($ishod);
$num = fgets(STDIN);
for ($i = 0; $i <= $num; $i++) {
    $nicks[$i] = str_ireplace('o','0',fgets(STDIN));
	$nicks[$i] = str_ireplace('l','1',$nicks[$i]);
	$nicks[$i] = str_ireplace('i','1',$nicks[$i]);
	$nicks[$i] = strtolower($nicks[$i]);
	$nicks[$i] = trim($nicks[$i]);
	if($ishod == $nicks[$i]){
		//Pishov nahui
		echo "No";
		$kostil = 1;
		break;
	}
}
if(!$kostil){
	echo "Yes";
}

<?php

function normalize($login){
	$login = strtolower(trim($login));
	$login = str_replace(['o','i','l'], [0,1,1], $login);
	return $login;
}

$ans = 'Yes';
$login = normalize(fgets(STDIN));
$n = (int) fgets(STDIN);
for($i=0;$i<$n;$i++){
	$check = normalize(fgets(STDIN));
	if(strcmp($login, $check)===0){
		$ans = 'No';
	}
}
echo $ans;

<?php
$login = preg_replace("/(\r\n|\r|\n)/",'',strtolower(fgets(STDIN)));

$count = fgets(STDIN);
$response = "Yes";
for($i = 0;$i<$count;$i++) {
    $currentLogin = preg_replace("/(\r\n|\r|\n)/",'',strtolower(fgets(STDIN)));
    if(strlen($currentLogin) == strlen($login)) {
        $login = str_replace("o","0",$login);
        $currentLogin = str_replace("o",0,$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }

        $login = str_replace("l","1",$login);
        $currentLogin = str_replace("l","1",$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }

        $login = str_replace("i","1",$login);
        $currentLogin = str_replace("i","1",$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }
    }
}

echo $response;

<?php
$input_data = explode("\n", str_replace(["0", "1", "i"], ["o", "l", "l"], strtolower(file_get_contents('php://stdin'))));
$login = $input_data[0];
unset($input_data[0]); unset($input_data[1]);
echo in_array($login, $input_data) ? "No" : "Yes";

<?php
$a = str_split(strtolower(trim(fgets(STDIN))));
for($i = 0;$i<count($a);$i++)
{
    switch($a[$i])
    {
        case '0': $a[$i] = 'o'; break;
        case '1': $a[$i] = 'l'; break;
        case 'i': $a[$i] = 'l'; break;
    }
}
$a = implode($a);
$b = fgets(STDIN);
for ($j = 0;$j<$b;$j++)
{
    $g = str_split(strtolower(trim(fgets(STDIN))));
        for($i = 0;$i<count($g);$i++)
        {
            switch($g[$i])
            {
                case '0': $g[$i] = 'o'; break;
                case '1': $g[$i] = 'l'; break;
                case 'i': $g[$i] = 'l'; break;
            }
        }
    $g=implode($g);
    if($g == $a)
    {
        $k = 1;
        break;
    }
}
if($k == 1)
{
    echo 'No';
}
else
{
    echo 'Yes';
}
?>

<?php
$result="Yes";
$trans = array("o" => "0", "i" => "1", "l" => "1");
$login = trim(strtr(strtolower(fgets(STDIN)), $trans));
$count = (int) fgets(STDIN);

for($i=0; $i < $count; $i++){
    $base = trim(strtr(strtolower(fgets(STDIN)), $trans));
    if($base == $login){
        $result="No";
    }
}
echo $result;
?>

<?php
$login = preg_replace("/(\r\n|\r|\n)/",'',strtolower(fgets(STDIN)));

$count = fgets($STDIN);
$response = "Yes";
for($i = 0;$i<$count;$i++) {
    $currentLogin = preg_replace("/(\r\n|\r|\n)/",'',strtolower(fgets(STDIN)));
    if(strlen($currentLogin) == strlen($login)) {
        $login = str_replace("o","0",$login);
        $currentLogin = str_replace("o",0,$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }

        $login = str_replace("l","1",$login);
        $currentLogin = str_replace("l","1",$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }

        $login = str_replace("i","1",$login);
        $currentLogin = str_replace("i","1",$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }
    }
}

echo $response;


<?php

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

$result = "";

for($i=0; $i < $case; $i++){
	fscanf(STDIN, "%d", $num);

	// 10의 0부터 10의 9까지 있음
	for($j=0; $j < 11; $j++){
		if($num < 10**$j){
			$goal = $num - 10**($j-1);
			$result .= $goal."\n";
			break;
		}
	}
}

echo $result;

<?php
function solve($n) {
    $l = strlen($n);
    return (int)$n - pow(10,$l-1) ;
}

$t = (int) fgets(STDIN);
$ans = [] ;
while($t--) {
    $n = trim(fgets(STDIN));
    $ans[] = solve($n);
}
print_r(implode("\n",$ans)) ;

<?php

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

$result = "";

for($i=0; $i < $case; $i++){
	fscanf(STDIN, "%d", $num);

	// 10의 0부터 10의 9까지 있음
	for($j=0; $j < 10; $j++){
		if($num < 10**$j){
			$goal = $num - 10**($j-1);
			$result .= $goal."\n";
			break;
		}
	}
}

echo $result;


<?php
$a=fgets(STDIN);

function npr($num,$nn){
$num=(int)$num;
$nn=(int)$nn;
$f= 1;
settype($f,"double");
for ($x=$num; $x>($num-$nn); $x--)
{    $f= $f* $x;
}
return $f; }
echo npr($a,5)/120+npr($a,6)/720+npr($a,7)/5040;

?>

<?php
$a=fgets(STDIN);

function npr($num,$nn){
$num=(int)$num;
$nn=(int)$nn;
$f= 1;
settype($f,"double");
for ($x=$num; $x>($num-$nn); $x--)
{    $f= $f* $x;
}
return $f; }
$x=npr($a,5)/120+npr($a,6)/720+npr($a,7)/5040;
$format_x = sprintf("%.0f ",$x);
echo $format_x;
?>

<?php
$a=fgets(STDIN);
function fact($num){
    $num=(int)$num;
    if($num>1){
$factorial = 1;
for ($x=$num; $x>=1; $x--)
{
  $factorial = $factorial * $x;
}
return $factorial; }else return 1;}
function npr($n,$r){
    $n=(int)$n; $r=(int)$r;
    if($n>=$r){
    return (fact($n)/fact($n-$r));}
    else{
    return 0;}}
function ncr($n,$r){$n=(int)$n; $r=(int)$r;return (npr($n,$r)/fact($r));}
$fact1 = fact(5);
echo ncr($a,5)+ncr($a,6)+ncr($a,7);

?>