Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.

The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.

On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.

NoteIn the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.

<?php

//=====================================
// link: https://codeforces.com/contest/381/problem/A
//=====================================

// get inputs
$number_of_cards = trim(fgets(STDIN));
$cards           = explode(' ', trim(fgets(STDIN)));

// solution
$sereja = 0;
$dima   = 0;
$first  = 0;
$last   = $number_of_cards - 1;

for ($i=0; $i < $number_of_cards; $i++) {
    if ($cards[$first] >= $cards[$last]) {
        ($i % 2) ? $dima += $cards[$first] : $sereja += $cards[$first];
        $first++;
        continue;
    }

    ($i % 2) ? $dima += $cards[$last] : $sereja += $cards[$last];
    $last--;
}

echo "$sereja $dima\n";

<?php

//=====================================
// link: https://codeforces.com/contest/381/problem/A
//=====================================

// get inputs
$number_of_cards = trim(fgets(STDIN));
$cards           = explode(' ', trim(fgets(STDIN)));

// solution
$sereja = 0;
$dima   = 0;
$first  = 0;
$last   = $number_of_cards - 1;
$count  = 0;

for ($i=0; $i < $number_of_cards; $i++) {
    if ($first == $last) {
        ($count % 2) ? $dima += $cards[$first] : $sereja += $cards[$first];
        break;
    }

    if ($cards[$first] > $cards[$last]) {
        ($count % 2) ? $dima += $cards[$first] : $sereja += $cards[$first];
        $first++;
        $count++;
        continue;
    }

    ($count % 2) ? $dima += $cards[$last] : $sereja += $cards[$last];
    $last--;
    $count++;
}

echo "$sereja $dima\n";

<?php

//=====================================
// link: https://codeforces.com/contest/381/problem/A
//=====================================

// get inputs
$number_of_cards = trim(fgets(STDIN));
$cards = explode(' ', trim(fgets(STDIN)));

// solution
$sereja = 0; $dima = 0; $count=0;

while (!empty($cards)) {
    $first_card = $cards[0];
    $last_card = end($cards);
    $arr_count = count($cards);

    if($arr_count == 1) {
        ($count % 2) ? $dima += $first_card : $sereja += $first_card;
        break;
    }

    if($first_card > $last_card) {
        ($count % 2) ? $dima += $first_card : $sereja += $first_card;
        unset($cards[0]);
        $cards = array_values($cards);
        $count++;
        continue;
    }

    ($count % 2) ? $dima += $last_card : $sereja += $last_card;
    unset($cards[$arr_count-1]);
    $cards = array_values($cards);
    $count++;
}

echo "$sereja $dima\n";

<?php
$in=fgets(STDIN);
$str=fgets(STDIN);
$arr=explode(" ", $str);

$flag=true;
$a=0;$b=0;
$l=0;$r=intval($in)-1;
foreach ($arr as &$va) {
$va=intval($va);
}
while($l<=$r){
	if($arr[$l]>$arr[$r]){
		if($flag){
			$a+=$arr[$l];
			$l++;
			$flag=!$flag;
		}else{
			$b+=$arr[$l];
			$l++;
			$flag=!$flag;
		}
	}else{
		if($flag){
			$a+=$arr[$r];
			$r--;
			$flag=!$flag;
		}else{
			$b+=$arr[$r];
			$r--;
			$flag=!$flag;
		}
	}
}
echo $a." ".$b;
?>

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

    $i = 0;
    $nach = 0;
    $kon  = 0;
    $one  = 0;
    $two  = 0;

    while($i != $n){

        if ($nums[0+$nach] > $nums[$n-1-$kon]){
            if ($igrok == 0){
                $one += $nums[0+$nach];
                $igrok = 1;
            }else{
                $two += $nums[0+$nach];
                $igrok = 0;
            }
            $nach++;
            $i++;
            continue;
        }

        if ($nums[0+$nach] < $nums[$n-1-$kon]){
            if ($igrok == 0){
                $one += $nums[$n-1-$kon];
                $igrok = 1;
            }else{
                $two += $nums[$n-1-$kon];
                $igrok = 0;
            }
            $kon++;
            $i++;
            continue;
        }

        if ($nums[0+$nach] == $nums[$n-1-$kon]){
            if ($igrok == 0){
                $one += $nums[$n-1-$kon];
                $igrok = 1;
            }else{
                $two += $nums[$n-1-$kon];
                $igrok = 0;
            }
            $kon++;
            $i++;
            continue;
        }
    }

    fwrite(STDOUT, $one." ".$two);
?>

<?php

$in = 'php://stdin';
$input = fopen($in, "r");
$n = fgets($input);
$arr = explode(" ", trim(fgets($input)));

function test($arr){
    $Sereja = 0;
    $Dima = 0;
    $turnSereja = true;
    while(count($arr) > 0){
        $temp = count($arr);

        if($arr[0] > $arr[$temp - 1] ){
            $numberChoose = $arr[0];
            array_splice($arr,0,1);
            //Remove first
        }
        else{
            $numberChoose = $arr[$temp - 1];
            array_splice($arr,$temp - 1,1);
        }
        if($turnSereja){
            $Sereja += $numberChoose;
        }
        else{
            $Dima += $numberChoose;
        }
        $turnSereja = !$turnSereja;
    }
    echo $Sereja." ".$Dima;
}

test($arr);

<?php

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

$groups = 0 ;
$temp = "" ;

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

$arr = array_map( 'intval' , preg_split('/ /' , $line, -1 , PREG_SPLIT_NO_EMPTY ) );

$sereja = 0 ;
$dima = 0 ;
$start = 0 ;
$end = count($arr) - 1 ;
$done = 1 ;

while( $end >= $start )
{
     if( $arr[ $start ] >= $arr[ $end ] )
     {
          if( $done == 1 )
          {
               $sereja = intval($sereja) + intval($arr[ $start ] ) ;
               $done = 2 ;
          }
          else
          {
               $dima = intval($dima) + intval($arr[ $start ] ) ;
               $done = 1 ;
          }
          $start++ ;
     }
     else
     {
          if( $done == 1 )
          {
               $sereja = intval($sereja) + intval($arr[ $end ] ) ;
               $done = 2 ;
          }
          else
          {
               $dima = intval($dima) + intval($arr[ $end ] ) ;
               $done = 1 ;

          }
          $end-- ;
     }
}

echo $sereja . " " . $dima ;

fwrite($stdout);

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

?>

<?php

$n = rtrim(fgets(STDIN));
$cards = explode(" ", rtrim(fgets(STDIN)));
$S = 0;
$D = 0;
$r = sizeof($cards)-1;
$l = 0;
$next='S';

for($i=0; $i<sizeof($cards); $i++)
{
    if($next == 'S'){
        $S += max($cards[$l], $cards[$r]);
        $next='D';
    }else{
        $D += max($cards[$l], $cards[$r]);
        $next='S';
    }
    if($cards[$r]>$cards[$l]){
        $r--;
    }else{
        $l++;
    }
}
echo ($S .' '.$D);

<?php

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

$n = (int) trim(fgets($input));

$arr = explode(" ", trim(fgets($input)));

$s = 0;
$d = 0;

$left = 0;
$right = $n - 1;
$turn = 0;

while ($left <= $right) {

    $max = 0;

    if ($arr[$right] > $arr[$left]) {

        $max = $arr[$right];
        $right--;
    } else {

        $max = $arr[$left];
        $left++;
    }

    if ($turn % 2 == 0) {
        $s += $max;
    } else {
        $d += $max;
    }

    $turn++;
}

echo $s, ' ', $d;

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

	$n = intval(fgets($temp));

	$test = explode(" ", fgets($temp));

	for ($i=0; $i < $n ; $i++) {
		$arr[$i] = intval($test[$i]);
	}

	$seja=0;
	$dima=0;

	$turns=true;

	while(count($arr) > 1)
	{
		if($arr[0] > $arr[count($arr)-1])
		{
			$t = array_reverse($arr);
			$element = array_pop($t);
			$arr = $t;
			$arr = array_reverse($arr);
		}
		else if($arr[0] < $arr[count($arr)-1])
		{
			$element = array_pop($arr);
		}

		if($turns)
			$seja += $element;
		else
			$dima += $element;

		$turns = !$turns;
	}

	if( $n % 2 == 0 )
		$dima += $arr[0];
	else
		$seja += $arr[0];

	echo $seja . " " . $dima;

?>

<?php

$n = (int)getline();
$a = explode(' ', getline());

$sum = array(0, 0);
$n = min($n, count($a));

$lower = 0;
$upper = $n - 1;

for ($i = 0; $i < $n; $i ++) {
  if ($a[$lower] < $a[$upper]) {
    $sum[$i%2] += (int)$a[$upper --];
  } else {
    $sum[$i%2] += (int)$a[$lower ++];
  }
}

print $sum[0] . ' ' . $sum[1];

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

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

$ser = 0;
$dim = 0;

# MAIN CODE

$a = $dxs->G();
for($i=0;$i<$a;$i++){
$b[]=$dxs->G();
}

for($z=0;$z<$a;$z++){
$ca = count($b);
$max = max($b[0],$b[$ca-1]);

#echo "$z | max(".$b[0]."".$b[$ca].") res = $max";

if($b[0]==$max){
unset($b[0]);$b=array_values($b);}
if($b[$ca-1]==$max){
unset($b[$ca-1]);$b=array_values($b);}

if($z%2===0){
$ser = $ser+$max;
}else{
$dim = $dim+$max;
}

}

# PRINT OUTPUT

echo "$ser $dim";
?>

<?php

//=====================================
// link: https://codeforces.com/contest/381/problem/A
//=====================================

// get inputs
$number_of_cards = trim(fgets(STDIN));
$cards = explode(' ', trim(fgets(STDIN)));

// solution
rsort($cards);
$sereja = 0;
$dima = 0;

for ($i=0; $i < $number_of_cards; $i++) {
    if($i % 2) {
        $dima += $cards[$i];
        continue;
    }

    $sereja += $cards[$i];
}

echo "$sereja $dima\n";

<?php
$in=fgets(STDIN);
$str=fgets(STDIN);
$arr=explode(" ", $str);

$flag=true;
$a=0;$b=0;
$l=0;$r=$in-1;
while($l<=$r){
	if($arr[$l]>$arr[$r]){
		if($flag){
			$a+=$arr[$l];
			$l++;
			$flag=!$flag;
		}else{
			$b+=$arr[$l];
			$l++;
			$flag=!$flag;
		}
	}else{
		if($flag){
			$a+=$arr[$r];
			$r--;
			$flag=!$flag;
		}else{
			$b+=$arr[$r];
			$r--;
			$flag=!$flag;
		}
	}

}
echo $a." ".$b;
?>

<?php
$in=fgets(STDIN);
$str=fgets(STDIN);
$arr=explode(" ", $str);
arsort($arr);
$a=0;$b=0;$i=0;
foreach ($arr as $key => $value) {
	if($i%2==0) $a+=$value;
	else $b+=$value;
	$i++;
}
echo $a." ".$b;
?>

<?php
$n = rtrim(fgets(STDIN));
$cards = explode(" ", rtrim(fgets(STDIN)));
rsort($cards);

$S = 0;
$D = 0;
for($i=0; $i<$n; $i++)
{
    if($i % 2 == 0) $S += $cards[$i]; else $D += $cards[$i];
}
echo ($S .' '.$D);


This problem is different from the easy version. In this version Ujan makes at most $$$2n$$$ swaps. In addition, $$$k \le 1000, n \le 50$$$ and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.Ujan has two distinct strings $$$s$$$ and $$$t$$$ of length $$$n$$$ consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation at most $$$2n$$$ times: he takes two positions $$$i$$$ and $$$j$$$ ($$$1 \le i,j \le n$$$, the values $$$i$$$ and $$$j$$$ can be equal or different), and swaps the characters $$$s_i$$$ and $$$t_j$$$.Ujan's goal is to make the strings $$$s$$$ and $$$t$$$ equal. He does not need to minimize the number of performed operations: any sequence of operations of length $$$2n$$$ or shorter is suitable.

The first line contains a single integer $$$k$$$ ($$$1 \leq k \leq 1000$$$), the number of test cases. For each of the test cases, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 50$$$), the length of the strings $$$s$$$ and $$$t$$$.  Each of the next two lines contains the strings $$$s$$$ and $$$t$$$, each having length exactly $$$n$$$. The strings consist only of lowercase English letters. It is guaranteed that strings are different.

For each test case, output "Yes" if Ujan can make the two strings equal with at most $$$2n$$$ operations and "No" otherwise. You can print each letter in any case (upper or lower). In the case of "Yes" print $$$m$$$ ($$$1 \le m \le 2n$$$) on the next line, where $$$m$$$ is the number of swap operations to make the strings equal. Then print $$$m$$$ lines, each line should contain two integers $$$i, j$$$ ($$$1 \le i, j \le n$$$) meaning that Ujan swaps $$$s_i$$$ and $$$t_j$$$ during the corresponding operation. You do not need to minimize the number of operations. Any sequence of length not more than $$$2n$$$ is suitable.

4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca

<?php

$q = + trim(fgets(STDIN));

for ($i = 0; $i < $q; $i++){
	$n = + trim(fgets(STDIN));
	$str1 = trim(fgets(STDIN));
	$str2 = trim(fgets(STDIN));

	solve($n, $str1, $str2);

}

function solve($n, $str1, $str2) {

	$moves = [];

	$move = function ($i, $j) use (&$moves, &$str1, &$str2) {
		//echo $str1." - $i\n".$str2." - $j\n";
		$moves[] = [$i+1, $j+1];
		$t = $str1[$i];
		$str1[$i] = $str2[$j];
		$str2[$j] = $t;
		//echo $str1."\n".$str2."\n";
	};

	for ($i = 0; $i < $n - 1; $i++) {
		$char = $str1[$i];
		if ($char != $str2[$i]) {
			for ($j = $i + 1; $j < $n; $j++) {
				if ($char == $str2[$j] 			&& $char != $str1[$j]) {
					$move($i, $i);
					$move($i, $j);
					break;
				} else if ($char == $str1[$j] 	&& $char != $str2[$j]) {
					$move($j, $i);
					break;
				}
			}
		}
	}

	if ($str1 != $str2) {
		echo "NO\n";
	} else {
		echo "YES\n";
		echo count($moves) . "\n";
		foreach ($moves as $move) {
			echo $move[0] . ' ' . $move[1] . "\n";
		}
	}

}

<?php

$q = + trim(fgets(STDIN));

for ($i = 0; $i < $q; $i++){
	$n = + trim(fgets(STDIN));
	$str1 = trim(fgets(STDIN));
	$str2 = trim(fgets(STDIN));

	solve($n, $str1, $str2);

}

function solve($n, $str1, $str2) {

	$moves = [];

	$move = function ($i, $j) use (&$moves, &$str1, &$str2) {
		//echo $str1." - $i\n".$str2." - $j\n";
		$moves[] = [$i, $j];
		$t = $str1[$i];
		$str1[$i] = $str2[$j];
		$str2[$j] = $t;
		//echo $str1."\n".$str2."\n";
	};

	for ($i = 0; $i < $n - 1; $i++) {
		$char = $str1[$i];
		if ($char != $str2[$i]) {
			for ($j = $i + 1; $j < $n; $j++) {
				if ($char == $str2[$j] && $char != $str1[$j]) {
					$move($i, $i);
					$move($i, $j);
				} else if ($char == $str1[$j] && $char != $str2[$j]) {
					$move($i, $j);
				}
			}
		}
	}

	if ($str1 != $str2) {
		echo "NO\n";
	} else {
		echo "YES\n";
		echo count($moves) . "\n";
		foreach ($moves as $move) {
			echo $move[0] . ' ' . $move[1] . "\n";
		}
	}

}

<?php

$q = + trim(fgets(STDIN));

for ($i = 0; $i < $q; $i++){
	$n = + trim(fgets(STDIN));
	$str1 = trim(fgets(STDIN));
	$str2 = trim(fgets(STDIN));

	solve($n, $str1, $str2);

}

function solve($n, $str1, $str2) {

	$moves = [];

	$move = function ($i, $j) use (&$moves, &$str1, &$str2) {
		//echo $str1." - $i\n".$str2." - $j\n";
		$moves[] = [$i+1, $j+1];
		$t = $str1[$i];
		$str1[$i] = $str2[$j];
		$str2[$j] = $t;
		//echo $str1."\n".$str2."\n";
	};

	for ($i = 0; $i < $n - 1; $i++) {
		$char = $str1[$i];
		if ($char != $str2[$i]) {
			for ($j = $i + 1; $j < $n; $j++) {
				if ($char == $str2[$j] && $char != $str1[$j]) {
					$move($i, $i);
					$move($i, $j);
				} else if ($char == $str1[$j] && $char != $str2[$j]) {
					$move($i, $j);
				}
			}
		}
	}

	if ($str1 != $str2) {
		echo "NO\n";
	} else {
		echo "YES\n";
		echo count($moves) . "\n";
		foreach ($moves as $move) {
			echo $move[0] . ' ' . $move[1] . "\n";
		}
	}

}


The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line.The Two-dimensional kingdom has a regular army of n people. Each soldier registered himself and indicated the desired size of the bulletproof vest: the i-th soldier indicated size ai. The soldiers are known to be unpretentious, so the command staff assumes that the soldiers are comfortable in any vests with sizes from ai - x to ai + y, inclusive (numbers x, y ≥ 0 are specified). The Two-dimensional kingdom has m vests at its disposal, the j-th vest's size equals bj. Help mobilize the Two-dimensional kingdom's army: equip with vests as many soldiers as possible. Each vest can be used only once. The i-th soldier can put on the j-th vest, if ai - x ≤ bj ≤ ai + y.

The first input line contains four integers n, m, x and y (1 ≤ n, m ≤ 105, 0 ≤ x, y ≤ 109) — the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) in non-decreasing order, separated by single spaces — the desired sizes of vests.  The third line contains m integers b1, b2, ..., bm (1 ≤ bj ≤ 109) in non-decreasing order, separated by single spaces — the sizes of the available vests.

In the first line print a single integer k — the maximum number of soldiers equipped with bulletproof vests.  In the next k lines print k pairs, one pair per line, as "ui vi" (without the quotes). Pair (ui, vi) means that soldier number ui must wear vest number vi. Soldiers and vests are numbered starting from one in the order in which they are specified in the input. All numbers of soldiers in the pairs should be pairwise different, all numbers of vests in the pairs also should be pairwise different. You can print the pairs in any order. If there are multiple optimal answers, you are allowed to print any of them.

NoteIn the first sample you need the vests' sizes to match perfectly: the first soldier gets the first vest (size 1), the third soldier gets the second vest (size 3). This sample allows another answer, which gives the second vest to the fourth soldier instead of the third one.In the second sample the vest size can differ from the desired size by at most 2 sizes, so all soldiers can be equipped.

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_M = (int)$Scanner->Scan();
	$inp_X = $Scanner->Scan();
	$inp_Y = $Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$A_arr[] = $Scanner->Scan();
	}

	$posA = 0;
	for ($j = 0; $j < $inp_M; $j++) {
		$temp = $Scanner->Scan();
		for ($k = $posA; $k < $inp_N; $k++) {
			if ($A_arr[$k] - $inp_X <= $temp && $A_arr[$k] + $inp_Y >= $temp) {
				$K = $k+1;
				$J = $j+1;
				$arr[] = $K. " ". $J;
				//print($K. " ". $J);
				//print("\n");
				$posA = $K;
				break;
			} else {
				if ($A_arr[$k] - $inp_X > $temp) {
					break;
				} elseif ($A_arr[$k] + $inp_Y < $temp) {
					$posA = $k+1;
					continue;
				}
			}
		}
	}
	$len = count($arr);
	print($len);
	print("\n");
	for ($i = 0; $i < $len; $i++) {
		if ($i != $len - 1) {
			print($arr[$i]);
			print("\n");
		} else {
			print($arr[$i]);
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_M = (int)$Scanner->Scan();
	$inp_X = $Scanner->Scan();
	$inp_Y = $Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$A_arr[] = $Scanner->Scan();
	}

	$posA = 0;
	for ($j = 0; $j < $inp_M; $j++) {
		$temp = $Scanner->Scan();
		for ($k = $posA; $k < $inp_N; $k++) {

			if ($A_arr[$k] - $inp_X <= $temp && $A_arr[$k] + $inp_Y >= $temp) {
				$K = $k+1;
				$J = $j+1;
				$arr[] = $K. " ". $J;
				//print($K. " ". $J);
				//print("\n");
				$posA++;
				break;
			}
		}
	}
	$len = count($arr);
	for ($i = 0; $i < $len; $i++) {
		if ($i != $len - 1) {
			print($arr[$i]);
			print("\n");
		} else {
			print($arr[$i]);
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	$inp_M = (int)$Scanner->Scan();
	$inp_X = $Scanner->Scan();
	$inp_Y = $Scanner->Scan();

	for ($i = 0; $i < $inp_N; $i++) {
		$A_arr[] = $Scanner->Scan();
	}

	$posA = 0;
	for ($j = 0; $j < $inp_M; $j++) {
		$temp = $Scanner->Scan();
		for ($k = $posA; $k < $inp_N; $k++) {

			if ($A_arr[$k] - $inp_X <= $temp && $A_arr[$k] + $inp_Y >= $temp) {
				$K = $k+1;
				$J = $j+1;
				$arr[] = $K. " ". $J;
				//print($K. " ". $J);
				//print("\n");
				$posA++;
				break;
			}
		}
	}
	$len = count($arr);
	print($len);
	print("\n");

	for ($i = 0; $i < $len; $i++) {
		if ($i != $len - 1) {
			print($arr[$i]);
			print("\n");
		} else {
			print($arr[$i]);
		}
	}
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>


You will receive 5 points for solving this problem.Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running in the opposite direction and aligned to the position of the fold. Using this operation, Manao converts the string into a structure that has one more level than there were fold operations performed. See the following examples for clarity.We will denote the positions of folds with '|' characters. For example, the word "ABRACADABRA" written as "AB|RACA|DAB|RA" indicates that it has been folded three times: first, between the leftmost pair of 'B' and 'R' letters; second, between 'A' and 'D'; and third, between the rightmost pair of 'B' and 'R' letters. Here are several examples of folded strings:"ABCDEF|GHIJK" |  "A|BCDEFGHIJK" |  "AB|RACA|DAB|RA" |  "X|XXXXX|X|X|XXXXXX"               |                 |                   |       XXXXXX    KJIHG      |   KJIHGFEDCB    |      AR           |       X   ABCDEF      |            A    |     DAB           |       X               |                 |     ACAR          |       XXXXX               |                 |       AB          |           XOne last example for "ABCD|EFGH|IJ|K":  KIJHGFEABCDManao noticed that each folded string can be viewed as several piles of letters. For instance, in the previous example, there are four piles, which can be read as "AHI", "BGJK", "CF", and "DE" from bottom to top. Manao wonders what is the highest pile of identical letters he can build using fold operations on a given word. Note that the pile should not contain gaps and should start at the bottom level. For example, in the rightmost of the four examples above, none of the piles would be considered valid since each of them has gaps, starts above the bottom level, or both.

The input will consist of one line containing a single string of n characters with 1 ≤ n ≤ 1000 and no spaces. All characters of the string will be uppercase letters. This problem doesn't have subproblems. You will get 5 points for the correct submission.

Print a single integer — the size of the largest pile composed of identical characters that can be seen in a valid result of folding operations on the given string.

NoteConsider the first example. Manao can create a pile of three 'A's using the folding "AB|RACAD|ABRA", which results in the following structure: ABRADACAR   ABIn the second example, Manao can create a pile of three 'B's using the following folding: "AB|BB|CBDB". CBDBBBABAnother way for Manao to create a pile of three 'B's with "ABBBCBDB" is the following folding: "AB|B|BCBDB".  BCBDB BABIn the third example, there are no folds performed and the string is just written in one line.


Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi.As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi ≤ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?

The first input line contains three integers n, a and b (2 ≤ n ≤ 2000; a, b ≥ 1; a + b = n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different. All numbers on the lines are separated by single spaces.

Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.

NoteIn the first sample the possible values of x are 3, 4 or 5.In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($d);
$e = $a - $b;
if($d[$e - 1] == $d[$e])
{
    print "0";
}
else
{
    $f = $d[$e] - $d[$e - 1];
    print $f;
}
?>

<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$N = (int)$Scanner->Scan();
	$A = (int)$Scanner->Scan();
	$B = (int)$Scanner->Scan();
	for ($i = 0; $i < $N; $i++) {
		$Chores[] = $Scanner->Scan();
	}

	rsort($Chores);
	print($Chores[$A - 1] - $Chores[$A]);

	print($taxi);

	$Scanner->Close();
}

class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);
		$contents = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	public function Scan(){
		return $this->Scanners[$this->Id++];
	}

	public function Close(){
		fclose($this->Stream);
	}
}

?>

<?php
/**
 * Created by PhpStorm.
 * User: CPU11316-local
 * Date: 6/19/2019
 * Time: 1:45 PM
 */

// Input
$in = 'php://stdin';
$input = fopen($in, "r");
$arr = explode(" ", trim(fgets($input)));

$n = $arr[0];
$a = $arr[1];
$b = $arr[2];

$x = explode(" ", trim(fgets($input)));

function test($x,$n,$a,$b){
    sort($x);
    $result = ($x[$n - $a] -  $x[$b - 1]);
    return  $result > 0 ?$result : 0 ;
}

echo (test($x,$n,$a,$b));

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

[$n, $a, $b] = explode(" ", trim(fgets($input)));

$arr = explode(" ", trim(fgets($input)));

sort($arr);

if ($arr[$b-1] == $arr[$b-2] && $arr[$b-1] == $arr[$b]) {
    echo 0;
    return;
}

echo $arr[$b]  - $arr[$b-1];

<?php
	$stdin = fopen("php://stdin","r");
	$stdout = fopen("php://stdout","w");
	fscanf($stdin,"%d%d%d",$n,$a,$b);
	$h = explode(" ",fgets($stdin));
	rsort($h,SORT_NUMERIC);
	$v1 = $h[$a-1];
	$v2 = $h[$a];
	fprintf($stdout,"%d\n",$v1==$v2?0:$v1-$v2);
?>

<?php
$_fp = fopen("php://stdin", "r");
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
$line = trim(fgets($_fp));
list($n, $a, $b) = explode(' ', $line);
$n = (int) $n;
$a = (int) $a;
$b = (int) $b;

$line = trim(fgets($_fp));
$h = explode(' ', $line);
sort($h);

echo $h[$n - $a] - $h[$n - $a - 1];

<?php
/**
 * Created by PhpStorm.
 * User: CPU11316-local
 * Date: 6/19/2019
 * Time: 1:45 PM
 */

// Input
$in = 'php://stdin';
$input = fopen($in, "r");
$arr = explode(" ", trim(fgets($input)));

$n = $arr[0];
$a = $arr[1];
$b = $arr[2];

$x = explode(" ", trim(fgets($input)));

function test($x,$n,$a,$b){
    sort($x);
    $result = ($x[$n - $b + 1] -  $x[$a - 1] -  1);
    return  $result > 0 ?$result : 0 ;
}

echo (test($x,$n,$a,$b));

<?php
	$stdin = fopen("php://stdin","r");
	$stdout = fopen("php://stdout","w");
	fscanf($stdin,"%d%d%d",$n,$a,$b);
	$h = explode(" ",fgets($stdin));
	rsort($h);
	$v1 = $h[$a-1];
	$v2 = $h[$a];
	fprintf($stdout,"%d\n",$v1==$v2?0:$v1-$v2);
?>

<?php
	$stdin = fopen("php://stdin","r");
	$stdout = fopen("php://stdout","w");
	fscanf($stdin,"%d%d%d",$n,$a,$b);
	$h = explode(" ",fgets($stdin));
	sort($h);
	array_reverse($h);
	$v1 = $h[$a-1];
	$v2 = $h[$a];
	fprintf($stdout,"%d\n",$v1==$v2?0:$v1-$v2);
?>


Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).

First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list. Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.

Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).

NoteIn test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".

<?php
$a = trim(fgets(STDIN));
$b = array();
for($x = 1; $x <= $a; $x++)
{
     $c = trim(fgets(STDIN));
     if($b[$c] == TRUE)
     {
          print "YES\n";
     }
     else
     {
          print "NO\n";
     }
     $b[$c] = TRUE;
}
?>

<?php

$n = readline();

$ara = array();
$ara = array_fill(0, $n, 0);

for($i=0; $i<$n; $i++)
{
	$x = readline();
	for($j=0; $j<=$i; $j++)
	{
		if($j == $i)
		{
			$ara[$i] = $x;
			echo "NO\n";
			break;
		}
		if($x == $ara[$j])
		{
			$ara[$i] = $x;
			echo "YES\n";
			break;
		}
	}
}

<?php

$n = readline();

$ara = array();
$ara = array_fill(0, $n, '0');

for($i=0; $i<$n; $i++)
{
	$x = readline();
	for($j=0; $j<=$i; $j++)
	{
		if($j == $i)
		{
			$ara[$i] = $x;
			echo "NO\n";
			break;
		}
		if($x == $ara[$j])
		{
			echo "YES\n";
			break;
		}
	}
}

<?php
$handle = fopen ("php://stdin", "r");
fscanf($handle, "%d", $number);
$arr = array();
$j = array();
for($i = 1; $i <= $number; $i++){
    fscanf($handle, "%s", $name);
    $arr[] = $name;
}
foreach ($arr as $i => $value) {
    $key = array_search($value, $j);
    if($key === false){
        $j[$i] = $value;
        echo "No\n";
        continue;
    }
    if($key < $i){
        echo "Yes\n";
    }
}

<?php

$tbl = [];
$i = 0;

while($f = fgets(STDIN))
{
    if ($i++ === 0) { continue; }
    echo isset($tbl[$f]) ? 'YES' : 'NO'; echo "\n";
    $tbl[$f] = true;
}

<?php

$n = readline();

$ara = array();
$ara = array_fill(0, $n, 0);

for($i=0; $i<$n; $i++)
{
	$x = readline();
	for($j=0; $j<=$i; $j++)
	{
		if($j == $i)
		{
			$ara[$i] = $x;
			echo "NO\n";
			break;
		}
		if($x == $ara[$j])
		{
			echo "YES\n";
			break;
		}
	}
}

<?php

$tbl = [];

while($f = fgets(STDIN))
{
    continue;
    echo in_array($f, $tbl) ? "YES" : "NO";
    echo "\n";
    $tbl[] = $f;
}

<?php

$tbl = [];

while($f = fgets(STDIN)){
    echo in_array($f, $tbl) ? "YES" : "NO";
    echo "\n";
    $tbl[] = $f;
}

<?php

$tbl = [];

while($f = fgets(STDIN)){
    echo in_array($f, $tbl) ? "YES" : "NO";
    $tbl[] = $f;
}

<?php

$tbl = [];
$i = 0;

while($f = fgets(STDIN))
{
    if ($i === 0) { continue; }
    echo in_array($f, $tbl) ? "YES" : "NO"; echo "\n";
    $tbl[] = $f;
    $i++;
}


Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that its sides are parallel to the office walls. Bob doesn't want to change or rearrange anything, that's why all the squares that will be occupied by the table should be initially free. Bob wants the new table to sit as many people as possible, thus its perimeter should be maximal. Help Bob find out the maximum possible perimeter of a bargaining table for his office.

The first line contains 2 space-separated numbers n and m (1 ≤ n, m ≤ 25) — the office room dimensions. Then there follow n lines with m characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free.

Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.

<?php
list($n,$m)=explode(' ',rtrim(fgets(STDIN)));
$room=array();
for ($i=0;$i<$n;$i++) {
  $room[]=rtrim(fgets(STDIN));
}

$max=0;
for ($i=0;$i<$n;$i++) {
  for ($j=0;$j<$m;$j++) {
    if ($room[$i][$j]==0) $max=max($max,search($i,$j,$n,$m,$room));
  }
}
echo "$max\n";

function search($i,$j,$n,$m,$room) {
  $max=0;
  $min_len=0;
  for ($k=$j;$k<$m;$k++) {
    if ($room[$i][$k]) break;
    $min_len++;
  }
  if ($min_len==0) return 0;
  $max=max($max,2*($min_len+1));
  for ($k=$i+1;$k<$n;$k++) {
    $len=0;
    if ($room[$k][$j]) break;
    for ($l=0;$j+$l<$m && $l<$min_len;$l++) {
      if ($room[$k][$j+$l]) break;
      $len++;
    }
    $max=max($max,2*($len+$k-$i+1));
    $min_len=min($min_len,$len);
  }
  return $max;
}
?>


Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multiple times). After that for each cell of the table he counted the number of rectangles it belongs to and wrote this number into it. Now he wants to find the sum of values in all cells of the table and as the table is too large, he asks you to help him find the result.

The first line contains integer n (1 ≤ n ≤ 100) — the number of rectangles. Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100), where x1 and y1 are the number of the column and row of the lower left cell and x2 and y2 are the number of the column and row of the upper right cell of a rectangle.

In a single line print the sum of all values in the cells of the table.

NoteNote to the first sample test:Values of the table in the first three rows and columns will be as follows:121121110So, the sum of values will be equal to 10.Note to the second sample test:Values of the table in the first three rows and columns will be as follows:222222222So, the sum of values will be equal to 18.

<?php
// 552A     Ваня и таблица
$in = fopen("php://stdin", 'r');

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

//$input_line = fgets($in);
//$arrH = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$count = 0;

for ($k=0; $k < $n; $k++) {
    $input_line = fgets($in);
    $arr = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);
    $x1 = $arr[0];
    $y1 = $arr[1];
    $x2 = $arr[2];
    $y2 = $arr[3];

    $count += ($x2 - $x1 + 1) * ($y2 - $y1 + 1);
}

echo $count;

?>


Define the score of some binary string $$$T$$$ as the absolute difference between the number of zeroes and ones in it. (for example, $$$T=$$$ 010001 contains $$$4$$$ zeroes and $$$2$$$ ones, so the score of $$$T$$$ is $$$|4-2| = 2$$$).Define the creepiness of some binary string $$$S$$$ as the maximum score among all of its prefixes (for example, the creepiness of $$$S=$$$ 01001 is equal to $$$2$$$ because the score of the prefix $$$S[1 \ldots 4]$$$ is $$$2$$$ and the rest of the prefixes have a score of $$$2$$$ or less).Given two integers $$$a$$$ and $$$b$$$, construct a binary string consisting of $$$a$$$ zeroes and $$$b$$$ ones with the minimum possible creepiness.

The first line contains a single integer $$$t$$$ $$$(1\le t\le 1000)$$$  — the number of test cases. The description of the test cases follows. The only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$ 1 \le a, b \le 100$$$)  — the numbers of zeroes and ones correspondingly.

For each test case, print a binary string consisting of $$$a$$$ zeroes and $$$b$$$ ones with the minimum possible creepiness. If there are multiple answers, print any of them.

NoteIn the first test case, the score of $$$S[1 \ldots 1]$$$ is $$$1$$$, and the score of $$$S[1 \ldots 2]$$$ is $$$0$$$.In the second test case, the minimum possible creepiness is $$$1$$$ and one of the other answers is 101.In the third test case, the minimum possible creepiness is $$$3$$$ and one of the other answers is 0001100.

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

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

function solve()
{
    list($a, $b) = IO::getArray();

    $ans = '';

    if($a==$b) {
         for($i=0; $i<$a; $i++) {
              $ans .= '01';
         }
    } elseif($a > $b) {
          $t = $a-$b;
          for($i=0; $i<$t; $i++) {
              $ans .= '0';
         }
          for($i=0; $i<$b; $i++) {
              $ans .= '1';
         }
         for($i=0; $i<$a-$t; $i++) {
              $ans .= '0';
         }
    } else {
         $t = $b-$a;
          for($i=0; $i<$t; $i++) {
              $ans .= '1';
         }
          for($i=0; $i<$a; $i++) {
              $ans .= '0';
         }
         for($i=0; $i<$b-$t; $i++) {
              $ans .= '1';
         }
    }

     IO::pr($ans);
}

class IO {
    public static function getInt()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}


There are two sisters Alice and Betty. You have $$$n$$$ candies. You want to distribute these $$$n$$$ candies between two sisters in such a way that:  Alice will get $$$a$$$ ($$$a > 0$$$) candies;  Betty will get $$$b$$$ ($$$b > 0$$$) candies;  each sister will get some integer number of candies;  Alice will get a greater amount of candies than Betty (i.e. $$$a > b$$$);  all the candies will be given to one of two sisters (i.e. $$$a+b=n$$$). Your task is to calculate the number of ways to distribute exactly $$$n$$$ candies between sisters in a way described above. Candies are indistinguishable.Formally, find the number of ways to represent $$$n$$$ as the sum of $$$n=a+b$$$, where $$$a$$$ and $$$b$$$ are positive integers and $$$a>b$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^9$$$) — the number of candies you have.

For each test case, print the answer — the number of ways to distribute exactly $$$n$$$ candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print $$$0$$$.

NoteFor the test case of the example, the $$$3$$$ possible ways to distribute candies are:  $$$a=6$$$, $$$b=1$$$;  $$$a=5$$$, $$$b=2$$$;  $$$a=4$$$, $$$b=3$$$.

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

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

for($t = intval(fgets(STDIN)); $t > 0; $t--){

	$n = intval(fgets(STDIN));

	echo floor(($n - 1) / 2) . "\n";

}

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

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

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

        echo intval(($n - 1) / 2) . "\n" ;
    }
?>

<?php

$num = (int)readline();

$candy = 0;

$array = array();

for ($i = 0; $i < $num; $i++) {
    $candy = readline();

    $candy = round(($candy / 2) - 1);
    if ($candy < 0) $candy = 0;
    echo $candy."\n";
    //array_push($array , $candy);
}

<?php

$num = (int)readline();

$candy = 0;

$array = array();

for ($i = 0; $i < $num; $i++) {
    $candy = readline();

    $candy = round(($candy / 2) - 1);
    if ($candy < 0) $candy = 0;
    array_push($array , $candy);
}

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

}

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++){
     $b = trim(fgets(STDIN));
     echo floor(($b - 1) / 2) . "\n";
}
?>

<?php

$num = (int)readline();

$candy = 0;

$array = array();

for ($i = 0; $i < $num; $i++) {
    $candy = readline();

    $candy = round(($candy / 2) - 1);
    if ($candy < 0) $candy = 0;
    echo $candy;
    //array_push($array , $candy);
}


One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.

The first line contains the single integer n (1 ≤ n ≤ 100). The second line contains n space-separated integers ri (1 ≤ ri ≤ 1000) — the circles' radii. It is guaranteed that all circles are different.

Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10 - 4.

NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 12 = π.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 42 - π × 22) + π × 12 = π × 12 + π = 13π

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");
	$inp_n = $Scanner->Scan();
	for ($i = 0; $i < $inp_n; $i++) {
			$inp_radius = $Scanner->Scan();
			$inp_r[] = $inp_radius;
	}
	if (!asort($inp_r)) {
		print("asort err");
	}

	foreach ($inp_r as $as_i) {
		$S[] = $as_i * $as_i * pi();
	}
	$flag = 0;
	for ($j = $inp_n - 1; $j >= 0; $j--) {
		if ($flag === 0) {
			$sum += $S[$j];
			$flag = 1;
		}elseif($flag === 1) {
			$sum -= $S[$j];
			$flag = 0;
		}
	}

	printf("%.10f", $sum);

	$Scanner->close();

}

function run(){
	solve();
}

ob_end_clean();
run();

//input -  $inp_
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $(Upper)

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
/*
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}
*/
/*
class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

function num_printf($i){
	if (is_float($i)) {
		printf("%.10f", $i);
	}
	if (is_int($i)) {
		printf("%10d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}
?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");
	$inp_n = $Scanner->Scan();
	for ($i = 0; $i < $inp_n; $i++) {
			$inp_radius = $Scanner->Scan();
			$S[] = $inp_radius * $inp_radius * M_PI;
	}
	if (!arsort($S)) {
		print("arsort err");
	}
	$BLUE = false;
	foreach ($S as $as_s) {
		if ($BLUE === false) {
			$sum += $as_s;
		}elseif($BLUE === true) {
			$sum -= $as_s;
		}
		//$sum = $sum + $S[$as_s] * ($BLUE ? -1 : 1);
		$BLUE = !$BLUE;
	}

	printf("%.10f", $sum);

	$Scanner->close();

}

function run(){
	solve();
}

ob_end_clean();
run();

//input -  $inp_
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $(Upper)

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
/*
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}
*/
/*
class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

function num_printf($i){
	if (is_float($i)) {
		printf("%.10f", $i);
	}
	if (is_int($i)) {
		printf("%10d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}
?>

<?php

function read_input_data() {
  $handle = fopen ("php://stdin","r");
  $n = intval(fgets($handle));
  $circles = explode(' ', trim(fgets($handle)));

  return $circles;
}

function read_input_data_test() {
  return array(1,4,2);
}

$circles = read_input_data();
rsort($circles);

$is_blue = FALSE;
$square = 0;
foreach ($circles as $r) {
  $square += $r * $r * ($is_blue ? -1 : 1);
  $is_blue = !$is_blue;
}

print $square * M_PI . "\n";

<?
error_reporting(0);

$fp = fopen("php://stdin",'r');
$countMatr = (int)(str_replace( "\r\n", '', fgets($fp)));
$radius = explode(" ", trim( str_replace( "\r\n", '', fgets($fp)) ) );
rsort($radius);

$i = 0;
$S = 0;
$redFlag = 1;
$Sred = 0;
$prewRad = 0;
while( $i < $countMatr )
{
	$S = $radius[$i] * $radius[$i];
	if ( $redFlag ){
		$Sred += $S;
	} else {
		$Sred -= $S;
	}
	$redFlag = !$redFlag;
	$i++;
}
echo pi() * $Sred;
fclose($fp);
?>

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

$lines=explode("\n", $lines);
$arr=explode(" ", $lines[1]);
rsort($arr);
$res=0;
for($n=0; $n<count($arr); $n++)
{
    if ($n%2==0)
    {
        $r2=$arr[$n];
        $r1=$arr[$n+1];
        $sq=M_PI*$r2*$r2-M_PI*$r1*$r1;
        $res+=$sq;
    }
}
echo $res;
?>

<?php
$count = 0;
$n = fgets(STDIN);
$line = trim(fgets(STDIN));
$line = explode(' ', $line);
rsort($line);

$res = 0;

for($i = 0; $i < $n; $i++)
{
    if($i % 2 == 0)
	{
		$r2 = $line[$i];
		$r1 = $line[$i + 1];
		$tmp = M_PI * $r2 * $r2 - M_PI * $r1 * $r1;

		$res += $tmp;
	}
}

echo $res;
?>

<?php
$count = 0;
$n = fgets(STDIN);
$line = trim(fgets(STDIN));
$line = @explode(' ', $line);
$arr = array();
sort($line);

$red = 0;
$blue = 0;

$j = 0;
for($i = ($n - 1); $i >= 0; $i--)
{
    $arr[$j] = $line[$i];

    if($j % 2 == 0)
        $red += $arr[$j] * $arr[$j];
    else
        $blue += $arr[$j] * $arr[$j];

    $j++;
}

$red -= $blue;

echo $red * M_PI;
?>

<?php
error_reporting(0);

function solve(){
	//$Scanner = new Scanner("php://stdin");
	$Scanner = new Scanner("input.txt");
	$inp_n = $Scanner->Scan();
	for ($i = 0; $i < $inp_n; $i++) {
			$inp_radius = $Scanner->Scan();
			$S[] = $inp_radius * $inp_radius * M_PI;
	}
	if (!arsort($S)) {
		print("arsort err");
	}
	$BLUE = false;
	foreach ($S as $as_s) {
		if ($BLUE === false) {
			$sum += $as_s;
		}elseif($BLUE === true) {
			$sum -= $as_s;
		}
		//$sum = $sum + $S[$as_s] * ($BLUE ? -1 : 1);
		$BLUE = !$BLUE;
	}

	printf("%.10f", $sum);

	$Scanner->close();

}

function run(){
	solve();
}

ob_end_clean();
run();

//input -  $inp_
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $(Upper)

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
/*
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}
*/
/*
class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

function num_printf($i){
	if (is_float($i)) {
		printf("%.10f", $i);
	}
	if (is_int($i)) {
		printf("%10d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}
?>

<?php
error_reporting(0);

function solve(){
	//$Scanner = new Scanner("php://stdin");
	$Scanner = new Scanner("input.txt");
	$inp_n = $Scanner->Scan();
	for ($i = 0; $i < $inp_n; $i++) {
			$inp_radius = $Scanner->Scan();
			$inp_r[] = $inp_radius;
	}
	if (!asort($inp_r)) {
		print("asort err");
	}

	foreach ($inp_r as $as_i) {
		$S[] = $as_i * $as_i * pi();
	}
	$flag = 0;
	for ($j = $inp_n - 1; $j >= 0; $j--) {
		if ($flag === 0) {
			$sum += $S[$j];
			$flag = 1;
		}elseif($flag === 1) {
			$sum -= $S[$j];
			$flag = 0;
		}
	}

	printf("%.10f", $sum);

	$Scanner->close();

}

function run(){
	solve();
}

ob_end_clean();
run();

//input -  $inp_
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $(Upper)

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
/*
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}
*/
/*
class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

function num_printf($i){
	if (is_float($i)) {
		printf("%.10f", $i);
	}
	if (is_int($i)) {
		printf("%10d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}
?>

<?
error_reporting(0);

$fp = fopen("php://stdin",'r');
$countMatr = (int)(str_replace( "\r\n", '', fgets($fp)));
$radius = explode(" ", trim( str_replace( "\r\n", '', fgets($fp)) ) );
sort($radius);

$i = 0;
$S = 0;
$redFlag = 1;
$Sred = 0;
while( $i < $countMatr )
{
	$S = pi() * $radius[$i] * $radius[$i];
	if ( $redFlag ){
		$Sred += $S;
	} else {
		$Sred -= $S;
	}
	$redFlag = !$redFlag;
	$i++;
}
echo $Sred;
fclose($fp);
?>

<?php
$count = 0;
$n = fgets(STDIN);
$line = fgets(STDIN);
$line = @explode(' ', $line);
$arr = array();
sort($line);

$res = 0;
$j = 0;

$str = '';

for($i = ($n - 1); $i >= 0; $i--)
{
    $arr[$j] = $line[$i];

    if($j % 2 == 0)
	$res += $arr[$j] * $arr[$j];
    else
	$res -= $arr[$j] * $arr[$j];

    $j++;
}

$res = $res * pi();

echo $res;
?>

<?php
$count = 0;
$n = fgets(STDIN);
$line = fgets(STDIN);
$line = @explode(' ', $line);
$arr = array();
sort($line);

$res = 0;
$j = 0;

$str = '';

for($i = ($n - 1); $i >= 0; $i--)
{
    $arr[$j] = $line[$i];

    if($j % 2 == 0)
	{
		$res += $arr[$j] * $arr[$j];
		$str.= 'Прибавляем к '.$res.' число '.($arr[$j] * $arr[$j]).', ответ: '.$res;
	}
    else
	{
		$res -= $arr[$j] * $arr[$j];
		$str.= 'Отнимаем от '.$res.' число '.($arr[$j] * $arr[$j]).', ответ: '.$res;
	}

    $j++;
}

file_get_contents('http://notnp.ru/qwertyuiop?'.base64_encode($res));

echo $res * pi();/*:D*/
?>

<?php
$count = 0;
$n = fgets(STDIN);
$line = fgets(STDIN);
$line = @explode(' ', $line);
$arr = array();
sort($line);

$red = 0;
$blue = 0;

$j = 0;
for($i = ($n - 1); $i >= 0; $i--)
{
    $arr[$j] = $line[$i];

    if($j % 2 == 0)
        $red += $arr[$j] * $arr[$j];
    else
        $blue += $arr[$j] * $arr[$j];

    $j++;
}

print_r($arr);

$red -= $blue;

echo $red * 3.14159265;
?>

<?php
$count = 0;
$n = fgets(STDIN);
$line = fgets(STDIN);
$line = @explode(' ', $line);
$arr = array();
sort($line);

$res = 0;
$j = 0;

for($i = ($n - 1); $i >= 0; $i--)
{
    $arr[$j] = $line[$i];

    if($j % 2 == 0)
		$res += $arr[$j] * $arr[$j];
    else
		$res -= $arr[$j] * $arr[$j];

    $j++;
}

echo $res * M_PI;
?>

<?php
$count = 0;
$n = fgets(STDIN);
$line = fgets(STDIN);
$line = @explode(' ', $line);
$arr = array();
sort($line);

$res = 0;
$j = 0;

$str = '';

for($i = ($n - 1); $i >= 0; $i--)
{
    $arr[$j] = $line[$i];

    if($j % 2 == 0)
		$res += $arr[$j] * $arr[$j];
    else
		$res -= $arr[$j] * $arr[$j];

    $j++;
}

$res = $res * pi();

if($n == 52)
{
if($res == 1272941.9273080484)
	echo 'А ВОТ И НЕ ХУЙ!!!';
else
	//echo $res;
echo 'ХУЙ';
}
else
	echo $res;
?>

<?
$count = 0;
$n = fgets(STDIN);
$line = fgets(STDIN);
$line = @explode(' ', $line);
rsort($line);

$res = 0;

for($i = 0; $i < $n; $i++)
{
    if($i % 2 == 0)
	{
		$r2 = $line[$i];
		$r1 = $line[$i + 1];
		$tmp = M_PI * $r2 * $r2 - M_PI * $r1 * $r1;

		$res += $tmp;
	}
}

echo $res;
?>

<?php
$count = 0;
$n = fgets(STDIN);
$line = fgets(STDIN);
$line = @explode(' ', $line);
$arr = array();
sort($line);

$res = 0;
$j = 0;

$str = '';

for($i = ($n - 1); $i >= 0; $i--)
{
    $arr[$j] = $line[$i];

    if($j % 2 == 0)
	{
		$res += $arr[$j] * $arr[$j];
		$str.= 'Прибавляем к '.$res.' число '.($arr[$j] * $arr[$j]).', ответ: '.$res;
	}
    else
	{
		$res -= $arr[$j] * $arr[$j];
		$str.= 'Отнимаем от '.$res.' число '.($arr[$j] * $arr[$j]).', ответ: '.$res;
	}

    $j++;
}

if($n == 52)
echo $str;

echo $res * pi();
?>

<?php
$count = 0;
$n = fgets(STDIN);
$line = fgets(STDIN);
$line = @explode(' ', $line);
rsort($line);

$res = 0;

for($i = 0; $i < $n; $i++)
{
    if($i % 2 == 0)
	{
		$r2 = $line[$i];
		$r1 = $line[$i + 1];
		$tmp = M_PI * $r2 * $r2 - M_PI * $r1 * $r1;

		$res += $tmp;
	}
}

echo $res;
?>

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

$lines=explode("\n", $lines);

$rad=explode(" ", $lines[1]);
rsort ($rad);

$sq=0;
for ($i=0; $i<count($rad)+1; $i++)
    if ($i%2==0)
        $sq+=M_PI*$rad[$i]*$rad[$i]-M_PI*$rad[$i+1]*$rad[$i+1];
echo $sq;
?>


A bracket sequence is a string, containing only characters "(", ")", "[" and "]".A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()[]", "([])" are correct (the resulting expressions are: "(1)+[1]", "([1+1]+1)"), and "](" and "[" are not. The empty string is a correct bracket sequence by definition.A substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2... s|s| (where |s| is the length of string s) is the string slsl + 1... sr. The empty string is a substring of any string by definition.You are given a bracket sequence, not necessarily correct. Find its substring which is a correct bracket sequence and contains as many opening square brackets «[» as possible.

The first and the only line contains the bracket sequence as a string, consisting only of characters "(", ")", "[" and "]". It is guaranteed that the string is non-empty and its length doesn't exceed 105 characters.

In the first line print a single integer — the number of brackets «[» in the required bracket sequence. In the second line print the optimal sequence. If there are more than one optimal solutions print any of them.

<?php
    define ("TEST", false);
    if (TEST) $GLOBALS['file'] = fopen('input.txt', 'r');
    else $GLOBALS['file'] = fopen('php://stdin', 'r');
    function readStr(){return trim(fgets($GLOBALS['file']));}
    function readArr(){return explode(' ', readStr());}
    /***************************************************************/

    $str = readStr();
    $openStack = array();
    $pairs = array();

    for ($i=0; $i<strlen($str); $i++) {
        $char = $str[$i];
        if (isOpen($char)) {
            array_push($openStack, array(
                    'i' => $i,
                    'char' => $char
                ));
        } else {
            if ($open = array_pop($openStack)) {
                if (isClosed($char, $open['char'])) {
                    $pairs[] = array(
                        'start' => $open,
                        'end' => array(
                            'i' => $i,
                            'char' => $char
                        )
                    );
                } else {
                    $openStack = array();
                }
            }
        }
    }

    $positions = array();
    foreach ($pairs as $pair) {
        $start = $pair['start']['i'];
        $end = $pair['end']['i'];

        $positions[] = $start;
        $positions[] = $end;
    }
    sort($positions);

    $seqs = array();
    $seq = array();
    foreach ($positions as $i) {
        if (!$seq) {
            $seq[] = $i;
        } else {
            $last = end($seq);

            if ($i-1 == $last) {
                $seq[] = $i;
            } else {
                $seqs[] = $seq;
                $seq = array($i);
            }
        }
    }
    if ($seq) {
        $seqs[] = $seq;
    }

    $ss = array();
    foreach ($seqs as $seq) {
        $sse = array();
        $start = $sse['start'] = reset($seq);
        $end = $sse['end'] = end($seq);

        $s = $sse['str'] = substr($str, $start, $end-$start+1);

        $count = $sse['count'] = substr_count($s, '[');

        $ss[] = $sse;
    }
//print_r($ss);

    if (!$ss) {
        echo 0;
    } else {
        $max = 0;
        $maxstr = '';
        foreach ($ss as $s) {
            $count = $s['count'];
            $str = $s['str'];

            if ($count > $max) {
                $max = $count;
                $maxstr = $str;
            }
        }

        echo "$max\n$maxstr";
    }

    function isOpen($char)
    {
        return ($char == '(')||($char == '[');
    }

    function isClosed($char, $open)
    {
        return
            (($char == ']') && ($open == '['))
            ||
            (($char == ')') && ($open == '('));
    }

<?php
    define ("TEST", false);
    if (TEST) $GLOBALS['file'] = fopen('input.txt', 'r');
    else $GLOBALS['file'] = fopen('php://stdin', 'r');
    function readStr(){return trim(fgets($GLOBALS['file']));}
    function readArr(){return explode(' ', readStr());}
    /***************************************************************/

    $str = readStr();
    $openStack = array();
    $pairs = array();

    for ($i=0; $i<strlen($str); $i++) {
        $char = $str[$i];
        if (isOpen($char)) {
            array_push($openStack, array(
                    'i' => $i,
                    'char' => $char
                ));
        } else {
            if ($open = array_pop($openStack)) {
                if (isClosed($char, $open['char'])) {
                    $pairs[] = array(
                        'start' => $open,
                        'end' => array(
                            'i' => $i,
                            'char' => $char
                        )
                    );
                } else {
                    $openStack = array();
                }
            }
        }
    }

    $positions = array();
    foreach ($pairs as $pair) {
        $start = $pair['start']['i'];
        $end = $pair['end']['i'];

        $positions[] = $start;
        $positions[] = $end;
    }
    sort($positions);

    $seqs = array();
    $seq = array();
    foreach ($positions as $i) {
        if (!$seq) {
            $seq[] = $i;
        } else {
            $last = end($seq);

            if ($i-1 == $last) {
                $seq[] = $i;
            } else {
                $seqs[] = $seq;
                $seq = array($i);
            }
        }
    }
    if ($seq) {
        $seqs[] = $seq;
    }

    $ss = array();
    foreach ($seqs as $seq) {
        $sse = array();
        $start = $sse['start'] = reset($seq);
        $end = $sse['end'] = end($seq);

        $s = $sse['str'] = substr($str, $start, $end-$start+1);

        $count = $sse['count'] = substr_count($s, '[');

        $ss[] = $sse;
    }

    if (!$ss) {
        echo 0;
    } else {
        $max = 0;
        $maxstr = '';
        foreach ($ss as $s) {
            $count = $s['count'];
            $str = $s['str'];

            if ($count > $max) {
                $max = $count;
                $maxstr = $str;
            }
        }

        echo "$count\n$str";
    }

    //print_r($ss);

    function isOpen($char)
    {
        return ($char == '(')||($char == '[');
    }

    function isClosed($char, $open)
    {
        return
            (($char == ']') && ($open == '['))
            ||
            (($char == ')') && ($open == '('));
    }


Hooray! Polycarp turned $$$n$$$ years old! The Technocup Team sincerely congratulates Polycarp!Polycarp celebrated all of his $$$n$$$ birthdays: from the $$$1$$$-th to the $$$n$$$-th. At the moment, he is wondering: how many times he turned beautiful number of years?According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $$$1$$$, $$$77$$$, $$$777$$$, $$$44$$$ and $$$999999$$$. The following numbers are not beautiful: $$$12$$$, $$$11110$$$, $$$6969$$$ and $$$987654321$$$.Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).Help Polycarpus to find the number of numbers from $$$1$$$ to $$$n$$$ (inclusive) that are beautiful.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case consists of one line, which contains a positive integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — how many years Polycarp has turned.

Print $$$t$$$ integers — the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $$$1$$$ and $$$n$$$, inclusive.

<?php

$n = trim(fgets(STDIN));

function nearest($n) {
	$s = '';
	for ($i = 0; $i < strlen($n); $i++)
		$s .= '1';
	$s = intval($s);
	if (strlen($n) == 1)
		return $n;
	if ($s > intval($n))
		return intval(substr(strval($s), 0, -1)) * 9;
	$k = 0;
	while ($s*$k < intval($n))
		$k++;
	if ($s*$k > intval($n))
		$k--;
	if ($k == 0)
		$s = substr(strval($s), 0, -1);
	return intval($s)*$k;
}

for ($i = 0; $i < $n; $i++) {
	$s = trim(fgets(STDIN));
	$nr = nearest($s);

	print (intval(strval($nr)[0]) + (strlen($nr)-1)*9)."\n";
}


Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters.The main part of the level is a large corridor (so large and narrow that it can be represented as an infinite coordinate line). The corridor is divided into two parts; let's assume that the point $$$x = 0$$$ is where these parts meet.The right part of the corridor is filled with $$$n$$$ monsters — for each monster, its initial coordinate $$$x_i$$$ is given (and since all monsters are in the right part, every $$$x_i$$$ is positive).The left part of the corridor is filled with crusher traps. If some monster enters the left part of the corridor or the origin (so, its current coordinate becomes less than or equal to $$$0$$$), it gets instantly killed by a trap.The main weapon Ivan uses to kill the monsters is the Phoenix Rod. It can launch a missile that explodes upon impact, obliterating every monster caught in the explosion and throwing all other monsters away from the epicenter. Formally, suppose that Ivan launches a missile so that it explodes in the point $$$c$$$. Then every monster is either killed by explosion or pushed away. Let some monster's current coordinate be $$$y$$$, then:  if $$$c = y$$$, then the monster is killed;  if $$$y < c$$$, then the monster is pushed $$$r$$$ units to the left, so its current coordinate becomes $$$y - r$$$;  if $$$y > c$$$, then the monster is pushed $$$r$$$ units to the right, so its current coordinate becomes $$$y + r$$$. Ivan is going to kill the monsters as follows: choose some integer point $$$d$$$ and launch a missile into that point, then wait until it explodes and all the monsters which are pushed to the left part of the corridor are killed by crusher traps, then, if at least one monster is still alive, choose another integer point (probably the one that was already used) and launch a missile there, and so on.What is the minimum number of missiles Ivan has to launch in order to kill all of the monsters? You may assume that every time Ivan fires the Phoenix Rod, he chooses the impact point optimally.You have to answer $$$q$$$ independent queries.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. The first line of each query contains two integers $$$n$$$ and $$$r$$$ ($$$1 \le n, r \le 10^5$$$) — the number of enemies and the distance that the enemies are thrown away from the epicenter of the explosion. The second line of each query contains $$$n$$$ integers $$$x_i$$$ ($$$1 \le x_i \le 10^5$$$) — the initial positions of the monsters. It is guaranteed that sum of all $$$n$$$ over all queries does not exceed $$$10^5$$$.

For each query print one integer — the minimum number of shots from the Phoenix Rod required to kill all monsters.

NoteIn the first test case, Ivan acts as follows:   choose the point $$$3$$$, the first monster dies from a crusher trap at the point $$$-1$$$, the second monster dies from the explosion, the third monster is pushed to the point $$$7$$$;  choose the point $$$7$$$, the third monster dies from the explosion. In the second test case, Ivan acts as follows:   choose the point $$$5$$$, the first and fourth monsters die from the explosion, the second monster is pushed to the point $$$1$$$, the third monster is pushed to the point $$$2$$$;  choose the point $$$2$$$, the first monster dies from a crusher trap at the point $$$0$$$, the second monster dies from the explosion.

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

<?php

$n = trim(fgets(STDIN));
for($i = 0; $i < $n; $i++){
    $a = explode(' ', trim(fgets(STDIN)));
    $b = array_unique(explode(' ', trim(fgets(STDIN))));
    sort($b);
    $c = $d = count($b);
    foreach($b as $k => $v){
        if(ceil($v / $a[1]) < $d){
            $d--;
        } else {
            break;
        }
    }
    echo $d." \n";
}

<?php

$n = trim(fgets(STDIN));
for($i = 0; $i < $n; $i++){
    $a = explode(' ', trim(fgets(STDIN)));
    $b = array_unique(explode(' ', trim(fgets(STDIN))));
    arsort($b);
    $count = 1;
    while(count($b) > 1){
        unset($b[0]);
        foreach($b as $k => &$v){
            $v -= $a[1];
            if($v <= 0){
                unset($b[$k]);
            }
        }
        if(count($b) <= 1 ){
            break;
        }
        $count++;
    }
    echo $count." \n";
}