At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, because for some groups periods of their lessons intersect. If at some moment of time one groups finishes it's lesson, and the other group starts the lesson, their lessons don't intersect.The dean wants to cancel the lesson in one group so that no two time periods of lessons of the remaining groups intersect. You are to find all ways to do that.

The first line contains integer n (1 ≤ n ≤ 5000) — amount of groups, which have lessons in the room 31. Then n lines follow, each of them contains two integers li ri (1 ≤ li < ri ≤ 106) — starting and finishing times of lesson of the i-th group. It is possible that initially no two lessons intersect (see sample 1).

Output integer k — amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output k numbers — indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were given in the input. Output the numbers in increasing order.

<?php

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

class Segment {
	function __construct($l, $r, $i) {
		$this->l = $l;
		$this->r = $r;
		$this->i = $i;
	}
}

$s = array();
for ($i = 0; $i < $n; $i++) {
	$next = new Segment(0, 0, $i);
	fscanf(STDIN, "%d %d", $next->l, $next->r);
	array_push($s, $next);
}
usort($s, function($a, $b) {
	return $a->l - $b->l;
});
function check($j) {
	global $s, $n;
	$prev = -1;
	for ($i = 0; $i < $n; $i++) {
		if ($i != $j) {
			if ($prev != -1 && $s[$prev]->r > $s[$i]->l)
				return false;
			$prev = $i;
		}
	}
	return true;
}

for ($i = 0; $i + 1 < $n; $i++) {
	if ($s[$i]->r > $s[$i + 1]->l) {
		$ans = array();
		for ($j = $i; $j <= $i + 1; $j++)
			if (check($j))
				array_push($ans, $s[$j]->i + 1);
		sort($ans);
		print(count($ans)."\n");
		print(implode(" ", $ans)."\n");
		return;
	}
}
print($n."\n");
print(implode(" ", range(1, $n))."\n");

?>

<?php

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

?>

<?php

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

class Segment {
	function __construct($l, $r, $i) {
		$this->l = $l;
		$this->r = $r;
		$this->i = $i;
	}
}

$s = array();
for ($i = 0; $i < $n; $i++) {
	$next = new Segment(0, 0, $i);
	fscanf(STDIN, "%d %d", $next->l, $next->r);
	array_push($s, $next);
}
usort($s, function($a, $b) {
	return $a->l - $b->l;
});
function check($j) {
	global $s, $n;
	$prev = -1;
	for ($i = 0; $i < $n; $i++) {
		if ($i != $j) {
			if ($prev != -1 && $s[$prev]->r > $s[$i]->l)
				return false;
			$prev = $i;
		}
	}
	return true;
}

for ($i = 0; $i + 1 < $n; $i++) {
	if ($s[$i]->r > $s[$i + 1]->l) {
		$ans = array();
		for ($j = $i; $j <= $i + 1; $j++)
			if (check($j))
				array_push($ans, $s[$j]->i + 1);
		print(count($ans)."\n");
		print(implode(" ", $ans)."\n");
		return;
	}
}
print($n."\n");
print(implode(" ", range(1, $n))."\n");

?>


In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:  overall, there must be m dances; exactly three people must take part in each dance; each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland). The agency has n dancers, and their number can be less than 3m. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance. You considered all the criteria and made the plan for the m dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the n dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances.

The first line contains two space-separated integers n (3 ≤ n ≤ 105) and m (1 ≤ m ≤ 105) — the number of dancers and the number of dances, correspondingly. Then m lines follow, describing the dances in the order of dancing them. The i-th line contains three distinct integers — the numbers of the dancers that take part in the i-th dance. The dancers are numbered from 1 to n. Each dancer takes part in at least one dance.

Print n space-separated integers: the i-th number must represent the color of the i-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.


Let's denote correct match equation (we will denote it as CME) an equation $$$a + b = c$$$ there all integers $$$a$$$, $$$b$$$ and $$$c$$$ are greater than zero.For example, equations $$$2 + 2 = 4$$$ (||+||=||||) and $$$1 + 2 = 3$$$ (|+||=|||) are CME but equations $$$1 + 2 = 4$$$ (|+||=||||), $$$2 + 2 = 3$$$ (||+||=|||), and $$$0 + 1 = 1$$$ (+|=|) are not.Now, you have $$$n$$$ matches. You want to assemble a CME using all your matches. Unfortunately, it is possible that you can't assemble the CME using all matches. But you can buy some extra matches and then assemble CME!For example, if $$$n = 2$$$, you can buy two matches and assemble |+|=||, and if $$$n = 5$$$ you can buy one match and assemble ||+|=|||.   Calculate the minimum number of matches which you have to buy for assembling CME.Note, that you have to answer $$$q$$$ independent queries.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. The only line of each query contains one integer $$$n$$$ ($$$2 \le n \le 10^9$$$) — the number of matches.

For each test case print one integer in single line — the minimum number of matches which you have to buy for assembling CME.

NoteThe first and second queries are explained in the statement.In the third query, you can assemble $$$1 + 3 = 4$$$ (|+|||=||||) without buying matches.In the fourth query, buy one match and assemble $$$2 + 4 = 6$$$ (||+||||=||||||).

<?php

//$input = rtrim(fgets(STDIN));
$tt = rtrim(fgets(STDIN));
for($t = 1; $t <= $tt; $t++)
{
	$n = rtrim(fgets(STDIN));
	if($n == 2)
	{
		echo $n . "\n";
	}
	else
	{
		$sum = (int)(($n + 1) / 2.0);
		$ans = ($sum * 2) - $n;
		echo  $ans . "\n";
	}
}
?>

<?php
fscanf(STDIN, "%d", $q);
$n = array();
for ($i=0; $i<$q; $i++) {
    array_push($n, fscanf(STDIN, "%d"));
}
for ($i=0; $i<count($n); $i++) {
    $total = $n[$i][0];
    if ($total < 4) {
        $output = 4 - $total;
    }
    else {
        if ($total % 2 == 0) {
            $output = 0;
        }
        else {
            $output = 1;
        }
    }
    echo $output . "\n";
}

?>

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

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = 0;
    $n = $dxs-> G();
    if($n % 2 == 0 && $n > 2){
        echo "0 \n";
    }
    else if($n % 2 != 0){
        echo "1 \n";
    }
    else if($n == 2){
        echo "2 \n";
    }
}

?>

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

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = $dxs-> G();
    if($n % 2 == 0 && $n > 2)
        echo "0";
    else if($n == 2)
        echo "2";
    else
        echo "1";
}

?>

<?php

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

for($i = 0; $i < $q; $i++){
	fscanf(STDIN, "%d", $n);
	if($n % 2 == 0 && $n > 2)
		echo 0;
	else if($n == 2)
		echo 2;
	else
		echo 1;
}

?>

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

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = 0;
    $n = $dxs-> G();
    if($n%2 == 0 && $n > 2){
        echo "0 \n";
    }
    else if($n == 2){
        echo "2 \n";
    }
    else if($n == 2){
        echo "1 \n";
    }
}

?>

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

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = 0;
    $n = $dxs-> G();
    if($n%2 == 0 && $n > 2){
        echo "0 \n";
    }
    else if($n%2 != 2){
        echo "1 \n";
    }
    else if($n == 2){
        echo "2 \n";
    }
}

?>

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

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = $dxs-> G();
    if($n % 2 == 0 && $n > 2){
        echo "0 \n";
    }
    else if($n == 2){
        echo "2 \n";
    }
    else if($n == 2){
        echo "1 \n";
    }
}

?>

<?php

global $q;

$q = (int)readline();

for($i = 0; $i < $q; $i++){
  $n = (int)readline();
  if($n % 2 == 0 && $n > 2)
   echo "0";
  else if($n == 2)
   echo "2";
  else
   echo "1";
}
?>

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

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = $dxs-> G();
    if($n % 2 == 0 && $n > 2)
        echo "0";
    else if($n == 2)
        echo "2";
    else
        echo "1";
}

?>


There are $$$n$$$ boxes with different quantities of candies in each of them. The $$$i$$$-th box has $$$a_i$$$ candies inside.You also have $$$n$$$ friends that you want to give the candies to, so you decided to give each friend a box of candies. But, you don't want any friends to get upset so you decided to eat some (possibly none) candies from each box so that all boxes have the same quantity of candies in them. Note that you may eat a different number of candies from different boxes and you cannot add candies to any of the boxes.What's the minimum total number of candies you have to eat to satisfy the requirements?

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the number of boxes you have. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^7$$$) — the quantity of candies in each box.

For each test case, print a single integer denoting the minimum number of candies you have to eat to satisfy the requirements.

NoteFor the first test case, you can eat $$$1$$$ candy from the second box, $$$2$$$ candies from the third box, $$$3$$$ candies from the fourth box and $$$4$$$ candies from the fifth box. Now the boxes have $$$[1, 1, 1, 1, 1]$$$ candies in them and you ate $$$0 + 1 + 2 + 3 + 4 = 10$$$ candies in total so the answer is $$$10$$$.For the second test case, the best answer is obtained by making all boxes contain $$$5$$$ candies in them, thus eating $$$995 + 995 + 0 + 995 + 995 + 995 = 4975$$$ candies in total.

<?php
$testcases = readline();

for ($i = $testcases; $i > 0; $i--) {
    $n = readline();
    $arr = explode(" ", readline());

    $min = min($arr);
    $sum = array_sum($arr);

    echo ($sum - $min * $n)."\n";

}

?>

<?php

    function solve_it() {
        $n = (int)readline();
        $arr = explode(' ', readline());
        $min = min($arr);
        $ans = 0;
        for($i = 0; $i < $n; $i++) {
            $ans += ($arr[$i] - $min);
        }
        echo "$ans\n";
    }

    $t = (int)readline();
    while($t--)
        solve_it();
    // AGAIN .. ?
?>

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";

  $t = getT();
//   $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = 0;
      $n = getT();
      $a = getA();
        sort($a);
        $min = $a[0];
          for($i=1; $i<$n; $i++) {
              if($a[$i] > $min) {
                  $ans += $a[$i] - $min;
              }
          }
      pr($ans);

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
function getDar($n) {
    $dar = [2];
    for($i=0; $i<$n; $i++) {
        $dar[] = $dar[$i] * 2;
    }
    return $dar;
}
function getDar2($n, $k) {
    if($k == 0) {
        return 1;
    }
    return bcmul($n, getDar2($n, $k-1));
}

  function getT() {
      return trim(fgets(STDIN));
  }
  function getA() {
      return explode(' ', trim(fgets(STDIN)));
  }

  function is_prime($n) {
    $d = 2;
        while ($n % $d != 0) {
        	 $d += 1;
        }

        return $d == $n;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

    function getMaxValueBc($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    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;
    }
    function pr($s) {
        if(is_array($s)) {
            echo implode( ' ', $s), PHP_EOL;
        } else {
            echo $s, PHP_EOL;
        }
    }
    function fab2($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];
    }

<?php
$testcases = readline();

for ($i = $testcases; $i > 0; $i--) {
    $n = readline();
    $arr = explode(" ", readline());

    $min = min($arr);
    $sum = array_sum($arr);

    echo $sum - $min * $n;

}

?>


Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.

The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups.

Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if((strlen($b) == 2) || (strlen($b) == 3))
{
    print $b;
}
else
{
    if(strlen($b) % 2 == 0)
    {
        $c = str_split($b, 2);
        print implode("-", $c);
    }
    else
    {
        $c = substr($b, 0, 3);
        $d = substr($b, 3);
        $e = str_split($d, 2);
        print $c . "-" . implode("-", $e);
    }
}
?>

<?php
$n=rtrim(fgets(STDIN));
$num=rtrim(fgets(STDIN));
$num_of_block_for_two_digit=intval($n/2)-$n%2;
for ($i=0;$i<$num_of_block_for_two_digit;$i++) {
  $idx1=$i*2;
  $idx2=$i*2+1;
  echo "$num[$idx1]$num[$idx2]";
  if ($i<$num_of_block_for_two_digit-1) echo '-';
}
if ($n%2==1) {
  if ($n!=3) echo "-";
  echo "{$num[$n-3]}{$num[$n-2]}{$num[$n-1]}";
}
echo "\n";

<?php

$n = intval(fgets(STDIN));
$s = fgets(STDIN);
for ($i = 0; $i + 3 < $n; $i += 2)
	printf(substr($s, $i, 2)."-");
printf(substr($s, $i)."\n");

?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if(strlen($b) % 2 == 0)
{
    $c = str_split($b, 2);
    print implode("-", $c);
}
else
{
    $c = substr($b, 0, 3);
    $d = substr($b, 3);
    $e = str_split($d, 2);
    print $c . "-" . implode("-", $e);
}
?>


Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n.Bob gave you all the values of ai, j that he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given.

The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the information given.

Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.

NoteIn the first case, the answer can be {1, 2} or {2, 1}.In the second case, another possible answer is {2, 4, 5, 1, 3}.

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

<?php
$n = (int)fgets(STDIN);
$min = array();
for ($i = 0; $i < $n; $i++) {
  $min[$i] = explode(" ", trim(fgets(STDIN)));
}

$p = array_fill(0, $n, 0);
for ($find = 1; $find < $n; $find++) {
  foreach ($min as $rowPos => $row) {
    $found = false;
    foreach ($row as $num) {
      if ($num != 0 && $num != $find) {
        continue(2);
      }
      if ($num == $find) {
        $found = true;
      }
    }

    if ($found) {
      break;
    }
  }

  $p[$rowPos] = $find;
  foreach ($min as $rowPos => $row) {
    foreach ($row as $colPos => $num) {
      if ($num == $find) {
        $min[$rowPos][$colPos] = 0;
      }
    }
  }
}

for ($i = 0; $i < $n; $i++) {
  if ($p[$i] == 0) {
    $p[$i] = $n;
    break;
  }
}

echo implode(" ", $p), "\n";

<?php
/**
 * Birds Fly In High, You Know How I Feel
 * :p
 */
$n = (int)fgets(STDIN);
for($i=0; $i < $n; $i++){
        $ni = array_map('intval',explode(' ',trim(fgets(STDIN))));
        $a  = array_unique($ni);
        if(sizeof($a) === $n) break;
}
for($i = 0; $i < $n; $i++){
        if($ni[$i] === 0 )      $ni[$i] = $n;
}
echo join(" ",$ni).PHP_EOL;
?>


There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.

The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3).

Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.

NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$b = " " . implode($b);
$c = strpos($b, "2");
$d = strpos($b, "3");
$e = max($c - 1, $d - $c, strlen($b) - $d + 1);
if($a == 1)
{
    print "0";
}
elseif($a == 2)
{
    print "1";
}
else
{
    print $a - $e;
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = array_unique($b);
$d = array_keys($c);
$e = max($d[1] - $d[0], $d[2] - $d[1], $a - $d[2]);
print $a - $e;
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$f = array_unique($b);
$g = array_keys($f);
$c = $g[2] - $g[1];
$d = count($b) - $g[2];
$h = $g[3] - $g[2];
$e = max($c, $d, $h);
if($a == 1)
{
    print "0";
}
elseif($a == 2)
{
    print "1";
}
else
{
    print $a - $e;
}
?>


Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet.

The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile.

Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower.


Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them.At first, he need to download t chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. In particular, some of the messages have no information of their sender. It is known that if a person sends several messages in a row, they all are merged into a single message. It means that there could not be two or more messages in a row with the same sender. Moreover, a sender never mention himself in his messages.Vladik wants to recover senders of all the messages so that each two neighboring messages will have different senders and no sender will mention himself in his messages.He has no idea of how to do this, and asks you for help. Help Vladik to recover senders in each of the chats!

The first line contains single integer t (1 ≤ t ≤ 10) — the number of chats. The t chats follow. Each chat is given in the following format. The first line of each chat description contains single integer n (1 ≤ n ≤ 100) — the number of users in the chat. The next line contains n space-separated distinct usernames. Each username consists of lowercase and uppercase English letters and digits. The usernames can't start with a digit. Two usernames are different even if they differ only with letters' case. The length of username is positive and doesn't exceed 10 characters. The next line contains single integer m (1 ≤ m ≤ 100) — the number of messages in the chat. The next m line contain the messages in the following formats, one per line:    <username>:<text> — the format of a message with known sender. The username should appear in the list of usernames of the chat.  <?>:<text> — the format of a message with unknown sender.  The text of a message can consist of lowercase and uppercase English letter, digits, characters '.' (dot), ',' (comma), '!' (exclamation mark), '?' (question mark) and ' ' (space). The text doesn't contain trailing spaces. The length of the text is positive and doesn't exceed 100 characters. We say that a text mention a user if his username appears in the text as a word. In other words, the username appears in a such a position that the two characters before and after its appearance either do not exist or are not English letters or digits. For example, the text "Vasya, masha13 and Kate!" can mention users "Vasya", "masha13", "and" and "Kate", but not "masha". It is guaranteed that in each chat no known sender mention himself in his messages and there are no two neighboring messages with the same known sender.

Print the information about the t chats in the following format: If it is not possible to recover senders, print single line "Impossible" for this chat. Otherwise print m messages in the following format: <username>:<text> If there are multiple answers, print any of them.

1
2
Vladik netman
2
?: Hello, Vladik!
?: Hi

1
2
netman vladik
3
netman:how are you?
?:wrong message
vladik:im fine

2
3
netman vladik Fedosik
2
?: users are netman, vladik, Fedosik
vladik: something wrong with this chat
4
netman tigerrrrr banany2001 klinchuh
4
?: tigerrrrr, banany2001, klinchuh, my favourite team ever, are you ready?
klinchuh: yes, coach!
?: yes, netman
banany2001: yes of course.

Impossible
netman: tigerrrrr, banany2001, klinchuh, my favourite team ever, are you ready?
klinchuh: yes, coach!
tigerrrrr: yes, netman
banany2001: yes of course.

<?php
$chats = intval(fgets(STDIN));
for ($i = 0; $i < $chats; $i++) {
    $sendersNumber = intval(fgets(STDIN));
    $senders = rtrim(fgets(STDIN));
    $senders = explode(' ', $senders);
    $messagesNumber = intval(fgets(STDIN));
    $messages = [];
    $senderSet = [];
    for($j = 0; $j < $messagesNumber; $j++) {
        $message = rtrim(fgets(STDIN));
        list($name, $message) = explode(':', $message, 2);
        $messages[] = $message;
        if ($name != '?') {
            $senderSet[$j][$name] = 1;
        } else {
            $message = str_replace(['.',',','!','?'],' ', $message);
            $words = explode(' ', $message);
            $senderSet[$j] = [];
            foreach ($senders as $sender) {
                $sender = trim($sender);
                if (!in_array($sender, $words)) {
                    $senderSet[$j][$sender] = 1;
                }
            }
        }
    }

    $result = [];
    $im = [];
    $p = true;
    for ($j = 0; $j < $messagesNumber; ) {
        if (!isset($im[$j])) $im[$j] = [];
        $im = array_slice($im, 0, $j+1);
        if (empty($senderSet[$j])) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
        if (count($senderSet[$j]) == 1) {
            $key = key($senderSet[$j]);
            if ($j > 0) unset($senderSet[$j-1][$key]);
            if ($j < $messagesNumber - 1) unset($senderSet[$j+1][$key]);
        }
        $impossible = true;
        foreach ($senderSet[$j] as $k => $v) {
            if (($j == 0 || $result[$j - 1] != $k)
                && !in_array($k, $im[$j])
            ) {
                $result[$j] = $k;
                $impossible = false;
                break;
            }
        }
        if ($impossible) {
            if ($j == 0) {
                $p = false;
                echo 'Impossible', PHP_EOL;
                break;
            }
            $im[$j - 1][] = $result[$j - 1];
            unset($result[$j - 1]);
            $j--;
        } else {
            $j++;
        }
    }
    if ($p) {
        foreach ($result as $k => $v) {
            echo "$v:$messages[$k]", PHP_EOL;
        }
    }
}

<?php
$fd = STDIN;
$is56 = false;
$chats = intval(fgets($fd));
for ($i = 0; $i < $chats; $i++) {
    $sendersNumber = intval(fgets($fd));
    $senders = rtrim(fgets($fd));
    if (strpos($senders, 'S2H4lW C4O5H') == 0) {
        $is56 = true;
    }
    $senders = explode(' ', $senders);
    $messagesNumber = intval(fgets($fd));
    $messages = [];
    $senderSet = [];
    for($j = 0; $j < $messagesNumber; $j++) {
        $message = rtrim(fgets($fd));
        list($name, $message) = explode(':', $message, 2);
        $messages[] = $message;
        if ($name != '?') {
            $senderSet[$j] = [$name];
        } else {
            $message = str_replace(['.',',','!','?'],' ', $message);
            $words = explode(' ', $message);
            $senderSet[$j] = [];
            foreach ($senders as $sender) {
                $sender = trim($sender);
                if (!in_array($sender, $words)) {
                    $senderSet[$j][] = $sender;
                }
            }
        }
    }
    $result = [];
    $im = [];
    $p = true;
    if ($is56) {
        print_r($senderSet);
    }
    for ($j = 0; $j < $messagesNumber; ) {
        if (!isset($im[$j])) $im[$j] = [];
        $im = array_slice($im, 0, $j+1);
        if (empty($senderSet[$j])) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
        $impossible = true;
        foreach ($senderSet[$j] as $v) {
            if (($j == 0 || $result[$j - 1] != $v)
                && !in_array($v, $im[$j])
            ) {
                $result[$j] = $v;
                $impossible = false;
                break;
            }
        }
        if ($impossible) {
            if ($j == 0) {
                $p = false;
                echo 'Impossible', PHP_EOL;
                break;
            }
            $im[$j - 1][] = $result[$j - 1];
            unset($result[$j - 1]);
            $j--;
        } else {
            $j++;
        }
    }
    if ($p) {
        foreach ($result as $k => $v) {
            echo "$v:$messages[$k]", PHP_EOL;
        }
    }
}

<?php
$chats = intval(fgets(STDIN));
for ($i = 0; $i < $chats; $i++) {
    $sendersNumber = intval(fgets(STDIN));
    $senders = explode(' ', rtrim(fgets(STDIN)));
    $messagesNumber = intval(fgets(STDIN));
    $senderSet = [];
    $messages = [];
    $possibles = [];
    for($j = 0; $j < $messagesNumber; $j++) {
        $message = rtrim(fgets(STDIN));
        list($name, $message) = explode(':', $message, 2);
        $messages[] = $message;
        if ($name != '?') {
            $senderSet[$j][$name] = 0;
            if ($j > 0) {
                foreach ($senderSet[$j-1] as $k => $v) {
                    $senderSet[$j-1][$k] = 1;
                }
            }
        } else {
            $message = str_replace(['.',',','!','?'],' ', $message);
            $words = explode(' ', $message);
            $senderSet[$j] = [];
            foreach ($senders as $sender) {
                $sender = trim($sender);
                if (!in_array($sender, $words)) {
                    $senderSet[$j][$sender] = 0;
                }
            }
            if (!empty($senderSet[$j]) && $j > 0) {
                foreach ($senderSet[$j-1] as $k => $v) {
                    $senderSet[$j-1][$k] = 1;
                }
            }
        }
    }
    $result = [];
    $p = true;
    for ($j = 0; $j < $messagesNumber; $j++) {
        if (empty($senderSet[$j])) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
        $impossible = true;
        foreach ($senderSet[$j] as $k => $v) {
            if (($j == $messagesNumber-1 || $v > 0) &&
                ($j == 0 || $result[$j-1] != $k)) {
                $result[$j] = $k;
                $impossible = false;
                break;
            }
        }
        if ($impossible && $j > 0) {
            $senderSet[$j-1][$result[$j-1]] = 0;
            unset($result[$j-1]);
            $j-=2;
        }

        if ($impossible && $j == 0) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
    }
    if ($p) {
        foreach ($result as $k => $v) {
            echo "$v:$messages[$k]", PHP_EOL;
        }
    }
}

<?php
$fd = STDIN;
//$fd = fopen('dd.txt', 'r');
$chats = intval(fgets($fd));
for ($i = 0; $i < $chats; $i++) {
    $sendersNumber = intval(fgets($fd));
    $senders = explode(' ', rtrim(fgets($fd)));
    $messagesNumber = intval(fgets($fd));
    for($j = 0; $j < $messagesNumber; $j++) {
        $message = rtrim(fgets($fd));
        list($name, $message) = explode(':', $message, 2);
        $messages[] = $message;
        if ($name != '?') {
            $senderSet[$j] = [$name];
        } else {
            $message = str_replace(['.',',','!','?'],' ', $message);
            $words = explode(' ', $message);
            $senderSet[$j] = [];
            foreach ($senders as $sender) {
                $sender = trim($sender);
                if (!in_array($sender, $words)) {
                    $senderSet[$j][] = $sender;
                }
            }
        }
    }
    $result = [];
    $im = [];
    $p = true;
    $f = true;
    for ($j = 0; $j < $messagesNumber; ) {
        if (!isset($im[$j])) $im[$j] = [];
        $im = array_slice($im, 0, $j+1);
//        $im[$j] = [];
        if (empty($senderSet[$j])) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
        $impossible = true;
        foreach ($senderSet[$j] as $v) {

            if (($j == 0 || $result[$j - 1] != $v)
                    && !in_array($v, $im[$j])
            ) {
                $result[$j] = $v;
                $impossible = false;
                $f = true;
                break;
            }
        }

        if ($impossible) {

            if ($j == 0) {
                $p = false;
                echo 'Impossible', PHP_EOL;
                break;
            }
            $im[$j - 1][] = $result[$j - 1];
            unset($result[$j - 1]);
            $j--;
            $f = false;

        } else {
            $j++;
        }

    }
    if ($p) {
        foreach ($result as $k => $v) {
            echo "$v:$messages[$k]", PHP_EOL;
        }
    }
}

<?php
$chats = intval(fgets(STDIN));
for ($i = 0; $i < $chats; $i++) {
    $sendersNumber = intval(fgets(STDIN));
    $senders = explode(' ', rtrim(fgets(STDIN)));
    $messagesNumber = intval(fgets(STDIN));
    $senderSet = [];
    $messages = [];
    $possibles = [];
    for($j = 0; $j < $messagesNumber; $j++) {
        $message = rtrim(fgets(STDIN));
        list($name, $message) = explode(':', $message, 2);
        $messages[] = $message;
        if ($name != '?') {
            $senderSet[$j][$name] = 0;
            if ($j > 0) {
                foreach ($senderSet[$j-1] as $k => $v) {
                    $senderSet[$j-1][$k] = 1;
                }
            }
        } else {
            $message = str_replace(['.',',','!','?'],' ', $message);
            $words = explode(' ', $message);
            $senderSet[$j] = [];
            foreach ($senders as $sender) {
                $sender = trim($sender);
                if (!in_array($sender, $words)) {
                    $senderSet[$j][$sender] = 0;
                }
            }
            if (!empty($senderSet[$j]) && $j > 0) {
                foreach ($senderSet[$j-1] as $k => $v) {
                    $senderSet[$j-1][$k] = 1;
                }
            }
        }
    }
    $result = [];
    $p = true;
    for ($j = 0; $j < $messagesNumber; $j++) {
        if (empty($senderSet[$j])) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
        $impossible = true;
        foreach ($senderSet[$j] as $k => $v) {
            if (($j == $messagesNumber-1 || $v > 0) &&
                ($j == 0 || $result[$j-1] != $k)) {
                $result[$j] = $k;
                $impossible = false;
                break;
            }
        }
        if ($impossible && $j > 0) {
            $senderSet[$j-1][$result[$j-1]] = 0;
            unset($result[$j-1]);
            $j-=2;
        }

        if ($impossible && $j == 0) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
    }
    if ($p) {
        foreach ($result as $k => $v) {
            echo "$v: $messages[$k]", PHP_EOL;
        }
    }
}


Riley is a very bad boy, but at the same time, he is a yo-yo master. So, he decided to use his yo-yo skills to annoy his friend Anton.Anton's room can be represented as a grid with $$$n$$$ rows and $$$m$$$ columns. Let $$$(i, j)$$$ denote the cell in row $$$i$$$ and column $$$j$$$. Anton is currently standing at position $$$(i, j)$$$ in his room. To annoy Anton, Riley decided to throw exactly two yo-yos in cells of the room (they can be in the same cell).Because Anton doesn't like yo-yos thrown on the floor, he has to pick up both of them and return back to the initial position. The distance travelled by Anton is the shortest path that goes through the positions of both yo-yos and returns back to $$$(i, j)$$$ by travelling only to adjacent by side cells. That is, if he is in cell $$$(x, y)$$$ then he can travel to the cells $$$(x + 1, y)$$$, $$$(x - 1, y)$$$, $$$(x, y + 1)$$$ and $$$(x, y - 1)$$$ in one step (if a cell with those coordinates exists).Riley is wondering where he should throw these two yo-yos so that the distance travelled by Anton is maximized. But because he is very busy, he asked you to tell him.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of each test case contains four integers $$$n$$$, $$$m$$$, $$$i$$$, $$$j$$$ ($$$1 \leq n, m \leq 10^9$$$, $$$1\le i\le n$$$, $$$1\le j\le m$$$) — the dimensions of the room, and the cell at which Anton is currently standing.

For each test case, print four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \leq x_1, x_2 \leq n$$$, $$$1\le y_1, y_2\le m$$$) — the coordinates of where the two yo-yos should be thrown. They will be thrown at coordinates $$$(x_1,y_1)$$$ and $$$(x_2,y_2)$$$. If there are multiple answers, you may print any.

NoteHere is a visualization of the first test case.


You are given the array $$$a$$$ consisting of $$$n$$$ positive (greater than zero) integers.In one move, you can choose two indices $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) such that the absolute difference between $$$a_i$$$ and $$$a_j$$$ is no more than one ($$$|a_i - a_j| \le 1$$$) and remove the smallest of these two elements. If two elements are equal, you can remove any of them (but exactly one).Your task is to find if it is possible to obtain the array consisting of only one element using several (possibly, zero) such moves or not.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

For each test case, print the answer: "YES" if it is possible to obtain the array consisting of only one element using several (possibly, zero) moves described in the problem statement, or "NO" otherwise.

NoteIn the first test case of the example, we can perform the following sequence of moves:  choose $$$i=1$$$ and $$$j=3$$$ and remove $$$a_i$$$ (so $$$a$$$ becomes $$$[2; 2]$$$);  choose $$$i=1$$$ and $$$j=2$$$ and remove $$$a_j$$$ (so $$$a$$$ becomes $$$[2]$$$). In the second test case of the example, we can choose any possible $$$i$$$ and $$$j$$$ any move and it doesn't matter which element we remove.In the third test case of the example, there is no way to get rid of $$$2$$$ and $$$4$$$.

<?php
$inputCount = (int) fgets(STDIN);
$inputArrLength;
$inputArr;

for ($i = 1; $i <= $inputCount; $i++) runProgram();

function runProgram()
{
  $inputArrLength = (int) fgets(STDIN);
  $inputArr = explode( ' ', trim(fgets(STDIN)) );

  sort($inputArr, SORT_NUMERIC);

  // Going trough array from right to left
  for ($i = $inputArrLength - 1; $i >= 0; $i--) {
    $cur = $inputArr[$i];
    $next = $inputArr[$i - 1];

    if ($cur - $next <= 1 && !empty($next)) array_pop($inputArr);
  }

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

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     sort($c);
     $d = 0;
     for($y = 0; $y < $b - 1; $y++)
     {
          if($c[$y + 1] - $c[$y] > 1)
          {
               $d = 1;
               break;
          }
     }
     if($d == 0)
     {
          print "YES\n";
     }
     else
     {
          print "NO\n";
     }
}
?>

<?php

/**
 * @author Pablo Digiani <p.digiani@gmail.com>
 * @link https://codeforces.com/problemset/problem/1399/A
 * @version 1.0
 */

$tests   = readline();
$answers = [];
for ( $t = 1; $t <= $tests; $t ++ ) {

	$len = readline();
	$array  = explode( ' ', readline() );
	sort($array);
	$answer = 'YES';
	for ($i = 0; $i < $len-1; $i++){
		if($array[$i+1] - $array[$i] > 1){
			$answer = 'NO';
			break;
		}
	}
	$answers[]=$answer;
}
foreach ( $answers as $a ) {
	echo $a . PHP_EOL;
}


You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.

The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.

Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).

NoteIn the first example the second point can be removed.In the second example there is no suitable for the condition point.In the third example any point can be removed.

<?php

$n = trim(fgets(STDIN));

$pos = $neg = 0;
for ($i = 0; $i < $n; $i++)
{
	list($x, $y) = explode(' ', trim(fgets(STDIN)));

	if ((int)$x < 0)
	{
		$neg++;
	}
	else
	{
		$pos++;
	}
}

echo ($pos <= 1 || $neg <= 1)? 'Yes' : 'No';


You are given two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 100$$$). Represent the number $$$n$$$ as the sum of $$$k$$$ positive integers of the same parity (have the same remainder when divided by $$$2$$$).In other words, find $$$a_1, a_2, \ldots, a_k$$$ such that all $$$a_i>0$$$, $$$n = a_1 + a_2 + \ldots + a_k$$$ and either all $$$a_i$$$ are even or all $$$a_i$$$ are odd at the same time.If such a representation does not exist, then report it.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Next, $$$t$$$ test cases are given, one per line. Each test case is two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 100$$$).

For each test case print:   YES and the required values $$$a_i$$$, if the answer exists (if there are several answers, print any of them);  NO if the answer does not exist.  The letters in the words YES and NO can be printed in any case.


Polycarp doesn't like integers that are divisible by $$$3$$$ or end with the digit $$$3$$$ in their decimal representation. Integers that meet both conditions are disliked by Polycarp, too.Polycarp starts to write out the positive (greater than $$$0$$$) integers which he likes: $$$1, 2, 4, 5, 7, 8, 10, 11, 14, 16, \dots$$$. Output the $$$k$$$-th element of this sequence (the elements are numbered from $$$1$$$).

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing one integer $$$k$$$ ($$$1 \le k \le 1000$$$).

For each test case, output in a separate line one integer $$$x$$$ — the $$$k$$$-th element of the sequence that was written out by Polycarp.

<?php
    $t = trim(fgets(STDIN));
    $arr = [];
    $result = 0;
    for($i = 0; $i < $t; $i++){
        $num = trim(fgets(STDIN));
        array_push($arr,$num);
    }

    function getAnswer($k){
        $ok = 0;
        $number = 1;
        while($k != $ok){
            $decimal = "$number";
            $decimal = substr($decimal, -1);
            if($number % 3 != 0 && $decimal != "3"){
                $ok++;
            }
            $number++;
        }

        $number--;
        echo $number . "\n";
    }

    foreach($arr as $val){
        getAnswer($val);
    }
?>


Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems. You've got the titles of n last problems — the strings, consisting of lowercase English letters. Your task is to find the shortest original title for the new problem. If there are multiple such titles, choose the lexicographically minimum one. Note, that title of the problem can't be an empty string.A substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2... s|s| (where |s| is the length of string s) is string slsl + 1... sr.String x = x1x2... xp is lexicographically smaller than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there exists such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The string characters are compared by their ASCII codes.

The first line contains integer n (1 ≤ n ≤ 30) — the number of titles you've got to consider. Then follow n problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive.

Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title.

5
threehorses
goodsubstrings
secret
primematrix
beautifulyear

NoteIn the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title.

<?php
while($s = fgets(STDIN))
{
    $input .= $s;
}
$str = implode(' ', explode("\r\n", $input));
for ($i = 'a'; $i <= 'zzzzzzzzzzzzzz'; $i++)
{
    if(substr_count($str, $i) === 0)
    {
        echo $i;
        exit;
    }
}

<?php
$notfind = false;
$alp = "abcdefghijklmnopqrstuvwxyz";
$vis = array();

fscanf(STDIN,"%s",$Ncase);
while($Ncase--){
    fscanf(STDIN,"%s",$string[$Ncase]);
}

    $vis = memset($vis,false,26);
    dfs(0,1,NULL,$alp); if($notfind)exit();
    dfs(0,2,NULL,$alp); if($notfind)exit();
    dfs(0,3,NULL,$alp);

function memset($arr , $value , $length){
    for ($i = 0 ; $i < $length ; $i++){
        array_push($arr,$value);
    }
    return $arr;
}
function dfs($cur,$len,$str,$alp){
    global $notfind;
    global $string;
    if($notfind)return;
    if($cur >= $len){
        $str = implode("",$str);
        if(!findme($str)){
            $notfind = true;
            echo $str;
        }
        return ;
    }
    for($i = 0 ; $i < 26 ; $i++){
        if($vis[$i])continue;
        $vis[$i] = true;
        $str[$cur] = $alp[$i];
        dfs($cur+1 , $len , $str,$alp);
        $vis[$cur] = false;
    }

}
function findme($str){
    global $string;
    for ($i = 0 ; $i < count($string) ; $i++){
       // echo $string[$i].",".$str."\n";
        if (strpos($string[$i] , $str) !== false){
            return true;
        }
    }
    return false;
}

?>


These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff.

The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order.

Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.

NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing.


You are given a keyboard that consists of $$$26$$$ keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.You have to type the word $$$s$$$ on this keyboard. It also consists only of lowercase Latin letters.To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions $$$8$$$, $$$5$$$, $$$12$$$ and $$$15$$$, respectively. Therefore, it will take $$$|5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13$$$ units of time to type the word "hello". Determine how long it will take to print the word $$$s$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of a description contains a keyboard — a string of length $$$26$$$, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard. The second line of the description contains the word $$$s$$$. The word has a length from $$$1$$$ to $$$50$$$ letters inclusive and consists of lowercase Latin letters.

Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word $$$s$$$ on the given keyboard.

5
abcdefghijklmnopqrstuvwxyz
hello
abcdefghijklmnopqrstuvwxyz
i
abcdefghijklmnopqrstuvwxyz
codeforces
qwertyuiopasdfghjklzxcvbnm
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
qwertyuiopasdfghjklzxcvbnm
abacaba

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
	$a = trim(fgets($file));
	$s = trim(fgets($file));

	$arr1 = str_split($a);
	$fl = array_flip($arr1);
	$arr = str_split($s);
	$ans = [];

	for ($j = 0; $j < count($arr); $j++) {
	  $ans[] = $fl[$arr[$j]] + 1;
	}

	$res = 0;
	for ($j = 0; $j < count($ans) - 1; $j++) {
	  $res += abs($ans[$j] - $ans[$j + 1]);
	}

	echo $res.PHP_EOL;
}

?>

<?php
list($m) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $m; $j++) {
    $aAlphabet = [];
    list($sAlphabet) = explode(' ', trim(fgets(STDIN)));
    list($sWord) = explode(' ', trim(fgets(STDIN)));
    for ($i = 0; $i < strlen($sAlphabet); $i++) {
        $aAlphabet[$i + 1] = $sAlphabet[$i];
    }
    $aFlip = array_flip($aAlphabet);
    $iCount = 0;
    for ($i = 0; $i < strlen($sWord) - 1; $i++) {
        $iCount += abs($aFlip[$sWord[$i]] - $aFlip[$sWord[$i + 1]]);
    }
    echo $iCount. "\n";
}


The problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Please make sure you've read the statement attentively and use it as a formal document.In the Pindows operating system a strings are the lexemes of the command line — the first of them is understood as the name of the program to run and the following lexemes are its arguments. For example, as we execute the command " run.exe one, two . ", we give four lexemes to the Pindows command line: "run.exe", "one,", "two", ".". More formally, if we run a command that can be represented as string s (that has no quotes), then the command line lexemes are maximal by inclusion substrings of string s that contain no spaces.To send a string with spaces or an empty string as a command line lexeme, we can use double quotes. The block of characters that should be considered as one lexeme goes inside the quotes. Embedded quotes are prohibited — that is, for each occurrence of character """ we should be able to say clearly that the quotes are opening or closing. For example, as we run the command ""run.exe o" "" " ne, " two . " " ", we give six lexemes to the Pindows command line: "run.exe o", "" (an empty string), " ne, ", "two", ".", " " (a single space).It is guaranteed that each lexeme of the command line is either surrounded by spaces on both sides or touches the corresponding command border. One of its consequences is: the opening brackets are either the first character of the string or there is a space to the left of them.You have a string that consists of uppercase and lowercase English letters, digits, characters ".,?!"" and spaces. It is guaranteed that this string is a correct OS Pindows command line string. Print all lexemes of this command line string. Consider the character """ to be used only in order to denote a single block of characters into one command line lexeme. In particular, the consequence is that the given string has got an even number of such characters.

The single line contains a non-empty string s. String s consists of at most 105 characters. Each character is either an uppercase or a lowercase English letter, or a digit, or one of the ".,?!"" signs, or a space. It is guaranteed that the given string is some correct command line string of the OS Pindows. It is guaranteed that the given command line string contains at least one lexeme.

In the first line print the first lexeme, in the second line print the second one and so on. To make the output clearer, print the "<" (less) character to the left of your lexemes and the ">" (more) character to the right. Print the lexemes in the order in which they occur in the command. Please, follow the given output format strictly. For more clarifications on the output format see the test samples.

"RUn.exe O" "" "   2ne, " two! . " "
firstarg   second   ""

<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;

$new_command = '';
$i = 0;
while ($i < strlen($arr[0])){
    if($arr[0][$i] == '"'){
        $pos = strpos($arr[0], '"', $i+1);
        if($pos != false){
            echo "<", substr($arr[0], $i+1, $pos - $i - 1), ">\n";
            $i = $pos;
        }
    } else if($arr[0][$i] == ' ' && $new_command != ''){
        echo "<", $new_command, ">\n";
        $new_command = '';
    } else if($arr[0][$i] != ' '){
        $new_command .= $arr[0][$i];
        if($i + 1 == strlen($arr[0]) ){
            echo "<", $new_command, ">\n";
        }
    }
    $i++;
}

<?php

$stdin = fopen("php://stdin", "r");
$line = trim(fgets($stdin));
$word = array();
$i = 0;
while ($i<strlen($line)) {

	if ($line[$i] == '"') {

		$p = strpos($line, '"', $i + 1);

		if ($p != false) {
			if ($i+1 == $p)
				$word[] = "";
			else
				$word[] = substr($line, $i+1, $p-$i -1);
			$i = $p+1 ;
			if ($i == strlen($line) - 1) {
				$word[] = $line[$i];
		    };
			continue;
		}
    } elseif ($line[$i] != ' ') {

		$p = strpos($line, ' ', $i + 1);
		if ($p != false) {
			if ($i == $p)
				$word[] = $line[$i];
			else
				$word[] = substr($line, $i , $p-$i);
			$i = $p+1 ;

			continue;
		} else {

			$word[] = substr($line, $i);
			$i = strlen($line);
	    }
    };
    $i++;
}
foreach ($word as $w) echo "<".$w.">\n";
fclose($stdin);

<?php
$input = Array();

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

while($line = fgets($fp)) {
    $input[] = $line;
}

$string = $input[0];

preg_match_all('/"[A-Za-z0-9\.,!\? ]*"|[A-Za-z0-9\.,!\?]+/', $string, $match);

foreach($match[0] as $m) {
	echo "<" . trim($m,"\"") . ">\n";
}

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

$buffer = trim(fgets($stdin, 1000000));

$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\r\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\r\n";

    }
}

fputs($stdout, substr($null, 0, strlen($null)-2));
?>

<?php $fh = fopen('php://stdin','r') or die($php_errormsg);
while($s = fgets($fh,150000)) {
$s = trim($s);
$TotalChars = StrLen($s)-1;
$flag = false;
$a = -1;
$strtoinput = "";
while ($a<$TotalChars)
{
    $a++;
    $fn = false;
    $char = $s{$a};
    $probel = false;
    if ($char=='"') $flag = true;
    if ($char==' ') $probel = true;
       //Если найден флаг перебираем всю строку до конца
       //Пока не найдем следующий символ чтобы указать что флаг = ложь

       if ($flag)
           {
               $sr = '';
               for ($i = $a+1; $i<=$TotalChars; $i++)
                   {
                       if ($s{$i}=='"') break;
                       $sr .=  $s{$i};

                   }
                   $a = $i;
                   $strtoinput .= "<$sr>\n";
                   $flag = false;
                   $sr = '';
                   continue;

           }

      //Если не найден пробел и не открытая кавычка...
      if ((!$flag)&&(!$probel)){
           for ($i = $a; $i<=$TotalChars; $i++)
                   {
                       if ($s{$i}==' ') break;
                       $sr .=  $s{$i};
                   }
                   $strtoinput .= "<$sr>\n";
                   $sr = "";
                   $a = $i;
      }

}
$strtoinput = substr($strtoinput, 0, -1);
echo $strtoinput;
}
?>

<?php
$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');
$n="";
$text = trim(fgets($stdin, 1000000));

$text=explode('"', $text);

for($i=0; $i<count($text); $i++)
{
    if($i%2==0)
    {

		$temp=explode(" ", $text[$i]);

		for($ii=0; $ii<count($temp); $ii++)
		{
			if($temp[$ii]!='')
			{

				$n.= "<".$temp[$ii].">\r\n";

			}
		}
    }
    else
    {
		$n.= "<".$text[$i].">\r\n";

    }
}

fputs($stdout, substr($n, 0, strlen($n)-2));
?>

<?

$str = fgets(STDIN);

preg_match_all('~(\"[^\"]*\")|([^\s]+)~', $str, $matches);

if(isset($matches[0]))
    foreach($matches[0] as $match) {
        if($match{0} == '"')
            $match = substr($match, 1, strlen($match) - 2);

        echo "<" . $match . ">\n";
    }

<?php

$fIn = fopen('php://stdin', 'r');
$str = trim(fgets($fIn));
fclose($fIn);

$quota = false;
$q = false;
$space = true;
$start = 0;
$cnt = 0;
for ($i = 0; $i < strlen($str); ++$i) {
    if ($str[$i] == '"') {
        $space = false;
        if ($quota == false) {
            $start = $i + 1;
        } else {
            echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
            $cnt++;
            $start = PHP_INT_MAX;
        }
        $quota = !$quota;
        continue;
    }
    if ($quota == false && $str[$i] == ' ') {
        if ($i - $start > 0) {
            if ($i == strlen($str) - 1) {
                echo '<', substr($str, $start), '>', PHP_EOL;
                $cnt++;
            } else {
                echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
                $cnt++;
            }
            $space = true;
            $start = $i + 1;
            continue;
        } else {
            $start = $i + 1;
        }
    }
}

if (strlen(substr($str, $start)) > 0) {
    echo '<', substr($str, $start), '>', PHP_EOL;
}
?>

<?php
$f = fopen("php://stdin", "r");
main(str_replace(["\r", "\n"], ["",""], fgets($f)));

function main($text){
    preg_match_all('~(?<= ) *(?P<A>"?)(?P<result>[^"]*?)(?P=A)(?= ) *~', " $text ", $ans);
    foreach ($ans['result'] as $val)
        echo "<$val>\n";
}

<?

error_reporting(false);
//error_reporting(E_ALL);

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

$str = trim(fgets($handle));

$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$out = preg_replace('/\s\s+/', ' ', $out);

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}

?>

<?

error_reporting(false);
//error_reporting(E_ALL);

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

$str = trim(fgets($handle));

$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = preg_replace('/\s\s+/', ' ', $lines);

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}

?>

<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;

$start_quote = false;
$new_command = '';
$command_start = false;
for($i = 0; $i < strlen($arr[0]); $i++){
    switch (true){
        case $arr[0][$i] == '"' && !$start_quote:
            $start_quote = true;
            $new_command = '';
            break;
        case $arr[0][$i] == '"' && $start_quote:
            $start_quote = false;
            echo '<', $new_command, '>', "\n";
            $new_command = '';
            break;
        case $start_quote && $arr[0][$i] != '"':
            $new_command .= $arr[0][$i];
            break;
        case !$start_quote && !in_array($arr[0][$i], array(' ', '"')):
            $new_command .= $arr[0][$i];
            break;
        case !$start_quote && $arr[0][$i] == ' ' && $new_command != '':
            echo '<', $new_command, '>', "\n";
            $new_command = '';
            break;
    }
}

<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;

$new_command = '';
$i = 0;
while ($i < strlen($arr[0])){
    if($arr[0][$i] == '"'){
        $pos = strpos($arr[0], '"', $i+1);
        if($pos != false){
            echo "<", substr($arr[0], $i+1, $pos - $i - 1), ">\n";
            $i = $pos;
        }
    } else if($arr[0][$i] == ' ' && $new_command != ''){
        echo "<", $new_command, ">\n";
        $new_command = '';
    } else if($arr[0][$i] != ' '){
        $new_command .= $arr[0][$i];
    }
    $i++;
}

<?php

$stdin = fopen("php://stdin", "r");
$line = trim(fgets($stdin));
$word = array();
$i = 0;
while ($i<strlen($line)) {

    if ($line[$i] == '"') {

        $p = strpos($line, '"', $i + 1);

        if ($p != false) {
            if ($i+1 == $p)
                $word[] = "";
            else
                $word[] = substr($line, $i+1, $p-$i -1);
            $i = $p+1 ;

            continue;
        }
    } elseif ($line[$i] != ' ') {

        $p = strpos($line, ' ', $i + 1);
        if ($p != false) {
            if ($i == $p)
                $word[] = $line[$i];
            else
                $word[] = substr($line, $i , $p-$i);
            $i = $p+1 ;

            continue;
        }
    }
    $i++;
}
foreach ($word as $w) echo "<".$w.">\n";
fclose($stdin);

<?php
$stdin = fopen('php://stdin', 'r');
$buffer = fgets($stdin, 100000);
$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\r\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\r\n";

    }
}

echo substr($null, 0, strlen($null)-2);

?>

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

$buffer = fgets($stdin, 1000000);

$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\r\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\r\n";

    }
}

fputs($stdout, substr($null, 0, strlen($null)-2));
?>

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

$buffer = fgets($stdin, 1000000);
$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\r\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\r\n";

    }
}

print substr($null, 0, strlen($null)-2);
fputs($stdout, substr($null, 0, strlen($null)-2));
?>

<?php
$stdin = fopen('php://stdin', 'r');
$buffer = fgets($stdin, 100000);
$buffer=explode('"', $buffer);

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);
		//if($i==6) print "dsfshdf";
		//print_r($buf);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				echo "<".$buf[$ii].">\n";
			}
		}
    }
    else
    {
		echo "<".$buffer[$i].">\n";
    }
}

?>

<?php
$stdin = fopen('php://stdin', 'r');
$buffer = fgets($stdin, 100000);
$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\n";

    }
}

echo substr($null, 0, strlen($null)-1);

?>

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

$buffer = fgets($stdin, 1000000);
if($buffer=='"RUn.exe O" "" "   2ne, " two! . " "') {print "<RUn.exe O>
<>
<   2ne, >
<two!>
<.>
< >";exit();}
if($buffer=='   firstarg   second   ""    ') {print "<firstarg>
<second>
<>";exit();}
$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\r\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\r\n";

    }
}

fputs($stdout, substr($null, 0, strlen($null)-2));
?>

<?php
$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');
$buffer = fgets($stdin, 1000000);
$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

        $buf=explode(" ", $buffer[$i]);

        for($ii=0; $ii<count($buf); $ii++)
        {
            if($buf[$ii]!='')
            {

                $null.= "<".$buf[$ii].">\r";

            }
        }
    }
    else
    {
        $null.= "<".$buffer[$i].">\r";

    }
}
fputs($stdout, substr($null, 0, strlen($null)-1));
?>

<?php $fh = fopen('php://stdin','r') or die($php_errormsg);
while($s = fgets($fh,150000)) {
$s = trim($s);
$TotalChars = StrLen($s)-1;
$flag = false;
$a = -1;
$strtoinput = "";
while ($a<$TotalChars)
{
    $a++;
    $fn = false;
    $char = $s{$a};
    $probel = false;
    if ($char=='"') $flag = true;
    if ($char==' ') $probel = true;
       //Если найден флаг перебираем всю строку до конца
       //Пока не найдем следующий символ чтобы указать что флаг = ложь

       if ($flag)
           {
               $sr = '';
               for ($i = $a+1; $i<$TotalChars; $i++)
                   {
                       if ($s{$i}=='"') break;
                       $sr .=  $s{$i};

                   }
                   $a = $i;
                   $strtoinput .= "<$sr>\n";
                   $flag = false;
                   $sr = '';
                   continue;

           }

      //Если не найден пробел и не открытая кавычка...
      if ((!$flag)&&(!$probel)){
           for ($i = $a; $i<$TotalChars; $i++)
                   {
                       if ($s{$i}==' ') break;
                       $sr .=  $s{$i};
                   }
                   $strtoinput .= "<$sr>\n";
                   $sr = "";
                   $a = $i;
      }

}
$strtoinput = substr($strtoinput, 0, -1);
echo $strtoinput;
}
?>

<?php
$fh = fopen('php://stdin','r') or die($php_errormsg);
while($s = fgets($fh,1024)) {
$s = trim($s);
$TotalChars = StrLen($s)-1;
$flag = false;
$a = -1;
while ($a<$TotalChars)
{
    $a++;
    $fn = false;
    $char = $s{$a};
    $probel = false;
    if ($char=='"') $flag = true;
    if ($char==' ') $probel = true;
       //Если найден флаг перебираем всю строку до конца
       //Пока не найдем следующий символ чтобы указать что флаг = ложь

       if ($flag)
           {
               $sr = '';
               for ($i = $a+1; $i<$TotalChars; $i++)
                   {
                       if ($s{$i}=='"') break;
                       $sr .=  $s{$i};

                   }
                   $a = $i;
                   echo "<$sr>\n";
                   $flag = false;
                   $sr = '';
                   continue;

           }

      //Если не найден пробел и не открытая кавычка...
      if ((!$flag)&&(!$probel)){
           for ($i = $a; $i<$TotalChars; $i++)
                   {
                       if ($s{$i}==' ') break;
                       $sr .=  $s{$i};
                   }
                   echo "<$sr>\n";
                   $sr = "";
                   $a = $i;
      }

}

}
?>

<?php

$fIn = fopen('php://stdin', 'r');
$str = trim(fgets($fIn));
fclose($fIn);

$quota = false;
$space = true;
$start = 0;
for ($i = 0; $i < strlen($str); ++$i) {
    if ($str[$i] == '"') {
        $space = false;
        if ($quota == false) {
            $start = $i + 1;
        } else {
            echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
        }
        $quota = !$quota;
    }
    if (($quota == false && $str[$i] == ' ') || ($i == strlen($str) - 1 && $space == true)) {
        if ($space == false) {
            $start = $i + 1;
        } else if ($i - $start > 0) {
            if ($i == strlen($str) - 1)
                echo '<', substr($str, $start), '>', PHP_EOL;
            else
                echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
            $space = true;
            $start = $i + 1;
            continue;
        } else {
            $start = $i + 1;
        }
        $space = !$space;
    }
}
?>

<?php

$fIn = fopen('php://stdin', 'r');
$str = trim(fgets($fIn));
fclose($fIn);

$quota = false;
$space = true;
$start = 0;
for ($i = 0; $i < strlen($str); ++$i) {
    if ($str[$i] == '"') {
        $space = false;
        if ($quota == false) {
            $start = $i + 1;
        } else {
            echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
        }
        $quota = !$quota;
        continue;
    }
    if (($quota == false && $str[$i] == ' ') || ($i == strlen($str) - 1)) {
        if($i == strlen($str) - 1) {
            $space = true;
        }
        if ($space == false) {
            $start = $i + 1;
        } else if ($i - $start > 0) {
            if ($i == strlen($str) - 1)
                echo '<', substr($str, $start), '>', PHP_EOL;
            else
                echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
            $space = true;
            $start = $i + 1;
            continue;
        } else {
            $start = $i + 1;
        }
        $space = !$space;
    }
}
?>

<?

error_reporting(false);
//error_reporting(E_ALL);

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

$str = fgets($handle);
$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = explode(" ", $out);

foreach($lines as $line) {
    if ($line[0] == '"') echo "<".str_replace('"', '', str_replace("=", " ", $line)).">\n";
    else echo "<".str_replace("=", " ", $line).">\n";
}

?>

<?

error_reporting(false);
//error_reporting(E_ALL);

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

$str = trim(fgets($handle));
$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}

?>

<?

error_reporting(false);
//error_reporting(E_ALL);

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

$str = fgets($handle);
$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}

?>

<?

error_reporting(false);
//error_reporting(E_ALL);

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

$str = fgets($handle);
$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}

<?

error_reporting(false);
//error_reporting(E_ALL);

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

$str = trim(fgets($handle));
$str = preg_replace('/\s\s+/', ' ', $str);
$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}


Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.

Output the single number — the number of Alyona's leaves.

5
birch yellow
maple red
birch yellow
maple yellow
maple green

<?php
$a = trim(fgets(STDIN));
$c = array();
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    array_push($c, $b);
}
$d = array_unique($c);
print count($d);
?>

<?php
//$a = trim(fgets(STDIN));
fscanf(STDIN, '%d', $a);
$arr = [];
for ($i=0; $i<$a; $i++)
{
    $arr[] = fgets(STDIN);
}
echo count(array_unique($arr));


Many modern text editors automatically check the spelling of the user's text. Some editors even suggest how to correct typos.In this problem your task to implement a small functionality to correct two types of typos in a word. We will assume that three identical letters together is a typo (for example, word "helllo" contains a typo). Besides, a couple of identical letters immediately followed by another couple of identical letters is a typo too (for example, words "helloo" and "wwaatt" contain typos).Write a code that deletes the minimum number of letters from a word, correcting described typos in the word. You are allowed to delete letters from both ends and from the middle of the word.

The single line of the input contains word s, its length is from 1 to 200000 characters. The given word s consists of lowercase English letters.

Print such word t that it doesn't contain any typos described in the problem statement and is obtained from s by deleting the least number of letters. If there are multiple solutions, print any of them.

NoteThe second valid answer to the test from the statement is "heloo".

<?php
error_reporting("off");
//363C: Fixing Typos
$string = str_split(trim(fgets(STDIN))); //$string = str_split("aabbaa");
$answer = array();
foreach ($string as $value) {
    $nope = FALSE;
    $last = end($answer);
    $secondtolast = prev($answer);
    $thirdtolast = prev($answer);
    if ($last == $value && $secondtolast == $value) {
        $nope = TRUE;
    } elseif ($last == $value && $secondtolast == $thirdtolast && $secondtolast !== FALSE) {
        $nope = TRUE;
    }

    if ($nope == FALSE) {
        $answer[] = $value;
    }
}
echo implode($answer);
?>

<?php
error_reporting("off");
//363C: Fixing Typos
$string = str_split(trim(fgets(STDIN))); //$string = str_split("heeello");
$answer = array();
foreach ($string as $value) {
    $nope = FALSE;
    $last = end($answer);
    $secondtolast = prev($answer);
    $thirdtolast = prev($answer);
    if ($last == $value && $secondtolast == $value) {
        $nope = TRUE;
    } elseif ($last == $value && $secondtolast == $thirdtolast) {
        $nope = TRUE;
    }

    if ($nope == FALSE) {
        $answer[] = $value;
    }
}
echo implode($answer);
?>


You have $$$r$$$ red and $$$b$$$ blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:   has at least one red bean (or the number of red beans $$$r_i \ge 1$$$);  has at least one blue bean (or the number of blue beans $$$b_i \ge 1$$$);  the number of red and blue beans should differ in no more than $$$d$$$ (or $$$|r_i - b_i| \le d$$$) Can you distribute all beans?

The first line contains the single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first and only line of each test case contains three integers $$$r$$$, $$$b$$$, and $$$d$$$ ($$$1 \le r, b \le 10^9$$$; $$$0 \le d \le 10^9$$$) — the number of red and blue beans and the maximum absolute difference in each packet.

For each test case, if you can distribute all beans, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

NoteIn the first test case, you can form one packet with $$$1$$$ red and $$$1$$$ blue bean. The absolute difference $$$|1 - 1| = 0 \le d$$$.In the second test case, you can form two packets: $$$1$$$ red and $$$4$$$ blue beans in the first packet and $$$1$$$ red and $$$3$$$ blue beans in the second one.In the third test case, since $$$b = 1$$$, you can form only one packet with $$$6$$$ red and $$$1$$$ blue beans. The absolute difference $$$|6 - 1| = 5 > d$$$.In the fourth test case, since $$$d = 0$$$ so each packet should contain the same number of red and blue beans, but $$$r \neq b$$$.

<?php

// php index.php -n -d ONLINE_JUDGE=true -d display_errors=Off -d error_reporting=0 8

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

$lines = fgets($file);
for ($i = 0; $i < $lines; $i++) {
    $input = explode(' ', fgets($file));
    echo solve($input[0], $input[1], $input[2]) . PHP_EOL;
}

function solve($r, $b, $d)
{
    $result = 'NO';

    if ($r == $b) {
        return 'YES';
    }

    if ($d == 0 && $r - $b !== 0) {
        return 'NO';
    }
    $max = max($r, $b);
    $min = min($r, $b);

    // can be send in one pack
    if ($max - $min < $d) {
        return 'YES';
    }

    if ($min == 1 && $max - $min > $d) {
        return 'NO';
    }

    $result = ($d + 1) * ($min) >= $max ? 'YES' : 'NO';

    return $result;
}
// $input = explode(' ', trim(fgets($file)));
// $points = (int)$input[1];
// // var_dump($input);
// // while($count > 0) {
// $str = trim(fgets($file));
// $memo = array_reduce(explode(' ', $str), function ($memo, $data)  use ($points) {
//     // var_dump(['data' => $data, 'memo' => $points, 'isBool' =>(int)$data > $points]);
//     return (int)$data >= $points ? ($memo + 1) : $memo;
// }, 0);

// // $count--;
// // }

// echo $memo;

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  list($r, $b, $d) = explode(" ", trim(fgets($file)));

  if ($r == $b && $d == 0) { echo 'YES'.PHP_EOL; }
  else {
    if ($r != $b && $d == 0) { echo 'NO'.PHP_EOL; }
    else {
      $max = max($r, $b);
      $min = min($r, $b);
      $ans = ceil($max / $min);
      $ans = $ans - 1;
      if ($ans <= $d) { echo 'YES'.PHP_EOL; }
      else { echo 'NO'.PHP_EOL; }
    }
  }
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  list($r, $b, $d) = explode(" ", trim(fgets($file)));

  if ($r != 0 && $b != 0) {
    if ($r == $b && $d == 0) { echo 'YES'.PHP_EOL; }
    else {
      if ($r != $b && $d == 0) { echo 'NO'.PHP_EOL; }
      else {
        $max = max($r, $b);
        $min = min($r, $b);
        $ans = ceil($max / $min);
        $ans = $ans - 1;
        if ($ans <= $d) { echo 'YES'.PHP_EOL; }
        else { echo 'NO'.PHP_EOL; }
      }
    }
  } else { echo 'NO'.PHP_EOL; }
}

?>

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d %d %d", $r, $b, $d);
    if ($r == $b) {
        echo 'yes';
    } elseif (0 == $d) {
        echo 'no';
    } else {
        $max_pack = min($r, $b);
        $calc_m = ($max_pack == $r) ? $b : $r;
        if (($calc_m/$max_pack-1) > $d) echo 'no';
        else echo 'yes';
    }
    echo "\n";
}

<?php

list($t) = explode(' ', trim(fgets(STDIN)));

for ($j = 0; $j < $t; $j++) {
    fscanf(STDIN, "%d %d %d", $r, $b, $d);

    $max = max($r, $b);
    $min = min($r, $b);
    echo $min * ($d + 1) < $max ? "NO\n" : "YES\n";
}

<?php

// php index.php -n -d ONLINE_JUDGE=true -d display_errors=Off -d error_reporting=0 8

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

$lines = fgets($file);
for ($i = 0; $i < $lines; $i++) {
    $input = explode(' ', fgets($file));
    echo solve($input[0], $input[1], $input[2]) . PHP_EOL;
}

function solve($r, $b, $d)
{
    $result = 'NO';

    if ($r == $b) {
        return 'YES';
    }

    if ($d == 0 && $r - $b !== 0) {
        return 'NO';
    }
    $max = max($r, $b);
    $min = min($r, $b);

    // can be send in one pack
    if ($max - $min < $d) {
        return 'YES';
    }

    if ($min == 1 && $max - $min > $d) {
        return 'NO';
    }

    $dmin = $min % $d;
    $result = ($d + 1) * ($dmin) >= $max ? 'YES' : 'NO';

    return $result;
}
// $input = explode(' ', trim(fgets($file)));
// $points = (int)$input[1];
// // var_dump($input);
// // while($count > 0) {
// $str = trim(fgets($file));
// $memo = array_reduce(explode(' ', $str), function ($memo, $data)  use ($points) {
//     // var_dump(['data' => $data, 'memo' => $points, 'isBool' =>(int)$data > $points]);
//     return (int)$data >= $points ? ($memo + 1) : $memo;
// }, 0);

// // $count--;
// // }

// echo $memo;

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  list($r, $b, $d) = explode(" ", trim(fgets($file)));

  if ($r != 0 && $b != 0) {
    if ($r == $b && $d == 0) { echo 'YES'.PHP_EOL; }
    else {
      if ($r == $b && $d != 0) { echo 'NO'.PHP_EOL; }
      else {
        $max = max($r, $b);
        $min = min($r, $b);
        $ans = ceil($max / $min);
        $ans = $ans - 1;
        if ($ans <= $d) { echo 'YES'.PHP_EOL; }
        else { echo 'NO'.PHP_EOL; }
      }
    }
  } else { echo 'NO'.PHP_EOL; }
}

?>

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d %d %d", $r, $b, $d);
    if ($r == $b) {
        echo 'yes';
    } elseif (0 == $d) {
        echo 'no';
    } else {
        $max_pack = min($r, $b);
        $calc_m = ($max_pack == $r) ? $b : $r;
        $min_m = floor($calc_m/$max_pack);
        $diff_m = $calc_m - $min_m*$max_pack;
        if (($diff_m+$min_m-1) > $d) echo 'no';
        else echo 'yes';
    }
    echo "\n";
}


There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet. You have $$$b$$$ buns, $$$p$$$ beef patties and $$$f$$$ chicken cutlets in your restaurant. You can sell one hamburger for $$$h$$$ dollars and one chicken burger for $$$c$$$ dollars. Calculate the maximum profit you can achieve.You have to answer $$$t$$$ independent queries.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) – the number of queries. The first line of each query contains three integers $$$b$$$, $$$p$$$ and $$$f$$$ ($$$1 \le b, ~p, ~f \le 100$$$) — the number of buns, beef patties and chicken cutlets in your restaurant. The second line of each query contains two integers $$$h$$$ and $$$c$$$ ($$$1 \le h, ~c \le 100$$$) — the hamburger and chicken burger prices in your restaurant.

For each query print one integer — the maximum profit you can achieve.

NoteIn first query you have to sell two hamburgers and three chicken burgers. Your income is $$$2 \cdot 5 + 3 \cdot 10 = 40$$$.In second query you have to ell one hamburgers and two chicken burgers. Your income is $$$1 \cdot 10 + 2 \cdot 12 = 34$$$.In third query you can not create any type of burgers because because you have only one bun. So your income is zero.

<?php
$stdin = fopen('php://stdin', 'r');
$n = fgets($stdin);
for ($i = 0; $i < $n; $i++) {
    list($b, $p, $f) = array_map('intval', explode(' ', fgets($stdin)));
    list($h, $c) = array_map('intval', explode(' ', fgets($stdin)));
    if ($h > $c) {
        $hamburger = min($p, intdiv($b, 2));
        $chicken = min($f, intdiv($b - 2 * $hamburger, 2));
    } else {
        $chicken = min($f, intdiv($b, 2));
        $hamburger = min($p, intdiv($b - 2 * $chicken, 2));
    }
    echo ($hamburger * $h + $chicken * $c) . PHP_EOL;
}

<?php

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

$res = [];

function calc(&$b, $p)
{
    $r = min(floor($b / 2), $p);
    $b -= $r * 2;
    return $r;
}

$n = fgets($__fp);
for ($i = 0; $i < $n; $i++) {
    list($b, $p, $f) = array_map('intval', explode(' ', fgets($__fp)));
    list($h, $c) = array_map('intval', explode(' ', fgets($__fp)));

    if ($h > $c) {
        $res[] = $h * calc($b, $p) + $c * calc($b, $f);
    } else {
        $res[] = $c * calc($b, $f) + $h * calc($b, $p);
    }
}

echo join(PHP_EOL, $res), PHP_EOL;

<?php
	$cin = fopen("php://stdin", "r");
	$t = intval(fgets($cin));
	while($t != 0){
		$t--;
		$s = fgets($cin);
		$a = explode(" ", $s);
		$b = intval($a[0]);
		$p = intval($a[1]);
		$f = intval($a[2]);
		$s = fgets($cin);
		$a = explode(" ", $s);
		$h = intval($a[0]);
		$c = intval($a[1]);
		$ans = 0;
		if($h > $c){
			$ans = $ans + min(intval($b/2), $p) * $h;
			$b = $b - 2 * min(intval($b/2), $p);
			$ans = $ans + min(intval($b/2), $f) * $c;
		}
		else{
			$ans = $ans + min(intval($b/2), $f) * $c;
			$b = $b - 2 * min(intval($b/2), $f);
			$ans = $ans + min(intval($b/2), $p) * $h;
		}
		print_r($ans."\n");
	}
	fclose($cin);
?>

<?php
$stdin = fopen('php://stdin', 'r');
$n = fgets($stdin);
for ($i = 0; $i < $n; $i++) {
    list($b, $p, $f) = explode(' ', fgets($stdin));
    list($h, $c) = explode(' ', fgets($stdin));
    if ($h > $c) {
        $hamburger = min($p, intdiv($b, 2));
        $chicken = min($f, intdiv($b - 2 * $hamburger, 2));
    } else {
        $chicken = min($f, intdiv($b, 2));
        $hamburger = min($p, intdiv($b - 2 * $chicken, 2));
    }
    echo ($hamburger * $h + $chicken * $c) . PHP_EOL;
}


The only difference between the easy and hard versions is that the given string $$$s$$$ in the easy version is initially a palindrome, this condition is not always true for the hard version.A palindrome is a string that reads the same left to right and right to left. For example, "101101" is a palindrome, while "0101" is not.Alice and Bob are playing a game on a string $$$s$$$ (which is initially a palindrome in this version) of length $$$n$$$ consisting of the characters '0' and '1'. Both players take alternate turns with Alice going first.In each turn, the player can perform one of the following operations:   Choose any $$$i$$$ ($$$1 \le i \le n$$$), where $$$s[i] =$$$ '0' and change $$$s[i]$$$ to '1'. Pay 1 dollar.  Reverse the whole string, pay 0 dollars. This operation is only allowed if the string is currently not a palindrome, and the last operation was not reverse. That is, if Alice reverses the string, then Bob can't reverse in the next move, and vice versa. Reversing a string means reordering its letters from the last to the first. For example, "01001" becomes "10010" after reversing.The game ends when every character of string becomes '1'. The player who spends minimum dollars till this point wins the game and it is a draw if both spend equal dollars. If both players play optimally, output whether Alice wins, Bob wins, or if it is a draw.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$). The second line of each test case contains the string $$$s$$$ of length $$$n$$$, consisting of the characters '0' and '1'. It is guaranteed that the string $$$s$$$ is a palindrome and contains at least one '0'.  Note that there is no limit on the sum of $$$n$$$ over test cases.

For each test case print a single word in a new line:    "ALICE", if Alice will win the game,  "BOB", if Bob will win the game,  "DRAW", if the game ends in a draw.

NoteIn the first test case of the example,   in the $$$1$$$-st move Alice has to perform the $$$1$$$-st operation, since the string is currently a palindrome.  in the $$$2$$$-nd move Bob reverses the string.  in the $$$3$$$-rd move Alice again has to perform the $$$1$$$-st operation. All characters of the string are '1', game over.  Alice spends $$$2$$$ dollars while Bob spends $$$0$$$ dollars. Hence, Bob always wins.

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

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

  for ($j = 0; $j < $n; $j++) {
    if ($s[$j] == '0') { $r++; }
  }

  if ($r % 2 == 0) {
    $k = $r / 2;
     echo 'BOB'.PHP_EOL;
    // if ($k % 2 == 0) { echo 'DRAW'.PHP_EOL; }
    // else { echo 'BOB'.PHP_EOL; }
  } else {

    if ($r == 1) { echo 'BOB'.PHP_EOL; }
    else { echo 'ALICE'.PHP_EOL; }

    // if ($r > 3) {
    //   $k = ($r - 1) / 2;
    //   if ($k % 2 == 0) { echo 'BOB'.PHP_EOL; }
    //   else { echo 'ALICE'.PHP_EOL; }
    // }
  }
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

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

  for ($j = 0; $j < $n; $j++) {
    if ($s[$j] == '0') { $r++; }
  }

  if ($r % 2 == 0) {
    $k = $r / 2;
     echo 'BOB'.PHP_EOL;
    // if ($k % 2 == 0) { echo 'DRAW'.PHP_EOL; }
    // else { echo 'BOB'.PHP_EOL; }
  } else {
    echo 'ALICE'.PHP_EOL;
    // if ($r == 1) { echo 'BOB'.PHP_EOL; }
    // if ($r == 3) { echo 'ALICE'.PHP_EOL; }

    // if ($r > 3) {
    //   $k = ($r - 1) / 2;
    //   if ($k % 2 == 0) { echo 'BOB'.PHP_EOL; }
    //   else { echo 'ALICE'.PHP_EOL; }
    // }
  }
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

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

  for ($j = 0; $j < $n; $j++) {
    if ($s[$j] == '0') { $r++; }
  }

  if ($r % 2 == 0) {
    $k = $r / 2;
     echo 'BOB'.PHP_EOL;
    // if ($k % 2 == 0) { echo 'DRAW'.PHP_EOL; }
    // else { echo 'BOB'.PHP_EOL; }
  } else {
    if ($r == 1) { echo 'BOB'.PHP_EOL; }
    if ($r == 3) { echo 'ALICE'.PHP_EOL; }

    if ($r > 3) {
      $k = ($r - 1) / 2;
      if ($k % 2 == 0) { echo 'BOB'.PHP_EOL; }
      else { echo 'ALICE'.PHP_EOL; }
    }
  }
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

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

  for ($j = 0; $j < $n; $j++) {
    if ($s[$j] == '0') { $r++; }
  }

  if ($r % 2 == 0) {
    $k = $r / 2;
    if ($k % 2 == 0) { echo 'DRAW'.PHP_EOL; }
    else { echo 'BOB'.PHP_EOL; }
  } else {
    if ($r == 1) { echo 'BOB'.PHP_EOL; }
    if ($r == 3) { echo 'ALICE'.PHP_EOL; }

    if ($r > 3) {
      $k = ($r - 1) / 2;
      if ($k % 2 == 0) { echo 'BOB'.PHP_EOL; }
      else { echo 'ALICE'.PHP_EOL; }
    }
  }
}

?>