There are $$$n$$$ robots driving along an OX axis. There are also two walls: one is at coordinate $$$0$$$ and one is at coordinate $$$m$$$.The $$$i$$$-th robot starts at an integer coordinate $$$x_i~(0 < x_i < m)$$$ and moves either left (towards the $$$0$$$) or right with the speed of $$$1$$$ unit per second. No two robots start at the same coordinate.Whenever a robot reaches a wall, it turns around instantly and continues his ride in the opposite direction with the same speed.Whenever several robots meet at the same integer coordinate, they collide and explode into dust. Once a robot has exploded, it doesn't collide with any other robot. Note that if several robots meet at a non-integer coordinate, nothing happens.For each robot find out if it ever explodes and print the time of explosion if it happens and $$$-1$$$ otherwise.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The first line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$2 \le m \le 10^8$$$) — the number of robots and the coordinate of the right wall. The second line of each testcase contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$0 < x_i < m$$$) — the starting coordinates of the robots. The third line of each testcase contains $$$n$$$ space-separated characters 'L' or 'R' — the starting directions of the robots ('L' stands for left and 'R' stands for right). All coordinates $$$x_i$$$ in the testcase are distinct. The sum of $$$n$$$ over all testcases doesn't exceed $$$3 \cdot 10^5$$$.

For each testcase print $$$n$$$ integers — for the $$$i$$$-th robot output the time it explodes at if it does and $$$-1$$$ otherwise.

NoteHere is the picture for the seconds $$$0, 1, 2$$$ and $$$3$$$ of the first testcase:   Notice that robots $$$2$$$ and $$$3$$$ don't collide because they meet at the same point $$$2.5$$$, which is not integer.After second $$$3$$$ robot $$$6$$$ just drive infinitely because there's no robot to collide with.

<?php

function isPrime($number)
{

    if ($number == 2 || $number == 3)
        return true;

    if ($number % 2 == 0 || $number % 3 == 0)
        return false;

    $divisor = 6;
    while ($divisor * $divisor - 2 * $divisor + 1 <= $number)
    {

        if ($number % ($divisor - 1) == 0)
            return false;

        if ($number % ($divisor + 1) == 0)
            return false;

        $divisor += 6;

    }

    return true;

}

function nextPrime($n)
{
    $n = $n + 1;
    while(!isPrime($n)){
        $n++;
    }

    return $n;
}

function gcd($a, $b)
{
    while($b != 0){
        $t = $a % $b;
        $a = $b;
        $b = $t;
    }
    return $a;
}

for($t = intval(trim(fgets(STDIN))); $t > 0; $t --) {
    list($n, $m) = array_map('intval', explode(' ', trim(fgets(STDIN))));

    $positions = explode(' ', trim(fgets(STDIN)));
    $directions = explode(' ', trim(fgets(STDIN)));
    $map = [];

    foreach($positions as $index => $position){
        $map[$index] = $position;
    }

    array_multisort($positions, $directions);

    $evenPos = [];
    $oddPos = [];
    $evenDir = [];
    $oddDir = [];

    $output = [];

    for($i = 0; $i < $n; $i++){
        if($positions[$i] % 2 == 0){
            $evenPos[$i] = $positions[$i];
            $evenDir[$i] = $directions[$i];
        }

        else{
            $oddPos[$i] = $positions[$i];
            $oddDir[$i] = $directions[$i];
        }
    }

    $leftStack = [];
    $rightStack = [];

    foreach($evenPos as $i => $pos){
        if($evenDir[$i] == 'R'){
            $rightStack[] = $i;
        }

        if($evenDir[$i] == 'L'){
            //if right stack is full match them together
            if(count($rightStack)){
                $match = array_pop($rightStack);
                $output[$evenPos[$i]] = $output[$evenPos[$match]] = abs($evenPos[$i] - $evenPos[$match]) / 2;
            }

            else{
                //if we already have an unmatched left directed, match it with the next left directed
                if(count($leftStack)){
                    $match = array_pop($leftStack);
                    $output[$evenPos[$i]] = $output[$evenPos[$match]] = $evenPos[$match] + abs($evenPos[$i] - $evenPos[$match]) / 2;
                }
                else
                    $leftStack[] = $i;
            }
        }

    }

    if(count($rightStack) >= 2){
        for($i = count($rightStack); $i > 1; $i -= 2){
            $match_1 = array_pop($rightStack);
            $match_2 = array_pop($rightStack);
            $output[$evenPos[$match_1]] = $output[$evenPos[$match_2]] = $m - $evenPos[$match_1] + abs($evenPos[$match_1] - $evenPos[$match_2]) / 2;
        }
    }

    if(count($rightStack) > 0){
        if(count($leftStack)){
            $right = array_pop($rightStack);
            $left = array_pop($leftStack);
            $output[$evenPos[$right]] = $output[$evenPos[$left]] = $m - $evenPos[$right] + abs($evenPos[$right] + $evenPos[$left]) / 2;
        }

        else{
            $right = array_pop($rightStack);
            $output[$evenPos[$right]] = -1;
        }
    }

    if(count($leftStack)){
        $left = array_pop($leftStack);
        $output[$evenPos[$left]] = -1;
    }

    /**redo same for odd*/
    $leftStack = [];
    $rightStack = [];

    foreach($oddPos as $i => $pos){
        if($oddDir[$i] == 'R'){
            $rightStack[] = $i;
        }

        if($oddDir[$i] == 'L'){
            //if right stack is full match them together
            if(count($rightStack)){
                $match = array_pop($rightStack);
                $output[$oddPos[$i]] = $output[$oddPos[$match]] = abs($oddPos[$i] - $oddPos[$match]) / 2;
            }

            else{
                //if we already have an unmatched left directed, match it with the next left directed
                if(count($leftStack)){
                    $match = array_pop($leftStack);
                    $output[$oddPos[$i]] = $output[$oddPos[$match]] = $oddPos[$match] + abs($oddPos[$i] - $oddPos[$match]) / 2;
                }
                else
                    $leftStack[] = $i;
            }
        }

    }

    if(count($rightStack) >= 2){
        for($i = count($rightStack); $i > 1; $i -= 2){
            $match_1 = array_pop($rightStack);
            $match_2 = array_pop($rightStack);
            $output[$oddPos[$match_1]] = $output[$oddPos[$match_2]] = $m - $oddPos[$match_1] + abs($oddPos[$match_1] - $oddPos[$match_2]) / 2;
        }
    }

    if(count($rightStack) > 0){
        if(count($leftStack)){
            $right = array_pop($rightStack);
            $left = array_pop($leftStack);
            $output[$oddPos[$right]] = $output[$oddPos[$left]] = $m - $oddPos[$right] + abs($oddPos[$right] + $oddPos[$left]) / 2;
        }

        else{
            $right = array_pop($rightStack);
            $output[$oddPos[$right]] = -1;
        }
    }

    if(count($leftStack)){
        $left = array_pop($leftStack);
        $output[$oddPos[$left]] = -1;
    }

    foreach($map as $i => $position){
        echo $output[$position]." ";
    }
    echo "\n";

}


You are given $$$n$$$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $$$(n-1)$$$ of the given $$$n$$$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.Find any point with integer coordinates that belongs to at least $$$(n-1)$$$ given rectangles.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 132\,674$$$) — the number of given rectangles. Each the next $$$n$$$ lines contains four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$ and $$$y_2$$$ ($$$-10^9 \le x_1 < x_2 \le 10^9$$$, $$$-10^9 \le y_1 < y_2 \le 10^9$$$) — the coordinates of the bottom left and upper right corners of a rectangle.

Print two integers $$$x$$$ and $$$y$$$ — the coordinates of any point that belongs to at least $$$(n-1)$$$ given rectangles.

NoteThe picture below shows the rectangles in the first and second samples. The possible answers are highlighted.  The picture below shows the rectangles in the third and fourth samples.

<?php
define('maxx',(int)1e9);

class Rectangle
{
    public $bottom_left_x;
    public $bottom_left_y;
    public $upper_right_x;
    public $upper_right_y;
    public function __construct($xl,$yl,$xr,$yr)
    {
        $this->bottom_left_x = $xl;
        $this->bottom_left_y = $yl;
        $this->upper_right_x = $xr;
        $this->upper_right_y = $yr;
    }
    public function uion(Rectangle $a)
    {
         $this->bottom_left_x = (int)max($this->bottom_left_x,$a->bottom_left_x);
         $this->bottom_left_y = (int)max($this->bottom_left_y,$a->bottom_left_y);
         $this->upper_right_x = (int)min($this->upper_right_x,$a->upper_right_x);
         $this->upper_right_y = (int)min($this->upper_right_y,$a->upper_right_y);
         if($this->bottom_left_x <= $this->upper_right_x&&$this->bottom_left_y <= $this->upper_right_y)
         {
             //var_dump('1111111');
             return true;
         }
         return false;
    }
}
fscanf(STDIN,"%d",$number);
$arr_l = array();
$arr_r = array();
for($i = 1;$i <= $number;$i++)
{
    fscanf(STDIN,"%d %d %d %d",$xl,$yl,$xr,$yr);
    $arr_l[$i] = new Rectangle($xl,$yl,$xr,$yr);
    $arr_r[$i] = new Rectangle($xl,$yl,$xr,$yr);
}
$arr_l[0] = new Rectangle(-maxx,-maxx,maxx,maxx);
$arr_l[$number + 1] = new Rectangle(-maxx,-maxx,maxx,maxx);
$arr_r[$number + 1] = new Rectangle(-maxx,-maxx,maxx,maxx);
$arr_r[0] = new Rectangle(-maxx,-maxx,maxx,maxx);
for($i = 2;$i <= $number;$i++)
{
    $arr_l[$i]->uion($arr_l[$i-1]);
    //var_dump($arr_l[$i]);
    $arr_r[$number-$i + 1]->uion($arr_r[$number-$i + 2]);
}
for($i = 1;$i <= $number;$i++)
{
    //if($i == $number)
    // var_dump($arr_l[$i-1],$arr_r[$i+1]);
    if($arr_l[$i-1]->uion($arr_r[$i+1]))
    {
        echo $arr_l[$i-1]->bottom_left_x.' '.$arr_l[$i-1]->bottom_left_y;
        break;
    }
   // var_dump($arr_l[$i-1]);
}

<?php
define('maxx',(int)1e9);

class Rectangle
{
    public $bottom_left_x;
    public $bottom_left_y;
    public $upper_right_x;
    public $upper_right_y;
    public function __construct($xl,$yl,$xr,$yr)
    {
        $this->bottom_left_x = $xl;
        $this->bottom_left_y = $yl;
        $this->upper_right_x = $xr;
        $this->upper_right_y = $yr;
    }
    public function uion(Rectangle $a)
    {
         $this->bottom_left_x = (int)max($this->bottom_left_x,$a->bottom_left_x);
         $this->bottom_left_y = (int)max($this->bottom_left_y,$a->bottom_left_y);
         $this->upper_right_x = (int)min($this->upper_right_x,$a->upper_right_x);
         $this->upper_right_y = (int)min($this->upper_right_y,$a->upper_right_y);
         if($this->bottom_left_x <= $this->upper_right_x&&$this->bottom_left_y <= $this->upper_right_y)
         {
             //var_dump('1111111');
             return true;
         }
         return false;
    }
}
fscanf(STDIN,"%d",$number);
$arr_l = array();
$arr_r = array();
for($i = 1;$i <= $number;$i++)
{
    fscanf(STDIN,"%d %d %d %d",$xl,$yl,$xr,$yr);
    $arr_l[$i] = new Rectangle($xl,$yl,$xr,$yr);
    $arr_r[$i] = new Rectangle($xl,$yl,$xr,$yr);
}
$arr_l[0] = new Rectangle(-maxx,-maxx,maxx,maxx);
$arr_l[$number + 1] = new Rectangle(-maxx,-maxx,maxx,maxx);
$arr_r[$number + 1] = new Rectangle(-maxx,-maxx,maxx,maxx);
$arr_r[0] = new Rectangle(-maxx,-maxx,maxx,maxx);
$arr_l[$number+1] = $arr_r[0] = $arr_r[$number+1] = new Rectangle(-maxx,-maxx,maxx,maxx);
for($i = 2;$i <= $number;$i++)
{
    $arr_l[$i]->uion($arr_l[$i-1]);
    //var_dump($arr_l[$i]);
    $arr_r[$number-$i + 1]->uion($arr_r[$number-$i + 2]);
}
for($i = 1;$i <= $number;$i++)
{
    //if($i == $number)
    // var_dump($arr_l[$i-1],$arr_r[$i+1]);
    if($arr_l[$i-1]->uion($arr_r[$i+1]))
    {
        echo $arr_l[$i-1]->bottom_left_x.' '.$arr_l[$i-1]->bottom_left_y;
        break;
    }
   // var_dump($arr_l[$i-1]);
}


The Central Company has an office with a sophisticated security system. There are $$$10^6$$$ employees, numbered from $$$1$$$ to $$$10^6$$$.The security system logs entrances and departures. The entrance of the $$$i$$$-th employee is denoted by the integer $$$i$$$, while the departure of the $$$i$$$-th employee is denoted by the integer $$$-i$$$.The company has some strict rules about access to its office:  An employee can enter the office at most once per day.  He obviously can't leave the office if he didn't enter it earlier that day.  In the beginning and at the end of every day, the office is empty (employees can't stay at night). It may also be empty at any moment of the day. Any array of events satisfying these conditions is called a valid day.Some examples of valid or invalid days:  $$$[1, 7, -7, 3, -1, -3]$$$ is a valid day ($$$1$$$ enters, $$$7$$$ enters, $$$7$$$ leaves, $$$3$$$ enters, $$$1$$$ leaves, $$$3$$$ leaves).  $$$[2, -2, 3, -3]$$$ is also a valid day.  $$$[2, 5, -5, 5, -5, -2]$$$ is not a valid day, because $$$5$$$ entered the office twice during the same day.  $$$[-4, 4]$$$ is not a valid day, because $$$4$$$ left the office without being in it.  $$$[4]$$$ is not a valid day, because $$$4$$$ entered the office and didn't leave it before the end of the day. There are $$$n$$$ events $$$a_1, a_2, \ldots, a_n$$$, in the order they occurred. This array corresponds to one or more consecutive days. The system administrator erased the dates of events by mistake, but he didn't change the order of the events.You must partition (to cut) the array $$$a$$$ of events into contiguous subarrays, which must represent non-empty valid days (or say that it's impossible). Each array element should belong to exactly one contiguous subarray of a partition. Each contiguous subarray of a partition should be a valid day.For example, if $$$n=8$$$ and $$$a=[1, -1, 1, 2, -1, -2, 3, -3]$$$ then he can partition it into two contiguous subarrays which are valid days: $$$a = [1, -1~ \boldsymbol{|}~ 1, 2, -1, -2, 3, -3]$$$.Help the administrator to partition the given array $$$a$$$ in the required way or report that it is impossible to do. Find any required partition, you should not minimize or maximize the number of parts.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^6 \le a_i \le 10^6$$$ and $$$a_i \neq 0$$$).

If there is no valid partition, print $$$-1$$$. Otherwise, print any valid partition in the following format:   On the first line print the number $$$d$$$ of days ($$$1 \le d \le n$$$).  On the second line, print $$$d$$$ integers $$$c_1, c_2, \ldots, c_d$$$ ($$$1 \le c_i \le n$$$ and $$$c_1 + c_2 + \ldots + c_d = n$$$), where $$$c_i$$$ is the number of events in the $$$i$$$-th day.  If there are many valid solutions, you can print any of them. You don't have to minimize nor maximize the number of days.

NoteIn the first example, the whole array is a valid day.In the second example, one possible valid solution is to split the array into $$$[1, -1]$$$ and $$$[1, 2, -1, -2, 3, -3]$$$ ($$$d = 2$$$ and $$$c = [2, 6]$$$). The only other valid solution would be to split the array into $$$[1, -1]$$$, $$$[1, 2, -1, -2]$$$ and $$$[3, -3]$$$ ($$$d = 3$$$ and $$$c = [2, 4, 2]$$$). Both solutions are accepted.In the third and fourth examples, we can prove that there exists no valid solution. Please note that the array given in input is not guaranteed to represent a coherent set of events.


Bob has a string $$$s$$$ consisting of lowercase English letters. He defines $$$s'$$$ to be the string after removing all "a" characters from $$$s$$$ (keeping all other characters in the same order). He then generates a new string $$$t$$$ by concatenating $$$s$$$ and $$$s'$$$. In other words, $$$t=s+s'$$$ (look at notes for an example).You are given a string $$$t$$$. Your task is to find some $$$s$$$ that Bob could have used to generate $$$t$$$. It can be shown that if an answer exists, it will be unique.

The first line of input contains a string $$$t$$$ ($$$1 \leq |t| \leq 10^5$$$) consisting of lowercase English letters.

Print a string $$$s$$$ that could have generated $$$t$$$. It can be shown if an answer exists, it is unique. If no string exists, print ":(" (without double quotes, there is no space between the characters).

NoteIn the first example, we have $$$s = $$$ "aaaaa", and $$$s' = $$$ "".In the second example, no such $$$s$$$ can work that will generate the given $$$t$$$.In the third example, we have $$$s = $$$ "ababacac", and $$$s' = $$$ "bbcc", and $$$t = s + s' = $$$ "ababacacbbcc".

<?php
# 1146B

$input = fopen('php://stdin', 'rb');
$str = trim(fgets($input));
$length = strlen($str);
$clearStr = str_replace('a', '', $str);
$clearStrLength = strlen($clearStr);

if ($clearStr === '') {
    die($str);
}

if ($clearStrLength % 2) {
    die(':(');
}
$_sLength = $clearStrLength/2;
$_s = substr($clearStr, $_sLength * -1);
$s = substr($str, 0, $length - $_sLength);
if (
    substr($str, $length - strlen($_s)) === $_s
    && substr($clearStr, 0, $clearStrLength/2) === $_s
) {
    echo $s;
} else {
    echo ':(';
}

<?php
	$s = str_split(trim(fgets(STDIN)));

	$ns = [];
	$ans = '';

	for($i = 0; $i<count($s); $i++){
		if($s[$i] != 'a') $ns[] = $s[$i];
	}
	$ok = true;
	if(count($ns) > 0){
		if(count($ns) % 2 == 0){
			if(substr(implode('', $ns), 0, count($ns)/2) == substr(implode('', $ns), count($ns)/2, count($ns))){

				for($i = count($s)-1; $i>count($s)-count($ns)/2-1; $i--){
					//echo "(".$s[$i].")";
					if($s[$i] == 'a'){
						echo ":(";
						$ok = false;
						break;
					}
				}
				if($ok) echo substr(implode('', $s), 0, -(count($ns)/2));
			}else{
				echo ":(";
			}
		}else{
			echo ":(";
		}
	}else{
		echo implode('',$s);
	}
?>

<?php
# 1146B

$input = fopen('php://stdin', 'rb');
$str = trim(fgets($input));
$length = strlen($str);
$clearStr = str_replace('a', '', $str);
$clearStrLength = strlen($clearStr);

if ($clearStr === '') {
    die($str);
}

if ($clearStrLength % 2) {
    die(':(');
}

$_s = substr($clearStr, $clearStrLength/2 * -1);
if (
    substr($str, $length - strlen($_s)) === $_s
    && substr($clearStr, 0, $clearStrLength/2) === $_s
) {
    echo $_s;
} else {
    echo ':(';
}

<?php
	$s = str_split(trim(fgets(STDIN)));

	$ns = [];
	$ans = '';

	for($i = 0; $i<count($s); $i++){
		if($s[$i] != 'a') $ns[] = $s[$i];
	}
	$ok = true;
	if(count($ns) > 0){
		if(count($ns) % 2 == 0){
			if(substr(implode('', $ns), 0, count($ns)/2) == substr(implode('', $ns), count($ns)/2, count($ns))){

				for($i = count($s)-1; $i>count($s)-count($ns)/2; $i--){
					if($s[$i] == 'a'){
						echo ":(";
						$ok = false;
						break;
					}
				}
				if($ok) echo substr(implode('', $s), 0, -(count($ns)/2));
			}else{
				echo ":(";
			}
		}else{
			echo ":(";
		}
	}else{
		echo implode('',$s);
	}
?>

<?php
	$s = str_split(trim(fgets(STDIN)));

	$ns = [];
	$ans = '';

	for($i = 0; $i<count($s); $i++){
		if($s[$i] != 'a') $ns[] = $s[$i];
	}
	$ok = true;
	if(count($ns) > 0){
		if(count($ns) % 2 == 0){
			for($i = count($s)-1; $i>count($s)-count($ns)/2; $i--){
				if($s[$i] == 'a'){
					echo ":(";
					$ok = false;
					break;
				}
			}
			if($ok) echo substr(implode('', $s), 0, -(count($ns)/2));
		}else{
			echo ":(";
		}
	}else{
		echo implode('',$s);
	}
?>

<?php
	$s = str_split(trim(fgets(STDIN)));

	$ns = [];
	$ans = '';

	for($i = 0; $i<count($s); $i++){
		if($s[$i] != 'a') $ns[] = $s[$i];
	}
	$ok = true;
	if(count($ns) > 0){
		if(count($ns) % 2 == 0){
			if(substr(implode('', $ns), 0, count($ns)/2) == substr(implode('', $ns), count($ns)/2, count($ns))){

				for($i = count($s)-1; $i>count($s)-count($ns)/2-1; $i--){
					echo "(".$s[$i].")";
					if($s[$i] == 'a'){
						echo ":(";
						$ok = false;
						break;
					}
				}
				if($ok) echo substr(implode('', $s), 0, -(count($ns)/2));
			}else{
				echo ":(";
			}
		}else{
			echo ":(";
		}
	}else{
		echo implode('',$s);
	}
?>


Two players decided to play one interesting card game.There is a deck of $$$n$$$ cards, with values from $$$1$$$ to $$$n$$$. The values of cards are pairwise different (this means that no two different cards have equal values). At the beginning of the game, the deck is completely distributed between players such that each player has at least one card. The game goes as follows: on each turn, each player chooses one of their cards (whichever they want) and puts on the table, so that the other player doesn't see which card they chose. After that, both cards are revealed, and the player, value of whose card was larger, takes both cards in his hand. Note that as all cards have different values, one of the cards will be strictly larger than the other one. Every card may be played any amount of times. The player loses if he doesn't have any cards.For example, suppose that $$$n = 5$$$, the first player has cards with values $$$2$$$ and $$$3$$$, and the second player has cards with values $$$1$$$, $$$4$$$, $$$5$$$. Then one possible flow of the game is:The first player chooses the card $$$3$$$. The second player chooses the card $$$1$$$. As $$$3>1$$$, the first player gets both cards. Now the first player has cards $$$1$$$, $$$2$$$, $$$3$$$, the second player has cards $$$4$$$, $$$5$$$.The first player chooses the card $$$3$$$. The second player chooses the card $$$4$$$. As $$$3<4$$$, the second player gets both cards. Now the first player has cards $$$1$$$, $$$2$$$. The second player has cards $$$3$$$, $$$4$$$, $$$5$$$.The first player chooses the card $$$1$$$. The second player chooses the card $$$3$$$. As $$$1<3$$$, the second player gets both cards. Now the first player has only the card $$$2$$$. The second player has cards $$$1$$$, $$$3$$$, $$$4$$$, $$$5$$$.The first player chooses the card $$$2$$$. The second player chooses the card $$$4$$$. As $$$2<4$$$, the second player gets both cards. Now the first player is out of cards and loses. Therefore, the second player wins.Who will win if both players are playing optimally? It can be shown that one of the players has a winning strategy.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows. The first line of each test case contains three integers $$$n$$$, $$$k_1$$$, $$$k_2$$$ ($$$2 \le n \le 100, 1 \le k_1 \le n - 1, 1 \le k_2 \le n - 1, k_1 + k_2 = n$$$) — the number of cards, number of cards owned by the first player and second player correspondingly. The second line of each test case contains $$$k_1$$$ integers $$$a_1, \dots, a_{k_1}$$$ ($$$1 \le a_i \le n$$$) — the values of cards of the first player. The third line of each test case contains $$$k_2$$$ integers $$$b_1, \dots, b_{k_2}$$$ ($$$1 \le b_i \le n$$$) — the values of cards of the second player. It is guaranteed that the values of all cards are different.

For each test case, output "YES" in a separate line, if the first player wins. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower).

NoteIn the first test case of the example, there is only one possible move for every player: the first player will put $$$2$$$, the second player will put $$$1$$$. $$$2>1$$$, so the first player will get both cards and will win.In the second test case of the example, it can be shown that it is the second player who has a winning strategy. One possible flow of the game is illustrated in the statement.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
     $e = explode(" ", trim(fgets(STDIN)));
     $f = explode(" ", trim(fgets(STDIN)));
     $g = max($e);
     $h = max($f);
     if($g > $h)
     {
          print "YES\n";
     }
     else
     {
          print "NO\n";
     }
}
?>

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

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

for (; $t!=0 ; $t--){
	list($n, $k1, $k2) = explode(' ', trim(fgets(STDIN)));
	$a1 = explode(' ', trim(fgets(STDIN)));
	$a2 = explode(' ', trim(fgets(STDIN)));

	if(max($a1) > max($a2)){
		echo "YES\n";
	} else {
		echo "NO\n";
	}
}

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));

for ($i=0;$i<$t;$i++)
{
    $x = trim(fgets($handle));
    $a = explode(' ', $x);
    $p = trim(fgets($handle));
    $p1 = explode(' ', $p);
    $p2 = trim(fgets($handle));
    $p22 = explode(' ', $p2);
    $max=0;
    for($j=0;$j<$a[1];$j++)
    {
        if($p1[$j]>$max)
        {
            $max=$p1[$j];
        }
    }
    $max1=0;
    for($j=0;$j<$a[2];$j++)
    {
        if($p22[$j]>$max1)
        {
            $max1=$p22[$j];
        }
    }
    if($max<$max1)
    {
        echo "NO"."\n";
    }else
    {
        echo "YES"."\n";
    }
}

?>


One day Vasya got hold of information on the Martian dollar course in bourles for the next n days. The buying prices and the selling prices for one dollar on day i are the same and are equal to ai. Vasya has b bourles. He can buy a certain number of dollars and then sell it no more than once in n days. According to Martian laws, one can buy only an integer number of dollars. Which maximal sum of money in bourles can Vasya get by the end of day n?

The first line contains two integers n and b (1 ≤ n, b ≤ 2000) — the number of days and the initial number of money in bourles. The next line contains n integers ai (1 ≤ ai ≤ 2000) — the prices of Martian dollars.

Print the single number — which maximal sum of money in bourles can Vasya get by the end of day n.

<?php
$line1 = explode(' ', trim(fgets(STDIN)));
$n = intval($line1[0]);
$b = intval($line1[1]);
$prices = explode(' ', trim(fgets(STDIN)));

$k = $b;

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

	$t = floor($b / $prices[$i]);
	for($j  = $i + 1; $j < $n; $j++){
		$tmp = $prices[$j] * $t + $b - $t * $prices[$i];
		if($k < $tmp)$k = $tmp;
	}
}
echo $b > $k ? $b : $k;

<?php
$line1 = explode(' ', trim(fgets(STDIN)));
$n = intval($line1[0]);
$b = intval($line1[1]);
$prices = explode(' ', trim(fgets(STDIN)));

$k = $b;

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

	$t = $b / $prices[$i];
	for($j  = $i + 1; $j < $n; $j++){
		$tmp = $prices[$j] * $t + $b - $t * $prices[$i];
		if($k < $tmp)$k = $tmp;
	}
}
echo $b > $k ? $b : $k;

<?php
$line1 = explode(' ', trim(fgets(STDIN)));
$n = intval($line1[0]);
$b = intval($line1[1]);
$prices = explode(' ', trim(fgets(STDIN)));

$segments = array();
for($i = 0; $i < $n; $i++){
	for($j = $i + 1; $j < $n; $j++){
		if($prices[$i] > $prices[$j]){
			break;
		}
		if($j + 1 == $n){// end of line
			$segments[] = array($i, $j);
			$i = $j;
			break;
		}
		if($prices[$j] > $prices[$j + 1]){// end of a segment
			$segments[] = array($i, $j);
			$i = $j;
			break;
		}
	}
}

foreach($segments as $segment){
	$unit = floor($b / $prices[$segment[0]]);
	$b -= $unit * $prices[$segment[0]];
	$sell = $unit * $prices[$segment[1]];
	$b += $sell;
}
echo $b;

<?php
$line1 = explode(' ', trim(fgets(STDIN)));
$n = intval($line1[0]);
$b = intval($line1[1]);
$prices = explode(' ', trim(fgets(STDIN)));

$segments = array();
for($i = 0; $i < $n; $i++){
	for($j = $i + 1; $j < $n; $j++){
		if($prices[$i] > $prices[$j]){
			break;
		}
		if($j + 1 == $n){// end of line
			$segments[] = array($i, $j);
			break;
		}
		if($prices[$j] > $prices[$j + 1]){// end of a segment
			$segments[] = array($i, $j);
			$i = $j;
			break;
		}
	}
}

foreach($segments as $segment){
	$unit = floor($b / $prices[$segment[0]]);
	$b -= $unit * $prices[$segment[0]];
	$sell = $unit * $prices[$segment[1]];
	$b += $sell;
}
echo $b;

<?php
$line1 = explode(' ', trim(fgets(STDIN)));
$n = intval($line1[0]);
$b = intval($line1[1]);
$prices = explode(' ', trim(fgets(STDIN)));

$segments = array();
for($i = 0; $i < $n; $i++){
	for($j = $i + 1; $j < $n; $j++){
		if($prices[$i] > $prices[$j]){
			break;
		}
		if($j + 1 == $n){// end of line
			$segments[] = array($i, $j);
			$i = $j + 1;
			break;
		}
		if($prices[$j] > $prices[$j + 1]){// end of a segment
			$segments[] = array($i, $j);
			$i = $j + 1;
			break;
		}
	}
}

foreach($segments as $segment){
	$unit = floor($b / $prices[$segment[0]]);
	$b -= $unit * $prices[$segment[0]];
	$sell = $unit * $prices[$segment[1]];
	$b += $sell;
}
echo $b;

<?php
$line1 = explode(' ', trim(fgets(STDIN)));
$n = intval($line1[0]);
$b = intval($line1[1]);
$prices = explode(' ', trim(fgets(STDIN)));

$segments = array();
for($i = 0; $i < $n; $i++){
	$max = $i;
	for($j = $i + 1; $j < $n; $j++){
		if($prices[$j] > $prices[$max]){
			$max = $j;
			break;
		}
	}
	if($max > $i){
		$segments[] = array($i, $max);
	}
}

foreach($segments as $segment){
	$unit = floor($b / $prices[$segment[0]]);
	$b -= $unit * $prices[$segment[0]];
	$sell = $unit * $prices[$segment[1]];
	$b += $sell;
}
echo $b;

<?php
$line1 = explode(' ', trim(fgets(STDIN)));
$n = intval($line1[0]);
$b = intval($line1[1]);
$prices = explode(' ', trim(fgets(STDIN)));

$segments = array();
for($i = 0; $i < $n; $i++){
	$max = $i;
	for($j = $i + 1; $j < $n; $j++){
		if($prices[$j] > $prices[$max]){
			$max = $j;
			break;
		}
	}
	if($max > $i){
		$segments[] = array($i, $max);
	}
}
$max_segment = array();
$max_diff = 0;
foreach($segments as $segment){
	$diff = $prices[$segment[1]] - $prices[$segment[0]];
	if($diff > $max_diff){
		$max_diff = $diff;
		$max_segment = $segment;
	}
}
if(!empty($max_segment)){
	$unit = floor($b / $prices[$max_segment[0]]);
	$b -= $unit * $prices[$max_segment[0]];
	$sell = $unit * $prices[$max_segment[1]];
	$b += $sell;
}
echo $b;


You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below:  $$$[1], [2], [3, 4, 5]$$$;  $$$[1], [2, 3], [4, 5]$$$;  $$$[1], [2, 3, 4], [5]$$$;  $$$[1, 2], [3], [4, 5]$$$;  $$$[1, 2], [3, 4], [5]$$$;  $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 < r_2 < \dots < r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway.

<?php

$c = trim(fgets(STDIN));
for($i = 0; $i<$c; $i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $b = explode(" ", trim(fgets(STDIN)));
    $val = array();
    $n = 0;
    $count = 0;
    foreach($b as $k => $v){
        if($v % 2 == 1){
            $count += 1;
            if($count <= $a[1]){
                $val[] = $k + 1;
            }
        }
    }
    $p = $count % $a[1];
    $val[count($val) - 1] = count($b);
    if(($count < $a[1] || ($count + 1 - $a[1]) % 2 == 0)){
        echo "NO\n";
        continue;
    } else {
        echo "YES\n";
        foreach($val as $r){
            echo $r." ";
        }
        echo "\n";
    }
}

?>

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $c; $j++){
    list($x,$y) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iCount = $y;
    $aTest = [];
    $bFlag = false;
    foreach ($aArray as $sK => $sV){
        if($sV % 2 != 0){
            if($iCount > 1){
                $aTest[] = $sK + 1;
                $iCount--;
            } elseif($iCount == 1 && test($aArray,$sK,$x) % 2 != 0){
                $aTest[] = $x;
                $iCount--;
                $bFlag = true;
            } else {
               $iCount--;
            }
        }
    }
    if(!$bFlag){
        echo "NO\n";
    } else {
        echo "YES\n";
        echo implode(" ",$aTest). "\n";
    }
}

function test(&$aArray, $iStart, $iEnd){
    $iT = 0;
    for($i = $iStart; $i < $iEnd; $i++){
        $iT += $aArray[$i];
    }
    return $iT;
}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $c; $j++){
    list($x,$y) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iCount = $y;
    $aTest = [];
    foreach ($aArray as $sK => $sV){
        if($sV % 2 != 0){
            if($iCount > 1){
                $aTest[] = $sK + 1;
                $iCount--;
            } elseif($iCount == 1){
                $aTest[] = $x;
                $iCount--;
            } else {
                $aTest[] = $x;
                $iCount--;
            }
        }
    }
    if(count($aTest) != $y){
        echo "NO\n";
    } else {
        echo "YES\n";
        echo implode(" ",$aTest). "\n";
    }

}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $c; $j++){
    list($x,$y) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iCount = $y;
    $aTest = [];
    $bFlag = false;
    $aArrayB = $aArray;
    $aArrayC = $aArray;
    foreach ($aArray as $sK => $sV){
        $aArrayB = $aArray;
        if($sV % 2 != 0){
            if($iCount > 1){
                $aTest[] = $sK + 1;
                $iCount--;
            } elseif($iCount == 1 && array_sum(array_slice($aArrayB,$sK,false)) % 2 != 0){
                $aTest[] = $x;
                $iCount--;
                $bFlag = true;
            }
        }
    }
    if(!$bFlag){
        echo "NO\n";
    } else {
        echo "YES\n";
        echo implode(" ",$aTest). "\n";
    }

}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $c; $j++){
    list($x,$y) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iCount = $y;
    $aTest = [];
    $bFlag = false;
    foreach ($aArray as $sK => $sV){
        if($sV % 2 != 0){
            $aArrayB = array_slice($aArray,$sK,$x,false);
            if($iCount > 1){
                $aTest[] = $sK + 1;
                $iCount--;
            } elseif($iCount == 1 && array_sum($aArrayB) % 2 != 0){
                $aTest[] = $x;
                $iCount--;
                $bFlag = true;
            }
        }
    }
    if(!$bFlag){
        echo "NO\n";
    } else {
        echo "YES\n";
        echo implode(" ",$aTest). "\n";
    }

}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $c; $j++){
    list($x,$y) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iCount = $y;
    $aTest = [];
    $bFlag = false;
    $aArrayB = $aArray;
    foreach ($aArray as $sK => $sV){
        if($sV % 2 != 0){
            if($iCount > 1){
                $aTest[] = $sK + 1;
                $iCount--;
            } elseif($iCount == 1 && array_sum(array_slice($aArrayB,$sK - 1)) % 2 != 0){
                $aTest[] = $x;
                $iCount--;
                $bFlag = true;
            }
        }
    }
    if(!$bFlag){
        echo "NO\n";
    } else {
        echo "YES\n";
        echo implode(" ",$aTest). "\n";
    }

}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $c; $j++){
    list($x,$y) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iCount = $y;
    $aTest = [];
    foreach ($aArray as $sK => $sV){
        if($sV % 2 != 0){
            if($iCount > 1){
                $aTest[] = $sK + 1;
                $iCount--;
            } else{
                $aTest[] = $x;
                $iCount--;
            }
        }
    }
    if(count($aTest) != $y){
        echo "NO\n";
    } else {
        echo "YES\n";
        echo implode(" ",$aTest). "\n";
    }

}

<?php

$c = trim(fgets(STDIN));
for($i = 0; $i<$c; $i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $b = explode(" ", trim(fgets(STDIN)));
    $val = array();
    $count = 0;
    foreach($b as $k => $v){
        if($v % 2 == 1){
            $count += 1;
            if($count <= $a[1]){
                $val[] = $k + 1;
            }

        }
    }
    $val[count($val) - 1] = count($b);
    if($count < $a[1] || $count - 1 == $a[1]){
        echo "NO\n";
        continue;
    } else {
        echo "YES\n";
        foreach($val as $r){
            echo $r." ";
        }
        echo "\n";
    }
}

?>

<?php

$c = trim(fgets(STDIN));
for($i = 0; $i<$c; $i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $b = explode(" ", trim(fgets(STDIN)));
    $val = array();
    $count = 0;
    foreach($b as $k => $v){
        if($v % 2 == 1){
            $count += 1;
            if($count <= $a[1]){
                $val[] = $k + 1;
            }

        }
    }
    $p = $count % $a[1];
    $val[count($val) - 1] = count($b);
    if($count < $a[1] || ($p % 2 == 1)){
        echo "NO\n";
        continue;
    } else {
        echo "YES\n";
        foreach($val as $r){
            echo $r." ";
        }
        echo "\n";
    }
}

?>

<?php

$c = trim(fgets(STDIN));
for($i = 0; $i<$c; $i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $b = explode(" ", trim(fgets(STDIN)));
    $val = array();
    $count = 0;
    foreach($b as $k => $v){
        if($v % 2 == 1){
            $count += 1;
            if($count <= $a[1]){
                $val[] = $k + 1;
            }

        }
    }
    $val[count($val) - 1] = count($b);
    if($count < $a[1] || $count % $a[1] == 1){
        echo "NO\n";
        continue;
    } else {
        echo "YES\n";
        foreach($val as $r){
            echo $r." ";
        }
        echo "\n";
    }
}

?>

<?php

$c = trim(fgets(STDIN));
for($i = 0; $i<$c; $i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $b = explode(" ", trim(fgets(STDIN)));
    $val = array();
    $n = 0;
    $count = 0;
    foreach($b as $k => $v){
        if($v % 2 == 1){
            $count += 1;
            $n += $v;
            if($count <= $a[1]){
                $val[] = $k + 1;
            }
        }
    }
    $p = $count % $a[1];
    $val[count($val) - 1] = count($b);
    if($count < $a[1] || (($p % 2 == 1) || ($n % 2 == 0 && $a[1] == 1))){
        echo "NO\n";
        continue;
    } else {
        echo "YES\n";
        foreach($val as $r){
            echo $r." ";
        }
        echo "\n";
    }
}

?>

<?php

$c = trim(fgets(STDIN));
for($i = 0; $i<$c; $i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $b = explode(" ", trim(fgets(STDIN)));
    $val = array();
    $count = 0;
    foreach($b as $k => $v){
        if($v % 2 == 1){
            $count += 1;
            $val[] = $k + 1;
        }
    }
    $val[count($val) - 1] = count($b);
    if($count < $a[1]){
        echo "NO\n";
        continue;
    } else {
        echo "YES\n";
        foreach($val as $r){
            echo $r." ";
        }
        echo "\n";
    }
}

?>

<?php

$c = trim(fgets(STDIN));
for($i = 0; $i<$c; $i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $b = explode(" ", trim(fgets(STDIN)));
    $val = array();
    $n = 0;
    $count = 0;
    foreach($b as $k => $v){
        if($v % 2 == 1){
            $count += 1;
            $n += $v;
            if($count <= $a[1]){
                $val[] = $k + 1;
            }
        }
    }
    $p = $count % $a[1];
    $val[count($val) - 1] = count($b);
    if($count < $a[1] || (($p % 2 == 1) || ($n % 2 == 0))){
        echo "NO\n";
        continue;
    } else {
        echo "YES\n";
        foreach($val as $r){
            echo $r." ";
        }
        echo "\n";
    }
}

?>

<?php

$c = trim(fgets(STDIN));
for($i = 0; $i<$c; $i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $b = explode(" ", trim(fgets(STDIN)));
    $val = array();
    $count = 0;
    foreach($b as $k => $v){
        if($v % 2 == 1){
            $count += 1;
            if($count <= $a[1]){
                $val[] = $k + 1;
            }

        }
    }
    $p = $count % $a[1];
    echo $p;
    $val[count($val) - 1] = count($b);
    if($count < $a[1] || ($p % 2 == 1)){
        echo "NO\n";
        continue;
    } else {
        echo "YES\n";
        foreach($val as $r){
            echo $r." ";
        }
        echo "\n";
    }
}

?>

<?php

$c = trim(fgets(STDIN));
for($i = 0; $i<$c; $i++){
    $a = explode(" ", trim(fgets(STDIN)));
    $b = explode(" ", trim(fgets(STDIN)));
    $val = array();
    $count = 0;
    foreach($b as $k => $v){
        if($v % 2 == 1){
            $count += 1;
            if($count <= $a[1]){
                $val[] = $k + 1;
            }

        }
    }
    $val[count($val) - 1] = count($b);
    if($count < $a[1]){
        echo "NO\n";
        continue;
    } else {
        echo "YES\n";
        foreach($val as $r){
            echo $r." ";
        }
        echo "\n";
    }
}

?>

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $c; $j++){
    list($x,$y) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iCount = $y;
    $aTest = [];
    $bFlag = false;
    $aArrayB = $aArray;
    $aArrayC = $aArray;
    foreach ($aArray as $sK => $sV){
        $aArrayB = $aArray;
        if($sV % 2 != 0){
            if($iCount > 1){
                $aTest[] = $sK + 1;
                $iCount--;
            } elseif($iCount == 1 && array_sum(array_slice($aArrayB,$sK,true)) % 2 != 0){
                $aTest[] = $x;
                $iCount--;
                $bFlag = true;
            }
        }
    }
    if(!$bFlag){
        echo "NO\n";
    } else {
        echo "YES\n";
        echo implode(" ",$aTest). "\n";
    }

}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $c; $j++){
    list($x,$y) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iCount = $y;
    $aTest = [];
    foreach ($aArray as $sK => $sV){
        if($sV % 2 != 0){
            if($iCount > 0){
                $aTest[] = $sK + 1;
                $iCount--;
            } else{
                $aTest[] = $x;
                $iCount--;
            }
        }
    }
    if(count($aTest) != $y){
        echo "NO\n";
    } else {
        echo "YES\n";
        echo implode(" ",$aTest). "\n";
    }

}

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $c; $j++){
    list($x,$y) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iCount = $y;
    $aTest = [];
    $bFlag = false;
    $aArrayB = $aArray;
    foreach ($aArray as $sK => $sV){
        if($sV % 2 != 0){
            if($iCount > 1){
                $aTest[] = $sK + 1;
                $iCount--;
            } elseif($iCount == 1 && array_sum(array_slice($aArrayB,$sK)) % 2 != 0){
                $aTest[] = $x;
                $iCount--;
                $bFlag = true;
            }
        }
    }
    if(!$bFlag){
        echo "NO\n";
    } else {
        echo "YES\n";
        echo implode(" ",$aTest). "\n";
    }

}


Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.

The first line of the input contains two integers n and d (1 ≤ n, d ≤ 100) — the number of opponents and the number of days, respectively. The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.

Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents.

NoteIn the first and the second samples, Arya will beat all present opponents each of the d days.In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.

<?php

$lines  = @file("php://stdin");
$info = explode(' ', array_shift($lines));
$enemies = $info[0];
$days = $info[1];
$seq = [];
foreach($lines as $line){
    if(in_array('0', str_split($line))) $seq[] = 1;
    else $seq[] = 0;
}
$len = 0;

for($i =0; $i < $days; $i++){
    if($seq[$i] == 1){
        $cur_len =0;
        $j=$i;
        do{
            $cur_len++;
            $j++;
        }
        while($seq[$j] == 1);
        if($cur_len > $len) $len = $cur_len;
        $i = $j;
    }
}

print_r( $len);

<?php
   $s=explode(" ",trim(fgets(STDIN)));
    $n=$s[0];
     $m=$s[1];
$counter=0;
$maxi=0;
   for($i=0;$i<$m;$i++){
         $x=trim(fgets(STDIN));
         if(strpos($x,"0")!==false){
              $counter++;
         }else{
               if($counter>$maxi)
                      $maxi=$counter;
               $counter=0;
          }
    }
     if($counter>$maxi)
                      $maxi=$counter;
    echo $maxi;
?>


You are given two positive integers $$$a$$$ and $$$b$$$. In one move you can increase $$$a$$$ by $$$1$$$ (replace $$$a$$$ with $$$a+1$$$). Your task is to find the minimum number of moves you need to do in order to make $$$a$$$ divisible by $$$b$$$. It is possible, that you have to make $$$0$$$ moves, as $$$a$$$ is already divisible by $$$b$$$. You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).

For each test case print the answer — the minimum number of moves you need to do in order to make $$$a$$$ divisible by $$$b$$$.

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

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

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

        $a = intval($in_str[0]) ;
        $b = intval($in_str[1]) ;

        $c = intval($a / $b) ;

        if($b * $c == $a) echo "0\n" ;
        else echo $b * ($c + 1) - $a . "\n" ;
    }
?>

<?php

$num = (int)readline();

$k = 0;

$array = array();

for ($i = 0; $i < $num; $i++) {
    $str = explode(' ' , readline());
    if($str[0] % $str[1] == 0) {
        $k = 0;
    } else {
        $k = abs($str[0] - ((int)($str[0]/$str[1]) + 1) * $str[1]);
    }
    array_push($array , $k);
}

foreach ($array as $elem) {
    echo $elem."\n";
}


Young boy Artem tries to paint a picture, and he asks his mother Medina to help him. Medina is very busy, that's why she asked for your help.Artem wants to paint an $$$n \times m$$$ board. Each cell of the board should be colored in white or black. Lets $$$B$$$ be the number of black cells that have at least one white neighbor adjacent by the side. Let $$$W$$$ be the number of white cells that have at least one black neighbor adjacent by the side. A coloring is called good if $$$B = W + 1$$$. The first coloring shown below has $$$B=5$$$ and $$$W=4$$$ (all cells have at least one neighbor with the opposite color). However, the second coloring is not good as it has $$$B=4$$$, $$$W=4$$$ (only the bottom right cell doesn't have a neighbor with the opposite color).  Please, help Medina to find any good coloring. It's guaranteed that under given constraints the solution always exists. If there are several solutions, output any of them.

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 20$$$). Each of the next $$$t$$$ lines contains two integers $$$n, m$$$ ($$$2 \le n,m \le 100$$$) — the number of rows and the number of columns in the grid.

For each test case print $$$n$$$ lines, each of length $$$m$$$, where $$$i$$$-th line is the $$$i$$$-th row of your colored matrix (cell labeled with 'B' means that the cell is black, and 'W' means white). Do not use quotes. It's guaranteed that under given constraints the solution always exists.

NoteIn the first testcase, $$$B=3$$$, $$$W=2$$$.In the second testcase, $$$B=5$$$, $$$W=4$$$. You can see the coloring in the statement.

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

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

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

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

        $cc = intval(($m + 1) / 2) ;
        $bb = $n * $m ;

        for($i = 0; $i < $n; $i ++)
        {
            if($i&1) $ss = str_repeat("WB", $cc) ;
            else $ss = str_repeat("BW", $cc) ;

            if($i == $n - 1 && $bb%2 == 0)
            {
                $ss[$m - 2] = 'B' ;
                $ss[$m - 1] = 'B' ;
            }

            echo substr($ss, 0, $m) . "\n" ;
        }
    }
?>


Try guessing the statement from this picture:   You are given a non-negative integer $$$d$$$. You have to find two non-negative real numbers $$$a$$$ and $$$b$$$ such that $$$a + b = d$$$ and $$$a \cdot b = d$$$.

The first line contains $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. Each test case contains one integer $$$d$$$ $$$(0 \le d \le 10^3)$$$.

For each test print one line. If there is an answer for the $$$i$$$-th test, print "Y", and then the numbers $$$a$$$ and $$$b$$$. If there is no answer for the $$$i$$$-th test, print "N". Your answer will be considered correct if $$$|(a + b) - a \cdot b| \le 10^{-6}$$$ and $$$|(a + b) - d| \le 10^{-6}$$$.

<?php

class InputReader {
	protected $_fh;

	public function __construct($fileHandler = STDIN)
	{
		$this->_fh = $fileHandler;
	}

	public function readFloat()
	{
		$d = trim(fgets($this->_fh));

		return (float)$d;
	}

	public function readInt()
	{
		$d = trim(fgets($this->_fh));

		return (int)$d;
	}

	public function readString()
	{
		$s = trim(fgets($this->_fh));

		return $s;
	}

	public function readArrayOfInt($size, $indexFrom = 0)
	{
		$a = [];
		$ind = $indexFrom;
		foreach (explode(' ', fgets($this->_fh)) as $item) {
			$a[$ind++] = (int)$item;
		}

		return $a;
	}

	public function readArrayOfString($size, $indexFrom = 0)
	{
		$a = [];
		$ind = $indexFrom;
		foreach (explode(' ', fgets($this->_fh)) as $item) {
			$a[$ind++] = $item;
		}

		return $a;
	}
}

function ntimes($n, $func, $returnResults = false) {
	$a = [];
	for ($i=1; $i<=$n; $i++) {
		$result = $func();

		if ($returnResults) {
			$a[$i] = $result;
		}
	}

	return $a;
}

$ir = new InputReader();
$testsCount = $ir->readInt();
ntimes($testsCount, function() use ($ir) {
	$d = $ir->readInt();

	if ($d==0) {
		printf("Y %01.9f %01.9f\n", 0.0, 0.0);
	} else if ($d<4) {
		printf("N\n");
	} else {
		$discr = sqrt($d*$d/4 - $d);
		$b1 = $discr + $d/2;
		$b2 = -$discr + $d/2;
		$a1 = $d - $b1;
		$a2 = $d - $b2;

		if ($a1>=0 && $b1>=0) {
			printf("Y %01.9f %01.9f\n", $a1, $b1);
		} elseif ($a2>=0 && $b2>=0) {
			printf("Y %01.9f %01.9f\n", $a2, $b2);
		} else {
			printf("N\n");
		}
	}
});

<?php

class InputReader {
	protected $_fh;

	public function __construct($fileHandler = STDIN)
	{
		$this->_fh = $fileHandler;
	}

	public function readFloat()
	{
		$d = trim(fgets($this->_fh));

		return (float)$d;
	}

	public function readInt()
	{
		$d = trim(fgets($this->_fh));

		return (int)$d;
	}

	public function readString()
	{
		$s = trim(fgets($this->_fh));

		return $s;
	}

	public function readArrayOfInt($size, $indexFrom = 0)
	{
		$a = [];
		$ind = $indexFrom;
		foreach (explode(' ', fgets($this->_fh)) as $item) {
			$a[$ind++] = (int)$item;
		}

		return $a;
	}

	public function readArrayOfString($size, $indexFrom = 0)
	{
		$a = [];
		$ind = $indexFrom;
		foreach (explode(' ', fgets($this->_fh)) as $item) {
			$a[$ind++] = $item;
		}

		return $a;
	}
}

function ntimes($n, $func, $returnResults = false) {
	$a = [];
	for ($i=1; $i<=$n; $i++) {
		$result = $func();

		if ($returnResults) {
			$a[$i] = $result;
		}
	}

	return $a;
}

$ir = new InputReader();
$testsCount = $ir->readInt();
ntimes($testsCount, function() use ($ir) {
	$d = $ir->readInt();

	if ($d==0) {
		printf("YES %01.9f %01.9f\n", 0.0, 0.0);
	} else if ($d<4) {
		printf("NO\n");
	} else {
		$discr = sqrt($d*$d/4 - $d);
		$b1 = $discr + $d/2;
		$b2 = -$discr + $d/2;
		$a1 = $d - $b1;
		$a2 = $d - $b2;

		if ($a1>=0 && $b1>=0) {
			printf("YES %01.9f %01.9f\n", $a1, $b1);
		} elseif ($a2>=0 && $b2>=0) {
			printf("YES %01.9f %01.9f\n", $a2, $b2);
		} else {
			printf("NO\n");
		}
	}
});


One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.At the end of the day there were n castles built by friends. Castles are numbered from 1 to n, and the height of the i-th castle is equal to hi. When friends were about to leave, Squidward noticed, that castles are not ordered by their height, and this looks ugly. Now friends are going to reorder the castles in a way to obtain that condition hi ≤ hi + 1 holds for all i from 1 to n - 1.Squidward suggested the following process of sorting castles:   Castles are split into blocks — groups of consecutive castles. Therefore the block from i to j will include castles i, i + 1, ..., j. A block may consist of a single castle.  The partitioning is chosen in such a way that every castle is a part of exactly one block.  Each block is sorted independently from other blocks, that is the sequence hi, hi + 1, ..., hj becomes sorted.  The partitioning should satisfy the condition that after each block is sorted, the sequence hi becomes sorted too. This may always be achieved by saying that the whole sequence is a single block. Even Patrick understands that increasing the number of blocks in partitioning will ease the sorting process. Now friends ask you to count the maximum possible number of blocks in a partitioning that satisfies all the above requirements.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day. The next line contains n integers hi (1 ≤ hi ≤ 109). The i-th of these integers corresponds to the height of the i-th castle.

Print the maximum possible number of blocks in a valid partitioning.

NoteIn the first sample the partitioning looks like that: [1][2][3].  In the second sample the partitioning is: [2, 1][3, 2]

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

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


You have two binary strings $$$a$$$ and $$$b$$$ of length $$$n$$$. You would like to make all the elements of both strings equal to $$$0$$$. Unfortunately, you can modify the contents of these strings using only the following operation:  You choose two indices $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$);  For every $$$i$$$ that respects $$$l \le i \le r$$$, change $$$a_i$$$ to the opposite. That is, $$$a_i := 1 - a_i$$$;  For every $$$i$$$ that respects either $$$1 \le i < l$$$ or $$$r < i \le n$$$, change $$$b_i$$$ to the opposite. That is, $$$b_i := 1 - b_i$$$. Your task is to determine if this is possible, and if it is, to find such an appropriate chain of operations. The number of operations should not exceed $$$n + 5$$$. It can be proven that if such chain of operations exists, one exists with at most $$$n + 5$$$ operations.

Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the strings. The second line of each test case contains a binary string $$$a$$$, consisting only of characters 0 and 1, of length $$$n$$$. The third line of each test case contains a binary string $$$b$$$, consisting only of characters 0 and 1, of length $$$n$$$. It is guaranteed that sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print first "YES" if it's possible to make all the elements of both strings equal to $$$0$$$. Otherwise, print "NO". If the answer is "YES", on the next line print a single integer $$$k$$$ ($$$0 \le k \le n + 5$$$) — the number of operations. Then $$$k$$$ lines follows, each contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$) — the description of the operation. If there are several correct answers, print any of them.

YES
1
2 2
NO
NO
YES
2
1 2
2 2
YES
2
1 1
2 3

NoteIn the first test case, we can perform one operation with $$$l = 2$$$ and $$$r = 2$$$. So $$$a_2 := 1 - 1 = 0$$$ and string $$$a$$$ became equal to 000. $$$b_1 := 1 - 1 = 0$$$, $$$b_3 := 1 - 1 = 0$$$ and string $$$b$$$ became equal to 000.In the second and in the third test cases, it can be proven that it's impossible to make all elements of both strings equal to $$$0$$$.In the fourth test case, we can perform an operation with $$$l = 1$$$ and $$$r = 2$$$, then string $$$a$$$ became equal to 01, and string $$$b$$$ doesn't change. Then we perform an operation with $$$l = 2$$$ and $$$r = 2$$$, then $$$a_2 := 1 - 1 = 0$$$ and $$$b_1 = 1 - 1 = 0$$$. So both of string $$$a$$$ and $$$b$$$ became equal to 00.In the fifth test case, we can perform an operation with $$$l = 1$$$ and $$$r = 1$$$. Then string $$$a$$$ became equal to 011 and string $$$b$$$ became equal to 100. Then we can perform an operation with $$$l = 2$$$ and $$$r = 3$$$, so both of string $$$a$$$ and $$$b$$$ became equal to 000.


Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally,   You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions).  Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding.    The picture shows a square that contains red and green rectangles.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles.

Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$.

NoteBelow are the answers for the first two test cases:

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


At many competitions that have a word «cup» in its official name the winner is presented with an actual cup. This time the organizers of one unusual programming competition have decided to please the winner even more and to add a nameplate to the cup with the handle of the winner.The nameplate is to be rectangular and the text on it will be printed as a table of several rows and columns. Having some measurements done, the organizers have found out that the number $$$a$$$ of rows cannot be greater than $$$5$$$ while the number $$$b$$$ of columns cannot exceed $$$20$$$. Every cell of the table will contain either an asterisk («*») or a letter of user's handle.Furthermore, the organizers want the rows of the table to be uniform, which means that the number of asterisks used in different rows should differ by at most one (i.e. you can't have two asterisks in the first row and none in the second). The main goal, however, is to obtain the winner's handle precisely when reading the table from top to bottom and from left to right in every row (skipping asterisks).The organizers want for the nameplate to have as few rows as possible and among all valid tables with the minimum number of rows they want to choose the one that has the minimum number of columns.The winner is not yet determined so your task is to write a program that, given a certain handle, generates the necessary table.

The only line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$), comprised of uppercase and lowercase Latin letters,  — the handle of the winner.

In the first line output the minimum number $$$a$$$ of rows in the table and the minimum number $$$b$$$ of columns in an optimal table with rows. The following $$$a$$$ lines should contain $$$b$$$ characters each  — any valid table.

3 15
MyNameIsLifeIAm
ForeverByYourSi
deMyNameIsL*ife

<?php
//define('STDIN', fopen('input.txt', 'r'));
$s = trim(fgets(STDIN));

$len = strlen($s);
$rowsCount = (int)ceil($len / 20);
$columnsCount = (int)ceil($len / $rowsCount);
$cellsInTable = $rowsCount * $columnsCount;
$fullRows = $rowsCount + $len - $cellsInTable;

echo( "$rowsCount $columnsCount\n" );

for ($numRow = 1, $pos = 0; $numRow <= $rowsCount; $numRow++) {
	if ($numRow <= $fullRows) {
		$substr = substr($s, $pos, $columnsCount);
		$pos += $columnsCount;
	} else {
		$substr = substr($s, $pos, $columnsCount-1) . '*';
		$pos += ($columnsCount - 1);
	}
	if ($numRow < $rowsCount) {
		echo("$substr\n");
	} else {
		echo("$substr");
	}
}

fclose(STDIN);

?>

<?php
$fl = STDIN;//fopen("input.txt","r");

$handleArray = preg_split("//ui", trim(fgets($fl)));
array_pop($handleArray);
array_shift($handleArray);
$columns = 0;
$lines = 0;
if(count($handleArray) <= 20){
    $columns = count($handleArray);
    $lines = 1;
} else {
    $lines = ceil(count($handleArray) / 20);
    $columns = ceil (count($handleArray) / $lines);
}
print((string)$lines . " " . (string)$columns . "\n");
$result = "";
$countArr = count($handleArray);
for($i = 0; $i < $lines; $i++){
    for($j = 0; $j < $columns; $j++){
        $result = $result . $handleArray[$i * $columns + $j];
        if($j == 0){
            if(($lines * $columns - $countArr) > $i){
                $result = $result . "*";
                $j++;
                array_unshift($handleArray, " ");
            }
        }
    }
    $result = $result . "\n";
}
print($result);

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

/* Perform action N times. Can return values in array */
function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}

/* Integral. Keys preserved. By reference. */
function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}

/* Difference. Keys preserved. By reference. */
function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}

function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
/*****************************************/

$ir = new InputReader();

/* TASK */

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

$r = intval($n/20);
if ($r*20 != $n) {
	$r++;
}

$c = 20;
$d = 20*$r - $n;
if ($d>0) {
	$c -= intval($d/$r);
}

echo "$r $c\n";
$stars = $c*$r - $n;
$start = 0;
for ($i = 1; $i<=$r; $i++) {
	if ($stars) {
		echo substr($s, $start, $c-1).'*'."\n";
		$start += $c-1;
		$stars--;
	} else {
		echo substr($s, $start, $c)."\n";
		$start += $c;
	}
}