Santa has $$$n$$$ candies and he wants to gift them to $$$k$$$ kids. He wants to divide as many candies as possible between all $$$k$$$ kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.Suppose the kid who recieves the minimum number of candies has $$$a$$$ candies and the kid who recieves the maximum number of candies has $$$b$$$ candies. Then Santa will be satisfied, if the both conditions are met at the same time:  $$$b - a \le 1$$$ (it means $$$b = a$$$ or $$$b = a + 1$$$);  the number of kids who has $$$a+1$$$ candies (note that $$$a+1$$$ not necessarily equals $$$b$$$) does not exceed $$$\lfloor\frac{k}{2}\rfloor$$$ (less than or equal to $$$\lfloor\frac{k}{2}\rfloor$$$). $$$\lfloor\frac{k}{2}\rfloor$$$ is $$$k$$$ divided by $$$2$$$ and rounded down to the nearest integer. For example, if $$$k=5$$$ then $$$\lfloor\frac{k}{2}\rfloor=\lfloor\frac{5}{2}\rfloor=2$$$.Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The $$$i$$$-th test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^9$$$) — the number of candies and the number of kids.

For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.

NoteIn the first test case, Santa can give $$$3$$$ and $$$2$$$ candies to kids. There $$$a=2, b=3,a+1=3$$$.In the second test case, Santa can give $$$5, 5, 4$$$ and $$$4$$$ candies. There $$$a=4,b=5,a+1=5$$$. The answer cannot be greater because then the number of kids with $$$5$$$ candies will be $$$3$$$.In the third test case, Santa can distribute candies in the following way: $$$[1, 2, 2, 1, 1, 2, 1]$$$. There $$$a=1,b=2,a+1=2$$$. He cannot distribute two remaining candies in a way to be satisfied.In the fourth test case, Santa can distribute candies in the following way: $$$[3, 3]$$$. There $$$a=3, b=3, a+1=4$$$. Santa distributed all $$$6$$$ candies.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / $c);
     $e = $b % $c;
     if($b < $c)
     {
          print min($b, floor($c / 2)) . "\n";
     }
     elseif($e == 0)
     {
          print $b . "\n";
     }
     elseif($b > $c)
     {
          if($e <= floor($c / 2))
          {
               print $b . "\n";
          }
          else
          {
               print $b - ($e - floor($c / 2)) . "\n";
          }
     }
}
?>

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

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

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

	list($n, $k) = explode(' ', trim(fgets(STDIN)));
	$n = intval($n);
	$k = intval($k);

	$ost = $n % $k;

	echo $n - $ost + min($ost, floor($k/2));

	echo "\n";
}

<?php

declare(strict_types = 1);

function main() {
	$tests = (int) fgets(STDIN);
	while (($tests--) > 0) {
		[$n, $k] = array_map( 'intval', explode( " ", fgets(STDIN) ) );
		$answer = $n - ($n % $k);
		$answer += min((int)($n % $k), (int)($k / 2));
		echo "$answer\n";
	}
}

main();

<?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 foo($n, $k)
{
    $od = $n % $k;
    $c = floor($k / 2);

    return $n - $od + min($od, $c);
}

$r = 0;

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

for ($i = 0; $i < $t; ++$i) {
    list($n, $k) = fscanf($input, "%d %d\n");

    $r = foo($n, $k);

    fwrite($output, $r . PHP_EOL);
}

<?php
$o = trim(fgets(STDIN));
for($j = 0; $j < $o; $j++){
    $a = explode(" ",trim(fgets(STDIN)));
    $r = array();
    $min = floor($a[0]/$a[1]);
    $b = true;
    $c = false;
    $count = $min * $a[1];
    $count += floor($a[1]/2);
    $count = $count > $a[0] ? $a[0] : $count;
    echo $count."\n";
}

<?php

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

for($i=0;$i<$t;$i++)
{
    $x=trim(fgets($handle));
    $a=explode(' ',$x);
    $min=(int)($a[0]/$a[1]);
    $hou=$a[0]%$a[1];
    if($hou<=$a[1]/2)
    {
        echo bcadd(bcmul($min,$a[1]),$hou)."\n";
    }else
    {
        echo bcadd(bcmul($min,$a[1]),(int)($a[1]/2))."\n";
    }

}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / $c);
     $e = $b % $c;
     if($b < $c)
     {
          print $b . "\n";
     }
     elseif($e == 0)
     {
          print $b . "\n";
     }
     else
     {
          $f = $b - ($e - floor($c / 2));
          print $f . "\n";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / $c);
     $e = $b % $c;
     if($e == 0)
     {
          print $b . "\n";
     }
     else
     {
          $f = $b - ($e - floor($c / 2));
          print $f . "\n";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / $c);
     $e = $b % $c;
     if($b < $c)
     {
          print min($b, floor($c / 2));
     }
     elseif($e == 0)
     {
          print $b . "\n";
     }
     else
     {
          $f = $b - ($e - floor($c / 2));
          print $f . "\n";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / $c);
     $e = $b % $c;
     if($b < $c)
     {
          print min($b, floor($c / 2)) . "\n";
     }
     elseif($e == 0)
     {
          print $b . "\n";
     }
     else
     {
          $f = $b - ($e - floor($c / 2));
          print $f . "\n";
     }
}
?>

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

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

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

	list($n, $k) = explode(' ', trim(fgets(STDIN)));
	$n = intval($n);
	$k = intval($k);

	$ost = $n % $k;

	echo $n - $ost + min($ost, ceil($k/2));

	echo "\n";
}

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

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

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

	list($n, $k) = explode(' ', trim(fgets(STDIN)));
	$n = intval($n);
	$k = intval($k);

	$ost = $n % $k;

	echo $n - $ost + min($ost, floor($k/2));

	echo "\n";
}

<?php

declare(strict_types = 1);

function main() {
	$tests = (int) fgets(STDIN);
	while (($tests--) > 0) {
		[$n, $k] = array_map( 'intval', explode( " ", fgets(STDIN) ) );
		$answer = $n - ($n % $k);
		$answer += min((int)($n % $k), (int)($k / 2));
		echo "$answer";
	}
}

main();

<?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 foo($n, $k)
{
    $a = floor($n / $k);

    $od = $n % $k;

    if ($od === 0 || $od === 1) {
        return $n;
    }

    if (($k > $n) && (($k - $n) > (int)($n / 2))) {
        return 0;
    }

    $c = $a * $k;
    $c += floor($k / 2);

    return $c > $n ? $n : $c;
}

$r = 0;

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

for ($i = 0; $i < $t; ++$i) {
    list($n, $k) = fscanf($input, "%d %d\n");

    $r = foo($n, $k);

    fwrite($output, $r . 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 foo($n, $k)
{
    $a = $n % $k;

    if ($a === 0) {
        return $n;
    }

    if (($k > $n) && (($k - $n) > (int)($n / 2))) {
        return 0;
    }

    $b = (int) ($k / 2);

    $c = $a - $b;

    return $n - $c;
}

$r = 0;

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

for ($i = 0; $i < $t; ++$i) {
    list($n, $k) = fscanf($input, "%d %d\n");

    $r = foo($n, $k);

    fwrite($output, $r . 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 foo($n, $k)
{
    $a = $n % $k;

    if ($a === 0) {
        return $n;
    }

    $b = (int) ($k / 2);
    $c = $a - $b;

    return $n - $c;
}

$r = 0;

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

for ($i = 0; $i < $t; ++$i) {
    list($n, $k) = fscanf($input, "%d %d\n");

    $r = foo($n, $k);

    fwrite($output, $r . PHP_EOL);
}


Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent.One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has.Find the volume fraction of orange juice in the final drink.

The first input line contains a single integer n (1 ≤ n ≤ 100) — the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≤ pi ≤ 100) — the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space.

Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10  - 4.

NoteNote to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal  milliliters. The total cocktail's volume equals 3·x milliliters, so the volume fraction of the juice in the cocktail equals , that is, 66.(6) percent.

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

$lin = explode("\n",$in);
$n = $lin[0];
$percent = explode(" ",$lin[1]);
$sum =0;
for($i=0;$i<$n;$i+=1){
    $sum += $percent[$i];
}
echo $sum/$n;
?>

<?php
$n = fgets(STDIN);
$d = explode(' ',fgets(STDIN));
$sum = 0;

for( $i=0; $i<$n; $i++ ){
    $sum = $sum + $d[$i];
}

echo $sum/$n;

<?php
$napitki=readline();
$prozenty = readline();

//$napitki = 4;
//$prozenty = '0 25 50 75';
$prozenty = explode(' ', $prozenty);
$sum = 0;
$i=0;
//for ($i = 0; $i < $napitki; $i++) {
foreach ($prozenty as $v) {
    $sum = $sum + $prozenty[$i];
    $i++;
}
    echo $sum / $napitki;

<?php
$stdin = fopen("php://stdin", "r");
$stdout = fopen("php://stdout", "w");
$n = intval(fgets($stdin));
$arr = explode(" ",fgets($stdin));
$sum = 0;
foreach($arr as $data){
$sum += intval($data);
}
fwrite($stdout,$sum * 1.0 / $n);
?>

<?php

fscanf(STDIN , "%f" , $n);
$a = explode(" " , trim(fgets(STDIN)));
$ans = array_sum($a) / $n;
echo $ans;

?>

<?php
fscanf(STDIN, "%d", $n);
$juice = explode(" ", trim(fgets(STDIN)));

echo array_sum($juice) / $n;

?>

<?php

// your code goes here
while($f = fgets(STDIN)){
    $lines[] = $f;
}

function getOrangeProp($lines){
	$drinks = $lines[0];
	$proportions = explode(' ', $lines[1]);
	$totalProp = 0;
	foreach($proportions as $prop){
		$totalProp += $prop;
	}
	$orangeProp = $totalProp/$drinks;
	return $orangeProp;
}

echo getOrangeProp($lines);

<?php
    $stdin = fopen("php://stdin", "r");
    fscanf(STDIN, "%d", $n);
    $arr = explode(" ", trim(fgets(STDIN)));
    fclose($stdin);

    foreach($arr as $x)
        $ans += $x;

    echo $ans / sizeof($arr) . PHP_EOL;
?>

<?php

	$handle = fopen("php://stdin", 'r');
	$readAll = stream_get_contents($handle);
	$contents = explode("\n", $readAll);
	$n = $contents[0];
	$other_contents = explode(' ', $contents[1]);
	$sum = 0;
	$size = sizeof($other_contents);
	for ($i = 0; $i < $size; $i++) {
		$sum += $other_contents[$i];
	}
	echo $sum/$size;

?>

<?php
error_reporting("off");
//200B: Drinks
$n = trim(fgets(STDIN)); //$n = 4;
$p = explode(" ", trim(fgets(STDIN))); //$p = explode(" ", "0 25 50 75");
$oj = 0;
$totalml = $n * 100;
foreach ($p as $value) {
    $oj += $value;
}
echo $oj / $totalml * 100;
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
print ($c / ($a * 100)) * 100;
?>

<?php
$i = fgets(STDIN);
if($i==0) die("0");
if($i == 1) die(fgets(STDIN));
$p = explode(" ", fgets(STDIN));
for($t=0; $t<=sizeof($p); $t++)
{
    $pa += $p[$t];
}
echo $pa/$i;
?>

<?php

$data1 = (int) trim(fgets(STDIN));
$data2 = trim(fgets(STDIN));

$main = new MainClass;

echo $main->solution($data1, $data2);

// End of interface

class MainClass {
	//public $problemLink = 'https://codeforces.com/problemset/problem/200/B';
	//public $submissionLink = '';

	public function solution($n, $string)
	{
		$arrayOfStrings = preg_split("/ /", $string);
		$sum = 0;
			for($i = 0; $i < $n; $i++){
				$sum = $sum + (int)$arrayOfStrings[$i];
			}
			return $sum / $n;
	}
}

<?php

$data1 = (int) trim(fgets(STDIN));
$data2 = preg_split("/ /", trim(fgets(STDIN)));

$main = new MainClass;

echo $main->solution($data1, $data2);

// End of interface

class MainClass {
	//public $problemLink = 'https://codeforces.com/problemset/problem/200/B';
	//public $submissionLink = '';

	public function solution($n, $arrayOfStrings)
	{
		$sum = 0;
			foreach ($arrayOfStrings as $value) {
    		$sum += $value;
			}
		return $sum / $n;
	}
}

<?php

$data1 = (int) trim(fgets(STDIN));
$data2 = explode(" ", trim(fgets(STDIN)));

$main = new MainClass;

echo $main->solution($data1, $data2);

// End of interface

class MainClass {
	//public $problemLink = 'https://codeforces.com/problemset/problem/200/B';
	//public $submissionLink = '';

	public function solution($n, $arrayOfStrings)
	{
		$sum = 0;
			foreach ($arrayOfStrings as $value) {
    		$sum += $value;
			}
			return $sum / $n;
	}
}

<?php

error_reporting(0);

solve();

function solve(){

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

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

	$sum = 0;

	for ($i = 0; $i < $n; $i++)
	{
		$sum += (int)$Input->in();
	}

	$p = 100 * $sum / (100 * $n);

	printf("%.12f",$p );
}

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

	public function __construct($localfile){

		if (is_file($localfile)) {

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

		} else {

			$contents = stream_get_contents(STDIN);

		}

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

	public function in(){

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

	}

	public function close(){

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

	}
}

?>

<?php

$n = readline();
$ara = explode(' ', readline());
echo array_sum($ara)/$n;

<?php
$n = fgets(STDIN);
print array_sum(explode(' ', fgets(STDIN)))/$n;

<?php
    fscanf(STDIN, "%d", $n);
    $arr = explode(" ", trim(fgets(STDIN)));
    $v = 0;
        for ($i = 0; $i < count($arr); $i++){
           $v = $v + $arr[$i];
        }
        $v = $v / $n ;
        printf("%.12f", $v);

<?php
    $stdin = fopen("php://stdin","r");
    $stdout=fopen("php://stdout","w");
    $cnt=0;$tmp=0;
    fscanf($stdin,"%d\n",&$cnt);
    $sum = 0;
    $st = fgets($stdin);
    /*
    for($i=0;$i<$cnt;$i++){
        fscanf($stdin,"%d ",&$tmp);
        $sum = $sum + $tmp;
    }
    */
    $arr = explode(' ',$st);
    foreach($arr as $v){
        $sum += $v;
    }
    fprintf($stdout,"%.12f\n",($sum/$cnt));
?>

<?php
function input()
{
    while (($line = trim(fgets(STDIN))) != PHP_EOL) {
        yield $line;
    }
}
function intParam($l) {
    return array_map('intval', explode(' ', $l));

}
$COUNT = 0;
foreach (input() as $line) {
    if ($COUNT == 0) {
        $n = intval($line);
        ++$COUNT;
        continue;
    }
    $q = intParam($line);

    $s = 0;
    for($i = 0; $i < $n; ++$i) {
        $s += $q[$i];
    }

    echo $s/$n;

    if (++$COUNT > 1) {
        break;
    }
}

<?php
// Retrieve input and show output
$stream = fopen("php://stdin", "r");
$input = stream_get_contents($stream);
$inputs = preg_split("/[\s]+/", $input);
echo func($inputs);

// Codeforces Contest 126 Division 2 Problem B
function func($in) {
$sum = 0;
for ($x = 1; $x <= $in[0]; $x++) {
	$sum += $in[$x];
}
return ($sum / $in[0]);
}

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

<?php
$stdin = fopen("php://stdin", "r");
$stdout = fopen("php://stdout", "w");
$n = intval(fgets($stdin));
$arr = explode(" ",fgets($stdin));
$sum = 0;
foreach($arr as $data){
$sum += intval($data);
}
fwrite($sum * 1.0 / $n);
?>

<?php
fscanf(STDIN , "%f" , $n);
$ans = 0;
for ($i=0; $i<$n; $i++){
	fscanf(STDIN, "%d", $a);
	$ans+=$a;
}
fprintf(STDOUT, "%f", $ans/$n);


All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point.Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.For each city calculate two values mini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city

The first line of the input contains integer n (2 ≤ n ≤ 105) — the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.

Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.

<?php
    $n = trim(fgets(STDIN));
    $arr = explode(" ", trim(fgets(STDIN)));
    sort($arr);
    function max_($index){
        global $arr;
        global $n;
        if($index == 0)
            return $arr[$n-1] -$arr[0];
        else if($index == $n-1){
            return $arr[$n-1] -$arr[0];
        }
        else{
            return $arr[$n-1] -$arr[$index] > $arr[$index] - $arr[0] ? $arr[$n-1] -$arr[$index] : $arr[$index] - $arr[0];
        }
    }
    function min_($index){
        global $arr;
        global $n;
        if($index == 0)
            return $arr[1] -$arr[0];
        else if($index == $n-1){
            return $arr[$n-1] -$arr[$n-2];
        }
        else{
            return $arr[$index] -$arr[$index - 1] > $arr[$index + 1] - $arr[$index] ? $arr[$index + 1] - $arr[$index] : $arr[$index] -$arr[$index - 1];
        }
    }
    for($i = 0;$i<$n; $i++){
        echo min_($i)." ".max_($i)."\n";
    }

<?php

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

fscanf( $stdin , "%d" , $t ) ;

fscanf( $stdin , "%[^\n]" , $test ) ;

$numbers = array_map( 'intval' , preg_split('/ /' , $test , -1 , PREG_SPLIT_NO_EMPTY ) );

$arr = [] ;

echo ( $numbers[1] - $numbers[0] ) . " " . ( $numbers[$t-1] - $numbers[0] ) . "\n" ;

for( $i=1 ; $i<$t-1 ; $i++)
{
   echo min( $numbers[$i+1] - $numbers[$i] , $numbers[$i] - $numbers[$i-1] ) . " " . max($numbers[$t-1] - $numbers[$i] , $numbers[$i] - $numbers[0] ) . "\n" ;
}

echo ( $numbers[$t-1] - $numbers[$t-2] ) . " " . ( $numbers[$t-1] - $numbers[0] ) . "\n" ;

fwrite($stdout);

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

?>

<?php
$line = trim(fgets(STDIN));
$n = intval($line);
$line = trim(fgets(STDIN));
$arr = array_map('intval', explode(' ', $line));

sort($arr);
for($i = 0; $i < $n; $i++) {
	$min = $i == 0 ? $arr[1] - $arr[0] : ($i == $n-1? $arr[$i] - $arr[$i-1]: min($arr[$i] - $arr[$i-1], $arr[$i+1] - $arr[$i]));
	$max = $i == 0 || $i== $n-1 ? $arr[$n-1] - $arr[0] : max($arr[$n-1] - $arr[$i], $arr[$i] - $arr[0]);
	echo $min;
	echo " ";
	echo $max;
	echo "\n";
}

<?php

function say($a, $b) {
    echo $a . ' ' . $b . PHP_EOL;
}

$input = fgets(STDIN);
$input = rtrim(fgets(STDIN));
$numbers = explode(' ', rtrim($input));
$countNumbers = count($numbers);

say(
    abs((int)$numbers[1] - (int)$numbers[0]),
    abs((int)$numbers[$countNumbers - 1] - (int)$numbers[0])
);

for ($i = 1; $i < $countNumbers - 1; $i++) {
    say(
        min(
            abs((int)$numbers[$i + 1] - (int)$numbers[$i]),
            abs((int)$numbers[$i] - (int)$numbers[$i - 1])
        ),
        max(
            abs((int)$numbers[$i] - (int)$numbers[0]),
            abs((int)$numbers[$countNumbers - 1] - (int)$numbers[$i])
        )
    );
}

say(
    abs((int)$numbers[$countNumbers - 1] - (int)$numbers[$countNumbers - 2]),
    abs((int)$numbers[$countNumbers - 1] - (int)$numbers[0])
);

<?php
    $n = trim(fgets(STDIN));
    $arr = explode(" ", trim(fgets(STDIN)));
    sort($arr);
    function max_($index){
        global $arr;
        global $n;
        if($index == 0)
            return $arr[$n-1] -$arr[0];
        else if($index == $n-1){
            return $arr[$n-1] -$arr[0];
        }
        else{
            return $arr[$n-1] -$arr[$index] > $arr[0] - $arr[$index] ? $arr[$n-1] -$arr[$index] : $arr[0] - $arr[$index];
        }
    }
    function min_($index){
        global $arr;
        global $n;
        if($index == 0)
            return $arr[1] -$arr[0];
        else if($index == $n-1){
            return $arr[$n-1] -$arr[$n-2];
        }
        else{
            return $arr[$index] -$arr[$index - 1] > $arr[$index + 1] - $arr[$index] ? $arr[$index + 1] - $arr[$index] : $arr[$index] -$arr[$index - 1];
        }
    }
    for($i = 0;$i<$n; $i++){
        echo min_($i)." ".max_($i)."\n";
    }


You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:  The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened;  The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise.

NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened.


You have a list of numbers from $$$1$$$ to $$$n$$$ written from left to right on the blackboard.You perform an algorithm consisting of several steps (steps are $$$1$$$-indexed). On the $$$i$$$-th step you wipe the $$$i$$$-th number (considering only remaining numbers). You wipe the whole number (not one digit).  When there are less than $$$i$$$ numbers remaining, you stop your algorithm. Now you wonder: what is the value of the $$$x$$$-th remaining number after the algorithm is stopped?

The first line contains one integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. The next $$$T$$$ lines contain queries — one per line. All queries are independent. Each line contains two space-separated integers $$$n$$$ and $$$x$$$ ($$$1 \le x < n \le 10^{9}$$$) — the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least $$$x$$$ numbers.

Print $$$T$$$ integers (one per query) — the values of the $$$x$$$-th number after performing the algorithm for the corresponding queries.

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

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
$aArrays = [];
for($i = 0; $i < $c; $i++){
    list($n,$x) = explode(' ', trim(fgets(STDIN)));
    echo $x * 2 . "\n";
}

<?php
// $a = ['a','a'];
// $b = ['b'];
// $c = ['ab','ab'];

$result = [];

function getPointedElements($n, $x)
{
    return 2*$x;
}

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

$nRequestNumber = $n[0];

if( !is_nan($nRequestNumber) )
{
    for($i = 0; $i < $nRequestNumber; $i++)
    {
        $line_data = explode(" ", trim(fgets(STDIN)));
        $n = $line_data[0];
        $x = $line_data[1];

        array_push($result, getPointedElements($n,$x));

    }
}

foreach($result as $value)
{
    echo $value.PHP_EOL;
}

<?php

$t = trim(fgets(STDIN));

for ($o = 0; $o < $t; $o++)
{
	$data = trim(fgets(STDIN));
	$data = explode(" ", $data);
	$n = $data[0];
	$x = $data[1];
	$ans = 2;
	echo ($ans * $x)."\n";
}

?>


Kawashiro Nitori is a girl who loves competitive programming.One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem.Given a string $$$s$$$ and a parameter $$$k$$$, you need to check if there exist $$$k+1$$$ non-empty strings $$$a_1,a_2...,a_{k+1}$$$, such that $$$$$$s=a_1+a_2+\ldots +a_k+a_{k+1}+R(a_k)+R(a_{k-1})+\ldots+R(a_{1}).$$$$$$ Here $$$+$$$ represents concatenation. We define $$$R(x)$$$ as a reversed string $$$x$$$. For example $$$R(abcd) = dcba$$$. Note that in the formula above the part $$$R(a_{k+1})$$$ is intentionally skipped.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case description contains two integers $$$n$$$, $$$k$$$ ($$$1\le n\le 100$$$, $$$0\le k\le \lfloor \frac{n}{2} \rfloor$$$)  — the length of the string $$$s$$$ and the parameter $$$k$$$. The second line of each test case description contains a single string $$$s$$$ of length $$$n$$$, consisting of lowercase English letters.

For each test case, print "YES" (without quotes), if it is possible to find $$$a_1,a_2,\ldots,a_{k+1}$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower).

7
5 1
qwqwq
2 1
ab
3 1
ioi
4 2
icpc
22 0
dokidokiliteratureclub
19 8
imteamshanghaialice
6 3
aaaaaa

NoteIn the first test case, one possible solution is $$$a_1=qw$$$ and $$$a_2=q$$$.In the third test case, one possible solution is $$$a_1=i$$$ and $$$a_2=o$$$.In the fifth test case, one possible solution is $$$a_1=dokidokiliteratureclub$$$.

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

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

for ($i = 0; $i < $t; $i++) {
  list($n, $k) = explode(" ", trim(fgets($file)));
  $s = trim(fgets($file));

  if ($k == 0 || $n == 1) {
		echo 'YES'.PHP_EOL;
	} else {
		$f = 0;
		if ($n % 2 == 1) {
		  $r = floor($n/2);

			for ($j = 0; $j < $r; $j++) {
				if ($s[$j] == $s[$n - $j - 1]) {
					$f++;
				} else { break; }
			}
			if ($f >= $k) { echo 'YES'.PHP_EOL; }
			else { echo 'NO'.PHP_EOL; }

		} else {
		  $r = floor($n/2) - 1;

			for ($j = 0; $j < $r; $j++) {
				if ($s[$j] == $s[$n - $j - 1]) {
					$f++;
				} else { break; }
			}

			if ($f >= $k) { echo 'YES'.PHP_EOL; }
			else { echo 'NO'.PHP_EOL; }
		}
	}
}

?>

<?php

$t = (int) trim(fgets(STDIN));
for ($i = 0; $i < $t; ++$i) {
    //i[]
    list($ni[], $ki[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $si[] = trim(fgets(STDIN));
}
for ($i = 0; $i < $t; ++$i) {
    $n = $ni[$i];
    $k = $ki[$i];
    $s = $si[$i];
    $len = strlen($s);
    echo ($len >= 2 * $k + 1 && substr($s, 0, $k) === strrev(substr($s, -$k, $k)) ? 'YES' : 'NO').PHP_EOL;
}

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

	for ($o = 0; $o < $t; $o++) {
		list($n, $k) = explode(" ", trim(fgets(STDIN)));
		$s = trim(fgets(STDIN));
		if ($k == 0) {
			print "YES\n";
			continue;
		} else {
			$c = 0;
			for ($i = 0; $i < floor($n/2); $i++) {
				if ($s[$i] == $s[$n - $i - 1]) {
					$c++;
				}
			}
			if ($n % 2 == 1) {
				if ($k > $c) {
					print "NO\n";
				} else {
					print "YES\n";
				}
			} else {
				if ($k + 1 > $c) {
					print "NO\n";
				} else {
					print "YES\n";
				}
			}
		}
	}
?>

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

	for ($o = 0; $o < $t; $o++) {
		list($n, $k) = explode(" ", trim(fgets(STDIN)));
		$s = trim(fgets(STDIN));
		if ($k == 0) {
			print "YES\n";
			continue;
		} else {
			$c = 0;
			for ($i = 0; $i < $n/2; $i++) {
				if ($s[$i] == $s[$n - $i - 1]) {
					$c++;
				}
			}
			if ($k+1 > $c) {
				print "NO\n";
			} else {
				print "YES\n";
			}
		}
	}
?>

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

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

for ($i = 0; $i < $t; $i++) {
  list($n, $k) = explode(" ", trim(fgets($file)));
  $s = trim(fgets($file));

  if ($k == 0 || $n == 1) {
		echo 'YES'.PHP_EOL;
	} else {
		$c = 0;
		if ($n % 2 == 1) {
		  $r = floor($n/2);
		  $str = substr($s, 0, $r);
		  $str1 = substr($s, '-'.$r);

			if (strrev($str) == $str1 && strlen($str) >= $k) { echo 'YES'.PHP_EOL; }
			else { echo 'NO'.PHP_EOL; }

		} else {
		  $r = floor($n/2) - 1;
		  $str = substr($s, 0, $r);
		  $str1 = substr($s, '-'.$r);

			if (strrev($str) == $str1 && strlen($str) >= $k) { echo 'YES'.PHP_EOL; }
			else { echo 'NO'.PHP_EOL; }
		}
	}
}

?>


You are given a string $$$s$$$ consisting of the characters '0', '1', and '?'. You need to replace all the characters with '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and has exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1'. Note that each of the characters '?' is replaced independently from the others.A string $$$t$$$ of length $$$n$$$ is called a palindrome if the equality $$$t[i] = t[n-i+1]$$$ is true for all $$$i$$$ ($$$1 \le i \le n$$$).For example, if $$$s=$$$"01?????0", $$$a=4$$$ and $$$b=4$$$, then you can replace the characters '?' in the following ways:   "01011010";  "01100110". For the given string $$$s$$$ and the numbers $$$a$$$ and $$$b$$$, replace all the characters with '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and has exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1'.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 2 \cdot 10^5$$$, $$$a + b \ge 1$$$). The second line of each test case contains the string $$$s$$$ of length $$$a+b$$$, consisting of the characters '0', '1', and '?'. It is guaranteed that the sum of the string lengths of $$$s$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output:    "-1", if you can't replace all the characters '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and that it contains exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1';  the string that is obtained as a result of the replacement, otherwise.  If there are several suitable ways to replace characters, you can output any.


Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи считают плохими. Когда Вася получает подряд три хорошие оценки, ему сразу вручают подарок, но для того, чтобы получить ещё один подарок, ему вновь надо получить подряд ещё три хорошие оценки.Например, если Вася получит подряд пять «четвёрок» оценок, а потом «двойку», то ему дадут только один подарок, а вот если бы «четвёрок» было уже шесть, то подарков было бы два. За месяц Вася получил n оценок. Вам предстоит посчитать количество подарков, которые получил Вася. Оценки будут даны именно в том порядке, в котором Вася их получал.

В первой строке входных данных следует целое положительное число n (3 ≤ n ≤ 1000) — количество оценок, полученных Васей. Во второй строке входных данных следует последовательность из n чисел a1, a2, ..., an (1 ≤ ai ≤ 5) — оценки, полученные Васей. Оценки заданы в том порядке, в котором Вася их получил.

Выведите одно целое число — количество подарков, полученных Васей.

ПримечаниеВ первом примере Вася получит два подарка — за первые три положительные оценки и за следующую тройку положительных оценок соответственно.

<?php
fscanf(STDIN, "%d\n", $number);
$marks = explode(" ", trim(fgets(STDIN)));
$streak = 0;
$presents = 0;

for ($i=0; $i <= $number-1; $i++) {
  if ($marks[$i] > 3) {
    $streak++;
  } else {
    $streak = 0;
  }

  if ($streak == 3) {
    $presents++;
    $streak = 0;
  }
}

echo $presents;

<?php
fgets(STDIN); // For spend count of numbers
$line = trim(fgets(STDIN));
$line = str_replace(' ', '', $line);
$c = preg_match_all('/(4|5){3}/', $line);
fwrite(STDOUT, $c.PHP_EOL);


There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated:   Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee n. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting).  When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end.  When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with n who are still eligible to vote make their statements.  The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction. You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.  The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.

Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.

NoteConsider one of the voting scenarios for the first sample:   Employee 1 denies employee 5 to vote.  Employee 2 denies employee 3 to vote.  Employee 3 has no right to vote and skips his turn (he was denied by employee 2).  Employee 4 denies employee 2 to vote.  Employee 5 has no right to vote and skips his turn (he was denied by employee 1).  Employee 1 denies employee 4.  Only employee 1 now has the right to vote so the voting ends with the victory of depublicans.


One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.You are given an integer n no less than 12, express it as a sum of two composite numbers.

The only line contains an integer n (12 ≤ n ≤ 106).

Output two composite integers x and y (1 < x, y < n) such that x + y = n. If there are multiple solutions, you can output any of them.

NoteIn the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.

<?php

$in = fopen("php://stdin", "r");
$number = trim(fgets($in));

$first = $number[0];
$length = strlen($number);
$last = substr($number, -1);
$s = $first * pow(10, $length);
$number = (int) $number;

if ($number[0] > 2) {
  if ($last == 0) {
      $result[] = $number/2;
      $reulst[] = $number/2;
  }

  elseif ($last % 2 == 0) {
   $result[] = $s;
   $result[] = $number - $s;
  }
  else {
     $result[] = $s - 5;
     $result[] = $number - $s - 5;
  }
} else {
  if ($last % 2 == 0) {
    $result[] = $number - 4;
     $result[] = 4;
  }
  else {
    $result[] = $number - 9;
    $result[] = 9;
  }
}

echo implode(" ", $result);

<?
	$n = intval(trim(fgets(STDIN)));
	for ($i=0;$i<=$n;$i++){
		if (isSost($i) && isSost($n-$i)){
			echo $i.' '.($n-$i);
			break;
		}
	}

	function isSost($n){
    	for($i=2;$i<=sqrt($n);$i++)
    	    if(($n % $i) == 0) return true;
    	return false;
	}
?>

<?php
/*
 * A. Уроки дизайна задач: учимся у математики
 */
$n = trim(fgets(STDIN));
($n%2==0) ? printf("%d %d",4,$n-4) : printf("%d %d",9,$n-9);

<?php
$line = fgets(STDIN);
$divider = array(2,3,4,5,6,7,8,9);
$abs = 4;
function isComposite($num)
{
    global $divider;
    $isComposite=0;
    for ($i=0;$i<8;$i++)
    {
        if ($num%$divider[$i]==0)$isComposite++;
    }
    if ($isComposite>=2)return true;
    else return false;
}
while (!(isComposite($line-$abs)&&isComposite($abs)))$abs++;
echo $line-$abs." ".$abs;

<?php
function prime ($x) {
    for($i=2;$i<=sqrt($x);++$i)
        if(!($x%$i))
            return false;
    return true;
}

$stdin = fopen("php://stdin", 'r');
$stdout = fopen("php://stdout", 'w');
fscanf($stdin, "%d", $n);
for($i = 4;$i<$n;++$i) {
    if(!prime($i) && !prime($n-$i)) {
        break;
    }
}
fprintf($stdout, "%d %d", $i , $n - $i);
?>

<?php
    $n = trim(fgets(STDIN));
    function is_prime($n)
    {
        for ($x = 2; $x <= sqrt($n); $x++) {
            if ($n % $x == 0) {
                return false;
            }
        }
        return true;
    }

    for ($i = 1; $i <= 1000000; $i++) {
        if (!is_prime($i)) {
            $s = $n - $i;
            if (!is_prime($s)) {
                echo "{$i} {$s}";
                return;
            }
        }
    }

<?php
// 472A Уроки дизайна задач: учимся у математики

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

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

$prime = array();
//$prime[2] = true;

for ($i=2; $i <= $n; $i++) {
    if (!isset($prime[$i])) {
        for ($j=$i*$i; $j < $n; $j += $i) {
            $prime[$j] = true;
        }
    }
}

for ($i=1; $i <= $n/2 ; $i++) {
    $a = $i;
    $b = $n - $a;
    if (isset($prime[$a]) and isset($prime[$b])) {
        break;
    }
}

echo "$a $b";

?>

<?php

$n = (int)fgets(STDIN);

if ($n % 2 == 0) {
	print implode(' ', array(4, $n - 4));
} else {
	print implode(' ', array(9, $n - 9));
}

<?php

function isPrime($number){
	$sqrt = sqrt($number);
	for ($i = 2; $i <= $sqrt; $i++) {
		if($number%$i == 0){
			return false;
		}
	}
	return true;
}

function solve(){
	$handle = fopen("php://stdin", 'r');
	$number = stream_get_contents($handle);
	$min = 2;
	$max = $number;
	while(true){
		$first_number = rand($min,$max-1);
		$second_number = $number - $first_number;
		if(!isPrime($first_number)&&!isPrime($second_number))
			break;
	}
	fclose($handle);
	if($first_number < $second_number)
		echo $first_number.' '.$second_number;
	else if($first_number > $second_number)
		echo $second_number.' '.$first_number;
	else
		echo $first_number.' '.$second_number;
}

solve();

?>

<?php
    function is_prime ($n)
    {
        for($x=2; $x * $x <= $n; $x++) {
            if($n % $x == 0) {
                return false;
            }
        }
    return true;
    }

    fscanf(STDIN, "%d", $n);
        for ($i = 4; $i < $n; $i++){
            $a = is_prime($i);
            $b = is_prime($n - $i);
            if (!$a && !$b){
                printf("%d %d", $i, $n - $i);
                // echo ($i . ' ' . $n - $i);
                break;

            }
        }

<?php
/*
 * A. Уроки дизайна задач: учимся у математики
 */

$n = trim(fgets(STDIN));

$random_number = rand(2,$n-2);
$second = $n - $random_number;
echo $random_number.' '.$second;

<?php
$line = trim(fgets(STDIN));
$firstHalf = intval($line/2);
$secondHalf = $line - $firstHalf;
echo $firstHalf." ".$secondHalf;

<?php
// 472A Уроки дизайна задач: учимся у математики

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

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

$a = intval($n / 2);

if (($n % 2) == 0) {
    $b = $a;
} else {
    $b = $a +1;
}
echo "$a $b";

?>

<?php

function solve(){
	$handle = fopen("php://stdin", 'r');
	$number = fread($handle, 1000);
	$min = 2;
	$max = $number;
	$first_number = rand($min,$max-1);
	$second_number = $number - $first_number;
	fclose($handle);
	echo $first_number.' '.$second_number;
}
solve();

?>

<?php

function solve(){
	$handle = fopen("php://stdin", 'r');
	$number = fread($handle, 1);
	$min = 1;
	$max = $number;
	$first_number = rand($min,$max-1);
	$second_number = $number - $first_number;
	fclose($handle);
	echo $first_number.' '.$second_number;
}

solve();

?>


A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took several permutations (perhaps, with a different number of elements), wrote them down consecutively as one array and then shuffled the resulting array. The task is to restore the initial permutations if it is possible.

The first line contains an integer n (1 ≤ n ≤ 105). The next line contains the mixed array of n integers, divided with a single space. The numbers in the array are from 1 to 105.

If this array can be split into several permutations so that every element of the array belongs to exactly one permutation, print in the first line the number of permutations. The second line should contain n numbers, corresponding to the elements of the given array. If the i-th element belongs to the first permutation, the i-th number should be 1, if it belongs to the second one, then its number should be 2 and so on. The order of the permutations’ numbering is free. If several solutions are possible, print any one of them. If there’s no solution, print in the first line  - 1.

NoteIn the first sample test the array is split into three permutations: (2, 1), (3, 2, 1, 4, 5), (1, 2). The first permutation is formed by the second and the fourth elements of the array, the second one — by the third, the fifth, the sixth, the seventh and the ninth elements, the third one — by the first and the eigth elements. Clearly, there are other splitting variants possible.

<?php

$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
array_unshift($b, " ");
unset($b[0]);
$c = array();
$d = 1;
$e = 1;
for($x = 1; $x <= 100000; $x++)
{
    $f = array_search($e, $b);
    if($f == TRUE)
    {
        $c[$f] = $d;
        $e++;
        unset($b[$f]);
    }
    else
    {
        $e = 1;
        $d++;
    }
}
ksort($c);
if($a == count($c))
{
    print $d . "\n";
    print implode(" ", $c);
}
else
{
    print "-1";
}
?>


The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.

The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value.

If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them.


Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once.Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome.You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string.

The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings.

In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.

<?php

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

$e = [];
$v = [];

while ($n--) {
    fscanf(STDIN, '%s', $s);

    for ($i = 0; $i < strlen($s); $i++) {
        $v[$s[$i]] = $s[$i];
        if ($i) {
            $e[$s[$i-1]] = $s[$i];
        }
    }
}

$arr = $v;
foreach ($e as $key => $value) {
    if (isset($arr[$value])) {
        unset($arr[$value]);
    }
}

$results = [];
foreach ($arr as $c) {
    $way = '';
    for ($i = $c; $i; $i = isset($e[$i]) ? $e[$i] : null) {
        $way .= $i;
    }

    $results[$c] = $way;
}

echo implode($results) . PHP_EOL;


You have $$$n$$$ gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The $$$i$$$-th gift consists of $$$a_i$$$ candies and $$$b_i$$$ oranges.During one move, you can choose some gift $$$1 \le i \le n$$$ and do one of the following operations:  eat exactly one candy from this gift (decrease $$$a_i$$$ by one);  eat exactly one orange from this gift (decrease $$$b_i$$$ by one);  eat exactly one candy and exactly one orange from this gift (decrease both $$$a_i$$$ and $$$b_i$$$ by one). Of course, you can not eat a candy or orange if it's not present in the gift (so neither $$$a_i$$$ nor $$$b_i$$$ can become less than zero).As said above, all gifts should be equal. This means that after some sequence of moves the following two conditions should be satisfied: $$$a_1 = a_2 = \dots = a_n$$$ and $$$b_1 = b_2 = \dots = b_n$$$ (and $$$a_i$$$ equals $$$b_i$$$ is not necessary).Your task is to find the minimum number of moves required to equalize all the given gifts.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of gifts. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the number of candies in the $$$i$$$-th gift. The third line of the test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$), where $$$b_i$$$ is the number of oranges in the $$$i$$$-th gift.

For each test case, print one integer: the minimum number of moves required to equalize all the given gifts.

NoteIn the first test case of the example, we can perform the following sequence of moves:  choose the first gift and eat one orange from it, so $$$a = [3, 5, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the second gift and eat one candy from it, so $$$a = [3, 4, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the second gift and eat one candy from it, so $$$a = [3, 3, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the third gift and eat one candy and one orange from it, so $$$a = [3, 3, 5]$$$ and $$$b = [2, 2, 2]$$$;  choose the third gift and eat one candy from it, so $$$a = [3, 3, 4]$$$ and $$$b = [2, 2, 2]$$$;  choose the third gift and eat one candy from it, so $$$a = [3, 3, 3]$$$ and $$$b = [2, 2, 2]$$$.

<?php
$testsCount = trim( fgets(STDIN) );
for ($i = 1; $i <= $testsCount; $i++) runProgram();

function runProgram()
{
  $presentCount = trim(fgets(STDIN));
  $presentCandies = explode( ' ', trim(fgets(STDIN)) );
  $presentOranges = explode( ' ', trim(fgets(STDIN)) );

  $minCandies = PHP_FLOAT_MAX;
  $minOranges = PHP_FLOAT_MAX;
  for ($i = 0; $i < $presentCount; $i++) {
    if ($presentCandies[$i] < $minCandies) $minCandies = $presentCandies[$i];
    if ($presentOranges[$i] < $minOranges) $minOranges = $presentOranges[$i];
  }

  $actionsCount = 0;
  for ($i = 0; $i < $presentCount;) {
    $candyDiff = $presentCandies[$i] - $minCandies;
    $orangeDiff = $presentOranges[$i] - $minOranges;

    $actions = 0;

    if ($candyDiff > 0 && $orangeDiff > 0) {
      $minDiff = $candyDiff > $orangeDiff ? $orangeDiff : $candyDiff;

      $presentCandies[$i] -= $minDiff;
      $presentOranges[$i] -= $minDiff;

      $actions += $minDiff;
    } else if ($candyDiff > 0) {
      $presentCandies[$i] -= $candyDiff;

      $actions += $candyDiff;
    } else if ($orangeDiff > 0) {
      $presentOranges[$i] -= $orangeDiff;

      $actions += $orangeDiff;
    } else {
      $i++;
      continue;
    }

    $actionsCount += $actions;
  }

  echo $actionsCount, "\n";
}

<?php

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

	$gifts = readline();
	$seqA = explode(' ', readline());
	$seqB = explode(' ', readline());

	$minA = min($seqA);
	$minB = min($seqB);

	$moves = 0;
	for($i = 0; $i < $gifts; $i++){
		if($minA < $seqA[$i] && $minB < $seqB[$i]){
			$diffA = $seqA[$i] - $minA;
			$diffB = $seqB[$i] - $minB;
			$max_double_decrements = min([$diffA, $diffB]);
			$moves+= $max_double_decrements;
			if($diffA > $diffB){
				$moves += $diffA - $max_double_decrements;
			}else{
				$moves += $diffB - $max_double_decrements;
			}
		}elseif($minA < $seqA[$i]){
			$moves+= $seqA[$i]- $minA;
		}elseif($minB < $seqB[$i]){
			$moves+= $seqB[$i]- $minB;
		}
	}
	$answers[]= $moves;

}
foreach($answers as $a) echo $a.PHP_EOL;

<?php

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

	$gifts = readline();
	$seqA = explode(' ', readline());
	$seqB = explode(' ', readline());

	$minA = min($seqA);
	$minB = min($seqB);

	$moves = 0;
	for($i = 0; $i < $gifts; $i++){
		if($minA < $seqA[$i] && $minB < $seqB[$i]){
			$diffA = $seqA[$i] - $minA;
			$diffB = $seqB[$i] - $minB;
			$max_double_decrements = min([$diffA, $diffB]);
			$moves+= $max_double_decrements;
			if($diffA > $diffB){
				$moves += $diffA - $max_double_decrements;
			}else{
				$moves += $diffB - $max_double_decrements;
			}
		}elseif($minA < $seqA[$i]){
			$moves+= $seqA[$i]- $minA;
		}elseif($minB < $seqB[$i]){
			$moves+= $seqB[$i]- $minB;
		}
	}

}
echo $moves;


Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res).Each item belongs to one class. In this problem we will only consider three of such classes: weapon, armor, orb.Besides, there's a whole new world hidden inside each item. We can increase an item's level travelling to its world. We can also capture the so-called residents in the Item WorldResidents are the creatures that live inside items. Each resident gives some bonus to the item in which it is currently located. We will only consider residents of types: gladiator (who improves the item's atk), sentry (who improves def) and physician (who improves res).Each item has the size parameter. The parameter limits the maximum number of residents that can live inside an item. We can move residents between items. Within one moment of time we can take some resident from an item and move it to some other item if it has a free place for a new resident. We cannot remove a resident from the items and leave outside — any of them should be inside of some item at any moment of time.Laharl has a certain number of items. He wants to move the residents between items so as to equip himself with weapon, armor and a defensive orb. The weapon's atk should be largest possible in the end. Among all equipping patterns containing weapon's maximum atk parameter we should choose the ones where the armor’s def parameter is the largest possible. Among all such equipment patterns we should choose the one where the defensive orb would have the largest possible res parameter. Values of the parameters def and res of weapon, atk and res of armor and atk and def of orb are indifferent for Laharl.Find the optimal equipment pattern Laharl can get.

The first line contains number n (3 ≤ n ≤ 100) — representing how many items Laharl has. Then follow n lines. Each line contains description of an item. The description has the following form: "name class atk def res size" — the item's name, class, basic attack, defense and resistance parameters and its size correspondingly.    name and class are strings and atk, def, res and size are integers.  name consists of lowercase Latin letters and its length can range from 1 to 10, inclusive.  class can be "weapon", "armor" or "orb".  0 ≤ atk, def, res ≤ 1000.  1 ≤ size ≤ 10.  It is guaranteed that Laharl has at least one item of each class. The next line contains an integer k (1 ≤ k ≤ 1000) — the number of residents. Then k lines follow. Each of them describes a resident. A resident description looks like: "name type bonus home" — the resident's name, his type, the number of points the resident adds to the item's corresponding parameter and the name of the item which currently contains the resident.    name, type and home are strings and bonus is an integer.  name consists of lowercase Latin letters and its length can range from 1 to 10, inclusive.  type may be "gladiator", "sentry" or "physician".  1 ≤ bonus ≤ 100.  It is guaranteed that the number of residents in each item does not exceed the item's size. The names of all items and residents are pairwise different. All words and numbers in the input are separated by single spaces.

Print on the first line the name of the weapon in the optimal equipping pattern; then print the number of residents the weapon contains; then print the residents' names. Print on the second and third lines in the same form the names of the armor and defensive orb as well as the residents they contain.  Use single spaces for separation. If there are several possible solutions, print any of them.

4
sword weapon 10 2 3 2
pagstarmor armor 0 15 3 1
iceorb orb 3 2 13 2
longbow weapon 9 1 2 1
5
mike gladiator 5 longbow
bobby sentry 6 pagstarmor
petr gladiator 7 iceorb
teddy physician 6 sword
blackjack sentry 8 sword

4
sword weapon 10 2 3 2
pagstarmor armor 0 15 3 1
iceorb orb 3 2 13 2
longbow weapon 9 1 2 1
6
mike gladiator 5 longbow
bobby sentry 6 pagstarmor
petr gladiator 7 iceorb
teddy physician 6 sword
blackjack sentry 8 sword
joe physician 6 iceorb

sword 2 petr mike
pagstarmor 1 blackjack
iceorb 2 teddy bobby

longbow 1 mike
pagstarmor 1 bobby
iceorb 2 petr joe

NoteIn the second sample we have no free space inside the items, therefore we cannot move the residents between them.


You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.The verse patterns for the given text is a sequence of n integers p1, p2, ..., pn. Text matches the given verse pattern if for each i from 1 to n one can divide words of the i-th line in syllables in such a way that the total number of syllables is equal to pi.You are given the text and the verse pattern. Check, if the given text matches the given verse pattern.

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of lines in the text. The second line contains integers p1, ..., pn (0 ≤ pi ≤ 100) — the verse pattern. Next n lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters.

If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).

4
13 11 15 15
to be or not to be that is the question
whether tis nobler in the mind to suffer
the slings and arrows of outrageous fortune
or to take arms against a sea of troubles

NoteIn the first sample, one can split words into syllables in the following way: in-telco-dech al-len-geSince the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one.

<?php
$n=trim(fgets(STDIN));
$p=explode(' ',trim(fgets(STDIN)));
$return='YES';
for($i=0;$i<$n;$i++){
	preg_match_all('/(i|e|a|o|u|y)/',trim(fgets(STDIN)),$a);
	if($p[$i]!=count($a[0])) $return='NO';
}
fwrite(STDOUT,$return);

<?php

###### IO ######
error_reporting(E_ALL);
error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	$stream = STDIN;
	if ($is_test)
		$stream = $f;
	/* begin body */
	$charFind = array('a' => true, 'e' => true, 'i' => true, 'o' => true, 'u' => true, 'y' => true);
	$strCount = readNum($stream, true);
	$rules = readStringExplodeNum($stream, ' ', true);
	$isFail = false;
	for ($i = 0; $i < $strCount; $i++) {
		$str = readString($stream);
		$words = explode(' ', $str);
		$slogCount = 0;
		foreach ($words as $word) {
			$wordLen = strlen($word);
			$wordSlogCount = 0;
			for ($k = 0; $k < $wordLen; $k++) {
				if (!empty($charFind[$word[$k]])) {
					$wordSlogCount++;
				}
			}
			$slogCount+=$wordSlogCount;
		}
		if ($slogCount != $rules[$i]) {
			echo 'NO';
			$isFail = true;
			break;
		}
	}
	if ($isFail === false) {
		echo 'YES';
	}
	/* / end body */
}

if (empty($is_test))
	getAnswer();


Toad Ivan has $$$m$$$ pairs of integers, each integer is between $$$1$$$ and $$$n$$$, inclusive. The pairs are $$$(a_1, b_1), (a_2, b_2), \ldots, (a_m, b_m)$$$. He asks you to check if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$.

The first line contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq m \leq 300\,000$$$) — the upper bound on the values of integers in the pairs, and the number of given pairs. The next $$$m$$$ lines contain two integers each, the $$$i$$$-th of them contains two space-separated integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n, a_i \neq b_i$$$) — the integers in the $$$i$$$-th pair.

Output "YES" if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$. Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first example, you can't choose any $$$x$$$, $$$y$$$ because for each such pair you can find a given pair where both numbers are different from chosen integers.In the second example, you can choose $$$x=2$$$ and $$$y=4$$$.In the third example, you can choose $$$x=1$$$ and $$$y=2$$$.

<?php
# 1169B
class Pairs {
    /** @var array $x */
    private $x;

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

    /** @var boolean */
    private $m;

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

    /**
     * @param int $a
     * @param int $b
     * @return bool
     */
    public function checkPair(int $a, int $b): bool {
        for ($i = 0; $i < $this->m; $i++) {
            if ($this->x[$i] === $a
                || $this->x[$i] === $b
                || $this->y[$i] === $a
                || $this->y[$i] === $b
            ) {
                continue;
            }
            if ($b === 0) {
                return $this->checkPair($a, $this->x[$i]) || $this->checkPair($a, $this->y[$i]);
            }
            return false;
        }
        return true;
    }
}

$stdin = STDIN;
[$n, $m] = fscanf($stdin, '%u %u');

$x = $y = [];
while ([$x_, $y_] = fscanf($stdin, '%u %u')) {
    $x[] = $x_;
    $y[] = $y_;
}
$pairs = new Pairs($x, $y, $m);
echo ($pairs->checkPair($x[0], 0) || $pairs->checkPair($y[0], 0)) ? 'YES' : 'NO';

<?php
# 1169B
$stdin = STDIN;
[$n, $m] = fscanf($stdin, '%u %u');
$unique = $pairs = [];
while ([$x, $y] = fscanf($stdin, '%u %u')) {
    $pairs[] = [min($x, $y), max($x, $y)];
    if (!isset($unique[$x])) {
        $unique[$x] = 0;
    }
    if (!isset($unique[$y])) {
        $unique[$y] = 0;
    }
    $unique[$x]++;
    $unique[$y]++;
}
$keys = [];
if (count($unique) === 2) {
    die ('YES');
}
arsort($unique);
foreach ($unique as $a => $item) {
    break;
}
$result = false;
foreach ($unique as $b => $amount) {
    if ($a === $b) {
        continue;
    }
    $fail = false;
    foreach ($pairs as $pair) {
        [$x, $y] = $pair;
        if ($a !== $x && $a !== $y && $b !== $x && $b !== $y) {
            $fail = true;
            break;
        }
    }
    if (!$fail) {
        $result = true;
        break;
    }
}
echo $result ? 'YES' : 'NO';

<?php
# 1169B
class Pairs {
    /** @var array $x */
    private $x;
    /** @var array $y */
    private $y;
    /** @var boolean */
    private $m;

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

    /**
     * @param int $a
     * @param int $b
     * @return bool
     */
    public function checkPair(int $a, int $b): bool {
        for ($i = 0; $i < $this->m; $i++) {
            if ($this->x[$i] === $a
                || $this->x[$i] === $b
                || $this->y[$i] === $a
                || $this->y[$i] === $b
            ) {
                continue;
            }
            if ($b === 0) {
                return $this->checkPair($a, $this->x[$i]) || $this->checkPair($a, $this->y[$i]);
            }
            return false;
        }
        return true;
    }
}

$stdin = STDIN;
[$n, $m] = fscanf($stdin, '%u %u');

$x = $y = [];
while ([$x_, $y_] = fscanf($stdin, '%u %u')) {
    $x[] = $x_;
    $y[] = $y_;
}
$pairs = new Pairs($x, $y, $m);
echo ($pairs->checkPair($x[0], 0) || $pairs->checkPair($y[0], 0)) ? 'YES' : 'NO';


Let $$$s(x)$$$ be sum of digits in decimal representation of positive integer $$$x$$$. Given two integers $$$n$$$ and $$$m$$$, find some positive integers $$$a$$$ and $$$b$$$ such that   $$$s(a) \ge n$$$,  $$$s(b) \ge n$$$,  $$$s(a + b) \le m$$$.

The only line of input contain two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1129$$$).

Print two lines, one for decimal representation of $$$a$$$ and one for decimal representation of $$$b$$$. Both numbers must not contain leading zeros and must have length no more than $$$2230$$$.

NoteIn the first sample, we have $$$n = 6$$$ and $$$m = 5$$$. One valid solution is $$$a = 6$$$, $$$b = 7$$$. Indeed, we have $$$s(a) = 6 \ge n$$$ and $$$s(b) = 7 \ge n$$$, and also $$$s(a + b) = s(13) = 4 \le m$$$.


Anu has created her own function $$$f$$$: $$$f(x, y) = (x | y) - y$$$ where $$$|$$$ denotes the bitwise OR operation. For example, $$$f(11, 6) = (11|6) - 6 = 15 - 6 = 9$$$. It can be proved that for any nonnegative numbers $$$x$$$ and $$$y$$$ value of $$$f(x, y)$$$ is also nonnegative. She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems.A value of an array $$$[a_1, a_2, \dots, a_n]$$$ is defined as $$$f(f(\dots f(f(a_1, a_2), a_3), \dots a_{n-1}), a_n)$$$ (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible?

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). Elements of the array are not guaranteed to be different.

Output $$$n$$$ integers, the reordering of the array with maximum value. If there are multiple answers, print any.

<?php

namespace io {
	$input_file_content = file_get_contents("php://stdin");
	$input_buf = explode("\n", $input_file_content);
	unset($input_file_content);
}

namespace main {
	error_reporting(E_ALL);
	ini_set('display_errors', true);
	ini_set('html_errors', false);

	use function io\next_line as next_line;
	use function io\next_ as next;
	use function io\next_int as next_int;
	use function io\next_double as next_double;

	$n = next_int();
	for($i=0; $i<$n; $i++) {
		$a[] = next_int();
	}

	$front[] = $a[0];
	$back[$n-1] = $a[$n-1];
	for($i=1; $i<$n; $i++) {
		$front[] = $front[$i-1] | $a[$i];
		$back[$n-$i-1] = $back[$n-$i] | $a[$n-$i-1];
	}

	$ans = -1;
	$idx = -1;
	for($i=0; $i<$n; $i++) {
		$l = ($i > 0) ? $front[$i-1] : 0;
		$r = ($i < $n-1) ? $back[$i+1] : 0;
		$y = ($l | $r);
		$temp = ($a[$i] | $y) - $y;
		if($temp > $ans) {
			$ans = $temp;
			$idx = $i;
		}
	}

	$first = $a[$idx];
	unset($a[$idx]);

	printf("%d %s\n", $first, implode(" ", $a));
}

namespace io {
	function next_line() {
		static $cnt = 0;
		global $input_buf;
		// while($input_buf[$cnt] == "") $cnt++;
		return $input_buf[$cnt++];
		// return trim($input_buf[$cnt++]);
	}
	function next_() {
		static $tk = [];
		static $tk_cnt = 0;
		if($tk_cnt == count($tk)) {
			$tk = explode(" ", next_line());
			$tk_cnt = 0;
		}
		return $tk[$tk_cnt++];
	}
	function next_int() {
		return (int)next_();
	}
	function next_double() {
		return (double)next_();
	}
}

?>


Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

Print one integer — the number of times Kolya will have to empty the waste section.

NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.

<?php

//=====================================
// link: http://codeforces.com/contest/709/problem/A
//=====================================

// get inputs
list($n_oranges, $max_size, $waste_size) = explode(' ', trim(fgets(STDIN)));
$oranges                                 = explode(' ', trim(fgets(STDIN)));

// solution
$collect_waste = 0;
$empty_wastes  = 0;

foreach ($oranges as $key => $orange) {
    if ($orange > $max_size) {
        continue;
    }

    $collect_waste += $orange;

    if ($collect_waste > $waste_size) {
        $empty_wastes++;
        $collect_waste = 0;
    }
}

echo "$empty_wastes\n";

<?php

###### IO ######
error_reporting(E_ALL);
#error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	list(, $b, $d) = readStringExplodeNum($f, ' ', true);
	$sizes = readStringExplodeNum($f, ' ', true);
	$poll = 0;
	$answer = 0;
	foreach ($sizes as $a) {
		if ($a > $b) {
			continue;
		}
		$poll+=$a;
		if ($poll > $d) {
			$poll = 0;
			$answer++;
		}
	}
	echo $answer;
	/* / end body */
}

if (empty($is_test))
	getAnswer();

<?php
list($num, $size, $waste)=explode(" ", trim(fgets(STDIN)));
$unit=explode(" ", trim(fgets(STDIN)));
for ($i=0; $i < $num; $i++) {
    if ($unit[$i] > $size) {
        $unit[$i] = 0;
    }
   }
$u=0;
foreach ($unit as $val) {
    $runningSum += $val;
    if ($runningSum > $waste) {
        $runningSum =0;
        $u++;
    }
}
echo $u;
?>

<?php

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

fscanf($stdin, "%d %d %d" , $n , $b , $d ) ;

$count = 0 ;
$waste = 0 ;

fscanf($stdin , "%[^\n]" , $test );
$arr = array_map( 'intval' , preg_split( "/ /" , $test , -1 , PREG_SPLIT_NO_EMPTY ) );

for( $i=0 ; $i<$n ; $i++ )
{
     if( $arr[$i] <= $b )
     {
          if( $arr[$i] + $waste > $d )
          {
               $count++ ;
               $waste = 0 ;
          }
          else
          {
               $waste += $arr[$i] ;
          }
     }
}
echo $count ;

fwrite($stdout);

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

?>

<?php

$stdin = fopen('php://stdin', 'r');
list($n,$b,$d)=sscanf(fgets($stdin),"%d %d %d");
$astr=fgets($stdin);
$arr = explode(" ",$astr);
$v=0;
$v_count=0;
for($i=0;$i<$n;$i++)
{
    if ($arr[$i]<=$b)
        $v+=$arr[$i];
    if ($v>$d)
    {
        $v_count+=1;
        $v=0;
//        $v=$v%$d;
    }
}
echo $v_count;
?>

<?php

class Solution
{
    protected function solve($p, $b, $d)
    {
        $count = $sum = 0;
        foreach ($p as $w) {
            if ($w > $b) {
                continue;
            }

            $sum += $w;

            if ($sum > $d) {
                $sum = 0;
                $count++;
                continue;
            }
        }

        return $count;
    }

    public function run()
    {
        fscanf(STDIN, '%d %d %d', $n, $b, $d);
        $p = explode(' ', trim(fgets(STDIN)));

        echo $this->solve($p, $b, $d) . PHP_EOL;
    }
}

$sol = new Solution();
$sol->run();

<?php

class Solution
{
    public function solve()
    {
        fscanf(STDIN, '%d %d %d', $n, $b, $d);
        $arr = explode(' ', trim(fgets(STDIN)));

        $sum = 0;
        $count = 0;
        foreach ($arr as $w) {
            $w = (int) $w;

            if ($w > $b) {
                continue;
            }

            $sum += $w;

            if ($sum > $d) {
                while ($sum > $d) {
                    $count++;
                    $sum = 0;
                    continue;
                }
            }
        }

        if ($sum > $d) {
            $count++;
        }

        echo $count . PHP_EOL;
    }
}

$sol = new Solution();
$sol->solve();

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

for($i=0;$i<$n;$i++){
	if($oranges[$i]<=$max_orange_size){
		$current_level+=$oranges[$i];
	}
	if($current_level>$container_volume){
		$oporodj+=1;
		//$current_level-=$container_volume;
		$current_level=0;

	}
}

echo $oporodj;

?>

<?php
      $t = array();
      list($n, $x, $y) = explode(' ', trim(fgets(STDIN)));
      $t = explode(' ', trim(fgets(STDIN)));
      $ans = 0;
      $s = 0;
      for($i = 0; $i < $n; $i ++)
      {
          if($t[$i] > $x)
            continue;
          $s += $t[$i];
          if($s > $y)
          {
              $ans ++;
              $s = 0;
          }
      }
      echo $ans;
?>

<?php

//=====================================
// link: http://codeforces.com/contest/709/problem/A
//=====================================

// get inputs
list($n_oranges, $max_size, $waste_size) = explode(' ', trim(fgets(STDIN)));
$oranges                                 = explode(' ', trim(fgets(STDIN)));

// solution
$collect_waste = 0;
$empty_wastes  = 0;

foreach ($oranges as $key => $orange) {
    if ($orange > $max_size) {
        continue;
    }

    $collect_waste += $orange;

    if ($collect_waste > $waste_size) {
        $empty_wastes++;
        $waste_size += $waste_size;
    }
}

echo "$empty_wastes\n";

<?php

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

fscanf($stdin, "%d %d %d" , $n , $b , $d ) ;

$count = 0 ;
$waste = 0 ;

fscanf($stdin , "%[^\n]" , $test );
$arr = array_map( 'intval' , preg_split( "/ /" , $test , -1 , PREG_SPLIT_NO_EMPTY ) );

for( $i=0 ; $i<$n ; $i++ )
{
     if( $arr[$i] <= $b )
     {
          if( $arr[$i] + $waste > $d )
          {
               $count++ ;
               $waste = $arr[$i] ;
          }
          else
          {
               $waste += $arr[$i] ;
          }
     }
}
echo $count ;

fwrite($stdout);

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

?>

<?php

$stdin = fopen('php://stdin', 'r');
list($n,$b,$d)=sscanf(fgets($stdin),"%d %d %d");
$astr=fgets($stdin);
$arr = explode(" ",$astr);
$v=0;
$v_count=0;
for($i=0;$i<$n;$i++)
{
    if ($arr[$i]<$b)
        $v+=$arr[$i];
    if ($v>=$d)
    {
        $v_count=(int)($v/$d);
        $v=$v%$d;
    }
}
echo $v_count;
?>

<?php

$stdin = fopen('php://stdin', 'r');
list($n,$b,$d)=sscanf(fgets($stdin),"%d %d %d");
$astr=fgets($stdin);
$arr = explode(" ",$astr);
$v=0;
$v_count=0;
for($i=0;$i<$n;$i++)
{
    if ($arr[$i]<$b)
        $v+=$arr[$i];
    if ($v>$d)
    {
        $v_count+=1;
        $v=0;
//        $v=$v%$d;
    }
}
echo $v_count;
?>

<?php

$stdin = fopen('php://stdin', 'r');
list($n,$b,$d)=sscanf(fgets($stdin),"%d %d %d");
$astr=fgets($stdin);
$arr = explode(" ",$astr);
$v=0;
$v_count=0;
for($i=0;$i<$n;$i++)
{
    if ($arr[$i]<$b)
        $v+=$arr[$i];
    if ($v>$d)
    {
        $v_count=(int)($v/$d);
        $v=0;
//        $v=$v%$d;
    }
}
echo $v_count;
?>

<?php

class Solution
{
    public function solve()
    {
        fscanf(STDIN, '%d %d %d', $n, $b, $d);
        $arr = explode(' ', trim(fgets(STDIN)));

        $sum = 0;
        $count = 0;
        foreach ($arr as $w) {
            $w = (int) $w;

            if ($w > $b) {
                continue;
            }

            if ($sum > $d) {
                $count++;
                $sum = 0;
                continue;
            }

            $sum += $w;
        }

        if ($sum > $d) {
            $count++;
        }

        echo $count . PHP_EOL;
    }
}

$sol = new Solution();
$sol->solve();

<?php

class Solution
{
    public function solve()
    {
        fscanf(STDIN, '%d %d %d', $n, $b, $d);
        $arr = explode(' ', trim(fgets(STDIN)));

        $sum = 0;
        $count = 0;
        foreach ($arr as $w) {
            $w = (int) $w;

            if ($w > $b) {
                continue;
            }

            if ($sum > $d) {
                $count++;
                $sum %= $d;
                continue;
            }

            $sum += $w;
        }

        if ($sum > $d) {
            $count++;
        }

        echo $count . PHP_EOL;
    }
}

$sol = new Solution();
$sol->solve();

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

for($i=0;$i<$n;$i++){
	if($oranges[$i]<$max_orange_size){
		$current_level+=$oranges[$i];
	}
	if($current_level>$container_volume){
		$oporodj+=1;
		//$current_level-=$container_volume;
		$current_level=0;

	}
}

echo $oporodj;

<?
$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

for($i=0;$i<$n;$i++){
	if($oranges[$i]<$max_orange_size){
		$current_level+=$oranges[$i];
	}
	if($current_level>$container_volume){
		$oporodj+=1;
		$current_level-=$container_volume;
	}
}

echo $oporodj;

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

for($i=0;$i<$n;$i++){
	if($oranges[$i]<$max_orange_size){
		$current_level+=$oranges[$i];
	}else{
		continue;
	}
	while($current_level>$container_volume){
		$oporodj+=1;
		$current_level-=$container_volume;
	}
}

echo $oporodj;

?>

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

for($i=0;$i<$n;$i++){
	if($oranges[$i]<$max_orange_size){
		$current_level+=$oranges[$i];
	}
	while($current_level>$container_volume){
		$oporodj+=1;
		$current_level-=$container_volume;
	}
}

echo $oporodj;

?>

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

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

	if($oranges[$i]<=$max_orange_size){

		$current_level+=$oranges[$i];

		while($current_level>$container_volume){
			$oporodj+=1;
			$current_level-=$container_volume;
		}
	}
}

echo $oporodj;

?>

<?php
      $t = array();
      list($n, $x, $y) = explode(' ', trim(fgets(STDIN)));
      $t = explode(' ', trim(fgets(STDIN)));
      $ans = 0;
      $s = 0;
      for($i = 0; $i < $n; $i ++)
      {
          $s += $t[$i] % $x;
          if($s > $y)
          {
              $ans ++;
              $s = 0;
          }
      }
      echo $ans;
?>


You are living on an infinite plane with the Cartesian coordinate system on it. In one move you can go to any of the four adjacent points (left, right, up, down).More formally, if you are standing at the point $$$(x, y)$$$, you can:   go left, and move to $$$(x - 1, y)$$$, or  go right, and move to $$$(x + 1, y)$$$, or  go up, and move to $$$(x, y + 1)$$$, or  go down, and move to $$$(x, y - 1)$$$. There are $$$n$$$ boxes on this plane. The $$$i$$$-th box has coordinates $$$(x_i,y_i)$$$. It is guaranteed that the boxes are either on the $$$x$$$-axis or the $$$y$$$-axis. That is, either $$$x_i=0$$$ or $$$y_i=0$$$.You can collect a box if you and the box are at the same point. Find the minimum number of moves you have to perform to collect all of these boxes if you have to start and finish at the point $$$(0,0)$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of boxes. The $$$i$$$-th line of the following $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-100 \le x_i, y_i \le 100$$$) — the coordinate of the $$$i$$$-th box. It is guaranteed that either $$$x_i=0$$$ or $$$y_i=0$$$. Do note that the sum of $$$n$$$ over all test cases is not bounded.

For each test case output a single integer — the minimum number of moves required.

NoteIn the first test case, a possible sequence of moves that uses the minimum number of moves required is shown below.  $$$$$$(0,0) \to (1,0) \to (1,1) \to (1, 2) \to (0,2) \to (-1,2) \to (-1,1) \to (-1,0) \to (-1,-1) \to (-1,-2) \to (0,-2) \to (0,-1) \to (0,0)$$$$$$ In the second test case, a possible sequence of moves that uses the minimum number of moves required is shown below.  $$$$$$(0,0) \to (0,1) \to (0,2) \to (-1, 2) \to (-2,2) \to (-3,2) \to (-3,1) \to (-3,0) \to (-3,-1) \to (-2,-1) \to (-1,-1) \to (0,-1) \to (0,0)$$$$$$ In the third test case, we can collect all boxes without making any moves.

<?php

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

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

    $minX = 0;
    $maxX = 0;
    $minY = 0;
    $maxY = 0;

    for ($i = 0; $i < $n; ++$i) {
        fscanf(STDIN, '%d %d', $x, $y);

        $minX = min($minX, $x);
        $maxX = max($maxX, $x);
        $minY = min($minY, $y);
        $maxY = max($maxY, $y);
    }

    $res = 2 * ($maxX + $maxY - $minX - $minY);

    echo $res.PHP_EOL;
}

<?php
function read() {
  return trim(fgets($GLOBALS['file'])) ;
}
function readInt() {
  return (int) read() ;
}
function readStrs() {
  return explode(" ",read()) ;
}
function readIntArray() {
  return array_map('intval', readStrs());
}
function readAsArray() {
  return str_split(read()) ;
}
function puts($arg) {
  if($arg === true) print_r("true");
  elseif($arg === false) print_r("false");
  else {
    print_r($arg) ;
  }
  print_r("\n") ;
}
$file = (file_exists("input.txt")) ? fopen("input.txt","r") : STDIN ;

//-----------------------------------//

$t = readInt() ;
while($t--) {
    $l = readInt() ;
    $ny = $py = $nx = $px = 0 ;
    for($i=0;$i<$l;$i++) {
        [$a,$b] = readIntArray() ;
        if($a == 0) {
            if($b < 0) {
                $ny = max($ny,-$b);
            }
            else {
                $py = max($py,$b);
            }
        }
        else{
            if($a < 0) {
                $nx = max($nx,-$a);
            }
            else {
                $px = max($px,$a);
            }
        }
    }
    puts(array_sum([$px*2,$py*2,$nx*2,$ny*2]));
}

<?php $t = (int)readline();
for ($T = 0; $T < $t; $T++) {
    $n = (int)readline();
    $ymx = 0;
    $ymn = 0;
    $xmx = 0;
    $xmn = 0;
    for ($i = 0; $i < $n; $i++) {
        $point = explode(" ", readline());
        $curx = (int)$point[0];
        $cury = (int)$point[1];
        if ($curx == 0) {
            $ymn = min($ymn, $cury);
            $ymx = max($ymx, $cury);
        } else {
            $xmn = min($xmn, $curx);
            $xmx = max($xmx, $curx);
        }
    }
    echo 2 * ($ymx - $ymn + $xmx - $xmn);
    echo "\n";
} ?>


You are given two integers $$$n$$$ and $$$m$$$ ($$$m < n$$$). Consider a convex regular polygon of $$$n$$$ vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length).  Examples of convex regular polygons Your task is to say if it is possible to build another convex regular polygon with $$$m$$$ vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon.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. The next $$$t$$$ lines describe test cases. Each test case is given as two space-separated integers $$$n$$$ and $$$m$$$ ($$$3 \le m < n \le 100$$$) — the number of vertices in the initial polygon and the number of vertices in the polygon you want to build.

For each test case, print the answer — "YES" (without quotes), if it is possible to build another convex regular polygon with $$$m$$$ vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon and "NO" otherwise.

Note  The first test case of the example It can be shown that the answer for the second test case of the example is "NO".

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

<?php
	$t = trim(fgets(STDIN));
	$ans = "";
	for ($o = 0; $o < $t; $o++) {
		$data = explode(" ", trim(fgets(STDIN)));
		$n = $data[0];
		$m = $data[1];
		if ($n % $m == 0)
			$ans .= "YES\n";
		else
			$ans .= "NO\n";
	}
	print $ans;
?>


Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.Before assembling the zebra Grisha can make the following operation $$$0$$$ or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".Determine the maximum possible length of the zebra that Grisha can produce.

The only line contains a string $$$s$$$ ($$$1 \le |s| \le 10^5$$$, where $$$|s|$$$ denotes the length of the string $$$s$$$) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.

Print a single integer — the maximum possible zebra length.

NoteIn the first example one of the possible sequence of operations is bwwwbww|bw $$$\to$$$ w|wbwwwbwb $$$\to$$$ wbwbwwwbw, that gives the answer equal to $$$5$$$.In the second example no operation can increase the answer.


You are given one integer number $$$n$$$. Find three distinct integers $$$a, b, c$$$ such that $$$2 \le a, b, c$$$ and $$$a \cdot b \cdot c = n$$$ or say that it is impossible to do it.If there are several answers, you can print any.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$n$$$ lines describe test cases. The $$$i$$$-th test case is given on a new line as one integer $$$n$$$ ($$$2 \le n \le 10^9$$$).

For each test case, print the answer on it. Print "NO" if it is impossible to represent $$$n$$$ as $$$a \cdot b \cdot c$$$ for some distinct integers $$$a, b, c$$$ such that $$$2 \le a, b, c$$$. Otherwise, print "YES" and any possible such representation.

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

for ($i = 0; $i < $t; $i++) {
    $n = trim(fgets((STDIN)));
    $status = false;
    for ($a = 2; $a <= (intval(sqrt($n))+1); $a++) {
        if (bcmod($n, $a) == 0) {
            $k = bcdiv($n, $a);
            for ($b = 2; $b <= (intval(sqrt($k))+1); $b++) {
                if ($a != $b && bcmod ($k ,$b) == 0) {
                    $c = bcdiv($k, $b);
                    if ($a != $c && $b != $c){
                        echo "YES\n";
                        echo $a. " ".$b. " ".$c."\n";
                        $status = true;
                        break;
                    }
                }
            }
        }

        if ($status) {
            break;
        }
    }
    if (!$status) {
        echo "NO\n";
    }

}

?>


PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?

The first input line contains two integers n and m (1 ≤ n, m ≤ 103) — number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per line — words familiar to PolandBall. Then m strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.

In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.

2 2
kremowka
wadowicka
kremowka
wiedenska

NoteIn the first example PolandBall knows much more words and wins effortlessly.In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.

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

    // define('DEBUG', true);
    define('DEBUG', false);

    $arrA = array();
    $arrB = array();
    for ($i = 0; $i < $a; $i++) {
        fscanf(STDIN, "%s", $aa);
        $arrA[$aa] = 1;
    }
    for ($i = 0; $i < $b; $i++) {
        fscanf(STDIN, "%s", $aa);
        $arrB[$aa] = 1;
    }
    if (DEBUG) var_dump($arrA);
    if (DEBUG) var_dump($arrB);

    foreach ($arrA as $k => $v) {
        if (isset($arrB[$k])) {
            $cntA++;
        }
    }
    foreach ($arrB as $k => $v) {
        if (isset($arrA[$k])) {
            $cntB++;
        }
    }

    $uniA = $a - $cntA;
    $uniB = $b - $cntB;

    for ($i = 0; $i < 100000; $i++) {
        switch ($i % 2) {
            case 0:
                if ($cntA > 0) {
                    $cntA--;
                    $cntB--;
                    if ($uniB < 0) {
                        exit('YES');
                    }
                } else {
                    $uniA--;
                    if ($uniA < 0) {
                        exit('NO');
                    }
                }
                break;

            case 1:
                if ($cntB > 0) {
                    $cntA--;
                    $cntB--;
                    if ($cntA < 0) {
                        exit('NO');
                    }
                } else {
                    $uniB--;
                    if ($uniB < 0) {
                        exit('YES');
                    }
                }
                break;
        }
        if (DEBUG) echo "A:{$uniA}-{$cntA}\n";
        if (DEBUG) echo "B:{$uniB}-{$cntB}\n";
        if (DEBUG) echo "-------\n";
    }

<?php

function readVocab($n)
{
    $result = [];
    foreach (range(1, $n) as $i) {
        $result[] = fgets(STDIN);
    }
    return $result;
}

$vocabLength = explode(' ', fgets(STDIN));
$p           = readVocab((int)$vocabLength[0]);
$w           = readVocab((int)$vocabLength[1]);

$shared = array_values(array_intersect($p, $w));
$uniqp = array_values(array_diff($p, $w));
$uniqw = array_values(array_diff($w, $p));
$even = count($shared) % 2 == 0;

//var_dump($uniqp);
//var_dump($uniqw);
//var_dump($shared);

if (count($uniqp) > count($uniqw)) {
    echo 'YES';
} else if (count($uniqp) == count($uniqw) && !$even) {
    echo 'YES';
} else {
    echo 'NO';
}

//echo (count($uniqp) > count($uniqw) && (count($shared) % 2 == 0))  ? 'YES' : 'NO';

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

    $arrA = array();
    $arrB = array();
    for ($i = 0; $i < $a; $i++) {
        fscanf(STDIN, "%s", $aa);
        $arrA[$aa] = 1;
    }
    for ($i = 0; $i < $b; $i++) {
        fscanf(STDIN, "%s", $aa);
        $arrB[$aa] = 1;
    }
    // var_dump($arrA);
    // var_dump($arrB);

    foreach ($arrA as $k => $v) {
        if (isset($arrB[$k])) {
            $cntA++;
        }
    }
    foreach ($arrB as $k => $v) {
        if (isset($arrA[$k])) {
            $cntB++;
        }
    }

    $uniA = $a - $cntA;
    $uniB = $b - $cntB;

    for ($i = 0; $i < 100000; $i++) {
        switch ($i % 2) {
            case 0:
                if ($uniA > 0) {
                    $uniA--;
                    $uniB--;
                    if ($uniB < 0) {
                        exit('YES');
                    }
                } else {
                    $cntA--;
                    if ($cntA < 0) {
                        exit('NO');
                    }
                }
                break;

            case 1:
                if ($uniB > 0) {
                    $uniA--;
                    $uniB--;
                    if ($uniA < 0) {
                        exit('NO');
                    }
                } else {
                    $cntB--;
                    if ($cntB < 0) {
                        exit('YES');
                    }
                }
                break;
        }
        // echo "A:{$uniA} {$cntA}\n";
        // echo "B:{$uniB} {$cntB}\n";
        // echo "-------\n";
    }

<?php

function readVocab($n)
{
    $result = [];
    foreach (range(1, $n) as $i) {
        $result[] = fgets(STDIN);
    }
    return $result;
}

$vocabLength = explode(' ', fgets(STDIN));
$p           = readVocab((int)$vocabLength[0]);
$w           = readVocab((int)$vocabLength[1]);

$shared = array_intersect($p, $w);
$uniqp = array_diff($p, $w);
$uniqw = array_diff($w, $p);
echo (count($uniqp) >= count($uniqw) || (count($shared) % 2 == 0))  ? 'YES' : 'NO';

<?php

function readVocab($n)
{
    $result = [];
    foreach (range(1, $n) as $i) {
        $result[] = fgets(STDIN);
    }
    return $result;
}

$vocabLength = explode(' ', fgets(STDIN));
$p           = readVocab((int)$vocabLength[0]);
$w           = readVocab((int)$vocabLength[1]);

$uniqp = array_diff($p, $w);
$uniqw = array_diff($w, $p);

echo count($uniqp) >= count($uniqw) ? 'YES' : 'NO';

<?php

function readVocab($n)
{
    $result = [];
    foreach (range(1, $n) as $i) {
        $result[] = fgets(STDIN);
    }
    return $result;
}

$vocabLength = explode(' ', fgets(STDIN));
$p           = readVocab((int)$vocabLength[0]);
$w           = readVocab((int)$vocabLength[1]);

$shared = array_intersect($p, $w);
$uniqp = array_diff($p, $w);
$uniqw = array_diff($w, $p);
echo (count($uniqp) > count($uniqw) || (count($shared) % 2 == 0))  ? 'YES' : 'NO';