<?php
/*
By Tianyi Chen
*/
$s=fgets(STDIN);
if($s[1]==='}')die('0');
print(count(array_unique(json_decode(str_replace('}',"\"]",str_replace('{',"[\"",str_replace(', ','","',$s)))))));

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

//$s = trim(fgets($f));
$s = trim(fgets($f));

$s = trim($s,'{');
$s = trim($s,'}');

$s = str_replace(" ","",$s);

if ($s==""){ echo(0);exit;}

$a = explode(',',$s);

$b = array();
foreach($a as $item){
    $b[$item] = 1;
}

echo count($b);

<?php

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

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

$s = str_replace( "{" , "" , $s ) ;
$s = str_replace( "}" , "" , $s ) ;

$arr = [] ;

if( $s != '' )
{
     for( $i=0 ; $i<strlen($s)-1 ; )
     {
          if( ! in_array( $s[$i] , $arr) )
          {
               $arr[] = $s[$i] ;
          }
          $i+= 3 ;
     }
}

echo count( $arr )  ;

fwrite($stdout);

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

?>

<?

$input = trim(fgets(STDIN));
$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo count(array_count_values($array)); }

?>

<?php
// 443A     Антон и буквы
$in = fopen("php://stdin", 'r');

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

$arr = array_unique($arr);

echo count($arr);

?>

<?php

$line = fgets(STDIN);

$used = array();
for ($i = ord('a'); $i <= ord('z'); $i ++) {
	$used[$i] = FALSE;
}

$output = 0;

for ($i = 0; $i < strlen($line); $i ++) {
	if (ctype_alpha($line{$i}) && $used[ord($line{$i})] === FALSE) {
		$used[ord($line{$i})] = TRUE;
		$output ++;
	}
}

print $output;

<?php

$letters = fgets(STDIN);
$letters = trim($letters);
$letters = substr($letters, 1, (strlen($letters) - 2));
$letters = explode(', ', $letters);

	$letters = array_unique($letters);

if($letters[0] == null){
	$letters = array();
}

print_r(count($letters));

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

$a = explode(", ",substr(rtrim(fgets($in)),1,-1));

if($a[0]=="")
    echo 0;
else
    echo count(array_unique($a));

<?php
$s = trim(trim(fgets(STDIN)), '{}');
if (!$s)
    print 0;
else
    print count(array_unique(explode(", ", $s)));
?>

<?php
error_reporting("off");
//443A: Anton and Letters
$n = explode(", ", substr(trim(fgets(STDIN)), 1, -1));
$unique = array_filter(array_unique($n));
echo count($unique);
?>

<?php
$a = trim(fgets(STDIN));
if($a == "{}")
{
    print "0";
}
else
{
    $b = str_split($a);
    unset($b[count($b) - 1]);
    unset($b[0]);
    $c = implode("", $b);
    $d = explode(", ", $c);
    $e = array_unique($d);
    print count($e);
}
?>

<?php

$a =  trim(trim(fgets(STDIN)), '{}');

if($a=="")
echo 0;
else
{
  echo count(array_unique(explode(", ", $a)));
}

?>

<?php
    $arr =  trim(fgets(STDIN));
    $v = array();
        for ($i = 0; $i < strlen($arr); $i++){
            if ($arr[$i] >= 'a' && $arr[$i] <= 'z'){
                $v[$arr[$i]] = 1;
            }

        }
         echo count($v);

<?php
/*
By Tianyi Chen
*/
$s=fgets(STDIN);
if($s[1]==='}')die('0');
$s=str_replace(', ','","',$s);
$s=str_replace('{',"[\"",$s);
$s=str_replace('}',"\"]",$s);
print(count(array_unique(json_decode($s))));

<?php
/*
 * A. Антон и буквы
 */
$s = trim(fgets(STDIN));

preg_match_all('/[a-z]/',$s,$m);

$m = array_unique($m[0]);

echo sizeof($m) > 0 ? sizeof($m) : '0';

<?php
$arr = str_replace(" ","",substr(substr(trim(fgets(STDIN)),0,-1),1));
$ArrOfBkv = explode(",", $arr );
if ($ArrOfBkv[0]=="")
echo "0"; else
echo count(array_unique($ArrOfBkv));
?>

<?php
$line = explode(",",str_replace(array("{","}"," "),"",trim(fgets(STDIN))));
$line = array_unique($line);
if (count($line)==1)
{
    if ($line[0]=="")echo 0;
    else echo 1;
}
else echo count($line);

<?php

$input = explode(", ", trim(fgets(STDIN),"{}\n\r"));
$result = array_unique($input);
$col = count($result);
if ( $col == 1) {
    if (empty($result[0])) {
        $output = 0;
    } else {
        $output = $col;
    }
} else {
    $output = $col;
}
print_r($output);

<?php
$set=trim(fgets(STDIN));
if ($set=="{}") {
	echo "0";
}
else{
$rmvbrket=trim($set,'{}');
$rmvspace=str_replace(', ','',$rmvbrket);

$count=0;
$alpbet="abcdefghijklmnopqrstuvwxyz";
for($i=0;$i<strlen($alpbet);$i++)
{
	for($j=0;$j<strlen($rmvspace);$j++)
	{
		if($alpbet[$i]==$rmvspace[$j])
		{
			$count++;
			break;
		}

	}
}
echo "$count";
}

<?php
$a = trim(fgets(STDIN));
$b = substr($a, 1);
$c = substr($b, 0, -1);
$d = explode(", ", $c);
$e = array_unique($d);
print count($d) - count($e);
?>

<?php
$a = trim(fgets(STDIN));
$b = substr($a, 1);
$c = substr($b, 0, -1);
$d = explode(", ", $c);
$e = array_unique($d);
print count($e);
?>

<?php
$a = trim(fgets(STDIN));
$b = str_split($a);
unset($b[0]);
unset($b[count($b)]);
$c = implode("", $b);
$e = array_unique($d);
if($a == "{}")
{
    print "0";
}
else
{
    print count($e);
}
?>

<?php
/*
By Tianyi Chen
*/
$s=fgets(STDIN);
if($s[1]==='}')die('0');
print(count(array_unique(json_decode(str_replace('}',"\"]",str_replace(', ','","',$s))))));

<?php
/*
By Tianyi Chen
*/
fscanf(STDIN,'%[^\n]',$s);
if($s[1]==='}')die('0');
$s=str_replace('{',"[\"",$s);
$s=str_replace('}',"\"]",$s);
$s=str_replace(', ','","',$s);
print(count(array_unique(json_decode($s))));

<?php
/*
By Tianyi Chen
*/
fscanf(STDIN,'%[^\n]',$s);
if(strlen($s)===2)die('0');
$s=str_replace('{',"[\"",$s);
$s=str_replace('}',"\"]",$s);
$s=str_replace(', ','","',$s);
print(count(array_unique(json_decode($s))));

<?php
$arr = str_replace(" ","",substr(substr(trim(fgets(STDIN)),0,-1),1));
$ArrOfBkv = explode(",", $arr );
echo count(array_unique($ArrOfBkv));
?>

<?php
list ($k,$n) = explode(" ",trim(fgets(STDIN)));
$n=$n-1;
if ($n<$k/2) echo intval($k/($k/2))*$n+1;
else echo 2+2*($n-round($k/2));

<?php
$input = explode(", ", trim(fgets(STDIN), "{}\n"));
$result = array_unique($input);
print(count($result));

<?php
$input = explode(", ", trim(fgets(STDIN), "{}\n\r"));
$result = array_unique($input, SORT_REGULAR);
print(count($result));

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

//$s = trim(fgets($f));
$s = trim(fgets($f));

$s = trim($s,'{');
$s = trim($s,'}');

$s = str_replace(" ","",$s);

if ($s=="") echo(0);exit;

$a = explode(',',$s);

$b = array();
foreach($a as $item){
    $b[$item] = 1;
}

echo count($b);

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

//$s = trim(fgets($f));
$s = trim(fgets($f));

$s = trim($s,'{');
$s = trim($s,'}');

$s = str_replace(" ","",$s);

if ($s=="") exit(0);

$a = explode(',',$s);

$b = array();
foreach($a as $item){
    $b[$item] = 1;
}

echo count($b);

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

//$s = trim(fgets($f));
$s = trim(fgets($f));

$s = trim($s,'{');
$s = trim($s,'}');

$s = str_replace(" ","",$s);
$a = explode(',',$s);

$b = array();
foreach($a as $item){
    $b[$item] = 1;
}

echo count($b);

<?

$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo intval(count(array_count_values($array))); }

?>

<?

$input = '{a, b, c}';
$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo intval(count(array_count_values($array))); }

?>

<?

$s = fopen("php://stdin", 'r');
$input = stream_get_contents($s);
$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo count(array_count_values($array)); }

?>

<?

$input = 'php://stdin';
$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo count(array_count_values($array)); }

?>

$input = '{a, b, a, b}';
$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo count(array_count_values($array)); }

<?php
error_reporting("off");
//443A: Anton and Letters
$n = explode(", ", substr(trim(fgets(STDIN)), 1, -1));
$unique = array_unique($n);
echo count($unique);
?>


<?php

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

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

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

	$tc = next_int();
	for($cc=0; $cc<$tc; $cc++) {
		$n = next_int();
		$s = next();

		$l = -1; $r = -1;
		$mn = 1234567;
		$lr = 0; $ud = 0;
		$a = [($lr . "+" . $ud) => 0];
		for($i=0; $i<$n; $i++) {
			if($s[$i] == "L") $lr--;
			elseif($s[$i] == "R") $lr++;
			elseif($s[$i] == "D") $ud--;
			else $ud++;

			$t = $lr . "+" . $ud;
			if(array_key_exists($t, $a)) {
				if($i + 1 - $a[$t] < $mn) {
					$mn = $i + 1 - $a[$t];
					$l = $a[$t] + 1;
					$r = $i + 1;
				}
			}
			$a[$t] = $i + 1;
		}
		if($l == -1) printf("%d\n", -1);
		else printf("%d %d\n", $l, $r);
	}
}

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

?>

<?php

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

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

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

	$tc = next_int();
	for($cc=0; $cc<$tc; $cc++) {
		$n = next_int();
		$s = next();

		$l = -1; $r = -1;
		$min_len = 1234567;
		$sum = 0;
		$a = [$sum => 0];
		for($i=0; $i<$n; $i++) {
			if($s[$i] == "L") $sum -= 1;
			elseif($s[$i] == "R") $sum += 1;
			elseif($s[$i] == "D") $sum -= 200001;
			else $sum += 200001;

			if(array_key_exists($sum, $a)) {
				if($i + 1 - $a[$sum] < $min_len) {
					$min_len = $i + 1 - $a[$sum];
					$l = $a[$sum] + 1;
					$r = $i + 1;
				}
			}
			$a[$sum] = $i + 1;
		}
		if($l == -1) printf("%d\n", -1);
		else printf("%d %d\n", $l, $r);
	}
}

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

?>


<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	readNum($f);
	$path = trim(readString($f));
	$n = strlen($path);

	$b = $r = array(0,0);
	for ($i = 0; $i < $n; $i++) {
		if ($path[$i] == 'r') {
			$r[$i % 2] ++;
		} else {
			$b[$i % 2] ++;
		}
	}
	echo min(max($r[0], $b[1]), max($r[1], $b[0]));
	/* / end body */
}

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

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	$n = readNum($f);
	$path = trim(readString($f));

	$actionCount = 0;
	for ($i = 1; $i < $n; $i++) {
		if ($path[$i] != $path[$i - 1]) {
			continue;
		}
		$doublePos = false;
		for ($j = $i + 2; $j < $n; $j++) {
			if ($path[$i] != $path[$j] && $path[$j] == $path[$j - 1]) {
				$doublePos = $j - 1;
				break;
			}
		}
		if ($doublePos !== false) {
			$t = $path[$i];
			$path[$i] = $path[$doublePos];
			$path[$doublePos] = $t;
			$actionCount++;
		} else {
			$actionCount++;
			if ($path[$i] == 'r') {
				$path[$i] = 'b';
			} else {
				$path[$i] = 'r';
			}
		}
	}
	echo $actionCount;
	/* / end body */
}

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

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	readNum($f);
	$path = trim(readString($f));
	$n = strlen($path);

	$actionCount = 0;
	for ($i = 1; $i < $n; $i++) {
		if ($path[$i] != $path[$i - 1]) {
			continue;
		}
		$doublePos = false;
		for ($j = $i + 2; $j < $n; $j++) {
			if ($path[$i] != $path[$j] && $path[$j] == $path[$j - 1]) {
				$doublePos = $j - 1;
				break;
			}
			if ($path[$i] != $path[$j] && $j + 1 == $n) {
				$doublePos = $j;
				break;
			}
		}
		if ($doublePos !== false) {
			$t = $path[$i];
			$path[$i] = $path[$doublePos];
			$path[$doublePos] = $t;
			$actionCount++;
		} else {
			$actionCount++;
			if ($path[$i] == 'r') {
				$path[$i] = 'b';
			} else {
				$path[$i] = 'r';
			}
		}
	}

	echo $actionCount;
	/* / end body */
}

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

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	readNum($f);
	$path = trim(readString($f));
	$n = strlen($path);

	$actionCount = 0;
	for ($i = 1; $i < $n; $i++) {
		if ($path[$i] != $path[$i - 1]) {
			continue;
		}
		$doublePos = false;
		for ($j = $i + 2; $j < $n; $j++) {
			if ($path[$i] != $path[$j] && $path[$j] == $path[$j - 1]) {
				$doublePos = $j - 1;
				break;
			}
		}
		if ($i + 2 == $n && $path[$i] != $path[$i + 1]) {
			$doublePos = $i + 1;
		}
		if ($doublePos !== false) {
			$t = $path[$i];
			$path[$i] = $path[$doublePos];
			$path[$doublePos] = $t;
			$actionCount++;
		} else {
			$actionCount++;
			if ($path[$i] == 'r') {
				$path[$i] = 'b';
			} else {
				$path[$i] = 'r';
			}
		}
	}

	echo $actionCount;
	/* / end body */
}

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


<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] === '.'
            || $notes[$i+$p] === '.'
            || $notes[$i] !== $notes[$i+$p];
        $notes[$i+$p] = (int)($notes[$i+$p] === '.'
            ? ($notes[$i] === '.' ? mt_rand(0,1) : !(bool)(int)$notes[$i])
            : $notes[$i+$p]);
        $notes[$i] = (int)($notes[$i] === '.'
            ? !(bool)(int)($notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] === '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] == '.'
            || $notes[$i+$p] == '.'
            || $notes[$i] != $notes[$i+$p];
        $notes[$i+$p] = (int)($notes[$i+$p] == '.'
            ? !(bool)($notes[$i] == '.' ? mt_rand(0,1) : (int)$notes[$i])
            : $notes[$i+$p]);
        $notes[$i] = (int)($notes[$i] == '.'
            ? !(bool)(int)($notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result || $notes[$i] == '.' || $notes[$i+$p] == '.' || $notes[$i] != $notes[$i+$p];
        $notes[$i] = (int)($notes[$i] == '.'
            ? !(bool)(int)($notes[$i+$p] = $notes[$i+$p] == '.' ? mt_rand(0,1) : $notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] == '.'
            || $notes[$i+$p] == '.'
            || $notes[$i] != $notes[$i+$p];
        $notes[$i+$p] = $notes[$i+$p] == '.'
            ? ($notes[$i] == '.' ? mt_rand(0,1) : !(bool)(int)$notes[$i])
            : $notes[$i+$p];
        $notes[$i] = (int)($notes[$i] == '.'
            ? !(bool)(int)($notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;

for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] == '.'
            || $notes[$i+$p] == '.'
            || $notes[$i] != $notes[$i+$p];

        if ($notes[$i+$p] == '.') {
            $notes[$i+$p] = (int)($notes[$i] == '.' ? 1 : !(bool)(int)$notes[$i]);
        }

        if ($notes[$i] == '.') {
            $notes[$i] = (int)!(bool)(int)($notes[$i+$p]);
        }

    } else {
        $notes[$i] = $notes[$i] == '.' ? 1 : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;

for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] == '.'
            || $notes[$i+$p] == '.'
            || $notes[$i] != $notes[$i+$p];

        if ($notes[$i+$p] == '.') {
            $notes[$i+$p] = (int)($notes[$i] == '.' ? mt_rand(0,1) : !(bool)(int)$notes[$i]);
        }

        if ($notes[$i] == '.') {
            $notes[$i] = (int)!(bool)(int)($notes[$i+$p]);
        }

    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $notes[$i] == '.' || $notes[$i+$p] == '.' || $notes[$i] != $notes[$i+$p];
        $notes[$i] = (int)($notes[$i] == '.'
            ? !(bool)(int)($notes[$i+$p] = $notes[$i+$p] == '.' ? mt_rand(0,1) : $notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] == '.'
            || $notes[$i+$p] == '.'
            || $notes[$i] != $notes[$i+$p];
        $notes[$i+$p] = (int)($notes[$i+$p] == '.'
            ? (int)($notes[$i] == '.' ? mt_rand(0,1) : !(bool)(int)$notes[$i])
            : $notes[$i+$p]);
        $notes[$i] = (int)($notes[$i] == '.'
            ? !(bool)(int)($notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";


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

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

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

  $newWord = [];
  $newWord[]= substr($a[0], 0, 1);

	for ($j = 1; $j < count($a);) {
		if (substr($a[$j - 1], 1, 1) == substr($a[$j], 0, 1)) {
			$newWord[] = substr($a[$j], 0, 1);
			$j++;
		} else {
			$newWord[] = substr($a[$j - 1], 1, 1);
			$a[$j - 1] = substr($a[$j - 1], 0, 1).substr($a[$j], 0, 1);
		}
	}

	$newWord[] = substr($a[$j - 1], 1, 1);

	if (count($newWord) < $n) {
		$newWord[] = substr($a[$j - 1], 1, 1);
	}

	$newStr = implode('', $newWord);
	echo $newStr.PHP_EOL;
}

?>

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

$solve = function ($n, $a) {

	$l = ($n - 2) * 3;
	$res = substr($a, 0,1);
	$a1 = substr($a, 1,1);
	$p = false;
	for ($i = 3; $i < $l; $i += 3){
		$a2 = substr($a, $i, 1);

		if($a1 != $a2 && !$p){
			$res .= $a1;
			$p = true;
		}

		$res .= $a2;
		$a1 = substr($a, $i + 1, 1);
	}
	$res .= $a1;
	if(!$p){
		$res .= 'a';
	}

	return $res;

};

$t = intval(fgets(STDIN));

for (; $t > 0; $t--) {

	$n = intval(fgets(STDIN));
	$a = fgets(STDIN);

	echo $solve($n, $a);
	echo "\n";

}

<?

$n = trim(fgets(STDIN));
for($i=0;$i<$n;$i++){
	$k = trim(fgets(STDIN));
	$arr = explode(" ",trim(fgets(STDIN)));
	$word = [];
	$word[]= substr($arr[0],0,1);
	//$word[]= substr($arr[0],1,1);
	for($j=1;$j<count($arr);){
		if(substr($arr[$j-1],1,1)==substr($arr[$j],0,1)){
			$word[] = substr($arr[$j],0,1);
			$j++;
		}else{
			$word[] = substr($arr[$j-1],1,1);
			$arr[$j-1] = substr($arr[$j-1],0,1).substr($arr[$j],0,1);
		}
	}
	$word[] = substr($arr[count($arr)-1],1,1);
	if(count($word)<$k){
		$word[] = substr($arr[count($arr)-1],1,1);
	}
	echo implode("",$word)."\n";
}

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

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

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

  $newWord = [];
  $newWord[]= substr($a[0], 0, 1);

	for ($j = 1; $j < count($a);) {
	  $part1 = substr($a[$j - 1], 1, 1);
	  $part2 = substr($a[$j], 0, 1);
		if ($part1 == $part2) {
			$newWord[] = $part2;
			$j++;
		} else {
			$newWord[] = $part1;
			$a[$j - 1] = substr($a[$j - 1], 0, 1).$part2;
		}
	}

	$newWord[] = $part1;

	if (count($newWord) < $n) {
		$newWord[] = $part1;
	}

	$newStr = implode('', $newWord);
	echo $newStr.PHP_EOL;
}
?>


<?php
fscanf(STDIN,"%d",$lenOfStr);
fscanf(STDIN,"%s",$str);
$decision=false;

if($lenOfStr%4==0)
 {
 	 $a=0;
 	 $g=0;
 	 $c=0;
 	 $t=0;
     $split=str_split($str);
     for ($i=0; $i <count($split) ; $i++)
      {
     	   if($split[$i]=='A')
     	   	   $a++;
     	   	elseif ($split[$i]=='G')
     	   	 {
     	   		$g++;
     	   	 }
     	   	elseif ($split[$i]=='C')
     	   	 {
     	   		$c++;
     	   	 }
     	   	 else
     	   	 {
     	   	 	if($split[$i]=='T')
     	   	 		$t++;
     	   	 }

      }
      $div=$lenOfStr/4;
      if($div<$a||$div<$g||$div<$c||$div<$t)
      	  $decision=false;
       //$loop=$div;
       else
       {

       	    while($a<$div)
       	    {
       	    	for ($i=0; $i <strlen($str) ; $i++)
       	    	 {
       	    		if($str[$i]=='?')
       	    		{
       	    			$str[$i]='A';
       	    			break;
       	    		}
       	    	 }
       	    	$a++;
       	    }
       	    while($c<$div)
       	    {
       	    	for ($i=0; $i <strlen($str) ; $i++)
       	    	 {
       	    		if($str[$i]=='?')
       	    		{
       	    			$str[$i]='C';
       	    			break;
       	    		}
       	    	 }
       	    	$c++;
       	    }
       	    while($g<$div)
       	    {
       	    	for ($i=0; $i <strlen($str) ; $i++)
       	    	 {
       	    		if($str[$i]=='?')
       	    		{
       	    			$str[$i]='G';
       	    			break;
       	    		}
       	    	 }
       	    	$g++;
       	    }
       	    while($t<$div)
       	    {
       	    	for ($i=0; $i <strlen($str) ; $i++)
       	    	 {
       	    		if($str[$i]=='?')
       	    		{
       	    			$str[$i]='T';
       	    			break;
       	    		}
       	    	 }
       	    	$t++;
       	    }

       	    //echo "$str";
        	$decision=true;
       }
 }
 echo $decision?"$str":"===";

<?php

function run($length, $string) {
    if ($length % 4 !== 0) return '===';

    $n = ['A', 'C', 'G', 'T'];

    $maxLen = $length/4;

    $count = array_fill_keys($n, $maxLen);

    for ($i = 0; $i < $length; $i++){
        $letter = $string[$i];
        if (isset($count[$letter])) {
            if ($count[$letter] <= 1) {
                unset($count[$letter]);
            } else {
                $count[$letter]--;
            }
        } elseif ($letter !== '?') {
            return '===';
        }
    }

    $result = '';

    for ($i = 0; $i < $length; $i++) {
        $letter = $string[$i];

        if ($letter === '?') {
            $key = array_shift(array_keys($count));
            if ($count[$key] <= 1) {
                unset($count[$key]);
            } else {
                $count[$key]--;
            }
            $result .= $key;
        } else {
            $result .= $letter;
        }
    }

    return $result;
}

echo run(fgets(STDIN), fgets(STDIN));

<?php
fscanf(STDIN,"%d",$lenOfStr);
fscanf(STDIN,"%s",$str);
$decision=false;

if($lenOfStr%4==0)
 {
 	 $a=0;
 	 $g=0;
 	 $c=0;
 	 $t=0;
     $split=str_split($str);
     for ($i=0; $i <count($split) ; $i++)
      {
     	   if($split[$i]=='A')
     	   	   $a++;
     	   	elseif ($split[$i]=='G')
     	   	 {
     	   		$g++;
     	   	 }
     	   	elseif ($split[$i]=='C')
     	   	 {
     	   		$c++;
     	   	 }
     	   	 else
     	   	 {
     	   	 	if($split[$i]=='T')
     	   	 		$t++;
     	   	 }

      }
      $div=$lenOfStr/4;
      if($div<$a||$div<$g||$div<$c||$div<$t)
      	  $decision=false;
       //$loop=$div;
       else
       {
       	$rslt=str_repeat("AGCT",$div);
       	$decision=true;
       }
     // echo "$str";
 }
 echo $decision?"$rslt":"===";


<?php
  $s = trim(fgets(STDIN));
  list($n, $x) = explode(' ', $s);
  $s = trim(fgets(STDIN));
  $a = explode(' ', $s);
  $sum = 0;
  for ($i = 0; $i < $n; $i++) {
    $sum += $a[$i];
  }
  $sum = abs($sum);
  echo floor($sum / $x) + ($sum % $x ? 1 : 0), "\n";

<?php
// 401A     Ваня и карточки

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

$input_line = fgets($in);
list($n, $x) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);
//$n = (int) $input_line;

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

$summa = 0;
foreach ($arr as $key => $value) {
    $summa += (int) $value;
}
$summa = abs($summa);

$col = intval($summa / (int) $x);
if ($summa % (int) $x !== 0) $col ++;

echo "$col\n";

?>

<?php

list($n, $x) = explode(' ', line());
$a = explode(' ', line());

$n = intval($n);
$x = intval($x);

$sum = 0;

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

print intval($sum / $x) + ($sum%$x > 0 ? 1 : 0);

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

<?php
 $f = fopen("php://stdin","r");
 $str1 = fgets($f);
 $str2 = fgets($f);
 $numbers = explode(" ", $str2);
 $summ = 0;
 foreach($numbers as $key=>$value)
 {
 		$summ += $value;
 }
 $data = explode(" ", $str1);
 $summ = abs($summ);
 $res = floor($summ / $data[1]);
 if($res * $data[1] != $summ)
 	$res++;
 echo $res;
 ?>

<?php
  $s = trim(fgets(STDIN));
  list($n, $x) = explode(' ', $s);
  $s = trim(fgets(STDIN));
  $a = explode(' ', $s);
  $sum = 0;
  for ($i = 0; $i < $n; $i++) {
    $sum += $a[$i];
  }
  $sum = abs($sum);
  echo floor($sum / $n) + ($sum % $n ? 1 : 0), "\n";


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($vNumber, $q) = explode(" ", trim(fgets($file)));
$aArray = array();
$kArray = array();
for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $aArray[$x][$y] = 1;
    $aArray[$y][$x] = 1;
    if (isset($kArray[$x])) {
        $kArray[$x]++;
    } else {
        $kArray[$x] = 1;
    }
    if (isset($kArray[$y])) {
        $kArray[$y]++;
    } else {
        $kArray[$y] = 1;
    }
}

$result = 2000000;

foreach ($aArray as $w => $kw) {
    $ak = array_keys($kw);
    for ($i = 0; $i < $kArray[$w]; $i++) {
        for ($j = $i+1; $j < $kArray[$w]; $j++) {
            if (isset($aArray[$ak[$i]][$ak[$j]])) {
                $sum = $kArray[$w] + $kArray[$ak[$i]] + $kArray[$ak[$j]] - 6;
                $result = min($result, $sum);
            }
        }
    }
}

echo $result == 2000000 ? "-1" : $result;

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($vNumber, $q) = explode(" ", trim(fgets($file)));
$aArray = array();
$kArray = array();
$vArray = array();
for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $aArray[$x][$y] = 1;
    $aArray[$y][$x] = 1;
    $vArray[$i] = array($x, $y);
    if (isset($kArray[$x])) {
        $kArray[$x]++;
    } else {
        $kArray[$x] = 1;
    }
    if (isset($kArray[$y])) {
        $kArray[$y]++;
    } else {
        $kArray[$y] = 1;
    }
}

$result = 2000000;

for ($i = 0; $i < $q; $i++) {
    $has = array();
    $x = $vArray[$i][0];
    $y = $vArray[$i][1];

    foreach ($aArray[$x] as $t=>$f) {
        if (isset($aArray[$y][$t])) {
            $result = min($result, $kArray[$x] + $kArray[$y] + $kArray[$t]-6);
        }
    }

}
echo $result == 2000000 ? "-1" : $result;

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($vNumber, $q) = explode(" ", trim(fgets($file)));
$aArray = array();
$kArray = array();
for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $aArray[$x][$y] = 1;
    $aArray[$y][$x] = 1;
    if (isset($kArray[$x])) {
        $kArray[$x]++;
    } else {
        $kArray[$x] = 1;
    }
    if (isset($kArray[$y])) {
        $kArray[$y]++;
    } else {
        $kArray[$y] = 1;
    }
}

$result = 2000000;

foreach ($aArray as $w => $kw) {
    $ak = array_keys($kw);
    for ($i = 0; $i < $kArray[$w]; $i++) {
        if ($ak[$i]>$w) {
            for ($j = $i+1; $j < $kArray[$w]; $j++) {
                if (isset($aArray[$ak[$i]][$ak[$j]])) {
                    $sum = $kArray[$w] + $kArray[$ak[$i]] + $kArray[$ak[$j]] - 6;
                    $result = min($result, $sum);
                }
            }
        }
    }
}

echo $result == 2000000 ? "-1" : $result;

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($vNumber, $q) = explode(" ", trim(fgets($file)));
$aArray = array();
$kArray = array();
for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $aArray[$x][$y] = 1;
    $aArray[$y][$x] = 1;
    if (isset($kArray[$x])) {
        $kArray[$x]++;
    } else {
        $kArray[$x] = 1;
    }
    if (isset($kArray[$y])) {
        $kArray[$y]++;
    } else {
        $kArray[$y] = 1;
    }
}

$result = 2000000;

foreach ($aArray as $w => $kw) {
    foreach ($kw as $i=>$v) {
        foreach ($kw as $j=>$v2) {
            if (isset($aArray[$i][$j])) {
                $sum = $kArray[$w] + $kArray[$i] + $kArray[$j] - 6;
                $result = min($result, $sum);
            }
        }
    }

}

echo $result == 2000000 ? "-1" : $result;

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($vNumber, $q) = explode(" ", trim(fgets($file)));
$aArray = array();
$kArray = array();
for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $aArray[$x][$y] = 1;
    $aArray[$y][$x] = 1;
    if (isset($kArray[$x])) {
        $kArray[$x]++;
    } else {
        $kArray[$x] = 1;
    }
    if (isset($kArray[$y])) {
        $kArray[$y]++;
    } else {
        $kArray[$y] = 1;
    }
}

$result = 2000000;

foreach ($aArray as $w => $kw) {
    $ak = array_keys($kw);
    for ($i = 0; $i < $kArray[$w]; $i++) {
        if ($ak[$i]<$w) {
            for ($j = $i+1; $j < $kArray[$w]; $j++) {
                if (isset($aArray[$ak[$i]][$ak[$j]])) {
                    $sum = $kArray[$w] + $kArray[$ak[$i]] + $kArray[$ak[$j]] - 6;
                    $result = min($result, $sum);
                }
            }
        }
    }
}

echo $result == 2000000 ? "-1" : $result;

<?php
$knights_arr = array();
$groups = array();
$recognation = array();
$r = 0;

$file = STDIN;

list($vNumber, $q) = explode(" ", trim(fgets($file)));

for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));

	if(empty($knights_arr[$x])){
		$knights_arr[$x] = array();
	}
	$knights_arr[$x][] = $y;
	if(empty($knights_arr[$y])){
		$knights_arr[$y] = array();
	}
	$knights_arr[$y][] = $x;

}

ksort($knights_arr,1);
foreach($knights_arr as $key => $arr){
	if ( count($arr) < 2 ) {
		continue;
	}
	sort($arr);
	foreach($arr as $i => $sec){
		if($sec < $key || count($knights_arr[$sec]) < 2 || ($i == count($arr)-1) ){
			continue;
		}
		$rem_arr = array_slice($arr, $i+1);
		foreach($rem_arr as $thrd){
			if($thrd > $sec && in_array($key, $knights_arr[$thrd]) && in_array($sec, $knights_arr[$thrd])){
				$group[$r] =  "$key-$sec-$thrd";
				$recognation[$r] = count($knights_arr[$key]) + count($knights_arr[$sec]) + count($knights_arr[$thrd]) - 6;
				$r++;
			}
		}
	}
}
if($r == 0){
	echo -1;
}else{
	echo min($recognation);
}

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($vNumber, $q) = explode(" ", trim(fgets($file)));
$aArray = array();
$kArray = array();
for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $aArray[$x][$y] = 1;
    $aArray[$y][$x] = 1;
    if (isset($kArray[$x])) {
        $kArray[$x]++;
    } else {
        $kArray[$x] = 1;
    }
    if (isset($kArray[$y])) {
        $kArray[$y]++;
    } else {
        $kArray[$y] = 1;
    }
}

$result = 2000000;

foreach ($aArray as $w => $kw) {
    $ak = array_keys($kw);
    for ($i = 0; $i < $kArray[$w]; $i++) {
        for ($j = $i+1; $j < $kArray[$w]; $j++) {
            $I = $ak[$i];
            $J = $ak[$j];
            if (isset($aArray[$I][$J])) {
                $sum = $kArray[$w] + $kArray[$I] + $kArray[$J] - 6;
                $result = min($result, $sum);
            }
        }
    }
}

echo $result == 2000000 ? "-1" : $result;

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($vNumber, $q) = explode(" ", trim(fgets($file)));
$aArray = array();
$kArray = array();
for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    if ($x > $y) {
        $aArray[$x][$y] = 1;
    } else {
        $aArray[$y][$x] = 1;
    }
    if (isset($kArray[$x])) {
        $kArray[$x]++;
    } else {
        $kArray[$x] = 1;
    }
    if (isset($kArray[$y])) {
        $kArray[$y]++;
    } else {
        $kArray[$y] = 1;
    }
}

$result = 2000000;

foreach ($aArray as $w => $kw) {
    $ak = array_keys($kw);
    $cw = count($kw);
    for ($i = 0; $i < $cw; $i++) {
        for ($j = $i + 1; $j < $cw; $j++) {
            if (isset($aArray[$ak[$i]])) {
                if (isset($aArray[$ak[$i]][$ak[$j]])) {
                    $sum = $kArray[$w] + $kArray[$ak[$i]] + $kArray[$ak[$j]] - 6;
                    $result = min($result, $sum);
                }
            } elseif (isset($aArray[$ak[$j]])) {
                if (isset($aArray[$ak[$j]][$ak[$i]])) {
                    $sum = $kArray[$w] + $kArray[$ak[$i]] + $kArray[$ak[$j]] - 6;
                    $result = min($result, $sum);
                }
            }
        }
    }
}

echo $result == 2000000 ? "-1" : $result;

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($vNumber, $q) = explode(" ", trim(fgets($file)));
$aArray = array();
$kArray = array();
$vArray = array();
for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $aArray[$x][$y] = 1;
    $aArray[$y][$x] = 1;
    $vArray[$i] = array($x, $y);
    if (isset($kArray[$x])) {
        $kArray[$x]++;
    } else {
        $kArray[$x] = 1;
    }
    if (isset($kArray[$y])) {
        $kArray[$y]++;
    } else {
        $kArray[$y] = 1;
    }
}

$result = 2000000;
for ($i = 0; $i < $q; $i++) {
    foreach (array_intersect($aArray[$vArray[$i][0]], $aArray[$vArray[$i][1]]) as $z) {
        $sum = $kArray[$vArray[$i][0]] + $kArray[$vArray[$i][1]] + $kArray[$z] - 6;
        $result = min($result, $sum);
    }

}
echo $result == 2000000 ? "-1" : $result;

<?php
$file = fopen('input.in', 'r');
//$file = STDIN;
list($vNumber, $q) = explode(" ", trim(fgets($file)));
$aArray = array();
$kArray = array();
$vArray = array();
for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $aArray[$x][] = $y;
    $aArray[$y][] = $x;
    $vArray[$i] = array($x, $y);
    if (isset($kArray[$x])) {
        $kArray[$x]++;
    } else {
        $kArray[$x] = 1;
    }
    if (isset($kArray[$y])) {
        $kArray[$y]++;
    } else {
        $kArray[$y] = 1;
    }
}

$result = 2000000;

for ($i = 0; $i < $q; $i++) {
    $ai = array_intersect($aArray[$vArray[$i][0]], $aArray[$vArray[$i][1]]);
    foreach ($ai as $z) {
        $sum = $kArray[$vArray[$i][0]] + $kArray[$vArray[$i][1]] + $kArray[$z] - 6;
        $result = min($result, $sum);
    }

}
echo $result == 2000000 ? "-1" : $result;

<?php
$file = fopen('input.in', 'r');
//$file = STDIN;
list($vNumber, $q) = explode(" ", trim(fgets($file)));
$aArray = array();
$kArray = array();
$vArray = array();
for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $aArray[$x][$y] = 1;
    $aArray[$y][$x] = 1;
    $vArray[$i] = array($x, $y);
    if (isset($kArray[$x])) {
        $kArray[$x]++;
    } else {
        $kArray[$x] = 1;
    }
    if (isset($kArray[$y])) {
        $kArray[$y]++;
    } else {
        $kArray[$y] = 1;
    }
}

$result = 2000000;

for ($i = 0; $i < $q; $i++) {
    $has = array();
    $x = $vArray[$i][0];
    $y = $vArray[$i][1];

    foreach ($aArray[$x] as $t=>$f) {
        if (isset($aArray[$y][$t])) {
            $result = min($result, $kArray[$x] + $kArray[$y] + $kArray[$t]-6);
        }
    }

}
echo $result == 2000000 ? "-1" : $result;

<?php
$knights_arr = array();
$groups = array();
$recognation = array();
$r = 0;

$file = STDIN;

list($vNumber, $q) = explode(" ", trim(fgets($file)));

for ($i = 0; $i < $q; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));

if($i == 0){
		continue;
	}

	if(empty($knights_arr[$x])){
		$knights_arr[$x] = array();
	}
	$knights_arr[$x][] = $y;
	if(empty($knights_arr[$y])){
		$knights_arr[$y] = array();
	}
	$knights_arr[$y][] = $x;

}

ksort($knights_arr,1);
foreach($knights_arr as $key => $arr){
	if ( count($arr) < 2 ) {
		continue;
	}
	sort($arr);
	foreach($arr as $i => $sec){
		if($sec < $key || count($knights_arr[$sec]) < 2 || ($i == count($arr)-1) ){
			continue;
		}
		$rem_arr = array_slice($arr, $i+1);
		foreach($rem_arr as $thrd){
			if($thrd > $sec && in_array($key, $knights_arr[$thrd]) && in_array($sec, $knights_arr[$thrd])){
				$group[$r] =  "$key-$sec-$thrd";
				$recognation[$r] = count($knights_arr[$key]) + count($knights_arr[$sec]) + count($knights_arr[$thrd]) - 6;
				$r++;
			}
		}
	}
}
if($r == 0){
	echo -1;
}else{
	echo min($recognation);
}

<?php
$file = STDIN;
list($vNumber, $q) = explode(" ", trim(fgets($file)));
$lines = array('0 0');
for ($i = 0; $i < $q; $i++) {
 $lines[] = trim(fgets($file));
}

foreach ($lines as &$line) {
$line = explode(" ", $line);
}
unset($lines[0]);

$probabilities = array();
$summations = array();
for($i = 1 ; $i <= sizeof($lines); $i++){
	for($j = $i+1 ; $j <= sizeof($lines) ; $j++){
		for($k = $j+1 ; $k <= sizeof($lines) ; $k++){
			$probabilities = array();
			$probabilities[$lines[$i][0]]++;
			$probabilities[$lines[$i][1]]++;
			$probabilities[$lines[$j][0]]++;
			$probabilities[$lines[$j][1]]++;
			$probabilities[$lines[$k][0]]++;
			$probabilities[$lines[$k][1]]++;
			$counter = 0;
			foreach ($probabilities as $probability) {
				if($probability == 2)
					$counter++;
			}
			if($counter == 3){
				getSummation($probabilities, $i, $j, $k);
			}
		}
	}
}

echo min($summations);
function getSummation($probabilities, $i, $j, $k){
	global $lines;
	global $summations;
	$selection = array_keys($probabilities);
	$sum = 0;
	foreach($lines as $key => $line){
		if($key == $i || $key == $j || $key == $k)
			continue;
		if($line[0] == $selection[0] || $line[0] == $selection[1] || $line[0] == $selection[2]
			|| $line[1] == $selection[0] || $line[1] == $selection[1] || $line[1] == $selection[2])
			$sum ++;
	}
	$summations[] = $sum;
}


<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aAnswer = [];
    $aTest = [];
    $aR = [];
    $aList = explode(' ', trim(fgets(STDIN)));
    sort($aList);
    foreach ($aList as $sK => $sV) {
        if (!isset($aTest[$sV])) {
            $aTest[$sV] = $sV;
        } else {
            $aR[$sK] = $sV;
        }
    }
    $aAnswer = array_merge($aTest , $aR);
    foreach ($aAnswer as $sK => $sV) {
        echo $sV . ' ';
    }
    echo "\n";
}

<?php
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    sort($a);
    $b = $c = [];
    foreach ($a as $v) {
        if(isset($b[$v])) {
            $c[] = $v;
        } else {
            $b[$v] = $v;
        }
    }
    IO::line(implode(' ', $b) . ' ' . implode(' ', $c));
}

<?php

$n = readline();
$final = array();
$cnt = 0;
while($n--) {
    $res = array();
    $buf = array();
    $k = readline();
    $arr = explode(' ', readline());
    sort($arr);
    for ($i = 0; $i < $k; $i++) {
        if ($i == $k - 1) {
            $res[] = $arr[$i];
        } elseif ($arr[$i] == $arr[$i+1]) {
            $buf[] = $arr[$i];
            unset($arr[$i]);
        } else {
            $res[] = $arr[$i];
        }
    }
    $final[] = array_merge($res, $buf);
    $cnt++;
}

//print_r($final);
//exit;
//print_r($res);
//print_r($res);
foreach ($final as $r) {
    foreach ($r as $item) {
        echo $item . ' ';
    }
    echo "\n";
}

<?php
fscanf(STDIN, "%d", $n);
while ($n--) {
    fgets(STDIN);
    $a = fgetcsv(STDIN, 0, ' ');
    $b = array_unique($a);
    sort($b, SORT_NUMERIC);
    echo $b ? implode(' ', $b) : 0;
    $b = array_fill_keys($b, true);
    foreach ($a as $value) {
        if (empty($b[$value])) {
            echo ' ', $value;
        } else {
            unset($b[$value]);
        }
    }
    echo "\n";
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aAnswer = [];
    $aTest = [];
    $aR = [];
    $aList = explode(' ', trim(fgets(STDIN)));
    sort($aList);
    foreach ($aList as $sK => $sV) {
        if (!isset($aTest[$sK])) {
            $aTest[$sK] = $sV;
        } else {
            $aR[$sK] = $sV;
        }
    }
    $aAnswer = array_merge($aTest , $aR);
    foreach ($aAnswer as $sK => $sV) {
        echo $sV . ' ';
    }
    echo "\n";
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aAnswer = [];
    $aTest = [];
    $aR = [];
    $aList = explode(' ', trim(fgets(STDIN)));
    sort($aList);
    foreach ($aList as $sK => $sV) {
        if (!isset($aTest[$sV])) {
            $aTest[$sK] = $sV;
        } else {
            $aR[$sK] = $sV;
        }
    }
    $aAnswer = array_merge($aTest , $aR);
    foreach ($aAnswer as $sK => $sV) {
        echo $sV . ' ';
    }
    echo "\n";
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aAnswer = [];
    $aTest = [];
    $aR = [];
    $aList = explode(' ', trim(fgets(STDIN)));
    sort($aList);
    foreach ($aList as $sK => $sV) {
        if (!isset($aTest[$sV])) {
            $aTest[$sV] = $sV;
        } else {
            $aR[$sV] = $sV;
        }
    }
    $aAnswer = array_merge($aTest , $aR);
    foreach ($aAnswer as $sK => $sV) {
        echo $sV . ' ';
    }
    echo "\n";
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aAnswer = [];
    $aTest = [];
    $aR = [];
    $aList = explode(' ', trim(fgets(STDIN)));
    asort($aList);
    foreach ($aList as $sK => $sV) {
        if (!isset($aTest[$sV])) {
            $aTest[$sV] = $sV;
        } else {
            $aR[$sV] = $sV;
        }
    }
    $aAnswer = array_merge($aTest , $aR);
    foreach ($aAnswer as $sK => $sV) {
        echo $sV . ' ';
    }
    echo "\n";
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aTest = [];
    $aR = [];
    $aList = explode(' ', trim(fgets(STDIN)));
    asort($aList);
    foreach ($aList as $sK => $sV) {
        if (!isset($aTest[$sV])) {
            $aTest[$sV] = $sV;
        } else {
            $aR[$sV] = $sV;
        }
    }
    $aAnswer = array_merge($aTest , $aR);
    echo implode(" ",$aAnswer). "\n";
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aTest = [];
    $aR = [];
    $aList = explode(' ', trim(fgets(STDIN)));
    asort($aList);
    foreach ($aList as $sK => $sV) {
        if (!isset($aTest[$sV])) {
            $aTest[$sV] = $sV;
        } else {
            $aR[$sV] = $sV;
        }
    }

    echo implode(" ",$aTest) . " " . implode(" ",$aR) . "\n";
}

<?php
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    sort($a);
    $b = $c = [];
    foreach ($a as $v) {
        if(isset($b[$v])) {
            $c[$v] = $v;
        } else {
            $b[$v] = $v;
        }
    }
    IO::line(implode(' ', $b) . ' ' . implode(' ', $c));
}


<?php
error_reporting("off");
//214B: Hometask
$n = trim(fgets(STDIN)); //$n = 11;
$digits = explode(" ", trim(fgets(STDIN))); //$digits = explode(" ", "3 9 9 6 4 3 6 4 9 6 0"); //999666330
rsort($digits);
$answer = 0;

//let's construct some sets of 1mod3 and 2mod3 digits
$onemodthree = array();
$twomodthree = array();
foreach ($digits as $value) {
    if ($value % 3 == 1) {
        $onemodthree[] = $value;
    } elseif ($value % 3 == 2) {
        $twomodthree[] = $value;
    }
}
sort($onemodthree);
sort($twomodthree);

//to be divisible by 2 and 5 the last digit has to be 0
if (!in_array(0, $digits)) { //if there's no 0 there's no way
    $answer = -1;
} else { //there's a zero
    $sum = array_sum($digits);
    if ($sum % 3 == 0) { //if it's divisible by 3, great!
        $answer = implode($digits); //also can be 00000...
    } elseif ($sum % 3 == 1) { //1mod3
        //check to delete just one digit to make it 0mod3
        if (isset($onemodthree[0])) {
            unset($digits[array_search($onemodthree[0], $digits)]);
        } else { //if you can't delete only one digit you have to delete two; it's always possible.
            unset($digits[array_search($twomodthree[0], $digits)]);
            unset($digits[array_search($twomodthree[1], $digits)]);
        }
        rsort($digits);
        $answer = implode($digits);
    } elseif ($sum % 3 == 2) { //2mod3
        //check to delete just one digit to make it 0mod3
        if (isset($twomodthree[0])) {
            unset($digits[array_search($twomodthree[0], $digits)]);
        } else { //if you can't delete only one digit you have to delete two; it's always possible.
            unset($digits[array_search($onemodthree[0], $digits)]);
            unset($digits[array_search($onemodthree[1], $digits)]);
        }
        rsort($digits);
        $answer = implode($digits);
    }
}

if (substr($answer, 0, 1) == "0") {
    $answer = 0;
}

echo $answer;
?>

<?php
error_reporting("off");
//214B: Hometask
$n = trim(fgets(STDIN)); //$n = 6;
$digits = explode(" ", trim(fgets(STDIN))); //$digits = explode(" ", "1 0 0 0 0 0");
rsort($digits);
$answer = 0;

//let's construct some sets of 1mod3 and 2mod3 digits
$onemodthree = array();
$twomodthree = array();
foreach ($digits as $value) {
    if ($value % 3 == 1) {
        $onemodthree[] = $value;
    } elseif ($value % 3 == 2) {
        $twomodthree[] = $value;
    }
}
sort($onemodthree);
sort($twomodthree);

//to be divisible by 2 and 5 the last digit has to be 0
if (!in_array(0, $digits)) { //if there's no 0 there's no way
    $answer = -1;
} else { //there's a zero
    $sum = array_sum($digits);
    if ($sum % 3 == 0) { //if it's divisible by 3, great!
        $answer = implode($digits); //also can be 00000...
    } elseif ($sum % 3 == 1) { //1mod3
        //check to delete just one digit to make it 0mod3
        if (isset($onemodthree[0])) {
            unset($digits[array_search($onemodthree[0], $digits)]);
        } else { //if you can't delete only one digit you have to delete two; it's always possible.
            $twounique = array_unique($twomodthree);
            unset($digits[array_search($twounique[0], $digits)]);
            unset($digits[array_search($twounique[1], $digits)]);
        }
        rsort($digits);
        $answer = implode($digits);
    } elseif ($sum % 3 == 2) { //2mod3
        //check to delete just one digit to make it 0mod3
        if (isset($twomodthree[0])) {
            unset($digits[array_search($twomodthree[0], $digits)]);
        } else { //if you can't delete only one digit you have to delete two; it's always possible.
            $oneunique = array_unique($onemodthree);
            unset($digits[array_search($oneunique[0], $digits)]);
            unset($digits[array_search($oneunique[1], $digits)]);
        }
        rsort($digits);
        $answer = implode($digits);
    }
}

if (substr($answer, 0, 1) == "0") {
    $answer = 0;
}

echo $answer;
?>


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

$line = trim(fgets($h));
$line_arr = explode(' ', $line);
$n = intval($line_arr[0]);
$n1 = intval($line_arr[1]);
$n2 = intval($line_arr[2]);

$line2 = trim(fgets($h));
$line_2_arr = explode(' ', $line2);
$arr = array_map('intval', $line_2_arr);

rsort($arr);
$total = $n1 + $n2;

$arr = array_slice($arr, 0, $total);

if ($n1 > $n2) {
	$temp = $n1;
	$n1 = $n2;
	$n2 = $temp;
}

$arr1 = array_slice($arr, 0, $n1);
$arr2 = array_slice($arr, $n1);

$res = array_sum($arr1)/$n1 + array_sum($arr2)/$n2;

echo $res;

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
rsort($d);
if(($b + $c == $a) && ($b < $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif(($b + $c == $a) && ($b == $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $b);
     print number_format($i, 6, '.', '');
}
elseif(($b + $c == $a) && ($b > $c))
{
     $e = array_slice($d, 0, $c);
     $f = array_slice($d, $c);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $c) + ($h / $b);
     print number_format($i, 6, '.', '');
}
elseif($b < $c)
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b, $c);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif($b == $c)
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $b);
     print number_format($i, 6, '.', '');
}
elseif($b > $c)
{
     $e = array_slice($d, 0, $c);
     $f = array_slice($d, $c, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $c) + ($h / $b);
     print number_format($i, 6, '.', '');
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
rsort($d);
if(($b + $c == $a) && ($b < $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif(($b + $c == $a) && ($b == $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $b);
     print number_format($i, 6, '.', '');
}
elseif(($b + $c == $a) && ($b > $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = bcadd(bcdiv($g, $b), bcdiv($h, $c));
     print number_format($i, 6, '.', '');
}
elseif($b < $c)
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b, $c);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif($b == $c)
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $b);
     print number_format($i, 6, '.', '');
}
elseif($b > $c)
{
     $e = array_slice($d, 0, $c);
     $f = array_slice($d, $c, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $c) + ($h / $b);
     print number_format($i, 6, '.', '');
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
rsort($d);
if(($b + $c == $a) && ($b < $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif(($b + $c == $a) && ($b == $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $b);
     print number_format($i, 6, '.', '');
}
elseif(($b + $c == $a) && ($b > $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif($b < $c)
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b, $c);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif($b == $c)
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $b);
     print number_format($i, 6, '.', '');
}
elseif($b > $c)
{
     $e = array_slice($d, 0, $c);
     $f = array_slice($d, $c, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $c) + ($h / $b);
     print number_format($i, 6, '.', '');
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
rsort($d);
if(($b + $c == $a) && ($b < $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif(($b + $c == $a) && ($b == $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif(($b + $c == $a) && ($b > $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif($b < $c)
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b, $c);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif($b == $c)
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $b);
     print number_format($i, 6, '.', '');
}
elseif($b > $c)
{
     $e = array_slice($d, 0, $c);
     $f = array_slice($d, $c, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $c) + ($h / $b);
     print number_format($i, 6, '.', '');
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
rsort($d);
if(($b + $c == $a) && ($b < $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif(($b + $c == $a) && ($b == $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $b);
     print number_format($i, 6, '.', '');
}
elseif(($b + $c == $a) && ($b > $c))
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $c) + ($h / $b);
     print number_format($i, 6, '.', '');
}
elseif($b < $c)
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b, $c);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $c);
     print number_format($i, 6, '.', '');
}
elseif($b == $c)
{
     $e = array_slice($d, 0, $b);
     $f = array_slice($d, $b, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $b) + ($h / $b);
     print number_format($i, 6, '.', '');
}
elseif($b > $c)
{
     $e = array_slice($d, 0, $c);
     $f = array_slice($d, $c, $b);
     $g = array_sum($e);
     $h = array_sum($f);
     $i = ($g / $c) + ($h / $b);
     print number_format($i, 6, '.', '');
}
?>


<?php
list($n, $k) = explode(' ', trim(fgets(STDIN)));
list($s) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));
$iCount = 0;
$j = 0;
for($i = 0; $i < strlen($s); $i++){
    if(in_array($s[$i],$aArray)){
        $j = $j + 1;
    } else {
        $iCount += ($j*($j + 1))/2;
        $j = 0;
    }
    if ($i == (strlen($s) - 1) && $j > 0) {
        $iCount += ($j*($j + 1))/2;
        $j = 0;
    }
}
echo $iCount . "\n";


<?php
class flclass{
var $num;
var $time;
var $team;
var $count;
var $out;
function __construct($a,$b,$c,$d){
$this->num = $a;
$this->time = $b;
$this->team = $c;
$this->count += $d;
$this->out = true;
$this->rec();
}
function upd($a,$b){
$this->time = $a;
$this->count += $b;
$this->rec();
}
function rec(){
if($this->count >= 2 && $this->out){
printf ("%s %d %d\n",$this->team,$this->num,$this->time);
$this->out = false;
}
}
}
$name__ = array();
$name___h = trim(fgets(STDIN));
$name___a = trim(fgets(STDIN));
$flclasss = array();
$n = trim(fgets(STDIN));
for ($i=0;$i<$n;$i++){
list($t,$a,$m,$b) = explode(" ",trim(fgets(STDIN)));
$b = ($b=='r')? 2 : 1;
$a = ($a=='h')? $name___h : $name___a;
if (!isset($flclasss[$a.$m])){
$flclasss[$a.$m]= new flclass($m,$t,$a,$b);
}else{
$flclasss[$a.$m]->upd($t,$b);
}
}
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$h = array();
array_unshift($h, " ");
unset($h[0]);
$i = array();
array_unshift($i, " ");
unset($i[0]);
$j = array();
$l = array();
array_unshift($l, " ");
unset($l[0]);
for($x = 1; $x <= $c; $x++)
{
    list($d, $e, $f, $g) = explode(" ", trim(fgets(STDIN)));
    if($g == "r")
    {
        $k = array_search($e . $f . $g, $h);
        $n = array_search($e . $f, $l);
        if(($k == FALSE) && ($n == FALSE))
        {
            if($e == "a")
            {
                array_push($j, $b . " " . $f . " " . $d);
            }
            else
            {
                array_push($j, $a . " " . $f . " " . $d);
            }
        }
        array_push($h, $e . $f . $g);
        array_push($i, "0");
        array_push($l, $e . $f);
    }
    else
    {
        $k = array_search($e . $f . $g, $h);
        $m = array_search($e . $f, $l);
        if(($k == TRUE) && ($i[$k] == 0) && ($l[$m] == FALSE))
        {
            $i[$k] = 1;
            array_push($l, $e . $f);
            if($e == "a")
            {
                array_push($j, $b . " " . $f . " " . $d);
            }
            else
            {
                array_push($j, $a . " " . $f . " " . $d);
            }
        }
        else
        {
            array_push($h, $e . $f . $g);
            array_push($i, "0");
        }
    }
}
for($x = 0; $x < count($j) - 1; $x++)
{
    print $j[$x] . "\n";
}
print $j[$x];
?>

<?php
	$fh = fopen("php://stdin", "r");
	$home = fgets($fh);
	$away = fgets($fh);
	$ncase = (int)(fgets($fh));
	$cases = array();
	for($i=0;$i<$ncase;$i++)
	{
		$cases[] = fgets($fh);
	}

	$reds = array();
    $yellow = array();
	foreach($cases as $case)
	{
		$caseAr =  explode(" ",$case);
		$player =  $caseAr[1].$caseAr[2];
		$time   =  $caseAr[0];
		$card   =  trim($caseAr[3]);
		if(! array_key_exists($player,$reds))
		{
			if(($card == "r") || (array_key_exists($player, $yellow)))
			{
				$team = ($caseAr[1]=="h") ?"$home":"$away";
				$nos  = $caseAr[2];
				$time = $caseAr[0];
				echo trim($team).' '.$nos.' '.$time."\n";
				$reds[$player] = $time;
			}
			else
			{
				$yellow[$player] = $time;
			}
		}

	}

	/*
	ASGDFJH
AHGRSDXGER
3
23 h 15 r
68 h 15 y
79 h 15 y
Output
ASGDFJH 15 79
Answer
ASGDFJH 15 23
Checker Log
wrong answer 1st lines differ - expected: 'ASGDFJH 15 23', found: 'ASGDFJH 15 79'

*/

<?php
class fl{
var $numq;
var $time;
var $team;
var $count;
var $out;
function __construct($a,$b,$c,$d){
$this->numq = $a;
$this->time = $b;
$this->team = $c;
$this->count += $d;
$this->out = true;
$this->rec();
}
function upd($a,$b){
$this->time = $a;
$this->count += $b;
$this->rec();
}
function rec(){
if($this->count >= 2 && $this->out){
printf ("%s %d %d\n",$this->team,$this->numq,$this->time);
$this->out = false;
}
}
}
$name = array();
$name_h = trim(fgets(STDIN));
$name_a = trim(fgets(STDIN));
$fls = array();
$n = trim(fgets(STDIN));
for ($i=0;$i<$n;$i++){
list($t,$a,$m,$b) = explode(" ",trim(fgets(STDIN)));
$b = ($b=='r')? 2 : 1;
$a = ($a=='h')? $name_h : $name_a;
if (!isset($fls[$a.$m])){
$fls[$a.$m]= new fl($m,$t,$a,$b);
}else{
$fls[$a.$m]->upd($t,$b);
}
}

<?php
$arr2 = array();

class calc {
    var $number;
    var $time;
    var $team;
    var $count;
    var $out;
    function __construct($a,$b,$c,$d){
        $this->number = $a;
        $this->time = $b;
        $this->team = $c;
        $this->count += $d;
        $this->output = true;
        $this->record();
    }
    function update($a,$b){
        $this->time = $a;
        $this->count += $b;
        $this->record();
    }
    function record(){
        global $arr2;
        if ($this->count >= 2 && $this->output){
            $arr2[$this->time] = sprintf("%s %d %d\n",$this->team,$this->number,$this->time);
            $this->output = false;
        }
    }
}

$name = array();
$name_h = trim(fgets(STDIN));
$name_a = trim(fgets(STDIN));
$n = trim(fgets(STDIN));

$arr = array();
for ($i=0; $i<$n; $i++) {
    list($t,$a,$m,$b) = explode(" ",trim(fgets(STDIN)));
    $b = ($b == 'r')? 2 : 1;
    $a = ($a == 'h')? $name_h : $name_a;
    if (!isset($arr[$a.$m])) {
        $arr[$a.$m] = new calc($m,$t,$a,$b);
    } else {
        $arr[$a.$m]->update($t,$b);
    }
}
ksort($arr2);
foreach ($arr2 as $value){
    echo $value;
}
?>

<?php
$file = fopen("php://stdin", "r");
// $file = fopen("493A.txt", "r");
$teamName["h"] = trim(fgets($file));
$teamName["a"] = trim(fgets($file));
$round = trim(fgets($file));

$history = array();
for($i=0;$i<$round;$i++){
    $perHis = fgets($file);

    //place==h||a , card==y||r
    $base = explode(" ", $perHis);
    $time = $base[0];
    $place = $base[1];
    $number = $base[2];
    $card = trim($base[3]);
    $key = $place.$number;

    if($card == "r"){
        if(array_key_exists($key, $history)){
            if($history[$key]==1){
                echo $teamName[$place]." ".$number." ".$time."\n";
                $history[$key] = 2;
            }
        }else{
            echo $teamName[$place]." ".$number." ".$time."\n";
                $history[$key] = 2;
        }
    }else if($card =="y"){
        if(array_key_exists($key,$history)){
            if($history[$key]==1){
                $history[$key] =2;
                echo $teamName[$place]." ".$number." ".$time."\n";
            }else if($history[$key]==1){
                echo $teamName[$place]." ".$number." ".$time."\n";
            }
        }else{
            $history[$key] = 1;
        }
    }
}

?>

<?php
	$fls2 = array();
	class fl{
		var $num;
		var $time;
		var $team;
		var $count;
		var $out;
		function __construct($a,$b,$c,$d){
			$this->num = $a;
			$this->time = $b;
			$this->team = $c;
			$this->count += $d;
			$this->out = true;
			$this->rec();
		}
		function upd($a,$b){
			$this->time = $a;
			$this->count += $b;
			$this->rec();
		}
		function rec(){
			global $fls2;
			if($this->count >= 2 && $this->out){
				$fls2[$this->time] = sprintf ("%s %d %d\n",$this->team,$this->num,$this->time);
				$this->out = false;
			}
		}
	}
	$name_h = trim(fgets(STDIN));
	$name_a = trim(fgets(STDIN));
	$fls = array();
	$n = trim(fgets(STDIN));
	for ($i=0;$i<$n;$i++){
		list($t,$a,$m,$b) = explode(" ",trim(fgets(STDIN)));
		$b = ($b=='r')? 2 : 1;
		$a = ($a=='h')? $name_h : $name_a;
		if (!isset($fls[$a.$m])){
			$fls[$a.$m]= new fl($m,$t,$a,$b);
		}else{
			$fls[$a.$m]->upd($t,$b);
		}
	}
	ksort($fls2);
	foreach($fls2 as $fl){
		echo $fl;
	}
?>

<?php
class fl{
var $num;
var $time;
var $team;
var $count;
var $out;
function __construct($a1,$b,$c,$d){
$this->num = $a1;
$this->time = $b;
$this->team = $c;
$this->count += $d;
$this->out = true;
$this->rec();
}
function upd($a1,$b){
$this->time = $a1;
$this->count += $b;
$this->rec();
}
function rec(){
if($this->count >= 2 && $this->out){
printf ("%s %d %d\n",$this->team,$this->num,$this->time);
$this->out = false;
}
}
}
$name = array();
$name_h = trim(fgets(STDIN));
$name_a = trim(fgets(STDIN));
$fls = array();
$n = trim(fgets(STDIN));
for ($i=0;$i<$n;$i++){
list($t,$a1,$m,$b) = explode(" ",trim(fgets(STDIN)));
$b = ($b=='r')? 2 : 1;
$a1 = ($a1=='h')? $name_h : $name_a;
if (!isset($fls[$a1.$m])){
$fls[$a1.$m]= new fl($m,$t,$a1,$b);
}else{
$fls[$a1.$m]->upd($t,$b);
}
}
?>

<?php
 class fl{
  var $avfhk;
  var $loinvds;
  var $pknndfj;
  var $hbjbskblj;
  var $hbhhnbnbnk;
  function __construct($a,$b,$c,$d){
   $this->avfhk = $a;
   $this->loinvds = $b;
   $this->pknndfj = $c;
   $this->hbjbskblj += $d;
   $this->hbhhnbnbnk = true;
   $this->rec();
  }
  function upd($a,$b){
   $this->loinvds = $a;
   $this->hbjbskblj += $b;
   $this->rec();
  }
  function rec(){
   if($this->hbjbskblj >= 2 && $this->hbhhnbnbnk){
    printf ("%s %d %d\n",$this->pknndfj,$this->avfhk,$this->loinvds);
    $this->hbhhnbnbnk = false;
   }
  }
 }
 $omnomnom = array();
 $omnomnom_h = trim(fgets(STDIN));
 $omnomnom_a = trim(fgets(STDIN));
 $fls = array();
 $n = trim(fgets(STDIN));
 for ($i=0;$i<$n;$i++){
  list($t,$a,$m,$b) = explode(" ",trim(fgets(STDIN)));
  $b = ($b=='r')? 2 : 1;
  $a = ($a=='h')? $omnomnom_h : $omnomnom_a;
  if (!isset($fls[$a.$m])){
   $fls[$a.$m]= new fl($m,$t,$a,$b);
  }else{
   $fls[$a.$m]->upd($t,$b);
  }
 }
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$h = array();
array_unshift($h, " ");
unset($h[0]);
$i = array();
array_unshift($i, " ");
unset($i[0]);
$j = array();
$l = array();
array_unshift($l, " ");
unset($l[0]);
for($x = 1; $x <= $c; $x++)
{
    list($d, $e, $f, $g) = explode(" ", trim(fgets(STDIN)));
    if($g == "r")
    {
        $k = array_search($e . $f . $g, $h);
        if($k == FALSE)
        {
            if($e == "a")
            {
                array_push($j, $b . " " . $f . " " . $d);
            }
            else
            {
                array_push($j, $a . " " . $f . " " . $d);
            }
        }
        array_push($h, $e . $f . $g);
        array_push($i, "0");
        array_push($l, $e . $f);
    }
    else
    {
        $k = array_search($e . $f . $g, $h);
        $m = array_search($e . $f, $l);
        if(($k == TRUE) && ($i[$k] == 0) && ($l[$m] == FALSE))
        {
            $i[$k] = 1;
            if($e == "a")
            {
                array_push($j, $b . " " . $f . " " . $d);
            }
            else
            {
                array_push($j, $a . " " . $f . " " . $d);
            }
        }
        else
        {
            array_push($h, $e . $f . $g);
            array_push($i, "0");
        }
    }
}
for($x = 0; $x < count($j) - 1; $x++)
{
    print $j[$x] . "\n";
}
print $j[$x];
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$h = array();
array_unshift($h, " ");
unset($h[0]);
$i = array();
array_unshift($i, " ");
unset($i[0]);
$j = array();
for($x = 1; $x <= $c; $x++)
{
    list($d, $e, $f, $g) = explode(" ", trim(fgets(STDIN)));
    if($g == "r")
    {
        $k = array_search($e . $f . $g, $h);
        if($k == FALSE)
        {
            if($e == "a")
            {
                array_push($j, $b . " " . $f . " " . $d);
            }
            else
            {
                array_push($j, $a . " " . $f . " " . $d);
            }
        }
        array_push($h, $e . $f . $g);
        array_push($i, "0");
    }
    else
    {
        $k = array_search($e . $f . $g, $h);
        if(($k == TRUE) && ($i[$k] == 0))
        {
            $i[$k] = 1;
            if($e == "a")
            {
                array_push($j, $b . " " . $f . " " . $d);
            }
            else
            {
                array_push($j, $a . " " . $f . " " . $d);
            }
        }
        else
        {
            array_push($h, $e . $f . $g);
            array_push($i, "0");
        }
    }
}
for($x = 0; $x < count($j) - 1; $x++)
{
    print $j[$x] . "\n";
}
print $j[$x];
?>

<?php
	$fh = fopen("php://stdin", "r");
	$home = fgets($fh);
	$away = fgets($fh);
	$ncase = (int)(fgets($fh));
	$cases = array();
	for($i=0;$i<$ncase;$i++)
	{
		$cases[] = fgets($fh);
	}

	$reds = array();
    $yellow = array();
	foreach($cases as $case)
	{
		$caseAr =  explode(" ",$case);
		$player =  $caseAr[1].$caseAr[2];
		$time   =  $caseAr[0];
		$card   =  trim($caseAr[3]);
		if($card == "r")
		{
			if(array_key_exists($player,$reds)) continue;
			$reds[$player] = $time;
			continue;
		}
		if(array_key_exists($player, $yellow))
		{
			$reds[$player] = $time;
			unset($yellow[$player]);
		}
		else
		{
			$yellow[$player] = $time;
		}

	}

	if(count($reds)> 0)
	{
		foreach($reds as $key=>$value)
		{
			$team = (substr($key,0,1)=="h") ?"$home":"$away";
			$nos  = substr($key,1,strlen($key)-1);
			$time = $value;
			echo trim($team).' '.$nos.' '.$value."\n";

		}

	}

	/*
	TANC
XNCOR
2
15 h 27 r
28 h 27 r
*/

<?php
	$fh = fopen("php://stdin", "r");
	$home = fgets($fh);
	$away = fgets($fh);
	$ncase = (int)(fgets($fh));
	$cases = array();
	for($i=0;$i<$ncase;$i++)
	{
		$cases[] = fgets($fh);
	}

	$reds = array();
    $yellow = array();
	foreach($cases as $case)
	{
		$caseAr =  explode(" ",$case);
		$player =  $caseAr[1].$caseAr[2];
		$time   =  $caseAr[0];
		$card   =  trim($caseAr[3]);
		if(array_key_exists($player,$reds))
		{
			continue;
		}
		else
		{
			$reds[$player] = $time;
			continue;

		}

		if(array_key_exists($player, $yellow))
		{
			$reds[$player] = $time;
			unset($yellow[$player]);
		}
		else
		{
			$yellow[$player] = $time;
		}

	}

	if(count($reds)> 0)
	{
		foreach($reds as $key=>$value)
		{
			$team = (substr($key,0,1)=="h") ?"$home":"$away";
			$nos  = substr($key,1,strlen($key)-1);
			$time = $value;
			echo trim($team).' '.$nos.' '.$value."\n";

		}

	}

	/*
	ASGDFJH
AHGRSDXGER
3
23 h 15 r
68 h 15 y
79 h 15 y
Output
ASGDFJH 15 79
Answer
ASGDFJH 15 23
Checker Log
wrong answer 1st lines differ - expected: 'ASGDFJH 15 23', found: 'ASGDFJH 15 79'

*/

<?php
	$fh = fopen("php://stdin", "r");
	$home = fgets($fh);
	$away = fgets($fh);
	$ncase = (int)(fgets($fh));
	$cases = array();
	for($i=0;$i<$ncase;$i++)
	{
		$cases[] = fgets($fh);
	}

	$reds = array();
    $yellow = array();
	foreach($cases as $case)
	{
		$caseAr =  explode(" ",$case);
		$player =  $caseAr[1].$caseAr[2];
		$time   =  $caseAr[0];
		$card   =  trim($caseAr[3]);
		if($card == "r")
		{
			$reds[$player] = $time;
			continue;
		}
		if(array_key_exists($player, $yellow))
		{
			$reds[$player] = $time;
			unset($yellow[$player]);
		}
		else
		{
			$yellow[$player] = $time;
		}

	}

	if(count($reds)> 0)
	{
		foreach($reds as $key=>$value)
		{
			$team = (substr($key,0,1)=="h") ?"$home":"$away";
			$nos  = substr($key,1,strlen($key)-1);
			$time = $value;
			echo trim($team).' '.$nos.' '.$value."\n";

		}

	}

<?php
$file = fopen("php://stdin", "r");
// $file = fopen("493A.txt", "r");
$nameH = trim(fgets($file));
$nameA = trim(fgets($file));
$round = trim(fgets($file));

$arrayH = array();
$arrayA = array();
for($i=0;$i<$round;$i++){
    $perHis = fgets($file);
    //0-time,1-place,2-number,3-color
    //place=h/a , card=y/r
    $baseArray = "";
    $baseArray = explode(" ", $perHis);
    if($baseArray[1]=="h"){
        if(in_array($baseArray[2], $arrayH)){
            echo $nameH." ".$baseArray[2]." ".$baseArray[0]."\n";
            $arrayH[$i] = "";
        }else{
            $arrayH[] = $baseArray[2];
        }
    }else if($baseArray[1]=="a"){
        if(in_array($baseArray[2],$arrayA)){
            echo $nameA." ".$baseArray[2]." ".$baseArray[0]."\n";
            $arrayA[$i] = "";
        }else{
            $arrayA[] = $baseArray[2];
        }
    }
}

?>

<?php
$file = fopen("php://stdin", "r");
// $file = fopen("493A.txt", "r");
$teamName["h"] = trim(fgets($file));
$teamName["a"] = trim(fgets($file));
$round = trim(fgets($file));

$history = array();
for($i=0;$i<$round;$i++){
    $perHis = fgets($file);

    //place==h||a , card==y||r
    $base = explode(" ", $perHis);
    $time = $base[0];
    $place = $base[1];
    $number = $base[2];
    $card = trim($base[3]);
    $key = $place.$number;

    if($card == "r"){
        echo $teamName[$place]." ".$number." ".$time."\n";
        if(array_key_exists($key, $history)){
            $history[$key] = 0;
        }
    }else if($card =="y"){
        if(array_key_exists($key,$history)){
            if($history[$key]==0){
                $history[$key] =1;
            }else{
                echo $teamName[$place]." ".$number." ".$time."\n";
            }
        }else{
            $history[$key] = 1;
        }
    }
}

?>

<?php
class fl{
var $num;
var $time;
var $team;
var $count;
var $out;
function __construct($e,$b,$c,$d){
$this->num = $e;
$this->time = $b;
$this->team = $c;
$this->count += $d;
$this->out = true;
$this->rec();
}
function upd($a,$b){
$this->time = $e;
$this->count += $b;
$this->rec();
}
function rec(){
if($this->count >= 2 && $this->out){
printf ("%s %d %d\n",$this->team,$this->num,$this->time);
$this->out = false;
}
}
}
$name = array();
$name_h = trim(fgets(STDIN));
$name_e = trim(fgets(STDIN));
$fls = array();
$n = trim(fgets(STDIN));
for ($i=0;$i<$n;$i++){
list($t,$e,$m,$b) = explode(" ",trim(fgets(STDIN)));
$b = ($b=='r')? 2 : 1;
$e = ($e=='h')? $name_h : $name_e;
if (!isset($fls[$e.$m])){
$fls[$e.$m]= new fl($m,$t,$e,$b);
}else{
$fls[$e.$m]->upd($t,$b);
}
}
?>

<?php
$h_team = trim(fgets(STDIN));
$a_team = trim(fgets(STDIN));
$count_of_falls = trim(fgets(STDIN));
$arr = array();
for ($i=0; $i<$count_of_falls; $i++) {
 $arr[] = explode(" ", trim(fgets(STDIN)));
}

for ($i=0; $i<$count_of_falls; $i++) {
 if ($arr[$i][1] == "h") {
 $arr_h[] = $arr[$i];
 } else if ($arr[$i][1] == "a") {
 $arr_a[] = $arr[$i];
 }
}
//print_r($arr_h);
//print_r($arr_a);

$arr_falls_h = array();
for ($i=0; $i<count($arr_h); $i++) {
 if (array_key_exists($arr_h[$i][2], $arr_falls_h) or $arr_h[$i][3] == "r") {
 $arr_falls_h[$arr_h[$i][2]] = array(2, $arr_h[$i][0], $arr_h[$i][2]);
 } else {
 $arr_falls_h[$arr_h[$i][2]] = 1;
 }
}
$arr_falls_a = array();
for ($i=0; $i<count($arr_a); $i++) {
 if (array_key_exists($arr_a[$i][2], $arr_falls_a) or $arr_a[$i][3] == "r") {
 $arr_falls_a[$arr_a[$i][2]] = array(2, $arr_a[$i][0], $arr_a[$i][2]);
 } else {
 $arr_falls_a[$arr_a[$i][2]] = 1;
 }
}
//print_r($arr_falls_h);
//print_r($arr_falls_a);

foreach ($arr_falls_h as $value) {
 if (!empty($value[0])) {
 echo $h_team." ".$value[2]." ".$value[1]."\n";
 }
}
foreach ($arr_falls_a as $value) {
 if (!empty($value[0])) {
 echo $a_team." ".$value[2]." ".$value[1]."\n";
 }
}
?>


<?php
list($count, $range) = explode(" ", fgets(STDIN));
$count = (int) $count;
$range = (int) $range;
$arr = explode(" ", fgets(STDIN));
$velo = 0;

$pos = $arr[0];
for($i = 1; $i < $count; $i++){
    if($arr[$i] > $pos){
    	$pos = $arr[$i-1] + $range;
		if($arr[$i] > $pos){
			$velo = -1;
			break;
		} else {$velo ++;}
    }
}
echo $velo."  ";

<?php
    $strs[0] = fgets(STDIN);
    $strs[1] = fgets(STDIN);

    $punkts_count = explode(" ", $strs[0])[0];
    $max_km = explode(" ", $strs[0])[1];
    $punkts = explode(" ", $strs[1]);

    $bikes_count = 1;
    $km_count = $max_km;

    for($i=0;$i<$punkts_count-1;$i++) {
        $n1 = $i+1;
        $offset = $punkts[$n1]-$punkts[$i];

        if($offset > $max_km) {
			die("-1");
		}
        elseif($offset > $km_count) {
            $bikes_count++;
            $km_count = $max_km;
        }

        $km_count = $km_count-$offset;
    }

    echo $bikes_count;
?>

<?php
$arr = explode(" ",fgets(STDIN));
$count_points_n = intval($arr[0]);
$max_rande_k = intval($arr[1]);
$arr = NULL;
$arr_x = explode(" ",fgets(STDIN));

$min_count_points = 1;
for($i = 0; $i < $count_points_n; $i++){
    $point = $i;
    $flag = true;
    $cur_range = $arr_x[$i] + $max_rande_k;
    $is_succses = 0;
    while($flag) {
        $point++;
        if ($cur_range >= $arr_x[$point]) {
            $i = $point - 1;
            if($point >= $count_points_n){
                break;
            }
            $is_succses = 1;
        }
        else{
            $min_count_points++;
            break;
        }
    }
    if(!$is_succses){
        $min_count_points = -1;
        break;
    }
}
echo $min_count_points;
?>

<?php
	list($bicycle_rental_count, $max_distance) = explode(" ", fgets(STDIN));
	$bicycle_rental_count = (int) $bicycle_rental_count;
	$max_distance = (int) $max_distance;
	$bicycle_rental_coords = explode(" ", fgets(STDIN));

	if(count($bicycle_rental_coords) != $bicycle_rental_count) die();
	if($bicycle_rental_count < 2 || $bicycle_rental_count > 1000) die();
	if($max_distance < 1 || $max_distance > 100000) die();
	if($bicycle_rental_coords[0] < 0 || $bicycle_rental_coords[$bicycle_rental_count-1] > 100000) die();

	$bicycle_count = 1; $distance_remain = $max_distance;
	for($i = 1; $i <= count($bicycle_rental_coords); $i++){
		if(($max_distance - ($bicycle_rental_coords[$i] - $bicycle_rental_coords[$i-1])) < 0){
			$bicycle_count = -1;
			break;
		}

		if($distance_remain == 0 && $i != count($bicycle_rental_coords) - 1){
			$bicycle_count++;
			$distance_remain = $max_distance;
		} else
		if($i == count($bicycle_rental_coords) - 1){
		    $distance_remain = $distance_remain - ($bicycle_rental_coords[$i] - $bicycle_rental_coords[$i-1]);
		    if($distance_remain < 0){
		        $bicycle_count++;
		    }
		    break;
		}

		$distance_remain = $distance_remain - ($bicycle_rental_coords[$i] - $bicycle_rental_coords[$i-1]);

		if($distance_remain < 0){
			$bicycle_count++;
			$distance_remain = $max_distance - ($bicycle_rental_coords[$i] - $bicycle_rental_coords[$i-1]);
		}
	}

	echo $bicycle_count;
?>

<?php
    $str = file_get_contents("стандартный ввод");

    $strs = explode("\n", $str);

    $punkts_count = explode(" ", $strs[0])[0];
    $max_km = explode(" ", $strs[0])[1];
    $punkts = explode(" ", $strs[1]);

    $bikes_count = 1;
    $km_count = $max_km;

    for($i=0;$i<$punkts_count-1;$i++) {
        $n1 = $i+1;
        $offset = $punkts[$n1]-$punkts[$i];

        if($offset > $max_km) {
			file_put_contents("стандартный вывод", "-1");
			die();
		}
        elseif($offset > $km_count) {
            $bikes_count++;
            $km_count = $max_km;
        }

        $km_count = $km_count-$offset;
    }

    file_put_contents("стандартный вывод", $bikes_count);
?>

<?php
    $str = file_get_contents("стандартный ввод");

    $strs = explode("\n", $str);

    $punkts_count = explode(" ", $strs[0])[0];
    $max_km = explode(" ", $strs[0])[1];
    $punkts = explode(" ", $strs[1]);

    $bikes_count = 0;
    $km_count = $max_km;

    for($i=0;$i<$punkts_count-1;$i++) {
        $n1 = $i+1;
        $offset = $punkts[$n1]-$punkts[$i];

        if($offset > $max_km) {
			file_put_contents("стандартный вывод", "-1");
			die();
		}
        elseif($offset > $km_count) {
            $bikes_count++;
            $km_count = $max_km;
        }

        $km_count = $km_count-$offset;
    }

    file_put_contents("стандартный вывод", $bikes_count);
?>

<?php
$arr = explode(" ",fgets(STDIN));
$count_points_n = intval($arr[0]);
$max_rande_k = intval($arr[1]);
$arr = NULL;
$arr_x = explode(" ",fgets(STDIN));

$min_count_points = 1;
for($i = 0; $i < $count_points_n; $i++){
    $point = $i;
    $flag = true;
    $cur_range = $arr_x[$i] + $max_rande_k;
    $is_succses = 0;
    while($flag) {
        $point++;
        if ($cur_range > $arr_x[$point]) {
            $i = $point;
            if($point >= $count_points_n){
                break;
            }
            $is_succses = 1;
        }
        else{
            $min_count_points++;
            break;
        }
    }
    if(!$is_succses){
        $min_count_points = -1;
        break;
    }
}
echo $min_count_points;

?>

<?php
list($count, $range) = explode(" ", fgets(STDIN));
$count = (int) $count;
$range = (int) $range;
$arr = explode(" ", fgets(STDIN));
$velo = 0;

$pos = $arr[0];
for($i = 1; $i < $count; $i++){
    if($arr[$i] > $pos){
     $pos = $arr[$i-1] + $range;
  if($arr[$i] > $pos){
   $velo = -1;
  } else {
   $velo ++;
  }

    }
}
echo $velo."  ";

<?php
// String
$q = '4 4';
$w = '3 6 8 10';
// Array
$q = explode(' ', $q);
$w = explode(' ', $w);
// Next
$t = $w[0];
// Bike
$u = 0;
// Foreach $w array
foreach($w as $key => $e){
	if($t < $e){
		// + "Next"
		$t += $q[1];
		// Search at array ($w) meanings ($t)
		$y = array_search($t, $w);
		// If $y == false
		if($y == false){
			// Check previous value
			if(!isset($w[$key - 1])){
				// Stop foreach
				$a = true;
			} else{
				// Duplicate "Next"
				$o = $t;
				// Bust
				$p = 0;
				// Search array($w)
				while($p < $e and $y == false){
					$o -= 1;
					$p += 1;
					$y = array_search($o, $w);
				}
				// If success search array
				if($o > 0 and isset($w[$y])){
					$t = $o;
					$u++;
				}
			}
		} else{ // If $y == true
			// Bike + 1
			$u++;
		}
	}
}
// Echo result
if($u > 0){
	echo $u;
} else{
	echo '-1';
}

<?php
$one = fgets(STDIN);
$two = fgets(STDIN);
$array_one = explode(' ', $one);
$array_two = explode(' ', $two);
$bike = 0;
$s = $array_two[0];
$q = 0;
foreach($array_two as $key => $pun){
	if($bike * $array_one[1] <= $array_two[0] + array_pop($array_two)){
		$s += $array_one[1];
		$var = array_search($s, $array_two);
		if($var == false){
			while($s > 0 and $var == false){
				$s -= 1;
				$var = array_search($s, $array_two);
			}
			if(isset($array_two[$var]) and $array_two[$var] != $pun){
				$bike++;
			}
		} else{
			$bike++;
		}
	}
}
if($bike <= 0){
	echo '-1';
} else{
	echo $bike;
}

<?php
	function one($num, $arr) {
		sort($arr);
		$less = array_filter($arr, function($d) use ($num){return $d <= $num;});
		$min = end($less);
		return $min;
	}

	$_1 = fgets(STDIN);
	$_2 = fgets(STDIN);
	$a = explode(' ', $_1);
	$b = explode(' ', $_2);
	$c = array_pop($b);
	$x = $b[0] + $a[1];

	while ($x != $c) {
		if (!in_array($x, $b)) {
			$y = one($x, $b);
			if ($y == $b[0]) break;
			$x = $y + $a[1];
			$z++;
		} else {
			$x = $x + $a[1];
			$z++;
		}
	}
	if ($z == 0) {
		echo '-1';
	} else {
		echo $z + 1;
	}
?>

<?php
	function one($num, $arr) {
		sort($arr);
		$less = array_filter($arr, function($d) use ($num){return $d <= $num;});
		$min = end($less);
		return $min;
	}

	$_1 = fgets(STDIN);
	$_2 = fgets(STDIN);
	$a = explode(' ', $_1);
	$b = explode(' ', $_2);
	$c = array_pop($b);
	$x = $b[0] + $a[1];

	while ($x != $c) {
		if (!in_array($x, $b)) {
			$y = one($x, $b);
			if ($y == $b[0]) break;
			if (($y + $a[1]) == $x) {$z++; break 1;}
			$x = $y + $a[1];
			$z++;
		} else {
			$x = $x + $a[1];
			$z++;
		}
	}
	if ($z == 0) {
		echo '-1';
	} else {
		echo $z + 1;
	}
?>


<?php

declare(strict_types = 1);

class Code
{
	private function readLn(): string
	{
		return fgets(STDIN);
	}

	private function readInt(): int
	{
		return intval(fgets(STDIN));
	}

	private function readStrings(): array
	{
		return explode(' ', fgets(STDIN));
	}

	private function readInts(): array
	{
		return explode(' ', fgets(STDIN));
	}

	public array $OUTPUT_LINES = [];

	private function outputLn(string $s): void
	{
		$this->OUTPUT_LINES[] = $s;
	}

	private function go(): void
	{
		$this->readLn();
		$this->outputLn(strval(abs(array_sum($this->readInts()))));
	}

	public function __construct()
	{
		$t = $this->readInt();
		for ($i = 0; $i < $t; $i++) {
			$this->go();
		}
		echo implode(PHP_EOL, $this->OUTPUT_LINES);
	}
}

new Code();

<?php

declare(strict_types = 1);

function go(): string {
	$n = intval(fgets(STDIN));
	$a = explode(' ', trim(fgets(STDIN)));

	foreach ($a as $k => $v) {
		$a[$k] = intval($v);
	}

	$s1 = $s2 = 0;

	foreach ($a as $k => $v) {
		if ($v >= 1) {
			$s1 += $v;
		} else {
			$s2 += $v;
		}
	}

	$res1 = abs($s1) - abs($s2);
	$res2 = abs($s2) - abs($s1);

	return max($res1, $res2) . PHP_EOL;
}

$t = intval(fgets(STDIN));

for ($i = 0; $i < $t; $i++) {
	echo go();
}

<?php
function getSum(){
    $count = trim(fgets(STDIN));
    $arr = explode(" ",trim(fgets(STDIN)));
    $sum1 = 0;
    $sum2 = 0;
    for ($i=0; $i<$count; $i++){
        if($arr[$i]>0){
            $s1[] =$arr[$i];
            $sum1 +=$arr[$i];
        } else {
            $s2[] =$arr[$i];
            $sum2 +=$arr[$i];
        }
    }
    if (abs($sum2)>abs($sum1)){
        $v = abs($sum2)-abs($sum1);
    } else {
        $v = abs($sum1)-abs($sum2);
    }
    echo "$v\n";
}
$count = trim(fgets(STDIN));
for ($j=0; $j<$count; $j++){
    getSum();
}
?>

<?php

declare(strict_types = 1);

class Code
{
	private function repeat(int $t): void
	{
		for ($i = 0; $i < $t; $i++) {
			$this->go();
		}
	}

	private function readLn(): string
	{
		return fgets(STDIN);
	}

	private function readInt(): int
	{
		return intval(fgets(STDIN));
	}

	private function readStrings(): array
	{
		return explode(' ', fgets(STDIN));
	}

	private function readInts(): array
	{
		return explode(' ', fgets(STDIN));
	}

	private array $OUTPUT_LINES = [];

	private function outputLn(string $s): void
	{
		$this->OUTPUT_LINES[] = $s;
	}

	private function go(): void
	{
		$this->readLn();
		$this->outputLn(strval(abs(array_sum($this->readInts()))));
	}

	public function __construct()
	{
		$this->repeat($this->readInt());
		echo implode(PHP_EOL, $this->OUTPUT_LINES);
	}
}

new Code();

<?php

declare(strict_types = 1);

function go(): string {
	$n = intval(fgets(STDIN));
	$a = explode(' ', trim(fgets(STDIN)));

	foreach ($a as $k => $v) {
		$a[$k] = intval($v);
	}

	$s1 = $s2 = 0;

	foreach ($a as $k => $v) {
		if ($v >= 1) {
			$s1 += $v;
		} else {
			$s2 += $v;
		}
	}

	$res1 = abs($s1) - abs($s2);
	$res2 = abs($s2) - abs($s1);

	return strval(max($res1, $res2));
}

$t = intval(fgets(STDIN));

for ($i = 0; $i < $t; $i++) {
	echo go();
}


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($aN, $bN) = explode(" ", trim(fgets($file)));
list($aT, $bT) = explode(" ", trim(fgets($file)));
$aArray = explode(" ", trim(fgets($file)));
$bArray = explode(" ", trim(fgets($file)));
$af = $aArray[$aT - 1];
$bf = $bArray[count($bArray) - $bT];
if ($af < $bf) {
    echo "YES";
}else{
    echo "NO";
}

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
list($c, $d) = explode(" ", trim(fgets(STDIN)));
$e = explode(" ", trim(fgets(STDIN)));
$f = explode(" ", trim(fgets(STDIN)));
$g = array_reverse($f);
$h = array_slice($e, 0, $c);
$i = array_slice($g, 0, $d);
$j = max($h);
$k = min($i);
if($j < $k)
{
    print "YES";
}
else
{
    print "NO";
}
?>

<?php
  list($na, $nb) = explode(' ', trim(fgets(STDIN)));
  list($k, $m) = explode(' ', trim(fgets(STDIN)));
  $a = explode(' ', trim(fgets(STDIN)));
  $b = explode(' ', trim(fgets(STDIN)));
  if ($a[$k - 1] < $b[$nb - $m])
    print('YES');
  else
    print('NO');
?>

    <?php
        $n = explode(" ",trim(fgets(STDIN)));
        $m =  explode(" ",trim(fgets(STDIN)));
        $A =  explode(" ",trim(fgets(STDIN)));
        $B =  explode(" ",trim(fgets(STDIN)));
        sort($A);
        sort($B);
        if($A[$m[0]-1] < $B[$n[1] - $m[1]]){
            echo "YES\n";
        }else{
            echo "NO\n";
        }

<?php
        $n = explode(" ",trim(fgets(STDIN)));
        $m =  explode(" ",trim(fgets(STDIN)));
        $A =  explode(" ",trim(fgets(STDIN)));
        $B =  explode(" ",trim(fgets(STDIN)));
        sort($A);
        sort($B);
        if($A[$m[0]-1] < $B[0]){
            echo "YES";
        }else{
            echo "NO";
        }

<?php
        $n = explode(" ",trim(fgets(STDIN)));
        $m =  explode(" ",trim(fgets(STDIN)));
        $A =  explode(" ",trim(fgets(STDIN)));
        $B =  explode(" ",trim(fgets(STDIN)));
        sort($A);
        sort($B);
        if($A[$m[0]-1] < $B[0]){
            echo "YES\n";
        }else{
            echo "NO\n";
        }


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

	while($t--) {
		list($a,$b) = explode(" ", trim(fgets(STDIN)));
		print $a*$b."\n";
	}
?>

<?php

/*
 * https://codeforces.com/contest/1484
 */

//$file = fopen("./input.txt", "r");
$file = fopen("php://stdin", "r");
$rowsNumber = trim(fgets($file));

for($i=0; $i<$rowsNumber; $i++) {
    list($a, $b) = explode(" ", trim(fgets($file)));

    echo $a*$b . PHP_EOL;
}

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

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

for ($i = 0; $i < $t; $i++) {
  list($a, $b) = explode(" ", trim(fgets($file)));
  $res = $a * $b;
  echo $res.PHP_EOL;
}

?>


<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$n = trim(fgets($handle));
$a = trim(fgets($handle));
$a=explode(' ',$a);
$b= trim(fgets($handle));
$b=explode(' ',$b);
$x=[];
for($i=0;$i<$n;$i++)
{
 $x[$b[$i]]=$i;
}
$max=-1;$ans=0;$as=0;
for($i=0;$i<$n;$i++)
{
    $ans=$x[$a[$i]];
    if($ans>$max)
    {
        $max=$ans;
    }
    else
    {
        $as++;
    }
    //$max=max($ans,$max);
}
echo $as;

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$n = trim(fgets($handle));
$a = trim(fgets($handle));
$a=explode(' ',$a);
$b= trim(fgets($handle));
$b=explode(' ',$b);
$x=[];
for($i=0;$i<$n;$i++)
{
 $x[$b[$i]]=$i;
}
$max=0;$ans=0;
for($i=0;$i<$n;$i++)
{
    $ans=$x[$a[$i]]-$i;
    $max=max($ans,$max);
}
echo $max;

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$n = trim(fgets($handle));
$a = trim(fgets($handle));
$a=explode(' ',$a);
$b= trim(fgets($handle));
$b=explode(' ',$b);
$x=[];
for($i=0;$i<$n;$i++)
{
 $x[$b[$i]]=$i;
}
$max=-1;$ans=0;
for($i=0;$i<$n;$i++)
{
    $ans=$x[$a[$i]]-$i;
    $max=max($ans,$max);
}
echo $max;


<?php
fscanf(STDIN,"%d",$numOfstr);
$str=array();
for ($i=0; $i <$numOfstr; $i++)
{
	fscanf(STDIN,"%s",$str[$i]);
}
for ($i=0; $i <$numOfstr-1 ; $i++)
 {
       for ($j=0; $j <$numOfstr-1 ; $j++)
        {
        	if(strlen($str[$j])>strlen($str[$j+1]))
        	{
        		$tmp=$str[$j];
        		$str[$j]=$str[$j+1];
        		$str[$j+1]=$tmp;
        	}
        }
 }
 //print_r($str)."\n";
 $count=0;
 for ($i=0; $i <$numOfstr-1 ; $i++)
  {
 	  $cnt=substr_count($str[$i+1],$str[$i]);
 	  if($cnt>=1)
 	  {
 	  	$count++;
 	  }
  }
  //echo "$count\n";

  if($count>=$numOfstr-1)
  {
	   echo "YES\n";
	  for ($i=0; $i <$numOfstr ; $i++)
	   {
	  	   echo "$str[$i]\n";
	   }
  }
  else
  	echo "NO\n";

<?php

$str = array();
$n = (int) readline();

for($i = 0; $i < $n; $i++)
    $str[] = readline();

for($i = 0; $i < $n; $i++) {
    for($j = $i + 1; $j < $n; $j++) {
        if(strlen($str[$j]) < strlen($str[$i])) {
            $temp = $str[$i];
            $str[$i] = $str[$j];
            $str[$j] = $temp;
        }
    }
}

for($i = 0; $i < $n - 1; $i++)
    if(strpos($str[$i+1], $str[$i]) === false)
        break;

if($i != ($n - 1)) echo "NO\n";
else {
    echo "YES\n";
    foreach($str as $val)
        echo $val."\n";
}

<?php
fscanf(STDIN,"%d",$numOfstr);
$str=array();
for ($i=0; $i <$numOfstr; $i++)
{
	fscanf(STDIN,"%s",$str[$i]);
}
for ($i=0; $i <$numOfstr-1 ; $i++)
 {
       for ($j=0; $j <$numOfstr-1 ; $j++)
        {
        	if(strlen($str[$j])>strlen($str[$j+1]))
        	{
        		$tmp=$str[$j];
        		$str[$j]=$str[$j+1];
        		$str[$j+1]=$tmp;
        	}
        }
 }
 print_r($str)."\n";
 $count=0;
 for ($i=0; $i <$numOfstr-1 ; $i++)
  {
 	  $cnt=substr_count($str[$i+1],$str[$i]);
 	  if($cnt>=1)
 	  {
 	  	$count++;
 	  }
  }
  //echo "$count\n";

  if($count>=$numOfstr-1)
  {
	   echo "YES\n";
	  for ($i=0; $i <$numOfstr ; $i++)
	   {
	  	   echo "$str[$i]\n";
	   }
  }
  else
  	echo "NO\n";

<?php
fscanf(STDIN,"%d",$numOfstr);
$str=array();
for ($i=0; $i <$numOfstr; $i++)
{
	fscanf(STDIN,"%s",$str[$i]);
}
for ($i=0; $i <$numOfstr-1 ; $i++)
 {
       for ($j=0; $j <$numOfstr-1 ; $j++)
        {
        	if(strlen($str[$j])>strlen($str[$j+1]))
        	{
        		$tmp=$str[$j];
        		$str[$j]=$str[$j+1];
        		$str[$j+1]=$tmp;
        	}
        }
 }
 $cnt=0;
 for ($i=0; $i <$numOfstr-1 ; $i++)
  {
 	  $cnt+=substr_count($str[$i+1],$str[$i]);
  }
  if($cnt>=$numOfstr-1)
  {
	   echo "YES\n";
	  for ($i=0; $i <$numOfstr ; $i++)
	   {
	  	   echo "$str[$i]\n";
	   }
  }
  else
  	echo "NO\n";