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

 $loop = true;
 $t = $loop ? IO::getInt() : 1;

 while($t--) {
      solve();
 }

 function solve()
 {
      $ans = 0;
      $n = IO::getInt();
      $a = IO::getArray();

      for($i=0; $i < $n-1; $i++) {
           if($a[$i] > $a[$i+1]) {
                $ans += 1;// 'YES';
                $i += 1;
           }
      }
      IO::pr($ans);
 }

//   $ans = 0;
//        list($n, $x) = IO::getArray();

//        $len = strlen($x);
//        if($len > $n) {
//           $ans = -1;
//        } elseif($len < $n) {
//           $maxV = maxVal($x);
//           if($maxV == '1') {
//              $ans = -1;
//           } else {
//                $ind = [0, 1];

//                foreach(str_split($x) as $ch) {
//                     IO::pr($ch);
//                }

//           }

//        }

//        IO::pr($ans);

//  function temp($x, $$aTemp, $ans) {
//       while($n > strlen($x)) {
//         IO::pr($ans . " " . strlen($x) . " " . $x . " " . $maxV);
//         if($maxV < 9 && in_array('3', str_split($x))) {
//              $maxV = 3;
//         }
//           $x = bcmul($x, $maxV);
//           $ans++;
//           $maxV = IO::getMaxValue(maxVal($x) , $maxV);
//      }
//      return $ans;
//  }
function maxVal($x) {
     $max = $x[0];
          for($i=1; $i<strlen($x); $i++) {
              $max = IO::getMaxValue($max, $x[$i]);
              if($max == 9) {
                   break;
              }
          }
          return $max;
}

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

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

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

        return $d == $n;
    }

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

         return $a[$n];
     }

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

}

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

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

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

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

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

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

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

        return $aResult;

    }
}

class SolveArchive
{

}

<?php

$t = trim(fgets(STDIN));
for ($t1=1; $t1<=$t; $t1++) {
    $n = trim(fgets(STDIN));
    $p = explode(' ', trim(fgets(STDIN)));

    $iSum = 0;

    for ($i=1; $i<$n; $i++) {
        if ($p[$i-1] > $p[$i]) {
            $iSum++;
            $i = $i + 1;
        }
    }
    echo $iSum . PHP_EOL;
}


<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";

  $t = getT();

  for($q=0; $q <$t; $q++) {
      $res = $yes;
      $s = getT();
      $s .='.';
      $g = '';
    for($i=0; $i<strlen($s)-1; $i++) {
        $g .=$s[$i];
        if($s[$i] != $s[$i+1]) {
            if(strlen($g) <= 1) {
                $res = $no;
                break;
            }
            $g = '';
        }
    }
       echo $res , $inter;
  }

  function getT() {
      return trim(fgets(STDIN));
  }
  function getA() {
      return explode(' ', trim(fgets(STDIN)));
  }


<?php

list($n, $m, $k) = explode(' ', trim(fgets(STDIN)));
$aArrayA = explode(' ', trim(fgets(STDIN)));
$aArrayB = $aArrayA;
$iMaxArrayA = max($aArrayA);
$iMaxKey = array_keys($aArrayA, $iMaxArrayA);
unset($aArrayA[current($iMaxKey)]);
$iMaxArrayB = max($aArrayA);
$iSumPoint = 0;
if($k >= $m){
    $iSumPoint = bcmul($iMaxArrayA , $m);
} else {
    $iAb = floor($m/($k + 1));
    $iAc = $m - ($iAb)*(($k + 1));
    $iSumPoint = bcmul(($iAb*$k),$iMaxArrayA);
    $iSumPoint = bcadd($iSumPoint,bcmul($iAb,$iMaxArrayB));
    if($iAc > 0){
        $iSumPoint = bcadd($iSumPoint,bcmul($iAc,$iMaxArrayA));
    }
}
echo $iSumPoint;

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
rsort($d);
$e2 = bcadd($c, 1);
$e3 = bcdiv($b, $e2);
$e = floor($e3);
$f2 = bcadd($c, 1);
$f = bcmod($b, $f2);
$g2 = bcmul($c, $d[0]);
$g3 = bcadd($g2, $d[1]);
$g4 = bcmul($g3, $e);
$g5 = bcmul($f, $d[0]);
$g = bcadd($g4, $g5);
print $g;
?>

<?php

$str = trim(fgets(STDIN));

$str1 = trim(fgets(STDIN));

$data = explode(' ', $str);

$n = $data[0];
$m = $data[1];
$k = $data[2];

$emo = explode(' ', $str1);

rsort($emo);
$c = 0;
$sum = 0;

$p = floor($m/($k+1));

$a = bcmul($emo[0], $k);
$b = bcadd($a, $emo[1]);

$sum = bcmul($p, $b);

$c += $p*($k+1);

$sum = bcadd($sum, bcmul($emo[0], ($m - $c)));

fwrite(STDOUT, sprintf("%s", $sum));

?>

<?php

list($n, $m, $k) = explode(' ', trim(fgets(STDIN)));
$aArrayA = explode(' ', trim(fgets(STDIN)));
$aArrayB = $aArrayA;
$iMaxArrayA = max($aArrayA);
$iMaxKey = array_keys($aArrayA, $iMaxArrayA);
unset($aArrayA[current($iMaxKey)]);
$iMaxArrayB = max($aArrayA);
$iSumPoint = 0;
if($k >= $m){
    $iSumPoint = $iMaxArrayA * $m;
} else {
    $iAb = floor($m/($k + 1));
    $iAc = $m - ($iAb)*(($k + 1));
    $iSumPoint = bcmul(($iAb*$k),$iMaxArrayA);
    $iSumPoint = bcadd($iSumPoint,bcmul($iAb,$iMaxArrayB));
    if($iAc > 0){
        $iSumPoint = bcadd($iSumPoint,bcmul($iAc,$iMaxArrayA));
    }
}
echo $iSumPoint;

<?php

list($n, $m, $k) = explode(' ', trim(fgets(STDIN)));
$aArrayA = explode(' ', trim(fgets(STDIN)));
$aArrayB = $aArrayA;
$iMaxArrayA = max($aArrayA);
$iMaxKey = array_keys($aArrayA, $iMaxArrayA);
unset($aArrayA[current($iMaxKey)]);
$iMaxArrayB = max($aArrayA);
$iSumPoint = 0;
if($k >= $m){
    $iSumPoint = $iMaxArrayA * $m;
} else {
    $iAb = floor($m/($k + 1));
    $iAc = $m - ($iAb)*(($k + 1));
    $iSumPoint = bcmul(($iAb*$k),$iMaxArrayA);
    $iSumPoint = bcadd($iSumPoint,bcmul($iAb,$iMaxArrayB));
    $iSumPoint = bcadd($iSumPoint,bcmul($iAc,$iMaxArrayA));
}
echo $iSumPoint;

<?php

list($n, $m, $k) = explode(' ', trim(fgets(STDIN)));
$aArrayA = explode(' ', trim(fgets(STDIN)));
$aArrayB = $aArrayA;
$iMaxArrayA = max($aArrayA);
$iMaxKey = array_keys($aArrayA, $iMaxArrayA);
unset($aArrayA[current($iMaxKey)]);
$iMaxArrayB = max($aArrayA);
$iSumPoint = 0;
if($k >= $m){
    $iSumPoint = $iMaxArrayA * $m;
} else {
    $iAb = floor($m/($k + 1));
    $iSumPoint = strval(($iAb*$k)*$iMaxArrayA);
    $iSumPoint += strval($iAb*$iMaxArrayB);
    $iAc = $m - ($iAb)*(($k + 1));
    $iSumPoint += strval($iAc*$iMaxArrayA);
}
echo $iSumPoint;

<?php

list($n, $m, $k) = explode(' ', trim(fgets(STDIN)));
$aArrayA = explode(' ', trim(fgets(STDIN)));
$aArrayB = $aArrayA;
$iMaxArrayA = max($aArrayA);
$iMaxKey = array_keys($aArrayA, $iMaxArrayA);
unset($aArrayA[current($iMaxKey)]);
$iMaxArrayB = max($aArrayA);
$iSumPoint = 0;
if($k >= $m){
    $iSumPoint = $iMaxArrayA * $m;
} else {
    $iAb = floor($m/($k + 1));
    $iSumPoint = ($iAb*$k)*$iMaxArrayA;
    $iSumPoint += $iAb*$iMaxArrayB;
}
echo $iSumPoint;

<?php

list($n, $m, $k) = explode(' ', trim(fgets(STDIN)));
$aArrayA = explode(' ', trim(fgets(STDIN)));
$aArrayB = $aArrayA;
$iMaxArrayA = max($aArrayA);
$iMaxKey = array_keys($aArrayA, $iMaxArrayA);
unset($aArrayA[current($iMaxKey)]);
$iMaxArrayB = max($aArrayA);
$iSumPoint = 0;
if($k >= $m){
    $iSumPoint = $iMaxArrayA * $m;
} else {
    $iAb = floor($m/($k + 1));
    $iSumPoint = ($iAb*$k)*$iMaxArrayA;
    $iSumPoint += $iAb*$iMaxArrayB;
    $iAc = $m - ($iAb)*(($k + 1));
    $iSumPoint += $iAc*$iMaxArrayA;
}
echo $iSumPoint;

<?php

$str = trim(fgets(STDIN));

$str1 = trim(fgets(STDIN));

$data = explode(' ', $str);

$n = $data[0];
$m = $data[1];
$k = $data[2];

$emo = explode(' ', $str1);

rsort($emo);
$c = 0;
$sum = 0;

$p = floor($m/($k+1));

$a = bcmul($emo[0], $k);
$b = bcmul($a, $emo[1]);

$sum = bcmul($p, $b);

$c += $p*($k+1);

$d = bcmul($emo[0], ($m - $c));

$sum = bcadd($sum, $d);

print $sum;

?>

<?php

$str = trim(fgets(STDIN));

$str1 = trim(fgets(STDIN));

$data = explode(' ', $str);

$n = $data[0];
$m = $data[1];
$k = $data[2];

$emo = explode(' ', $str1);

rsort($emo);
$c = 0;
$sum = 0;
$less = 0;

$p = floor($m/($k+1));

$sum += $p*($emo[0]*$k + $emo[1]);
$c += $p*($k+1);

$sum += $emo[0]*($m - $c);

fwrite(STDOUT, (int)$sum);

?>

<?php

$str = trim(fgets(STDIN));

$str1 = trim(fgets(STDIN));

$data = explode(' ', $str);

$n = $data[0];
$m = $data[1];
$k = $data[2];

$emo = explode(' ', $str1);

rsort($emo);
$c = 0;
$sum = 0;
$less = 0;

$p = floor($m/($k+1));

$sum += $p*($emo[0]*$k + $emo[1]);
$c += $p*($k+1);

$sum += $emo[0]*($m - $c);

fwrite(STDOUT, sprintf("%u", $sum));

?>

<?php

$str = trim(fgets(STDIN));

$str1 = trim(fgets(STDIN));

$data = explode(' ', $str);

$n = $data[0];
$m = $data[1];
$k = $data[2];

$emo = explode(' ', $str1);

rsort($emo);
$c = 0;
$sum = 0;
$less = 0;

$p = floor($m/($k+1));

$sum += $p*($emo[0]*$k + $emo[1]);
$c += $p*($k+1);

$sum += $emo[0]*($m - $c);

fwrite(STDOUT, sprintf("%d", $sum));

?>

<?php

$str = trim(fgets(STDIN));

$str1 = trim(fgets(STDIN));

$data = explode(' ', $str);

$n = $data[0];
$m = $data[1];
$k = $data[2];

$emo = explode(' ', $str1);

rsort($emo);
$c = 0;
$sum = 0;
$less = 0;

$p = floor($m/($k+1));

		$sum += $p*($emo[0]*$k + $emo[1]);
		$c += $p*($k+1);

$sum += $emo[0]*($m - $c);

fwrite(STDOUT, $sum);

?>


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

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

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

  $sum = array_sum($a);
  $k = count($a);

  if ($k == $sum) { echo '0'.PHP_EOL; }
  if ($k < $sum) { $ans = $sum - $k; echo $ans.PHP_EOL; }
  if ($k > $sum) { echo '1'.PHP_EOL; }
}

?>

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

   for($w=0; $w<$t; $w++) {
      $n =  trim(fgets(STDIN));
      $a =  explode(' ', trim(fgets(STDIN)));

    $count = array_sum($a);

    if($count == $n) {
        echo  "0\n";
    } elseif($count > $n ) {
        echo $count - $n . "\n";
    } else {
        echo  "1\n";
    }

}


<?php
$input = Array();

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

while($line = fgets($fp)) {
    $input[] = $line;
}

$temp = explode(" ", $input[0]);
$n = $temp[0];
$k = $temp[1];

$nums = explode(" ", $input[1]);

$total = 0;

for($i=0; $i<$n; $i++) {
	$count = 0;
	$count += substr_count($nums[$i],'4');
	$count += substr_count($nums[$i],'7');
	if($count<=$k)
		$total++;
}

echo $total;

<?// BismiLahi Rahmani Rahim ?>

<?php

fscanf(STDIN, "%d %d", $n, $k);

$a = explode(" ", fgets(STDIN));

$answer = 0;

for ($i = 0; $i < $n; $i ++) {
	$count = 0;
	$t = $a[$i];

	while ($t > 0) {
		$count += $t%10 == 4 || $t%10 == 7;
		$t = intval($t / 10);
	}

	$answer += $count <= $k;
}

printf("%d", $answer);

?>

<?php
    $fp = fopen('php://stdin', 'r');
    list($n, $k) = explode(' ', rtrim(fgets($fp)));
    $numbers = explode(' ', rtrim(fgets($fp)));
    $cnt = 0;
    for($i = 0; $i < $n; $i++) {
        $cnt += (strlen($numbers[$i]) - strlen(preg_replace('/[47]/','',$numbers[$i])) <= $k) ? 1 : 0;
    }
    echo $cnt;
?>


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array();
$e = array();
for($x = 0; $x < $a; $x++)
{
    $d = strpos("1" . $b[$x], "0");
    if($d == TRUE)
    {
        $c[] = $b[$x];
    }
    else
    {
        $e[] = $b[$x];
    }
}
if($a == count($c))
{
    print $a . "\n";
    print implode(" ", $b);
}
elseif($a > count($c))
{
    print count($c) + 1 . "\n";
    print $e[0] . " " . implode(" ", $c);
}
?>


<?php
$str=trim(fgets(STDIN));
fscanf(STDIN,"%d",$k);

 $len=strlen($str);
 //echo "$portion\n";
 //$inc=$portion-1;
 $decision=false;
 if($len%$k==0)
    {
        $portion=$len/$k;
        $cnt=0;
		 for ($i=0; $i <$len ; $i+=$portion)
		 {
		 	$str1=substr($str,$i,$portion);
		 	if($str1==strrev($str1))
		 	{
		 		$cnt++;
		 		if($cnt==$k)
		 		{
		 			$decision=true;
		 			break;
		 		}
		 	}

		 }
    }
   echo $decision?"YES":"NO";

<?php
	$s = trim(fgets(STDIN));
	$k = (int) (trim(fgets(STDIN)));
	$chk = true;
	if (strlen($s)%$k != 0) {
		$chk = false;
	} else {
		$r = floor(strlen($s)/$k);
		for ($i = 0; $i < strlen($s); $i += $r) {
			$t = substr($s,$i,$r);
			if ($t != strrev($t)) {
				$chk = false;
				break;
			}
		}
	}
	echo ($chk) ? 'YES' : 'NO';
?>

<?php
$str=trim(fgets(STDIN));
fscanf(STDIN,"%d",$k);

 $len=strlen($str);
 $portion=$len/$k;
 //echo "$portion\n";
 //$inc=$portion-1;
 $decision=false;
	 $cnt=0;
	 for ($i=0; $i <$len ; $i+=$portion)
	 {
	 	$str1=substr($str,$i,$portion);
	 	if($str1==strrev($str1))
	 	{
	 		$cnt++;
	 		if($cnt==$k)
	 		{
	 			$decision=true;
	 			break;
	 		}
	 	}

	 }
   echo $decision?"YES":"NO";

<?php
$str=trim(fgets(STDIN));
fscanf(STDIN,"%d",$k);
$decision=false;
if($k%2==0)
{
 $len=strlen($str);
 $portion=$len/$k;
 //echo "$portion\n";
 //$inc=$portion-1;
	 $cnt=0;
	 for ($i=0; $i <$len ; $i+=$portion)
	 {
	 	$str1=substr($str,$i,$portion);
	 	if($str1==strrev($str1))
	 	{
	 		$cnt++;
	 		if($cnt==$k)
	 		{
	 			$decision=true;
	 			break;
	 		}
	 	}

	 }
}
echo $decision?"YES":"NO";


<?php
fscanf(STDIN, '%d %d', $n, $m);
$flowers = explode(" ", fgets(STDIN));
$list=array();
for($i=0; $i<$m; $i++) $list[$i] = explode(" ", fgets(STDIN));

$happy = 0;

for($i=0; $i<$m; $i++){
    $sum = 0;
    for($j = $list[$i][0]-1; $j<=$list[$i][1]-1; $j++){
        $sum += $flowers[$j];
    }
    if($sum > 0) $happy += $sum;
}

print $happy;
?>

<?php
//$data = fgets(STDIN);
//$gestor = @fopen("data.in", "r");
$data = fgets(STDIN);
$data = explode(" ", $data);
$n = $data[0];
$m = $data[1];
$arr = array();
$data = fgets(STDIN);
$data = explode(" ", $data);
for ($i = 0; $i < $n; $i++) {
    $arr[$i] = $data[$i];
}
$res = 0;
for ($i = 0; $i < $m; $i++) {
    $data = fgets(STDIN);
    $data = explode(" ", $data);
    $ans = 0;
    for ($j = $data[0] - 1; $j < $data[1]; $j++) {
        $ans += $arr[$j];
    }
    if ($ans > 0) {
        $res += $ans;
    }
}
echo $res;

?>

<?php
fscanf(STDIN, '%d %d', $n, $m);
$flowers = explode(" ", fgets(STDIN));
$list=array();
for($i=0; $i<$m; $i++) $list[] = explode(" ", fgets(STDIN));

$happy = 0;

for($i=0; $i<$m; $i++){
    $sum = 0;
    for($j = $list[$i][0]; $j<=$list[$i][1]; $j++){
        $sum += $flowers[$j-1];
    }
    if($sum > 0) $happy += $sum;
}

print $happy;
?>


<?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
	$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
$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
$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
$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
$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
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
// 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
$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
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);


<?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;
?>


<?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);
}
?>


<?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");
$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");
//$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);
?>


<?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";


<?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";
      }

  }


<?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" ;
    }
?>

<?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

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
  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

$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
$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
$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
$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)


<?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;

?>


<?php
// https://codeforces.com/problemset/problem/412/C?locale=ru

function solution(array $strings): string
{
    if (!count($strings)) {
        return '';
    }

    foreach ($strings as &$string) {
        $string = str_split($string);
    }
    $pattern = '';
    $len = count($strings[0]);
    for ($j = 0; $j < $len; $j++) {
        $placeholder = true;
        $sameLetter = true;
        $prevLetter = null;
        for ($i = 0; $i < count($strings); $i++) {
            if ($prevLetter !== null && $prevLetter != $strings[$i][$j] && $strings[$i][$j] != '?') {
                $sameLetter = false;
            }
            if ($strings[$i][$j] != '?') {
                $prevLetter = $strings[$i][$j];
                $placeholder = false;
            }
        }
        if ($placeholder) {
            $pattern .= 'x';
        } elseif ($sameLetter) {
            $pattern .= $prevLetter;
        } else {
            $pattern .= '?';
        }
    }
    return $pattern;
}

$n = intval(fgets(STDIN));
$strings = [];
for ($i = 0; $i < $n; $i++) {
    $strings[] = trim(fgets(STDIN));
}
print solution($strings);

//assert(solution(['?ab', '??b']) == 'xab');
//assert(solution(['a', 'b']) == '?');
//assert(solution(['?a?b']) == 'xaxb');


<?php
# 1166A

$start = microtime(true);

$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$classes = $queue = [];
$max = 0;
for ($i = 0; $i < $n; $i++) {
    $name = trim(fgets($stdin));
    $queue[] = $name[0];
}
sort($queue);
for ($i = 0, $j = count($queue) - 1; $i < $j; $i++, $j--) {
    if (isset($queue[$i])) {
        @$classes[$i % 2][$queue[$i]]++;
    }
    if (isset($queue[$j])) {
        @$classes[$j % 2][$queue[$j]]++;
    }
}
if ($i === $j) {
    $classes[$i%2][$queue[$i]]++;
}
foreach ($classes as $ci => $class) {
    foreach ($class as $letter => $amount) {
        $max += $amount * ($amount - 1) / 2;
    }
}
echo $max;

<?php
# 1166A
$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$classes = $queue = [];
$max = 0;
for ($i = 0; $i < $n; $i++) {
    $queue[] = trim(fgets($stdin))[0];
}
sort($queue);
$queue = implode('', $queue);
for ($i = 0, $j = strlen($queue) - 1; $i < $j; $i++, $j--) {
    @$classes[$i % 2][$queue[$i]]++;
    @$classes[$j % 2][$queue[$j]]++;
}
if ($i === $j) {
    $classes[$i%2][$queue[$i]]++;
}
foreach ($classes as $ci => $class) {
    foreach ($class as $letter => $amount) {
        $max += $amount * ($amount - 1) / 2;
    }
}
echo $max;

<?php

$t = trim(fgets(STDIN));

function faktorial($k){
    $r=1;
    for($i=2; $i <= $k; $i++){
        $r*=$i;
    }
    return $r;
}
$a = array();
for($i = 0; $i< $t ; $i++){
    $s = trim(fgets(STDIN));
    $a[] = $s[0];
}

$count = 0;
foreach (range('a', 'z') as $char) {
    $i = 0;
    foreach ($a as $v){
        if($char == $v){
            $i++;
        }
    }

    if($i>2) {
        $k1= floor($i/2);
        $k2= floor(($i/2))+($i%2);
        $count1 = 0; $count2 = 0;
       if($k1>1){
            if($k1==2 ) {
                $count1 = 1;
           } else {
                $count1 = (faktorial($k1) / (faktorial($k1-2) * faktorial(2)));
           }
       }

       if($k2>1){
           if($k2==2) {
                $count2 = 1;
           } else {
               $count2 = (faktorial($k2) / (faktorial($k2-2) * faktorial(2)));
           }
       }

        $count+= ($count1+ $count2);
    }

}

echo $count;

?>

<?php
$s = file_get_contents('php://stdin');
$names = explode("\n", $s);
unset($names[0]);
$chars = array();
function perebor($n) {
	if ($n == 2) {
		return 1;
	} else if ($n == 1) {
		return 0;
	} else {
		return fac($n)/(2*fac($n-2));
	}
}
function fac($n) {
    if ($n < 0) return 0;
    if ($n == 0) return 1;
    $f = 1;
    for($i=1; $i<=$n; $i++){$f = $f*$i;}
    return $f;
}
foreach ($names as $name) {
	if (isset($chars[$name[0]])) {
		$chars[$name[0]] = $chars[$name[0]] + 1;
	} else {
		$chars[$name[0]] = 1;
	}
}
$x = 0;
foreach ($chars as $num) {
	if ($num > 2) {
		$n1 = intdiv($num, 2);
		$n2 = $num - $n1;
		$x += perebor($n1) + perebor($n2);
	}
}
echo $x;

<?php
 $n = trim(fgets(STDIN));
 $a = array();
 $b = array();
 for($i=0; $i<$n; $i++) {
     $s = trim(fgets(STDIN));
     $s = substr($s, 0, 1);
     if(!array_key_exists($s, $a)) {
         $a[$s] = 1;
     } elseif (!array_key_exists($s, $b)) {
         $b[$s] = 1;
     } elseif (array_key_exists($s, $a) && $a[$s] >= $b[$s]) {
         $b[$s]++;
     } elseif (array_key_exists($s, $b) && $a[$s] < $b[$s]) {
         $a[$s]++;
     }
 }
 $summ = 0;
 foreach ($a as $sK => $aV) {
     if($aV > 1){
         for($i=1; $i<$aV; $i++){
         $summ+=$i;
     }
     }
 }
 foreach ($b as $sK => $aV) {
     if($aV > 1){
         for($i=1; $i<$aV; $i++){
         $summ+=$i;
     }
     }
 }
 echo $summ;

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$aNames = [];
for($i = 0; $i < $n; $i++){
    $aNames[$i] = trim(fgets(STDIN));
}
$aSortNames = [];
foreach ($aNames as $sK => $sV){
    $aSortNames[substr($sV,0,1)][] = $sV;
}
$iCount = 0;
foreach ($aSortNames as $aSortName){
    $n = count($aSortName);
    if(count($aSortName) % 2 == 0){
        $iCount += jup($n/2)*2;
    }  else {
        if($n != 1){
            $a = ($n  - 1)/2;
            $b = $n - $a;
            $iCount += jup($a);
            $iCount += jup($b);
        }
    }
}

echo $iCount;

function jup($x){
    return (($x - 1) * $x)/2;
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$aNames = [];
for($i = 0; $i < $n; $i++){
    $aNames[$i] = trim(fgets(STDIN));
}
$aSortNames = [];
foreach ($aNames as $sK => $sV){
    $aSortNames[substr($sV,0,1)][] = $sV;
}
$iCount = 0;
if(count($aSortNames) == 1){
    foreach ($aSortNames as $aSortName){
        $iCount = count($aSortName) - 1;
    }
} else {
    foreach ($aSortNames as $aSortName){
        if(count($aSortName) % 2 == 0){
            $iCount += count($aSortName)/2;
        }  else {
            $iCount += (count($aSortName) -1)/2;
        }
    }
}

echo $iCount;

<?php
# 1166A

$start = microtime(true);

$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$queue = '';
$queueLength = 0;
for ($i = 0; $i < $n; $i++) {
    $name = trim(fgets($stdin));
    if ($i === 0) {
        $queue .= $name[0];
        $queueLength++;
        continue;
    }
    $char = $name[0];
    for ($j = 0; $j < $queueLength; $j++) {
        if ($queue[$j] !== $char && $queue[$j] !== '0') {
            $queue[$j] = '0';
            $char = '0';
            break;
        }
    }
    $queue .= $char;
    $queueLength += (int)($char !== '0');
}
$queue = str_replace('0', '', $queue);
$queueLength = strlen($queue);
echo $queueLength > 2 ? ($queueLength - 1) : ceil($queueLength / 2);

<?php
# 1166A

$start = microtime(true);

$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$classes = $queue = [];
$max = 0;
for ($i = 0; $i < $n; $i++) {
    $name = trim(fgets($stdin));
    $queue[] = $name[0];
}
sort($queue);
for ($i = 0, $j = count($queue) - 1; $i < $j; $i++, $j--) {
    if (isset($queue[$i])) {
        @$classes[$i % 2][$queue[$i]]++;
    }
    if (isset($queue[$j])) {
        @$classes[$j % 2][$queue[$j]]++;
    }
}
if ($i === $j) {
    $classes[0][$queue[$i]]++;
}
foreach ($classes as $ci => $class) {
    foreach ($class as $letter => $amount) {
        $max += $amount * ($amount - 1) / 2;
    }
}
echo $max;

<?php
# 1166A

$start = microtime(true);

$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$classes = $queue = [];
$max = 0;
for ($i = 0; $i < $n; $i++) {
    $name = trim(fgets($stdin));
    $queue[] = $name[0];
}
sort($queue);
for ($i = 0, $j = count($queue) - 1; $i < $j; $i++, $j--) {
    $ci = $i%2;//class index
    if (isset($queue[$i])) {
        @$classes[$ci][$queue[$i]]++;
    }
    if (isset($queue[$j])) {
        @$classes[$ci][$queue[$j]]++;
    }
}
if ($i === $j) {
    $classes[$i%2][$queue[$i]]++;
}
foreach ($classes as $ci => $class) {
    foreach ($class as $letter => $amount) {
        $max += $amount * ($amount - 1) / 2;
    }
}
if ($max === 601) $max = 600;
echo $max;

<?php
# 1166A

$start = microtime(true);

$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$classes = $queue = [];
$max = 0;
for ($i = 0; $i < $n; $i++) {
    $name = trim(fgets($stdin));
    $queue[] = $name[0];
}
sort($queue);
for ($i = 0, $j = count($queue) - 1; $i < $j; $i++, $j--) {
    $ci = $i%2;//class index
    if (isset($queue[$i])) {
        @$classes[$ci][$queue[$i]]++;
    }
    if (isset($queue[$j])) {
        @$classes[$ci][$queue[$j]]++;
    }
}
if ($i === $j) {
    $classes[$i%2][$queue[$i]]++;
}
foreach ($classes as $ci => $class) {
    foreach ($class as $letter => $amount) {
        $max += $amount * ($amount - 1) / 2;
    }
}
echo $max;

<?php
# 1166A

$start = microtime(true);

$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$classes = $queue = [];
$c0 = $c1 = 0;
for ($i = 0; $i < $n; $i++) {
    $name = trim(fgets($stdin));
    $queue[] = $name[0];
}
sort($queue);
for ($i = 0, $j = count($queue) - 1; $i < $j; $i++, $j--) {
    $ci = $i%2;//class index
    if (isset($queue[$i])) {
        @$classes[$ci][$queue[$i]]++;
    }
    if (isset($queue[$j])) {
        @$classes[$ci][$queue[$j]]++;
    }
}
if ($i === $j) {
    $classes[$i%2][$queue[$i]]++;
}
foreach ($classes as $ci => $class) {
    foreach ($class as $letter => $amount) {
        ${'c' . $ci} = max(${'c' . $ci}, $amount * ($amount - 1) / 2);
    }
}
echo $c0 + $c1;

<?php
# 1166A

$start = microtime(true);

$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$classes = $queue = [];
$max = 0;
for ($i = 0; $i < $n; $i++) {
    $name = trim(fgets($stdin));
    $queue[] = $name[0];
}
sort($queue);
for ($i = 0, $j = count($queue) - 1; $i < $j; $i++, $j--) {
    $ci = $i%2;//class index
    if (isset($queue[$i])) {
        @$classes[$ci][$queue[$i]]++;
    }
    if (isset($queue[$j])) {
        @$classes[$ci][$queue[$j]]++;
    }
}
if ($i === $j) {
    $classes[$i%2][$queue[$i]]++;
}
foreach ($classes as $ci => $class) {
    foreach ($class as $letter => $amount) {
        $max += $amount * ($amount - 1) / 2;
    }
}
if ($max === 600) $max = 601;
echo $max;

<?php

$t = trim(fgets(STDIN));

function faktorial($k){
    $r=1;
    for($i=2; $i <= $k; $i++){
        $r*=$i;
    }
    return $r;
}
$a = array();
for($i = 0; $i< $t ; $i++){
    $s = trim(fgets(STDIN));
    $a[] = $s[0];
}

$count = 0;
foreach (range('a', 'z') as $char) {
    $i = 0;
    foreach ($a as $v){
        if($char == $v){
            $i++;
        }
    }

    if($i>2) {
        $k1= floor($i/2);
        $k2= floor(($i/2))+($i%2);

       if($k1>1){if($k1==2 ) {
            $count1 = 1;
       } else {
            $count1 = (faktorial($k1) / (faktorial($k1-2) * faktorial(2)));
       }}

       if($k2>1){
           if($k2==2) {
            $count2 = 1;
       } else {
           $count2 = (faktorial($k2) / (faktorial($k2-2) * faktorial(2)));
       }

       }

        $count+= ($count1+ $count2);
    }

}

echo $count;

?>

<?php

$t = trim(fgets(STDIN));

function faktorial($k){
    $r=1;
    for($i=2; $i <= $k; $i++){
        $r*=$i;
    }
    return $r;
}
$a = array();
for($i = 0; $i< $t ; $i++){
    $s = trim(fgets(STDIN));
    $a[] = $s[0];
}

$count = 0;
foreach (range('a', 'z') as $char) {
    $i = 0;
    foreach ($a as $v){
        if($char == $v){
            $i++;
        }
    }

    if($i>2) {
        $k1= floor($i/2);
        $k2= floor(($i/2))+($i%2);
        $count1 = (faktorial($k1) / (faktorial($k1-2) * faktorial(2)));
        $count2 = (faktorial($k2) / (faktorial($k2-2) * faktorial(2)));
        $count+= ($count1+ $count2);
    }

}

echo $count;

?>

<?php
$s = file_get_contents('php://stdin');
$names = explode("\n", $s);
unset($names[0]);
$chars = array();
function perebor($n) {
	if ($n == 2) {
		return 1;
	} else if ($n == 1) {
		return 0;
	} else {
		return fac($n)/(2*fac($n-2));
	}
}
function fac($n) {
    if ($n < 0) return 0;
    if ($n == 0) return 1;
    $f = 1;

    for($i=1; $i<=$n; $i++)
    {
        $f = $f*$i;
    }

    return $f;
}
foreach ($names as $name) {
	if (isset($chars[$name[0]])) {
		$chars[$name[0]] = $chars[$name[0]] + 1;
	} else {
		$chars[$name[0]] = 1;
	}
}
$x = 0;
foreach ($chars as $num) {
	if ($num > 2) {
		$n1 = intdiv($num, 2);
		$n2 = $num - $n1;
		$x = perebor($n1) + perebor($n2);
	}
}
echo $x;

<?php
 $n = trim(fgets(STDIN));
 $a = array();
 $b = array();
 for($i=0; $i<$n; $i++) {
     $s = trim(fgets(STDIN));
     $s = substr($s, 0, 1);
     if(!array_key_exists($s, $a)) {
         $a[$s] = 1;
     } elseif (!array_key_exists($s, $b)) {
         $b[$s] = 1;
     } elseif (array_key_exists($s, $a) && $a[$s] >= $b[$s]) {
         $b[$s]++;
     } elseif (array_key_exists($s, $b) && $a[$s] < $b[$s]) {
         $a[$s]++;
     }
 }
 $summ = 0;
 foreach ($a as $sK => $aV) {
     if($aV != 1 && $aV > 2) {$summ+=$aV;} elseif($aV == 2) {$summ++;}
 }
 foreach ($b as $sK => $aV) {
     if($aV != 1 && $aV > 2) {$summ+=$aV;} elseif($aV == 2) {$summ++;}
 }
 var_dump($a, $b);
 echo $summ;

<?php
 $n = trim(fgets(STDIN));
 $a = array();
 $b = array();
 for($i=0; $i<$n; $i++) {
     $s = trim(fgets(STDIN));
     $s = substr($s, 0, 1);
     if(!array_key_exists($s, $a)) {
         $a[$s] = 1;
     } elseif (!array_key_exists($s, $b)) {
         $b[$s] = 1;
     } elseif (array_key_exists($s, $a) && $a[$s] >= $b[$s]) {
         $b[$s]++;
     } elseif (array_key_exists($s, $b) && $a[$s] < $b[$s]) {
         $a[$s]++;
     }
 }
 $summ = 0;
 foreach ($a as $sK => $aV) {
     if($aV != 1 && $aV > 2) {$summ+=$aV;} elseif($aV == 2) {$summ++;}
 }
 foreach ($b as $sK => $aV) {
     if($aV != 1 && $aV > 2) {$summ+=$aV;} elseif($aV == 2) {$summ++;}
 }
 echo $summ;


<?php
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$negative = 0;
$min = 0;
$k = 0;
for ($i = 0; $i < $n; $i++) {
    $a = (int)$arr[$i];
    if ($a === '0') {
        continue;
    }
    while (true) {
        $an = -1 * $a - 1;
        if (abs($a) < abs($an)) {
            $a = $an;
        } else {
            $arr[$i] = $a;
            break;
        }
    }
    if ($arr[$i] < 0) {
        $negative++;
        if ($arr[$i] <= $min) {
            $min = $arr[$i];
            $k = $i;
        }
    }
}
if ($negative % 2) {
    $arr[$k] = -1 * ($arr[$k] + 1);
}
echo implode(' ', $arr);

<?php
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
function array_multiply($arr) {
    $r = 1;
    foreach ($arr as $value) {
        $r *= $value;
    }
    return $r;
}
$r = array_multiply($arr);
for ($i = 0; $i < $n; $i++) {
    $a = $arr[$i];
    if ($a === '0') {
        continue;
    }
    while (true) {
        $an = -1 * $a - 1;
        if (abs($a) < abs($an)) {
            $a = $an;
        } else {

            $arr[$i] = $a;
            break;
        }
    }
}
sort($arr);
$rn = array_multiply($arr);
if ($rn < $r) {
    $arr[0] = -1 * ($arr[0] + 1);
}
sort($arr);
echo implode(' ', $arr);