Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.  Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.

The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.

On the single line of the output print the number of groups of magnets.

NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$d = 1;
for($x = 1; $x < $a; $x++)
{
    $c = trim(fgets(STDIN));
    if($b[1] != $c[0])
    {
        continue;
    }
    else
    {
        $d++;
    }
    $b = $c;
}
print $d;
?>

<?php
$last = "";
$tot = 0;
fscanf (STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
    fscanf (STDIN, "%s", $cur);
    if ($last != $cur) $tot++;
    $last = $cur;
}
printf ("%d\n", $tot);
?>

<?php

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

// get inputs
$number_of_magnets = trim(fgets(STDIN));

// solution
$previous_magnet = '';
$groups = 0;

for ($i=0; $i < $number_of_magnets; $i++) {
    $magnet = trim(fgets(STDIN));

    if($magnet == $previous_magnet) {
        continue;
    }

    $previous_magnet = $magnet;
    $groups++;
}

echo $groups . "\n";

<?php
	$i = 0;
	$str = "";
	$n = trim(fgets(STDIN));
	while($i < $n)
	{
		$str = $str . trim(fgets(STDIN)) . " ";
		$i = $i+1;
	}
	$x = substr($str,0,2);
	$group = 0;
	$pos=-3;
	while(($pos = strpos($str, $x, $pos+3)) !== false){
		$group = $group + 1;
		if($x == "10")
			$x = "01";
		else if($x == "01")
			$x = "10";
	}
	echo $group;
?>

<?php

    $s = fopen("php://stdin", 'r');
    $n = stream_get_contents($s);
    $arr= explode("\n",$n);
    $num = $arr[0];
    $flag = 1;

    $pre = $arr[1];

    for ($i=2; $i <= $num; $i++)
    {
        if($arr[$i] != $pre)
        {

            $flag++;
            $pre = $arr[$i];
        }
    }

    echo $flag;
?>

<?php
function input()
{
    while (($line = fgets(STDIN)) != PHP_EOL) {
        yield $line;
    }
}

$COUNT = 0;
$g = 0;
$before = '';
foreach (input() as $line) {
    if ($COUNT == 0) {
        $n = intval($line);
        ++$COUNT;
        continue;
    }
    if ($before == '') {
        $before = $line;
    }

    if( $before != $line) {
        $g += 1;
    }

    $before = $line;

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

<?php
readline();
$a = str_replace("\r\n", '', file_get_contents('php://stdin'));
echo substr_count($a, "00") + substr_count($a, "11") + 1;

<?php
$n = trim(fgets(STDIN));
$last = '';
$group = 0;

for( $i=0; $i<$n; $i++ ){
    $magnet = trim(fgets(STDIN));

    if( $last != $magnet ){
        $group++;
        $last = $magnet;
    }
}
echo  $group;

<?php
$n = trim(fgets(STDIN));
$g=0;$next=trim(fgets(STDIN));
for ($i=1;$i<$n;$i++)
{
    $prev = $next;
    $next = trim(fgets(STDIN));
    if ($next != $prev) $g++;
}
echo $g+1;

<?php

$n=(int)fgets(STDIN);

$prev=fgets(STDIN);
$cnt=1;
for($i=1;$i<$n;$i++)    {
	$new=fgets(STDIN);
	if($new!=$prev)    $cnt++;
	$prev=$new;
}

echo $cnt."\n";

?>

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

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

	$max = 0;
	$counter = 0;
	$groups = 0;

	$magnets[] = fgets($input);

	for ( $i=1 ; $i < $n ; $i++ ) {
		 $magnets[] = fgets($input);
	}

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

		if($magnets[$i] != $magnets[$i+1])
			{
				$groups++;
			}
	}

	echo $groups+1;

?>

<?php

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

$groups = 0 ;
$temp = "" ;

fscanf($stdin, "%d", $n);
for( $i=0 ; $i<$n ; $i++ )
{
     fscanf( $stdin , "%s" , $s );

     if( $i == 0 )
     {
          $groups++ ;
          $temp = $s[1] ;
     }
     else
     {
          if( $s[0] == $temp )
          {
               $groups++ ;
               $temp = $s[1] ;
          }
     }
}
echo $groups ;

fwrite($stdout);

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

?>

<?php
$n = rtrim(fgets(STDIN));
$current = '';
$last    = '';
$count   = 0;

for($i=0; $i < $n; $i++){
    $magnet = rtrim(fgets(STDIN));
    if(($magnet == 01 && $last == 10) || ($count == 0 && $magnet == 01)){
        $current = $last = 01;
        $count++;
    }elseif(($magnet == 10 && $last == 01) || ($count == 0 && $magnet == 10)){
        $current = $last = 10;
        $count++;
    }
}
echo($count);

<?php
$n = trim(fgets(STDIN));
$last = array(-1, -1);
$len = 1;
for($i=0;$i<$n;$i++){
    $magnet = str_split(trim(fgets(STDIN)));
    if ($magnet[0] == $last[1])
        $len++;
    $last[0] = $magnet[0];
    $last[1] = $magnet[1];
}

echo $len;

?>

<?php
$n=trim(fgets(STDIN));
$hasil=0;
$temp1=-1;
$temp2=-1;

for ($i=0; $i < $n ; $i++) {
	$a=str_split(trim(fgets(STDIN)));
	if ($temp1 != $a[0] && $temp2 != $a[1]) {
		$hasil++;
		$temp1=$a[0];
		$temp2=$a[1];
	}
}

echo $hasil;
?>

<?php
$n=trim(fgets(STDIN));
$arr=array();
$hasil=1;
for ($i=0; $i < $n ; $i++) {
	$arr[$i]=trim(fgets(STDIN));
}

for ($i=0; $i < count($arr)-1 ; $i++) {
	if ($arr[$i] != $arr[$i+1]) {
		$hasil++;
	}
}
echo $hasil;
?>

<?php
// 344A Магниты
$in = fopen("php://stdin", 'r');

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

$str = fgets($in);
$out = 1;
for ($i=2; $i <= $n ; $i++) {
    $input_line = fgets($in);
    if ($str !== $input_line) {
        $str = $input_line;
        $out ++;
    }
}

echo $out;

?>

<?php

$in = 'php://stdin';

$input = fopen($in, "r");

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

$s = "";

for ($i=0;$i<$n;$i++) {
   $s .= trim(fgets($input));
}

echo 1 + substr_count($s, "00") + substr_count($s, "11");
?>

<?php

$n = intval(trim(fgets(STDIN)));
$answer = '';

for ($i = 0; $i < $n; $i ++) {
  $line = trim(fgets(STDIN));
  if (strlen($answer) == 0 || substr($answer, -1) !== $line[0]) {
    $answer .= $line;
  } else {
    $answer .= ' ' . $line;
  }
}

//var_dump($answer);
print substr_count($answer, ' ') + 1;

?>

<?php
$number = fgets(STDIN);

$magnits = [];
$breaks = 0;

// считывание всех магнитов
for ($i=0; $i < $number; $i++) {
	fscanf(STDIN, '%s\n', $magnits[$i]);
}

for ($i=0; $i < count($magnits); $i++) {
	if($magnits[$i] == $magnits[$i+1]){
		continue;
	} else {
		$breaks++;
	}
}

print_r($breaks);

<?php

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

$group = 1;
fscanf(STDIN, '%s', $s);
$n--;

while($n--) {
    fscanf(STDIN, '%s', $m);
    if ($m != $s) $group++;
    $s = $m;
}

echo $group;

<?php
$result = trim(fgets(STDIN));
$magn = array();
$p = 1;
for ($i = 0;$i<$result;$i++){
    $magnet = trim(fgets(STDIN));
    if ($i==0){
        $magn[] = $magnet;
        continue;
    }
    $magn[] = $magnet;
    if ($magnet == $magn[$i-1]){
        continue;
    } else {
        $p++;
    }
}
echo "$p\n";

<?php
error_reporting("off");
//344A: Magnets
$n = trim(fgets(STDIN));
$magnets = "";
for ($i = 0; $i < $n; $i++) {
    $magnets .= trim(fgets(STDIN));
}
$doubles = substr_count($magnets, "00") + substr_count($magnets, "11");
echo $doubles + 1;
?>

<?php
readline();
$a = file_get_contents('php://stdin');
var_dump($a);
echo substr_count($a, "0\n0") + substr_count($a, "1\n1") + 1;

<?php
readline();
$a = file_get_contents('php://stdin');
echo substr_count($a, "0\n0") + substr_count($a, "1\n1") + 1;

<?php

$magnet = rtrim(fgets(STDIN));

$current = '';
$last    = '';
$count   = 0;

if(($magnet == 01 && $last == 10) || ($count == 0 && $magnet == 01)){
    $current = $last = 01;
    $count++;
}elseif(($magnet == 10 && $last == 01) || ($count == 0 && $magnet == 10)){
    $current = $last = 10;
    $count++;
}

echo($count);

<?php

$input = rtrim(fgets(STDIN));

$current = '';
$last    = '';
$count   = 0;

foreach(explode(" ", $input) as $magnet){
    if(($magnet == 01 && $last == 10) || ($count == 0 && $magnet == 01)){
        $current = $last = 01;
        $count++;
    }elseif(($magnet == 10 && $last == 01) || ($count == 0 && $magnet == 10)){
        $current = $last = 10;
        $count++;
    }
}
echo($count);

<?php
$n = trim(fgets(STDIN));
$last = array(-1, -1);
$len = 0;
for($i=0;$i<$n;$i++){
    $magnet = str_split(trim(fgets(STDIN)));
    if ($magnet[0] != $last[1])
        $len++;
    $last[0] = $magnet[0];
    $last[1] = $magnet[1];
}

echo $len;

?>

<?php
$n=trim(fgets(STDIN));
$arr=array();
$hasil=0;
$temp1=-1;
$temp2=-1;

for ($i=0; $i < $n ; $i++) {
	$a=explode(" ", trim(fgets(STDIN)));
	if ($temp1 != $a[0] && $temp2 != $a[1]) {
		$hasil++;
		$temp1=$a[0];
		$temp2=$a[1];
	}
}

echo $hasil;
?>

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

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

	$max = 0;
	$counter = 0;

	$magnets[] = fgets($input);

	for ( $i=1 ; $i < $n ; $i++ ) {
		 $magnets[] = fgets($input);
	}

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

		if($magnets[$i] != $magnets[$i+1])
			{
				if($counter > $max)
					$max = $counter;

				$counter=0;
			}
		$counter++;
	}

	echo $max+1;

?>

<?php
$number = fgets(STDIN);

$magnits = [];
$breaks = 0;

$islands = 0;

// считывание всех магнитов
for ($i=0; $i < $number; $i++) {
	fscanf(STDIN, '%s\n', $magnits[$i]);
}

for ($i=0; $i < count($magnits); $i++) {
	if($magnits[$i] !== $magnits[$i++]){
		$islands++;
		// не могу понять, почему вместо break не сработал continue
	} else {
		$breaks++;
	}
}

print_r($islands);

<?php

$number = fgets(STDIN);

$magnits = [];
$breaks = 0;

// считывание всех магнитов
for ($i=0; $i < $number; $i++) {
	fscanf(STDIN, '%s\n', $magnits[$i]);
}

for ($i=0; $i < count($magnits); $i++) {
	if($magnits[$i] !== $magnits[$i++]){
		break;
	} else {
		$breaks++;
	}
}

print_r($breaks);


Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the i-th client number ti ( - 10 ≤ ti ≤ 10). Of course, one number can be assigned to any number of customers."Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of t. Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence t1, t2, ..., tn. For example, if t = (1,  - 1, 1,  - 1), then any two elements ti and tj form a couple if i and j have different parity. Consequently, in this case the sought number equals 4.Of course, a client can't form a couple with him/herself.

The first line of the input data contains an integer n (1 ≤ n ≤ 105) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers t1, t2, ..., tn ( - 10 ≤ ti ≤ 10), ti — is the parameter of the i-th customer that has been assigned to the customer by the result of the analysis of his interests.

Print the number of couples of customs with opposite t. The opposite number for x is number  - x (0 is opposite to itself). Couples that only differ in the clients' order are considered the same. Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

NoteIn the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).In the second sample any couple of clients is opposite.


You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters.Your task is to add spaces to the text by the following rules:  if there is no punctuation mark between two words, then they should be separated by exactly one space  there should be no spaces before each punctuation mark  there should be exactly one space after each punctuation mark It is guaranteed that there is at least one word between any two punctuation marks. The text begins and ends with a Latin letter.

The input data contains of a single non-empty line — the text whose length is no more than 10000 characters.

Print the text, edited according to the rules. In this problem you should follow the output format very strictly. For example, extra space at the end of the output line is considered as wrong answer. Note that a newline character at the end of the line doesn't matter.

galileo galilei was an italian physicist, mathematician, astronomer

<?php
while($s = fgets(STDIN)){
$input .= $s;
}

$string = $input;

while (substr_count($string, ' !')) {
    $string = str_replace(' !', '!', $string);
}

$string = str_replace('!', '! ', $string);

while (substr_count($string, ' ?')) {
    $string = str_replace(' ?', '?', $string);
}

$string = str_replace('?', '? ', $string);

while (substr_count($string, ' .')) {
    $string = str_replace(' .', '.', $string);
}

$string = str_replace('.', '. ', $string);

while (substr_count($string, ' ,')) {
    $string = str_replace(' ,', ',', $string);
}

$string = str_replace(',', ', ', $string);
while(substr_count($string, '  ')) {
    $string = str_replace('  ', ' ', $string);
}

echo $string;

<?php
$text = stream_get_contents(fopen("php://stdin", 'r'));
$text = trim(preg_replace("~\s+~", " ", $text));
$symb = array(".", ",", "!", "?");
foreach($symb as $s) { $text = str_replace($s, $s." ", $text); $text = str_replace(" ".$s, $s, $text); }

echo trim(preg_replace("~\s+~", " ", $text));
?>

<?php
while($s = fgets(STDIN)){
$input .= $s;
}

$string = $input;
while (substr_count($string, ' ,')) {
    $string = str_replace(' ,', ',', $string);
}

$string = str_replace(',', ', ', $string);
while(substr_count($string, '  ')) {
    $string = str_replace('  ', ' ', $string);
}

echo $string;

<?php
$Str = fgets(STDIN);
$Str = preg_replace("/(\s+)/",' ',$Str);
$Str = preg_replace("/(\s*\,\s*)/",', ',$Str);

echo $Str;
?>

<?php
$Str = fgets(STDIN);
$Str = preg_replace('/(\s+)/',' ',$Str);
$Str = preg_replace('/(\s*\,\s*)/',',',$Str);
$Str = preg_replace('/(\,)/',', ',$Str);

echo $Str;
?>

<?php
$Str = fgets(STDIN);
$Str = preg_replace('/(\s+)/',' ',$Str);
$Str = preg_replace('/(\s*\,\s*)/',',',$Str);
$Str = preg_replace('/(\,)/',', ',$Str);

echo $Str . "\r\n";
?>

<?php
$text = stream_get_contents(fopen("php://stdin", 'r'));
//$text = "galileo galilei was an   italian physicist  ,mathematician,astronomer";
$text = trim(preg_replace("~\s+~", " ", $text));
$symb = array(".", ",", "!", "?");
foreach($symb as $s) { $text = str_replace($s, $s." ", $text); $text = str_replace(" ".$s, $s, $text); }

echo $text;
?>


New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \le hh < 24$$$ and $$$0 \le mm < 60$$$. We use 24-hour time format!Your task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1439$$$) — the number of test cases. The following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \le h < 24$$$, $$$0 \le m < 60$$$). It is guaranteed that this time is not a midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros.

For each test case, print the answer on it — the number of minutes before the New Year.

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

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

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

	list($h, $m) = explode(' ', trim(fgets(STDIN)));
	$h = intval($h);
	$m = intval($m);

	echo (1440 - ($h * 60 + $m));
	echo "\n";

}

<?php

declare(strict_types = 1);

function main() {
	$n = (int) fgets(STDIN);
	while (($n--) > 0) {
		[$a, $b] = array_map( 'intval', explode( " ", fgets(STDIN) ) );
		$answer = (24 - $a) * 60 - $b;
		echo "$answer\n";
	}
}
main();

<?php

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

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

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

function foo($h, $m)
{
    if ($h == 0 && $m == 0) {
        return 0;
    }

    return 1440 - ($h * 60 + $m);
}

$r = 0;

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

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

    $r = foo($h, $m);

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

<?php

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

for($i=0;$i<$t;$i++)
{
    $x=trim(fgets($handle));
    $a=explode(' ',$x);
    $min=60-$a[1];
    $hou=23-$a[0];
    echo $min+($hou*60)."\n";

}
?>

<?php
function getResult($input)
{
	$result = [];
	foreach ($input as $time)
	{
		$time = explode(' ', $time);
		$hours = $time[0];
		$mins = $time[1];
		$result[] = 24 * 60 - ($hours * 60 + $mins);
	}
	return implode(PHP_EOL,$result);
}

$input = [];
while ($newLine = fgets(STDIN))
{
	$input[] = trim($newLine);
}
array_shift($input);
fwrite(STDOUT, getResult($input));

<?php
$input = STDIN;
$output = STDOUT;

$h = fgets($input);
while (($l = fgets($input)) !== false) {
    $t = explode(' ', $l);
    $r = 1440 - (60 * $t[0] + $t[1]);
    fwrite($output, $r . PHP_EOL);
}
?>

<?php
// define('TXTIN', fopen('input.txt', 'r'));
// define('TXTOUT', fopen('output.txt', 'w'));
// $input = TXTIN;
// $output = TXTOUT;
$input = STDIN;
$output = STDOUT;

$h = fgets($input);
while (($l = fgets($input)) !== false) {
    $t = explode(' ', $l);
    $r = 1440 - (60 * $t[0] + $t[1]);
    fwrite($output, $r . PHP_EOL);
}
?>

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

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

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

	list($h, $m) = explode(' ', trim(fgets($stdin)));
	$h = intval($h);
	$m = intval($m);

	echo (1440 - ($h * 60 + $m));
	echo "\n";

}

<?php
$h = fgets(STDIN);
while (($l = fgets($input)) !== false) {
    $t = explode(' ', $l);
    $r = 1440 - (60 * $t[0] + $t[1]);
    fwrite(STDOUT, $r . PHP_EOL);
}
?>


Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):   Clerihew (aabb);  Alternating (abab);  Enclosed (abba). If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.

The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104. If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.

Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.

2 1
day
may
sun
fun
test
hill
fest
thrill

NoteIn the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".

<?php
function regex($param, $k) {
    $pattern = "/([^aeiou]*?[aeiou]){" . $k . "}/";
    preg_match($pattern, $param, $match);
    return $match[0];
}
$fr = fopen("php://stdin", "r");
$arr = fgets($fr);
$arr = explode(' ', $arr);
$n = (int) $arr[0];
$k = (int) $arr[1];
$flag = FALSE;
for ($i = 0; $i < 4 * $n; ++$i) {
    $str[$i] = fgets($fr);
    $str[$i] = strrev($str[$i]);
    $str[$i] = regex($str[$i], $k);
    //Æ¥ÅäÊ§”¡
    if ($str[$i] == NULL) {
        $flag = TRUE;
        break;
    }
}
if ($flag) {
    die("NO\n");
}
//$str_ans = array();
$aaaa = FALSE;
$aabb = FALSE;
$abab = FALSE;
$abba = FALSE;
$no = FALSE;
$cnt_aaaa = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4] == $str[$i * 4 + 3]) {
//        $str_ans[] = "aaaa";
        $cnt_aaaa++;
        $aaaa = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4 + 2] == $str[$i * 4 + 3]) {
//        $str_ans[] = "aabb";
        $aabb = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4 + 1] == $str[$i * 4 + 3]) {
//        $str_ans[] = "abab";
        $abab = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 3] && $str[$i * 4 + 1] == $str[$i * 4 + 2]) {
//        $str_ans[] = "abba";
        $abba = TRUE;
    } else {
        $no = TRUE;
    }
}
if ($no)
    echo "NO\n";
elseif (!$aabb && !$abab && $abba) {
    echo "abba\n";
} elseif (!$aabb && $abab && !$abba) {
    echo "abab\n";
} elseif ($aabb && !$abab && !$abba) {
    echo "aabb";
} elseif ($aaaa && $cnt_aaaa == $n) {
    echo "aaaa";
} else {
    echo "NO\n";
}
?>

<?php

function regex($param, $k) {
    $pattern = "/([^aeiou]*?[aeiou]){" . $k . "}/";
    preg_match($pattern, $param, $match);
    return $match[0];
}

$fr = fopen("php://stdin", "r");
$arr = fgets($fr);
$arr = explode(' ', $arr);
$n = (int) $arr[0];
$k = (int) $arr[1];

$flag = FALSE;
for ($i = 0; $i < 4 * $n; ++$i) {
    $str[$i] = fgets($fr);
    $str[$i] = strrev($str[$i]);
    $str[$i] = regex($str[$i], $k);
    //匹配失敗
    if ($str[$i] == NULL) {
        $flag = TRUE;
        break;
    }
}
if ($flag) {
    die("NO\n");
    exit;
}

//$str_ans = array();
$aaaa = FALSE;
$aabb = FALSE;
$abab = FALSE;
$abba = FALSE;
$no = FALSE;

$cnt_aaaa = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4] == $str[$i * 4 + 3]) {
//        $str_ans[] = "aaaa";
        $cnt_aaaa++;
        $aaaa = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4 + 2] == $str[$i * 4 + 3]) {
//        $str_ans[] = "aabb";
        $aabb = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4 + 1] == $str[$i * 4 + 3]) {
//        $str_ans[] = "abab";
        $abab = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 3] && $str[$i * 4 + 1] == $str[$i * 4 + 2]) {
//        $str_ans[] = "abba";
        $abba = TRUE;
    } else {
        $no = TRUE;
    }
}

if ($no)
    echo "NO\n";
elseif (!$aabb && !$abab && $abba) {
    echo "abba\n";
} elseif (!$aabb && $abab && !$abba) {
    echo "abab\n";
} elseif ($aabb && !$abab && !$abba) {
    echo "aabb\n";
} elseif ($aaaa && $cnt_aaaa == $n) {
    echo "aaaa\n";
} else {
    echo "NO";
}
?>

<?php

function regex($param, $k) {
    $pattern = "/([^aeiou]*?[aeiou]){" . $k . "}/";
    preg_match($pattern, $param, $match);
    return $match[0];
}

$fr = fopen("php://stdin", "r");
$arr = fgets($fr);
$arr = explode(' ', $arr);
$n = (int) $arr[0];
$k = (int) $arr[1];

$flag = FALSE;
for ($i = 0; $i < 4 * $n; ++$i) {
    $str[$i] = fgets($fr);
    $str[$i] = strrev($str[$i]);
    $str[$i] = regex($str[$i], $k);
    //匹配失敗
    if ($str[$i] == NULL) {
        $flag = TRUE;
        break;
    }
}
if ($flag) {
    die("NO\n");
}

//$str_ans = array();
$aaaa = FALSE;
$aabb = FALSE;
$abab = FALSE;
$abba = FALSE;
$no = FALSE;

$cnt_aaaa = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4] == $str[$i * 4 + 3]) {
//        $str_ans[] = "aaaa";
        $cnt_aaaa++;
        $aaaa = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4 + 2] == $str[$i * 4 + 3]) {
//        $str_ans[] = "aabb";
        $aabb = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4 + 1] == $str[$i * 4 + 3]) {
//        $str_ans[] = "abab";
        $abab = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 3] && $str[$i * 4 + 1] == $str[$i * 4 + 2]) {
//        $str_ans[] = "abba";
        $abba = TRUE;
    } else {
        $no = TRUE;
    }
}

if ($no)
    echo "NO\n";
elseif (!$aabb && !$abab && $abba) {
    echo "abba\n";
} elseif (!$aabb && $abab && !$abba) {
    echo "abab\n";
} elseif ($aabb && !$abab && !$abba) {
    echo "aabb";
} elseif ($aaaa && $cnt_aaaa == $n) {
    echo "aaaa";
} else {
    echo "NO\n";
}
?>

<?php

function regex($param, $k) {
    $pattern = "/([^aeiou]*?[aeiou]){" . $k . "}/";
    preg_match($pattern, $param, $match);
    return $match[0];
}

$fr = fopen("php://stdin", "r");
//$n = (int) fgets($fr);
$arr = fgets($fr);
$arr = explode(' ', $arr);
$n = $arr[0];
$k = (int) $arr[1];

$flag=FALSE;
for ($i = 0; $i < 4 * $n; ++$i) {
    $str[$i] = fgets($fr);
    $str[$i] = strrev($str[$i]);
    $str[$i] = regex($str[$i], $k);
    if($str[$i]==NULL){
        $flag=TRUE;
        break;
    }
}
if($flag){
    die("NO\n");
    exit ;
}

$str_ans = array();
$aaaa = FALSE;
$aabb = FALSE;
$abab = FALSE;
$abba = FALSE;
$no = FALSE;

$cnt_aaaa=0;
for ($i = 0; $i < $n; ++$i) {
    if ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4] == $str[$i * 4 + 3]) {
        $str_ans[] = "aaaa";
        $cnt_aaaa++;
        $aaaa = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4 + 2] == $str[$i * 4 + 3]) {
        $str_ans[] = "aabb";
        $aabb = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4 + 1] == $str[$i * 4 + 3]) {
        $str_ans[] = "abab";
        $abab = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 3] && $str[$i * 4 + 1] == $str[$i * 4 + 2]) {
        $str_ans[] = "abba";
        $abba = TRUE;
    } else {
        $no = TRUE;
    }
}

if ($no)
    echo "NO\n";
elseif (!$aabb && !$abab && $abba) {
    echo "abba\n";
} elseif (!$aabb && $abab && !$abba) {
    echo "abab\n";
} elseif ($aabb && !$abab && !$abba) {
    echo "aabb\n";
} elseif ($aaaa && $cnt_aaaa==$n) {
    echo "aaaa\n";
} else {
    echo "NO\n";
}

//$cnt=$aaaa+$aabb+$abab+$abba;
//foreach ($str_ans as $key => $value) {
//    echo $value . "\n";
//}
//var_dump($str);
?>

<?php

function regex($param, $k) {
    $pattern = "/([^aeiou]*?[aeiou]){" . $k . "}/";
    preg_match($pattern, $param, $match);
    return $match[0];
}

$fr = fopen("php://stdin", "r");
$arr = fgets($fr);
$arr = explode(' ', $arr);
$n = (int) $arr[0];
$k = (int) $arr[1];

$flag = FALSE;
for ($i = 0; $i < 4 * $n; ++$i) {
    $str[$i] = fgets($fr);
    $str[$i] = strrev($str[$i]);
    $str[$i] = regex($str[$i], $k);
    //匹配失敗
    if ($str[$i] == NULL) {
        $flag = TRUE;
        break;
    }
}
if ($flag) {
    die("NO\n");
    exit;
}

//$str_ans = array();
$aaaa = FALSE;
$aabb = FALSE;
$abab = FALSE;
$abba = FALSE;
$no = FALSE;

$cnt_aaaa = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4] == $str[$i * 4 + 3]) {
//        $str_ans[] = "aaaa";
        $cnt_aaaa++;
        $aaaa = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4 + 2] == $str[$i * 4 + 3]) {
//        $str_ans[] = "aabb";
        $aabb = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4 + 1] == $str[$i * 4 + 3]) {
//        $str_ans[] = "abab";
        $abab = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 3] && $str[$i * 4 + 1] == $str[$i * 4 + 2]) {
//        $str_ans[] = "abba";
        $abba = TRUE;
    } else {
        $no = TRUE;
    }
}

if ($no)
    echo "NO\n";
elseif (!$aabb && !$abab && $abba) {
    echo "abba\n";
} elseif (!$aabb && $abab && !$abba) {
    echo "abab\n";
} elseif ($aabb && !$abab && !$abba) {
    echo "aabb\n";
} elseif ($aaaa && $cnt_aaaa == $n) {
    echo "aaaa\n";
} else {
    echo "NO\n";
}
?>

<?php

function regex($param, $k) {
    $pattern = "/([^aeiou]*?[aeiou]){" . $k . "}/";
    preg_match($pattern, $param, $match);
    return $match[0];
}

$fr = fopen("php://stdin", "r");
//$n = (int) fgets($fr);
$arr = fgets($fr);
$arr = explode(' ', $arr);
$n = $arr[0];
$k = (int) $arr[1];

$flag=FALSE;
for ($i = 0; $i < 4 * $n; ++$i) {
    $str[$i] = fgets($fr);
    $str[$i] = strrev($str[$i]);
    $str[$i] = regex($str[$i], $k);
    if($str[$i]==NULL)
        $flag=TRUE;
}
if($flag)
    die("NO\n");

$str_ans = array();
$aaaa = FALSE;
$aabb = FALSE;
$abab = FALSE;
$abba = FALSE;
$no = FALSE;

for ($i = 0; $i < $n; ++$i) {
    if ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4] == $str[$i * 4 + 3]) {
        $str_ans[] = "aaaa";
        $aaaa = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4 + 2] == $str[$i * 4 + 3]) {
        $str_ans[] = "aabb";
        $aabb = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4 + 1] == $str[$i * 4 + 3]) {
        $str_ans[] = "abab";
        $abab = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 3] && $str[$i * 4 + 1] == $str[$i * 4 + 2]) {
        $str_ans[] = "abba";
        $abba = TRUE;
    } else {
        $no = TRUE;
    }
}

if ($no)
    echo "NO\n";
elseif (!$aabb && !$abab && $abba) {
    echo "abba\n";
} elseif (!$aabb && $abab && !$abba) {
    echo "abab\n";
} elseif ($aabb && !$abab && !$abba) {
    echo "aabb\n";
} elseif ($aaaa) {
    echo "aaaa\n";
} else {
    echo "NO\n";
}

//$cnt=$aaaa+$aabb+$abab+$abba;
//foreach ($str_ans as $key => $value) {
//    echo $value . "\n";
//}
//var_dump($str);
?>

<?php

function regex($param, $k) {
    $pattern = "/([^aeiou]*?[aeiou]){" . $k . "}/";
    preg_match($pattern, $param, $match);
    return $match[0];
}

$fr = fopen("php://stdin", "r");
//$n = (int) fgets($fr);
$arr = fgets($fr);
$arr = explode(' ', $arr);
$n = $arr[0];
$k = (int) $arr[1];

for ($i = 0; $i < 4 * $n; ++$i) {
    $str[$i] = fgets($fr);
    $str[$i] = strrev($str[$i]);
    $str[$i] = regex($str[$i], $k);
}

$str_ans = array();
$aaaa = FALSE;
$aabb = FALSE;
$abab = FALSE;
$abba = FALSE;
$no = FALSE;

for ($i = 0; $i < $n; ++$i) {
    if ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4] == $str[$i * 4 + 3]) {
        $str_ans[] = "aaaa";
        $aaaa = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4 + 2] == $str[$i * 4 + 3]) {
        $str_ans[] = "aabb";
        $aabb = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4 + 1] == $str[$i * 4 + 3]) {
        $str_ans[] = "abab";
        $abab = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 3] && $str[$i * 4 + 1] == $str[$i * 4 + 2]) {
        $str_ans[] = "abba";
        $abba = TRUE;
    } else {
        $no = TRUE;
    }
}

if ($no)
    echo "NO\n";
elseif (!$aabb && !$abab && $abba) {
    echo "abba\n";
} elseif (!$aabb && $abab && !$abba) {
    echo "abab\n";
} elseif ($aabb && !$abab && !$abba) {
    echo "aabb\n";
} else {
    echo "aaaa\n";
}

//$cnt=$aaaa+$aabb+$abab+$abba;
//foreach ($str_ans as $key => $value) {
//    echo $value . "\n";
//}
//var_dump($str);
?>

<?php

function regex($param, $k) {
    $pattern = "/([^aeiou]*?[aeiou]){" . $k . "}/";
    preg_match($pattern, $param, $match);
    return $match[0];
}

$fr = fopen("php://stdin", "r");
//$n = (int) fgets($fr);
$arr = fgets($fr);
$arr = explode(' ', $arr);
$n = $arr[0];
$k = (int) $arr[1];

$flag=FALSE;
for ($i = 0; $i < 4 * $n; ++$i) {
    $str[$i] = fgets($fr);
    $str[$i] = strrev($str[$i]);
    $str[$i] = regex($str[$i], $k);
    if($str[$i]==NULL){
        $flag=TRUE;
        break;
    }
}
if($flag){
    die("NO\n");
    exit ;
}

$str_ans = array();
$aaaa = FALSE;
$aabb = FALSE;
$abab = FALSE;
$abba = FALSE;
$no = FALSE;

for ($i = 0; $i < $n; ++$i) {
    if ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4] == $str[$i * 4 + 3]) {
        $str_ans[] = "aaaa";
        $aaaa = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4 + 2] == $str[$i * 4 + 3]) {
        $str_ans[] = "aabb";
        $aabb = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4 + 1] == $str[$i * 4 + 3]) {
        $str_ans[] = "abab";
        $abab = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 3] && $str[$i * 4 + 1] == $str[$i * 4 + 2]) {
        $str_ans[] = "abba";
        $abba = TRUE;
    } else {
        $no = TRUE;
    }
}

if ($no)
    echo "NO\n";
elseif (!$aabb && !$abab && $abba) {
    echo "abba\n";
} elseif (!$aabb && $abab && !$abba) {
    echo "abab\n";
} elseif ($aabb && !$abab && !$abba) {
    echo "aabb\n";
} elseif ($aaaa) {
    echo "aaaa\n";
} else {
    echo "NO\n";
}

//$cnt=$aaaa+$aabb+$abab+$abba;
//foreach ($str_ans as $key => $value) {
//    echo $value . "\n";
//}
//var_dump($str);
?>

<?php

function regex($param, $k) {
    $pattern = "/([^aeiou]*?[aeiou]){" . $k . "}/";
    preg_match($pattern, $param, $match);
    return $match[0];
}

$fr = fopen("php://stdin", "r");
//$n = (int) fgets($fr);
$arr = fgets($fr);
$arr = explode(' ', $arr);
$n = $arr[0];
$k = (int) $arr[1];

for ($i = 0; $i < 4 * $n; ++$i) {
    $str[$i] = fgets($fr);
    $str[$i] = strrev($str[$i]);
    $str[$i] = regex($str[$i], $k);
}

$str_ans = array();
$aaaa = FALSE;
$aabb = FALSE;
$abab = FALSE;
$abba = FALSE;
$no = FALSE;

for ($i = 0; $i < $n; ++$i) {
    if ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4] == $str[$i * 4 + 3]) {
        $str_ans[] = "aaaa";
        $aaaa = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 1] && $str[$i * 4 + 2] == $str[$i * 4 + 3]) {
        $str_ans[] = "aabb";
        $aabb = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 2] && $str[$i * 4 + 1] == $str[$i * 4 + 3]) {
        $str_ans[] = "abab";
        $abab = TRUE;
    } elseif ($str[$i * 4] == $str[$i * 4 + 3] && $str[$i * 4 + 1] == $str[$i * 4 + 2]) {
        $str_ans[] = "abba";
        $abba = TRUE;
    } else {
        $no = TRUE;
    }
}

if ($no)
    echo "NO\n";
elseif (!$aabb && !$abab && $abba) {
    echo "abba\n";
} elseif (!$aabb && $abab && !$abba) {
    echo "abab\n";
} elseif ($aabb && !$abab && !$abba) {
    echo "aabb\n";
} elseif ($aaaa) {
    echo "aaaa\n";
} else {
    echo "NO\n";
}

//$cnt=$aaaa+$aabb+$abab+$abba;
//foreach ($str_ans as $key => $value) {
//    echo $value . "\n";
//}
//var_dump($str);
?>


Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking requests received by now. Each request is characterized by two numbers: ci and pi — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly.We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment.Unfortunately, there only are k tables in the restaurant. For each table, we know ri — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing.Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum.

The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≤ ci, pi ≤ 1000) — the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly. The next line contains integer k (1 ≤ k ≤ 1000) — the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≤ ri ≤ 1000) — the maximum number of people that can sit at each table.

In the first line print two integers: m, s — the number of accepted requests and the total money you get from these requests, correspondingly. Then print m lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input. If there are multiple optimal answers, print any of them.


A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull.Let's try to make a new task. Firstly we will use the following task. There are n people, sort them by their name. It is just an ordinary sorting problem, but we can make it more interesting by adding nondeterministic element. There are n people, each person will use either his/her first name or last name as a handle. Can the lexicographical order of the handles be exactly equal to the given permutation p?More formally, if we denote the handle of the i-th person as hi, then the following condition must hold: .

The first line contains an integer n (1 ≤ n ≤ 105) — the number of people. The next n lines each contains two strings. The i-th line contains strings fi and si (1 ≤ |fi|, |si| ≤ 50) — the first name and last name of the i-th person. Each string consists only of lowercase English letters. All of the given 2n strings will be distinct. The next line contains n distinct integers: p1, p2, ..., pn (1 ≤ pi ≤ n).

If it is possible, output "YES", otherwise output "NO".

3
gennady korotkevich
petr mitrichev
gaoyuan chen
1 2 3

3
gennady korotkevich
petr mitrichev
gaoyuan chen
3 1 2

2
galileo galilei
nicolaus copernicus
2 1

10
rean schwarzer
fei claussell
alisa reinford
eliot craig
laura arseid
jusis albarea
machias regnitz
sara valestin
emma millstein
gaius worzel
1 2 3 4 5 6 7 8 9 10

10
rean schwarzer
fei claussell
alisa reinford
eliot craig
laura arseid
jusis albarea
machias regnitz
sara valestin
emma millstein
gaius worzel
2 4 9 6 5 7 1 3 8 10

NoteIn example 1 and 2, we have 3 people: tourist, Petr and me (cgy4ever). You can see that whatever handle is chosen, I must be the first, then tourist and Petr must be the last.In example 3, if Copernicus uses "copernicus" as his handle, everything will be alright.

<?php
    $input = explode("\n", trim(file_get_contents("php://stdin")));
    $count = $input[0];
    $ps = explode(' ', end($input));
    $hs = array_slice($input, 1, $count, true);
    $sorted = array();
    foreach($hs as $key => $hi){
        $sorted[$hi] = $key;
        $fi = explode(' ', $hi);
        $sorted[$fi[0]] = $key;
        $sorted[$fi[1]] = $key;
    }
    ksort($sorted);
    $i = 0;
    foreach($sorted as $order){
        if(isset($ps[$i]) && $ps[$i] == $order){
            unset($ps[$i]);
            $i++;
        }
    }
    echo empty($ps) ? "YES" : "NO";

<?php
    $input = explode("\n", file_get_contents("php://stdin"));
    $count = $input[0];
    $ps = explode(' ', end($input));
    $hs = array_slice($input, 1, $count, true);
    $sorted = array();
    foreach($hs as $key => $hi){
        $sorted[$hi] = $key;
        $fi = explode(' ', $hi);
        $sorted[$fi[0]] = $key;
        $sorted[$fi[1]] = $key;
    }
    ksort($sorted);
    $i = 0;
    foreach($sorted as $order){
        if(isset($ps[$i]) && $ps[$i] == $order){
            unset($ps[$i]);
            $i++;
        }
    }
    echo empty($ps) ? "YES" : "NO";


Your working week consists of $$$n$$$ days numbered from $$$1$$$ to $$$n$$$, after day $$$n$$$ goes day $$$1$$$ again. And $$$3$$$ of them are days off. One of the days off is the last day, day $$$n$$$. You have to decide when the other two are.Choosing days off, you pursue two goals:   No two days should go one after the other. Note that you can't make day $$$1$$$ a day off because it follows day $$$n$$$.  Working segments framed by days off should be as dissimilar as possible in duration. More specifically, if the segments are of size $$$l_1$$$, $$$l_2$$$, and $$$l_3$$$ days long, you want to maximize $$$\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$$$. Output the maximum value of $$$\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$$$ that can be obtained.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. The only line of each test case contains the integer $$$n$$$ ($$$6 \le n \le 10^9$$$).

For each test case, output one integer — the maximum possible obtained value.

NoteIn the image below you can see the example solutions for the first two test cases. Chosen days off are shown in purple. Working segments are underlined in green.In test case $$$1$$$, the only options for days off are days $$$2$$$, $$$3$$$, and $$$4$$$ (because $$$1$$$ and $$$5$$$ are next to day $$$n$$$). So the only way to place them without selecting neighboring days is to choose days $$$2$$$ and $$$4$$$. Thus, $$$l_1 = l_2 = l_3 = 1$$$, and the answer $$$\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|) = 0$$$.   For test case $$$2$$$, one possible way to choose days off is shown. The working segments have the lengths of $$$2$$$, $$$1$$$, and $$$4$$$ days. So the minimum difference is $$$1 = \min(1, 3, 2) = \min(|2 - 1|, |1 - 4|, |4 - 2|)$$$. It can be shown that there is no way to make it larger.

<?php
   $cases = fgets(STDIN);
   while ($cases--) {
       $n = fgets(STDIN);

       echo intdiv($n - 6, 3);
       echo "\n";
   }


Codeforces separates its users into $$$4$$$ divisions by their rating:  For Division 1: $$$1900 \leq \mathrm{rating}$$$  For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$  For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$  For Division 4: $$$\mathrm{rating} \leq 1399$$$ Given a $$$\mathrm{rating}$$$, print in which division the $$$\mathrm{rating}$$$ belongs.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of testcases. The description of each test consists of one line containing one integer $$$\mathrm{rating}$$$ ($$$-5000 \leq \mathrm{rating} \leq 5000$$$).

For each test case, output a single line containing the correct division in the format "Division X", where $$$X$$$ is an integer between $$$1$$$ and $$$4$$$ representing the division for the corresponding rating.

Division 4
Division 4
Division 4
Division 4
Division 3
Division 2
Division 1

NoteFor test cases $$$1-4$$$, the corresponding ratings are $$$-789$$$, $$$1299$$$, $$$1300$$$, $$$1399$$$, so all of them are in division $$$4$$$.For the fifth test case, the corresponding rating is $$$1400$$$, so it is in division $$$3$$$.For the sixth test case, the corresponding rating is $$$1679$$$, so it is in division $$$2$$$.For the seventh test case, the corresponding rating is $$$2300$$$, so it is in division $$$1$$$.

<?php
$t = Read::int();
while($t--){
 solve();
 echo "\n";
}
function solve(){
	$t = Read::int();
if($t >=1900){
echo 'Division 1';
} else if($t > 1599 && $t <= 1899){
echo 'Division 2';
}else if($t > 1399 && $t <= 1599){
Echo 'Division 3';
} else {
echo 'Division 4';
}
}

class Read
{
    public static function string()
    {
        return trim(fgets(STDIN));
    }

    public static function int()
    {
        return intval(fgets(STDIN));
    }

    public static function array_int($sep = ' ')
    {
        $s = trim(fgets(STDIN));
        return preg_split("/[\s,]+/", $s);
    }

}

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

  for($q=0; $q <$t; $q++) {

      $n = trim(fgets(STDIN));

      if($n <= 1399 ) {
          echo "Division 4 \n";
      } elseif($n >= 1400 && $n <= 1599) {
          echo "Division 3 \n";
      }elseif($n >= 1600 && $n <= 1899 ) {
          echo "Division 2 \n";
      } else {
          echo "Division 1 \n";
      }

  }

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     if($b <= 1399)
     {
          print "Division 4\n";
     }
     elseif($b <= 1599)
     {
          print "Division 3\n";
     }
     elseif($b <= 1899)
     {
          print "Division 2\n";
     }
     else
     {
          print "Division 1\n";
     }
}
?>

<?php
$t = Read::int();
while($t--){
 solve();
 echo '\n';
}
function solve(){
	$t = Read::int();
if($t >=1900){
echo 'Division 1';
} else if($t > 1599 && $t <= 1899){
echo 'Division 2';
}else if($t > 1399 && $t <= 1599){
Echo 'Division 3';
} else {
echo 'Division 4';
}
}

class Read
{
    public static function string()
    {
        return trim(fgets(STDIN));
    }

    public static function int()
    {
        return intval(fgets(STDIN));
    }

    public static function array_int($sep = ' ')
    {
        $s = trim(fgets(STDIN));
        return preg_split("/[\s,]+/", $s);
    }

}

<?php
$t = Read::int();
echo 'Division '. $t;
while($t--){
 solve();
 echo '\n';
}
function solve(){
	$t = Read::int();
if($t >=1900){
echo 'Division 1';
} else if($t > 1599 && $t <= 1899){
echo 'Division 2';
}else if($t > 1399 && $t <= 1599){
Echo 'Division 3';
} else {
echo 'Division 4';
}
}

class Read
{
    public static function string()
    {
        return trim(fgets(STDIN));
    }

    public static function int()
    {
        return intval(fgets(STDIN));
    }

    public static function array_int($sep = ' ')
    {
        $s = trim(fgets(STDIN));
        return preg_split("/[\s,]+/", $s);
    }

}

$t = Read::int();
while($t--){
 solve();
 echo '\n';
}
function solve(){
	$t = Read::int();
if($t >=1900){
echo 'Division 1';
} else if($t <=1600 || $t >= 1899){
echo 'Division 2';
}else if($t <= 1400 || $t >= 1599){
Echo 'Division 3';
} else {
echo 'Division 4';
}
}

class Read
{
    public static function string()
    {
        return trim(fgets(STDIN));
    }

    public static function int()
    {
        return intval(fgets(STDIN));
    }

    public static function array_int($sep = ' ')
    {
        $s = trim(fgets(STDIN));
        return preg_split("/[\s,]+/", $s);
    }

}

$t = Read::int();
    solve($t);
 function solve($t){
If($t >=1900){
echo 1;
} else if($t <=1600 || $t >= 1899){
echo 2;
}else if($t <= 1400 || $t >= 1599){
Echo 3;
} else {
echo 4;
}
}

class Read
{
    public static function string()
    {
        return trim(fgets(STDIN));
    }

    public static function int()
    {
        return intval(fgets(STDIN));
    }

    public static function array_int($sep = ' ')
    {
        $s = trim(fgets(STDIN));
        return preg_split("/[\s,]+/", $s);
    }

}

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

  for($q=0; $q <$t; $q++) {

      $n = trim(fgets(STDIN));

      if($n <= 1399 ) {
          echo "Division 4 /n";
      } elseif($n >= 1400 && $n <= 1599) {
          echo "Division 3 /n";
      }elseif($n >= 1600 && $n <= 1899 ) {
          echo "Division 2 /n";
      } else {
          echo "Division 1 /n";
      }

  }


A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.The town where Laurenty lives in is not large. The houses in it are located in two rows, n houses in each row. Laurenty lives in the very last house of the second row. The only shop in town is placed in the first house of the first row.The first and second rows are separated with the main avenue of the city. The adjacent houses of one row are separated by streets.Each crosswalk of a street or an avenue has some traffic lights. In order to cross the street, you need to press a button on the traffic light, wait for a while for the green light and cross the street. Different traffic lights can have different waiting time.The traffic light on the crosswalk from the j-th house of the i-th row to the (j + 1)-th house of the same row has waiting time equal to aij (1 ≤ i ≤ 2, 1 ≤ j ≤ n - 1). For the traffic light on the crossing from the j-th house of one row to the j-th house of another row the waiting time equals bj (1 ≤ j ≤ n). The city doesn't have any other crossings.The boy wants to get to the store, buy the products and go back. The main avenue of the city is wide enough, so the boy wants to cross it exactly once on the way to the store and exactly once on the way back home. The boy would get bored if he had to walk the same way again, so he wants the way home to be different from the way to the store in at least one crossing.    Figure to the first sample. Help Laurenty determine the minimum total time he needs to wait at the crossroads.

The first line of the input contains integer n (2 ≤ n ≤ 50) — the number of houses in each row.  Each of the next two lines contains n - 1 space-separated integer — values aij (1 ≤ aij ≤ 100).  The last line contains n space-separated integers bj (1 ≤ bj ≤ 100).

Print a single integer — the least total time Laurenty needs to wait at the crossroads, given that he crosses the avenue only once both on his way to the store and on his way back home.

NoteThe first sample is shown on the figure above. In the second sample, Laurenty's path can look as follows:   Laurenty crosses the avenue, the waiting time is 3;  Laurenty uses the second crossing in the first row, the waiting time is 2;  Laurenty uses the first crossing in the first row, the waiting time is 1;  Laurenty uses the first crossing in the first row, the waiting time is 1;  Laurenty crosses the avenue, the waiting time is 1;  Laurenty uses the second crossing in the second row, the waiting time is 3.  In total we get that the answer equals 11.In the last sample Laurenty visits all the crossings, so the answer is 4.


A basketball competition is held where the number of players in a team does not have a maximum or minimum limit (not necessarily $$$5$$$ players in one team for each match). There are $$$N$$$ candidate players in the competition that will be trained by Pak Chanek, the best basketball coach on earth. The $$$i$$$-th candidate player has a power of $$$P_i$$$.Pak Chanek will form zero or more teams from the $$$N$$$ candidate players on the condition that each candidate player may only join in at most one team. Each of Pak Chanek's teams will be sent to compete once with an enemy team that has a power of $$$D$$$. In each match, the team sent is said to defeat the enemy team if the sum of powers from the formed players is strictly greater than $$$D$$$.One of Pak Chanek's skills is that when a team that has been formed plays in a match, he can change the power of each player in the team to be equal to the biggest player power from the team.Determine the maximum number of wins that can be achieved by Pak Chanek.

The first line contains two integers $$$N$$$ and $$$D$$$ ($$$1 \le N \le 10^5$$$, $$$1 \le D \le 10^9$$$) — the number of candidate players and the power of the enemy team. The second line contains $$$N$$$ integers $$$P_1, P_2, \ldots, P_N$$$ ($$$1 \le P_i \le 10^9$$$) — the powers of all candidate players.

A line containing an integer representing the maximum number of wins that can be achieved by Pak Chanek.

NoteThe $$$1$$$-st team formed is a team containing players $$$4$$$ and $$$6$$$. The power of each player in the team becomes $$$100$$$. So the total power of the team is $$$100 + 100 = 200 > 180$$$.The $$$2$$$-nd team formed is a team containing players $$$1$$$, $$$2$$$, and $$$5$$$. The power of each player in the team becomes $$$90$$$. So the total power of the team is $$$90 + 90 + 90 = 270 > 180$$$.

<?php

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

fscanf($inp, '%d %d', $n, $d);
++$d;
$arr = fscanf($inp, str_repeat('%d ', $n));

rsort($arr);

$res = 0;

/** @noinspection SlowArrayOperationsInLoopInspection */
/** @noinspection ForeachInvariantsInspection */
for ($i = 0; $i < count($arr); ++$i) {
    $l = $arr[$i];
    $p = intdiv($d, $l) + ($d % $l !== 0);

    if ($i + $p > count($arr)) {
        break;
    }

    array_splice($arr, -$p + 1);

    ++$res;
}

echo $res.PHP_EOL;
/*

3 200
100 90 80

6 180
90 80 70 60 50 100
 */


The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also reads like a good criminal.However I, Heidi, will have none of that. As my joke for today, I am removing the story from the statement and replacing it with these two unhelpful paragraphs. Now solve the problem, fools!

The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104).

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
sort($c);
$d = 0;
for($x = 0; $x < $b; $x++)
{
     $d += $c[$x];
}
print $d;
?>


Many years ago Berland was a small country where only $$$n$$$ people lived. Each person had some savings: the $$$i$$$-th one had $$$a_i$$$ burles.The government considered a person as wealthy if he had at least $$$x$$$ burles. To increase the number of wealthy people Berland decided to carry out several reforms. Each reform looked like that:   the government chooses some subset of people (maybe all of them);  the government takes all savings from the chosen people and redistributes the savings among the chosen people equally. For example, consider the savings as list $$$[5, 1, 2, 1]$$$: if the government chose the $$$1$$$-st and the $$$3$$$-rd persons then it, at first, will take all $$$5 + 2 = 7$$$ burles and after that will return $$$3.5$$$ burles to the chosen people. As a result, the savings will become $$$[3.5, 1, 3.5, 1]$$$.A lot of data was lost from that time, so we don't know how many reforms were implemented and to whom. All we can do is ask you to calculate the maximum possible number of wealthy people after several (maybe zero) reforms.

The first line contains single integer $$$T$$$ ($$$1 \le T \le 1000$$$) — the number of test cases. Next $$$2T$$$ lines contain the test cases — two lines per test case. The first line contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le x \le 10^9$$$) — the number of people and the minimum amount of money to be considered as wealthy. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the initial savings of each person. It's guaranteed that the total sum of $$$n$$$ doesn't exceed $$$10^5$$$.

Print $$$T$$$ integers — one per test case. For each test case print the maximum possible number of wealthy people after several (maybe zero) reforms.

NoteThe first test case is described in the statement.In the second test case, the government, for example, could carry out two reforms: $$$[\underline{11}, \underline{9}, 11, 9] \rightarrow [10, 10, \underline{11}, \underline{9}] \rightarrow [10, 10, 10, 10]$$$.In the third test case, the government couldn't make even one person wealthy.In the fourth test case, the government could choose all people to carry out a reform: $$$[\underline{9}, \underline{4}, \underline{9}] \rightarrow [7\frac{1}{3}, 7\frac{1}{3}, 7\frac{1}{3}]$$$.

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

$check = function($n, $x, $a){
	sort($a);

	$s1 = array_sum($a);
	$s2 = $n * $x;

	for ($i = 0; $i < count($a); $i++){
		if($s2 <= $s1){
			return $n - $i;
		}
		$s2 -= $x;
		$s1 -= $a[$i];
	}

	return 0;
};

for($t = intval(fgets(STDIN)); $t > 0; $t--){
	list($n, $x) = explode(' ', trim(fgets(STDIN)));
	$a = explode(' ', trim(fgets(STDIN)));

	echo $check($n, $x, $a)."\n";

}

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

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

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $in_str = explode(" ", trim(fgets(STDIN))) ;

        $n = intval($in_str[0]) ;
        $x = intval($in_str[1]) ;

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

        for($i = 0; $i < $n; $i ++) $in_str[$i] = intval($in_str[$i]) ;
        sort($in_str) ;

        $sum = 0 ;
        $ans = 0 ;
        for($i = $n - 1; $i >= 0; $i --)
        {
            $sum += $in_str[$i] ;

            if($sum >= ($n - $i) * $x) $ans = $n - $i ;
            else break ;
        }

        echo $ans . "\n" ;
    }
?>


Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete?

The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one.

In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0.


Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them.The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point $$$(0, 0)$$$. While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to $$$OX$$$ or $$$OY$$$ axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification.Alexey wants to make a polyline in such a way that its end is as far as possible from $$$(0, 0)$$$. Please help him to grow the tree this way.Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 100\,000$$$) — the number of sticks Alexey got as a present. The second line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$) — the lengths of the sticks.

Print one integer — the square of the largest possible distance from $$$(0, 0)$$$ to the tree end.

NoteThe following pictures show optimal trees for example tests. The squared distance in the first example equals $$$5 \cdot 5 + 1 \cdot 1 = 26$$$, and in the second example $$$4 \cdot 4 + 2 \cdot 2 = 20$$$.


You are given two integers $$$b$$$ and $$$w$$$. You have a chessboard of size $$$10^9 \times 10^9$$$ with the top left cell at $$$(1; 1)$$$, the cell $$$(1; 1)$$$ is painted white.Your task is to find a connected component on this chessboard that contains exactly $$$b$$$ black cells and exactly $$$w$$$ white cells. Two cells are called connected if they share a side (i.e. for the cell $$$(x, y)$$$ there are at most four connected cells: $$$(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)$$$). A set of cells is called a connected component if for every pair of cells $$$C_1$$$ and $$$C_2$$$ from this set, there exists a sequence of cells $$$c_1$$$, $$$c_2$$$, ..., $$$c_k$$$ such that $$$c_1 = C_1$$$, $$$c_k = C_2$$$, all $$$c_i$$$ from $$$1$$$ to $$$k$$$ are belong to this set of cells and for every $$$i \in [1, k - 1]$$$, cells $$$c_i$$$ and $$$c_{i + 1}$$$ are connected.Obviously, it can be impossible to find such component. In this case print "NO". Otherwise, print "YES" and any suitable connected component.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. Then $$$q$$$ queries follow. The only line of the query contains two integers $$$b$$$ and $$$w$$$ ($$$1 \le b, w \le 10^5$$$) — the number of black cells required and the number of white cells required. It is guaranteed that the sum of numbers of cells does not exceed $$$2 \cdot 10^5$$$ ($$$\sum w + \sum b \le 2 \cdot 10^5$$$).

For each query, print the answer to it. If it is impossible to find the required component, print "NO" on the first line. Otherwise, print "YES" on the first line. In the next $$$b + w$$$ lines print coordinates of cells of your component in any order. There should be exactly $$$b$$$ black cells and $$$w$$$ white cells in your answer. The printed component should be connected. If there are several answers, you can print any. All coordinates in the answer should be in the range $$$[1; 10^9]$$$.


A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database.

The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.

Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.

<?php
$a = trim(fgets(STDIN));
$c = array();
array_unshift($c, " ");
unset($c[0]);
for($x = 1; $x < $a; $x++)
{
    $b = trim(fgets(STDIN));
    $d = array_key_exists($b, $c);
    if($d == FALSE)
    {
        $c[$b] = 0;
        print "OK" . "\n";
    }
    else
    {
        $c[$b]++;
        print $b . $c[$b] . "\n";
    }
}
$b = trim(fgets(STDIN));
$d = array_key_exists($b, $c);
if($d == FALSE)
{
    $c[$b] = 0;
    print "OK";
}
else
{
    $c[$b]++;
    print $b . $c[$b];
}
?>

<?php

fscanf(STDIN,"%d",$t);
$arr=array();
while($t--){
    fscanf(STDIN,"%s",$s);

    if(!$arr[$s]){
        fprintf(STDOUT,"OK\n");
        $arr[$s]++;
    }else{
        fprintf(STDOUT,"%s%d\n",$s,$arr[$s]);
        $arr[$s]++;
    }
}

?>

<?php declare(strict_types=1);

$fp = fopen('php://stdin', 'r');
$n = (int)fgets($fp);

$names = [];
for ($i = 0; $i < $n; ++$i) {
    $name = rtrim(fgets($fp));

    if (!isset($names[$name])) {
        $names[$name] = 0;
        echo "OK\n";
    } else {
        echo $name . ++$names[$name] . "\n";
    }
}
fclose($fp);

<?php

$first = trim(fgets(STDIN));

$nums = array();
$i = 1;

do
{
    $nums[] = trim(fgets(STDIN));
    $i++;
}
while ($i <= $first);

$nums_kol = Array();

foreach($nums as $key=>$value)
    if(!isset($nums_kol[$value]))
    {
        $nums_kol[$value] = 0;
        echo "OK"."\n";
    }
    else
    {
        $nums_kol[$value] += 1;
        echo $value.$nums_kol[$value]."\n";
    }

?>

<?php
	$n=fgets(STDIN);
	$hash=array();
	for($i=0; $i<$n; $i++)
	{
		$s=trim(fgets(STDIN));
		if(isset($hash[$s]))
		{
			$hash[$s]++;
			print $s.$hash[$s]."\n";
		}
		else
		{
			$hash[$s]=0;
			print "OK\n";
		}
	}
?>

<?php
$in = file_get_contents("php://stdin");
$in = explode("\r\n",$in);
$k =$in[0];
$p = array();
for($i=1;$i<=$k;$i++)
{
$name = $in[$i];

if(array_key_exists($name,$p))
{
  $p[$name]++;
  echo ($name.$p[$name]."\n");
}
else
{
$p[$name] = 0;
echo "OK\n";
}

}

<?php
$n = rtrim(fgets(STDIN));
$names = array();
for($i = 0;$i < $n;$i++){
    $name = rtrim(fgets(STDIN));
    if(!isset($names[$name])){
        $names[$name] = 1;
        print "OK\n";
    }
    else{
        print $name . $names[$name]++ . "\n";
    }
}

<?php

/**
 * В скором времени в Берляндии откроется новая почтовая служба "Берляндеск". Администрация сайта хочет запустить свой проект как можно быстрее, поэтому они попросили Вас о помощи. Вам предлагается реализовать прототип системы регистрации сайта.
 *
 * Система должна работать по следующему принципу. Каждый раз, когда новый пользователь хочет зарегистрироваться, он посылает системе запрос name со своим именем. Если данное имя не содержится в базе данных системы, то оно заносится туда и пользователю возвращается ответ OK, подтверждающий успешную регистрацию. Если же на сайте уже присутствует пользователь с именем name, то система формирует новое имя и выдает его пользователю в качестве подсказки, при этом подсказка также добавляется в базу данных. Новое имя формируется по следующему правилу. К name последовательно приписываются числа, начиная с единицы (name1, name2, ...), и среди них находят такое наименьшее i, что namei не содержится в базе данных сайта.
 * Входные данные
 *
 * В первой строке входных данных задано число n (1 ≤ n ≤ 105). Следующие n строк содержат запросы к системе. Каждый запрос представляет собой непустую строку длиной не более 32 символов, состоящую только из строчных букв латинского алфавита.
 * Выходные данные
 *
 * В выходных данных должно содержаться n строк — ответы системы на запросы: ОК в случае успешной регистрации, или подсказку с новым именем, если запрашиваемое уже занято.
 */

define('DEBUG', 0);

function doLog($log) {
	if (DEBUG) {
		echo "[" . microtime(true) ."] " . $log . "\n";
	}
}

function solve($nick)
{
	global $db;

	if (isset($db[$nick])) {
		$db[$nick] += 1;
		return $nick . $db[$nick];
	} else {
		$db[$nick] = 0;
		return 'OK';
	}
}

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

$db = [];
$result = '';
while ($n--) {
	$nick = trim(fgets(STDIN));
	$result .= solve($nick) . "\n";
}

doLog($result . "\n");

echo $result;

<?php

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

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

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

function foo($name, &$names)
{
    if (isset($names[$name])) {
        $names[$name]++;

        return $name . $names[$name];
    }

    $names[$name] = 0;

    return 'OK';
}

$names = [];
$r = 0;

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

for ($i = 0; $i < $n; ++$i) {
    list($name) = fscanf($input, "%s\n");

    $r = foo($name, $names);

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

<?php
$n = fgets(STDIN);
$reg = [];

for ($i = 0; $i < $n; $i++)
{
	$s = trim(fgets(STDIN));
	if(isset($reg[$s]))
	{
		$reg[$s]++;
		print $s . $reg[$s] . "\n";
	} else
	{
			$reg[$s] = 0;
			print "OK\n";
	}
}

<?php
$x = rtrim(fgets(STDIN));
$p = array();
for($i = 0; $i < $x; $i++){
    $a = rtrim(fgets(STDIN));
    if (!array_key_exists($a, $p)){
        $p[$a] = 1;
        printf("OK\n");
    }
    else{
        $p[$a]++;
        printf("%s%d\n", $a, $p[$a] - 1);
    }
}
?>

<?php
fscanf(STDIN, "%d", $n);
$hashTable = array();
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s", $name);
    if (isset($hashTable[$name])) {
        $nameCount = $hashTable[$name];
        printf($name.$nameCount."\n");
        $hashTable[$name.$nameCount] = 1;
        $hashTable[$name] = $nameCount + 1;
    } else {
        printf("OK\n");
        $hashTable[$name] = 1;
    }
}
?>

<?php
$db = [];
for($n = trim(fgets(STDIN)); $n > 0; $n--){
    $nombre = trim(fgets(STDIN));
    if (array_key_exists($nombre, $db)){
        $cant = $db[$nombre];
        $db[$nombre] = $cant+1;
        echo $nombre.$cant."\n";
    }
    else{
        $db[$nombre] = 1;
        echo "OK\n";
    }
}
?>

<?php
$n = trim(fgets(STDIN));
$bd_words = [];
$array_count = [];
for($i = 0; $i < $n; $i++){
  fscanf(STDIN, "%s\n", $new_word);
  if(isset($bd_words[$new_word])){
    $array_count[$new_word]++;
    echo $new_word.$array_count[$new_word]."\n";
  }else{
    $array_count[$new_word] = 0;
    echo 'OK'."\n";
  }
  $bd_words[$new_word] = true;
}

?>

<?php
  fscanf(STDIN,"%d",$n);
  $arr = array();
  $res=array();
  for($i=0;$i<$n;$i++)
  {
    fscanf(STDIN,"%s",$str);
    if(array_key_exists($str,$arr))
    {
      $res[]=$str.$arr[$str];
      $arr[$str]++;

    }
    else {
      $arr[$str]=1;
      $res[]="OK";
    }
  }
  for($i=0;$i<$n;$i++)
    echo $res[$i]."\n";

?>

<?php
fscanf(STDIN, "%d", $n);
$name = array();
for ($i=0;$i<$n;$i++){
	fscanf(STDIN, "%s", $s);
	if (array_key_exists($s, $name)){
		$name[$s]++;
		echo $s.$name[$s]."\n";
	}
	else{
		$name[$s] = 0;
		echo "OK\n";
	}
}
?>

<?php
fscanf(STDIN, "%d", $n);
$name = array();
$index = array();
for ($i=0;$i<$n;$i++){
	fscanf(STDIN, "%s", $s);
	if (in_array($s, $name)){
		$x = array_search($s, $name);
		$index[$x]++;
		echo $s.$index[$x]."\n";
	}
	else{
		array_push($name, $s);
		array_push($index, 0);
		echo "OK\n";
	}
}
?>

<?php
fscanf(STDIN, "%d\n", $n);
$cnt = array();
for (; $n > 0; $n--) {
	fscanf(STDIN, "%s\n", $s);
	if (!array_key_exists($s, $cnt)) {
		$cnt[$s] = 1;
		print("OK\n");
	} else {
		print($s.$cnt[$s]."\n");
		$cnt[$s] += 1;
	}
}
?>

<?php
$n=trim(fgets(STDIN));
while($n--)
{
    $a=trim(fgets(STDIN));
    echo ($b[$a])? $a.$b[$a]."\n" : "OK\n";
    $b[$a]++;
}

?>

<?php
fscanf(STDIN, "%d", $c);
// $input = explode(' ', trim(fgets(STDIN)));
// $input = array_map('intval',  $input);

$h = [];
$db = [];
$results = [];

for($i=0; $i<$c; $i++) {
    $name = trim(fgets(STDIN));
    $newName = isset($db[$name]) ? $name.$db[$name] : $name;
    $db[$name] = isset($db[$name]) ? $db[$name]+1 : 1;
    $results[] = $newName === $name ? 'OK' : $newName;
}
echo implode("\n", $results);

<?php

fscanf(STDIN, "%d\n", $number);

for ($i = 0; $i < $number; $i++) $input[] = trim(fgets(STDIN));

$counter = array();

// in_array — операция «медленная»; время её выполнения линейно зависит от размера массива, в котором производится поиск
// проблема в том, что in_array делает следующее: она последовательно сравнивает наш элемент с каждым из элементов массива

// в php есть другой способ сделать то же самое; это использование ассоциативного массива

// вот; вроде, так :)
// смысл в том, что операция поиска в ассоциативном массиве очень быстрая, близкая к константному числу времени
// как и операция добавления в него
// на самом деле в PHP массив это хэш-таблица; знаете, что такое хэш-таблицы? nope)
// сейчас накидаю ссылок)

foreach ($input as $value) {
    if (!isset($counter[$value])) {
        echo "OK\n";
        $counter[$value] = 0;
    }
    else {
        $counter[$value] = $counter[$value] + 1;
        echo $value.$counter[$value]."\n";
    }
}

?>

<?php
	$arr = array();
	$number = trim(fgets(STDIN));
	for ($i=0; $i < $number; $i++) {
			 $string = trim(fgets(STDIN));
			 if(array_key_exists($string, $arr))
			 		echo $string . ++$arr[$string] . "\r\n";
			 else {
			 		$arr[$string] = 0;
			 		echo "OK\r\n";
			 }
	}
?>

<?php
class stdIn
{
    var $ntxt = 0;
    var $nline = 0;
    var $arr_txt;
    var $arr_line;
    var $linex;
    var $liney;
    function stdIn($local = false){
        if($local){
            $dir = fopen("input.txt", 'r');
        }else{
            $dir = fopen("php://stdin", 'r');
        }
        $datatxt = stream_get_contents($dir);
        $del = Array("\n","\r","\n\r");
        $data = explode("\n",$datatxt);
        $il = 0;
        $id = 0;
        foreach($data as $line){
            if(strlen($line) > 0){
                $line = str_replace($del,'',$line);
                $dataex[] = $line;
                $text = explode(" ",$line);
                foreach($text as $txt){
                    $arr_txt[] = $txt;
                    $this->linex[$id] = $il;
                    $this->liney[$il] = $id;
                    $id++;
                }
            }
            $il++;
        }
        $this->arr_line = $dataex;
        $this->arr_txt  = $arr_txt;
    }
    function G(){
        $ret = $this->arr_txt[$this->ntxt++];
        $this->nline = $this->linex[$this->ntxt];
        return $ret;
    }
    function GL(){
        $this->ntxt = $this->liney[$this->nline]+1;
        return $this->arr_line[$this->nline++];
    }
}
$in = new stdIn();
$n = $in->G();
for($i = 0; $i<$n; $i++){
    $name = $in->G();
    $arr[$name]++;
    if($arr[$name]>1){
        echo $name.($arr[$name]-1)."\n";
    }else{
        echo "OK\n";
    }
}
?>

<?php
$stdout = fopen('php://stdout', 'w');
$h = fopen('php://stdin', 'r');
$n = trim(fgets($h));
if (($n>=1)&&($n<=exp(5*log(10))))
{// n ������ ���� �� ��������� �� 1 �� 10^5
	$f=true;
	for($i=1; $i<=$n; $i++)
	{
		$users[$i]=trim(fgets($h));
		$len=strlen($users[$i]);
		if (($len<1)||($len>32)){$f=false;} //����� ������� ��  ������ ��������� 32 �������
		for ($j=0; $j<$len; $j++)
		{
			if ((ord($users[$i][$j])<97)||(ord($users[$i][$j])>122)){$f=false;}//������ ������� �� ��������� ���� ���������� ��������
		}
	}
	if ($f)
	{
		fputs(STDOUT, "\n");
		$base = array();

		foreach($users as $user)
		{
			if(!isset($base[$user]))
			{
				$base[$user] = 0;
				fputs(STDOUT, "OK");
				fputs(STDOUT, "\n");
			}
			else
			{
				$base[$user]++;
				$name = $user . $base[$user];
				fputs(STDOUT, "$name");
				fputs(STDOUT, "\n");
			}
		}

	}
}
?>

<?php
$stdout = fopen('php://stdout', 'w');
$h = fopen('php://stdin', 'r');
$n = trim(fgets($h));
if (($n>=1)&&($n<=exp(5*log(10))))
{// n должно быть из диапозона от 1 до 10^5
    $f=true;
    for($i=1; $i<=$n; $i++)
    {
        $users[$i]=trim(fgets($h));
        $len=strlen($users[$i]);
        if (($len<1)||($len>32)){$f=false;} //длина запроса не  должна превышать 32 символа
        for ($j=0; $j<$len; $j++)
        {
            if ((ord($users[$i][$j])<97)||(ord($users[$i][$j])>122)){$f=false;}//запрос состоит из сторочных букв латинскаго алфавита
        }
    }
    if ($f)
    {
        fputs(STDOUT, "\n");
        $base = array();

        foreach($users as $user)
        {
            if(!isset($base[$user]))
            {
                $base[$user] = 0;
                fputs(STDOUT, "OK");
                fputs(STDOUT, "\n");
            }
            else
            {
                $base[$user]++;
                $name = $user . $base[$user];
                fputs(STDOUT, "$name");
                fputs(STDOUT, "\n");
            }
        }

    }
}
?>

<?php
$n=trim(fgets(STDIN));
$hashmap = array();
for ($i = 0; $i < $n; $i ++) {
    $s = trim(fgets(STDIN));
    if (array_key_exists($s, $hashmap)) {
        $num = $hashmap[$s] + 1;
        $hashmap[$s] = $num;
        print "$s$num \n";
    } else {
        $hashmap[$s] = 0;
        print "OK \n";
    }
}
?>

<?php
    $n = trim(fgets(STDIN));
    while($username = trim(fgets(STDIN)))
        echo ($cnt[$username]++) ? $username . ($cnt[$username] - 1) . PHP_EOL : "OK\n";
?>

<?php
	$n = trim(fgets(STDIN));
	$a = array();
	for($i = 0; $i < $n; $i++)
	{
		$s = trim(fgets(STDIN));
		if(array_key_exists($s, $a))
			echo $s.++$a[$s]."\n";
		else
		{
			$a[$s] = 0;
			echo "OK\n";
		}
	}
?>

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

$ua = array();

for($i=1;$i<=$n;$i++){
 $u = trim(fgets(STDIN));
 if(array_key_exists($u,$ua)){
  print $u.++$ua[$u]."\r\n";
 }else{
  $ua[$u] = 0;
  print "OK\r\n";
 }
}
?>

<?php
    $stdin = fopen("php://stdin", 'r');
    $n = fgets($stdin);
    for($i=0; $i<$n; $i++){
        $s = trim(fgets($stdin));
        if($p[$s])
            echo $s.$p[$s]++."\n";
        else{
            echo "OK\n";
            $p[$s] = 1;
        }
    }
?>

<?php
$handle = fopen ("php://stdin","r");
$lineNums = (int) fgets($handle);
$a=array();
$b=array();
for($i=0;$i<$lineNums;$i++){
	$next_line = trim(fgets($handle, 1024));
	if(array_key_exists($next_line,$a))
	{
		$b[]=$next_line.''.$a[$next_line];
		$a[$next_line]++;
	}else{
		$a[$next_line] = 1;
		$b[]="OK";
	}
}
for($i=0;$i<count($b);$i++){
	echo $b[$i]."\n";
}

<?php
$a = trim(fgets(STDIN));
$c = array();
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    $d = preg_grep("/" . "\b" . $b . "\b" . "/", $c);
    if(count($d) == "0")
    {
        array_push($c, $b);
        print "OK";
    }
    else
    {
        print $b . count($d);
    }
    if($x != $a)
    {
        print "\n";
    }
}
?>

<?php

$first = trim(fgets(STDIN));

$nums = array();
$i = 1;

do
{
    $nums[] = trim(fgets(STDIN));
    $i++;
}
while ($i <= $first);

$nums_kol = Array();

foreach($nums as $key=>$value)
    if(!isset($nums_kol[$value]))
    {
        $nums_kol[$value] = 1;
        echo "OK"."\n";
    }
    else
    {
        $nums_kol[$value] += 1;
        echo $value.$nums_kol[$value]."\n";
    }

?>

<?php

$first = trim(fgets(STDIN));

$nums = array();
$i = 1;

do
{
    $nums[] = trim(fgets(STDIN));
    $i++;
}
while ($i <= $first);

$nums_kol = Array();
$$nums_fin = Array();

foreach($nums as $key=>$value)
    if(!isset($nums_kol[$value]))
    {
        $nums_kol[$value] = 1;
        echo "OK"."\n";
    }
    else
    {
        $nums_kol[$value] += 1;
        echo $value.$nums_kol[$value]."\n";
    }

?>

<?php
$n = rtrim(fgets(STDIN));
$names = array();
for($i = 0;$i < $n;$i++){
    $name = rtrim(fgets(STDIN));
    if(!isset($names[$name])){
        $names[$name] = 1;
        print "OK\n";
    }
    else{
        print $name . ++$names[$name] . "\n";
    }
}

<?php
fscanf(STDIN, "%d", $n);
$hashTable = array();
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s", $name);
    if (isset($hashTable[$name])) {
        $nameCount = $hashTable[$name];
        $hashTable[$name.$nameCount] = 1;
        $hashTable[$name] = $nameCount + 1;
        $name = $name.$nameCount;
        printf($name.$nameCount."\n");
    } else {
        printf("OK\n");
        $hashTable[$name] = 1;
    }
}
?>

<?php
    error_reporting(0);
    $stdin = fopen('php://stdin', 'r');
    $stdout = fopen('php://stdout', 'w');

    $n = fgets($stdin);
    $failures = array();
    for($i=0; $i<$n; ++$i){
        $db[$i] = fgets($stdin);
        $db[$i] = rtrim($db[$i], " \r\n");
        $fail = false;
        for($j=0;$j<$i;++$j){
            if($db[$j]==$db[$i]) {
                $fail = true;
                break;
            }
        }
        if($fail==true){
            $tmp = array_count_values($failures);
            $index = $tmp[$db[$i]];
            $failures[] = $db[$i];
            $out[$i] = substr($db[$i], 0, strlen($db[$i])) . (string)($index+1);
        }
        else $out[$i] = "ОК";

    }
    for($i=0;$i<$n;++$i){
        fputs($stdout, $out[$i]);
        if($i!=$n-1) fputs($stdout, "\n");
    }
?>

<?php
    error_reporting(0);
    $stdin = fopen('php://stdin', 'r');
    $stdout = fopen('php://stdout', 'w');

    $n = fgets($stdin);
    $failures = array();
    for($i=0; $i<$n; ++$i){
        $db[$i] = fgets($stdin);
        $fail = false;
        for($j=0;$j<$i;++$j){
            if($db[$j]==$db[$i]) {
                $fail = true;
                break;
            }
        }
        if($fail==true){
            $tmp = array_count_values($failures);
            $index = $tmp[$db[$i]];
            $failures[] = $db[$i];
            $out[$i] = substr($db[$i], 0, strlen($db[$i])-1) . (string)($index+1);
        }
        else $out[$i] = "ОК";

    }
    for($i=0;$i<$n;++$i){
        fputs($stdout, $out[$i] . "\n");
    }

?>

<?php

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

    $n = fgets($stdin);
    $failures = array();
    for($i=0; $i<$n; ++$i){
        $db[$i] = fgets($stdin);
        $fail = false;
        for($j=0;$j<$i;++$j){
            if($db[$j]==$db[$i]) {
                $fail = true;
                break;
            }
        }
        if($fail==true){
            $tmp = array_count_values($failures);
            $index = $tmp[$db[$i]];
            $failures[] = $db[$i];
            $out[$i] = substr($db[$i], 0, strlen($db[$i])-1) . (string)($index+1);
        }
        else $out[$i] = "ОК";

    }
    for($i=0;$i<$n;++$i){
        fputs($stdout, $out[$i] . "\n");
    }

?>

<?php
$db = [];
for($n = trim(fgets(STDIN)); $n > 0; $n--){
    $nombre = trim(fgets(STIN));
    if (array_key_exists($nombre, $db)){
        $cant = $db[$nombre];
        $db[$nombre] = $cant+1;
        echo $nombre.$cant."\n";
    }
    else{
        $db[$nombre] = 1;
        echo "OK\n";
    }
}
?>

<?php
$n = trim(fgets(STDIN));
$words = [];
$res = [];
$numbers = ['0','1','2','3','4','5','6','7','8','9'];
for($i = 0; $i < $n; $i++){
  $new_word = trim(fgets(STDIN));
  if(in_array($new_word,$words)){
    $e_word = $words[array_search($new_word,$words)];
    $num_ad = 0;
    for($j = 0; $j<strlen($e_word);$j++){
      if(in_array($e_word[$j],$numbers)){
        $num_ad = substr($e_word,$j,-1);
        break;
      }
    }
    $num_ad++;
    $e_word = $e_word.$num_ad;
    $new_word = $e_word;
    array_push($res, $new_word);
  }else{
    array_push($res, 'OK');
  }
  array_push($words, $new_word);
}
foreach ($res as $re) {
  echo $re."\n";
}

?>

<?php
$n = trim(fgets(STDIN));
$res = [];
$bd_words = [];
$array_count = [];
for($i = 0; $i < $n; $i++){
  fscanf(STDIN, "%s\n", $new_word);
  if(in_array($new_word, $bd_words)){
    $array_count[$new_word]++;
    echo $new_word.$array_count[$new_word];
  }else{
    echo 'OK';
  }
  array_push($bd_words, $new_word);
}
foreach ($res as $re) {
  echo $re."\n";
}

?>

<?php
$n = trim(fgets(STDIN));
$res = [];
$bd_words = [];
$array_count = [];
for($i = 0; $i < $n; $i++){
  fscanf(STDIN, "%s\n", $new_word);
  if(in_array($new_word, $bd_words)){
    $array_count[$new_word]++;
    echo $new_word.$array_count[$new_word];
  }else{
    echo 'OK'."\n";
  }
  array_push($bd_words, $new_word)."\n";
}

?>

<?php
$n = trim(fgets(STDIN));
$res = [];
$bd_words = [];
$array_count = [];
for($i = 0; $i < $n; $i++){
  fscanf(STDIN, "%s\n", $new_word);
  if(in_array($new_word, $bd_words)){
    $array_count[$new_word]++;
    array_push($res,'OK');
  }else{
    array_push($res,$new_word.$array_count[$new_word]);
  }
  array_push($bd_words, $new_word);
}
foreach ($res as $re) {
  echo $re."\n";
}
?>

<?php
$n = trim(fgets(STDIN));
$words = [];
$res = [];
$bd_words = [];
$numbers = ['0','1','2','3','4','5','6','7','8','9'];
for($i = 0; $i < $n; $i++){
  $new_word = trim(fgets(STDIN));
  if(in_array($new_word,$bd_words)){
    $count = array_count_values($bd_words)[$new_word];
    $res_word = $new_word.$count;
    array_push($res, $res_word);
  }else{
    array_push($res, 'OK');
  }
  array_push($words, $new_word);
  array_push($bd_words, $new_word);
}
var_dump($res);
foreach ($res as $re) {
  echo $re;
}

?>

<?php
  fscanf(STDIN,"%d",$n);
  $arr = array();
  $res=array();
  for($i=0;$i<$n;$i++)
  {
    fscanf(STDIN,"%s",$str);
    if(array_key_exists($str,$arr))
    {
      $res[]=$str.$arr[$str];
      $arr[$str]++;

    }
    else {
      $arr[$str]=1;
      $res[]=$str;
    }
  }
  for($i=0;$i<$n;$i++)
    echo $res[$i]."\n";

?>

<?php
fscanf(STDIN, "%d", $n);
$name = array();
$index = array();
for ($i=0;$i<$n;$i++){
	fscanf(STDIN, "%s", $s);
	if (in_array($s, $name)){
		$x = array_search($s, $name);
		$index[$x]++;
		echo $s.$index[$x]."
";
	}
	else{
		array_push($name, $s);
		array_push($index, 0);
		echo "OK
";
	}
}
?>

<?php

fscanf(STDIN, "%d\n", $number);

for ($i = 0; $i < $number; $i++) $input[] = trim(fgets(STDIN));

$DB = array();
$counter = array();

foreach ($input as $value) {
    if (!in_array($value, $DB)) {
        echo "OK\n";
        $DB[] = $value;
        break;
    }
    else {
        $counter[$value] = $counter[$value] + 1;
        echo $value.$counter[$value]."\n";
        $DB[] = $value.$counter[$value];
    }
}

?>

<?php

fscanf(STDIN, "%d\n", $number);

for ($i = 0; $i < $number; $i++) $input[] = trim(fgets(STDIN));

$DB = array();
$counter = array();

for ($i = 0; $i < number; $i++) {
    if (!in_array($input($i), $DB)) {
        echo "OK\n";
        $DB[] = $input($i);
    }
    else {
        $counter[$input($i)] = $counter[$input($i)] + 1;
        echo $input($i) . $counter[$input($i)] . "\n";
        $DB[] = $input($i) . $counter[$input($i)];
    }
}

?>

<?php

fscanf(STDIN, "%d\n", $number);

for ($i = 0; $i < $number; $i++) $input[] = trim(fgets(STDIN));

$DB = array();

foreach ($input as $value) {
    if (in_array($value, $DB)) {
        echo $value.$counter."\n";
        $counter = $counter + 1;
        $DB[] = $value.$counter;
    }
    else {
        echo "OK\n";
        $DB[] = $value;
    }
}

print_r($DB);
?>

<?php

fscanf(STDIN, "%d\n", $number);

for ($i = 0; $i < $number; $i++) $input[] = trim(fgets(STDIN));

$DB = array();
$counter = 0;

foreach ($input as $value) {
    if (!in_array($value, $DB)) {
        echo "OK\n";
        $DB[] = $value;
    }
    else {
        $counter = $counter + 1;
        echo $value.$counter."\n";
        $DB[] = "$value.$counter";
    }
}

?>

<?php

fscanf(STDIN, "%d\n", $number);

for ($i = 0; $i < $number; $i++) $input[] = trim(fgets(STDIN));

$DB = array();

foreach ($input as $value) {
    if (in_array($value, $DB)) {
        echo $value.$counter."\n";
        $counter = $counter + 1;
        $DB[] = $value.$counter;
    }
    else {
        echo "OK\n";
        $DB[] = $value;
    }
}

?>

<?php

	$arr = array();
	$number = trim(fgets(STDIN));
	for ($i=0; $i < 6; $i++) {
			 $string = trim(fgets(STDIN));
			 if(array_key_exists($string, $arr))
			 		echo $string . $arr[$string] ++ . "\r\n";
			 else {
			 		echo "OK\n";
			 		$arr[$string] ++;
			 }
	}
?>

<?php

	$arr = array();
	$number = trim(fgets(STDIN));
	for ($i=0; $i < 6; $i++) {
			 $string = trim(fgets(STDIN));
			 if(array_key_exists($string, $arr))
			 		echo $string . $arr[$string] ++ . "\r\n";
			 else {
			 		$arr[$string] = 0;
			 		echo "OK\r\n";
			 }
	}
?>

<?php

	$arr = array();
	$number = trim(fgets(STDIN));
	for ($i=0; $i < 6; $i++) {
			 $string = trim(fgets(STDIN));
			 if(array_key_exists($string, $arr))
			 		echo $string . $arr[$string] ++ . "\r\n";
			 else {
			 		$arr[$string] = 0;
			 		echo "OK\n";
			 }
	}
?>

<?php

	$arr = array();
	$number = trim(fgets(STDIN));
	for ($i=0; $i < $number; $i++) {
			 $string = trim(fgets(STDIN));
			 if(array_key_exists($string, $arr))
			 		echo $string . $arr[$string] ++ . "\r\n";
			 else {
			 		$arr[$string] = 0;
			 		echo "OK\r\n";
			 }
	}
?>

<?php

	$arr = array();
	$number = trim(fgets(STDIN));
	for ($i=0; $i < 6; $i++) {
			 $string = trim(fgets(STDIN));
			 if(array_key_exists($string, $arr))
			 		echo $string . $arr[$string] ++ . "\r\n";
			 else {
			 		echo "OK\n";
			 		$arr[$string] = 0;
			 }
	}
?>

<?php
	$arr = array();
	$number = fgets(STDIN);
	for ($i=0; $i < 6; $i++) {
			 $string = fgets(STDIN);
			 if(array_key_exists($string, $arr))
			 		echo $string . $arr[$string] ++ . "\n";
			 else {
			 		echo "OK\n";
			 		$arr[$string] ++;
			 }
	}
?>

<?php
$stdout = fopen('php://stdout', 'w');
$h = fopen('php://stdin', 'r');
$n = trim(fgets($h));
if (($n>=1)&&($n<=exp(5*log(10))))
{// n должно быть из диапозона от 1 до 10^5
    $f=true;
    for($i=1; $i<=$n; $i++)
    {
        $users[$i]=trim(fgets($h));
        $len=strlen($users[$i]);
        if (($len<1)||($len>32)){$f=false;} //длина запроса не  должна превышать 32 символа
        for ($j=0; $j<$len; $j++)
        {
            if ((ord($s[$j])<97)||(ord($s[$j])>122)){$f=false;}//запрос состоит из сторочных букв латинскаго алфавита
        }
    }
    if ($f)
    {
        $base = array();

        foreach($users as $user)
        {
            if(!isset($base[$user]))
            {
                $base[$user] = 0;
                echo "OK";
            }
            else
            {
                $base[$user]++;
                echo $user . $base[$user];
            }
        }

    }
}
?>

n = input()
n = int(n)
usernames = {}
newlist = []
for i in range(n):
    name = raw_input()
    if name in usernames:
		newlist.append(name+str(usernames[name]))
		usernames[name] += 1
    else:
        newlist.append('OK')
	usernames[name]=1

for name in newlist:
    print(name)


Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.

The first line contains integer n (1 ≤ n ≤ 100) — the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai, bi (1 ≤ ai, bi ≤ 1000) — the description of the i-th bottle.

In a single line print a single integer — the answer to the problem.

<?php
$a = trim(fgets(STDIN));
$d = array();
for($x = 1; $x <= $a; $x++)
{
    list($b, $c) = explode(" ", trim(fgets(STDIN)));
    if($b != $c)
    {
        array_push($d, $c);
    }
}
$e = array_unique($d);
print $a - count($e);
?>

<?php
$a = trim(fgets(STDIN));
$d = array();
$e = array();
$h = 0;
for($x = 1; $x <= $a; $x++)
{
    list($b, $c) = explode(" ", trim(fgets(STDIN)));
    if($b != $c)
    {
        array_push($d, $c);
    }
    array_push($e, $b);
}
$f = array_unique($d);
$g = array_unique($e);
sort($f);
sort($g);
for($x = 0; $x < count($f); $x++)
{
    for($y = 0; $y < count($g); $y++)
    {
        if($f[$x] == $g[$y])
        {
            $h++;
        }
    }
}
print $a - $h;
?>

<?php
$a = trim(fgets(STDIN));
$d = array();
$e = array();
$h = 0;
for($x = 1; $x <= $a; $x++)
{
    list($b, $c) = explode(" ", trim(fgets(STDIN)));
    if($b != $c)
    {
        array_push($d, $c);
    }
    array_push($e, $b);
}
$f = array_unique($d);
sort($f);
for($x = 0; $x < count($e); $x++)
{
    for($y = 0; $y < count($f); $y++)
    {
        if($e[$x] == $f[$y])
        {
            $h++;
        }
    }
}
print $a - $h;
?>

<?

    $col = trim(fgets(STDIN));
    $c = 0;

    $s;

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

        list($type, $trg) = explode(" ", trim(fgets(STDIN)));
        if ($type == $trg) $s[$trg]++;
        else $ob[$trg] = 1;

        $buts[] = $type;

    }

    //print_r($buts);
    //print_r($ob);

    foreach($buts as $type=>$targ) {
        if ($ob[$targ] || $s[$targ] > 1) $c++;

    }

    echo $col - $c;

?>

<?

    $col = trim(fgets(STDIN));
    $ob = array();
    $c = 0;
    for($i=0; $i<$col; $i++) {
        $b = explode(" ", trim(fgets(STDIN)));
        $ob[$b[1]] = true;
    }

    for($i=1; $i<=$col; $i++) {
        if ($ob[$i]) $c++;
    }

    echo $col - $c;

?>

<?

    $col = trim(fgets(STDIN));
    $c = 0;

    for($i=0; $i<$col; $i++) {
        $b = explode(" ", trim(fgets(STDIN)));
        $ob[$b[1]]++;
        $buts[$b[0]] = $b[1];
    }

    foreach($buts as $type=>$targ) {
        if ($ob[$type] > 1) $c += $ob[$type];
        if ($ob[$type] == 1 && $targ!= $type) $c++;

    }

    echo $col - $c;

?>

<?

    $col = trim(fgets(STDIN));
    $c = 0;

    $s;

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

        list($type, $trg) = explode(" ", trim(fgets(STDIN)));
        if ($type == $trg) $s[$type]++;
        else {
            $ob[$type] = 1;
        }

        $buts[] = $type;

    }

    foreach($buts as $type=>$targ) {
        if ($ob[$type] || $s[type] > 1) $c++;

    }

    echo $col - $c;

?>