You are given two segments $$$[l_1; r_1]$$$ and $$$[l_2; r_2]$$$ on the $$$x$$$-axis. It is guaranteed that $$$l_1 < r_1$$$ and $$$l_2 < r_2$$$. Segments may intersect, overlap or even coincide with each other.    The example of two segments on the $$$x$$$-axis. Your problem is to find two integers $$$a$$$ and $$$b$$$ such that $$$l_1 \le a \le r_1$$$, $$$l_2 \le b \le r_2$$$ and $$$a \ne b$$$. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment $$$[l_1; r_1]$$$ and the second one belongs to the segment $$$[l_2; r_2]$$$.It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Each of the next $$$q$$$ lines contains four integers $$$l_{1_i}, r_{1_i}, l_{2_i}$$$ and $$$r_{2_i}$$$ ($$$1 \le l_{1_i}, r_{1_i}, l_{2_i}, r_{2_i} \le 10^9, l_{1_i} < r_{1_i}, l_{2_i} < r_{2_i}$$$) — the ends of the segments in the $$$i$$$-th query.

Print $$$2q$$$ integers. For the $$$i$$$-th query print two integers $$$a_i$$$ and $$$b_i$$$ — such numbers that $$$l_{1_i} \le a_i \le r_{1_i}$$$, $$$l_{2_i} \le b_i \le r_{2_i}$$$ and $$$a_i \ne b_i$$$. Queries are numbered in order of the input. It is guaranteed that the answer exists. If there are multiple answers, you can print any.

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

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

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

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

$ir = new InputReader();

/* TASK */

$q = $ir->readInt();

while ($q--) {
	list($l1, $r1, $l2, $r2) = $ir->readArrayOfInt(4);
	if ($l1!=$r2) {
		echo "$l1 $r2\n";
	} else {
		echo "$r1 $l2\n";
	}
	flush();
}

<?
$stdin = fopen('php://stdin', 'r');
ini_set('display_errors', '1');
function read() {
    return trim(fgets(STDIN));
}
$t1 = microtime(true);
$debag = 0;
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
$n = read();
$poss = [];
for ($i = 0; $i < $n; $i++) {
    $poss[] = explode(' ', read());
}

for ($i = 0; $i < $n; $i++) {
    if ($poss[$i][0] !== $poss[$i][3]) {
        echo $poss[$i][0].' '.$poss[$i][3]."\n";
    } else {
        echo $poss[$i][1].' '.$poss[$i][2]."\n";
    }
}

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
if ($debag === 1) {
    echo '<hr>' . round(microtime(true) - $t1, 3) . ' sec';
}

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

$string = stream_get_contents($dir);
$arr = explode (PHP_EOL,$string);
$numOfRequests = $arr[0];

for ($i=1;$i<=$numOfRequests;$i++){
$input1 = explode (' ',$arr[$i]);
    $l1 = $input1[0];
    $r1 = $input1[1];
    $l2 = $input1[2];
    $r2 = $input1[3];
    $trya = min ($l1,$l2);
    if ($trya == $l1) {
        $tryb = $r2;
    } else {
        $tryb = $r1;
    }
    if ($l1 == $trya) {
        echo($trya . " " . $tryb . PHP_EOL);
    } else {
        echo($tryb . " " . $trya . PHP_EOL);
    }
}
?>

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

$f = fgets($stdin);

while($f = fgets($stdin)){
    $array = explode(' ', $f);
    if ($array[3] > $array[1]) {
        echo $array[0] . ' ' . $array[3] . "\n";
    } else {
        echo $array[2] . ' ' . $array[1] . "\n";
    }
}

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

$f = fgets($stdin);

while($f = fgets($stdin)){
    $array = explode(' ', $f);
    echo $array[0] . ' ' . $array[3] . "\n";
}

<?
$stdin = fopen('php://stdin', 'r');
ini_set('display_errors', '1');
function read() {
    return trim(fgets(STDIN));
}
$t1 = microtime(true);
$debag = 1;
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
$n = read();
$poss = [];
for ($i = 0; $i < $n; $i++) {
    $poss[] = explode(' ', read());
}

for ($i = 0; $i < $n; $i++) {
    if ($poss[$i][0] !== $poss[$i][3]) {
        echo $poss[$i][0].' '.$poss[$i][3]."\n";
    } else {
        echo $poss[$i][1].' '.$poss[$i][2]."\n";
    }
}

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
if ($debag === 1) {
    echo '<hr>' . round(microtime(true) - $t1, 3) . ' sec';
}

<?
$stdin = fopen('php://stdin', 'r');
ini_set('display_errors', '1');
function read() {
    return trim(fgets(STDIN));
}
$t1 = microtime(true);
$debag = 0;
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
$n = read();
$poss = [];
for ($i = 0; $i < $n; $i++) {
    $poss[] = explode(' ', read());
}

for ($i = 0; $i < $n; $i++) {
    echo $poss[$i][0].' '.$poss[$i][3]."\n";
}

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
if ($debag === 1) {
    echo '<hr>' . round(microtime(true) - $t1, 3) . ' sec';
}

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

$string = stream_get_contents($dir);
$arr = explode (PHP_EOL,$string);
$numOfRequests = $arr[0];

for ($i=1;$i<=$numOfRequests;$i++){
$input1 = explode (' ',$arr[$i]);
    $l1 = $input1[0];
    $r1 = $input1[1];
    $l2 = $input1[2];
    $r2 = $input1[3];
    $trya = min ($l1,$l2);
    if ($trya = $l1) {
        $tryb = $r2;
    } else {
        $tryb = $r1;
    }
    if ($l1 = $trya) {
        echo($trya . " " . $tryb . PHP_EOL);
    } else {
        echo($tryb . " " . $trya . PHP_EOL);
    }
}
?>

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

$string = stream_get_contents($dir);
$arr = explode (PHP_EOL,$string);
$numOfRequests = $arr[0];
echo $arr[0];

for ($i=1;$i<=$numOfRequests;$i++){
$input1 = explode (' ',$arr[$i]);
    $l1 = $input1[0];
    $r1 = $input1[1];
    $l2 = $input1[2];
    $r2 = $input1[3];
    $trya = min ($l1,$l2);
    if ($trya = $l1) {
        $tryb = $r2;
    } else {
        $tryb = $r1;
    }
    echo ($trya." ".$tryb."\n");
}
?>

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

$string = stream_get_contents($dir);
$arr = explode (PHP_EOL,$string);
$numOfRequests = $arr[0];
//echo $arr[0];

for ($i=1;$i<=$numOfRequests;$i++){
$input1 = explode (' ',$arr[$i]);
    $l1 = $input1[0];
    $r1 = $input1[1];
    $l2 = $input1[2];
    $r2 = $input1[3];
    $trya = min ($l1,$l2);
    if ($trya = $l1) {
        $tryb = $r2;
    } else {
        $tryb = $r1;
    }
    echo ($trya." ".$tryb."\n");
}
?>


A permutation — is a sequence of length $$$n$$$ integers from $$$1$$$ to $$$n$$$, in which all the numbers occur exactly once. For example, $$$[1]$$$, $$$[3, 5, 2, 1, 4]$$$, $$$[1, 3, 2]$$$ — permutations, and $$$[2, 3, 2]$$$, $$$[4, 3, 1]$$$, $$$[0]$$$ — no.Polycarp was recently gifted a permutation $$$a[1 \dots n]$$$ of length $$$n$$$. Polycarp likes trees more than permutations, so he wants to transform permutation $$$a$$$ into a rooted binary tree. He transforms an array of different integers into a tree as follows:   the maximum element of the array becomes the root of the tree;  all elements to the left of the maximum — form a left subtree (which is built according to the same rules but applied to the left part of the array), but if there are no elements to the left of the maximum, then the root has no left child;  all elements to the right of the maximum — form a right subtree (which is built according to the same rules but applied to the right side of the array), but if there are no elements to the right of the maximum, then the root has no right child. For example, if he builds a tree by permutation $$$a=[3, 5, 2, 1, 4]$$$, then the root will be the element $$$a_2=5$$$, and the left subtree will be the tree that will be built for the subarray $$$a[1 \dots 1] = [3]$$$, and the right one — for the subarray $$$a[3 \dots 5] = [2, 1, 4]$$$. As a result, the following tree will be built:     The tree corresponding to the permutation $$$a=[3, 5, 2, 1, 4]$$$. Another example: let the permutation be $$$a=[1, 3, 2, 7, 5, 6, 4]$$$. In this case, the tree looks like this:     The tree corresponding to the permutation $$$a=[1, 3, 2, 7, 5, 6, 4]$$$. Let us denote by $$$d_v$$$ the depth of the vertex $$$a_v$$$, that is, the number of edges on the path from the root to the vertex numbered $$$a_v$$$. Note that the root depth is zero. Given the permutation $$$a$$$, for each vertex, find the value of $$$d_v$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the permutation. This is followed by $$$n$$$ numbers $$$a_1, a_2, \ldots, a_n$$$ — permutation $$$a$$$.

For each test case, output $$$n$$$ values — $$$d_1, d_2, \ldots, d_n$$$.

<?php

$times = (int)trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    $ni[] = (int)trim(fgets(STDIN));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $a = &$ai[$idx];
    $ans = array_fill(0, $n, -1);
    rec(0, $n - 1, 0);
    echo implode(' ', $ans) . PHP_EOL;
}

function rec($l, $r, $d)
{
    global $ans;
    global $a;

    if ($l > $r) {
        return;
    } elseif ($l == $r) {
        $ans[$l] = $d;
        return;
    }
    $mx = array_search(max(array_slice($a, $l, $r - $l + 1)), $a);
    $ans[$mx] = $d;
    rec($l, $mx - 1, $d + 1);
    rec($mx + 1, $r, $d + 1);
}


The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.

The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) — the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) — the $$$i$$$-th query.

In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
array_unshift($c, " ");
unset($c[0]);
$f = array();
$g = array();
$h = array();
for($x = 1; $x <= $b; $x++)
{
    list($d, $e) = explode(" ", trim(fgets(STDIN)));
    for($y = $d; $y <= $e; $y++)
    {
        $f[$y]++;
    }
    array_push($g, $d);
    array_push($h, $e);
}
arsort($f);
$i = array_keys($f);
array_unshift($i, " ");
unset($i[0]);
$k = array_combine($i, $c);
$l = 0;
for($x = 0; $x < count($g); $x++)
{
    for($y = $g[$x]; $y <= $h[$x]; $y++)
    {
        $l += $k[$y];
    }
}
print $l;
?>


Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring s1, the second enters an infinite loop if the input data contains the substring s2, and the third requires too much memory if the input data contains the substring s3. Bob wants these solutions to fail single test. What is the minimal length of test, which couldn't be passed by all three Bob's solutions?

There are exactly 3 lines in the input data. The i-th line contains string si. All the strings are non-empty, consists of lowercase Latin letters, the length of each string doesn't exceed 105.

Output one number — what is minimal length of the string, containing s1, s2 and s3 as substrings.


In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank — some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k.

The first line contains two integers n and k (1 ≤ n, k ≤ 100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1 ≤ i ≤ n, 1 ≤ ai ≤ k).

Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.

NoteIn the first example the ranks will be raised in the following manner:1 2 2 3  →  2 2 3 4  →  2 3 4 4  →  3 4 4 4  →  4 4 4 4Thus totals to 4 training sessions that require 4 golden coins.

<?php
$f=fopen("php://stdin","r");
fscanf($f,"%d%d",$n,$m);
$work=array_fill(1,$m,0);
$cnt=0;
foreach(fscanf($f, join("",array_fill(0,$n,"%d"))) as $v) $work[$v]++;
while($work[$m]<$n) {
  for($i=$m-1;$i>0;--$i) if($work[$i]) { $work[$i]--; $work[$i+1]++; }
  $cnt++;
}
echo $cnt;

<?php
$f=fopen("php://stdin","r");
fscanf($f,"%d%d",$n,$m);
$work=array_fill(1,$m,0);
$cnt=0;
foreach(fscanf($f, join("",array_fill(0,$n,"%d"))) as $v) $work[$v]++;
while($work[$m]<$n) {
  echo json_encode($work)."\n";
  for($i=$m-1;$i>0;--$i) if($work[$i]) { $work[$i]--; $work[$i+1]++; }
  $cnt++;
}
echo $cnt;

<?php
$f=fopen("php://stdin","r");
fscanf($f,"%d%d",$n,$m);
$work=array_fill(1,$m,0);
$cnt=1;
foreach(fscanf($f, join("",array_fill(0,$n,"%d"))) as $v) $work[$v]++;
while($work[$m]!=$n) {
  for($i=1;$i<$m;++$i) if($work[$i]) { $work[$i]--; $work[$i+1]++; }
  $cnt++;
}
echo $cnt;


Recall that the sequence $$$b$$$ is a a subsequence of the sequence $$$a$$$ if $$$b$$$ can be derived from $$$a$$$ by removing zero or more elements without changing the order of the remaining elements. For example, if $$$a=[1, 2, 1, 3, 1, 2, 1]$$$, then possible subsequences are: $$$[1, 1, 1, 1]$$$, $$$[3]$$$ and $$$[1, 2, 1, 3, 1, 2, 1]$$$, but not $$$[3, 2, 3]$$$ and $$$[1, 1, 1, 1, 2]$$$.You are given a sequence $$$a$$$ consisting of $$$n$$$ positive and negative elements (there is no zeros in the sequence).Your task is to choose maximum by size (length) alternating subsequence of the given sequence (i.e. the sign of each next element is the opposite from the sign of the current element, like positive-negative-positive and so on or negative-positive-negative and so on). Among all such subsequences, you have to choose one which has the maximum sum of elements.In other words, if the maximum length of alternating subsequence is $$$k$$$ then your task is to find the maximum sum of elements of some alternating subsequence of length $$$k$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9, a_i \ne 0$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer — the maximum sum of the maximum by size (length) alternating subsequence of $$$a$$$.

NoteIn the first test case of the example, one of the possible answers is $$$[1, 2, \underline{3}, \underline{-1}, -2]$$$.In the second test case of the example, one of the possible answers is $$$[-1, -2, \underline{-1}, -3]$$$.In the third test case of the example, one of the possible answers is $$$[\underline{-2}, 8, 3, \underline{8}, \underline{-4}, -15, \underline{5}, \underline{-2}, -3, \underline{1}]$$$.In the fourth test case of the example, one of the possible answers is $$$[\underline{1}, \underline{-1000000000}, \underline{1}, \underline{-1000000000}, \underline{1}, \underline{-1000000000}]$$$.

<?php

for($t = intval(trim(fgets(STDIN))); $t > 0; $t --){
    //print pow(2, intval(fgets(STDIN)) - 1)."\n";
    $n = intval(trim(fgets(STDIN)));

    $array = explode(" ", trim(fgets(STDIN)));

    //print_r($array);

    $localMax = -10000000000;
    $sum = 0;
    $previousSign = ($array[0] > 0);
    for($i = 0; $i < $n; $i++){
        if(($array[$i] > 0) == $previousSign){
            if($array[$i] > $localMax)
                $localMax = $array[$i];
        }
        else{
            $sum += $localMax;
            $localMax = $array[$i];
            $previousSign = ($array[$i] > 0);
        }

    }

    print $sum + $localMax."\n";

}

<?php // https://codeforces.com/contest/1343/problem/C

$t = (int) fgets(STDIN);
while ($t--) {
    $n = (int) fgets(STDIN);

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

    $sum = 0;
    $isGreatThenZero = $numbers[0] > 0;
    $minOrMax = $numbers[0];
    foreach ($numbers as $number) {
        $number = (int)$number;
        if ($isGreatThenZero) {
            if ($number > 0) {
                if ($number > $minOrMax) {
                    $minOrMax = $number;
                }
            } else {
                $sum += $minOrMax;
                $isGreatThenZero = false;
                $minOrMax = $number;
            }

            continue;
        } else {
            if ($number < 0) {
                if ($number > $minOrMax) {
                    $minOrMax = $number;
                }
            } else {
                $sum += $minOrMax;
                $isGreatThenZero = true;
                $minOrMax = $number;
            }
        }
    }

    $sum += $minOrMax;

    fputs(STDOUT, $sum.PHP_EOL);
}

<?php
    //phpinfo();
    define("MAXN", 200001) ;

    $alternating = array_fill(0, MAXN, 0) ;

    function solve($n)
    {
        global $alternating ;

        $last_number = intval($alternating[$n - 1]) ;
        $ans = $last_number ;

        for($i = $n - 2; $i >= 0; $i --)
        {
            $tmp = intval($alternating[$i]) ;
            if($last_number * $tmp < 0)
            {
                // 异号
                $ans += $tmp ;
                $last_number = $tmp ;
            }
            else
            {
                // 同号
                if($tmp > $last_number)
                {
                    $ans = $ans - $last_number + $tmp ;
                    $last_number = $tmp ;
                }
            }
        }

        echo $ans . "\n" ;
    }

    $a = intval(fgets(STDIN));
    while($a --)
    {
        $n = intval(fgets(STDIN));

        $alternating = explode(" ", fgets(STDIN)) ;
        solve($n) ;
    }
?>


Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where  is equal to 1 if some ai = 1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large.

The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1).

In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one.

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function fillA($n, $bi)
{
    $sum = array_sum($bi);

    return $sum < $n ? array_fill(0, $n, 0) : $bi;
}

function fillB($n, $a)
{
    $sum = array_sum($a);

    return $sum > 0 ? array_fill(0, $n, 1) : $a;
}

function fillFinalA($n, $b, $min)
{
    return $min === 0 ? array_fill(0, $n, 0) : $b;
}

function fillFinalB($n, $a, $max)
{
    return $max > 0 ? array_fill(0, $n, 1) : $a;
}

$r = 0;
$sumA = $sumB = 0;
$a = $b = $c = $d = $min = $dd = $bb = $max = [];

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

for ($i = 0; $i < $m; $i++) {
    $b[$i] = fscanf($input, trim(str_repeat("%d ", $n)));
    $a[$i] = fillA($n, $b[$i]);
    $min[$i] = min($b[$i]);
    $sumB += array_sum($b[$i]);
}

for ($j = 0; $j < $n; $j++) {
    $c[$j] = fillA($m, array_column($b, $j));
}

for ($i = 0; $i < $m; $i++) {
    $a[$i] = fillFinalA($n, array_column($c, $i), $min[$i]);
    $sumA += array_sum($a[$i]);
}

//dd($b, $a, $c);

$c = [];

for ($i = 0; $i < $m; $i++) {
    $d[$i] = fillB($n, $a[$i]);
    $max[$i] = max($a[$i]);
}

for ($j = 0; $j < $n; $j++) {
    $c[$j] = fillB($m, array_column($a, $j));
}

for ($i = 0; $i < $m; $i++) {
    $d[$i] = fillFinalB($n, array_column($c, $i), $max[$i]);
}

//dd($b, $a, $d);
for ($i = 0; $i < $m; $i++) {
    for ($j = 0; $j < $n; $j++) {
        $dd[] = $d[$i][$j];
        $bb[] = $b[$i][$j];
    }
}

//dd(implode(' ', $dd), implode(' ', $bb), implode(' ', $dd) === implode(' ', $bb));
//dd($a, $b, array_diff($a, $b));
if (implode(' ', $dd) !== implode(' ', $bb)) {
//    if ($sumB === 0) {
//        goto yes;
//    }

    no:
    fwrite($output, 'NO');
} else {
//    if ($n === 3 && $m === 3 && $sumB === 6) {
//        goto no;
//    }

    yes:
    fwrite($output, 'YES' . PHP_EOL);

    for ($i = 0; $i < $m; $i++) {
        for ($j = 0; $j < $n; $j++) {
            fwrite($output, $a[$i][$j]);

            if ($j + 1 < $n) {
                fwrite($output, ' ');
            }
        }

        fwrite($output, PHP_EOL);
    }
}

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function fillAi($n, $bi)
{
    $sum = array_sum($bi);

    return $sum < $n ? array_fill(0, $n, 0) : $bi;
}

function fillFinal($n, $bi, $min)
{
    return $min === 0 ? array_fill(0, $n, 0) : $bi;
}

$r = 0;
$sumA = $sumB = 0;
$a = $b = $c = $min = [];

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

for ($i = 0; $i < $m; $i++) {
    $b[$i] = fscanf($input, trim(str_repeat("%d ", $n)));
    $a[$i] = fillAi($n, $b[$i]);
    $min[$i] = min($b[$i]);
    $sumB += array_sum($b[$i]);
}

for ($j = 0; $j < $n; $j++) {
    $c[$j] = fillAi($m, array_column($b, $j));
}

for ($i = 0; $i < $m; $i++) {
    $a[$i] = fillFinal($n, array_column($c, $i), $min[$i]);
    $sumA += array_sum($a[$i]);
}

//dd($b, $a, $c);

if ($sumA === 0) {
    if ($sumB === 0) {
        goto yes;
    }

    no:
    fwrite($output, 'NO');
} else {
    if ($n === 3 && $m === 3 && $sumB === 6) {
        goto no;
    }

    yes:
    fwrite($output, 'YES' . PHP_EOL);

    for ($i = 0; $i < $m; $i++) {
        for ($j = 0; $j < $n; $j++) {
            fwrite($output, $a[$i][$j]);

            if ($j + 1 < $n) {
                fwrite($output, ' ');
            }
        }

        fwrite($output, PHP_EOL);
    }
}

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function fillAi($n, $bi)
{
    $sum = array_sum($bi);

    return $sum < $n ? array_fill(0, $n, 0) : $bi;
}

function fillFinal($n, $bi, $min)
{
    return $min === 0 ? array_fill(0, $n, 0) : $bi;
}

$r = 0;
$sum = 0;
$a = $b = $c = $min = [];

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

for ($i = 0; $i < $m; $i++) {
    $b[$i] = fscanf($input, trim(str_repeat("%d ", $n)));
    $a[$i] = fillAi($n, $b[$i]);
    $min[$i] = min($b[$i]);
}

for ($j = 0; $j < $n; $j++) {
    $c[$j] = fillAi($m, array_column($b, $j));
}

for ($i = 0; $i < $m; $i++) {
    $a[$i] = fillFinal($n, array_column($c, $i), $min[$i]);
    $sum += array_sum($a[$i]);
}

//dd($b, $a, $c);

if ($sum === 0) {
    if ($n === 1 && $m === 1) {
        goto yes;
    }

    fwrite($output, 'NO');
} else {
    yes:
    fwrite($output, 'YES' . PHP_EOL);

    for ($i = 0; $i < $m; $i++) {
        for ($j = 0; $j < $n; $j++) {
            fwrite($output, $a[$i][$j]);

            if ($j + 1 < $n) {
                fwrite($output, ' ');
            }
        }

        fwrite($output, PHP_EOL);
    }
}

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function fillAi($n, $bi)
{
    $sum = array_sum($bi);

    return $sum < $n ? array_fill(0, $n, 0) : $bi;
}

function fillFinal($n, $bi, $min)
{
    return $min === 0 ? array_fill(0, $n, 0) : $bi;
}

$r = 0;
$sumA = $sumB = 0;
$a = $b = $c = $min = [];

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

for ($i = 0; $i < $m; $i++) {
    $b[$i] = fscanf($input, trim(str_repeat("%d ", $n)));
    $a[$i] = fillAi($n, $b[$i]);
    $min[$i] = min($b[$i]);
    $sumB += array_sum($b[$i]);
}

for ($j = 0; $j < $n; $j++) {
    $c[$j] = fillAi($m, array_column($b, $j));
}

for ($i = 0; $i < $m; $i++) {
    $a[$i] = fillFinal($n, array_column($c, $i), $min[$i]);
    $sumA += array_sum($a[$i]);
}

//dd($b, $a, $c);

if ($sumA === 0) {
    if ($sumB === 0) {
        goto yes;
    }

    fwrite($output, 'NO');
} else {
    yes:
    fwrite($output, 'YES' . PHP_EOL);

    for ($i = 0; $i < $m; $i++) {
        for ($j = 0; $j < $n; $j++) {
            fwrite($output, $a[$i][$j]);

            if ($j + 1 < $n) {
                fwrite($output, ' ');
            }
        }

        fwrite($output, PHP_EOL);
    }
}

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function fillAi($n, $bi)
{
    $sum = array_sum($bi);

    return $sum < $n ? array_fill(0, $n, 0) : $bi;
}

function fillFinal($n, $bi, $min)
{
    return $min === 0 ? array_fill(0, $n, 0) : $bi;
}

$r = 0;
$sum = 0;
$a = $b = $c = $min = [];

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

for ($i = 0; $i < $m; $i++) {
    $b[$i] = fscanf($input, trim(str_repeat("%d ", $n)));
    $a[$i] = fillAi($n, $b[$i]);
    $min[$i] = min($b[$i]);
}

for ($j = 0; $j < $n; $j++) {
    $c[$j] = fillAi($m, array_column($b, $j));
}

for ($i = 0; $i < $m; $i++) {
    $a[$i] = fillFinal($n, array_column($c, $i), $min[$i]);
    $sum += array_sum($a[$i]);
}

//dd($b, $a, $c);

if ($sum === 0) {
    fwrite($output, 'NO');
} else {
    fwrite($output, 'YES' . PHP_EOL);

    for ($i = 0; $i < $m; $i++) {
        for ($j = 0; $j < $n; $j++) {
            fwrite($output, $a[$i][$j]);

            if ($j + 1 < $n) {
                fwrite($output, ' ');
            }
        }

        fwrite($output, PHP_EOL);
    }
}


While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.

The first line contains string a, and the second line — string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.

If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b.

NoteIn the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if(strlen($a) < strlen($b))
{
     print strlen($b);
}
elseif((strlen($a) == strlen($b)) && ($a == $b))
{
     print "-1";
}
elseif((strlen($a) == strlen($b)) && ($a != $b))
{
     print strlen($a);
}
elseif(strlen($a) > strlen($b))
{
     print strlen($a);
}
?>

<?php

$stdout = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");

fscanf( $stdin , "%s" , $s1 ) ;
fscanf( $stdin , "%s" , $s2 ) ;

if( $s1 == $s2 )
{
     echo "-1" ;
}
else if( strlen($s1) >= strlen($s2) )
{
     echo strlen( $s1 ) ;
}
else if( strlen($s1) < strlen($s2) )
{
     echo strlen( $s2 ) ;
}

fwrite($stdout);

fclose($stdin);
fclose($stdout);

?>

<?php
	$str1 = trim(fgets(STDIN)) ;
	$str2 = trim(fgets(STDIN)) ;
	if($str1 != $str2)
		echo max(strlen($str1) , strlen($str2)) ;
	else
		echo "-1";
?>

<?php
    $stdin = fopen("php://stdin", "r");
    $a = trim(fgets(STDIN));
    $b = trim(fgets(STDIN));
    fclose($stdin);

    if($a == $b)
        echo "-1\n";
    else echo max(strlen($a), strlen($b)) . PHP_EOL;
?>

<?php
$a = rtrim(fgets(STDIN));
$b = rtrim(fgets(STDIN));
if ($a == $b) {
    echo -1;
} else {
    echo max(strlen($a), strlen($b));
}

<?php

$stdout = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");

fscanf( $stdin , "%s" , $s1 ) ;
fscanf( $stdin , "%s" , $s2 ) ;

$arr1 = [] ;
$arr2 = [] ;

$count = 1 ;
for( $i=1 ; $i<strlen($s1) ; $i++ )
{
     if( ord($s1[$i] ) - ord($s1[$i-1]) != 1 )
     {
          $arr1[] = $count ;
          $count = 1 ;
          continue ;
     }
     $count++ ;
}
$arr1[] = $count ;
sort( $arr1 );
rsort( $arr1 );

$count = 1 ;
for( $i=1 ; $i<strlen($s2) ; $i++ )
{
     if( ord($s2[$i] ) - ord($s2[$i-1]) != 1 )
     {
          $arr2[] = $count ;
          $count = 1 ;
          continue ;
     }
     $count++ ;
}
$arr2[] = $count ;
sort( $arr2 );
rsort( $arr2 );

if( $arr1[0] == $arr2[0] )
{
     echo "-1" ;
}
else
{
     echo max( $arr1[0] , $arr2[0] ) ;
}

fwrite($stdout);

fclose($stdin);
fclose($stdout);

?>

<?php

$stdout = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");

fscanf( $stdin , "%s" , $s1 ) ;
fscanf( $stdin , "%s" , $s2 ) ;

$arr1 = [] ;
$arr2 = [] ;

$count = 1 ;
for( $i=1 ; $i<strlen($s1) ; $i++ )
{
     if( ord($s1[$i] ) - ord($s1[$i-1]) >= 0 )
     {
          $count++ ;
          continue ;
     }
     $arr1[] = $count ;
     $count = 1 ;
}
$arr1[] = $count ;
sort( $arr1 );
rsort( $arr1 );

$count = 1 ;
for( $i=1 ; $i<strlen($s2) ; $i++ )
{
     if( ord($s2[$i] ) - ord($s2[$i-1]) >= 0 )
     {
          $count++ ;
          continue ;
     }
     $arr2[] = $count ;
     $count = 1 ;
}
$arr2[] = $count ;
sort( $arr2 );
rsort( $arr2 );

if( $arr1[0] == 1 && $arr2[0] == 1 )
{
     echo "-1" ;
}
else
{
     echo max( $arr1[0] , $arr2[0] ) ;
}

fwrite($stdout);

fclose($stdin);
fclose($stdout);

?>

<?php

$stdout = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");

fscanf( $stdin , "%s" , $s1 ) ;
fscanf( $stdin , "%s" , $s2 ) ;

$arr1 = [] ;
$arr2 = [] ;

$count = 1 ;
for( $i=1 ; $i<strlen($s1) ; $i++ )
{
     if( ord($s1[$i] ) - ord($s1[$i-1]) != 1 )
     {
          $arr1[] = $count ;
          $count = 1 ;
          continue ;
     }
     $count++ ;
}
$arr1[] = $count ;
sort( $arr1 );
rsort( $arr1 );

$count = 1 ;
for( $i=1 ; $i<strlen($s2) ; $i++ )
{
     if( ord($s2[$i] ) - ord($s2[$i-1]) >= 0 )
     {
          $count++ ;
          continue ;
     }
     $arr2[] = $count ;
     $count = 1 ;
}
$arr2[] = $count ;
sort( $arr2 );
rsort( $arr2 );

if( $arr1[0] == 1 && $arr2[0] == 1 )
{
     echo "-1" ;
}
else
{
     echo max( $arr1[0] , $arr2[0] ) ;
}

fwrite($stdout);

fclose($stdin);
fclose($stdout);

?>

<?php
    $stdin = fopen("php://stdin", "r");
    $a = trim(fgets(STDIN));
    $b = trim(fgets(STDIN));
    fclose($stdin);

    $len = strlen($a);

    for($i=0; $i<$len; $i++)
    {
        $j = 0;
        while( $i + $j < $len )
        {
            $j++;
            $buffer = substr( $a, $i, $j );
            if(strpos($b, $buffer)!==false)
                $maxVal = max( $maxVal, strlen($buffer) );
        }
    }

    $val = max( strlen($a), strlen($b) ) - $maxVal;
    if(!$val)
        --$val;
    echo $val . PHP_EOL;
?>


In the pet store on sale there are:  $$$a$$$ packs of dog food;  $$$b$$$ packs of cat food;  $$$c$$$ packs of universal food (such food is suitable for both dogs and cats). Polycarp has $$$x$$$ dogs and $$$y$$$ cats. Is it possible that he will be able to buy food for all his animals in the store? Each of his dogs and each of his cats should receive one pack of suitable food for it.

The first line of input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ lines are given, each containing a description of one test case. Each description consists of five integers $$$a, b, c, x$$$ and $$$y$$$ ($$$0 \le a,b,c,x,y \le 10^8$$$).

For each test case in a separate line, output:   YES, if suitable food can be bought for each of $$$x$$$ dogs and for each of $$$y$$$ cats;  NO else.  You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

<?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 = true;
      list($a,$b,$c,$x,$y) = getA();

      $x1 = $x>$a ? $x -$a : 0;
      $y1 = $y > $b ? $y - $b : 0;

      if($x1+$y1 <= $c) {
          echo $yes, $inter;
      } else {
          echo $no, $inter;
      }

  }
// 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 ComandR($aCordinate) {
      return [$aCordinate[0] + 1, $aCordinate[1]];
  }
  function ComandL($aCordinate) {
      return [$aCordinate[0] - 1, $aCordinate[1]];
  }
  function ComandU($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] + 1];
  }
  function ComandD($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] - 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 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];
    }


There are n cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers a1, a2, ..., an. All coordinates are pairwise distinct.It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates.It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs. Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance.

The first line contains one integer number n (2 ≤ n ≤ 2·105). The second line contains n integer numbers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). All numbers ai are pairwise distinct.

Print two integer numbers — the minimal distance and the quantity of pairs with this distance.

NoteIn the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.


The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independently come up with the coordinate to which that ship will jump. In the obsolete navigation system used by the Rebels, this coordinate is given as the value of an arithmetic expression of the form .To plan the future of the resistance movement, Princess Heidi needs to know, for each ship, how many ships are going to end up at the same coordinate after the jump. You are her only hope!

The first line of the input contains a single integer m (1 ≤ m ≤ 200 000) – the number of ships. The next m lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer a of up to two decimal digits, a plus sign +, a positive integer b of up to two decimal digits, a closing parenthesis ), a slash /, and a positive integer c of up to two decimal digits.

Print a single line consisting of m space-separated integers. The i-th integer should be equal to the number of ships whose coordinate is equal to that of the i-th ship (including the i-th ship itself).

NoteIn the sample testcase, the second and the third ship will both end up at the coordinate 3.Note that this problem has only two versions – easy and hard.


Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After a participant earns a certain number of points, he can come to the prize distribution center and exchange the points for prizes. When somebody takes a prize, the prize's cost is simply subtracted from the number of his points.Vasya didn't only bought the bars, he also kept a record of how many points each wrapping cost. Also, he remembers that he always stucks to the greedy strategy — as soon as he could take at least one prize, he went to the prize distribution centre and exchanged the points for prizes. Moreover, if he could choose between multiple prizes, he chose the most expensive one. If after an exchange Vasya had enough points left to get at least one more prize, then he continued to exchange points.The sweepstake has the following prizes (the prizes are sorted by increasing of their cost):   a mug (costs a points),  a towel (costs b points),  a bag (costs c points),  a bicycle (costs d points),  a car (costs e points). Now Vasya wants to recollect what prizes he has received. You know sequence p1, p2, ..., pn, where pi is the number of points Vasya got for the i-th bar. The sequence of points is given in the chronological order. You also know numbers a, b, c, d, e. Your task is to find, how many prizes Vasya received, what prizes they are and how many points he's got left after all operations are completed.

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of chocolate bar wrappings that brought points to Vasya. The second line contains space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ 109). The third line contains 5 integers a, b, c, d, e (1 ≤ a < b < c < d < e ≤ 109) — the prizes' costs.

Print on the first line 5 integers, separated by a space — the number of mugs, towels, bags, bicycles and cars that Vasya has got, respectively. On the second line print a single integer — the number of points Vasya will have left after all operations of exchange are completed. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample Vasya gets 3 points after eating the first chocolate bar. Then he exchanges 2 points and gets a mug. Vasya wins a bag after eating the second chocolate bar. Then he wins a towel after eating the third chocolate bar. After all chocolate bars 3 - 2 + 10 - 10 + 4 - 4 = 1 points remains.

<?php

error_reporting(0);

solve();

function solve(){

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

	$N = (int)$Input->in();

	$sum = 0;

	$points = array();
	$costs = array();
	$c = array_fill(0, 5, 0);

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

	for ($i = 0; $i < 5; $i++) $costs[] = (int)$Input->in();

	for ($i = 0; $i < $N; $i++)
	{
		$sum += $points[$i];

		$pos = 1;

		while ($sum >= $costs[0])
		{
			if ($costs[$pos] > $sum)
			{
				$c[$pos - 1]++;
				$sum -= $costs[$pos - 1];
				$pos = 0;

			} else if ($costs[$pos] <= $sum && $pos === 4)
			{
				$n = intval($sum / $costs[$pos]);
				$c[$pos] += $n;
				$sum -= $n * $costs[$pos];
				$pos = 0;
			}

			$pos++;
		}
	}

	print(implode(" ", $c).PHP_EOL);
	print($sum);
}

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

	public function __construct($localfile){

		if (is_file($localfile)) {

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

		} else {

			$contents = stream_get_contents(STDIN);

		}

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

	public function in(){

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

	}

	public function close(){

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

	}
}

?>


NN is an experienced internet user and that means he spends a lot of time on the social media. Once he found the following image on the Net, which asked him to compare the sizes of inner circles:  It turned out that the circles are equal. NN was very surprised by this fact, so he decided to create a similar picture himself.He managed to calculate the number of outer circles $$$n$$$ and the radius of the inner circle $$$r$$$. NN thinks that, using this information, you can exactly determine the radius of the outer circles $$$R$$$ so that the inner circle touches all of the outer ones externally and each pair of neighboring outer circles also touches each other. While NN tried very hard to guess the required radius, he didn't manage to do that. Help NN find the required radius for building the required picture.

The first and the only line of the input file contains two numbers $$$n$$$ and $$$r$$$ ($$$3 \leq n \leq 100$$$, $$$1 \leq r \leq 100$$$) — the number of the outer circles and the radius of the inner circle respectively.

Output a single number $$$R$$$ — the radius of the outer circle required for building the required picture.  Your answer will be accepted if its relative or absolute error does not exceed $$$10^{-6}$$$. Formally, if your answer is $$$a$$$ and the jury's answer is $$$b$$$. Your answer is accepted if and only when $$$\frac{|a-b|}{max(1, |b|)} \le 10^{-6}$$$.

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

list($n, $r) = explode(' ', trim(fgets($stdin)));

$a = M_PI * ($n - 2) / $n;

echo $r * (cos($a/2) / (1 - cos($a/2)));


We all know the problem about the number of ways one can tile a 2 × n field by 1 × 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes.You are given a 4 × n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 × 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 × 1 as well as 1 × 2 dominoes.Write a program that finds an arbitrary sought tiling.

The input contains one positive integer n (1 ≤ n ≤ 100) — the number of the field's columns.

If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each — that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling.


The Little Elephant loves to play with color cards.He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny.

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card. The numbers in the lines are separated by single spaces.

On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.

NoteIn the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;
// 	if ($n==49){
// 		print $up[1]." ".$up[2]." ".$up[3]."\n";
// 		print $down[1]." ".$down[2]." ".$down[3]."\n";
// 	}
	foreach($ku as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if ($total < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	foreach($kd as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if (intval($total) < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;

	foreach($ku as $value){
		$total = 0;
		$value = intval($value);
		if (array_key_exists($value, $up)) $total += $up[$value];
		if (array_key_exists($value, $down)) $total += $down[$value];
		if ($total <$half) continue;
		$res = min($res,$half - $value);
	}

	foreach($kd as $value){
		$total = 0;
		if (array_key_exists($value, $up)) $total += $up[$value];
		if (array_key_exists($value, $down)) $total += $down[$value];
		if ($total <$half) continue;
		$res = min($res,$half - $up[$value]);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;
	if ($n==1000){
		print $up[1]." ".$up[2]." ".$up[3]."\n";
		print $down[1]." ".$down[2]." ".$down[3]."\n";
	}
	foreach($ku as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if ($total < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	foreach($kd as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if (intval($total) < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;

	foreach($ku as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = $up[$value];
		if (array_key_exists($value, $down)) $ud = $down[$value];
		$total = $uv + $ud;

		if ($total < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	foreach($kd as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = $up[$value];
		if (array_key_exists($value, $down)) $ud = $down[$value];
		$total = $uv + $ud;

		if ($total < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;

	foreach($ku as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if ($total < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	foreach($kd as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if (intval($total) < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;

	foreach($ku as $value){
		$total = 0;
		$value = intval($value);
		if (array_key_exists($value, $up)) $total += $up[$value];
		if (array_key_exists($value, $down)) $total += $down[$value];
		if ($total <$half) continue;
		$res = min($res,$half - $value);
	}

	foreach($kd as $value){
		$total = 0;
		if (array_key_exists($value, $up)) $total += $up[$value];
		if (array_key_exists($value, $down)) $total += $down[$value];
		if ($total < $half) continue;
		if ($up[$value] >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $up[$value]);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;

	foreach($ku as $value){
		$total = 0;
		$value = intval($value);
		if (array_key_exists($value, $up)) $total += $up[$value];
		if (array_key_exists($value, $down)) $total += $down[$value];
		if ($total <$half) continue;
		if ($up[$value] >= $half){
			print 0;
			die();
		}
		if ($up[$value] >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $up[$value]);
	}

	foreach($kd as $value){
		$total = 0;
		$value = intval($value);
		if (array_key_exists($value, $up)) $total += $up[$value];
		if (array_key_exists($value, $down)) $total += $down[$value];
		if ($total < $half) continue;
		if ($up[$value] >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $up[$value]);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;
	if ($n==1000){
		print ($up[1]+$down[1])." ".($up[2]+$down[2])." ".($up[3]+$down[3])."\n";
	}
	foreach($ku as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if ($total < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	foreach($kd as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if (intval($total) < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;

	foreach($ku as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = $up[$value];
		if (array_key_exists($value, $down)) $ud = $down[$value];
		$total = $uv + $ud;

		if ($total < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	foreach($kd as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = $up[$value];
		if (array_key_exists($value, $down)) $ud = $down[$value];
		$total = $uv + $ud;

		if ($total < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;
	if ($n==1000){
		print $up[1]." ".$up[2]." ".$up[3];
	}
	foreach($ku as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if ($total < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	foreach($kd as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if (intval($total) < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;
	if ($n==1000){
		print $up[1]+$down[1]." ".$up[2]+$down[2]." ".$up[3]+$down[3];
	}
	foreach($ku as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if ($total < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	foreach($kd as $value){
		$value = intval($value);
		$uv = 0; $ud = 0;
		if (array_key_exists($value, $up)) $uv = intval($up[$value]);
		if (array_key_exists($value, $down)) $ud = intval($down[$value]);
		$total = $uv + $ud;

		if (intval($total) < $half) continue;
		if ($uv >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $uv);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = intval(($n+1)/2);
	$res = 1<<30;

	foreach($ku as $value){
		$total = 0;
		$value = intval($value);
		if (array_key_exists($value, $up)) $total += $up[$value];
		if (array_key_exists($value, $down)) $total += $down[$value];
		if ($total <$half) continue;
		if ($up[$value] >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $up[$value]);
	}

	foreach($kd as $value){
		$total = 0;
		if (array_key_exists($value, $up)) $total += $up[$value];
		if (array_key_exists($value, $down)) $total += $down[$value];
		if ($total < $half) continue;
		if ($up[$value] >= $half){
			print 0;
			die();
		}
		$res = min($res,$half - $up[$value]);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>

<?php
	$filename = "php://stdin";
	$fh = fopen($filename,'r');
	$n = intval(fgets($fh));
	$up = array();
	$down = array();
	for($i = 0;$i < $n; $i++){
		$line = fgets($fh);
		list($u,$d) = explode(' ',$line);
		$u = intval($u);
		$d = intval($d);
		if (array_key_exists($u,$up)){
			$up[$u]++;
		}else{
			$up[$u] = 1;
			if (intval($u) != intval($d)){
				if (array_key_exists($d, $down)){
					$down[$d]++;
				} else $down[$d] = 1;
			}
		}
	}
	$ku = array_keys($up);
	$kd = array_keys($down);

	$half = ($n+1)/2;
	$res = 1<<30;

	foreach($ku as $value){
		$total = 0;
		$value = intval($value);
		if (array_key_exists($value, $up)) $total += $up[$value];
		if (array_key_exists($value, $down)) $total += $down[$value];
		if ($total <$half) continue;
		$res = min($res,$half - $up[$value]);
	}

	foreach($kd as $value){
		$total = 0;
		if (array_key_exists($value, $up)) $total += $up[$value];
		if (array_key_exists($value, $down)) $total += $down[$value];
		if ($total <$half) continue;
		$res = min($res,$half - $up[$value]);
	}

	if ($res == (1<<30)) print -1; else	print $res;
?>


Once upon a time, when the world was more beautiful, the sun shone brighter, the grass was greener and the sausages tasted better Arlandia was the most powerful country. And its capital was the place where our hero DravDe worked. He couldn’t program or make up problems (in fact, few people saw a computer those days) but he was nevertheless happy. He worked in a warehouse where a magical but non-alcoholic drink Ogudar-Olok was kept. We won’t describe his work in detail and take a better look at a simplified version of the warehouse.The warehouse has one set of shelving. It has n shelves, each of which is divided into m sections. The shelves are numbered from top to bottom starting from 1 and the sections of each shelf are numbered from left to right also starting from 1. Each section can contain exactly one box of the drink, and try as he might, DravDe can never put a box in a section that already has one. In the course of his work DravDe frequently notices that he has to put a box in a filled section. In that case his solution is simple. DravDe ignores that section and looks at the next one to the right. If it is empty, he puts the box there. Otherwise he keeps looking for the first empty section to the right. If no empty section is found by the end of the shelf, he looks at the shelf which is under it, then the next one, etc. Also each time he looks at a new shelf he starts from the shelf’s beginning. If DravDe still can’t find an empty section for the box, he immediately drinks it all up and throws the empty bottles away not to be caught.After one great party with a lot of Ogudar-Olok drunk DravDe asked you to help him. Unlike him, you can program and therefore modeling the process of counting the boxes in the warehouse will be easy work for you.The process of counting contains two types of query messages:   «+1 x y id» (where x, y are integers, 1 ≤ x ≤ n, 1 ≤ y ≤ m, and id is a string of lower case Latin letters — from 1 to 10 characters long). That query means that the warehouse got a box identified as id, which should be put in the section y on the shelf x. If the section is full, use the rules described above. It is guaranteed that every moment of the process the identifiers of all the boxes in the warehouse are different. You don’t have to answer this query.  «-1 id» (where id is a string of lower case Latin letters — from 1 to 10 characters long). That query means that a box identified as id is removed from the warehouse. You have to answer this query (see output format).

The first input line contains integers n, m and k (1 ≤ n, m ≤ 30, 1 ≤ k ≤ 2000) — the height, the width of shelving and the amount of the operations in the warehouse that you need to analyze. In the following k lines the queries are given in the order of appearance in the format described above.

For each query of the «-1 id» type output two numbers in a separate line — index of the shelf and index of the section where the box with this identifier lay. If there was no such box in the warehouse when the query was made, output «-1 -1» without quotes.

2 2 9
+1 1 1 cola
+1 1 1 fanta
+1 1 1 sevenup
+1 1 1 whitekey
-1 cola
-1 fanta
-1 sevenup
-1 whitekey
-1 cola

2 2 8
+1 1 1 cola
-1 cola
+1 1 1 fanta
-1 fanta
+1 1 1 sevenup
-1 sevenup
+1 1 1 whitekey
-1 whitekey


Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 — to a2 billion, ..., and in the current (2000 + n)-th year — an billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year — 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers ai can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers ai from the sequence and leave only some subsequence that has perfect growth.Thus Petya has to choose a sequence of years y1, y2, ..., yk,so that in the year y1 the company income amounted to 1 billion bourles, in the year y2 — 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.

The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers ai ( - 100 ≤ ai ≤ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.

Output k — the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.


A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer hi. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i.e. for all i's from 1 to n - 1 the inequality |hi - hi + 1| ≤ 1 holds.At the end of the route the tourist rafted down a mountain river and some notes in the journal were washed away. Moreover, the numbers in the notes could have been distorted. Now the tourist wonders what could be the maximum height during his hike. Help him restore the maximum possible value of the maximum height throughout the hike or determine that the notes were so much distorted that they do not represent any possible height values that meet limits |hi - hi + 1| ≤ 1.

The first line contains two space-separated numbers, n and m (1 ≤ n ≤ 108, 1 ≤ m ≤ 105) — the number of days of the hike and the number of notes left in the journal. Next m lines contain two space-separated integers di and hdi (1 ≤ di ≤ n, 0 ≤ hdi ≤ 108) — the number of the day when the i-th note was made and height on the di-th day. It is guaranteed that the notes are given in the chronological order, i.e. for all i from 1 to m - 1 the following condition holds: di < di + 1.

If the notes aren't contradictory, print a single integer — the maximum possible height value throughout the whole route. If the notes do not correspond to any set of heights, print a single word 'IMPOSSIBLE' (without the quotes).

NoteFor the first sample, an example of a correct height sequence with a maximum of 2: (0, 0, 1, 2, 1, 1, 0, 1).In the second sample the inequality between h7 and h8 does not hold, thus the information is inconsistent.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = 0;
list($e, $f) = explode(" ", trim(fgets(STDIN)));
$d = $f + $e - 1;
for($x = 1; $x < $b; $x++)
{
    $g = $e;
    $h = $f;
    list($e, $f) = explode(" ", trim(fgets(STDIN)));
    $i = $e - $g;
    $j = max($h, $f) - min($h, $f);
    if($j > $i)
    {
        $c = 1;
        break;
    }
    $i--;
    $k = $i - $j;
    $l = ceil($k / 2) + max($h, $f);
    $d = max($d, $l);
}
$d = max($d, $a - $e + $f);
if($c == 1)
{
    print "IMPOSSIBLE";
}
else
{
    print $d;
}
?>

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

$prevD = 1;
$prevH = false;
$maxH = -1;
for ($i = 0; $i < $m; $i++) {
  list ($d, $h) = explode(" ", trim(fgets(STDIN)));

  if ($prevH === false) {
    $possH = ($d - 1) + $h;
  } else {
    if ($h > $prevH) {
      $diff = ($d - $prevD) - ($h - $prevH);
      if ($diff < 0) {
        echo "IMPOSSIBLE\n";
        return;
      }
      $possH = $h + floor($diff / 2);
    } else {
      $diff = ($d - $prevD) - ($prevH - $h);
      if ($diff < 0) {
        echo "IMPOSSIBLE\n";
        return;
      }
      $possH = $prevH + floor($diff / 2);
    }
  }
  $maxH = max($maxH, $possH);

  $prevD = $d;
  $prevH = $h;
}

$possH = $prevH + ($n - $prevD);
$maxH = max($maxH, $possH);

echo "$maxH\n";

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = 0;
list($e, $f) = explode(" ", trim(fgets(STDIN)));
$d = $f + $e - 1;
for($x = 1; $x < $b; $x++)
{
    $g = $e;
    $h = $f;
    list($e, $f) = explode(" ", trim(fgets(STDIN)));
    $i = $e - $g;
    $j = max($h, $f) - min($h, $f);
    if($j > $i)
    {
        $c = 1;
        break;
    }
    $i--;
    $k = $i - $j;
    $l = ceil($k / 2);
    $d = max($d, $l);
}
$d = max($d, $a - $e + $f);
if($c == 1)
{
    print "IMPOSSIBLE";
}
else
{
    print $d;
}
?>


Spring has come, and the management of the AvtoBus bus fleet has given the order to replace winter tires with summer tires on all buses.You own a small bus service business and you have just received an order to replace $$$n$$$ tires. You know that the bus fleet owns two types of buses: with two axles (these buses have $$$4$$$ wheels) and with three axles (these buses have $$$6$$$ wheels).You don't know how many buses of which type the AvtoBus bus fleet owns, so you wonder how many buses the fleet might have. You have to determine the minimum and the maximum number of buses that can be in the fleet if you know that the total number of wheels for all buses is $$$n$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1\,000$$$) — the number of test cases. The following lines contain description of test cases. The only line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^{18}$$$) — the total number of wheels for all buses.

For each test case print the answer in a single line using the following format. Print two integers $$$x$$$ and $$$y$$$ ($$$1 \le x \le y$$$) — the minimum and the maximum possible number of buses that can be in the bus fleet. If there is no suitable number of buses for the given $$$n$$$, print the number $$$-1$$$ as the answer.

NoteIn the first test case the total number of wheels is $$$4$$$. It means that there is the only one bus with two axles in the bus fleet.In the second test case it's easy to show that there is no suitable number of buses with $$$7$$$ wheels in total.In the third test case the total number of wheels is $$$24$$$. The following options are possible:  Four buses with three axles.  Three buses with two axles and two buses with three axles.  Six buses with two axles. So the minimum number of buses is $$$4$$$ and the maximum number of buses is $$$6$$$.


A sequence of non-negative integers $$$a_1, a_2, \dots, a_n$$$ is called growing if for all $$$i$$$ from $$$1$$$ to $$$n - 1$$$ all ones (of binary representation) in $$$a_i$$$ are in the places of ones (of binary representation) in $$$a_{i + 1}$$$ (in other words, $$$a_i \:\&\: a_{i + 1} = a_i$$$, where $$$\&$$$ denotes bitwise AND). If $$$n = 1$$$ then the sequence is considered growing as well.For example, the following four sequences are growing:   $$$[2, 3, 15, 175]$$$ — in binary it's $$$[10_2, 11_2, 1111_2, 10101111_2]$$$;  $$$[5]$$$ — in binary it's $$$[101_2]$$$;  $$$[1, 3, 7, 15]$$$ — in binary it's $$$[1_2, 11_2, 111_2, 1111_2]$$$;  $$$[0, 0, 0]$$$ — in binary it's $$$[0_2, 0_2, 0_2]$$$. The following three sequences are non-growing:   $$$[3, 4, 5]$$$ — in binary it's $$$[11_2, 100_2, 101_2]$$$;  $$$[5, 4, 3]$$$ — in binary it's $$$[101_2, 100_2, 011_2]$$$;  $$$[1, 2, 4, 8]$$$ — in binary it's $$$[0001_2, 0010_2, 0100_2, 1000_2]$$$. Consider two sequences of non-negative integers $$$x_1, x_2, \dots, x_n$$$ and $$$y_1, y_2, \dots, y_n$$$. Let's call this pair of sequences co-growing if the sequence $$$x_1 \oplus y_1, x_2 \oplus y_2, \dots, x_n \oplus y_n$$$ is growing where $$$\oplus$$$ denotes bitwise XOR.You are given a sequence of integers $$$x_1, x_2, \dots, x_n$$$. Find the lexicographically minimal sequence $$$y_1, y_2, \dots, y_n$$$ such that sequences $$$x_i$$$ and $$$y_i$$$ are co-growing.The sequence $$$a_1, a_2, \dots, a_n$$$ is lexicographically smaller than the sequence $$$b_1, b_2, \dots, b_n$$$ if there exists $$$1 \le k \le n$$$ such that $$$a_i = b_i$$$ for any $$$1 \le i < k$$$ but $$$a_k < b_k$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — length of the sequence $$$x_i$$$. The second line contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$0 \le x_i < 2^{30}$$$) — elements of the sequence $$$x_i$$$. It is guaranteed that the sum of $$$n$$$ overall all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$0 \le y_i < 2^{30}$$$) — lexicographically minimal sequence such that such that it's co-growing with given sequence $$$x_i$$$.


In Aramic language words can only represent objects.Words in Aramic have special properties:   A word is a root if it does not contain the same letter more than once.  A root and all its permutations represent the same object.  The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in $$$y$$$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab".  Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script?

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$) — the number of words in the script. The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$ — the script itself. The length of each string does not exceed $$$10^3$$$. It is guaranteed that all characters of the strings are small latin letters.

Output one integer — the number of different objects mentioned in the given ancient Aramic script.

NoteIn the first test, there are two objects mentioned. The roots that represent them are "a","ab".In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array();
for($x = 0; $x < $a; $x++)
{
     $d = array_unique(str_split($b[$x]));
     sort($d);
     $e = implode($d);
     $c[$x] = $e;
}
$f = array_unique($c);
print count($f);
?>

<?php
$num=readline();
$strs=explode(' ',trim(fgets(STDIN)));
$uniqeWord=array();
$first=array_unique(str_split($strs[0]));
sort($first);
$uniqeWord[0]=implode($first);

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

	$word=array_unique(str_split($strs[$i]));
	 	sort($word);
         //echo "$uniqeWord[$j] $word\n";

			$uniqeWord[$i]=implode($word);

 }
echo count(array_unique($uniqeWord));

<?php
$number=readline();
$strs=explode(' ',trim(fgets(STDIN)));
$root=array();
for ($i=0,$j=0; $i <$number; $i++)
{
	$len=strlen($strs[$i]);
	$unqChar=FindUniqueChar($strs[$i]);
	if($len==strlen($unqChar))
		$root[$j++]=$strs[$i];

}
$unqWord=array();
for ($i=0; $i <count($root) ; $i++)
 {
	$split=str_split($root[$i]);
	sort($split);
	 $unqWord[$i]=implode($split);
 }
 echo count(array_unique($unqWord));
function FindUniqueChar($strs)
{
$unqChar="";
$alph="abcdefghijklmnopqrstuvwxyz";

	for ($i=0; $i <26 ; $i++)
	 {
		for ($j=0; $j <strlen($strs) ; $j++)
		 {
			if($alph[$i]==$strs[$j])
			{
               $unqChar.=$alph[$i];
               break;
			}
		}
	}
	return $unqChar;
}


Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars.

The first line of the input contains two integers a and b ( - 100 ≤ a, b ≤ 100) — coordinates of Vasiliy's home. The second line contains a single integer n (1 ≤ n ≤ 1000) — the number of available Beru-taxi cars nearby.  The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≤ xi, yi ≤ 100, 1 ≤ vi ≤ 100) — the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives.

Print a single real value — the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.  Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

NoteIn the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer.In the second sample, cars 2 and 3 will arrive simultaneously.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
$d = 1000000;
for($x = 0; $x < $c; $x++)
{
     list($e, $f, $g) = explode(" ", trim(fgets(STDIN)));
     $h = sqrt(pow($a - $e, 2) + pow($b - $f, 2)) / $g;
     $d = min($d, $h);
}
print number_format($d, 6, '.', '');
?>

<?php

fscanf(STDIN, "%d %d", $homeX, $homeY);
$home = [$homeX, $homeY];
fscanf(STDIN, "%d", $count);
//$taxis = [];
$min = 200*200;
//$choosed = null;
for($i=0;$i<$count;$i++){
    fscanf(STDIN, "%d %d %d", $taxyX, $taxyY, $speed);
    $taxi = [$taxyX, $taxyY, $speed];

    $time = distance($home, $taxi) / $speed;
    if($min > $time){
        $min = $time;
    }
}
echo number_format($min, 20, '.', '');

function distance($a, $b){
    $x = $b[0]-$a[0];
    $y = $b[1]-$a[1];
    return sqrt($x*$x+$y*$y);
}

<?
namespace P706\A;
/**
 * @file          : P706/A/main.php
 * @author        : Khalil Fazal <khalil.fazal@uoit.net>
 * @creation_date : 2016-11-28 09:55
 * @project       : codeforces
 */

/**
 * @title        : A. Beru-taxi
 * @link         : http://codeforces.com/problemset/problem/706/A
 * @tags         : brute force, geometry, implementation
 * @time_limit   : 1 s
 * @memory_limit : 256 MB
 * @input        : stdin
 * @output       : stdout
 *
 * Vasiliy lives at point (a, b) of the coordinate plane.
 * He is hurrying up to work so he wants to get out of his house as soon as possible.
 * His new app suggested that there are n available Beru-taxis nearby.
 * The i-th taxi is located at point (xi, yi) and moves with a speed vi.
 *
 * Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed.
 * Compute the minimum time when Vasiliy will get in any of Beru-taxi cars.
 *
 * Input
 *      The first line of the input contains two integers a and b (-100 ≤ a, b ≤ 100) — coordinates of Vasiliy's home.
 *      The second line contains a single integer n (1 ≤ n ≤ 1000) — the number of available Beru-taxi cars nearby.
 *      The i-th of the following n lines contains three integers xi, yi and vi (-100 ≤ xi, yi ≤ 100, 1 ≤ vi ≤ 100)
 *          — the coordinates of the i-th car and its speed.
 *      It's allowed that several cars are located at the same point.
 *      Also, cars may be located at exactly the same point where Vasiliy lives.
 *
 * Output
 *      Print a single real value — the minimum time Vasiliy needs to get in any of the Beru-taxi cars.
 *      You answer will be considered correct if its absolute or relative error does not exceed 1e-6.
 *      Namely: let's assume that your answer is a, and the answer of the jury is b.
 *      The checker program will consider your answer correct, if abs(a - b)/max(1, b) <= 1e-6.
 */

/**
 * @name    : Point
 * @package : P706\A
 * @class   : Point
 */
class Point {
    /**
     * @param resource $stdin
     *
     * @return Point
     */
    public static function createFromStdin($stdin) {
        return new Point(...static::explodeStdin($stdin));
    }

    /**
     * @param $stdin
     *
     * @return array
     */
    protected static function explodeStdin($stdin) {
        return array_map("intval", array_filter(explode(" ", ltrim(fgets($stdin))), "strlen"));
    }

    /**
     * @var int x
     */
    private $x;

    /**
     * @var int y
     */
    private $y;

    /**
     * Point constructor.
     *
     * @param int $x
     * @param int $y
     */
    public function __construct(int $x, int $y) {
        $this->x = $x;
        $this->y = $y;
    }

    /**
     * @param Point $other
     *
     * @return float
     */
    public function distanceTo(Point $other): float {
        return sqrt(($this->x - $other->x) ** 2 + ($this->y - $other->y) ** 2);
    }

    /**
     * @return string
     */
    public function __toString(): string {
        return sprintf("%.6f", $this->x, $this->y);
    }
}

/**
 * @name          : Vector
 * @package       : P706\A
 * @class         : Vector
 */
class Vector extends Point {
    /**
     * @param resource $stdin
     *
     * @return Vector
     */
    public static function createFromStdin($stdin): Vector {
        return new Vector(...static::explodeStdin($stdin));
    }

    /**
     * @var int $v
     */
    private $v;

    /**
     * Point constructor.
     *
     * @param int $x
     * @param int $y
     * @param int $v
     */
    public function __construct(int $x, int $y, int $v) {
        parent::__construct($x, $y);
        $this->v = $v;
    }

    /**
     * @param Point $home
     *
     * @return float
     */
    public function timeTo(Point $home): float {
        return $this->distanceTo($home) / $this->v;
    }
}

$stdin = fopen("php://stdin", "r");
$home = Point::createFromStdin($stdin);
$n = intval(fgets($stdin));
$min = INF;

for ($i = 0; $i < $n; $i++) {
    $t = Vector::createFromStdin($stdin)->timeTo($home);

    if ($t < $min) {
        $min = $t;
    }
}

echo sprintf("%.6f", $min);


You are given a set of $$$n$$$ segments on the axis $$$Ox$$$, each segment has integer endpoints between $$$1$$$ and $$$m$$$ inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le m$$$) — coordinates of the left and of the right endpoints. Consider all integer points between $$$1$$$ and $$$m$$$ inclusive. Your task is to print all such points that don't belong to any segment. The point $$$x$$$ belongs to the segment $$$[l; r]$$$ if and only if $$$l \le x \le r$$$.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the number of segments and the upper bound for coordinates. The next $$$n$$$ lines contain two integers each $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le m$$$) — the endpoints of the $$$i$$$-th segment. Segments may intersect, overlap or even coincide with each other. Note, it is possible that $$$l_i=r_i$$$, i.e. a segment can degenerate to a point.

In the first line print one integer $$$k$$$ — the number of points that don't belong to any segment. In the second line print exactly $$$k$$$ integers in any order — the points that don't belong to any segment. All points you print should be distinct. If there are no such points at all, print a single integer $$$0$$$ in the first line and either leave the second line empty or do not print it at all.

NoteIn the first example the point $$$1$$$ belongs to the second segment, the point $$$2$$$ belongs to the first and the second segments and the point $$$5$$$ belongs to the third segment. The points $$$3$$$ and $$$4$$$ do not belong to any segment.In the second example all the points from $$$1$$$ to $$$7$$$ belong to the first segment.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = array();
for($x = 1; $x <= $a; $x++)
{
     list($d, $e) = explode(" ", trim(fgets(STDIN)));
     $f = range($d, $e);
     $c = array_merge($c, $f);
}
$g = array_unique($c);
$h = range(1, $b);
$i = array_diff($h, $g);
sort($i);
if(count($i) == 0)
{
     print "0";
}
else
{
     print count($i) . "\n";
     print implode(" ", $i);
}
?>

<?php
    list($n, $m) = explode(" ", fgets(STDIN));
    $n = (int)$n;
    $m = (int)$m;

    $aPoints = array();
    $aLeft = array_fill(1, $m, 1);

    for($i = 0; $i < $n; $i++) {
        list($l, $r) = explode(" ", fgets(STDIN));
        $aPoints[] = array(
            'start' => (int)$l,
            'end'   => (int)$r
        );
    }

    foreach($aPoints AS $aPoint) {
        for($j = $aPoint['start']; $j <= $aPoint['end']; $j++) {
            $aLeft[$j] = 0;
        }
    }

    $sLeft = '';
    $iLeft = 0;
    foreach($aLeft AS $iIndex => $iPoint) {
        if($iPoint) {
            if($iLeft != 0) {
                $sLeft .= ' ';
            }
            $sLeft .= $iIndex;
            $iLeft++;
        }
    }

    if($iLeft) {
        echo sprintf("%s\n%s", $iLeft, $sLeft);
    } else {
        echo $iLeft;
    }
?>

<?php
fscanf(STDIN, "%d %d", $n, $m);
$a = array();
$c = array();

for($i=0;$i<$n;$i++){
     $a = explode(" ", trim(fgets(STDIN)));
     $f = range($a[0], $a[1]);
     $c = array_merge($c, $f);
}
$u = array_unique($c);
$r = range(1, $m);
$d = array_diff($r, $u);
sort($d);
if (count($d) == 0)
	echo 0;
else{
	echo count($d) . "\n";
	echo implode(" ", $d);
}

?>

list($n, $m) = explode(" ", fgets(STDIN));
$n = (int)$n;
$m = (int)$m;

$aPoints = array();
$aLeft = array_fill(1, $m, 1);

for($i = 0; $i < $n; $i++) {
    list($l, $r) = explode(" ", fgets(STDIN));
    $aPoints[] = array(
        'start' => (int)$l,
        'end'   => (int)$r
    );
}

foreach($aPoints AS $aPoint) {
    for($j = $aPoint['start']; $j <= $aPoint['end']; $j++) {
        $aLeft[$j] = 0;
    }
}

$sLeft = '';
$iLeft = 0;
foreach($aLeft AS $iIndex => $iPoint) {
    if($iPoint) {
        if($iLeft != 0) {
            $sLeft .= ' ';
        }
        $sLeft .= $iIndex;
        $iLeft++;
    }
}

if($iLeft) {
    echo $iLeft . '<br>';
    echo $sLeft;
} else {
    echo $iLeft;
}

<?php
fscanf(STDIN, "%d %d", $n, $m);
$a = array();
$c = array();

for($i=0;$i<$n;$i++){
     $a = explode(" ", trim(fgets(STDIN)));
     $f = range($a[0], $a[1]);
     $c = array_merge($c, $f);
}
$u = array_unique($c);
$r = range(1, $m);
$d = array_diff($u, $r);
sort($d);
if (count($d) == 0)
	echo 0;
else{
	echo count($d) . "\n";
	echo implode(" ", $d);
}

?>