<?php
// 461A     Яблов и Тостов
$in = fopen("php://stdin", 'r');

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

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

foreach ($arr as $key => &$value) {
    $value = (int) $value;
}
unset($value);

sort($arr);

$x = $arr[$n-1];
$x = (string) $x;
$sum = bcmul($x, $n);

for ($i=0; $i < $n-1; $i++) {
    $sum = bcadd($sum, bcmul((string) $arr[$i], (string) ($i + 2)));
}
echo $sum;

?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
if($a == 1)
{
    print $b[0];
}
else
{
    sort($b);
    $c = array_sum($b);
    $e = $c;
    for($x = 0; $x < $a - 1; $x++)
    {
        $d = $e;
        $c += $d;
        if(count($b) == 2)
        {
            break;
        }
        else
        {
            $e -= $b[$x];
        }
    }
    print $c;
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
if($a == 1)
{
    print $b[0];
}
else
{
    sort($b);
    $c = array_sum($b);
    for($x = 1; $x <= 2; $x++)
    {
        $d = array_sum($b);
        $c += $d;
        if(count($b) == 2)
        {
            break;
        }
        else
        {
            unset($b[0]);
        }
    }
    print $c;
}
?>

<?php
// 461A     Яблов и Тостов
$in = fopen("php://stdin", 'r');

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

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

foreach ($arr as $key => &$value) {
    $value = (int) $value;
}
unset($value);

// $sum = array_sum($arr);
sort($arr);
$sum = $arr[$n-1] * $n;

/*
while ( count($arr) > 1) {
    $sum += array_sum($arr);
    array_pop($arr);
}
*/

for ($i=0; $i < $n-1; $i++) {
    $sum += $arr[$i] * ($i + 2);
}
echo $sum;

?>

<?php
// 461A     Яблов и Тостов
$in = fopen("php://stdin", 'r');

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

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

foreach ($arr as $key => &$value) {
    $value = (int) $value;
}
unset($value);

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

while ( count($arr) > 1) {
    $sum += array_sum($arr);
    array_pop($arr);
echo "sum=$sum \n";
}

echo $sum;

?>


<?php
	// God & me
	// I found myself in Love empire !
	$INPUTS = preg_split("/[\s]+/", file_get_contents('php://stdin'));
	function in(){
		static $i = 0;
		global $INPUTS;
		return $INPUTS[$i++];
	}
	$n = in();  $last = in();  $mx = in();
	for($i = 0; $i < $n; $i++){
		$a[$i] = $last > 0 ? $mx : 1;
		$last = $a[$i] - $last;
	}
	$a[$n - 1] -= $last;
	if($a[$n - 1] < 1 || $a[$n - 1] > $mx)
		echo -1;
	else
		for($i = 0; $i < $n; $i++)
			echo $a[$i]. ' ';
?>

<?php
	// God & me
	// I found myself in Love empire !
	$INPUTS = preg_split("/[\s]+/", file_get_contents('php://stdin'));
	function in(){
		static $i = 0;
		global $INPUTS;
		return $INPUTS[$i++];
	}
	$n = in();  $last = in();  $mx = in();
	for($i = 0; $i < $n; $i++){
		$a[$i] = $last > 0 ? $mx : 1;
		$last = $a[$i] - $last;
	}
	if($a[$n - 1] < 1 || $a[$n - 1] > $mx)
		echo -1;
	else
		for($i = 0; $i < $n; $i++)
			echo $a[$i]. ' ';
?>


<?php
$fp = fopen('php://stdin', 'r');
$n = (int)fgets($fp);
$heap = new SplMinHeap();
$result = [];

for($i = 0; $i < $n; ++$i) {
	$ln = fgets($fp);
	if (strcmp($ln, "removeMin") >= 0) {
		if ($heap->count() == 0) {
			$result[] = "insert 0\n";
		} else {
			$heap->extract();
		}
	} else {
		list($op, $arg) = explode(' ', $ln);
		$arg = intval($arg);
		if ($op == 'insert') {
			$heap->insert($arg);
		} else {
			while($heap->count() && $heap->top() < $arg) {
				$result[] = "removeMin\n";
				$heap->extract();
			}
			if ($heap->count() == 0 || $heap->top() > $arg) {
				$result[] = "insert $arg\n";
				$heap->insert($arg);
			}
		}
	}
	$result[] = $ln;
}
echo count($result)."\n";
echo implode("", $result);

<?php
$fp = fopen('php://stdin', 'r');
$n = (int)fgets($fp);
$heap = [];
$result = [];

for($i = 0; $i < $n; ++$i) {
	$ln = fgets($fp);
	if (strcmp($ln, "removeMin") >= 0) {
		if (count($heap) == 0) {
			$result[] = "insert 0\n";
		} else {
			array_shift($heap);
		}
	} else {
		list($op, $arg) = explode(' ', $ln);
		$arg = intval($arg);
		if ($op == 'insert') {
			$heap[] = $arg;
			sort($heap);
		} else {
			while(count($heap) && $heap[0] < $arg) {
				$result[] = "removeMin\n";
				array_shift($heap);
			}
			if (count($heap) == 0 || $heap[0] > $arg) {
				$result[] = "insert $arg\n";
			}
		}
	}
	$result[] = $ln;
}
echo count($result)."\n";
echo implode("", $result);


<?php

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

list($count) = fscanf($stdin, "%d");

echo "1";

$step = $count-1;
$napr = 1;
$pos = 1;
while ($step) {
    $pos += $step*$napr;
    echo " $pos";
    $napr *= -1;
    $step--;
}
echo "\n";

exit;


<?php
$a = trim(fgets(STDIN));
$b = 1;
$c = 0;
$d = array();
for($x = 1; $x <= $a; $x++)
{
    list($e, $f) = explode(" ", trim(fgets(STDIN)));
    if($f > 0)
    {
        $b += $f;
        $b--;
        $c += $e;
    }
    else
    {
        array_push($d, $e);
    }
}
rsort($d);
$g = array_splice($d, 0, $b);
$h = array_sum($g);
print $c + $h;
?>

<?php

function solve(){
	$Token = new Token(rtrim(fgets(STDIN)), " ");
	$inp_n = $Token->nextInt();
	$inp_arr1 = array();
	$temp_counter = 1;
	$temp_point = 0;
	for ($i = 0; $i < $inp_n; $i++) {
		$Token = new Token(rtrim(fgets(STDIN)), " ");
		$inp_p = $Token->nextInt();
		$inp_c = $Token->nextInt();
		if ($inp_c == 0) $inp_arr1[] = $inp_p;
		else {
			$temp_counter = $temp_counter - 1 + $inp_c;
			$temp_point += $inp_p;

		}
	}
	if (arsort($inp_arr1) === false) {
		//print(-1);
		//return;
	}

	foreach ($inp_arr1 as $as_i) {
		$temp_point += $as_i;
		$temp_counter = $temp_counter - 1;

		if ($temp_counter == 0) break;
	}
	printf("%d", $temp_point);

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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');
$n = (int)(str_replace( "\r\n", '', fgets($fp)));

$score = 0;
$nullCard = array();
$countCardToDrop = 1;
while( $n-- ){
	$card = explode(" ", trim( str_replace( "\r\n", '', fgets($fp)) ) );
	if( $card[1] > 0 ){
		$score += $card[0];
		$countCardToDrop += $card[1] - 1;
	} else {
		$nullCard[] = $card[0];
	}
}
rsort($nullCard);
$i = 0;
while( $countCardToDrop-- ){
	if( !isset($nullCard[$i]) ){
		break;
	}
	$score += $nullCard[$i];
	$i++;
}
echo $score;
fclose($fp);
?>

<?php
function cmp($a, $b){
    if ($a[0] == $b[0]) {
        return 0;
    }
    return ($a[0] > $b[0]) ? -1 : 1;
}
/*ccccccccccccccccccccccccccccccccccccc*/
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$arr = explode("\n", $n);
$count = (int) $arr[0];
$summ_left = 0;
$summ_right = 0;
$cards = array();
$cards_left = array();
$cards_right = array();
$c_more_right = 0;
for($i = 1; $i <= $count; $i++){
    $exp = explode(" ", $arr[$i]);
    $summ_left+= $exp[0];
    $summ_right+= $exp[1];
    if($exp[1] > 0) $c_more_right++;
    $cards[] = $exp;
    $cards_left[] = $exp[0];
    $cards_right[] = $exp[1];
}
if($summ_right == 0){
    echo max($cards_left);
    exit;
}
$count_step = array_sum($cards_right);
if($count_step >= $count){
    echo array_sum($cards_left);
    exit;
}
usort($cards, cmp);
$count_step-= ($c_more_right - 1);
$countpoint = 0;
for($i = 0; $i < $count; $i++){
    if($cards[$i][1] == 0){
        if($count_step > 0){
            $count_step--;
            $countpoint+= $cards[$i][0];
        }
    } else {
        $countpoint+= $cards[$i][0];
    }
}
echo $countpoint;

<?php
$a = trim(fgets(STDIN));
$b = 1;
$c = 0;
$d = array();
for($x = 1; $x <= $a; $x++)
{
    list($e, $f) = explode(" ", trim(fgets(STDIN)));
    if($f > 0)
    {
        $b += $f;
        $c += $e;
    }
    else
    {
        array_push($d, $e);
    }
}
rsort($d);
$g = array_splice($d, 0, $b);
$h = array_sum($g);
print $c + $h;
?>

<?php

function solve(){
	$Token = new Token(rtrim(fgets(STDIN)), " ");
	$inp_n = $Token->nextInt();
	$inp_arr = array();
	for ($i = 0; $i < $inp_n; $i++) {
		$Token = new Token(rtrim(fgets(STDIN)), " ");
		$inp_p = $Token->nextInt();
		$inp_c = $Token->nextInt();
		$inp_arr[$inp_p] = $inp_c;
	}
/*	if (arsort($inp_arr) === false) {
		print(-1);
		return;
	}
*/
	$temp_counter = 1;
	$temp_point = 0;
	$temp = 1;
	//$c = 0;
	foreach ($inp_arr as $as_key => $as_val) {
		if ($as_val == 0) break;

		$temp_point += $as_key;
		$temp_counter = $temp_counter - 1 + $as_val;
		//$c++;
	}

	/*$len = $c;
	for ($i = 0; $i < $len; $i++) {
		$_inp_arr = array_shift($inp_arr);
	}
	*/
	$temp_arr = array();
	foreach ($inp_arr as $as_key => $as_val) {
		if ($as_val == 0) $temp_arr[$as_key] = $as_val;
	}

	//if (ksort($inp_arr) === false) {
	//if (krsort($inp_arr) === false) {
/*	if (krsort($temp_arr) === false) {
		print(-1);
		return;
	}
*/
	$end = $temp_counter;
	//foreach ($inp_arr as $as_key => $as_val) {
	foreach ($temp_arr as $as_key => $as_val) {
		//if ($as_val == 0) print("count err");

		$temp_point += $as_key;
		$temp_counter--;

		if ($temp_counter == 0) break;
	}

	printf("%d", $temp_point);

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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 solve(){
	$Token = new Token(rtrim(fgets(STDIN)), " ");
	$inp_n = $Token->nextInt();
	$inp_arr1 = array();
	$inp_arr2 = array();
	for ($i = 0; $i < $inp_n; $i++) {
		$Token = new Token(rtrim(fgets(STDIN)), " ");
		$inp_p = $Token->nextInt();
		$inp_c = $Token->nextInt();
		if ($inp_c == 0) $inp_arr1[$inp_p] = $inp_c;
		else $inp_arr2[$inp_p] = $inp_c;
	}
	if (arsort($inp_arr2) === false) {
		//print(-1);
		//return;
	}
	$temp_counter = 1;
	$temp_point = 0;
	$temp = 1;
	//$c = 0;
	foreach ($inp_arr2 as $as_key => $as_val) {
		$temp_point += $as_key;
		$temp_counter = $temp_counter - 1 + $as_val;
	}
	if (krsort($inp_arr1) === false) {
		//print(-1);
		//return;
	}
	foreach ($inp_arr1 as $as_key => $as_val) {
		$temp_point += $as_key;
		$temp_counter--;

		if ($temp_counter == 0) break;
	}

	printf("%d", $temp_point);

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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 solve(){
	$Token = new Token(rtrim(fgets(STDIN)), " ");
	$inp_n = $Token->nextInt();
	$inp_arr = array();
	for ($i = 0; $i < $inp_n; $i++) {
		$Token = new Token(rtrim(fgets(STDIN)), " ");
		$inp_p = $Token->nextInt();
		$inp_c = $Token->nextInt();
		$inp_arr[$inp_p] = $inp_c;
	}
	if (arsort($inp_arr) === false) {
		print(-1);
		return;
	}
	$temp_counter = 1;
	$temp_point = 0;
	$temp = 1;
	$c = 0;
	foreach ($inp_arr as $as_key => $as_val) {
		if ($as_val == 0) break;

		$temp_point += $as_key;
		$temp_counter = $temp_counter - 1 + $as_val;
		$c++;
	}

	/*$len = $c;
	for ($i = 0; $i < $len; $i++) {
		$_inp_arr = array_shift($inp_arr);
	}
	*/
	$temp_arr = array();
	foreach ($inp_arr as $as_key => $as_val) {
		if ($as_val == 0) $temp_arr[$as_key] = $as_val;
	}

	//if (ksort($inp_arr) === false) {
	//if (krsort($inp_arr) === false) {
	if (krsort($temp_arr) === false) {
		print(-1);
		return;
	}

	$end = $temp_counter;
	//foreach ($inp_arr as $as_key => $as_val) {
	foreach ($temp_arr as $as_key => $as_val) {
		//if ($as_val == 0) print("count err");

		$temp_point += $as_key;
		$temp_counter--;

		if ($temp_counter == 0) break;
	}

	printf("%d", $temp_point);

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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 solve(){
	$Token = new Token(rtrim(fgets(STDIN)), " ");
	$inp_n = $Token->nextInt();
	$inp_arr = array();
	for ($i = 0; $i < $inp_n; $i++) {
		$Token = new Token(rtrim(fgets(STDIN)), " ");
		$inp_p = $Token->nextInt();
		$inp_c = $Token->nextInt();
		$inp_arr[$inp_p] = $inp_c;
	}
	if (arsort($inp_arr) === false) {
		//print(-1);
		//return;
	}
	$temp_counter = 1;
	$temp_point = 0;
	$temp = 1;
	//$c = 0;
	foreach ($inp_arr as $as_key => $as_val) {
		if ($as_val == 0) break;

		$temp_point += $as_key;
		$temp_counter = $temp_counter - 1 + $as_val;
		//$c++;
	}

	/*$len = $c;
	for ($i = 0; $i < $len; $i++) {
		$_inp_arr = array_shift($inp_arr);
	}
	*/
	$temp_arr = array();
	foreach ($inp_arr as $as_key => $as_val) {
		if ($as_val == 0) $temp_arr[$as_key] = $as_val;
	}

	//if (ksort($inp_arr) === false) {
	//if (krsort($inp_arr) === false) {
	if (krsort($temp_arr) === false) {
		//print(-1);
		//return;
	}

	$end = $temp_counter;
	//foreach ($inp_arr as $as_key => $as_val) {
	foreach ($temp_arr as $as_key => $as_val) {
		//if ($as_val == 0) print("count err");

		$temp_point += $as_key;
		$temp_counter--;

		if ($temp_counter == 0) break;
	}

	printf("%d", $temp_point);

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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 solve(){
	$Token = new Token(rtrim(fgets(STDIN)), " ");
	$inp_n = $Token->nextInt();
	$inp_arr1 = array();
	$inp_arr2 = array();
	for ($i = 0; $i < $inp_n; $i++) {
		$Token = new Token(rtrim(fgets(STDIN)), " ");
		$inp_p = $Token->nextInt();
		$inp_c = $Token->nextInt();
		if ($inp_c == 0) $inp_arr1[$inp_p] = $inp_c;
		else $inp_arr2[$inp_p] = $inp_c;
	}
	if (arsort($inp_arr2) === false) {
		//print(-1);
		//return;
	}
	$temp_counter = 1;
	$temp_point = 0;
	$temp = 1;
	//$c = 0;
	foreach ($inp_arr2 as $as_key => $as_val) {
		$temp_point += $as_key;
		$temp_counter = $temp_counter - 1 + $as_val;
		if ($temp_counter == 0) break;
	}
	if (krsort($inp_arr1) === false) {
		//print(-1);
		//return;
	}
	foreach ($inp_arr1 as $as_key => $as_val) {
		$temp_point += $as_key;
		$temp_counter--;

		if ($temp_counter == 0) break;
	}

	printf("%d", $temp_point);

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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 solve(){
	$Token = new Token(rtrim(fgets(STDIN)), " ");
	$inp_n = $Token->nextInt();
	$inp_arr = array();
	for ($i = 0; $i < $inp_n; $i++) {
		$Token = new Token(rtrim(fgets(STDIN)), " ");
		$inp_p = $Token->nextInt();
		$inp_c = $Token->nextInt();
		$inp_arr[$inp_p] = $inp_c;
	}
	if (arsort($inp_arr) === false) {
		print(-1);
		return;
	}
	$temp_counter = 1;
	$temp_point = 0;
	$temp = 1;
	$c = 0;
	foreach ($inp_arr as $as_key => $as_val) {
		if ($as_val == 0) break;

		$temp_point += $as_key;
		$temp_counter = $temp_counter - 1 + $as_val;
		$c++;
	}

	/*$len = $c;
	for ($i = 0; $i < $len; $i++) {
		$_inp_arr = array_shift($inp_arr);
	}
	*/
	$temp_arr = array();
	foreach ($inp_arr as $as_key => $as_val) {
		if ($as_val == 0) $temp_arr[$as_key] = $as_val;
	}

	//if (ksort($inp_arr) === false) {
	//if (krsort($inp_arr) === false) {
	if (krsort($temp_arr) === false) {
		print(-1);
		return;
	}

	$end = $temp_counter;
	//foreach ($inp_arr as $as_key => $as_val) {
	foreach ($temp_arr as $as_key => $as_val) {
		//if ($as_val == 0) print("count err");

		$temp_point += $as_key;
		$temp_counter--;
		printf("%d", $as_key);

		if ($temp_counter == 0) break;
	}

	printf("%d", $temp_point);

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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
$tc=readline();
while ($tc--)
 {
	  fscanf(STDIN,"%d %d",$a,$b);
	  echo (int)((abs($a-$b)+9)/10);
	  echo "\n";

 }

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     if($b <= $c)
     {
          print ceil(($c - $b) / 10) . "\n";
     }
     else
     {
          print ceil(($b - $c) / 10) . "\n";
     }
}
?>


<?php

$inp = fopen('php://stdin', 'rb');

fscanf($inp, '%d', $t);

while ($t--) {
    [
        $a,
        $b,
        $c,
        $d
    ] = fscanf($inp, '%d %d %d %d');

    $ad = $a * $d;
    $bc = $b * $c;

    if ($ad === $bc) {
        echo 0 .PHP_EOL;
    } elseif ($ad === 0 || $bc === 0) {
        echo 1 .PHP_EOL;
    } elseif ($ad % $bc === 0 || $bc % $ad === 0) {
        echo 1 .PHP_EOL;
    } else {
        echo 2 .PHP_EOL;
    }
}

<?php
function inputInt($sys)
{
    fscanf($sys, "%d", $n);
    return $n;
}

function inputArray($sys)
{
    fscanf($sys, "%[^\n]", $tempA);
    $arr = array_map('intval', preg_split('/ /', $tempA, -1, PREG_SPLIT_NO_EMPTY));
    return $arr;
}

$stdin = fopen('php://stdin', 'r');
$T = inputInt($stdin);
function solve($sys)
{
    $arr = inputArray($sys);

    $ad = $arr[0] * $arr[3];
    $bc = $arr[1] * $arr[2];

    if ($ad == $bc) {
        echo 0;
    }
    else if ($ad == 0 || $bc == 0) {
        echo 1;
    }
    else if ($bc > $ad && ($bc % $ad == 0)) {
        echo 1;
    }
    else if ($ad > $bc && ($ad % $bc == 0)) {
        echo 1;
    }
    else {
        echo 2;
    }
    echo "\n";
}
while ($T--) {
    solve($stdin);
}


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

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

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

  $r = ceil($k / 2);

  echo $n - $r.PHP_EOL;
  if ($n - $r != 0) {
    for ($j = $r; $j <= $n; $j++) {
      if ($j != $k) { echo $j.' '; }
    }
    echo PHP_EOL;
  }
}
?>


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

$op = 0;
$i = 0;
while($i < $n){
	if($status[$i] == 1){
		$op += 2;
		$i++;
		while($status[$i] == 1){
			$op++;
			$i++;
		}
	}else $i++;
}

if($op > 0)
	$op--;
echo $op;
?>


<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	$n = rtrim(fgets(STDIN));
	//$n = (int)rtrim(fgets($handle));
	$t = explode(" ",rtrim(fgets(STDIN)));
	//$t = explode(" ", rtrim(fgets($handle)));

	$sum = array_sum($t);

	if ($sum % 2 === 0) $half = (int)(array_sum($t) / 2);
	else $half = (int)(array_sum($t) / 2) + 1;

	$temp = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$temp += (int)$t[$i];
		if ($temp >= $half) {
			$pos = $i;
			break;
		}
	}

	for ($i = 0; $i < $pos; $i++) {
		$alice += (int)$t[$i];
	}
	if ($alice <= array_sum($t) - $alice - $t[$pos]) {
		$num = $pos + 1;
	} else {
		$num = $pos;
	}
	print($num. " ". ($n - $num));
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	//$n = (int)rtrim(fgets($handle));
	//$t = explode(" ", rtrim(fgets($handle)));

	$n = rtrim(fgets(STDIN));
	$t = explode(" ",rtrim(fgets(STDIN)));

	$sum = array_sum($t);
	$num = 0;

	for ($i = 0; $i < count($t); $i++)
	{
		$temp += $t[$i];
		if ($temp - $t[$i] <= $sum - $temp) $num++;
		else break;
	}

	print($num. " ". ($n - $num));
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	//$n = (int)rtrim(fgets($handle));
	//$t = explode(" ", rtrim(fgets($handle)));

	$n = rtrim(fgets(STDIN));
	$t = explode(" ",rtrim(fgets(STDIN)));

	$dp = array();
	for ($i = 0; $i < count($t); $i++) {
		$dp[$i] = $sum += $t[$i];
	}

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

		if ($dp[$i] - $t[$i] <= $sum - $dp[$i]) $num++;
		else break;

		print($temp);
	}
	print($num. " ". ($n - $num));
}
?>

<?php
function input()
{
    return rtrim(fgets(STDIN));
}

function input_array()
{
    return explode(' ', input());
}

$n = input();
$num = input_array();
$dp = array(0);
$sum = 0;
for ($i = 0; $i < $n; $i++)
{
    $dp[$i + 1] = $sum += $num[$i];
}
for ($i = 0; $i < $n; $i++)
{
    if ($dp[$i] <= $sum - $dp[$i + 1]) continue;
    else
    {
        echo $i . ' ' . ($n - $i) . "\n";
        exit();
    }
}
echo  "$n 0\n";
?>

<?php

error_reporting(0);

solve();

function solve(){

	$n = rtrim(fgets(STDIN));
	for ($i = 0; $i < $n; $i++)
	{
		$t[] = rtrim(fgets(STDIN));
	}

	$sum = array_sum($t);

	if ($sum % 2 === 0) $half = intval(array_sum($t) / 2);
	else $half = intval(array_sum($t) / 2) + 1;

	for ($i = 0; $i < $n; $i++)
	{
		$temp += $t[$i];
		if ($temp > $half) {
			$num = $i + 1;
			break;
		}
	}

	print($num. " ". $n - $num);
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	$n = rtrim(fgets(STDIN));
	//$n = (int)rtrim(fgets($handle));
	$t = str_split(rtrim(fgets(STDIN)));
	//$t = explode(" ", rtrim(fgets($handle)));

	$sum = array_sum($t);

	if ($sum % 2 === 0) $half = (int)(array_sum($t) / 2);
	else $half = (int)(array_sum($t) / 2) + 1;

	$temp = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$temp += (int)$t[$i];
		if ($temp >= $half) {
			$pos = $i;
			break;
		}
	}

	for ($i = 0; $i < $pos; $i++) {
		$alice += (int)$t[$i];
	}
	if ($alice < array_sum($t) - $alice - $t[$pos]) {
		$num = $pos + 2;
	} else {
		$num = $pos + 1;
	}

	print($num. " ". ($n - $num));
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	$n = rtrim(fgets(STDIN));
	//$n = (int)rtrim(fgets($handle));
	$t = str_split(rtrim(fgets(STDIN)));
	//$t = explode(" ", rtrim(fgets($handle)));

	$sum = array_sum($t);

	if ($sum % 2 === 0) $half = (int)(array_sum($t) / 2);
	else $half = (int)(array_sum($t) / 2) + 1;

	$temp = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$temp += (int)$t[$i];
		if ($temp >= $half) {
			$pos = $i;
			break;
		}
	}

	for ($i = 0; $i < $pos; $i++) {
		$alice += (int)$t[$i];
	}
	if ($alice < array_sum($t) - $alice - $t[$pos]) {
		$num = $pos;
	} else {
		$num = $pos-1;
	}

	print($num. " ". ($n - $num));
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	//$n = (int)rtrim(fgets($handle));
	//$t = explode(" ", rtrim(fgets($handle)));

	$n = rtrim(fgets(STDIN));
	$t = explode(" ",rtrim(fgets(STDIN)));

	$sum = array_sum($t);
	$num = 0;
	for ($i = 0; $i < count($t); $i++) {
		$temp += $t[$i];
		if ($temp - $t[$i] <= $sum - $temp) $num++;
		else break;

		print($temp);
	}
	print($num. " ". ($n - $num));
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	$n = rtrim(fgets(STDIN));
	//$n = (int)rtrim(fgets($handle));
	$t = str_split(rtrim(fgets(STDIN)));
	//$t = explode(" ", rtrim(fgets($handle)));

	$sum = array_sum($t);

	if ($sum % 2 === 0) $half = (int)(array_sum($t) / 2);
	else $half = (int)(array_sum($t) / 2) + 1;

	$temp = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$temp += (int)$t[$i];
		if ($temp >= $half) {
			$pos = $i;
			break;
		}
	}

	for ($i = 0; $i < $pos; $i++) {
		$alice += (int)$t[$i];
	}
	if ($alice > array_sum($t) - $alice - $t[$pos]) {
		$num = $pos + 1;
	} else {
		$num = $pos;
	}

	print($num. " ". ($n - $num));
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	$n = rtrim(fgets(STDIN));
	//$n = (int)rtrim(fgets($handle));
	$t = str_split(rtrim(fgets(STDIN)));
	//$t = explode(" ", rtrim(fgets($handle)));

	$sum = array_sum($t);

	if ($sum % 2 === 0) $half = (int)(array_sum($t) / 2);
	else $half = (int)(array_sum($t) / 2) + 1;

	$temp = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$temp += (int)$t[$i];
		if ($temp >= $half) {
			$pos = $i;
			break;
		}
	}

	for ($i = 0; $i < $pos; $i++) {
		$alice += (int)$t[$i];
	}
	if ($alice < array_sum($t) - $alice - $t[$pos]) {
		$num = $pos + 1;
	} else {
		$num = $pos;
	}

	print($num. " ". ($n - $num));
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	$n = rtrim(fgets(STDIN));
	//$n = (int)rtrim(fgets($handle));
	$t = explode(" ",rtrim(fgets(STDIN)));
	//$t = explode(" ", rtrim(fgets($handle)));

	$sum = array_sum($t);

	if ($sum % 2 === 0) $half = (int)(array_sum($t) / 2);
	else $half = (int)(array_sum($t) / 2) + 1;

	$temp = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$temp += (int)$t[$i];
		if ($temp >= $half) {
			$pos = $i;
			break;
		}
	}

	for ($i = 0; $i < $pos; $i++) {
		$alice += (int)$t[$i];
	}
	if ($alice < array_sum($t) - $alice - $t[$pos]) {
		$num = $pos + 1;
	} else {
		$num = $pos;
	}
	print($num. " ". ($n - $num));
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	$n = rtrim(fgets(STDIN));
	//$n = (int)rtrim(fgets($handle));
	$t = str_split(rtrim(fgets(STDIN)));
	//$t = explode(" ", rtrim(fgets($handle)));

	$sum = array_sum($t);

	if ($sum % 2 === 0) $half = (int)(array_sum($t) / 2);
	else $half = (int)(array_sum($t) / 2) + 1;

	$temp = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$temp += (int)$t[$i];
		if ($temp > $half) {
			$num = $i + 1;
			break;
		}
	}

	print($num. " ". ($n - $num));
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	$n = rtrim(fgets(STDIN));
	for ($i = 0; $i < $n; $i++)
	{
		$t[] = rtrim(fgets(STDIN));
	}

	$sum = array_sum($t);

	if ($sum % 2 === 0) $half = intval(array_sum($t) / 2);
	else $half = intval(array_sum($t) / 2) + 1;

	for ($i = 0; $i < $n; $i++)
	{
		$temp += $t[$i];
		if ($temp > $half) {
			$num = $i + 1;
			break;
		}
	}

	printf($num. " ". $n - $num);
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	//$handle = @fopen("input.txt", "r");
	$n = rtrim(fgets(STDIN));
	//$n = (int)rtrim(fgets($handle));
	$t = explode(rtrim(fgets(STDIN)));
	//$t = explode(" ", rtrim(fgets($handle)));

	$sum = array_sum($t);

	if ($sum % 2 === 0) $half = (int)(array_sum($t) / 2);
	else $half = (int)(array_sum($t) / 2) + 1;

	$temp = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$temp += (int)$t[$i];
		if ($temp >= $half) {
			$pos = $i;
			break;
		}
	}

	for ($i = 0; $i < $pos; $i++) {
		$alice += (int)$t[$i];
	}
	if ($alice < array_sum($t) - $alice - $t[$pos]) {
		$num = $pos + 1;
	} else {
		$num = $pos;
	}
	print($num. " ". ($n - $num));
}
?>


<?php

$n = trim(fgets(STDIN));
$map = array();
for ($i = 0; $i < $n; $i++) {
	$str = substr(trim(fgets(STDIN)), 7);
	$slashPost = strpos($str, '/');
	if ($slashPost !== false) {
		$host = substr($str, 0, $slashPost);
		$path = substr($str, $slashPost);
	} else {
		$host = $str;
		$path = '';
	}
	if (empty($map[$host])) {
		$map[$host] = array();
	}
	$map[$host][$path] = true;
}
$hostsMap = array();
foreach ($map as $host => $urls) {
	$urls = array_keys($urls);
	sort($urls);
	$urlKey = implode('#', $urls);
	if (empty($hostsMap[$urlKey])) {
		$hostsMap[$urlKey] = array();
	}
	$hostsMap[$urlKey][] = $host;
}
unset($map);

foreach ($hostsMap as $k => $hosts) {
	if (count($hosts) < 2) {
		unset($hostsMap[$k]);
	}
}
echo count($hostsMap) . "\n";
foreach ($hostsMap as $hosts) {
	foreach ($hosts as $host) {
		echo 'http://' . $host . ' ';
	}
	echo "\n";
}

<?php
  $data = file_get_contents("php://stdin");

  $data = preg_split('#\s+#', trim($data));
  $n = intval($data[0]);
  $server = array();
  for($i=0;$i<$n;$i++)
  {
    preg_match('#(http://[^/]+)([^\s]*)#', $data[$i+1], $match);
    $server[$match[1]][] = $match[2];
  }
  $groups = array();
  foreach($server as $a=>$b)
  {
    $x = array_unique($b); sort($x);
    $groups[md5(implode("|", $x), true)][] = $a;
  }
  $n = 0;
  foreach($groups as $a)
  {
    if (count($a) > 1) $n ++;
  }
  echo $n."\n";
  foreach($groups as $a)
  {
    if (count($a) > 1) echo implode(" ", $a)."\n";
  }

?>

<?php

$n = fgets(STDIN);

$separated = [];
$joined = [];
$ans = [];

for ($i = 0; $i < $n; $i++) {
	$line = trim(fgets(STDIN));
	preg_match('/http:\/\/[a-z.]+/', $line, $domain);
	$path = str_replace($domain[0], '', $line);
	$separated[$domain[0]][] = $path;
}

foreach ($separated as $domain => $paths) {
	$separated[$domain] = array_unique($paths);
	sort($separated[$domain]);
}

foreach ($separated as $domain => $paths) {
	$paths = implode('#', $paths);
	$joined[$paths][] = $domain;
}

foreach ($joined as $paths => $domains) {
	if (count($domains) > 1) {
		$ans[] = $domains;
	}
}

echo count($ans) . "\n";

foreach ($ans as $domains) {
	echo implode(' ', $domains) . "\n";
}

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

function get_int() {
	global $stdin;
	return (int) fgets($stdin);
}

function get_line() {
	global $stdin;
	return (string) rtrim(fgets($stdin));
}

$format = "/(http:\/\/)([^\/]+)(\/(.*))?/";
//          ^1         ^2      ^3 ^4

$n = 0; $m = 0; $paths = array(); $groups = array();

// Main code

$n = get_int(); $m = 0;

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

	$matches = null;

	if (!preg_match($format, $line, $matches))
		die("Wrong format");

	$domain = $matches[2];
	$path = $matches[3];

	if (!isset($path))
		$path = '';

	if (!isset($paths[$domain]))
		$paths[$domain] = array();
	array_push($paths[$domain], $path);
}

foreach ($paths as $key => $value) {
	sort($value);

	$vlen = count($value);
	$array = array($value[0]); $size = 1;

	for ($i = 1; $i < $vlen; $i++) {
		if ($array[$size - 1] != $value[$i])
			$array[$size++] = $value[$i];
	}

	$fullpath = implode('#', $array) . '#';

	if (!isset($groups[$fullpath]))
		$groups[$fullpath] = array();

	array_push($groups[$fullpath], $key);
}

foreach ($groups as $value) {
	if (count($value) > 1)
		$m++;
}

print($m . "\n");

foreach ($groups as $key => $value) {
	$len = count($value);
	if ($len > 1) {
		for ($i = 0; $i < $len; $i++) {
			print('http://' . $value[$i] . ' ');
		}
		print("\n");
	}
}
?>

<?php
  $data = file_get_contents("php://input");

  $data = preg_split('#\s+#', trim($data));
  $n = intval($data[0]);
  $server = array();
  for($i=0;$i<$n;$i++)
  {
    preg_match('#(http://[^/]+)([^\s]*)#', $data[$i+1], $match);
    $server[$match[1]][] = $match[2];
  }
  $groups = array();
  foreach($server as $a=>$b)
  {
    $x = array_unique($b); sort($x);
    $groups[md5(implode("|", $x), true)][] = $a;
  }
  $n = 0;
  foreach($groups as $a)
  {
    if (count($a) > 1) $n ++;
  }
  echo $n."\n";
  foreach($groups as $a)
  {
    if (count($a) > 1) echo implode(" ", $a)."\n";
  }

?>

<?php

$n = fgets(STDIN);

$separated = [];
$joined = [];
$ans = [];

for ($i = 0; $i < $n; $i++) {
	$line = trim(fgets(STDIN));
	preg_match('/http:\/\/[a-z.]+/', $line, $domain);
	$path = str_replace($domain[0], '', $line);
	$separated[$domain[0]][] = $path;
}

foreach ($separated as $domain => $paths) {
	$separated[$domain] = array_unique($paths);
	sort($separated[$domain]);
}

foreach ($separated as $domain => $paths) {
	$paths = implode('', $paths);
	$joined[$paths][] = $domain;
}

foreach ($joined as $paths => $domains) {
	if (count($domains) > 1) {
		$ans[] = $domains;
	}
}

echo count($ans) . "\n";

foreach ($ans as $domains) {
	echo implode(' ', $domains) . "\n";
}


<?php
    //init
    $a=[];
    $stime=getMillisecond();
    fscanf(STDIN, "%d%d", $n, $m);
    // $n=2;
    // $m=1;

    function getMillisecond() {
        list($t1, $t2) = explode(' ', microtime());
        return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
    }

    function swap(&$a,&$b){
        $temp = $a;
        $a = $b;
        $b = $temp;
    }

    function check($i){
        global $m,$a;
        if ($i%$m!=0) if (abs($a[$i]-$a[$i-1])==1||abs($a[$i]-$a[$i-1])==$m) return true;
        if ($i>=$m) if (abs($a[$i]-$a[$i-$m])==1||abs($a[$i]-$a[$i-$m])==$m) return true;
        return 0;
    }

    foreach(range(1, $n*$m) as $temp) $a[]=$temp;
    $ok=0;
    while (getMillisecond()-$stime < 1000) {
        shuffle($a);
        $f=0;
        foreach(range(0, $n*$m-1) as $i){
            $cnt=0;
            while (check($i) && $cnt<=100) {
                if ($i < $n*$m-1) swap($a[$i], $a[rand()%($n*$m-$i-1)+$i+1]);
                else $cnt=1e9;
                $cnt++;
            }
            if ($cnt>100) {
                $f=1;
                break;
            }
        }
        if($f) continue;
        $ok=1;
        echo "YES\n";
        foreach(range(1, $n) as $i){
            foreach (range(0, $m-1) as $j) {
                echo $a[($i-1)*$m+$j];
                echo " ";
            }
            echo "\n";
        }
        break;
    }
    if (!$ok) echo "NO\n";
    return 0;

<?php
    //init
    $a=[];
    $stime=microtime(true);
    fscanf(STDIN, "%d%d", $n, $m);

    function swap(&$a,&$b){
        $temp = $a;
        $a = $b;
        $b = $temp;
    }

    function check($i){
        global $m,$a;
        if ($i%$m!=0) if (abs($a[$i]-$a[$i-1])==1||abs($a[$i]-$a[$i-1])==$m) return true;
        if ($i>=$m) if (abs($a[$i]-$a[$i-$m])==1||abs($a[$i]-$a[$i-$m])==$m) return true;
        return 0;
    }

    foreach(range(1, $n*$m) as $temp) $a[]=$temp;
    $ok=0;
    while (microtime(true)-$stime < 1) {
        shuffle($a);
        $f=0;
        foreach(range(0, $n*$m-1) as $i){
            $cnt=0;
            while (check($i)&&$cnt<=100) {
                if ($i < $n*$m-1) swap($a[$i], $a[rand()%($n*$m-$i-1)+$i+1]);
                else $cnt=1e9;
                $cnt++;
            }
            if ($cnt>100) {
                $f=1;
                break;
            }
        }
        if($f) continue;
        $ok=1;
        echo "YES\n";
        foreach(range(1, $n) as $i){
            foreach (range(0, $m-1) as $j) {
                echo $a[($i-1)*$m+$j];
                echo " ";
            }
            echo "\n";
        }
        break;
    }
    if (!$ok) echo "NO\n";
    return 0;


<?php
function gcd($x, $y) {
    if($y > $x) {
        $temp1 = $y;
        $y = $x;
        $x = $temp1;
    }

    if($x == 0 && $y == 0) return 1;
    if ($x == 0) return $y;
    if ($y == 0) return $x;
    if ($x < 0) $x = -$x;
    if ($y < 0) $y = -$y;
    if ($x == $y) return $x;
    while($y > 0) {
        $temp2 = $y;
        $y = $x % $y;
        $x = $temp2;
    }
    return $x;
}

function lcm($x, $y) {
    return ($x * $y)/gcd($x, $y);
}

function primeCheck($number){
    if ($number == 1)
    return 0;
    for ($i = 2; $i <= $number/2; $i++){
        if ($number % $i == 0)
            return 0;
    }
    return 1;
}

$t = (int)readline();
$input = array();
for($k = 0; $k < $t; $k++) {
    $input[] = explode(' ',readline());
}
foreach($input as $n) {
    $out = array(-1,-1);

    if ($n[0] * 2 <= $n[1]) $out = array($n[0], $n[0]*2);
    echo $out[0] . ' ' . $out[1] . "\n";
}

<?php
function gcd($x, $y) {
    if($y > $x) {
        $temp1 = $y;
        $y = $x;
        $x = $temp1;
    }

    if($x == 0 && $y == 0) return 1;
    if ($x == 0) return $y;
    if ($y == 0) return $x;
    if ($x < 0) $x = -$x;
    if ($y < 0) $y = -$y;
    if ($x == $y) return $x;
    while($y > 0) {
        $temp2 = $y;
        $y = $x % $y;
        $x = $temp2;
    }
    return $x;
}

function lcm($x, $y) {
    return ($x * $y)/gcd($x, $y);
}

function primeCheck($number){
    if ($number == 1)
    return 0;
    for ($i = 2; $i <= $number/2; $i++){
        if ($number % $i == 0)
            return 0;
    }
    return 1;
}

$t = (int)readline();
$input = array();
for($k = 0; $k < $t; $k++) {
    $input[] = explode(' ',readline());
}
foreach($input as $n) {
    $out = array(-1,-1);
    $break = false;
    for($i = $n[0]; $i < $n[1]; $i++) {
        if(($i % 2) != 0 && $i+1 != $n[1] && $i != 1) $i++;
        for($j = $i+1; $j <= $n[1]; $j++) {
            if(lcm($i, $j) >= $n[0] && lcm($i, $j) <= $n[1]) {
                $out = array($i, $j);
                $break = true;
                break;
            }
        }
        if($break) break;
    }
    echo $out[0] . ' ' . $out[1] . "\n";
}

<?php
function gcd($x, $y) {
    if($y > $x) {
        $temp1 = $y;
        $y = $x;
        $x = $temp1;
    }

    if($x == 0 && $y == 0) return 1;
    if ($x == 0) return $y;
    if ($y == 0) return $x;
    if ($x < 0) $x = -$x;
    if ($y < 0) $y = -$y;
    if ($x == $y) return $x;
    while($y > 0) {
        $temp2 = $y;
        $y = $x % $y;
        $x = $temp2;
    }
    return $x;
}

function lcm($x, $y) {
    return ($x * $y)/gcd($x, $y);
}

function primeCheck($number){
    if ($number == 1)
    return 0;
    for ($i = 2; $i <= $number/2; $i++){
        if ($number % $i == 0)
            return 0;
    }
    return 1;
}

$t = (int)readline();
$input = array();
for($k = 0; $k < $t; $k++) {
    $input[] = explode(' ',readline());
}
foreach($input as $n) {
    $out = array(-1,-1);
    $break = false;
    for($i = $n[0]; $i < $n[1]; $i++) {
        if(($i % 2) != 0 && $i+1 != $n[1]) $i++;
        for($j = $i+1; $j <= $n[1]; $j++) {
            if(lcm($i, $j) >= $n[0] && lcm($i, $j) <= $n[1]) {
                $out = array($i, $j);
                $break = true;
                break;
            }
        }
        if($break) break;
    }
    echo $out[0] . ' ' . $out[1] . "\n";
}

<?php
function gcd($x, $y) {
    if($y > $x) {
        $temp1 = $y;
        $y = $x;
        $x = $temp1;
    }

    if($x == 0 && $y == 0) return 1;
    if ($x == 0) return $y;
    if ($y == 0) return $x;
    if ($x < 0) $x = -$x;
    if ($y < 0) $y = -$y;
    if ($x == $y) return $x;
    while($y > 0) {
        $temp2 = $y;
        $y = $x % $y;
        $x = $temp2;
    }
    return $x;
}

function lcm($x, $y) {
    return ($x * $y)/gcd($x, $y);
}

function primeCheck($number){
    if ($number == 1)
    return 0;
    for ($i = 2; $i <= $number/2; $i++){
        if ($number % $i == 0)
            return 0;
    }
    return 1;
}

$t = (int)readline();
$input = array();
for($k = 0; $k < $t; $k++) {
    $input[] = explode(' ',readline());
}
foreach($input as $n) {
    $out = array(-1,-1);
    $break = false;
    for($i = $n[0]; $i < $n[1]; $i++) {
        if(($i % 2) != 0) $i++;
        for($j = $i+1; $j <= $n[1]; $j++) {
            if(lcm($i, $j) >= $n[0] && lcm($i, $j) <= $n[1]) {
                $out = array($i, $j);
                $break = true;
                break;
            }
        }
        if($break) break;
    }
    echo $out[0] . ' ' . $out[1] . "\n";
}

<?php
function gcd($x, $y) {
    if($y > $x) {
        $temp1 = $y;
        $y = $x;
        $x = $temp1;
    }

    if($x == 0 && $y == 0) return 1;
    if ($x == 0) return $y;
    if ($y == 0) return $x;
    if ($x < 0) $x = -$x;
    if ($y < 0) $y = -$y;
    if ($x == $y) return $x;
    while($y > 0) {
        $temp2 = $y;
        $y = $x % $y;
        $x = $temp2;
    }
    return $x;
}

function lcm($x, $y) {
    return ($x * $y)/gcd($x, $y);
}

$t = (int)readline();
$input = array();
for($k = 0; $k < $t; $k++) {
    $input[] = explode(' ',readline());
}
print_r($input);
foreach($input as $n) {
    $out = array(-1,-1);
    $break = false;
    for($i = (int)$n[0]; $i < (int)$n[1]; $i++) {
        for($j = $i+1; $j <= (int)$n[1]; $j++) {
            if(lcm($i, $j) >= (int)$n[0] && lcm($i, $j) <= (int)$n[1]) {
                $out = array($i, $j);
                $break = true;
                break;
            }
        }
        if($break) break;
    }
    echo $out[0] . ' ' . $out[1] . "\n";
}


<?php
$nm= explode(" ",strval(trim(fgets(STDIN))));
$n = intval($nm[0]);
$m = intval($nm[1]);
$result = "YES";
$prevColor="";
for ($i=0; $i < $n; $i++) {

	$line = str_split(trim(fgets(STDIN)));
	if(count($line)!=$m) {echo "NO";die();}
	if($line[0]==$prevColor && $prevColor!="") {echo "NO";die();}
	foreach ($line as $l) {
		if($l!=$line[0]) {echo "NO";die();}
	}
	$prevColor = $line[0];
}
echo $result;

<?php

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

    $n_m = explode(" ", fgets($stdin));
    $n = $n_m[0];
    $m = $n_m[1];

    for($i=0; $i<$n; ++$i){
        $matrix[$i] = fgets($stdin);
    }

    for($i=0;$i<$n;++$i){
        for($j=1;$j<$m;++$j){
            if($matrix[$i][$j-1] != $matrix[$i][$j]) {
                fputs($stdout, "NO");
                return;
            }
        }
        if(($i!=0)&&($matrix[$i][0] == $matrix[$i-1][0])){
            fputs($stdout, "NO");
            return;
        }
    }
    fputs($stdout, "YES");
?>

<?php

function debug($data, $die = true) {
    echo '<pre>';

    if (is_array($data)) {
        print_r($data);
    } else {
        var_dump($data);
    }

    if ($die) {
        die();
    }

    echo '</pre>';
}

function stdin() {
    $stdin = @fopen('data.txt', 'r');
    if (!$stdin) {
        $stdin = fopen('php://stdin', 'r');
    }

    return $stdin;
}

function g() {
    global $stdin;
    return trim(fgets($stdin));
}

$stdin = stdin();
/****************************************************** Solving block *****************************************************/
list($n, $m) = explode(' ', g());

$flag = true;
$temp = -1;
for ($i = 0; $i < $n; $i++) {
    $line = g();
    $array = str_split($line);
    $sum = array_sum($array);

    if($sum != substr($line, 0, 1) * $m || $temp == $sum) {
        $flag = false;
    }

    $temp = $sum;
}

echo $flag ? 'YES' : 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                break;
            }

        }
        if ($one_color == false) break;
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}

if (($cols == 1) && (count($stripes) == 1)) echo 'YES';
else if (count($stripes) == 1) {
    if (oneColor($stripes)) echo 'YES';
    else echo 'NO';
}
else if ($cols == 1){
    if (alt($stripes)) echo 'YES';
    else echo 'NO';
}
else if (oneColor($stripes) && alt($stripes)) echo 'YES';
    else echo 'NO';

?>

<?php
list($n,$m) = explode(' ',rtrim(fgets(STDIN)));
$prev=-1;
for ($i=0;$i<$n;$i++) {
  $line=rtrim(fgets(STDIN));
  if ($prev==$line[0]) {
    echo "NO\n";
    exit(0);
  }
  $prev=$line[0];
  for ($j=1;$j<$m;$j++) {
    if ($line[$j-1]!=$line[$j]) {
      echo "NO\n";
      exit(0);
    }
  }
}
echo "YES\n";

<?php

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

    $n_m = fgets($stdin);
    $n = $n_m[0];
    $m = $n_m[2];

    for($i=0; $i<$n; ++$i){
        $matrix[$i] = fgets($stdin);
    }

    for($i=0;$i<$n;++$i){
        for($j=1;$j<$m;++$j){
            if($matrix[$i][$j-1] != $matrix[$i][$j]) {
                fputs($stdout, "NO");
                return;
            }
        }
        if(($i!=0)&&($matrix[$i][0] == $matrix[$i-1][0])){
            fputs($stdout, "NO");
            return;
        }
    }
    fputs($stdout, "YES");
?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                break;
            }

        }
        if ($one_color == false) break;
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}
//if (!oneColor($stripes)) echo "color failure";
//if (!alt($stripes)) echo "shift failure";
/*
function oneElem($array) {
    foreach ($array as $value) {
        if (strlen($value) == 1) $one = true;
        else {
            $one = false;
            break;
        }
    }
    return $one;
}
*/

if (count($stripes) == 1) {
    if (oneColor($stripes)) echo 'YES';
    else echo 'NO';
}
else if ($cols == 1){//(oneElem($stripes)) {
    if (alt($stripes)) echo 'YES';
    else echo 'NO';
}
else if (oneColor($stripes) && alt($stripes)) echo 'YES';
    else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

//print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                break;
            }

        }
        if ($one_color == false) break;
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}
//if (!oneColor($stripes)) echo "color failure";
//if (!alt($stripes)) echo "shift failure";

if (count($stripes) == 1) {
    if (oneColor($stripes)) echo 'YES';
    else echo 'NO';
    }
else if (oneColor($stripes) && alt($stripes)) echo 'YES';
    else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

//$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                break;
            }

        }
        if ($one_color == false) break;
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}
//if (!oneColor($stripes)) echo "color failure";
//if (!alt($stripes)) echo "shift failure";
/*
function oneElem($array) {
    foreach ($array as $value) {
        if (strlen($value) == 1) $one = true;
        else {
            $one = false;
            break;
        }
    }
    return $one;
}
*/

if (count($stripes) == 1) {
    if (oneColor($stripes)) echo 'YES';
    else echo 'NO';
}
else if ($cols == 1){//(oneElem($stripes)) {
    if (alt($stripes)) echo 'YES';
    else echo 'NO';
}
else if (oneColor($stripes) && alt($stripes)) echo 'YES';
    else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                break;
            }

        }
        if ($one_color == false) break;
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}
//if (!oneColor($stripes)) echo "color failure";
//if (!alt($stripes)) echo "shift failure";
/*
function oneElem($array) {
    foreach ($array as $value) {
        if (strlen($value) == 1) $one = true;
        else {
            $one = false;
            break;
        }
    }
    return $one;
}
*/

if (count($stripes) == 1) {
    if (oneColor($stripes)) echo 'YES';
    else echo 'NO';
}
else if ($cols == 1){//(oneElem($stripes)) {
    if (alt($stripes)) echo 'YES';
    else echo 'NO';
}
else if (oneColor($stripes) && alt($stripes)) echo 'YES';
    else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

//print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            //if ($one_color == true) echo "True";
            else {
                $one_color = false;
                //if ($one_color == false) echo "false";
                break;
            }

        }
        if ($one_color == false) break;
    }
    if ($one_color == true) echo "True";
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}
if (!oneColor($stripes)) echo "color failure";
if (!alt($stripes)) echo "shift failure";
if (oneColor($stripes) && alt($stripes)) echo 'YES';
else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

//print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                break;
            }
        }
        if (one_color == false) break;
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}

//if (!alt($stripes)) echo "shift failure";
if (oneColor($stripes) && alt($stripes)) echo 'YES';
else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

//print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                break;
            }
            if ($one_color == false) break;
        }
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}

//if (!alt($stripes)) echo "shift failure";
if (oneColor($stripes) && alt($stripes)) echo 'YES';
else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                break;
            }

        }
        if ($one_color == false) break;
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}

if (count($stripes) == 1) {
    if (oneColor($stripes)) echo 'YES';
    else echo 'NO';
}
else if ($cols == 1){//(oneElem($stripes)) {
    if (alt($stripes)) echo 'YES';
    else echo 'NO';
}
else if (($cols == 1) && count($stripes) == 1) echo 'YES';
else if (oneColor($stripes) && alt($stripes)) echo 'YES';
    else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

//print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                //break;
               // goto a;
            }
            if ($one_color == false) break;
        }
    }
     return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}

//if (!alt($stripes)) echo "shift failure";
if (oneColor($stripes) && alt($stripes)) echo 'YES';
else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

//print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                break;
            }
        }
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}

//if (!alt($stripes)) echo "shift failure";
if (oneColor($stripes) && alt($stripes)) echo 'YES';
else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

//print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                break;
            }
        }
        break;
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}

//if (!alt($stripes)) echo "shift failure";
if (oneColor($stripes) && alt($stripes)) echo 'YES';
else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                break;
            }

        }
        if ($one_color == false) break;
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}
//if (!oneColor($stripes)) echo "color failure";
//if (!alt($stripes)) echo "shift failure";

if (count($stripes) == 1) {
    if (oneColor($stripes)) echo 'YES';
    else echo 'NO';
    }
else if (oneColor($stripes) && alt($stripes)) echo 'YES';
    else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

//print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            //if ($one_color == true) echo "True";
            else {
                $one_color = false;
                //if ($one_color == false) echo "false";
                break;
            }

        }
        if ($one_color == false) break;
    }
    return $one_color;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}
//if (!oneColor($stripes)) echo "color failure";
//if (!alt($stripes)) echo "shift failure";
if (oneColor($stripes) && alt($stripes)) echo 'YES';
else echo 'NO';

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$stripes = array();

for ($i = 0; $i < $data[0]; $i++) {
    $stripes[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

//print_r($stripes);

function oneColor($array) {
    foreach ($array as $value) {
        for ($i = 1; $i < strlen($value); $i++) {
            if ($value[$i] == $value[$i-1]) $one_color = true;
            else {
                $one_color = false;
                //break;
            }

        }
        if ($one_color == false) break;
    }
    return $onecolor;
}

function alt($array) {
    for ($i = 1; $i < count($array); $i++) {
        if ($array[$i-1][0] != $array[$i][0]) {
            $shift = true;
        }
        else {
            $shift = false;
            break;
        }
    }
    return $shift;
}

//if (!alt($stripes)) echo "shift failure";
if (oneColor($stripes) && alt($stripes)) echo 'YES';
else echo 'NO';

?>


<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";
define("INTMAXVALUE",     2147483646);

   $t = IO::getInt();
//   $point = ord('a') + ord('b') ;

   for($q=0; $q <$t; $q++) {
       $ans = 0;
       $n = IO::getInt();

       $len = strlen($n);
        if($len == 2) {
             $ans = $n[1];
        } else {
             $ans = $n[0];
             for($i=1; $i<$len; $i++) {
                  if($ans > $n[$i]) {
                       $ans = $n[$i];
                  }
             }
        }
       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)
     {
         if(is_array($s)) {
             echo implode( ' ', $s), PHP_EOL;
         } else {
             echo $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;
     }
 }

 class Algor {
    public static function isPrime($n) {
         $d = 2;
         while ($n % $d != 0) {
         $d += 1;
         }

        return $d == $n;
    }

     public static function fabicon($n, $a) {
         if($n <= 1) {
             return $a[$n];
         }
         for($i=2; $i<=$n; $i++) {
             $a[$i] = $a[$i-1] + $a[$i-2];
         }

         return $a[$n];
     }

     function getRotate($a, $s, $e, $ind) {
         $ar = [];
         for ($i= $s; $i<=$e; $i++) {
             $ar[$i] = $a[$i];
             $j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
             // echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
             $a[$i] = $j < $i ? $ar[$j] : $a[$j];
         }
         return $a;
     }

}

class bigOperation {
    public static function  isBigNumber($n)
    {
        return bccomp($n, INTMAXVALUE) == 1;
    }
    // bcadd — Сложить 2 числа произвольной точности
    public static function  bcAdd($x, $y)
    {
        return bcadd($x, $y);
    }
// bccomp — Сравнение двух чисел произвольной точности
//return 1 if x>y, 0= x==y, -1 x < y
    public static function  bcComp($x, $y)
    {
        return bccomp($x, $y);
    }
// bcdiv — Операция деления для чисел произвольной точности
    public static function  bcDiv($x, $y)
    {
        return bcdiv($x, $y);
    }
// bcmod — Получает остаток от деления чисел с произвольной точностью
    public static function  bcMod($x, $y)
    {
        return bcmod($x, $y);
    }
// bcmul — Умножение двух чисел с произвольной точностью
    public static function  bcMul($x, $y)
    {
        return bcmul($x, $y);
    }
// bcpow — Возведение в степень чисел с произвольной точностью
    public static function  bcPow($x, $y)
    {
        return bcpow($x, $y);
    }
// bcpowmod — Возводит одно число в степень другого и возвращает остаток от деления результата на третье число
// bcscale — Задает количество чисел после десятичной точки по умолчанию для всех bc math функций.
// bcsqrt — Извлекает квадратный корень из числа с произвольной точностью
    public static function  bcSqrt($x, $y)
    {
        return bcsqrt($x, $y);
    }
// bcsub — Вычитает одно число с произвольной точностью из другого
    public static function  bcSub($x, $y)
    {
        return bcsub($x, $y);
    }
    public static function getMaxValue($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    public static function getMinValue($x, $y) {
        return bccomp($x, $y) == 1 ? $y : $x;
    }

    public static function getDareje($n, $k) {
        if($k == 0) {
            return 1;
        }
        return bcmul($n, self::getDareje($n, $k-1));
    }
}

class Sorting
{
    public static function mergeSort($aArray) {
        if(count($aArray) <= 1) {
            return $aArray;
        }
        $aLeft = [];
        $aRight = [];
        $n =floor(count($aArray) / 2);
        for($i = 0; $i <$n; $i++) {
            $aLeft[] = $aArray[$i];
        }
        for($i = $n; $i <count($aArray); $i++) {
            $aRight[] = $aArray[$i];
        }

        return self::merge(self::mergeSort($aLeft), self::mergeSort($aRight));
    }

    public static function merge($aLeft, $aRight) {
        $aResult = [];
        $iL = 0;
        $iR = 0;

        while($iL < count($aLeft) && $iR < count($aRight)) {
            if($aLeft[$iL] <= $aRight[$iR]) {
                $aResult[] = $aLeft[$iL];
                $iL++;
            } else {
                $aResult[] = $aRight[$iR];
                $iR++;
            }
        }

        while($iL < count($aLeft)) {
            $aResult[] = $aLeft[$iL];
            $iL++;
        }
        while($iR < count($aRight)) {
            $aResult[] = $aRight[$iR];
            $iR++;
        }

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
    $t = trim(fgets(STDIN));
    for($n = 1; $n <= $t; $n++) {
        $s = trim(fgets(STDIN));

        $a = str_split($s);
        if (count($a) == 2) {
            echo $a[1] . PHP_EOL;
        } else {
            sort($a);
            echo $a[0] . PHP_EOL;
        }
    }
?>


<?php

while (FALSE !== ($line = fgets(STDIN))) {

    $stat = array();
    $unrecoverableFlag = false;

    for($i = 1; $i <= $line; $i++){
        $cupValue = fgets(STDIN);

        if($unrecoverableFlag === true){
            continue;
        }

        $cupValue = trim($cupValue);

        if($stat[$cupValue]){
            $stat[$cupValue][0] = $i;    //line number
            $stat[$cupValue][1]++;       //count
        }else{
            $stat[$cupValue] = array($i, 1);
        }

        if(count($stat) > 3) {
            $unrecoverableFlag = true;
        }
    } //end of input taking and general statistics part ..

    $count = count($stat);

    if($unrecoverableFlag){
        echo 'Unrecoverable configuration.' . PHP_EOL;
    }

    if($count == 2){
        if($line == 2){
            //very special case ..
            $sorted = array_keys($stat);
            sort($sorted);
            $cupOneValue = $sorted[0];
            $cupTwoValue = $sorted[1];

            if( $stat[$cupOneValue][1] == 1 && $stat[$cupTwoValue][1] == 1){

                $diff = $cupTwoValue - $cupOneValue;
                if($diff % 2 == 1){
                    echo 'Unrecoverable configuration.' . PHP_EOL;
                }else{
                    $volum = $diff / 2;

                    echo $volum . ' ml. from cup #' . $stat[$cupOneValue][0] .
                       ' to cup #' . $stat[$cupTwoValue][0] . '.' . PHP_EOL;
                }

            }else{
                echo 'Unrecoverable configuration.' . PHP_EOL;
            }
        }else{
            echo 'Unrecoverable configuration.' . PHP_EOL;
        }
    }

    if($count == 1) {
        echo 'Exemplary pages.' . PHP_EOL;
    }

    if($count == 3){

        $sorted = array_keys($stat);

        sort($sorted);

        $cupOneValue = $sorted[0];
        $cupTwoValue = $sorted[2];

        if( $stat[$cupOneValue][1] == 1 && $stat[$cupTwoValue][1] == 1){

           $volum = ($cupTwoValue - $cupOneValue) / 2;

            if($volum  == ($sorted[1] - $cupOneValue)){
                echo $volum . ' ml. from cup #' . $stat[$cupOneValue][0] .
                   ' to cup #' . $stat[$cupTwoValue][0] . '.' . PHP_EOL;
            }else{
                echo 'Unrecoverable configuration.' . PHP_EOL;
            }

        }else{
            echo 'Unrecoverable configuration.' . PHP_EOL;
        }
    }
}

<?php

    fscanf(STDIN, "%d", $n);
    for($i=0;$i<$n;$i++)
    {
        fscanf(STDIN, "%d", $a);
        $graf[$i]=$a;
    }
    $graf1=$graf;
    sort($graf1, SORT_NUMERIC);asort($graf, SORT_NUMERIC);
    if($n==1){printf("%s\n", "Exemplary pages.");exit;}

    if($graf1[0]==$graf1[$n-1])
    {
        printf("%s\n", "Exemplary pages.");
        exit;
    }else{

        if(((array_sum($graf1)/$n)==ceil(array_sum($graf1)/$n) and ($graf1[0]+$graf1[$n-1])==(2*$graf1[1])) or ((($graf1[0]+$graf1[$n-1])/2)==ceil(($graf1[0]+$graf1[$n-1])/2) and $n==2))
        {
            reset($graf);
            current($graf);
            $w1=key($graf);
            end($graf);
            $w2=key($graf);
            printf("%d ml. from cup #%d to cup #%d.\n", ($graf1[$n-1]-$graf1[0])/2, $w1+1, $w2+1);exit;
        }else{
            printf("%s\n", "Unrecoverable configuration.");exit;
        }
    }

?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt = "5
// 270
// 250
// 250
// 230
// 250
// ";
$text = explode("\n",$datatxt);
$total = intval($text[0]);
unset($text[0]);
foreach($text as $key => $value) {
if(empty($value)){
unset($text[$key]);
}
}
$cups = array_map('intval', $text);
$sum = array_sum($cups);
if(($sum%$total) !=0)
{
echo "Unrecoverable configuration.";
exit;
} else {
$tmp = $sum/$total;
$diff = array();
foreach($cups as $key => $value) {
if ($tmp != $value){
$diff[$key]=$value;
}
}

if (empty($diff)) {
echo "Exemplary pages.";
exit;

}
if (count($diff)!=2) {
echo "Unrecoverable configuration.";
exit;
}
$max = 0;
$min = 0;
$minkey = 0;
$maxkey = 0;
$first =true;
foreach($diff as $key => $value){
if ($first) {
$max = $value;
$maxkey = $key;
$min = $value;
$minkey = $key;
}
if ($value>$max) {
$min = $max;
$minkey = $maxkey;
$max = $value;
$maxkey = $key;
} else {
$min = $value;
$minkey = $key;
}
$first = false;
}
$ml = ($max-$min)/2;
echo "{$ml} ml. from cup #{$minkey} to cup #{$maxkey}.";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = array();
for($x = 0; $x < $a; $x++)
{
    $c = trim(fgets(STDIN));
    $b[$x] = $c;
}
$d = array_unique($b);
rsort($d);
if(count($d) == 1)
{
    print "Exemplary pages.";
}
elseif(count($d) == 3)
{
    $e = ($d[0] - $d[2]) / 2;
    $f = 0;
    $g = 0;
    for($x = 0; $x < $a; $x++)
    {
        if($b[$x] == $d[0])
        {
            $f = $x + 1;
        }
        if($b[$x] == $d[2])
        {
            $g = $x + 1;
        }
    }
    print $e . " ml. from cup #" . $g . " to cup #" . $f . ".";
}
else
{
    print "Unrecoverable configuration.";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = array();
for($x = 0; $x < $a; $x++)
{
    $c = trim(fgets(STDIN));
    $b[$x] = $c;
}
$d = array_unique($b);
rsort($d);
if(count($d) == 1)
{
    print "Exemplary pages.";
}
elseif(count($d) == 3)
{
    $e = ($d[0] - $d[2]) / 2;
    $f = 0;
    $g = 0;
    for($x = 0; $x < $a; $x++)
    {
        if($b[$x] == $d[0])
        {
            $f = $x + 1;
        }
        if($b[$x] == $d[2])
        {
            $g = $x + 1;
        }
    }
    print $e . " ml. from cup #" . $g . " to cup #" . $f . ".";
}
elseif(count($d) > 3)
{
    print "Unrecoverable configuration.";
}
?>

<?php

    fscanf(STDIN, "%d", $n);
    for($i=0;$i<$n;$i++)
    {
        fscanf(STDIN, "%d", $a);
        $graf[$i]=$a;
    }
    $graf1=$graf;
    sort($graf1, SORT_NUMERIC);asort($graf, SORT_NUMERIC);
    if($n==1){printf("%s\n", "Exemplary pages.");exit;}

    if($graf1[0]==$graf1[$n-1])
    {
        printf("%s\n", "Exemplary pages.");
        exit;
    }else{

        if(($graf1[0]+$graf1[$n-1])==(2*$graf1[1]))
        {
            reset($graf);
            current($graf);
            $w1=key($graf);
            end($graf);
            $w2=key($graf);
            printf("%d ml. from cup #%d to cup #%d.\n", ($graf1[$n-1]-$graf1[0])/2, $w1+1, $w2+1);exit;
        }else{
            printf("%s\n", "Unrecoverable configuration.");exit;
        }
    }

?>

<?php

    fscanf(STDIN, "%d", $n);
    for($i=0;$i<$n;$i++)
    {
        fscanf(STDIN, "%d", $a);
        $graf[$i]=$a;
    }
    $graf1=$graf;
    sort($graf1, SORT_NUMERIC);asort($graf, SORT_NUMERIC);
    if($n==1){printf("%s\n", "Exemplary pages.");exit;}

    if($graf1[0]==$graf1[$n-1])
    {
        printf("%s\n", "Exemplary pages.");
        exit;
    }else{

        if(($graf1[0]+$graf1[$n-1])==(2*$graf1[1]))
        {
            reset($graf);
            current($graf);
            $w1=key($graf);
            end($graf);
            $w2=key($graf);
            printf("%d ml. from cup #%d to cup #%d.\n", ($graf1[$n-1]-$graf1[0]), $w1+1, $w2+1);exit;
        }else{
            printf("%s\n", "Unrecoverable configuration.");exit;
        }
    }

?>

<?php

    fscanf(STDIN, "%d", $n);
    for($i=0;$i<$n;$i++)
    {
        fscanf(STDIN, "%d", $a);
        $graf[$i]=$a;
    }
    $graf1=$graf;
    sort($graf1, SORT_NUMERIC);asort($graf, SORT_NUMERIC);
    if($n==1){printf("%s\n", "Exemplary pages.");exit;}

    if($graf1[0]==$graf1[$n-1])
    {
        printf("%s\n", "Exemplary pages.");
        exit;
    }else{

        if(($graf1[0]+$graf1[$n-1])==(2*$graf1[1]) or ((($graf1[0]+$graf1[$n-1])/2)==ceil(($graf1[0]+$graf1[$n-1])/2) and $n==2))
        {
            reset($graf);
            current($graf);
            $w1=key($graf);
            end($graf);
            $w2=key($graf);
            printf("%d ml. from cup #%d to cup #%d.\n", ($graf1[$n-1]-$graf1[0])/2, $w1+1, $w2+1);exit;
        }else{
            printf("%s\n", "Unrecoverable configuration.");exit;
        }
    }

?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
$text = explode("\n",$datatxt);
$total = intval($text[0]);
unset($text[0]);
$cups = array_map('intval', $text);
$sum = array_sum($cups);
if(($sum%$total) !=0)
{
echo "Unrecoverable configuration.";
exit;
} else {
$tmp = $sum/$total;
$diff = array();
foreach($cups as $key => $value) {
if ($tmp != $value){
$diff[$key]=$value;
}
}
if (empty($diff)) {
echo "Exemplary pages.";
exit;
}
sort($diff);
$max = 0;
$min = 0;
foreach($diff as $key => $value){
if($value>$max) {
$max = $value;
$maxkey = $key;
} else {
$min = $value;
$minkey = $key;
}
}
$ml = ($max-$min)/2;
echo "{$ml} ml. from cup #{$minkey} to cup #{$maxkey}.";
}
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt = "5
// 270
// 250
// 250
// 230
// 250
// ";
$text = explode("\n",$datatxt);
$total = intval($text[0]);
unset($text[0]);
foreach($text as $key => $value) {
if(empty($value)){
unset($text[$key]);
}
}
$cups = array_map('intval', $text);
$sum = array_sum($cups);
if(($sum%$total) !=0)
{
echo "Unrecoverable configuration.";
exit;
} else {
$tmp = $sum/$total;
$diff = array();
foreach($cups as $key => $value) {
if ($tmp != $value){
$diff[$key]=$value;
}
}

if (empty($diff)) {
echo "Exemplary pages.";
exit;

}
$max = 0;
$min = 0;
$minkey = 0;
$maxkey = 0;
$first =true;
foreach($diff as $key => $value){
if ($first) {
$max = $value;
$maxkey = $key;
$min = $value;
$minkey = $key;
}
if ($value>$max) {
$min = $max;
$minkey = $maxkey;
$max = $value;
$maxkey = $key;
} else {
$min = $value;
$minkey = $key;
}
$first = false;
}
$ml = ($max-$min)/2;
echo "{$ml} ml. from cup #{$minkey} to cup #{$maxkey}.";
}
?>

<?php

while (FALSE !== ($line = fgets(STDIN))) {

    $stat = array();
    $unrecoverableFlag = false;

    for($i = 1; $i <= $line; $i++){
        $cupValue = fgets(STDIN);

        if($unrecoverableFlag === true){
            continue;
        }

        $cupValue = trim($cupValue);

        if($stat[$cupValue]){
            $stat[$cupValue][0] = $i;    //line number
            $stat[$cupValue][1]++;       //count
        }else{
            $stat[$cupValue] = array($i, 1);
        }

        if(count($stat) > 3) {
            $unrecoverableFlag = true;
        }
    } //end of input taking and general statistics part ..

    $count = count($stat);

    if($unrecoverableFlag){
        echo 'Unrecoverable configuration.' . PHP_EOL;
    }

    if($count == 2){
        if($line == 2){
            //very special case ..
            $sorted = array_keys($stat);
            sort($sorted);
            $cupOneValue = $sorted[0];
            $cupTwoValue = $sorted[1];

            if( $stat[$cupOneValue][1] == 1 && $stat[$cupTwoValue][1] == 1){

                $diff = $cupTwoValue - $cupOneValue;
                if($diff % 2 == 1){
                    echo 'Unrecoverable configuration.' . PHP_EOL;
                }else{
                    $volum = $diff / 2;

                    echo $volum . ' ml. from cup #' . $stat[$cupOneValue][0] .
                       ' to cup #' . $stat[$cupTwoValue][0] . '.' . PHP_EOL;
                }

            }else{
                echo 'Unrecoverable configuration.' . PHP_EOL;
            }
        }else{
            echo 'Unrecoverable configuration.' . PHP_EOL;
        }
    }

    if($count == 1) {
        echo 'Exemplary pages.' . PHP_EOL;
    }

    if($count == 3){

        $sorted = array_keys($stat);

        sort($sorted);

        $cupOneValue = $sorted[0];
        $cupTwoValue = $sorted[2];

        if( $stat[$cupOneValue][1] == 1 && $stat[$cupTwoValue][1] == 1){

            $diff = $cupTwoValue - $cupOneValue;

            if($diff % 2 == 1){
                echo 'Unrecoverable configuration.' . PHP_EOL;
            }else{
                $volum = $diff / 2;

                echo $volum . ' ml. from cup #' . $stat[$cupOneValue][0] .
                   ' to cup #' . $stat[$cupTwoValue][0] . '.' . PHP_EOL;
            }

        }else{
            echo 'Unrecoverable configuration.' . PHP_EOL;
        }
    }
}