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

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

    for ($i = 1; $i < $n; $i++) {
        $idx = $i - 1;
        $s = $a[$i-1];
        unset($a[$i-1]);

        $x = (int) $a[$i];
        for ($j = 0; $j < $n; $j++) {
            if ($idx == $j) continue;
            if ($i == $j) continue;

            $x = $x ^ (int) $a[$j];
        }
        $a[$idx] = $s;
        if (in_array($x, $a)) {
            echo $x . PHP_EOL;
            break;
        }
    }
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fgets(STDIN);
    fscanf(STDIN, "%d", $a);
    echo "$a\n";
}

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

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

function solve()
{
     $n = IO::get();
     $a = IO::getArray();
     $tt = [];
     for($i=0; $i<$n; $i++) {
          if(isset($tt[$a[$i]])) {
               unset($tt[$a[$i]]);
          } else {
               $tt[$a[$i]] = 1;
          }
     }

     if(count($tt) == 0) {
          $ans = $a[0];
     } else {
          $v = array_keys($tt);
        for($i=0; $i<count($v); $i++) {
          $tM = $v[$i];
          $tV = 0;
          for($j=0; $j<count($v); $j++) {
               if($tM == $v[$j]) {
                    continue;
               }
               $tV = $tV ^ $v[$j];
          }
          if($tV == $tM) {
              $ans = $tM;
              break;
          }
        }
     }

     IO::pr($ans);

}

class IO {
    public static function get()
    {
        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;
    }
}


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

<?php
	$n = trim(fgets(STDIN));
	$A = explode(" ", trim(fgets(STDIN)));
	sort($A);
	if ($A[0] == 1) {
		print "-1";
	} else {
		print "1";
	}
?>

<?php
error_reporting(0);
//////////////////////// Class For Read Input --- @laurenceHR [02/2012] ////////////////////////////////////////////////////////////
class stdIn{var $ntxt = 0;var $nline = 0;var $arr_txt;var $arr_line;var $linex;var $liney;
function stdIn($local = false){if($local){$dir = fopen("input.txt", 'r');}else{$dir = fopen("php://stdin", 'r');}
$datatxt = stream_get_contents($dir);$del = Array("\n","\r","\n\r");$data = explode("\n",$datatxt); $il = 0;$id = 0;
foreach($data as $line){if(strlen($line) > 0){$line = str_replace($del,'',$line);$dataex[] = $line;$text = explode(" ",$line);
foreach($text as $txt){$arr_txt[] = $txt;$this->linex[$id] = $il;$this->liney[$il] = $id;$id++;}}$il++;}$this->arr_line = $dataex;$this->arr_txt  = $arr_txt;}
function G(){$ret = $this->arr_txt[$this->ntxt++];$this->nline = $this->linex[$this->ntxt];return $ret;}
function GL(){$this->ntxt = $this->liney[$this->nline]+1;return $this->arr_line[$this->nline++];}} /*init*/
$dxs = new stdIn();

$n = $dxs->G();
$ok = false;
for($i = 0; $i < $n; $i++) {
    $x = $dxs->G();
    if($x == 1) {
        $ok = true;
    }
}

if($ok) {
    echo -1;
} else {
    echo 1;
}
?>

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

<?php

fscanf(STDIN, "%d", &$n);
for($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d", &$x);
    if($x == 1) {
        echo -1;
        exit;
    }
}
echo 1;


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

function check(){
    $arr=[];
    for($i=0; $i<8; $i++){
     $arr[] = str_split(trim(fgets(STDIN)));
    }

    for($j=0; $j<8; $j++){
        if ($arr[$j][0] != 'R')
            continue;

        $color = true;
        for ($k =0; $k<8; $k++){
            if ($arr[$j][$k] != 'R'){
                $color = false;
                break;
            }
        }
        if($color)
            return 'R';
    }

    for($j=0; $j<8; $j++){
        if ($arr[0][$j] != 'B')
            continue;

        $color = true;
        for ($k=0; $k<8; $k++){
            if ($arr[$k][$j] != 'B'){
                $color = false;
                break;
            }
        }
        if($color)
            return 'B';
    }
}

for($g=0; $g<$count; $g++){
    $c = trim(fgets(STDIN));

    $col = check();
    echo "$col\n";
}

<?php

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

for ($case = 0; $case < $t; $case++)
{
    fgets(STDIN);

    $last = "B";

    for ($line = 0; $line < 8; $line++)
    {
        $value = trim(fgets(STDIN));

        if($last == "B" && !str_contains($value, "B"))
        {
            $last = "R";
        }
    }

    echo($last . PHP_EOL);
}

<?php

fscanf(STDIN, '%u', $t);

$rF = 'RRRRRRRR';
$bF = 'BBBBBBBB';

while ($t--) {
    $l = [];
    fgets(STDIN);
    for ($i = 0; $i < 8; ++$i) {
        fscanf(STDIN, '%s', $l[$i]);
    }

    if (in_array($rF, $l, true)) {
        echo 'R'.PHP_EOL;
    } elseif (in_array($bF, $l, true)) {
        echo 'B'.PHP_EOL;
    } else {
        // transpose
        $tL = array_map('implode', array_map(null, ...array_map('str_split', $l)));

        if (in_array($rF, $tL, true)) {

            if ($t === 4000 - 17) {
                echo implode($l).PHP_EOL;
                continue;
            }

            echo 'R'.PHP_EOL;
        } elseif(in_array($bF, $tL, true)) {
            echo 'B'.PHP_EOL;
        } else {
            throw new \RuntimeException('oops');
        }
    }
}

/*

4

....B...
....B...
....B...
RRRRRRRR
....B...
....B...
....B...
....B...

RRRRRRRB
B......B
B......B
B......B
B......B
B......B
B......B
RRRRRRRB

RRRRRRBB
.B.B..BB
RRRRRRBB
.B.B..BB
.B.B..BB
RRRRRRBB
.B.B..BB
.B.B..BB

........
........
........
RRRRRRRR
........
........
........
........

 */

<?php

fscanf(STDIN, '%u', $t);

$rF = 'RRRRRRRR';
$bF = 'BBBBBBBB';

while ($t--) {
    $l = [];
    fgets(STDIN);
    for ($i = 0; $i < 8; ++$i) {
        fscanf(STDIN, '%s', $l[$i]);
    }

    if (in_array($rF, $l, true)) {
        echo 'R'.PHP_EOL;
    } elseif (in_array($bF, $l, true)) {
        echo 'B'.PHP_EOL;
    } else {
        // transpose
        $tL = array_map('implode', array_map(null, ...array_map('str_split', $l)));

        if (in_array($rF, $tL, true)) {
            echo 'R'.PHP_EOL;
        } elseif(in_array($bF, $tL, true)) {
            echo 'B'.PHP_EOL;
        } else {
            throw new \RuntimeException('oops');
        }
    }
}

/*

4

....B...
....B...
....B...
RRRRRRRR
....B...
....B...
....B...
....B...

RRRRRRRB
B......B
B......B
B......B
B......B
B......B
B......B
RRRRRRRB

RRRRRRBB
.B.B..BB
RRRRRRBB
.B.B..BB
.B.B..BB
RRRRRRBB
.B.B..BB
.B.B..BB

........
........
........
RRRRRRRR
........
........
........
........

 */


<?php

list($height, $width) = explode(' ', trim(fgets(STDIN)));
$lines = [];
$startX = $startY = $endX = $endY = 0;
for ($i = 0; $i < (int)$height; $i++)
{
    $lines[] = trim(fgets(STDIN));
    if (strpos($lines[$i], 'S') !== false)
    {
        $startY = $i;
        $startX = strpos($lines[$i], 'S');
    }
    if (strpos($lines[$i], 'E') !== false)
    {
        $endY = $i;
        $endX = strpos($lines[$i], 'E');
    }
}
$inputs = trim(fgets(STDIN));

$patterns = [
    [0, 1],
    [0, -1],
    [1, 0],
    [-1, 0]
];

$result = 0;
for ($i = 0; $i < 4; $i++)
{
    for ($j = 0; $j < 4; $j++)
    {
        if ($i === $j)
        {
            continue;
        }
        for ($k = 0; $k < 4; $k++)
        {
            if ($i === $k || $j === $k)
            {
                continue;
            }
            for ($l = 0; $l < 4; $l++)
            {
                if ($i === $l || $j === $l || $k === $l)
                {
                    continue;
                }

                $x = $startX;
                $y = $startY;
                $target = 0;
                for ($index = 0; $index < strlen($inputs); $index++)
                {
                    if ($i === (int)$inputs[$index])
                    {
                        $target = 0;
                    }
                    else if ($j === (int)$inputs[$index])
                    {
                        $target = 1;
                    }
                    else if ($k === (int)$inputs[$index])
                    {
                        $target = 2;
                    }
                    else if ($l === (int)$inputs[$index])
                    {
                        $target = 3;
                    }

                    $pattern = $patterns[$target];
                    $y += $pattern[1];
                    $x += $pattern[0];

                    if ($y < 0 || $x < 0 || $y >= $height || $x >= $width || $lines[$y][$x] === '#')
                    {
                        break;
                    }

                    if ($x === $endX && $y === $endY)
                    {
                        $result++;
                        break;
                    }
                }
            }
        }
    }
}

echo $result;


<?php

$s1 = trim(fgets(STDIN));
$s2 = trim(fgets(STDIN));
$s3 = trim(fgets(STDIN));
$p = '/[aeiou]/';

if(preg_match_all($p,$s1,$o)==5&&preg_match_all($p,$s2,$o)==7&&preg_match_all($p,$s3,$o)==5)
 print 'YES'; else print 'NO';
?>

<?php

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

  $line = "";
  $first = $second = $third = 0;

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

  $line = explode("\n",$line);

  $ans = array(0 , 0 ,  0);
  for($i = 0 ; $i < 3 ; ++ $i)
  {
  		for($j = 0 ; $j < strlen($line[$i]); ++ $j)
  		if($line[$i][$j] == 'a' || $line[$i][$j] == 'u' || $line[$i][$j] == 'i' || $line[$i][$j] == 'o' || $line[$i][$j] == 'e')
  			++ $ans[$i];
  }
  if($ans[0] == 5 && $ans[1] == 7 && $ans[2] == 5)
  	file_put_contents("php://stdout","YES");
  	else
  	  	file_put_contents("php://stdout","NO");
?>

<?php
$firsCnt=0;
$secondCnt=0;
$thirdCnt=0;
for ($i=0; $i <3 ; $i++)
{
$str[$i]=str_replace(' ','',trim(fgets(STDIN)));

for ($j=0; $j <strlen($str[$i]) ; $j++)
{

			if($str[$i][$j]=='a'||$str[$i][$j]=='e'||$str[$i][$j]=='i'||$str[$i][$j]=='o'||$str[$i][$j]=='u')
			{
					 if($i==0)
					 	$firsCnt++;
					 elseif ($i==1)
					   $secondCnt++;
					  else
					  	$thirdCnt++;
			}

}
}
if($firsCnt==5&&$secondCnt==7&&$thirdCnt==5)
	echo "YES";
else
	echo "NO";

<?
$n1=trim(fgets(STDIN));
$n2=trim(fgets(STDIN));
$n3=trim(fgets(STDIN));
function icount($n){
    for($i=0;$i<strlen($n);$i++){
        if($n[$i]=='a' || $n[$i]=='e' ||  $n[$i]=='i' || $n[$i]=='o' ||  $n[$i]=='u')
            $count++;
    }
    return $count;
}
$a=icount($n1);
$b=icount($n2);
$c=icount($n3);
if ($a==5 && $b==7 && $c==5)
    echo "YES";
else echo "NO";
?>


<?php
    $n = trim(fgets(STDIN));
    $m = trim(fgets(STDIN));
    $a = array();
    for ($i = 0 ; $i < $n ; $i ++)
    {
        $a[$i] = trim(fgets(STDIN));
    }
    rsort($a);
    $sum = 0;
    $res = -1;
    for ($i = 0 ; $i < $n ; $i ++)
    {
        $sum += $a[$i];
        if ($sum >= $m){
            $res = $i + 1;
            break;
        }
    }
    echo($res);
?>

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

<?php

$handle = fopen ("php://stdin","r");
$input = stream_get_contents($handle);
$input = explode(PHP_EOL, $input);
$num_usbs = $input[0];
$total_size = $input[1];
$usbs_size = array_slice($input, 2);
rsort($usbs_size);
$i = 0;
while($total_size > 0) {
    $total_size -= $usbs_size[$i];
    $i++;
}
echo $i;

<?php
fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%d', $size);
$arr = array();
for($i = 0; $i < $n; $i++){
    fscanf(STDIN, '%d', $x);
    $arr[] = $x;
}
rsort($arr);
$sum = 0;
foreach($arr as $k=>$a){
    $sum+= $a;
    if($sum >= $size){
        fprintf(STDOUT, '%d', $k + 1); exit;
    }
}
?>

<?php
$a = array();
$n = trim(fgets(STDIN));
$m = trim(fgets(STDIN));
for($i=0; $i<$n; $i++)
	$a[$i] = trim(fgets(STDIN));
rsort($a);
$j=0;
$i=0;
while($j<$m)
	$j=$j+$a[$i++];
echo $i;
?>

<?php
fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%d', $size);
$arr = array();
for($i = 0; $i < $n; $i++){
    fscanf(STDIN, '%d', $x);
    $arr[] = $x;
}
rsort($arr);
$sum = 0;
foreach($arr as $k=>$a){
    $sum+= $a;
    if($sum >= $size){
        fprintf(STDOUT, '%d', $k); exit;
    }
}
?>

<?php
fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%d', $size);
$arr = array();
for($i = 0; $i < $n; $i++){
    fscanf(STDIN, '%d', $x);
    $arr[] = $x;
}
rsort($arr);
$sum = 0;
foreach($arr as $k=>$a){
    $sum+= $a;
    if($sum > $size){
        fprintf(STDOUT, '%d', $k); exit;
    }
}
?>


<?php
$handle = fopen ("php://stdin","r");
$t = fgets($handle);
for($i=0; $i<$t; $i++) {
	$n = fgets($handle);
	$s = fgets($handle);
	$n = (int)$n;

	if($n < 11 || strpos($s, "8") === false) {
		echo "NO\n";
	} else if($n === 11) {
		echo $s[0] === "8" ? "YES\n" : "NO\n";
	} else {
		$odd = $n - 11;
		echo strpos($s, "8") <= $odd ? "YES\n" : "NO\n";
	}
}
?>

<?php
    $t = trim(fgets(STDIN));
    for ($i = 0; $i < $t; $i++) {
        $n = trim(fgets(STDIN));
        $s = trim(fgets(STDIN));
        $l = substr($s, 0, -10);
        if (preg_match("/8/", $l)) {
            echo "YES"."\n";
        } else {
            echo "NO"."\n";
        }
    }
?>

<?php

$k = trim(fgets(STDIN));

for($i = 0; $i< $k ; $i++){
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));

   if(strpos($s, '8') !== false && $n-strpos($s, '8') >= 11){
      echo "YES\n";
    } else {
        echo "NO\n";
    }
}

?>

<?php
# Alireza
# JAHANI
# PH_PY_LA
# Dont Repeat Your self ...

$n = fgets(STDIN);
$result=[];
for ($i=0; $i < $n; $i++) {
      $count = fgets(STDIN);
      settype($count,'int');
      $tell=str_split(trim(fgets(STDIN)));
      $eight=array_search('8',$tell)+1;
      if(in_array('8',$tell)){
      	if ($count - $eight >= 10)
      	$result[]="YES";
      else
      	$result[]="NO";
  }else{
  	$result[]="NO";
  }
}
foreach ($result as  $value) {
	echo($value."\n");
}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
		fscanf(STDIN,"%d",$n);
		fscanf(STDIN,"%s",$str);
		$len=strlen($str);
        $flag=0;
		for ($i=0; $i <$len ; $i++)
		 {
			if($str[$i]=='8')
			{
				if($len-$i>=11)
				{
					$flag=1;
					break;
				}

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

}

<?php
$testCasesCount = intval(trim(fgets(STDIN)));
$testCasesArray = [];
if (is_int($testCasesCount) && $testCasesCount > 0 && $testCasesCount <= 100) {
    for ($i = 0; $i < $testCasesCount; $i++) {
        $testCasesArray[$i]['numberLength'] = intval(trim(fgets(STDIN)));
        $testCasesArray[$i]['number']       = trim(fgets(STDIN));
    }
    for ($i = 0; $i < $testCasesCount; $i++) {
        $numberLength = $testCasesArray[$i]['numberLength'];
        $number       = $testCasesArray[$i]['number'];
        if ($numberLength < 11) {
            echo "NO\n";
            continue;
        }
        $eightNumberPos = strpos($number, '8');
        if ($eightNumberPos === false) {
            echo "NO\n";
            continue;
        } elseif (($numberLength - 11) >= $eightNumberPos) {
            echo "YES\n";
            continue;
        } else {
            echo "NO\n";
            continue;
        }
    }
}

<?php
  $n = trim(fgets(STDIN));
  $f = '8';
  for($i = 0; $i<$n; $i++) {
          $l = trim(fgets(STDIN));
          $str = trim(fgets(STDIN));
          $pos = strpos($str, $f);

          if($l - $pos >= 11 && strlen($pos)) {
              echo "YES\n";
              continue;
          } else {
              echo "NO\n";
              continue;
          }
  }

<?php

$t = trim(fgets(STDIN));

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

   if(strpos($s, '8') !== false && $n-strpos($s, '8') >= 11){
      echo "YES\n";
    } else {
        echo "NO\n";
    }
}

?>

<?php
//$testCasesCount = trim(fgets(STDIN));
//$testCasesArray = [];
$testCasesCount = 2;
$testCasesArray = [
    0 => ['numberLength' => 13, 'number' => 7818005553535],
    1 => ['numberLength' => 11, 'number' => 31415926535]
];
if (is_int($testCasesCount) && $testCasesCount > 0) {
//    for ($i = 0; $i < $testCasesCount; $i++) {
//        $testCasesArray[$i]['numberLength'] = trim(fgets(STDIN));
//        $testCasesArray[$i]['number']       = trim(fgets(STDIN));
//    }
    for ($i = 0; $i < $testCasesCount; $i++) {
        $numberLength = $testCasesArray[$i]['numberLength'];
        $number       = $testCasesArray[$i]['number'];
        if ($numberLength < 11) {
            //echo 'NO' . PHP_EOL;
            echo "NO\n";
            continue;
        }
        $eightNumberPos = strpos(((string) $number), '8');
        if ($eightNumberPos === false) {
            //echo 'NO' . PHP_EOL;
            echo "NO\n";
            continue;
        } elseif (($numberLength - 11) >= $eightNumberPos) {
            //echo 'YES' . PHP_EOL;
            echo "YES\n";
            continue;
        } else {
            //echo 'NO' . PHP_EOL;
            echo "NO\n";
            continue;
        }
    }
}

<?php
$testCasesCount = trim(fgets(STDIN));
$testCasesArray = [];
if (is_int($testCasesCount) && $testCasesCount > 0 && $testCasesCount <= 100) {
    for ($i = 0; $i < $testCasesCount; $i++) {
        $testCasesArray[$i]['numberLength'] = trim(fgets(STDIN));
        $testCasesArray[$i]['number']       = trim(fgets(STDIN));
    }
    for ($i = 0; $i < $testCasesCount; $i++) {
        $numberLength = $testCasesArray[$i]['numberLength'];
        $number       = $testCasesArray[$i]['number'];
        if ($numberLength < 11) {
            echo "NO\n";
            continue;
        }
        $eightNumberPos = strpos(((string) $number), '8');
        if ($eightNumberPos === false) {
            echo "NO\n";
            continue;
        } elseif (($numberLength - 11) >= $eightNumberPos) {
            echo "YES\n";
            continue;
        } else {
            echo "NO\n";
            continue;
        }
    }
}

<?php
$testCasesCount = intval(trim(fgets(STDIN)));
$testCasesArray = [];
if (is_int($testCasesCount) && $testCasesCount > 0 && $testCasesCount <= 100) {
    for ($i = 0; $i < $testCasesCount; $i++) {
        $testCasesArray[$i]['numberLength'] = intval(trim(fgets(STDIN)));
        $testCasesArray[$i]['number']       = intval(trim(fgets(STDIN)));
    }
    for ($i = 0; $i < $testCasesCount; $i++) {
        $numberLength = $testCasesArray[$i]['numberLength'];
        $number       = $testCasesArray[$i]['number'];
        if ($numberLength < 11) {
            echo "NO\n";
            continue;
        }
        $eightNumberPos = strpos(((string) $number), '8');
        if ($eightNumberPos === false) {
            echo "NO\n";
            continue;
        } elseif (($numberLength - 11) >= $eightNumberPos) {
            echo "YES\n";
            continue;
        } else {
            echo "NO\n";
            continue;
        }
    }
}

<?php
$testCasesCount = trim(fgets(STDIN));
$testCasesArray = [];
if (is_int($testCasesCount) && $testCasesCount > 0 && $testCasesCount <= 100) {
    for ($i = 0; $i < $testCasesCount; $i++) {
        $testCasesArray[$i]['numberLength'] = trim(fgets(STDIN));
        $testCasesArray[$i]['number']       = trim(fgets(STDIN));
    }
    for ($i = 0; $i < $testCasesCount; $i++) {
        $numberLength = $testCasesArray[$i]['numberLength'];
        $number       = $testCasesArray[$i]['number'];
        if ($numberLength < 11) {
            echo 'NO' . PHP_EOL;
            continue;
        }
        $eightNumberPos = strpos(((string) $number), '8');
        if ($eightNumberPos === false) {
            echo 'NO' . PHP_EOL;
            continue;
        } elseif (($numberLength - 11) >= $eightNumberPos) {
            echo 'YES' . PHP_EOL;
            continue;
        } else {
            echo 'NO' . PHP_EOL;
            continue;
        }
    }
}

<?php

$t = trim(fgets(STDIN));

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

    if(strpos($s, '8') !== false && $n>=11){
      echo "YES\n";
    } else {
        echo "NO\n";
    }
}

?>

<?php

$t = trim(fgets(STDIN));

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

    if($n == 11){
        if($s[0] == 8){
            echo "YES\n";
        } else {
            echo "NO\n";
        }

    } else {
        $s1 = substr($s, 0, $n-11);
        if(strpos($s1, '8') !== false){
          echo "YES\n";
        } else {
            echo "NO\n";
        }
    }
}

?>

<?php

$t = trim(fgets(STDIN));

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

   if(strpos($s, '8') !== false && $n-strpos($s, '8') == 12){
      echo "YES\n";
    } else {
        echo "NO\n";
    }
}

?>

<?php

$t = trim(fgets(STDIN));

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

   if(strpos($s, '8') !== false && $n-strpos($s, '8') >= 12){
      echo "YES\n";
    } else {
        echo "NO\n";
    }
}

?>

<?php

$t = trim(fgets(STDIN));

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

    if($n == 11){
        if($s[0] == 8){
            echo "YES\n";
        } else {
            echo "NO\n";
        }

    } else {
        //$s1 = substr($s, 0, $n-11);
        if(strpos($s, '8') !== false && $n>=11){
          echo "YES\n";
        } else {
            echo "NO\n";
        }
    }
}

?>

<?php
# Alireza
# JAHANI
# PH_PY_LA
# Dont Repeat Your self ...

$n = fgets(STDIN);
$result=[];
for ($i=0; $i < $n; $i++) {
      $count = fgets(STDIN);
      settype($count,'int');
      $tell=str_split(trim(fgets(STDIN)));
      $eight=array_search('8',$tell)+1;
      if (count($tell) - $eight >= 11)
      	$result[]="YES";
      else
      	$result[]="NO";
}
foreach ($result as  $value) {
	echo($value."\n");
}

<?php
# Alireza
# JAHANI
# PH_PY_LA
# Dont Repeat Your self ...

$n = fgets(STDIN);
$result=[];
for ($i=0; $i < 2; $i++) {
      $count = fgets(STDIN);
      settype($count,'int');
      $tell=str_split(trim(fgets(STDIN)));
      $eight=array_search('8',$tell)+1;
      if (count($tell) - $eight >= 11)
      	$result[]="YES";
      else
      	$result[]="NO";
}
foreach ($result as  $value) {
	echo($value."\n");
}

<?php
# Alireza
# JAHANI
# PH_PY_LA
# Dont Repeat Your self ...

$n = fgets(STDIN);
$result=[];
for ($i=0; $i < $n; $i++) {
      $count = fgets(STDIN);
      settype($count,'int');
      $tell=str_split(trim(fgets(STDIN)));
      $eight=array_search('8',$tell)+1;
      if ($count - $eight >= 10)
      	$result[]="YES";
      else
      	$result[]="NO";
}
foreach ($result as  $value) {
	echo($value."\n");
}

<?php
# Alireza
# JAHANI
# PH_PY_LA
# Dont Repeat Your self ...

$n = fgets(STDIN);
$result=[];
for ($i=0; $i < $n; $i++) {
      $count = fgets(STDIN);
      settype($count,'int');
      $tell=str_split(trim(fgets(STDIN)));
      $eight=array_search('8',$tell)+1;
      if ($count - $eight >= 11)
      	$result[]="YES";
      else
      	$result[]="NO";
}
foreach ($result as  $value) {
	echo($value."\n");
}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
		fscanf(STDIN,"%d",$n);
		fscanf(STDIN,"%s",$str);
		$len=strlen($str);
		for ($i=0; $i <$len ; $i++)
		 {
			if($str[$i]=='8')
			{
				$pos=$i+1;
				break;
			}
		 }
		 if($len-$pos>=11)
		 	echo "YES\n";
		 else
		 	echo "NO\n";

}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
		fscanf(STDIN,"%d",$n);
		fscanf(STDIN,"%s",$str);
		$len=strlen($str);
		for ($i=0; $i <$len ; $i++)
		 {
			if($str[$i]=='8')
			{
				$pos=$i+1;
				break;
			}
		 }
		 if($len-$pos==11)
		 	echo "YES\n";
		 else
		 	echo "NO\n";

}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
		fscanf(STDIN,"%d",$n);
		fscanf(STDIN,"%s",$str);
		$len=strlen($str);
		for ($i=0; $i <$len ; $i++)
		 {
			if($str[$i]=='8')
			{
				$pos=$i;
				break;
			}
		 }
		 if($len-$pos>=11)
		 	echo "YES\n";
		 else
		 	echo "NO\n";

}

<?php
$handle = fopen ("php://stdin","r");
$t = fgets($handle);
for($i=0; $i<$t; $i++) {
	$n = fgets($handle);
	$s = fgets($handle);
	$n = (int)$n;
	var_dump($n);
	if($n < 11) {
		echo "NO\n";
	} else if($n === 11) {
		echo $s[0] === "8" ? "YES\n" : "NO\n";
	} else {
		$odd = $n - 11;
		echo strpos($s, "8") <= $odd ? "YES\n" : "NO\n";
	}
}

?>

<?php
$handle = fopen ("php://stdin","r");
$t = fgets($handle);
for($i=0; $i<$t; $i++) {
	$n = fgets($handle);
	$s = fgets($handle);
	$n = (int)$n;
	if($n < 11) {
		echo "NO\n";
	} else if($n === 11) {
		echo $s[0] === "8" ? "YES\n" : "NO\n";
	} else {
		$odd = $n - 11;
		echo strpos($s, "8") <= $odd ? "YES\n" : "NO\n";
	}
}

?>


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

$danger = 0;
for ($i = 0; $i <= $n; $i++) {
    $v = explode(' ', trim(fgets(STDIN)));
    $x = $v[0];
    $y = $v[1];

    if (isset($lastX)) {
        if ($x > $lastX) {
            $parts[$i] = 'R';
        } else if ($x < $lastX) {
            $parts[$i] = 'L';
        } else if ($y > $lastY) {
            $parts[$i] = 'T';
        } else {
            $parts[$i] = 'B';
        }

        if (isset($parts[$i-1])) {
            $situation = $parts[$i-1].$parts[$i];
            if (in_array($situation, array('RT','TL','LB', 'BR'))) {
                $danger++;
            }
        }
    }

    $lastX = $x;
    $lastY = $y;

}
echo $danger;

?>

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

for ($i = 0; $i <= $n; $i++) {
    $v = explode(' ', trim(fgets(STDIN)));
    $x = $v[0];
    $y = $v[1];

    if (isset($lastX)) {
        if ($x > $lastX) {
            $parts[$i] = 'R';
        } else if ($x < $lastX) {
            $parts[$i] = 'L';
        } else if ($y > $lastY) {
            $parts[$i] = 'T';
        } else {
            $parts[$i] = 'B';
        }

        if (isset($parts[$i-1])) {
            $situation = $parts[$i-1].$parts[$i];
            if (in_array($situation, array('RT','TL','LB', 'BR'))) {
                $danger++;
            }
        }
    }

    $lastX = $x;
    $lastY = $y;

}
echo $danger;

?>


<?php function o($s){if(strlen($s)%2)return $s;$l=o(substr($s,0,strlen($s)/2));$r=o(substr($s,strlen($s)/2));return $l<$r?$r.$l:$l.$r;}echo o(trim(fgets(STDIN)))==o(trim(fgets(STDIN)))?"YES\n":"NO\n";

<?php
error_reporting(-1);

$cache = array();

function order($string) {
	if (strlen($string) % 2 == 1)
		return $string;

	$left = order(substr($string, 0, strlen($string)/2));
	$right = order(substr($string, strlen($string)/2));
	return strcmp($left, $right) > 0 ? $right.$left : $left.$right;
}

$input = array_map('trim', explode("\n", file_get_contents('php://stdin')));
$a = order(array_shift($input));
$b = order(array_shift($input));

if ($a == $b)
	echo 'YES', PHP_EOL;
else
	echo 'NO', PHP_EOL;

<?php
function o($s){if(strlen($s)%2==1)return $s;$l=o(substr($s,0,strlen($s)/2));$r=o(substr($s,strlen($s)/2));return $l<$r?$r.$l:$l.$r;}
echo o(trim(fgets(STDIN)))==o(trim(fgets(STDIN)))?'YES':'NO',"\n";

<?php function o($s){if(strlen($s)%2)return $s;$l=o(substr($s,0,$h=strlen($s)/2));$r=o(substr($s,$h));return $l<$r?$r.$l:$l.$r;}echo o(trim(fgets(STDIN)))==o(trim(fgets(STDIN)))?"YES\n":"NO\n";

<?php function o($s){if(($l=strlen($s))%2)return $s;$l=o(substr($s,0,$h=$l/2));$r=o(substr($s,$h));return $l<$r?$r.$l:$l.$r;}echo o(trim(fgets(STDIN)))==o(trim(fgets(STDIN)))?"YES\n":"NO\n";

<?php
error_reporting(-1);

$cache = array();

function order($string) {
	if (strlen($string) == 1)
		return $string;

	$left = order(substr($string, 0, strlen($string)/2));
	$right = order(substr($string, strlen($string)/2));
	return strcmp($left, $right) > 0 ? $right.$left : $left.$right;
}

$input = array_map('trim', explode("\n", file_get_contents('php://stdin')));
$a = order(array_shift($input));
$b = order(array_shift($input));

if ($a == $b)
	echo 'YES', PHP_EOL;
else
	echo 'NO', PHP_EOL;

<?php
error_reporting(-1);

function order($string) {
	$string = str_split($string);
	sort($string);
	return implode('', $string);
}

$input = array_map('trim', explode("\n", file_get_contents('php://stdin')));
$a = array_shift($input);
$a1 = order(substr($a, 0, strlen($a)/2));
$a2 = order(substr($a, strlen($a)/2));
$b = array_shift($input);
$b1 = order(substr($b, 0, strlen($b)/2));
$b2 = order(substr($b, strlen($b)/2));

if (($a1 == $b1 && $a2 == $b2) || ($a1 == $b2) && ($a2 == $b1))
	echo 'YES', PHP_EOL;
else
	echo 'NO', PHP_EOL;


<?php
# 1153A
$start = microtime(1);
$input = fopen('php://stdin', 'rb');
[$busCount, $servalTime] = explode(' ', fgets($input));
$busCount = (int)$busCount;
$servalTime = (int)$servalTime;
$busArrival = [];
$busShift = [];

for ($i = 1; $i <= $busCount; $i++) {
    $_busData = explode(' ', fgets($input));
    if ((int)$_busData[0] === $servalTime) {
        echo $i;
        die();
    }
    $busArrival[$i] = (int)$_busData[0];
    $busShift[$i] = (int)$_busData[1];
}
$time = min([$servalTime] + $busArrival);
$result = 0;
while ($result === 0) {
    foreach ($busArrival as $busIndex => $busDatum) {
        if ($servalTime === $busDatum) {
            $result = $busIndex;
            break 2;
        }
        if ($time === $busDatum) {
            if ($time >= $servalTime) {
                $result = $busIndex;
                break 2;
            }
            $busArrival[$busIndex] += $busShift[$busIndex];
        }
    }
    $time = min($busArrival);
}
echo $result;

<?php

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

$n = $ser[0];
$t = $ser[1];

$pot = [];

for($i = 0; $i<$n; $i++){
	$bus = explode(' ', trim(fgets(STDIN)));
	$s = $bus[0];
	$d = $bus[1];

	while($s < $t){
		$s+=$d;
	}

	$pot[] = $s;
}

//print_r($pot);

fwrite(STDOUT, array_search(min($pot), $pot)+1);

<?php
# 1153A
$start = microtime(1);
$input = fopen('php://stdin', 'rb');
[$busCount, $servalTime] = explode(' ', fgets($input));
$busCount = (int)$busCount;
$servalTime = (int)$servalTime;
$busArrival = [];
$busShift = [];

$maxTime = 1000000000;
$result = 0;
for ($i = 1; $i <= $busCount; $i++) {
    [$busArrival, $busShift] = explode(' ', fgets($input));
    $busArrival = (int)$busArrival;
    $busShift = (int)$busShift;
    if ($servalTime < $busArrival) {
        if ($maxTime > $busArrival) {
            $maxTime = $busArrival;
            $result = $i;
        }
        continue;
    }
    $delta = ($servalTime - $busArrival) / $busShift;
    if (($servalTime - $busArrival) % $busShift !==0) {
        $delta++;
    }
    $shift = $busArrival + $delta * $busShift;
    if ($shift < $maxTime) {
        $maxTime = $shift;
        $result = $i;
    }
}
echo $result;

<?php
# 1153A
$start = microtime(1);
$input = fopen('php://stdin', 'rb');
[$busCount, $servalTime] = explode(' ', fgets($input));
$busCount = (int)$busCount;
$servalTime = (int)$servalTime;
$busArrival = [];
$busShift = [];

for ($i = 1; $i <= $busCount; $i++) {
    $_busData = explode(' ', fgets($input));
    if ((int)$_busData[0] === $servalTime) {
        echo $i;
        die();
    }
    $busArrival[$i] = (int)$_busData[0];
    $busShift[$i] = (int)$_busData[1];
}
foreach($busArrival as $busIndex => $arrivalTime) {
    $waiting = $servalTime - $arrivalTime;
    $minimalWaiting = $waiting - floor($waiting / $busShift[$busIndex]) * $busShift[$busIndex];
    $busArrival[$busIndex] = (int)($minimalWaiting ?: $servalTime);
}
$time = min($busArrival);
while ($time<= $servalTime) {
    foreach ($busArrival as $busIndex => $busDatum) {
        if ($servalTime === $busDatum) {
            echo $busIndex;
            break 2;
        }
        if ($time === $busDatum) {
            if ($time >= $servalTime) {
                echo $busIndex;
                break 2;
            }
            $busArrival[$busIndex] += $busShift[$busIndex];
        }
    }
    $time = min($busArrival);
}

<?php
# 1153A
$start = microtime(1);
$input = fopen('php://stdin', 'rb');
[$busCount, $servalTime] = explode(' ', fgets($input));
$busCount = (int)$busCount;
$servalTime = (int)$servalTime;

$maxTime = 1000000000;
$result = 0;
for ($i = 1; $i <= $busCount; $i++) {
    [$busArrival, $busShift] = explode(' ', fgets($input));
    $busArrival = (int)$busArrival;
    $busShift = (int)$busShift;
    if ($servalTime <= $busArrival) {
        if ($maxTime > $busArrival) {
            $maxTime = $busArrival;
            $result = $i;
        }
        continue;
    }
    $delta = ($servalTime - $busArrival) / $busShift;
    if (($servalTime - $busArrival) % $busShift !== 0) {
        $delta++;
    }
    $shift = $busArrival + $delta * $busShift;
    if ($shift < $maxTime) {
        $maxTime = $shift;
        $result = $i;
    }
}
echo $result;

<?php
# 1153A
$start = microtime(1);
$input = fopen('php://stdin', 'rb');
[$busCount, $servalTime] = explode(' ', fgets($input));
$busCount = (int)$busCount;
$servalTime = (int)$servalTime;
$busArrival = [];
$busShift = [];

for ($i = 1; $i <= $busCount; $i++) {
    $_busData = explode(' ', fgets($input));
    if ((int)$_busData[0] === $servalTime) {
        echo $i;
        die();
    }
    $busArrival[$i] = (int)$_busData[0];
    $busShift[$i] = (int)$_busData[1];
}
foreach($busArrival as $busIndex => $arrivalTime) {
    if ($servalTime > $arrivalTime) {
        $waiting = $servalTime - $arrivalTime;
        $minimalWaiting = $waiting - floor($waiting / $busShift[$busIndex]) * $busShift[$busIndex];
        $busArrival[$busIndex] = (int)($minimalWaiting ?: $servalTime);
    }
}
$time = min([-1 => $servalTime] + $busArrival);
$result = 0;
while ($result === 0) {
    foreach ($busArrival as $busIndex => $busDatum) {
        if ($servalTime === $busDatum) {
            $result = $busIndex;
            break 2;
        }
        if ($time === $busDatum) {
            if ($time >= $servalTime) {
                $result = $busIndex;
                break 2;
            }
            $busArrival[$busIndex] += $busShift[$busIndex];
        }
    }
    $time = min($busArrival);
}
echo $result;

<?php

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

$n = $ser[0];
$t = $ser[1];

$pot = [];

for($i = 0; $i<$n; $i++){
	$bus = explode(' ', trim(fgets(STDIN)));
	$s = $bus[0];
	$d = $bus[1];

	while($s < $t){
		$s+=$d;
	}

	$pot[] = $s;
}

print_r($pot);

fwrite(STDOUT, array_search(min($pot), $pot)+1);

<?php

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

$n = $ser[0];
$t = $ser[1];

$pot = [];

for($i = 0; $i<$n; $i++){
	$bus = explode(' ', trim(fgets(STDIN)));
	$s = $bus[0];
	$d = $bus[1];

	while($s < $t){
		$s+=$t;
	}

	$pot[] = $s;
}

fwrite(STDOUT, array_search(min($pot), $pot)+1);


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

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

$t = IO::str();
$res = array();
while ($t--) {
    list($n,$k) = IO::arr();
    $arr = IO::arr();
    $cnt = 0;
    $total = 0;
    $end = count($arr) - 1;
    while (true) {
        if ($end == $cnt || $k == 0) {
            break;
        }

        if ($k - $arr[$cnt] > 0) {
            $k = $k - $arr[$cnt];
            $total += $arr[$cnt];
            $arr[$cnt] = 0;
        } else {
            $total += $k;
            $arr[$cnt] -= $k;
            $k = 0;
        }

        $cnt++;
    }

    $arr[$end] += $total;
    $res[] = $arr;
}

foreach ($res as $r) {
    foreach ($r as $i) {
        echo $i . ' ';
    }
    echo "\n";
}

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

$solve = function ($n, $k, $a) {
	$i = 0;
	while ($k > 0 && $i < $n - 1){
		$delta = min($k, $a[$i]);
		$a[$i] -= $delta;
		$a[$n-1] += $delta;
		$k -= $delta;
		$i++;
	}
	return $a;
};

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

	list ($n, $k) = explode(' ', fgets(STDIN));
	$a = array_map(function($itm){ return intval($itm); }, explode(' ', trim(fgets(STDIN))));

	$a = $solve($n, $k, $a);
	echo implode(' ', $a);
	echo "\n";

}

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

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

$t = IO::str();
$res = array();
while ($t--) {
    list($n,$k) = IO::arr();
    $arr = IO::arr();
    $cnt = 0;
    $total = 0;
    $end = count($arr) - 1;
    while ($k--) {
        if ($cnt == $end) {
            break;
        }

        if ($arr[$cnt] > 0) {
            $arr[$cnt]--;
            if ($arr[$cnt] == 0) {
                $cnt++;
            }
            $total++;
        } else {
            $cnt++;
        }
    }

    $arr[$end] += $total;
    $res[] = $arr;
}

foreach ($res as $r) {
    foreach ($r as $i) {
        echo $i . ' ';
    }
    echo "\n";
}

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

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

$t = IO::str();
$res = array();
while ($t--) {
    list($n,$k) = IO::arr();
    $arr = IO::arr();
    $cnt = 0;
    $total = 0;
    $end = count($arr) - 1;
    while ($k--) {
        if ($cnt == $end) {
            break;
        }

        if ($arr[$cnt] > 0) {
            $arr[$cnt]--;
            if ($arr[$cnt] == 0) {
                $cnt++;
            }
            $total++;
        }
    }

    $arr[$end] += $total;
    $res[] = $arr;
}

foreach ($res as $r) {
    foreach ($r as $i) {
        echo $i . ' ';
    }
    echo "\n";
}

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

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

$t = IO::str();
$res = array();
while ($t--) {
    list($n,$k) = IO::arr();
    $arr = IO::arr();
    $cnt = 0;
    $total = 0;
    $end = count($arr) - 1;
    while ($k--) {
        if ($cnt == $end) {
            break;
        }

        if ($arr[$cnt] > 0) {
            $arr[$cnt]--;
            $total++;
        } else {
            $cnt++;
        }
    }
    $arr[$end] += $total;
    $res[] = $arr;
}

foreach ($res as $r) {
    foreach ($r as $i) {
        echo $i . ' ';
    }
    echo "\n";
}

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

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

$t = IO::str();
$res = array();
while ($t--) {
    list($n,$k) = IO::arr();
    $arr = IO::arr();
    if ($k < $arr[0]) {
        $s = $k;
    } else {
        $s = $arr[0];
    }

    $arr[0] = $arr[0] - $s;

    $arr[count($arr) - 1] = $arr[count($arr) - 1] + $s;

    $res[] = $arr;
}

foreach ($res as $r) {
    foreach ($r as $i) {
        echo $i . ' ';
    }
    echo "\n";
}

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

$solve = function ($n, $k, $a) {
	$i = 0;
	while ($k > 0 && $i < $n - 1){
		$delta = min($k, $a[$i]);
		$a[$i] -= $delta;
		$a[$n-1] += $delta;
		$k -= $delta;
		$i++;
	}
	return $a;
};

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

	list ($n, $k) = explode(' ', fgets(STDIN));
	$a = array_map(function($itm){ return intval($itm); }, explode(' ', trim(fgets(STDIN))));
	echo implode(' ', $a) . "\n";
	$a = $solve($n, $k, $a);
	echo implode(' ', $a);

	echo "\n";

}


<?php

    $dataSetLength = (int) fgets(STDIN);
    for ($dataSet = 0; $dataSet < $dataSetLength; $dataSet++) {
        fgets(STDIN);
        $numArray = explode(' ', trim(fgets(STDIN)));
        $realNumArray = [];
        $numMap = [0,0,0,0,0,0,0,0,0,0];
        for ($i = 0; $i < count($numArray); $i++) {
            $number = (int) $numArray[$i][-1];
            $numMap[$number]++;
            if ($numMap[$number] <= 3) {
                $realNumArray[] = $number;
            }
            if (array_sum($numMap) >= 30) {
                break;
            }
        }
        if (check3Sum($realNumArray)) {
            echo('YES'.PHP_EOL);
        } else {
            echo('NO'.PHP_EOL);
        }
    }

    function check3Sum($numArray)
    {
        for ($i = 0; $i < count($numArray); $i++) {
            $numMap = [];
            for ($j = $i + 1; $j < count($numArray); $j++) {
                $tempSum = $numArray[$i] + $numArray[$j];
                if ($tempSum <= 3) {
                    if ($numMap[3 - $tempSum]) {
                        return true;
                    }
                } else {
                    if ($numMap[10 - (($tempSum - 3) % 10)]) {
                        return true;
                    }
                }
                $numMap[$numArray[$j]] = true;
            }
        }
        return false;
    }

<?php

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

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

    $cts = [];

    foreach ($ar as $el) {
        if (!isset($cts[$el % 10])) {
            $cts[$el % 10] = 1;
        } else {
            ++$cts[$el % 10];
        }
    }

    $simplified = [];

    foreach ($cts as $item => $count) {
        $count = min($count, 3);

        while ($count--) {
            $simplified[] = $item;
        }
    }

    $y = false;

    for ($i = 0, $iM = count($simplified); $i < $iM; ++$i) {
        for ($j = $i + 1; $j < $iM; ++$j) {
            for ($k = $j + 1; $k < $iM; ++$k) {
                if (($simplified[$i] + $simplified[$j] + $simplified[$k]) % 10 === 3) {
                    fprintf(STDOUT, "%s\n", 'YES');
                    $y = true;
                    break 3;
                }
            }
        }
    }

    if (!$y) {
        fprintf(STDOUT, "%s\n", 'NO');
    }
}
/*

1
3
1 1 1

1
5
1 1 1 3 3

1
3
13 0 0

1
3
5 5 3

 */

<?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;
$temp = [];
for($i=0; $i<10; $i++) {
    for($j=0; $j<10; $j++) {
        for($q=0; $q<10; $q++) {
            if(($i+$j+$q) % 10 == 3) {
                $temp[] = [$i, $j, $q];
            }
        }
    }
}
while($t--) {
//    var_dump($temp[0]);
    solve($temp);
}

function solve($temp)
{
    $n = IO::getInt();
    $a = IO::getArray();
    $ans = 'NO';
    $tt = [];

    for($i=0; $i<$n; $i++) {
        $ss = $a[$i] % 10;
        if(isset($tt[$ss])) {
            $tt[$ss] += 1;
        } else {
            $tt[$ss] = 1;
        }
}
for($i=0; $i < count($temp); $i++) {
     $we = $tt;
     $pp = 0;
     $rr = $temp[$i];
   for($j=0; $j < 3; $j++) {
        if(isset($we[$rr[$j]]) && $we[$rr[$j]] > 0 )  {
             $we[$rr[$j]] -= 1;
             $pp++;
        }

   }
   if($pp == 3) {
        $ans = 'YES';
        break;
   } else {
        $pp = 0;
   }
}
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

    $dataSetLength = (int) fgets(STDIN);
    for ($dataSet = 0; $dataSet < $dataSetLength; $dataSet++) {
        $numArray = explode(' ', trim(fgets(STDIN)));
        $numArray = array_map(function ($number) {
            return $number % 10;
        }, $numArray);
        if (check3Sum($numArray)) {
            echo('YES'.PHP_EOL);
        } else {
            echo('NO'.PHP_EOL);
        }
    }

    function check3Sum($numArray)
    {
        for ($i = 0; $i < count($numArray); $i++) {
            $numMap = [];
            for ($j = $i + 1; $j < count($numArray); $j++) {
                $tempSum = $numArray[$i] + $numArray[$j];
                if ($tempSum <= 3) {
                    if ($numMap[3 - $tempSum]) {
                        return true;
                    }
                } else {
                    if ($numMap[10 - (($tempSum - 3) % 10)]) {
                        return true;
                    }
                }
                $numMap[$numArray[$j]] = true;
            }
        }
        return false;
    }


<?php
fscanf(STDIN, "%d", $t);

$arr = array();
for ($j=0; $j<$t; $j++) {
    array_push($arr, fscanf(STDIN, "%s"));
}

for ($j=0; $j<$t; $j++) {
	if (getSuffix($arr[$j][0], 2) === 'po') {
		echo 'FILIPINO';
	}
	else if (getSuffix($arr[$j][0], 4) === 'desu' || getSuffix($arr[$j][0], 4) === 'masu') {
		echo 'JAPANESE';
	}
	else if (getSuffix($arr[$j][0], 5) === 'mnida') {
		echo 'KOREAN';
	}
	echo "\n";
}

function getSuffix($str, $num) {
	return substr($str, strlen($str)-$num);
}

?>

<?php
function solve()
{
    $server = "php://stdin";
    $local = "input.txt";
    $handle = fopen($server, "r");
    $t= trim(fgets($handle));
    while ($t>0)
    {
       $s=trim(fgets($handle));
       $arr=explode('_',$s);
       $newStr= $arr[sizeof($arr)-1];

       if($newStr[strlen($newStr)-1]=='o')
       {
           echo "FILIPINO";
           echo "\n";
       }else if($newStr[strlen($newStr)-1]=='u')
       {
           echo "JAPANESE";
           echo "\n";
       }else
       {
           echo "KOREAN";
           echo "\n";
       }

        --$t;
    }

}

solve();
?>

<?php

$head_str = readline();

$head_info = explode(' ', $head_str);
$size = $head_info[0];

for($a = 0;$a < $size; $a++){

    $str = trim(readline()).'#';
    if(strpos($str, 'desu#') !== FALSE || strpos($str, 'masu#') !== FALSE){
        print_r('JAPANESE'.PHP_EOL);
    }
    elseif(strpos($str, 'po#') !== FALSE){
        print_r('FILIPINO'.PHP_EOL);
    }
    else{
        print_r('KOREAN'.PHP_EOL);
    }
}
return 0;

?>

<?php

function FirstReverse($str) {

  // code goes here
  $char = substr($str, strlen($str)-3);
  if(ord($char) == 111){
    return 'FILIPINO'."\r\n";
  }elseif (ord($char) == 117) {
    return 'JAPANESE'."\r\n";
  }elseif (ord($char) == 97) {
    return 'KOREAN'."\r\n";
  }
}

// keep this function call here
// $file = fopen('input.txt', 'r');
$file = fopen('php://stdin', 'r');
$num = fgets($file);
for ($i=0; $i < $num; $i++) {
  $str = fgets($file);
  echo FirstReverse($str);
  // return 0;
}
// echo FirstReverse(fgets(fopen('input.txt', 'r')));
// echo FirstReverse(fgets(fopen('php://stdin', 'r')));

?>

<?php

function FirstReverse($str) {

  // code goes here
  $char = substr($str, strlen($str)-3);
  if(ord($char) == 111){
    return 'FILIPINO
';
  }elseif (ord($char) == 117) {
    return 'JAPANESE
';
  }elseif (ord($char) == 97) {
    return 'KOREAN
';
  }
}

// keep this function call here
$file = fopen('php://stdin', 'r');
$num = fgets($file);
for ($i=0; $i < $num; $i++) {
  $str = fgets($file);
  echo FirstReverse($str);
  // return 0;
}
// echo FirstReverse(fgets(fopen('input.txt', 'r')));
// echo FirstReverse(fgets(fopen('php://stdin', 'r')));

?>

<?php
// $dir = fopen("php://stdin", 'r');
// $dir = fopen("input.txt", 'r');
// $str = stream_get_contents($dir);
$length = fgets($dir);
for ($i=0; $i < $length; $i++) {
    // $line = substr(fgets($dir), 1);
    $line  = fgets($dir);
    $str = substr($line, strlen($line)-3);
    if (ord($str) == 111) {
        echo 'FILIPINO';
    }
    elseif (ord($str) == 117) {
        echo 'JAPANESE';
    }elseif (ord($str) == 97) {
        echo 'KOREAN';
    }
}

// echo FirstReverse(fgets(fopen('php://stdin', 'r')));
// echo (fgets(fopen('input.txt', 'r')));
?>

<?php

// function FirstReverse($str) {

//   // code goes here
//   $char = substr($str, strlen($str)-3);
//   if(ord($char) == 111){
//     return 'FILIPINO';
//   }elseif (ord($char) == 117) {
//     return 'JAPANESE';
//   }elseif (ord($char) == 97) {
//     return 'KOREAN';
//   }
// }

// // keep this function call here
// echo FirstReverse(fgets(fopen('input.txt', 'r')));
// echo FirstReverse(fgets(fopen('php://stdin', 'r')));

echo 'FILIPINO';
?>

<?php
$dir = fopen("php://stdin", 'r');
// $dir = fopen("input.txt", 'r');
// $str = stream_get_contents($dir);
$length = fgets($dir);
for ($i=0; $i < $length; $i++) {
    // $line = substr(fgets($dir), 1);
    $line  = fgets($dir);
    $str = substr($line, strlen($line)-3);
    if (ord($str) == 111) {
        echo 'FILIPINO';
    }
    elseif (ord($str) == 117) {
        echo 'JAPANESE';
    }elseif (ord($str) == 97) {
        echo 'KOREAN';
    }
}

// echo FirstReverse(fgets(fopen('php://stdin', 'r')));
// echo (fgets(fopen('input.txt', 'r')));
?>

<?php

$head_str = readline();

$head_info = explode(' ', $head_str);
$size = $head_info[0];

for($a = 0;$a < $size; $a++){

    $str = trim(readline());
    if(strpos($str, 'desu') !== FALSE || strpos($str, 'masu') !== FALSE){
        print_r('JAPANESE'.PHP_EOL);
    }
    elseif(strpos($str, 'po') !== FALSE){
        print_r('FILIPINO'.PHP_EOL);
    }
    else{
        print_r('KOREAN'.PHP_EOL);
    }
}
return 0;

?>

<?php
fscanf(STDIN, "%d", $t);

$arr = array();
for ($j=0; $j<$t; $j++) {
    array_push($arr, fscanf(STDIN, "%s"));
}

for ($j=0; $j<$t; $j++) {
	if (getSuffix($arr[$j][0], 2) === 'po') {
		echo 'PHILIPINO';
	}
	else if (getSuffix($arr[$j][0], 4) === 'desu' || getSuffix($arr[$j][0], 4) === 'masu') {
		echo 'JAPANESE';
	}
	else if (getSuffix($arr[$j][0], 5) === 'mnida') {
		echo 'KOREAN';
	}
	echo "\n";
}

function getSuffix($str, $num) {
	return substr($str, strlen($str)-$num);
}

?>


<?php

$count = (int)readline();

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

	$left = 0;
	$right = pow(2, $n);

	$sideSize = $n / 2;

	$leftSize = $sideSize;
	$rightSize = $sideSize - 1;

	for ($j = 0; $j < $rightSize; $j++) {
		$num = pow(2, $j + 1);

		$right += $num;
	}

	for ($j = $n - 1; $j >= $leftSize; $j--) {
		$num = pow(2, $j);

		$left += $num;
	}

	echo max($left, $right) - min($left, $right);
	echo PHP_EOL;
}

<?php
$input = fopen("php://stdin", 'r');
fscanf($input, "%d", $testsCount);

for ($i = 1; $i <= $testsCount; $i++) {
  fscanf($input, "%d", $coinsCount);
  echo solve($coinsCount) . "\n";
}

function solve(int $coinsCount): int
{
    $firstPileWeight = 0;
    $secondPileWeight = 0;

    $firstPileWeight += pow(2, $coinsCount);
    $secondPileWeight += pow(2, $coinsCount - 1);

    if ($coinsCount > 2) {
        for ($i = 1; $i < $coinsCount / 2; $i++) {
            $firstPileWeight += pow(2, $i);
            $secondPileWeight += pow(2, $coinsCount - 1 - $i);
        }
    }

    return abs($firstPileWeight - $secondPileWeight);
}

<?php
fscanf(STDIN, '%d\n', $inputCount);

for ($i = 1; $i <= $inputCount; $i++) {
  $response = balanceCoins( (int) trim( fgets(STDIN) ) );
  echo $response . "\n";
}

function balanceCoins($power)
{
  $pile1 = [];
  $pile2 = [];

  for (;$power >= 1; $power--) {
    if ($pile1 > $pile2) $pile2[] = pow(2, $power);
    else $pile1[] = pow(2, $power);
  }

  return abs(array_sum($pile1) - array_sum($pile2));
}

<?php

$count = (int)readline();

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

	$left = 0;
	$right = 0;

	for ($j = 0, $k = $n; $j < $n / 2; $j++, $k--) {
		$num1 = pow(2, $j + 1);
		$num2 = pow(2, $k);

		if ($n === 2) {
			$left += $num1;
			$right += $num2;
		} else if ($j % 2 === 0) {
			$left += $num1 + $num2;
		} else {
			$right += $num1 + $num2;
		}
	}

	echo max($left, $right) - min($left, $right);
	echo PHP_EOL;
}


<?php

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

list($n,$x) = explode(" ", rtrim(fgets($in)));
$a = explode(" ", rtrim(fgets($in)));

shuffle($a);
sort($a);
$sumHi = 0;
$sumLo = 0;
for($i=0; $i<$n; $i++){
    $sumLo += $x*$a[$i];
    $sumHi += $resHi;
    if ($sumLo >= 1000000000) {
        $temp = floor($sumLo / 1000000000);
        $sumHi += floor($sumLo / 1000000000);
        $sumLo -= $temp * 1000000000;
    }
    if($x>1)
        $x--;
}

if ($sumHi) {
    echo $sumHi . substr('' .($sumLo + 1000000000), 1);
} else {
    echo $sumLo;
}

<?php
$_fp = fopen("php://stdin", "r");
list($n , $x) = explode(' ', trim(fgets($_fp)));

$c = explode(' ' , trim(fgets($_fp)));

$c_sort = $c;
$c_rsort = $c;

$sum_sort = 0;
$sum_rsort = 0;

$x_sort = $x;
$x_rsort = $x;

sort($c_sort);
rsort($c_rsort);

for ($i = 0; $i < $n; $i++) {
    $sum_sort = bcadd($sum_sort, $x_sort * $c_sort[$i]);
    if ($x_sort > 1) {
        $x_sort--;
    }
}

for ($i = 0; $i < $n; $i++) {
    $sum_rsort = bcadd($sum_rsort, $x_rsort * $c_rsort[$i]);
    if ($x_rsort > 1) {
        $x_rsort--;
    }
}

$result = $sum_sort < $sum_rsort ? $sum_sort : $sum_rsort;

echo (string)$result;

<?php

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

list($n,$x) = explode(" ", rtrim(fgets($in)));
$a = explode(" ", rtrim(fgets($in)));

sort($a);
$sum = 0;
for($i=0; $i<$n; $i++){
    $sum += $x*$a[$i];
    if($x>1)
        $x--;
}

echo $sum;

<?php
$_fp = fopen("php://stdin", "r");
list($n , $x) = explode(' ', trim(fgets($_fp)));

$c = explode(' ' , trim(fgets($_fp)));

$c_sort = $c;
$c_rsort = $c;

$sum_sort = 0;
$sum_rsort = 0;

$x_sort = $x;
$x_rsort = $x;

sort($c_sort);
rsort($c_rsort);

for ($i = 0; $i < $n; $i++) {
    $sum_sort += $x_sort * $c_sort[$i];
    if ($x_sort > 1) {
        $x_sort--;
    }
}

for ($i = 0; $i < $n; $i++) {
    $sum_rsort += $x_rsort * $c_rsort[$i];
    if ($x_rsort > 1) {
        $x_rsort--;
    }
}

$result = $sum_sort < $sum_rsort ? $sum_sort : $sum_rsort;

echo (string)$result;

<?php
$_fp = fopen("php://stdin", "r");
list($n , $x) = explode(' ', trim(fgets($_fp)));

$c = explode(' ' , trim(fgets($_fp)));

$c_sort = $c;
$c_rsort = $c;

$sum_sort = 0;
$sum_rsort = 0;

$x_sort = $x;
$x_rsort = $x;

sort($c_sort);
rsort($c_rsort);

for ($i = 0; $i < $n; $i++) {
    $sum_sort += $x_sort * $c_sort[$i];
    if ($x_sort > 1) {
        $x_sort--;
    }
}

for ($i = 0; $i < $n; $i++) {
    $sum_rsort += $x_rsort * $c_rsort[$i];
    if ($x_rsort > 1) {
        $x_rsort--;
    }
}

echo $sum_sort < $sum_rsort ? $sum_sort : $sum_rsort;


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$a = explode(" ",$a);
$b = explode(" ",$b);
$c = explode(" ",$c);

$gameCost = $b;
$bills = $c;
$currentBillIndex = 0;
$count = 0;

foreach($gameCost as $key => $value){
    if($currentBillIndex >= $a[1]){
        break;
    }
    if($value > $bills[$currentBillIndex]){
        continue;
    }

    $count++;
    $currentBillIndex++;
}
echo "$count";

?>

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

<?php
fscanf(STDIN, "%d %d", $N, $M);
$c = explode(" ", trim(fgets(STDIN)));
$a = explode(" ", trim(fgets(STDIN)));

$ans = 0;
$cursorC = 0;
$cursorA = 0;

while ($cursorC < $N && $cursorA < $M) {
	if ($c[$cursorC] <= $a[$cursorA]) {
		$ans++;
		$cursorC++;
		$cursorA++;
	} else {
		$cursorC++;
	}
}
echo $ans;

<?php
  $data = file('php://stdin');
  $games = explode(' ', $data[1]);
  $money = explode(' ', $data[2]);
  $count = 0;

  foreach ($games as $game) {
    if ((int)$game <= (int)$money[0]) {
      $count++;
      array_shift($money);
    }
  }
  echo $count;
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$a = explode(" ",$a);
$b = explode(" ",$b);
$c = explode(" ",$c);

//$a = [5, 4];
//$b = [2, 4, 5, 2, 4];
//$c = [5, 3, 4, 6];

$gameCost = $b;
$bills = $c;
$currentBillIndex = 0;
$count = 0;

foreach($gameCost as $key => $value){
    if($currentBillIndex >= $a[1]){
        break;
    }
    if($value > $bills[$currentBillIndex]){
        continue;
    }

    $count++;
    $currentBillIndex++;
}
echo "$count";

?>


<?php

//$stream = fopen( 'input.txt', 'r' );
$stream = STDIN;

// Input data
$data = explode( "\n", stream_get_contents( $stream ) );

$n = explode( ' ', trim( $data[0] ) ); $n = $n[0]; // Пассажири
$m = explode( ' ', trim( $data[0] ) ); $m = $m[1]; // Самолеты
$free = explode( ' ', trim( $data[1] ) );

$max = 0;
$min = 0;

// Max
$mx = $free;

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

	$max_free_index = 0;
	$max_free_value = 0;

	foreach ($mx as $k => $f) {

		if( $f == 0 ) continue;

		if( $max_free_value < $f ) {
			$max_free_index = $k;
			$max_free_value = $f;
		}
	}

	$mx[ $max_free_index ]--;

	$max += $max_free_value;
}

// Min
$mn = $free;

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

	$min_free_index = 0;
	$min_free_value = 1000;

	foreach ($mn as $k => $f) {

		if( $f == 0 ) continue;

		if( $min_free_value > $f ) {

			$min_free_index = $k;
			$min_free_value = $f;
		}
	}

	$mn[ $min_free_index ]--;

	$min += $min_free_value;
}

$result = "$max $min";

echo $result;

<?php
list($n,$m)=explode(" ",trim(fgets(STDIN)));
for($i=0;$i<$m;$i++) $s.="%d ";
$a_min=fscanf(STDIN,"$s");
sort($a_min); $a_max=$a_min;
$n_min=$n;$n_max=$n;
$min=0; $max=$m-1;
while($n_min>0)
    if($a_min[$min]>0) {
        --$n_min;
        $out_min+=$a_min[$min];
        --$a_min[$min];
    }
    else $min++;
while($n_max>0) {
    --$n_max;
    rsort($a_max);
    $out_max+=$a_max[0];
    $a_max[0]--;
}
print "$out_max $out_min";

<?php
// Retrieve input
$stdin = fopen('php://stdin', 'r');
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Problem 218B
// Codeforces Contest 134 Div 2 Problem B
$raw = g();
$n = $raw[0];
$m = $raw[1];
$raw = g();
for ($x = 0; $x < $m; $x++) {
	$a[$x] = $raw[$x];
}

$b = merge_sort($a);
$b[-1] = 0;

$max = 0;
for ($x = 0; $x < $n; $x++) {
	for ($y = $m-1; $y >= 0; $y--) {
		if ($b[$y] > $b[$y-1]) {
			$max += $b[$y];
			$b[$y]--;
			break;
		}
	}
}

$b = merge_sort($a);
$b[-1] = 0;
$min = 0;
for ($x = 0; $x < $n; $x++) {
	for ($y = 0; $y < $m; $y++) {
		if ($b[$y] != 0) {
			$min += $b[$y];
			$b[$y]--;
			break;
		}
	}
}

echo $max . " " . $min;

function merge_sort($m) {
    if (count($m) <= 1) {
        return $m;
	}
	$mid = round((count($m) - 1) / 2, 0, PHP_ROUND_HALF_UP);
    for ($x = 0; $x < $mid; $x++) {
		$left[$x] = $m[$x];
	}
    for ($x = 0; $x <= $mid; $x++) {
		if ($mid + $x < count($m)) {$right[$x] = $m[$mid + $x];}
	}
	$left = merge_sort($left);
	$right = merge_sort($right);

	$l = 0;
	$r = 0;
	for ($x = 0; $x < count($m); $x++) {
		if (($l < count($left)) && ($r < count($right))) {
			if ($left[$l] <= $right[$r]) {
				$res[$x] = $left[$l];
				$l++;
			} else {
				$res[$x] = $right[$r];
				$r++;
			}
		} else if ($l >= count($left)) {
			$res[$x] = $right[$r];
			$r++;
		} else {
			$res[$x] = $left[$l];
			$l++;
		}
	}

	return $res;
}

// End of submission file
// Submission by chaotic_iak
?>

<?
list($n,$m)=explode(" ",trim(fgets(STDIN)));
//$a_min=explode(" ",fgets(STDIN));
for($i=0;$i<$m;$i++) $s.="%d ";
$a_min=fscanf(STDIN,"$s");
sort($a_min); $a_max=$a_min; //rsort($a_max);
$n_min=$n;$n_max=$n;
$min=0; $max=$m-1;
while($n_min>0 or $n_max>0){
    if($a_min[$min]>0) {--$n_min; $out_min+=$a_min[$min]; --$a_min[$min]; }
        else $min++;
    if($a_max[$max]>0 && !($a_max[$max]<$a_max[$max-1])) {--$n_max; $out_max+=$a_max[$max]; --$a_max[$max]; }
        else $max--;

}
print "$out_max $out_min";

<?
list($n,$m)=explode(" ",trim(fgets(STDIN)));
//$a_min=explode(" ",fgets(STDIN));
for($i=0;$i<$m;$i++) $s.="%d ";
$a_min=fscanf(STDIN,"$s");
sort($a_min); $a_max=$a_min; //rsort($a_max);
$n_min=$n;$n_max=$n;
$min=0; $max=$m-1;
while($n_min>0) if($a_min[$min]>0) {--$n_min; $out_min+=$a_min[$min]; --$a_min[$min]; }
                                    else $min++;
while($n_max>0) if($a_max[$max]>0 && !($a_max[$max]<$a_max[$max-1])) {--$n_max; $out_max+=$a_max[$max]; --$a_max[$max]; }
                                    elseif ($a_max[$max]==0 && !($a_max[$max-1])) $max++;
                                    else $max--;

print "$out_max $out_min";


<?php
function solve() {
    $n = intval(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $a = preg_split("/[\s,]+/", $s);
    rsort($a);
    $iCountAlice = 0; $iCountBob = 0;
    for ($i = 0; $i < $n; $i++) {
        if ($i % 2 == 0 && $a[$i] % 2 == 0) {
            $iCountAlice += $a[$i];
        }
        if ($i % 2 == 1 && $a[$i] % 2 == 1) {
            $iCountBob += $a[$i];
        }
    }
    if ($iCountAlice == $iCountBob) {
        echo 'Tie';
    } elseif ($iCountAlice > $iCountBob) {
        echo 'Alice';
    } else {
        echo 'Bob';
    }
}

$t = trim(fgets(STDIN));
while ($t--) {
    solve();
    echo "\n";
}
?>

<?php

$times = (int)trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    $ni[] = (int)trim(fgets(STDIN));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $a = &$ai[$idx];
    rsort($a);
    $sma = 0;
    $smb = 0;
    for ($i = 0; $i < $n; ++$i) {
        $i % 2 == 0 && $a[$i] % 2 == 0 && $sma += $a[$i];
        $i % 2 == 1 && $a[$i] % 2 == 1 && $smb += $a[$i];
    }
    $sma -= $smb;
    $result = ['Bob', 'Tie', 'Alice'];
    echo $result[($sma > 0) + ($sma >= 0)] . PHP_EOL;
}

<?php
function _end()
{
	$end = readline();
	die();
}
function startPlay($arr)
{
	rsort($arr);
	$A = 0;
	$B = 0;
	foreach($arr as $key => $value)
	{
		if($key % 2 == 0)
		{
			if($value % 2 == 0)
				$A += $value;
		}
		else
		{
			if($value % 2 != 0)
				$B += $value;
		}
	}

	if($A == $B)
		$res = "Tie";
	elseif($A > $B)
		$res = "Alice";
	else
		$res = "Bob";
	return $res;
}

$t = fgets(STDIN);
for($i=0;$i<$t;$i++)
{
	$arr = array();
	$n = fgets(STDIN);
	$arr_str = fgets(STDIN);
	$arr = explode(" ", trim($arr_str));
	print(startPlay($arr)."\r\n");
}
$end = fgets(STDIN);
?>


<?php
fscanf(STDIN, "%d", $number);
$result = array();
for ($i = 0; $i < $number; $i++){
    fscanf(STDIN, "%d %d", $x, $y);
    if (abs($x - $y) <= 1)
        array_push($result, $x + $y);
    else
        array_push($result, max($x, $y) * 2 - 1);
}

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


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

$arr = $arr = explode(' ',trim(fgets(STDIN)));
sort($arr,SORT_NUMERIC);

$sum = 0 ;
//print_r($arr);
for($i=0;$i<$n/2;$i++){
	//echo $arr[$i]." ".$arr[$n-$i-1]."\n";
	$sum += ($arr[$i]+$arr[$n-$i-1])*($arr[$i]+$arr[$n-$i-1]);
}

echo $sum;


<?php

$t = trim(fgets(STDIN));

$ans = '';

for ($i = 0; $i < $t; $i++) {
	$n = trim(fgets(STDIN));
	$a = explode(" ", trim(fgets(STDIN)));
	$b = explode(" ", trim(fgets(STDIN)));
	$is_diff = 0;
	$diff = 0;
	$diff0 = 0;
	$ok = 1;
	for ($j = 0; $j < $n; $j++) {
		if ($a[$j] != $b[$j])
		{
			if ($is_diff == 2)
			{
				$ok = 0;
				$ans .= "NO\n";
				break;
			}
			if ($is_diff == 0) {
				$is_diff = 1;
				$diff = $a[$j] - $b[$j];
			}
			if ($diff > 0)
			{
				$ok = 0;
				$ans .= "NO\n";
				break;
			}
			if ($a[$j] - $b[$j] != $diff) {
				$ok = 0;
				$ans .= "NO\n";
				break;
			}
		} else {
			if ($is_diff == 1)
				$is_diff = 2;
		}
	}
	if ($ok == 1)
		$ans .= "YES\n";
}

echo $ans;
?>

<?php
function solve()
{
    $server = "php://stdin";
    $local = "input.txt";
    $handle = fopen($server, "r");
    $x = trim(fgets($handle));
    for ($j = 0; $j < $x; $j++) {
        $n=trim(fgets($handle));
        $qx = trim(fgets($handle));
        $arr1 = explode(' ', $qx);
        $qb = trim(fgets($handle));
        $arr2= explode(' ', $qb);
        $l=0;$r=$n-1;
        for ($i=0;$i<$n;$i++)
        {
            if($arr1[$i]!=$arr2[$i])
            {
                $r=$i;
            }
        }
        for ($i=$n-1;$i>=0;$i--)
        {
            if($arr1[$i]!=$arr2[$i])
            {
                $l=$i;
            }
        }
        $ans=1;
        $count=$arr2[$l]-$arr1[$l];
        if($count>=0)
            for ($i=$l;$i<$r+1;$i++)
            {
                if($arr2[$i]-$arr1[$i]!=$count)
                {
                    $ans=0;
                    break;
                }
            }
        else
        {
            $ans=0;
        }

        if($ans)
        {
            echo "YES\n";
        }else
        {
            echo "NO\n";
        }
    }
}

solve();
?>

<?php
function solve()
{
    $server = "php://stdin";
    $local = "input.txt";
    $handle = fopen($server, "r");
    $x = trim(fgets($handle));
    for ($j = 0; $j < $x; $j++) {
        $n=trim(fgets($handle));
        $qx = trim(fgets($handle));
        $arr1 = explode(' ', $qx);
        $qb = trim(fgets($handle));
        $arr2= explode(' ', $qb);
        $flage=false;$count=0;
        $ans=1;
        for ($i=0;$i<$n;$i++)
        {
            if($arr1[$i]!=$arr2[$i] && $flage!=true)
            {
                $flage=true;
                $count=$arr2[$i]-$arr1[$i];
                if($count<0)
                {
                    $ans=0;
                    break;
                }
            }
            if($flage==true && $arr1[$i]!=$arr2[$i])
            {
                if($count!=$arr2[$i]-$arr1[$i] || ($arr2[$i]-$arr1[$i])<0) {
                    $ans=0;
                    break;
                }
            }
        }
        if($ans)
        {
            echo "YES\n";
        }else
        {
            echo "NO\n";
        }

    }
}

solve();
?>

<?php

$t = trim(fgets(STDIN));

$ans = '';

for ($i = 0; $i < $t; $i++) {
	$n = trim(fgets(STDIN));
	$a = explode(" ", trim(fgets(STDIN)));
	$b = explode(" ", trim(fgets(STDIN)));
	$is_diff = 0;
	$diff = 0;
	$ok = 1;
	for ($j = 0; $j < $n; $j++) {
		if ($a[$j] != $b[$j])
		{
			if ($is_diff == 2)
			{
				$ok = 0;
				$ans .= "NO\n";
				break;
			}
			$is_diff = 1;
			$diff = $a[$j] - $b[$j];
			if ($diff > 0)
			{
				$ok = 0;
				$ans .= "NO\n";
				break;
			}
			if ($a[$j] - $b[$j] != $diff) {
				$ok = 0;
				$ans .= "NO\n";
				break;
			}
		} else {
			if ($is_diff == 1)
				$is_diff = 2;
		}
	}
	if ($ok == 1)
		$ans .= "YES\n";
}

echo $ans;
?>


<?php
$n = trim(fgets(STDIN));
$fMin = -1;
$fMax = -1;
for($i = 0; $i < $n; $i++) {
    list($a, $b) = explode(' ', trim(fgets(STDIN)));
    if($fMax == -1 || $fMax < $a) {
        $fMax = $a;
    }
    if($fMin == -1 || $fMin > $b) {
        $fMin = $b;
    }
}
$m = trim(fgets(STDIN));
$sMin = -1;
$sMax = -1;
for($i = 0; $i < $m; $i++) {
    list($a, $b) = explode(' ', trim(fgets(STDIN)));
    if($sMax == -1 || $sMax < $a) {
        $sMax = $a;
    }
    if($sMin == -1 || $sMin > $b) {
        $sMin = $b;
    }
}
$r = 0;
if($fMin < $sMax) {
    $r = max($r, $sMax - $fMin);
}
if($sMin < $fMax) {
    $r = max($r, $fMax - $sMin);
}
echo $r;

<?php
$n = trim(fgets(STDIN));
$fMin = -1;
$fMax = -1;
for($i = 0; $i < $n; $i++) {
    list($a, $b) = explode(' ', trim(fgets(STDIN)));
    if($fMax == -1 || $fMax < $a) {
        $fMax = $a;
    }
    if($fMin == -1 || $fMin > $b) {
        $fMin = $b;
    }
}
$m = trim(fgets(STDIN));
$sMin = -1;
$sMax = -1;
for($i = 0; $i < $m; $i++) {
    list($a, $b) = explode(' ', trim(fgets(STDIN)));
    if($sMax == -1 || $sMax < $a) {
        $sMax = $a;
    }
    if($sMin == -1 || $sMin > $b) {
        $sMin = $b;
    }
}
//echo $fMin, $sMax, $sMin, $fMax;
if($fMin < $sMax) {
    echo $sMax - $fMin;
}
else if($sMin < $fMax) {
    echo $fMax - $sMin;
}
else {
    echo 0;
}


<?php
list($n,$b) = explode(' ', trim(fgets(STDIN)));
$aChests = explode(' ', trim(fgets(STDIN)));
$aKeys = explode(' ', trim(fgets(STDIN)));

$iEven = $iOdd = 0; $jEven = $jOdd = 0; $iTotal = 0;
foreach ($aKeys as $sK => $sV){
    $sV % 2 === 1 ? $iEven++ : $iOdd++;
}

foreach ($aChests as $sK => $sVal){
    $sVal % 2 === 1 ? $jEven++ : $jOdd++;
}

if($jOdd >= $iEven){
    $iTotal += $iEven;
} else {
    $iTotal += $jOdd;
}

if($jEven >= $iOdd){
    $iTotal += $iOdd;
} else {
    $iTotal += $jEven;
}
echo $iTotal;

<?php
# 1152A

$input = fopen('php://stdin', 'rb');
[$chestsCount, $keysCount] = fscanf($input, '%u %u' . "\n");
$chestsOddCount = $chestsEvenCount = 0;
$chests = explode(' ', trim(fgets($input)));
foreach ($chests as $chest) {
    if ($chest % 2 === 0) {
        $chestsEvenCount++;
    } else {
        $chestsOddCount++;
    }
}
unset($chests);
$keysOddCount = $keysEvenCount = 0;
$keys = explode(' ', trim(fgets($input)));
foreach ($keys as $key) {
    if ($key % 2 === 0) {
        $keysEvenCount++;
    } else {
        $keysOddCount++;
    }
}
unset($keys);
echo min($chestsEvenCount, $keysOddCount) + min($chestsOddCount, $keysEvenCount);

<?php
# 1152A

fgets(STDIN);
$coc = $cec = 0;
$_cs = explode(' ', fgets(STDIN));
foreach ($_cs as $_c) {if ((int)$_c % 2 === 0) {$cec++;} else {$coc++;}}
unset($_cs);
$koc = $kec = 0;
$_ks = explode(' ', fgets(STDIN));
foreach ($_ks as $_k) {if ((int)$_k % 2 === 0) {$kec++;} else {$koc++;}}
unset($_ks);
echo min($cec, $koc) + min($coc, $kec);

<?php
  $n = explode(" ", trim(fgets(STDIN)));
  $m = explode(" ", trim(fgets(STDIN)));
  $z = explode(" ", trim(fgets(STDIN)));
  $jup = 0;
  $tak = 0;
  $summ = 0;
 foreach($m as $sK => $sV) {
     if($sV % 2 == 0) {
         $jup++;
     }
 }
 foreach($z as $sK1 => $sV1) {
     if($sV1 % 2 !== 0){
         $tak++;
     }
 }
 $a = $n[0] - $jup;
 $b = $n[1] - $tak;
 if($a == 0 && $tak == 0) { echo '0'; exit;}
 if($b == 0 && $jup == 0) { echo '0'; exit;}
 if($jup > $tak){
     $summ += $tak;
     if($a > $b) {
         $summ += $b;
     } else {
         $summ += $a;
     }
 } else {
     $summ += $jup;
     if($a > $b) {
         $summ += $b;
     } else {
         $summ += $a;
     }
 }
  echo $summ;

?>

<?php
  $n = explode(" ", trim(fgets(STDIN)));
  $m = explode(" ", trim(fgets(STDIN)));
  $z = explode(" ", trim(fgets(STDIN)));
  $jup = 0;
  $tak = 0;
  $summ = 0;
 foreach($m as $sK => $sV) {
     if($sV % 2 == 0) {
         $jup++;
     }
 }
 foreach($z as $sK1 => $sV1) {
     if($sV1 % 2 !== 0){
         $tak++;
     }
 }
 $a = $n[0] - $jup;
 $b = $n[1] - $tak;
 if($ja == 0 || $tak == 0) { echo '0'; exit;}
 if($jb == 0 || $jup == 0) { echo '0'; exit;}
 if($jup > $tak){
     $summ += $tak;
     if($a > $b) {
         $summ += $b;
     } else {
         $summ += $a;
     }
 } else {
     $summ += $jup;
     if($a > $b) {
         $summ += $b;
     } else {
         $summ += $a;
     }
 }
  echo $summ;

?>

<?php
  $n = explode(" ", trim(fgets(STDIN)));
  $m = explode(" ", trim(fgets(STDIN)));
  $z = explode(" ", trim(fgets(STDIN)));
  $jup = 0;
  $tak = 0;
  $summ = 0;
 foreach($m as $sK => $sV) {
     if($sV % 2 == 0){
         $jup++;
     }
 }
 foreach($z as $sK1 => $sV1) {
     if($sV1 % 2 !== 0){
         $tak++;
     }
 }
 $a = $n[0] - $jup;
 $b = $n[1] - $tak;
 if($jup == 0 || $tak == 0) { echo '0'; exit;}
 if($jup > $tak){
     $summ += $tak;
     if($a > $b) {
         $summ += $b;
     } else {
         $summ += $a;
     }
 } else {
     $summ += $jup;
     if($a > $b) {
         $summ += $b;
     } else {
         $summ += $a;
     }
 }
  echo $summ;

?>

<?php
  $n = explode(" ", trim(fgets(STDIN)));
  $m = explode(" ", trim(fgets(STDIN)));
  $z = explode(" ", trim(fgets(STDIN)));
  $jup = 0;
  $tak = 0;
  $summ = 0;
 foreach($m as $sK => $sV) {
     if($sV % 2 == 0) {
         $jup++;
     }
 }
 foreach($z as $sK1 => $sV1) {
     if($sV1 % 2 !== 0){
         $tak++;
     }
 }
 $a = $n[0] - $jup;
 $b = $n[1] - $tak;
 if($a == 0 || $tak == 0) { echo '0'; exit;}
 if($b == 0 || $jup == 0) { echo '0'; exit;}
 if($jup > $tak){
     $summ += $tak;
     if($a > $b) {
         $summ += $b;
     } else {
         $summ += $a;
     }
 } else {
     $summ += $jup;
     if($a > $b) {
         $summ += $b;
     } else {
         $summ += $a;
     }
 }
  echo $summ;

?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = 1000000;
for($x = 0; $x < $a; $x++)
{
     list($d, $e) = explode(" ", trim(fgets(STDIN)));
     $e = $d / $e * $b;
     $c = min($c, $e);
}
print number_format($c, 8, '.', '');
?>

<?php

// ჰაიტ.

// აგამემნონი  :3

// მენელაოსის ძმა. ბერძენთა წინამძღოლი ტროას ომში.  ელენას მაზლი :3
// ნუ.. ფილმში ძაან ჩათლახადაა გამოყვანილი ((:

$agamemnoni = 1234321;

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

for($i=0;$i<$a;$i++){
    list($x,$y) = explode(" ",trim(fgets(STDIN)));
    $agamemnoni = min($agamemnoni, $x/$y);
}

$agamemnoni*=$b;

echo $agamemnoni;

?>

<?php

fscanf(STDIN, "%d %d\n", $n, $m);
$best_price = 5000 * 100 + 1.0;
while($n--){
  fscanf(STDIN, "%d %d\n", $a, $b);
  $best_price = min($best_price, ($a/$b));
}
echo ($best_price * $m);


<?php

$t = intval(readline());

for ($i = 0; $i < $t; $i++) {
    $n = intval(readline());
    $isOdd = $n % 2 === 1;
    $middle = ($n + 1) / 2;
    for ($j = $n; $j >= 1; $j--) {
        if ($isOdd && $j === 1) {
            echo "$middle ";
        } elseif ($isOdd && $j === $middle) {
            echo "1 ";
        } else {
            echo "$j ";
        }
    }
    echo "\n";
}

<?php
/**
 * Created by PhpStorm.
 * User: ordec
 * Date: 24/11/20
 * Time: 20:39
 */

$n = readline();
$res = array();
$cnt = 0;
for ($i = 0; $i < $n; $i++) {

    $num = readline();
    for ($j = 2; $j <= $num; $j++) {
        $res[$cnt][$j] = $j;
    }
//    $res[$cnt][$num] = "\n";
    $res[$cnt][1] = 1;
    $cnt++;
}

foreach ($res as $items) {
//    print_r($items);
    foreach ($items as $item){
        echo $item . ' ';
    }
    echo "\n";
}

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

while ($t--) {
    $n = trim(fgets(STDIN));
    $res = '';
    for ($i = 2; $i <= $n; $i++) {
        $res.= $i.' ';
    }

    echo $res."1\n";
}

<?php
fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
    $p = range(1, intval(fgets(STDIN)));
    $p[] = array_shift($p);
    printf("%s \n", implode(' ', $p));
}

<?php
/**
 * Created by PhpStorm.
 * User: ordec
 * Date: 24/11/20
 * Time: 20:39
 */

$n = readline();
$res = array();
$cnt = 0;
for ($i = 0; $i < $n; $i++) {

    $num = readline();
    for ($j = 2; $j <= $num; $j++) {
        $res[$cnt][$j] = $j;
    }
    $res[$num] = "\n";
    $res[$cnt][1] = 1;
    $cnt++;
}

foreach ($res as $items) {
    foreach ($items as $item){
        echo $item . ' ';
    }
}

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

while ($t--) {
    $n = trim(fgets(STDIN));
    $res = '';
    for ($i = $n; $i > 0; $i--) {
        $res.=$i.' ';
    }
    echo trim($res)."\n";
}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	fscanf(STDIN,"%d",$n);
	for ($i=$n; $i>=1 ; $i--)
	 {
	 	if($i==1)
		echo "$i"."\n";
	    else
	    	echo "$i ";
	 }
}

<?php

$t = intval(readline());

for ($i = 0; $i < $t; $i++) {
    $n = intval(readline());
    $isOdd = $n % 2 === 1;
    $middle = ($n + 1) / 2;
    for ($j = $n; $j >= 1; $j--) {
        if ($isOdd && $j === $n) {
            echo "$middle ";
        } elseif ($isOdd && $j === $middle) {
            echo "1 ";
        } else {
            echo "$j ";
        }
    }
    echo "\n";
}