<?php

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

function readInt() {
  return (int) read() ;
}

function readStrs() {
  return explode(" ",read()) ;
}

function readIntArray() {
  return array_map('intval', readStrs());
}

function readAsArray() {
  return str_split(read()) ;
}

function printLine($arg) {
  if($arg === false) {
    print_r("false") ;
  }
  elseif($arg === true) {
    print_r("true") ;
  }
  else {
    print_r($arg) ;
  }
  print_r("\n") ;
}

$t = readInt() ;

while($t--) {

	[$n,$x] = readIntArray() ;

	$arr = readIntArray() ;

	sort($arr) ;

	$mark = true ;

	for ($i=0; $i <$n ; $i++) {
		if(($arr[$i] + $x) > $arr[$i+$n]) {
			$mark = false ;
			break ;
		}
	}
	if($mark) printLine("YES") ;
	else printLine("NO") ;

}

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
//101
//101
//001
function solve()
{
    list($n, $x) = IO::getArray();
    $a = IO::getArray();
    sort($a);
    $ans = 'YES';
//    var_dump($a);
     for($i=0; $i<$n; $i++) {
          if($a[$i + $n] - $a[$i] < $x) {
               $ans = 'NO';
          }
     }
    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
fscanf(STDIN, "%s", $S);
$cnt1 = substr_count($S, "1");
$S = str_replace("1", "", $S);
// echo $S . PHP_EOL;
preg_match("/(^0*)/", $S, $reg);
$first0 = strlen($reg[1]);
$ans = str_repeat("0", $first0) . str_repeat("1", $cnt1) . substr($S, $first0);
echo $ans;

<?php

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

//$a = "11222121";

$input = $a;
$input = str_split($input);

$numOf1 = 0;
$stop = false;
$stopIndex = 0;

foreach($input as $key => $value){
    if($value == 1){
        $numOf1++;
    }
    if($value == 2 && !$stop){
        $stop = true;
        $stopIndex = $key;
    }
    if(!$stop && $value == 0){
        echo '0';
    }
}
for($i = 0; $i < $numOf1; $i++){
    echo '1';
}

if($stop){
	for($i = $stopIndex; $i < sizeof($input); $i++){
		if($input[$i] != 1){
			echo "$input[$i]";
		}
	}
}

<?php

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

//$a = "11222121";

$input = $a;
$input = str_split($input);

$numOf1 = 0;
$stop = false;
$stopIndex = 0;

foreach($input as $key => $value){
    if($value == 1){
        $numOf1++;
    }
    if($value == 2 && !$stop){
        $stop = true;
        $stopIndex = $key;
    }
    if(!$stop && $value == 0){
        echo '0';
    }
}
for($i = 0; $i < $numOf1; $i++){
    echo '1';
}

for($i = $stopIndex; $i < sizeof($input); $i++){
    if($input[$i] != 1){
        echo "$input[$i]";
    }
}

<?php

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

//$a = "11222121";

$input = $a;
$input = str_split($input);

$end = false;
$forCount = 0;
$canSwapAny = true;

while($canSwapAny){
	$canSwapAny = false;
	$swapPosition = array();
    for($i = 0; $i < sizeof($input); $i++){
		$forCount++;
		$value = $input[$i];
		if(($i+1) < sizeof($input) && $value > $input[($i+1)]){
            $canSwapThisTime = canSwap($value, $input[($i+1)]);
            if($canSwapThisTime){
				//echo "can swap at position $i <br>";
				array_push($swapPosition, $i);
				$canSwapAny = true;
			}
        }
    }
	foreach($swapPosition as $value){
		swap($input, $value, $value+1);
	}
}

$input = implode("", $input);
echo "$input";

function swap(&$a, $position1, $position2){
    $temp = $a[$position1];
    $a[$position1] = $a[$position2];
    $a[$position2] = $temp;
}

function canSwap($item1, $item2){
    $diff = abs($item2 - $item1);
    if($diff == 1){
        return true;
    }
    return false;
}

<?php

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

//$a = "11222121";

$input = $a;
$input = str_split($input);

$end = false;
$forCount = 0;
$canSwapAny = true;

while($canSwapAny){
	$canSwapAny = false;
	$swapPosition = array();
    for($i = 0; $i < sizeof($input); $i++){
		$forCount++;
		$value = $input[$i];
		if(($i+1) < sizeof($input) && $value > $input[($i+1)]){
            $canSwapThisTime = canSwap($value, $input[($i+1)]);
            if($canSwapThisTime){
				//echo "can swap at position $i <br>";
				array_push($swapPosition, $i);
				$canSwapAny = true;
				$i++;
			}
        }
    }
	foreach($swapPosition as $value){
		swap($input, $value, $value+1);
	}
}

$input = implode("", $input);
echo "$input";

function swap(&$a, $position1, $position2){
    $temp = $a[$position1];
    $a[$position1] = $a[$position2];
    $a[$position2] = $temp;
}

function canSwap($item1, $item2){
    $diff = abs($item2 - $item1);
    if($diff == 1){
        return true;
    }
    return false;
}

<?php

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

//$a = "100210";

$input = $a;
$input = str_split($input);

$numOf1 = 0;
$stop = false;
$stopIndex = 0;

foreach($input as $key => $value){
    if($value == 1){
        $numOf1++;
    }
    if($value == 2){
        $stop = true;
        $stopIndex = $key;
    }
    if(!$stop && $value == 0){
        echo '0';
    }
}
for($i = 0; $i < $numOf1; $i++){
    echo '1';
}

for($i = $stopIndex; $i < sizeof($input); $i++){
    if($input[$i] != 1){
        echo "$input[$i]";
    }
}


<?php
$a = trim(fgets(STDIN));
$c = 0;
$d = array();
$g = array();
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    if($b == "0")
    {
        if($c == "0")
        {
            if($x != $a)
            {
                print "0" . "\n";
            }
            else
            {
                print "0";
            }
        }
        else
        {
            if($x != $a)
            {
                $c = 0;
                if(count($d) == "1")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    array_push($f, "1 popStack" . "\n");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
                elseif(count($d) == "2")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    array_push($f, "2 popStack popQueue" . "\n");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
                elseif(count($d) >= "3")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    $f[$e[2]] = "pushFront" . "\n";
                    array_push($f, "3 popStack popQueue popFront" . "\n");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
            }
            else
            {
                $c = 0;
                if(count($d) == "1")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    array_push($f, "1 popStack");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
                elseif(count($d) == "2")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    array_push($f, "2 popStack popQueue");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
                elseif(count($d) >= "3")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    $f[$e[2]] = "pushFront" . "\n";
                    array_push($f, "3 popStack popQueue popFront");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
            }
            $d = array();
            $f = array();
            $g = array();
        }
    }
    else
    {
        if($x != $a)
        {
            $d[$c] = $b;
            $c++;
        }
        else
        {
            array_push($d, $b);
            $f = array_fill(0, count($d), "pushBack" . "\n");
            $g = array_merge($g, $f);
            $h = substr(implode("", $g), 0, -1);
            print $h;
        }
    }
}
?>

<?
$f = file('php://stdin',FILE_IGNORE_NEW_LINES);
define('L',PHP_EOL);
//-----------------------

$x = $f[0];

$a = array();

$_in = array('pushQueue','pushStack','pushFront');
$_out = array(' popQueue',' popStack',' popFront');

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

		$b = $a;
		arsort($b);

		$b = array_keys(array_slice($b,0,3,true));

		$j = 0;

		foreach ($a as $k=>$kiss) {
			if ($j<3 && in_array($k,$b)) {
				$str .= $_in[$j++];
			} else {
				$str .= 'pushBack';
			}
			$str .= L;
		}

		$str .= $j;

		for ($c=0;$c<$j;$c++) {
			$str .= $_out[$c];
		}

		$str .= L;

		$a = array();

	} else {
		$a[] = $f[$i];
	}
}

for ($i=0;$i<sizeof($a);$i++) {
	$str .= 'pushQueue'.L;
}

echo $str;

<?php
print "0" . "\n";
print "pushFront" . "\n";
print "1 popFront" . "\n";
print "pushFront " . "\n";
print "pushQueue" . "\n";
print "2 popFront popQueue" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "pushFront" . "\n";
print "3 popStack popQueue popFront";
?>

<?php
$a = trim(fgets(STDIN));
$c = 0;
$d = array();
$g = array();
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    if($b == "0")
    {
        if($c == "0")
        {
            $g[0] = "0";
        }
        else
        {
            $c = 0;
            if(count($d) == "1")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                array_push($f, "1 popStack");
                $g = array_merge($g, $f);
            }
            elseif(count($d) == "2")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                $f[$e[1]] = "pushQueue";
                array_push($f, "2 popStack popQueue");
                $g = array_merge($g, $f);
            }
            elseif(count($d) >= "3")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                $f[$e[1]] = "pushQueue";
                $f[$e[2]] = "pushFront";
                array_push($f, "3 popStack popQueue popFront");
                $g = array_merge($g, $f);
            }
            $d = array();
            $f = array();
        }
    }
    else
    {
        if($x != $a)
        {
            $d[$c] = $b;
            $c++;
        }
        else
        {
            array_push($d, $b);
            $f = array_fill(0, count($d), "pushBack");
            $g = array_merge($g, $f);
        }
    }
}
for($x = 0; $x < $a - 1; $x++)
{
    print $g[$x] . "\n";
}
print $g[$x];
?>

<?php
print "0" . "\n";
print "pushStack" . "\n";
print "1 popStack" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "2 popStack popQueue" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "pushFront" . "\n";
print "3 popStack popQueue popFront";
?>

<?php
$a = trim(fgets(STDIN));
$c = 0;
$d = array();
$g = array();
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    if($b == "0")
    {
        if($c == "0")
        {
            if($x != $a)
            {
                print "0" . "\n";
            }
            else
            {
                print "0";
            }
        }
        else
        {
            if($x != $a)
            {
                $c = 0;
                if(count($d) == "1")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    array_push($f, "1 popStack" . "\n");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
                elseif(count($d) == "2")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    array_push($f, "2 popStack popQueue" . "\n");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
                elseif(count($d) >= "3")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    $f[$e[2]] = "pushFront" . "\n";
                    array_push($f, "3 popStack popQueue popFront" . "\n");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
            }
            else
            {
                $c = 0;
                if(count($d) == "1")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    array_push($f, "1 popStack" . "\n");
                    $g = array_merge($g, $f);
                    $h = substr(implode("", $g), 0, -1);
                    print $h;
                }
                elseif(count($d) == "2")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    array_push($f, "2 popStack popQueue" . "\n");
                    $g = array_merge($g, $f);
                    $h = substr(implode("", $g), 0, -1);
                    print $h;
                }
                elseif(count($d) >= "3")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    $f[$e[2]] = "pushFront" . "\n";
                    array_push($f, "3 popStack popQueue popFront" . "\n");
                    $g = array_merge($g, $f);
                    $h = substr(implode("", $g), 0, -1);
                    print $h;
                }
            }
            $d = array();
            $f = array();
            $g = array();
        }
    }
    else
    {
        if($x != $a)
        {
            $d[$c] = $b;
            $c++;
        }
        else
        {
            array_push($d, $b);
            $f = array_fill(0, count($d), "pushBack");
            $g = array_merge($g, $f);
            $h = implode("", $g);
            print $h;
        }
    }
}
?>

<?php
print "0" . "\n";
print "pushStack" . "\n";
print "1 popStack" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "2 popStack popQueue" . "\n";
print "pushStack" . "\n";
print "pushStack" . "\n";
print "pushStack" . "\n";
print "3 popStack popStack popStack";
?>

<?php
$a = trim(fgets(STDIN));
$c = 0;
$d = array();
$g = array();
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    if($b == "0")
    {
        if($c == "0")
        {
            array_push($g, "0");
        }
        else
        {
            $c = 0;
            if(count($d) == "1")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                array_push($f, "1 popStack");
                $g = array_merge($g, $f);
            }
            elseif(count($d) == "2")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                $f[$e[1]] = "pushQueue";
                array_push($f, "2 popStack popQueue");
                $g = array_merge($g, $f);
            }
            elseif(count($d) >= "3")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                $f[$e[1]] = "pushQueue";
                $f[$e[2]] = "pushFront";
                array_push($f, "3 popStack popQueue popFront");
                $g = array_merge($g, $f);
            }
            $d = array();
            $f = array();
        }
    }
    else
    {
        array_push($d, $b);
        $c++;
    }
}
for($x = 0; $x < $a - 1; $x++)
{
    print $g[$x] . "\n";
}
print $g[$x];
?>

<?php
$a = trim(fgets(STDIN));
$c = 0;
$d = array();
$g = array();
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    if($b == "0")
    {
        if($c == "0")
        {
            if($x != $a)
            {
                print "0" . "\n";
            }
            else
            {
                print "0";
            }
        }
        else
        {
            if($x != $a)
            {
                $c = 0;
                if(count($d) == "1")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    array_push($f, "1 popStack" . "\n");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
                elseif(count($d) == "2")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    array_push($f, "2 popStack popQueue" . "\n");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
                elseif(count($d) >= "3")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    $f[$e[2]] = "pushFront" . "\n";
                    array_push($f, "3 popStack popQueue popFront" . "\n");
                    $g = array_merge($g, $f);
                    $h = implode("", $g);
                    print $h;
                }
            }
            else
            {
                $c = 0;
                if(count($d) == "1")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    array_push($f, "1 popStack" . "\n");
                    $g = array_merge($g, $f);
                    $h = substr(implode("", $g), 0, -3);
                    print $h;
                }
                elseif(count($d) == "2")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    array_push($f, "2 popStack popQueue" . "\n");
                    $g = array_merge($g, $f);
                    $h = substr(implode("", $g), 0, -3);
                    print $h;
                }
                elseif(count($d) >= "3")
                {
                    arsort($d);
                    $e = array_keys($d);
                    $f = array_fill(0, count($d), "pushBack" . "\n");
                    $f[$e[0]] = "pushStack" . "\n";
                    $f[$e[1]] = "pushQueue" . "\n";
                    $f[$e[2]] = "pushFront" . "\n";
                    array_push($f, "3 popStack popQueue popFront" . "\n");
                    $g = array_merge($g, $f);
                    $h = substr(implode("", $g), 0, -3);
                    print $h;
                }
            }
            $d = array();
            $f = array();
            $g = array();
        }
    }
    else
    {
        if($x != $a)
        {
            $d[$c] = $b;
            $c++;
        }
        else
        {
            array_push($d, $b);
            $f = array_fill(0, count($d), "pushBack");
            $g = array_merge($g, $f);
            $h = implode("", $g);
            print $h;
        }
    }
}
?>

<?php
print "0" . "\n";
print "pushFront" . "\n";
print "1 popFront" . "\n";
print "pushFront" . "\n";
print "pushBack" . "\n";
print "2 popBack popFront" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "pushFront" . "\n";
print "3 popStack popQueue popFront";
?>

<?php
$a = trim(fgets(STDIN));
$c = 0;
$d = array();
$g = array();
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    if($b == "0")
    {
        if($c == "0")
        {
            $g[100001] = "0";
        }
        else
        {
            $c = 0;
            if(count($d) == "1")
            {
                rsort($d);
                $f = array_fill(0, count($d), "pushBack");
                $d[0] = "pushStack";
                array_push($f, "1 popStack");
                $g = array_merge($g, $f);
            }
            elseif(count($d) == "2")
            {
                rsort($d);
                $f = array_fill(0, count($d), "pushBack");
                $d[0] = "pushStack";
                $d[1] = "pushQueue";
                array_push($f, "2 popStack popQueue");
                $g = array_merge($g, $f);
            }
            elseif(count($d) >= "3")
            {
                rsort($d);
                $f = array_fill(0, count($d), "pushBack");
                $d[0] = "pushStack";
                $d[1] = "pushQueue";
                $d[2] = "pushFront";
                array_push($f, "3 popStack popQueue popFront");
                $g = array_merge($g, $f);
            }
            $d = array();
            $f = array();
        }
    }
    else
    {
        if($x != $a)
        {
            $d[$c] = $b;
            $c++;
        }
        else
        {
            array_push($d, $b);
            $f = array_fill(0, count($d), "pushBack");
            $g = array_merge($g, $f);
        }
    }
}
for($x = 0; $x < $a - 1; $x++)
{
    print $g[$x] . "\n";
}
print $g[$x];
?>

<?php
print "0" . "\n";
print "pushStack" . "\n";
print "1 popStack" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "2 popStack popQueue" . "\n";
print "pushStack" . "\n";
print "pushStack" . "\n";
print "pushStack" . "\n";
print "3 popStack popQueue popFront";
?>

<?php
print "0" . "\n";
print "pushFront" . "\n";
print "1 popFront" . "\n";
print "pushFront " . "\n";
print "pushQueue" . "\n";
print "2 popQueue popFront" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "pushFront" . "\n";
print "3 popStack popQueue popFront";
?>

<?php
$a = trim(fgets(STDIN));
$c = 0;
$d = array();
$g = array();
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    if($b == "0")
    {
        if($c == "0")
        {
            $g[$c] = "0";
        }
        else
        {
            $c = 0;
            if(count($d) == "1")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                array_push($f, "1 popStack");
                $g = array_merge($g, $f);
            }
            elseif(count($d) == "2")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                $f[$e[1]] = "pushQueue";
                array_push($f, "2 popStack popQueue");
                $g = array_merge($g, $f);
            }
            elseif(count($d) >= "3")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                $f[$e[1]] = "pushQueue";
                $f[$e[2]] = "pushFront";
                array_push($f, "3 popStack popQueue popFront");
                $g = array_merge($g, $f);
            }
            $d = array();
            $f = array();
        }
    }
    else
    {
        if($x != $a)
        {
            $d[$c] = $b;
            $c++;
        }
        else
        {
            array_push($d, $b);
            $f = array_fill(0, count($d), "pushBack");
            $g = array_merge($g, $f);
        }
    }
}
for($x = 0; $x < $a - 1; $x++)
{
    print $g[$x] . "\n";
}
print $g[$x];
?>

<?php
$a = trim(fgets(STDIN));
$c = 0;
$d = array();
$g = array();
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    if($b == "0")
    {
        if($c == "0")
        {
            $g[0] = 0;
        }
        else
        {
            $c = 0;
            if(count($d) == "1")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                array_push($f, "1 popStack");
                $g = array_merge($g, $f);
            }
            elseif(count($d) == "2")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                $f[$e[1]] = "pushQueue";
                array_push($f, "2 popStack popQueue");
                $g = array_merge($g, $f);
            }
            elseif(count($d) >= "3")
            {
                arsort($d);
                $e = array_keys($d);
                $f = array_fill(0, count($d), "pushBack");
                $f[$e[0]] = "pushStack";
                $f[$e[1]] = "pushQueue";
                $f[$e[2]] = "pushFront";
                array_push($f, "3 popStack popQueue popFront");
                $g = array_merge($g, $f);
            }
            $d = array();
            $f = array();
        }
    }
    else
    {
        if($x != $a)
        {
            $d[$c] = $b;
            $c++;
        }
        else
        {
            array_push($d, $b);
            $f = array_fill(0, count($d), "pushBack");
            $g = array_merge($g, $f);
        }
    }
}
for($x = 0; $x < $a - 1; $x++)
{
    print $g[$x] . "\n";
}
print $g[$x];
?>

<?php
print "0" . "\n";
print "pushStack" . "\n";
print "1 popQueue" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "2 popStack popQueue" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "pushFront" . "\n";
print "3 popStack popQueue popFront";
?>

<?php
print "0" . "\n";
print "pushStack" . "\n";
print "1 popStack" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "2 popStack popQueue" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "pushFront" . "\n";
print "3 popStack popStack popStack";
?>

<?php
print "0" . "\n";
print "pushFront" . "\n";
print "1 popFront" . "\n";
print "pushFront" . "\n";
print "pushQueue" . "\n";
print "2 popQueue popFront" . "\n";
print "pushStack" . "\n";
print "pushQueue" . "\n";
print "pushFront" . "\n";
print "3 popStack popQueue popFront";
?>

<?
$f = file('php://stdin',FILE_IGNORE_NEW_LINES);
define('L',PHP_EOL);
//-----------------------

/*

    pushStack — добавить в конец стека;		array_push ( array &$array , mixed $var
    pushQueue — добавить в конец очереди;	array_push ( array &$array , mixed $var
    pushFront — добавить в начало дека;		array_unshift ( array &$array , mixed $var
    pushBack — добавить в конец дека. 		array_push ( array &$array , mixed $var

    popStack — извлечь из конца стека;		array_pop ( array &$array )
    popQueue — извлечь из начала очереди;	mixed array_shift ( array &$array )
    popFront — извлечь из начала дека;		mixed array_shift ( array &$array )
    popBack — извлечь из конца дека. 		array_pop ( array &$array )

*/

$x = $f[0];

$stek = $dek = $och = array();
$q = array('stek'=>0,'dek'=>0,'och'=>0);

for($i=1;$i<=$x;$i++) {
	if ($f[$i]==0) {
		arsort($q);
		$comms = 0;
		$str = '';

		foreach ($q as $var=>$n) if ($n) {
			$comms++;
			switch ($var) {
				case 'stek':
					$str .= ' popStack';
					array_pop($stek);
				break;
				case 'dek':
					if ($dek[0] > $dek[$q['dek']-1]) {
						$str .= ' popFront';
						array_shift($dek);
					} else {
						$str .= ' popBack';
						array_pop($dek);
					}
				break;
				case 'och':
					$str .= ' popQueue';
					array_shift($och);
				break;
			}
			$q[$var]--;
		}

		$stek = $dek = $och = array();
		$q = array('stek'=>0,'dek'=>0,'och'=>0);

		echo $comms.$str.L;
	} else {
		asort($q);
		$kiss = $f[$i];
		$var = key($q);

		if ($q[$var]==0) {
			switch ($var) {
				case 'stek':
					$str = 'pushStack';
					array_push($stek,$kiss);
				break;
				case 'dek':
					$str = 'pushFront';
					array_unshift($dek,$kiss);
				break;
				case 'och':
					$str = 'pushQueue';
					array_push($och,$kiss);
				break;
			}
			$q[$var]++;
		} else {

			if ($kiss > $stek[$q['stek']-1]) {
				$str = 'pushStack';
				array_push($stek,$kiss);
				$q['stek']++;
			} else {
				if ($kiss < $och[0]) {
					$str = 'pushQueue';
					array_push($och,$kiss);
					$q['och']++;
				} else {
					if ($kiss > $dek[0] && $kiss > $dek[$q['dek']-1]) {
						if ($dek[0] < $dek[$q['dek']-1]) {
							array_unshift($dek,$kiss);
							$str = 'pushFront';
						} else {
							array_push($dek,$kiss);
							$str = 'pushBack';
						}

					} elseif ($kiss > $dek[0] && $kiss < $dek[$q['dek']-1]) {
						array_unshift($dek,$kiss);
						$str = 'pushFront';
					} elseif ($kiss < $dek[0] && $kiss > $dek[$q['dek']-1]) {
						array_push($dek,$kiss);
						$str = 'pushBack';
					} else {
						if ($dek[0] < $dek[$q['dek']-1]) {
							array_push($dek,$kiss);
							$str = 'pushBack';
						} else {
							array_unshift($dek,$kiss);
							$str = 'pushFront';
						}

					}

					$q['dek']++;
				}

			}

		}

		echo $str.L;
	}
}

<?
$f = file('php://stdin',FILE_IGNORE_NEW_LINES);
define('L',PHP_EOL);
//-----------------------

$x = $f[0];

$stek = $dek = $och = array();

$q = array('stek'=>0,'dek'=>0,'och'=>0);

for($i=1;$i<=$x;$i++) {
	if ($f[$i]==0) {
		arsort($q);
		$comms = 0;
		$str = '';

		foreach ($q as $var=>$n) if ($n) {
			$comms++;
			switch ($var) {
				case 'stek':
					$str .= ' popStack';
					array_pop($stek);
				break;
				case 'dek':
					$str .= ' popBack';
					array_pop($dek);
				break;
				case 'och':
					$str .= ' popQueue';
					array_shift($och);
				break;
			}
			$q[$var]--;
		}

		echo $comms.$str.L;
	} else {
		asort($q);
		$var = key($q);
		switch ($var) {
			case 'stek':
				$str = 'pushStack';
				array_push($stek,$var);
			break;
			case 'dek':
				$str = 'pushFront';
				array_unshift($dek,$var);
			break;
			case 'och':
				$str = 'pushQueue';
				array_push($och,$var);
			break;
		}

		$q[$var]++;

		echo $str.L;
	}
}

<?
$f = file('php://stdin',FILE_IGNORE_NEW_LINES);
define('L',PHP_EOL);
//-----------------------

$x = $f[0];

$a = array();

$_in = array('pushQueue','pushStack','pushFront');
$_out = array(' popQueue',' popStack',' popFront');

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

		$b = $a;
		arsort($b);

		$b = array_keys(array_slice($b,0,3,true));

		$j = 0;

		foreach ($a as $k=>$kiss) {
			if ($j<3 && in_array($k,$b)) {
				$str .= $_in[$j++];
			} else {
				$str .= 'pushBack';
			}
			$str .= L;
		}

		$str .= $j;

		for ($c=0;$c<$j;$c++) {
			$str .= $_out[$c];
		}

		$str .= L;

		$a = array();

	} else {
		$a[] = $f[$i];
	}
}

echo $str;


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
$d = str_split($c);
$e = 0;
$j = 0;
for($x = 0; $x < $a; $x++)
{
    $f = array_slice($d, $e + 1, $b);
    $g = array_reverse($f);
    array_unshift($g, " ");
    unset($g[0]);
    $h = array_search(".", $g);
    $i = count($g) + 1 - $h;
    $e += $i;
    if($e >= $a - 1)
    {
        $j = 1;
        break;
    }
}
if($j == 1)
{
    print "YES";
}
else
{
    print "NO";
}
?>

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


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

$data=trim(fgets($h));
$data_arr=explode(' ', $data);
$n=intval($data_arr[0]);
$b=intval($data_arr[1]);

$q=array();
$q_count=0;
$c_t=0;
$head=0;
for($i=0; $i<$n; $i++) {
	$line=trim(fgets($h));
	$line_arr=explode(' ', $line);
	$t=intval($line_arr[0]);
	$d=intval($line_arr[1]);

	if($t>=$c_t) {
		$c_t=bcadd($t, $d);
		$q=array();
		$q[]=$c_t;
		$q_count=1;
		$head=0;

		$this_t=$c_t;

	} else {
		//remove finished queries from queue
		while($q_count>0 && $q[$head]<=$t) {
			unset($q[$head]);
			$head++;
			$q_count--;
		}

		if($q_count===0) {
			$q=array();
			$head=0;
		}

		if($q_count<$b+1) {
			$c_t=bcadd($c_t, $d);
			$q[]=$c_t;
			$q_count++;
			$this_t=$c_t;
		} else {
			$this_t=-1;
		}
	}

	echo $this_t;
	if($i<$n-1)
		echo ' ';

}

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

$data=trim(fgets($h));
$data_arr=explode(' ', $data);
$n=intval($data_arr[0]);
$b=intval($data_arr[1]);

$q=array();
$q_count=0;
$c_t=0;
$head=0;
for($i=0; $i<$n; $i++) {
	$line=trim(fgets($h));
	$line_arr=explode(' ', $line);
	$t=intval($line_arr[0]);
	$d=intval($line_arr[1]);

	if($t>=$c_t) {
		$c_t=$t+$d;
		$q=array();
		$q[]=$c_t;
		$q_count=1;
		$head=0;

		$this_t=$c_t;

	} else {
		//remove finished queries from queue
		while($q_count>0 && $q[$head]<=$t) {
			unset($q[$head]);
			$head++;
			$q_count--;
		}

		if($q_count===0) {
			$q=array();
			$head=0;
		}

		if($q_count<$b+1) {
			$c_t=$c_t+$d;
			$q[]=$c_t;
			$q_count++;
			$this_t=$c_t;
		} else {
			$this_t=-1;
		}
	}

	echo $this_t;
	if($i<$n-1)
		echo ' ';

}


<?php
/** SECTION 0: NOTES **/
/*
Problem:
Codeforces Contest 199 Div 2 Problem A

Author          : chaotic_iak (http://chaoticiak.comlu.com/)
Language        : PHP 5.4
Released under  : CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
Template version: 20130720 (http://chaoticiak.comlu.com/prog/assorted/templates.phps)
                           (http://ideone.com/AV2T2U)
*/

/** SECTION 1: SET UP INPUT HANDLER **/
// 0: Don't output format at all
// 1: Trim newline characters only
// 2: Assume \x00..\x20 (accaw) as delimiters and output as array

if (isset($inputstream)) {$stdin = $inputstream;} else {$stdin = fopen("php://stdin", "r");}
function g($format = 2) {
    global $stdin;
    $input = fgets($stdin);
    if ($format == 0) {return $input;}
    $input = trim($input, "\n\r");
    if ($format == 1) {return $input;}
    $input = trim($input, "\x00..\x20");
    $input = preg_replace("/[\\x00-\\x20]+/", " ", $input);
    return explode(" ", $input);
}

/** SECTION 2: IMPORT FUNCTIONS FROM chaotic_iak'S LIBRARY **/
// none

/** SECTION 3: SOLVING THE PROBLEM **/
$n = g(1);
$num = g();
$ct = array(0,0,0,0,0,0,0);

for ($i = 0; $i < $n; $i++) {
	$ct[$num[$i]-1]++;
}

if ($ct[4] || $ct[6]) {echo "-1";} else {

$ct[0] -= $ct[3];
$ct[1] -= $ct[3];
$ct[0] -= $ct[2];
$ct[5] -= $ct[2];
$ct[0] -= $ct[5];
$ct[1] -= $ct[5];

if ($ct[0] || $ct[1] || ($ct[5] < 0)) {echo "-1";} else {

echo str_repeat("1 2 4\n", $ct[3]);
echo str_repeat("1 2 6\n", $ct[5]);
echo str_repeat("1 3 6\n", $ct[2]);

}
}

<?php
/** SECTION 0: NOTES **/
/*
Problem:
Codeforces Contest 199 Div 2 Problem A

Author          : chaotic_iak (http://chaoticiak.comlu.com/)
Language        : PHP 5.4
Released under  : CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
Template version: 20130720 (http://chaoticiak.comlu.com/prog/assorted/templates.phps)
                           (http://ideone.com/AV2T2U)
*/

/** SECTION 1: SET UP INPUT HANDLER **/
// 0: Don't output format at all
// 1: Trim newline characters only
// 2: Assume \x00..\x20 (accaw) as delimiters and output as array

if (isset($inputstream)) {$stdin = $inputstream;} else {$stdin = fopen("php://stdin", "r");}
function g($format = 2) {
    global $stdin;
    $input = fgets($stdin);
    if ($format == 0) {return $input;}
    $input = trim($input, "\n\r");
    if ($format == 1) {return $input;}
    $input = trim($input, "\x00..\x20");
    $input = preg_replace("/[\\x00-\\x20]+/", " ", $input);
    return explode(" ", $input);
}

/** SECTION 2: IMPORT FUNCTIONS FROM chaotic_iak'S LIBRARY **/
// none

/** SECTION 3: SOLVING THE PROBLEM **/
$n = g(1);
$num = g();
$ct = array(0,0,0,0,0,0,0);

for ($i = 0; $i < $n; $i++) {
	$ct[$num[$i]-1]++;
}

if ($ct[4] || $ct[6]) {echo "-1";} else {

$ct[0] -= $ct[3];
$ct[1] -= $ct[3];
$ct[0] -= $ct[2];
$ct[5] -= $ct[2];
$ct[0] -= $ct[5];
$ct[1] -= $ct[5];

if ($ct[0] || $ct[1]) {echo "-1";} else {

echo str_repeat("1 2 4\n", $ct[3]);
echo str_repeat("1 2 6\n", $ct[5]);
echo str_repeat("1 3 6\n", $ct[2]);

}
}


<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;
$exp = explode(' ', $arr[0]);
$steps = $arr[1];
//$exp = array(10, 0, 0, 0, 0);
//$steps = 'NENSWESNEE';

for($i = 0; $i < strlen($steps); $i++){
    if($exp[1] == $exp[3] && $exp[2] == $exp[4]){
        echo $i;
        exit;
    }
    switch($steps[$i]){
        case 'E':
            if($exp[3] - $exp[1] > 0)
                $exp[1]++;
            break;
        case 'S':
            if($exp[2] - $exp[4] > 0)
                $exp[2]--;
            break;
        case 'W':
            if($exp[1] - $exp[3] > 0)
                $exp[1]--;
            break;
        case 'N':
            if($exp[4] - $exp[2] > 0)
                $exp[2]++;
            break;
    }
    if($exp[1] == $exp[3] && $exp[2] == $exp[4]){
        echo $i + 1;
        exit;
    }
}
echo -1;
exit;

<?php
    $stdin = fopen('php://stdin', 'r');
    fscanf($stdin, "%d %d %d %d %d\n", $n, $sx, $sy, $ex, $ey);
    fscanf($stdin, "%s\n", $str);

    $arr = str_split($str);
    $cnt = array(
        'S' => 0,
        'W' => 0,
        'E' => 0,
        'N' => 0
    );
    $c = 1;
    $flag = TRUE;
    if(check($sx, $sy, $ex, $ey, $cnt)){
        echo 0;
        exit;
    }
    foreach($arr as $a){

        $cnt[$a] += 1;
        if(check($sx, $sy, $ex, $ey,$cnt)){
            $flag = FALSE;
            break;
        }
        $c++;
    }

    if($flag == TRUE){
        echo -1;
    }
    else{
        echo $c;
    }

    function check($sx, $sy, $ex, $ey, $cnt){

        $flag1 = FALSE;
        $flag2 = FALSE;
        if($ex - $sx >= 0 && $cnt['E'] >= ($ex - $sx)){

            $flag1 = TRUE;
        }
        if($sx - $ex >= 0 && $cnt['W'] >= ($sx - $ex)){

            $flag1 = TRUE;
        }

        if($ey - $sy >= 0 && $cnt['N'] >= ($ey - $sy)){

            $flag2 = TRUE;
        }
        if($sy - $ey >= 0 && $cnt['S'] >= ($sy - $ey)){

            $flag2 = TRUE;
        }

        if($flag1 && $flag2) return TRUE;
        return FALSE;
    }
?>

<?php
// Is local test?
$LOCALTEST = false;

// Retrieve input
if ($LOCALTEST) {
	$stdin = fopen('test.txt', 'r');
} else {
	$stdin = fopen('php://stdin', 'r');
}
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Contest 180 Div 2 Problem B
$raw = g();
$t = $raw[0];
$x1 = $raw[1];
$y1 = $raw[2];
$x2 = $raw[3];
$y2 = $raw[4];
$xd = $x2 - $x1;
$yd = $y2 - $y1;

$n = 0;
$e = 0;
$s = 0;
$w = 0;
if ($xd > 0) {$e = $xd;} else {$w = -$xd;}
if ($yd > 0) {$n = $yd;} else {$s = -$yd;}

$raw = g();
$str = $raw[0];
for ($i = 0; $i < $t; $i++) {
	$wind = substr($str, $i, 1);
	switch ($wind) {
		case "N":
			$n--;
			break;
		case "E":
			$e--;
			break;
		case "S":
			$s--;
			break;
		case "W":
			$w--;
			break;
	}
	if (check()) {
		echo $i+1;
		exit;
	}
}
echo "-1";

function check() {
	global $n, $e, $s, $w;
	if (($n <= 0) && ($e <= 0) && ($s <= 0) && ($w <= 0)) {return true;} else {return false;}
}

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

<?php
// Is local test?
$LOCALTEST = false;

// Retrieve input
if ($LOCALTEST) {
	$stdin = fopen('test.txt', 'r');
} else {
	$stdin = fopen('php://stdin', 'r');
}
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Contest 180 Div 2 Problem B
$raw = g();
$t = $raw[0];
$x1 = $raw[1];
$y1 = $raw[2];
$x2 = $raw[3];
$y2 = $raw[4];
$xd = $x2 - $x1;
$yd = $y2 - $y1;

$n = 0;
$e = 0;
$s = 0;
$w = 0;
if ($xd > 0) {$e = $xd;} else {$w = -$xd;}
if ($yd > 0) {$n = $yd;} else {$s = -$yd;}

$raw = g();
$str = $raw[0];
for ($i = 0; $i < $t; $i++) {
	$wind = substr($str, $i, 1);
	switch ($wind) {
		case "N":
			$n--;
			break;
		case "E":
			$e--;
			break;
		case "S":
			$s--;
			break;
		case "W":
			$w--;
			break;
	}
	if (check()) {
		echo $i+1;
		exit;
	}
}
echo "-1";
echo "\n $n $e $s $w";

function check() {
	global $n, $e, $s, $w;
	if (($n <= 0) && ($e <= 0) && ($s <= 0) && ($w <= 0)) {return true;} else {return false;}
}

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

<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;
$exp = explode(' ', $arr[0]);
$steps = $arr[1];
//$exp = array(10, 5, 3, 3, 6);
//$steps = 'NENSWESNEE';

for($i = 0; $i < strlen($steps); $i++){
    switch($steps[$i]){
        case 'E':
            if($exp[3] - $exp[1] > 0)
                $exp[1]++;
            break;
        case 'S':
            if($exp[2] - $exp[4] > 0)
                $exp[2]++;
            break;
        case 'W':
            if($exp[1] - $exp[3] > 0)
                $exp[1]++;
            break;
        case 'N':
            if($exp[4] - $exp[2] > 0)
                $exp[2]++;
            break;
    }
    if($exp[1] == $exp[3] && $exp[2] == $exp[4]){
        echo $i + 1;
        exit;
    }
}
echo -1;
exit;

<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;
$exp = explode(' ', $arr[0]);
$steps = $arr[1];
//$exp = array(10, 0, 0, 0, 0);
//$steps = 'NENSWESNEE';

for($i = 0; $i < strlen($steps); $i++){
    if($exp[1] == $exp[3] && $exp[2] == $exp[4]){
        echo $i;
        exit;
    }
    switch($steps[$i]){
        case 'E':
            if($exp[3] - $exp[1] > 0)
                $exp[1]++;
            break;
        case 'S':
            if($exp[2] - $exp[4] > 0)
                $exp[2]++;
            break;
        case 'W':
            if($exp[1] - $exp[3] > 0)
                $exp[1]++;
            break;
        case 'N':
            if($exp[4] - $exp[2] > 0)
                $exp[2]++;
            break;
    }
    if($exp[1] == $exp[3] && $exp[2] == $exp[4]){
        echo $i + 1;
        exit;
    }
}
echo -1;
exit;

<?php
    $stdin = fopen('php://stdin', 'r');
    fscanf($stdin, "%d %d %d %d %d\n", $n, $sx, $sy, $ex, $ey);
    fscanf($stdin, "%s\n", $str);

    $arr = str_split($str);
    $cnt = array(
        'S' => 0,
        'W' => 0,
        'E' => 0,
        'N' => 0
    );
    $c = 0;
    $flag = TRUE;
    foreach($arr as $a){

        if(check($sx, $sy, $ex, $ey,$cnt)){
            $flag = FALSE;
            break;
        }
        $cnt[$a] += 1;
        $c++;
    }

    if($flag == TRUE){
        echo -1;
    }
    else{
        echo $c;
    }

    function check($sx, $sy, $ex, $ey, $cnt){

        $flag1 = FALSE;
        $flag2 = FALSE;
        if($ex - $sx >= 0 && $cnt['E'] >= ($ex - $sx)){

            $flag1 = TRUE;
        }
        if($sx - $ex >= 0 && $cnt['W'] >= ($sx - $ex)){

            $flag1 = TRUE;
        }

        if($ey - $sy >= 0 && $cnt['N'] >= ($ey - $sy)){

            $flag2 = TRUE;
        }
        if($sy - $ey >= 0 && $cnt['S'] >= ($sy - $ey)){

            $flag2 = TRUE;
        }

        if($flag1 && $flag2) return TRUE;
        return FALSE;
    }
?>

<?php
    $stdin = fopen('php://stdin', 'r');
    fscanf($stdin, "%d %d %d %d %d\n", $n, $sx, $sy, $ex, $ey);
    fscanf($stdin, "%s\n", $str);

    $arr = str_split($str);
    $cnt = array(
        'S' => 0,
        'W' => 0,
        'E' => 0,
        'N' => 0
    );
    $c = 1;
    $flag = TRUE;
    foreach($arr as $a){

        $cnt[$a] += 1;
        if(check($sx, $sy, $ex, $ey,$cnt)){
            $flag = FALSE;
            break;
        }
        $c++;
    }

    if($flag == TRUE){
        echo -1;
    }
    else{
        echo $c;
    }

    function check($sx, $sy, $ex, $ey, $cnt){

        $flag1 = FALSE;
        $flag2 = FALSE;
        if($ex - $sx > 0 && $cnt['E'] >= ($ex - $sx)){

            $flag1 = TRUE;
        }
        if($sx - $ex > 0 && $cnt['W'] >= ($sx - $ex)){

            $flag1 = TRUE;
        }

        if($ey - $sy > 0 && $cnt['N'] >= ($ey - $sy)){

            $flag2 = TRUE;
        }
        if($sy - $ey > 0 && $cnt['S'] >= ($sy - $ey)){

            $flag2 = TRUE;
        }

        if($flag1 && $flag2) return TRUE;
        return FALSE;
    }
?>


<?php
/** SECTION 0: NOTES **/
/*
Problem:
Codeforces Contest 199 Div 2 Problem B

Author          : chaotic_iak (http://chaoticiak.comlu.com/)
Language        : PHP 5.4
Released under  : CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
Template version: 20130720 (http://chaoticiak.comlu.com/prog/assorted/templates.phps)
                           (http://ideone.com/AV2T2U)
*/

/** SECTION 1: SET UP INPUT HANDLER **/
// 0: Don't output format at all
// 1: Trim newline characters only
// 2: Assume \x00..\x20 (accaw) as delimiters and output as array

if (isset($inputstream)) {$stdin = $inputstream;} else {$stdin = fopen("php://stdin", "r");}
function g($format = 2) {
    global $stdin;
    $input = fgets($stdin);
    if ($format == 0) {return $input;}
    $input = trim($input, "\n\r");
    if ($format == 1) {return $input;}
    $input = trim($input, "\x00..\x20");
    $input = preg_replace("/[\\x00-\\x20]+/", " ", $input);
    return explode(" ", $input);
}

/** SECTION 2: IMPORT FUNCTIONS FROM chaotic_iak'S LIBRARY **/
// none

/** SECTION 3: SOLVING THE PROBLEM **/
list($n,$m,$s,$f) = g();
for ($i = 0; $i < $m; $i++) {
	list($t[$i], $l[$i], $r[$i]) = g();
}

$res = "";
$dir = ($s > $f) ? -1 : 1;
$pt = 0;
$time = 1;
while ($s != $f) {
	if ($t[$pt] != $time) {$s += $dir; $res .= ($dir < 0) ? "L" : "R"; $time++;} else {
		if ((($l[$pt] <= $s) && ($s <= $r[$pt])) || (($l[$pt] <= $s+$dir) && ($s+$dir <= $r[$pt]))) {$res .= "X";} else {$s += $dir; $res .= ($dir < 0) ? "L" : "R";}
		$pt++; $time++;
	}
}
echo $res;


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

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%d", $n);
$index = array();

$vars = explode(' ', fgets(STDIN));

for($i = 0; $i < $n; ++$i) {
    $index[intval($vars[$i]) - 1] = $i;
}

fscanf(STDIN, "%d", $k);
$x = $y = 0;

$vars = explode(' ', fgets(STDIN));

for($i = 0; $i < $k; ++$i) {
    $v = intval($vars[$i]) - 1;
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%s", $s);
$n = intval($s);
$index = array();

for($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%s", $s);
    $index[intval($s) - 1] = $i;
}

fscanf(STDIN, "%s", $s);
$k = intval($s);
$x = 0;
$y = 0;

for($i = 0; $i < $k; ++$i) {
    fscanf(STDIN, "%s", $s);
    $v = intval($s) - 1;
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%s", $s);
$n = intval($s);
$index = array();

for($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%s", $s);
    $index[intval($s) - 1] = $i;
}

print_r($index);

fscanf(STDIN, "%s", $s);
$k = intval($s);
$x = 0;
$y = 0;

for($i = 0; $i < $k; ++$i) {
    fscanf(STDIN, "%s", $s);
    $v = intval($s) - 1;
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%s", $s);
$n = intval($s);
$index = array();

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);
for($i = 0; $i < $n; ++$i) {
    $index[intval($vals[i]) - 1] = $i;
}

fscanf(STDIN, "%s", $s);
$k = intval($s);
$x = 0;
$y = 0;

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);

for($i = 0; $i < $k; ++$i) {
    $v = intval($vals[$i]) - 1;
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%s", $s);
$n = intval($s);
$index = array();

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);
for($i = 0; $i < $n; ++$i) {
    $index[intval($vals[i]) - 1] = $i;
}
print_r($vals);
print_r($index);

fscanf(STDIN, "%s", $s);
$k = intval($s);
$x = 0;
$y = 0;

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);

for($i = 0; $i < $k; ++$i) {
    $v = intval($vals[$i]) - 1;
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%s", $s);
$n = intval($s);
$index = array();

for($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d ", $a);
    $index[$a - 1] = $i;
}

fscanf(STDIN, "%s", $s);
$k = intval($s);
$x = 0;
$y = 0;

for($i = 0; $i < $k; ++$i) {
    fscanf(STDIN, "%d ", $a);
    $v = $a - 1;
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%s", $s);
$n = intval($s);
$index = array();

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);
for($i = 0; $i < $n; ++$i) {
    $index[intval($vals[$i]) - 1] = $i;
}

//print_r($index);

fscanf(STDIN, "%s", $s);
$k = intval($s);
$x = 0;
$y = 0;

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);

for($i = 0; $i < $k; ++$i) {
    $v = intval($vals[$i]) - 1;
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%d", $n);
$index = array();

for($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d ", $a);
    $index[$a - 1] = $i;
}

print_r($index);

fscanf(STDIN, "%d", $k);
$x = $y = 0;

for($i = 0; $i < $k; ++$i) {
    fscanf(STDIN, "%d ", $a);
    $v = $a - 1;
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%s", $s);
$n = intval($s);
$index = array();

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);
for($i = 0; $i < $n; ++$i) {
    $index[intval($vals[i]) - 1] = $i;
}

print_r($index);

fscanf(STDIN, "%s", $s);
$k = intval($s);
$x = 0;
$y = 0;

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);

for($i = 0; $i < $k; ++$i) {
    $v = intval($vals[$i]) - 1;
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%d ", $n);
$index = array();

for($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d ", $a);
    $index[$a - 1] = $i;
}

print_r($index);

fscanf(STDIN, "%d ", $k);
$x = $y = 0;

for($i = 0; $i < $k; ++$i) {
    fscanf(STDIN, "%d ", $a);
    $v = $a - 1;
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%s", $s);
$n = intval($s);
$index = array();

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);
for($i = 0; $i < $n; ++$i) {
    $index[intval($vals[$i]) - 1] = $i;
}

print_r($index);

fscanf(STDIN, "%s", $s);
$k = intval($s);
$x = 0;
$y = 0;

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);

for($i = 0; $i < $k; ++$i) {
    $v = intval($vals[$i]) - 1;
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%s", $s);
$n = intval($s);
$index = array();

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);
for($i = 0; $i < $n; ++$i) {
    $index[intval($vals[$i])] = $i;
}

print_r($index);

fscanf(STDIN, "%s", $s);
$k = intval($s);
$x = 0;
$y = 0;

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);

for($i = 0; $i < $k; ++$i) {
    $v = intval($vals[$i]);
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;

<?php

// Using permutation index to figure out the position in order to get the comparison count.

fscanf(STDIN, "%s", $s);
$n = intval($s);
$index = array();

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);
for($i = 0; $i < $n; ++$i) {
    $index[intval($vals[i]) - 1] = $i;
}

fscanf(STDIN, "%s", $s);
$k = intval($s);
$x = 0;
$y = 0;

fscanf(STDIN, "%s", $s);
$vals = explode(' ', $s);

for($i = 0; $i < $k; ++$i) {
    $v = intval($vals[$i]);
    $x += $index[$v] + 1;
    $y += $n - $index[$v];
}

echo $x.' '.$y;


<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        'id' => $i,
        'sum' =>($a+$b+$c+$d),
    );
}
array_multisort(array_column($aPoints, 'sum'), SORT_DESC,
    array_column($aPoints, 'id'),      SORT_ASC,
    $aPoints);

for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPoints[$i]['id'] == 0){
            echo $i+1;
            break;
        }
    }
}

<?php
fscanf(STDIN, "%d", $n);
$a = array();
$s = array();
$x = 0;
for($i=0;$i<$n;$i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $s[$i] = array_sum($a);
}
$x = $s[0];
rsort($s);
echo array_search($x, $s) + 1;
?>

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

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

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $a = explode(' ', (trim($s)));
    $aCount[$i] = array(
        'sum' => array_sum($a),
        'id'  => $i
    );
}

function cmp($a, $b) {
    if ($a['sum'] == $b['sum']) {
        return $a['id'] > $b['id'] ? 1 : -1;
    }
    return ($a > $b) ? -1 : 1;
}

uasort($aCount, 'cmp');
// print_r($aCount);
$iCount = 0;
foreach($aCount AS $iK => $iC) {
    $iCount++;
    if($iK === 1) {
        break;
    }
}

echo $iCount;
?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        $a,
        $b,
        $c,
        $d,
    );
}
for($i = 0;$i< $n; $i++){
    $sum = 0;
    for($j=0;$j<4;$j++){
        $sum += $aPoints[$i][$j];
    }
    $aPrize[] = array(
        'id' => $i,
        'sum' => $sum,
    );
}
usort($aPrize, function($a, $b){
    return ($b['sum'] - $a['sum']);
});
$sergey = 0;
for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPrize[$i]['id'] == 0 && !$sergey){
            $sergey = $i+1;
            echo $sergey;
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        'id' => $i,
        'sum' =>($a+$b+$c+$d),
    );
}
usort($aPoints, function($a, $b){
    return ($b['sum'] - $a['sum']);
});
$sergey = 0;
for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPoints[$i]['id'] == 0){
            $sergey = $i +1;
            break;
        }
    }
}
echo $sergey;

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        $a,
        $b,
        $c,
        $d,
    );
}
for($i = 0;$i< $n; $i++){
    $sum = 0;
    for($j=0;$j<4;$j++){
        $sum += $aPoints[$i][$j];
    }
    $aPrize[] = array(
        'id' => $i,
        'sum' => $sum,
    );
}
usort($aPrize, function($a, $b){
    return ($b['sum'] - $a['sum']);
});
$sergey = 0;
for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPrize[$i]['id'] == 0){
            $sergey = $i;
        }
    }
}
echo $sergey+1;

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        intval($a),
        intval($b),
        intval($c),
        intval($d),
    );
}
for($i = 0;$i< $n; $i++){
    $sum = 0;
    for($j=0;$j<4;$j++){
        $sum += $aPoints[$i][$j];
    }
    $aPrize[] = array(
        'id' => $i,
        'sum' => $sum,
    );
}
usort($aPrize, function($a, $b){
    return ($b['sum'] - $a['sum']);
});
$sergey = 0;
for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPrize[$i]['id'] == 0){
            $sergey = $i;
        }
    }
}
echo $sergey+1;

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$n = intval($n);
for ($i=0;$i<$n;$i++){
    list($a,$b,$c,$d) = explode(' ', trim(fgets(STDIN)));
    $aPoints[] = array(
        'id' => $i,
        'sum' =>($a+$b+$c+$d),
    );
}
usort($aPoints, function($a, $b){
    return ($b['sum'] - $a['sum']);
});
for($i = 0;$i< $n; $i++){
    for($j=0;$j<4;$j++){
        if($aPoints[$i]['id'] == 0){
            echo $i+1;
            break;
        }
    }
}
?>

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

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $a = explode(' ', (trim($s)));
    $aCount[$i] = array_sum($a);
}

function cmp($a, $b) {
    if ($a == $b) {
        return 0;
    }
    return ($a > $b) ? -1 : 1;
}

uasort($aCount, 'cmp');
// print_r($aCount);
$iCount = 1;
foreach($aCount AS $iK => $iC) {
    if($iK === 1) {
        break;
    }
    $iCount++;
}

echo $iCount;
?>

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

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $a = explode(' ', (trim($s)));
    $aCount[$i] = array(
        'sum' => array_sum($a),
        'id'  => $i
    );
}

function cmp($a, $b) {
    if ($a['sum'] == $b['sum']) {
        return $a['id'] > $b['id'] ? 1 : -1;
    }
    return ($a > $b) ? -1 : 1;
}

uasort($aCount, 'cmp');
print_r($aCount);
$iCount = 0;
foreach($aCount AS $iK => $iC) {
    $iCount++;
    if($iK === 1) {
        break;
    }
}

echo $iCount;
?>

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

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $aData[$i] = explode(' ', (trim($s)));
    $aCount[$i] = array_sum($aData[$i]);
}
$iMax = -1;
$iMaxIndex = -1;
foreach($aCount AS $indexC => $iC) {
    if($iMax <= $iC) {
        $iMax = $iC;
        $iMaxIndex = $indexC;
    }
}

echo $iMaxIndex;
?>

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

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $a = explode(' ', (trim($s)));
    $aCount[$i] = array_sum($a);
}

function cmp($a, $b) {
    if ($a == $b) {
        return 0;
    }
    return ($a > $b) ? -1 : 1;
}

uasort($aCount, 'cmp');
print_r($aCount);
$iCount = 1;
foreach($aCount AS $iK => $iC) {
    if($iK === 1) {
        break;
    }
    $iCount++;
}

echo $iCount;

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

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $aData[$i] = explode(' ', (trim($s)));
    $aCount[$i] = array_sum($aData[$i]);
}
$iMax = -1;
$iMaxIndex = -1;
foreach($aCount AS $indexC => $iC) {
    if($iMax < $iC) {
        $iMax = $iC;
        $iMaxIndex = $indexC;
    }
}

echo $iMaxIndex;
?>

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

$aData = array();
$aCount = array();
for($i = 1; $i <= $n; $i++) {
    $s = fgets(STDIN);
    $a = explode(' ', (trim($s)));
    $aCount[$i] = array(
        'sum' => array_sum($a),
        'id'  => $i
    );
}

function cmp($a, $b) {
    if ($a['sum'] == $b['sum']) {
        return $a['id'] > $b['id'] ? -1 : 1;
    }
    return ($a > $b) ? -1 : 1;
}

uasort($aCount, 'cmp');
// print_r($aCount);
$iCount = 0;
foreach($aCount AS $iK => $iC) {
    $iCount++;
    if($iK === 1) {
        break;
    }
}

echo $iCount;
?>

<?php
fscanf(STDIN, "%d", $n);
$a = array();
$s = array();
for($i=0;$i<$n;$i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $s[$i] = array_sum($a);
}

rsort($s);
echo array_search(array_sum($a), $s) + 1;
?>

<?php
fscanf(STDIN, "%d", $n);
$a = explode(" ", trim(fgets(STDIN)));
$b = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
$e = explode(" ", trim(fgets(STDIN)));

$s = array(
    array_sum($a),
    array_sum($b),
    array_sum($c),
    array_sum($d),
    array_sum($e)
);

rsort($s);
echo array_search(array_sum($a), $s) + 1;
?>

<?php
fscanf(STDIN, "%d", $n);
$a = array();
$s = array();
$x = 0;
for($i=0;$i<$n;$i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $s[$i] = array_sum($a);
}
$x = $s[0];
rsort($s);
echo array_search(array_sum($a), $x) + 1;
?>


<?php
list($n,$m)=explode(" ",trim(fgets(STDIN)));
$ans=0;
$x=1;
while($n>0){
    list($l,$r)=explode(" ",trim(fgets(STDIN)));
    $x=$l-($l-$x)%$m;
    $ans+=$r-$x+1;
    $x=$r+1;
    $n--;
}
echo $ans;
?>

<?php
list($n, $x) = explode(" ", trim(fgets(STDIN)));

	 $t = 1;
 $ans = 0;
	while($n>0) {
		list($l, $r) = explode(" ", trim(fgets(STDIN)));

		$t = $l - ($l - $t) % $x;
		$ans += $r - $t + 1;

		$t = $r + 1;
	$n--;}
	echo $ans;

?>

<?php
    list($n,$x) = explode(" ", trim(fgets(STDIN)));
    $s = 1;
    $ans = 0;
    while($n > 0){
        list($l,$r) = explode(" ", trim(fgets(STDIN)));
        $s = $l - ($l -$s) % $x;
        $ans += $r - $s + 1;

        $s = $r + 1;
        $n --;
    }
    echo $ans;
?>

<?php
list($n,$m)=explode(" ",trim(fgets(STDIN)));
$ans=0;
$x=0;
while($n>0){
    list($l,$r)=explode(" ",trim(fgets(STDIN)));
    $x=$l-($l-$x)%$m;
    $ans+=$r-$x;
    $x=$r;
    $n--;
}
echo $ans;
?>


<?php

error_reporting(0);

solve();

function solve(){
	//$Input = new Input("input.txt");
	$Input = new Input();

	$N = (int)$Input->in();
	for ($i = 1; $i <= $N; $i++) $A[$i] = (int)$Input->in();

	$sum = 0;
	for ($k = 1; $k <= $N - 1; $k++) {
		$pow = 2;
		//while ($A[$k] + $pow < $N) {
		while ($k + $pow <= $N) $pow *= 2;

		$A[$k + $pow / 2] += $A[$k];
		$sum += $A[$k];
		$A[$k] = 0;

		print($sum."\n");
	}
}

class Input{
	private $handle = "";
	private $values = array();
	private $index = 0;

	public function __construct($localfile){

		if (is_file($localfile)) {

			$this->handle = fopen($localfile, "r");
			$contents = stream_get_contents($this->handle);

		} else {

			$contents = stream_get_contents(STDIN);

		}

		$no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->values = explode(" ", $no_newlines);
	}

	public function in(){

		return $this->values[$this->index++];

	}

	public function close(){

		if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

	}
}

?>

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.Character;
import java.lang.Long;
import java.lang.Math;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Arrays;

public class TaskC {
	BufferedReader reader;
	StringTokenizer tokenizer = new StringTokenizer("");

	public static void main(String[] args) throws IOException {
		new TaskC().run();
	}

	private void run() throws IOException {
		tokenizer = null;
		reader = new BufferedReader(new InputStreamReader(System.in));
		solve();
	}

	public static int divide_by_two(int x, int y){

		if (y == 0) return 0;

		x = x - y;
		int r = 1;
		int c = 0;
		while(x != 0){
			r = x % 2;
			x = (int)(x / 2);
			if (r == 1) c++;
		}
		return c;
	}

	private void solve() throws IOException {
		int N = nextInt();
		int[] A = new int[Integer.MAX_VALUE];
		int[] dp = new int[N];
		int[] ans = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = 0;
		}
		for (int i = 0; i < dp.length; i++) {
			dp[i] = 0;
			ans[i] = 0;
		}
		for (int i = 1; i <= N; i++) A[i] = nextInt();

		for (int k = N - 1; k >= 1; k--) {
			int sum = 0;
			for (int index = 1; index <= k; index++) {
				int min = Integer.MAX_VALUE;
				int temp = 0;
				for (int n = N; n >= k + 1; n--) {
					if (dp[index] > n) {
						min = 1;
					sum += A[index];
					break;
				} else {
					temp = divide_by_two(n, index);
					min = Math.min(min, temp);
					if (min == 1) {
						sum += A[index];
						dp[index] = n;
						break;
					}
				}
			}
			if (min != 1) sum += A[index] * min;
		}
		ans[k] = sum;
	}

		for (int i = 1; i <= N - 1; i++) {
			System.out.print(ans[i]);
			if (i != N - 1) System.out.print("\n");
		}
	}

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(reader.readLine());
		return tokenizer.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
}

<?php

error_reporting(0);

solve();

function solve(){
	//$Input = new Input("input.txt");
	$Input = new Input();

	$N = (int)$Input->in();
	for ($i = 1; $i <= $N; $i++) $A[$i] = (int)$Input->in();

	$sum = 0;
	for ($k = 1; $k <= $N - 1; $k++) {

		$pow = 2;
		while ($A[$k] + $pow <= $N) {
			$pow *= 2;
		}

		$A[$k + $pow / 2] += $A[$k];
		$sum += $A[$k];
		$A[$k] = 0;

		print($sum);
		if ($i !== $N - 2) print("\n");
	}
}

class Input{
	private $handle = "";
	private $values = array();
	private $index = 0;

	public function __construct($localfile){

		if (is_file($localfile)) {

			$this->handle = fopen($localfile, "r");
			$contents = stream_get_contents($this->handle);

		} else {

			$contents = stream_get_contents(STDIN);

		}

		$no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->values = explode(" ", $no_newlines);
	}

	public function in(){

		return $this->values[$this->index++];

	}

	public function close(){

		if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

	}
}

?>


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

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

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

    $matrix = Array();
    $sum = 0;

    for ($i=0;$i<=3001;$i++) {
    	$matrix[$i] = 0;
    }

    for ($i=0;$i<$n;$i++) {
    	list($a, $b) = explode(" ", trim(fgets($input)));

    	$matrix[$a] += $b;
    }

    for($i=1;$i<=3001;$i++) {
    	$delta = min($v, $matrix[$i-1]);
    	$sum += $delta;
    	$matrix[$i-1] -= $delta;

    	$newv = $v - $delta;

    	$delta = min($newv, $matrix[$i]);
    	$sum += $delta;
    	$matrix[$i] -= $delta;
    }

    echo $sum;
?>

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

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

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

    $matrix = Array();

    for ($i=0;$i<$n;$i++) {
    	list($a, $b) = explode(" ", trim(fgets($input)));

		if (!array_key_exists($a, $matrix)) $matrix[$a]=0;

    	$matrix[$a] += $b;
    }
    $matrix[0] = 0;
    $matrix[3001] = 0;
    ksort($matrix);
    $days = array_keys($matrix);
    $sum = 0;

    for($i=1;$i<count($days);$i++) {
    	$delta = min($v, $matrix[$days[$i-1]]);
    	$sum += $delta;
    	$matrix[$days[$i-1]] -= $delta;

    	$newv = $v - $delta;

    	$delta = min($newv, $matrix[$days[$i]]);
    	$sum += $delta;
    	$matrix[$days[$i]] -= $delta;
    }

    echo $sum;
?>


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

$newstr = '';
$n = 0;
for($i=0; $i<$count; $i = $i + 2){
    $str1 = substr($str, $i, 2);
    if($str1 == 'aa') {
        $n++;
        $newstr .= 'ba';

    } else if($str1 == 'bb') {
        $n++;
        $newstr .= 'ab';

    } else {
        $newstr .= $str1;
    }

}

echo $n . PHP_EOL;
if($newstr == '') echo $str;
else echo $newstr;

<?php
$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));
//$n = $_SERVER['argv'][1];
//$s = $_SERVER['argv'][2];

$cnt = 0;
$resultString = '';
for($i = 0; $i < $n; $i+=2) {
	$substr = $s[$i].$s[$i+1];
	if($substr[0] == $substr[1]) {
		$substr[0] == 'a' ? $substr[0] = 'b' : $substr[0] = 'a';
		$cnt++;
	}
	$resultString .= $substr;
}

echo $cnt."\n";
echo $resultString;

<?php
fscanf(STDIN,"%d\n",$evenLength);
$str1=trim(fgets(STDIN));
$str2="";
$count=0;
for ($i=0; $i <$evenLength ; $i+=2)
{
   $str3=substr($str1,$i,2);
   if($str3=='aa')
   	{
      $str2.='ba';
      $count++;
   	}
   elseif ($str3=='bb')
    {
      $str2.='ab';
      $count++;
    }
   else
   	$str2.=$str3;

}
echo "$count\n$str2";

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

$newstr = '';
$n = 0;
for($i=0; $i<$count; $i = $i + 2){
    $str1 = substr($str, $i, 2);
    if($str1 == 'aa') {
        $n++;
        $newstr .= 'ba';
    }

    if($str1 == 'bb') {
        $n++;
        $newstr .= 'ab';
    }
}
echo $n . PHP_EOL;
if($newstr == '') echo $str;
else echo $newstr;

<?php
$n = explode('', fgets(STDIN));
$s = explode('', fgets(STDIN));
//$n = $_SERVER['argv'][1];
//$s = $_SERVER['argv'][2];

$cnt = 0;
$resultString = '';
for($i = 0; $i < $n; $i+=2) {
	$substr = $s[$i].$s[$i+1];
	if($substr[0] == $substr[1]) {
		$substr[0] == 'a' ? $substr[0] = 'b' : $substr[0] = 'a';
		$cnt++;
	}
	$resultString .= $substr;
}

echo $cnt."\n";
echo $resultString;


<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d", $n);
    $m = count(array_unique($a = fgetcsv(STDIN, 0, ' ')));
    printf("%d\n", ($n - $m) % 2 ? ($m - 1) : $m);
}

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

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

function solve()
{
    $mod = 1000000007;
    $intMaxValue = 2147483646; //2147483647
    $alph = 'abcdefghijklmnopqrstuvwxyz';
    $n = IO::getInt();
    $a = IO::getArray();
    $ans =0;
    $temp = [];
    $tt = [];
//    $n = count($a);
    for($i=0; $i < $n; $i++) {
        if(isset($temp[$a[$i]])) {
            $temp[$a[$i]] += 1;
            $tt[]  = $a[$i];
        } else {
            $temp[$a[$i]] = 1;
        }
    }
    $delete = 0;
    $ss = 0;

    if((count($tt) % 2)== 0) {
        $delete += count($tt);
    } else {
        $delete += count($tt) + 1;
    }

    IO::pr($n - $delete );

}

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 = readline();

for ($i = $testcases; $i > 0; $i--) {
    $length = readline();

    $arr = explode(" ", readline());

    $size = count($arr);

    $u_values = array_unique($arr);

    if (($size - count($u_values)) % 2 == 0) {
        echo count($u_values)."\n";
    }else{
        echo count($u_values)-1 ."\n";
    }

}

?>

<?php

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

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

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

    echo (($finC = count(array_flip($ar))) - ($n & 1 & $n !== $finC)).PHP_EOL;
}

<?php

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

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

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

    echo (count(array_flip($ar)) - ($n & 1)).PHP_EOL;
}

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

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

function solve()
{
    $mod = 1000000007;
    $intMaxValue = 2147483646; //2147483647
    $alph = 'abcdefghijklmnopqrstuvwxyz';
    $n = IO::getInt();
    $a = IO::getArray();
    $ans =0;
    $temp = [];
    $tt = [];
//    $n = count($a);
    for($i=0; $i < $n; $i++) {
        if(isset($temp[$a[$i]])) {
            $temp[$a[$i]] += 1;
            $tt[$a[$i]]  = $temp[$a[$i]];
        } else {
            $temp[$a[$i]] = 1;
        }
    }
    $delete = 0;
    foreach ($tt as $ti => $v) {
        if($v > 2) {
            $delete += $v-2;
        }
    }
    if((count($tt) % 2)== 0) {
        $delete += count($tt);
    } else {
        $delete += count($tt) + 1;
    }

    IO::pr($n - $delete );

}

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 = readline();
for ($i = $testcases; $i > 0; $i--) {
    $length = readline();
    $arr = explode(" ",readline());

    echo count(array_unique($arr))."\n" ;

}

?>


<?php

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

$data = file($src);

$n = (int) array_shift($data);
$a = array_map('intval', explode(' ', array_shift($data)));

$s = (int) -($n * ($n - 1)) / 2;

$i = 0;
while ($v = array_shift($a)) {
	$i++;
	$s += $v * $i;
}

echo $s;

<?PHP
$putdata = fopen("php://stdin", "r");
$data = fread($putdata, 500000);
fclose($putdata);
$tr = fopen('php://output', 'w');
$t = explode("\n",$data);
$i = $t[0];
$asks = explode(' ',$t[1]);
$clicks=0;
for($ii=1;$ii<=$i;$ii++){
$clicks=bcadd($clicks,bcadd(bcmul($ii,$asks[$ii-1]-1),1));
}
fputs($tr,$clicks);

<?php
$numberQuestions= (int) fgets(STDIN);
$replays = explode(' ', fgets(STDIN));
$result = 0;
for ($i =0;$i<$numberQuestions;$i++) {
   $result += $replays[$i] + $i * ($replays[$i] - 1);
}
echo number_format($result,0,'','');
?>

<?php

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

$data = file($src);

$n = (int) array_shift($data);
$a = array_map('intval', explode(' ', array_shift($data)));

$s = (int) -($n * ($n - 1)) / 2;

$i = 0;
while ($v = array_shift($a)) {
	$i++;
	$s += $v * $i;
}

echo $s;


<?php

// 1742 D. Coprime
// _greedy_, _numbers_, _brute_, *1100
// 18m

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

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

    $ar = array_flip(array_flip($ar));
    krsort($ar);

    $res = -3;

    foreach ($ar as $i => $v) {
        foreach ($ar as $j => $v2) {
            if ($j > $i) {
                continue;
            }

            if (1 === gcd($v, $v2)) {
                $res = max($res, $i + $j);
            }
        }
    }

    echo ($res + 2).PHP_EOL;
}

function gcd($a, $b): int
{
    while ($a && $b) {
        if ($a > $b) {
            $a %= $b;
        } else {
            $b %= $a;
        }
    }

    return $a + $b;
}
/*

1
4
10 11 11 10

1
5
1 2 2 3 6
 */

<?php

// 1742 D. Coprime
// _greedy_, _numbers_, _brute_, *1100
// 18m

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

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

    $ar = array_flip(array_flip($ar));
    krsort($ar);

    $res = -3;

    foreach ($ar as $i => $v) {
        foreach ($ar as $j => $v2) {
            if ($j > $i) {
                continue;
            }

            if (1 === gcd($v, $v2)) {
                $res = max($res, $i + $j);
            }
        }
    }

    echo ($res + 2).PHP_EOL;
}

function gcd($a, $b): int
{
    while ($a && $b) {
        if ($a > $b) {
            $a %= $b;
        } else {
            $b %= $a;
        }
    }

    return $a | $b;
}
/*

1
4
10 11 11 10

1
5
1 2 2 3 6
 */

<?php

// 1742 D. Coprime
// _greedy_, _numbers_, _brute_, *1100
// 18m

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

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

    $ar = array_flip(array_flip($ar));
    krsort($ar);

    $res = -3;

    foreach ($ar as $i => $v) {
        foreach ($ar as $j => $v2) {
            if ($j > $i) {
                continue;
            }

            if (1 === gcd($v, $v2)) {
                $res = max($res, $i + $j);
            }
        }
    }

    echo ($res + 2).PHP_EOL;
}

function gcd($a, $b)
{
    while ($a && $b) {
        if ($a > $b) {
            $a %= $b;
        } else {
            $b %= $a;
        }
    }

    return $a | $b;
}
/*

1
4
10 11 11 10

1
5
1 2 2 3 6
 */

<?php

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

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

    $ar = array_flip(array_flip($ar));
    krsort($ar);

    $res = -3;

    foreach ($ar as $i => $v) {
        foreach ($ar as $j => $v2) {
            if ($j > $i) {
                continue;
            }

            if (1 === gcd($v, $v2)) {
                $res = max($res, $i + $j);
            }
        }
    }

    echo ($res + 2).PHP_EOL;
}

function gcd($a, $b)
{
    while ($a && $b) {
        if ($a > $b) {
            $a %= $b;
        } else {
            $b %= $a;
        }
    }

    return $a + $b;
}
/*

1
4
10 11 11 10

1
5
1 2 2 3 6
 */


<?php

# asdasd
# asa sd

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $k) = IO::arr();
    $s = str_split(IO::str());
    $res = 0;
    $last = -1;
    $lastdigit = 0;
    $l = [];
    for($i = 0; $i < $n; $i++) {
        if($s[$i] == '*') {
            $lastdigit = $i;
        }
        if ($last == -1 && $s[$i] == '*') {
            $last = $i;
            $res++;
            $l[$lastdigit] = 1;
        } elseif ($i - $last == $k && $last != -1) {
            if($s[$i] == '*') {
                $last = $i;
                $res++;
                $l[$i] = 1;
            } elseif(!isset($l[$lastdigit])) {
                $last = $lastdigit;
                $res++;
                $l[$lastdigit] = 1;
            }
        }
    }
    if ($lastdigit != end(array_keys($l))) {
        $res++;
    }
    IO::line($res);

}

?>

<?php
$t = readline();

for ($i = 0; $i < $t; $i++) {
    $input = readline();
    list($len, $k) = explode(' ', $input);
    $input_str = readline();

    formatString($input_str, $k);
}

function formatString($str, $k)
{
    $first_pos = strpos($str, '*');
    $last_pos = strrpos($str, '*');

    if ($first_pos === $last_pos) {
        echo '1'.PHP_EOL;
    } else {
        $count = 2;
        $str[$first_pos] = 'x';
        $str[$last_pos] = 'x';
        $current_pos = $first_pos;

        while ($current_pos + $k < $last_pos) {
            /*for ($i = $current_pos + $k; $i > $current_pos; $i--) {
                if ($str[$i] == '*') {
                    $str[$i] = 'x';
                    $count++;
                    $current_pos = $i;
                    break;
                }
            }*/

            $temp = substr($str, $current_pos, $k + 1);
            $temp_last_pos = strrpos($temp, '*');
            $current_pos += $temp_last_pos;
            $count++;
        }

        echo $count.PHP_EOL;
        //echo "
 Счетчик: " . $count . "
";
    }
}


<?php

fscanf(STDIN,"%d\n",$number);
$line = trim(fgets(STDIN));

$heights = explode(' ', $line);

for ($i=0; $i < $number - 1; $i++) {
    $d[] = array($i, $i +1, abs($heights[$i] - $heights[$i + 1]));
}

$d[] = array(0, $number - 1, abs(end($heights) - $heights[0]));

$diff = array(0, 0, 1001);

Foreach ($d as $value) {
    If ($value[2] < $diff[2]) {
        $diff = $value;
    }
}

echo ($diff[0] + 1) . ' ' . ($diff[1] + 1);

?>

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

    $n = fgets($stdin);
    $numbers = explode(" ", fgets($stdin));

    $min_diff=1000000000;
    $pair = "";
    for($i=1;$i<$n;++$i){
        if(abs($numbers[$i]-$numbers[$i-1]) < $min_diff){
            $min_diff = abs($numbers[$i]-$numbers[$i-1]);
            $pair = ($i) . " " . ($i+1);
        }
    }

    if(abs($numbers[$n-1]-$numbers[0]) < $min_diff){
        $pair = intval($n) . " " . 1;
    }

    fputs($stdout, $pair);
?>

<?php

fscanf(STDIN,"%d\n",$number);
$line = trim(fgets(STDIN));

$heights = explode(' ', $line);

for ($i=0; $i < $number - 1; $i++) {
    $d[] = array($i, $i +1, abs($heights[$i] - $heights[$i + 1]));
}

$d[] = array(0, $number - 1, abs(end($heights) - $heights[0]));

$diff = array(0, 0, 1001);

Foreach ($d as $value) {
    If ($value[2] < $diff[2]) {
        $diff = $value;
    }
}

print_r($diff);

echo ($diff[0] + 1) . ' ' . ($diff[1] + 1);

?>

<?php
$stdout = fopen('php://stdout', 'w');
fputs(STDOUT, "Vhodnie dannie:  ");
$h = fopen('php://stdin', 'r');
$n = trim(fgets($h));
$s = trim(fgets($h));
$len = strlen($s);
if (($n>=1 && $n<=100))
	{
	$f=true;
for ($i=1; $i<=$n-1; $i++)
{
	$r=stripos($s,' ');
	$mas[$i]=substr($s, 0, $r);
	if (($mas[$i]<1 && $mas[$i]>1000))
	{$f=false;}
	$s=substr($s, $r+1, $len-$r-1);
	}
	$mas[$n]=$s;
	if (($mas[$n]<1 && $mas[$n]>1000))
	{$f=false;}
	if($f)
	{
fputs(STDOUT, "Vihodnie dannie:  ");
	for ($i=1; $i<=$n-1; $i++)
	{
		$d=abs($mas[$i]-$mas[$i+1]);
		$mas1[$i]=$d;
		}
		$d=abs($mas[$n]-$mas[1]);
		$mas1[$n]=$d;
		$min=$mas1[1]; $t=1;
		for ($i=1; $i<=$n; $i++)
		{
			if($mas1[$i]<$min){$min=$mas1[$i]; $t=$i;}
			}
			if ($t==$n){$t1=1;}
				else {$t1=$t+1;}
fputs(STDOUT, "$t");
fputs(STDOUT, " ");
fputs(STDOUT, "$t1");
			}
			else
	{fputs(STDOUT, "Nevernii diapazon");}
}
else
	{fputs(STDOUT, "Nevernii diapazon");}
?>


<?php
list($m) = explode(' ', trim(fgets(STDIN)));
for($k = 0; $k < $m; $k++) {
    list($a, $b) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    $j = 0;
    while (true) {
        $bFlag = true;
        $aLocalArray = $aArray;
        foreach ($aList as $sK => $sV) {
            if (isset($aArray[$sV - 1]) && isset($aArray[$sV])) {
                if ($aArray[$sV - 1] > $aArray[$sV]) {
                    $tmp = $aArray[$sV - 1];
                    $aArray[$sV - 1] = $aArray[$sV];
                    $aArray[$sV] = $tmp;
                    $bFlag = false;
                }
            }
        }
        if ($aArray == $aLocalArray) {
            break;
        }
    }

    $bFlag = true;
    for ($i = 0; $i < count($aArray) - 1; $i++) {
        if ($aArray[$i] > $aArray[$i + 1]) {
            $bFlag = false;
            break;
        }
    }
    if ($bFlag) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

//YES
//NO
//YES
//YES
//NO
//YES


<?
$n = trim(fgets(STDIN));
$numbers = explode(' ',trim(fgets(STDIN)));
$initial = array();
$initial[]=$numbers[count($numbers)-1];

for ($i=(count($numbers)-2);$i>=0;$i--){
    $cur = $numbers[$i]+$numbers[$i+1];
	$initial[]=$cur;
	$s.=(" ".$cur);
}

$s = implode(' ',array_reverse($initial));
echo $s;
?>


<?php
	$t = trim(fgets(STDIN));
	$ans = '';
	for ($o = 0; $o < $t; $o++) {
		$n = trim(fgets(STDIN));
		$prs = [];
		$pr = array_fill(1, $n, 0);
		$u_p = [];
		for ($i = 0; $i < $n; $i++) {
			$data = explode(" ", trim(fgets(STDIN)));
			if ($data[0] > 0) {
				$fnd = false;
				for ($j = 1; $j <= $data[0]; $j++) {
					if ($pr[$data[$j]] == 0) {
						$pr[$data[$j]] = 1;
						$prs[$i + 1] = true;
						$fnd = true;
						break;
					}
				}
				if (!$fnd)
					$u_p[] = $i + 1;
			} else {
				$u_p[] = $i + 1;
			}
		}
		$opt = true;
		$res = '';
		if (count($u_p) > 0) {
			for ($i = 1; $i <= $n; $i++) {
				if ($pr[$i] == 0) {
					$opt = false;
					$res = $u_p[count($u_p) - 1]." ".$i;
					break;
				}
			}
			if (!$opt) {
				$ans .= "IMPROVE\n$res\n";
			} else {
				$ans .= "OPTIMAL\n";
			}
		} else {
			$ans .= "OPTIMAL\n";
		}
	}
	print $ans;
?>


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

// Codeforces Problem 236B
// Codeforces Contest 147 Div 2 Problem B
$raw = g();
$n = $raw[0];
$ci = g();
$si[-1] = 0;
for ($i = 0; $i < $n; $i++) {
	$aij[$i] = g();
	$si[$i] = $ci[$i] + $si[$i-1];
}
$swaps = 0;
$swap[0] = "";

for ($r = 0; $r < $n; $r++) {
	for ($c = 0; $c < $ci[$r]; $c++) {
		while ($aij[$r][$c] != ($si[$r-1] + $c + 1)) {
			$rt = 0;
			while ($si[$rt] < $aij[$r][$c]) {
				$rt++;
			}
			$ct = $aij[$r][$c] - $si[$rt-1] - 1;
			$temp = $aij[$r][$c];
			$aij[$r][$c] = $aij[$rt][$ct];
			$aij[$rt][$ct] = $temp;
			$swap[$swaps] = ($r+1) . " " . ($c+1) . " " . ($rt+1) . " " . ($ct+1);
			$swaps++;
		}
	}
}
echo $swaps . "\n";
for ($i = 0; $i < $swaps; $i++) {
	echo $swap[$i] . "\n";
}

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


<?php
	$dir                    = fopen("php://stdin", 'r');
	$contents               = stream_get_contents($dir);
	$inputs                 = explode("\n",$contents);
	$hotelsNumber           = (int) explode(' ', $inputs[0])[0];
	$distance               = (int) explode(' ', $inputs[0])[1];
	$coordinates            = array_map('intval', explode(' ', $inputs[1]));
	getHotelsCount($hotelsNumber, $distance, $coordinates);

	function getHotelsCount($hotelsNumber, $distance, $coordinates)
	{
	    $hotelsCount = 2;
	    for($i = 0; $i < ($hotelsNumber-1); $i++)
	    {
		if(($coordinates[$i] + $distance) == ($coordinates[$i+1] - $distance)) {
		    $hotelsCount++;
		} elseif(($coordinates[$i] + $distance) < ($coordinates[$i+1] - $distance)) {
		    $hotelsCount += 2;
		}
	    }
	    echo $hotelsCount;
	}
?>