In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills. Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration. Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life. As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where [y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0. Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible. You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be?

The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 20, 0.01 ≤ k ≤ 0.99). Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive.  Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates.  All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names.

Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order.

5 4 0.75
axe 350
impaler 300
ionize 80
megafire 120
magicboost 220
heal
megafire
shield
magicboost

6
axe 262
heal 0
impaler 225
magicboost 165
megafire 0
shield 0

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

$skills = [];

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

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

    $expK = bcmul($exp, $k, 2);

    if (bccomp($expK, '100.00', 2) > -1) {
        $skills[$name] = bcadd($expK, '0.00', 0);
    }
}

for ($i = 0; $i < $m; $i++) {
    $name = trim(fgets($input));

    $skills[$name] = $skills[$name] ?? '0';
}

fwrite($output, count($skills) . PHP_EOL);

ksort($skills);

foreach ($skills as $skill => $value) {
    fwrite($output, $skill . ' ' . $value . PHP_EOL);
}

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

$skills = [];

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

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

    $expK = $exp * $k;

    if ($expK >= 100) {
        $skills[$name] = (int)$expK;
    }
}

for ($i = 0; $i < $m; $i++) {
    $name = trim(fgets($input));

    $skills[$name] = $skills[$name] ?? 0;
}

fwrite($output, count($skills) . PHP_EOL);

ksort($skills);

foreach ($skills as $skill => $value) {
    fwrite($output, $skill . ' ' . $value . PHP_EOL);
}

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

$skills = [];

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

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

    $expK = $exp * $k;

    if ($expK > 100) {
        $skills[$name] = (int)$expK;
    }
}

for ($i = 0; $i < $m; $i++) {
    $name = trim(fgets($input));

    $skills[$name] = $skills[$name] ?? 0;
}

fwrite($output, count($skills) . PHP_EOL);

ksort($skills);

foreach ($skills as $skill => $value) {
    fwrite($output, $skill . ' ' . $value . PHP_EOL);
}

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

$skills = [];

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

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

    $expK = bcmul($exp, $k, 2);

    if (bccomp($expK, '100.00', 2) === 1) {
        $skills[$name] = bcadd($expK, '0.00', 0);
    }
}

for ($i = 0; $i < $m; $i++) {
    $name = trim(fgets($input));

    $skills[$name] = $skills[$name] ?? '0';
}

fwrite($output, count($skills) . PHP_EOL);

ksort($skills);

foreach ($skills as $skill => $value) {
    fwrite($output, $skill . ' ' . $value . PHP_EOL);
}


Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number.One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment.Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so.Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted — that is, one call connects exactly two people.

The first line contains integer n (1 ≤ n ≤ 103) — the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: id1, id2, ..., idn (0 ≤ idi ≤ 109). Number idi equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to n in some way.

Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.

NoteIn the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.In the second test sample the described situation is impossible as conferences aren't allowed.

<?php
$num = trim(fgets(STDIN));
$arr = explode(' ', fgets(STDIN));
foreach($arr as $k=>$v){
 $arr[$k] = trim($v);
}
function my_find($a){
 $result = 0;
 $t_a = Array();
 foreach($a as $v){
  if($v == 0)
   continue;
  $t_a[$v] += 1;
  if($t_a[$v] == 2){
   $result+=1;
  }elseif($t_a[$v] > 2){
   return -1;
  }
 }
 return $result;
}

if($num == 1){
 echo '0';
}elseif($num != count($arr)){
 echo '-1';
}else{
 echo my_find($arr);
}
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
//$num_sec = 3;
//$num_talk_array = array("1", "1", "1");
$result = 0;
for ($i = 0; $i < $num_sec - 1; $i++) {
    $c = 0;
    for ($j = $i + 1; $j < $num_sec; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j] && $num_talk_array[$i] <> 0) {
            $c++;
            //echo "

\$i = " . $i . "
\$j = " . $j .
                //"
\$num_talk_array[\$i] = " . $num_talk_array[$i] . " -- \$num_talk_array[\$j] = " . $num_talk_array[$j] .
                //"
\$result = ";
        }
    }
    if ($c > 1) {
        $result = -1;
        echo $result;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?
error_reporting(false);
$handle = fopen('php://stdin', 'r');
$c = 0;
$num = (int)(trim(fgets($handle))*1 / 2);
$arr = explode(" ", trim(fgets($handle)));
$t = array();
foreach($arr as $val) {
    if ($val != 0) $t[$val]++;
}
$c = 0;
foreach($t as $k=>$id) {
    if ($id > 2 ) die("-1");
    if ($id == 2) $c++;
}
echo $c;
?>

<?php $fh = fopen('php://stdin','r') or die($php_errormsg);
$s = fgets($fh, 1500);
$s = substr($s, 0, -1);
$r = trim(fgets($fh, 1000000));
$r = explode(" ", $r);
$flag = true;
if (count($r)!=$s) $flag = false;
$r = array_slice($r, 0, $s);

$r = array_count_values($r);
$counter = 0;

if ($s<1) $flag = false;

foreach ($r as $item => $key)
{
if (!is_numeric($item)) $flag = false;

if ($item<>0) {
    if ($key == 2) $counter += 1;
    if ($key > 2) $flag = false;
}

}

if ($flag) echo $counter; else echo "-1";

?>

<?php

$fIn = fopen('php://stdin', 'r');
$n = intval(fgets($fIn));
$str = explode(' ', fgets($fIn));
fclose($fIn);
$res = 0;
$a = array();
for ($i = 0; $i < $n; ++$i) {
    $num = intval($str[$i]);
    if ($num == 0)
        continue;
    if (isset($a[$num])) {
        $a[$num]++;
    } else {
        $a[$num] = 1;
    }
    if ($a[$num] == 2) {
        $res++;
    } else if ($a[$num] > 2) {
        $res = -1;
        break;
    }
}

echo $res, PHP_EOL;
?>

<?php
$f = fopen("php://stdin", "r");
$n = trim(fgets($f));
$text = trim(fgets($f));
fclose($f);
//$n = 6;
//$text = "0";
$list = explode(" ", $text);
$list = array_map('intval', $list);
sort($list);
$prev = -1;
$count = 0;
$result = 0;
foreach ($list as $val) {
    if (!$val)
        continue;
    if ($val === $prev)
        $count++;
    else
        $count = 1;

    $prev = $val;

    if ($count == 2)
        $result++;
    elseif ($count > 2)
        die("-1");

}

echo $result;

<?php

$sec_num = trim(fgets(STDIN))-1;
$sessions = trim(fgets(STDIN));

$sess = split(' ', $sessions);
$ses_num = count($sess);

$i=0;
$nope=0;
$pairs=0;
while ($i<$ses_num) {
	if ($sess[$i]>0) {
		$sessi[$sess[$i]]++;
		if ($sessi[$sess[$i]]==2) { $pairs++; } else if ($sessi[$sess[$i]]>2) { $pairs=-1; $i=$sec_num+10; }
	} else {
		$nope++;
	}
	$i++;
}

fwrite(STDOUT, "$pairs\n" );

?>

<?

error_reporting(false);
//error_reporting(E_ALL);

$handle = fopen('php://stdin', 'r');
//$handle = fopen('in.txt', 'r');

$c = 0;

$num = (int)(trim(fgets($handle))*1 / 2);

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

$t = array();

foreach($arr as $val) {
    if ($val != 0) $t[$val]++;
}

$c = 0;
foreach($t as $k=>$id) {

    if ($id > 2 ) die("-1");
    if ($id == 2) $c++;
}

echo $c;

?>

<?php

$n = intval(line());
$a = explode(' ', line());

$count = array();

for ($i = 0; $i < $n; $i ++) {
  if (isset($count[$a[$i]])) {
    $count[$a[$i]] ++;
  } else {
    $count[$a[$i]] = 1;
  }
}

$answer = 0;

foreach ($count as $index => $value) {
  if ($index == 0) {
    continue;
  } elseif ($value > 2) {
    $answer = -1;
    break;
  }
  $answer += ($value == 2);
}

print $answer;

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

<?php
# Строка со входящими данными
$num = trim(fgets(STDIN));
$ids = explode(' ',trim(fgets(STDIN)));

# Проверка условий
if(count($ids) == $num){
	# Вычисление количества повторяющихся значений (идентификаторов)
	$acv = array_count_values($ids);
	if(isset($acv[0]))unset($acv[0]);
	# Сортировка по значениям
	asort($acv);
	# Переход на последний элемент
	end($acv);
	# Значение последнего элемента не должно быть больше двух, если это не нулевой идентификатор
	if(current($acv) > 2 && key($acv) != 0){
		$OUT = -1;
	}else{
		# Вычисление количества типов соединений
		$acv = array_count_values($acv);
		# Возможно есть секретари, ведущие разговор между собой
		if(isset($acv[2])){
			$OUT = $acv[2];
		}else{
			$OUT = 0;
		}
	}
}else{
	$OUT = -1;
}

print $OUT;
?>

<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;
$n = $arr[0];
$exp = explode(' ', $arr[1]);
$aVal = array();
foreach($exp AS $value){
    if($value == 0)
        continue;
    $aVal[$value] += 1;
}
$count = 0;
foreach($aVal AS $value){
    if($value == 2){
        $count++;
    }
    if($value > 2){
        echo -1;
        exit;
    }
}
echo $count;

<?php
$num = trim(fgets(STDIN));
$arr = explode(' ', fgets(STDIN));

function my_find($a){
 $result = 0;
 $t_a = Array();
 foreach($a as $v){
  if($v == 0)
   continue;
  $t_a[$v] += 1;
  if($t_a[$v] == 2){
   $result+=1;
  }elseif($t_a[$v] > 2){
   return -1;
  }
 }
 return $result;
}

if($num == 1){
 echo '0';
}else{
 echo my_find($arr);
}
?>

<?php
$num = trim(fgets(STDIN));
$arr = explode(' ', fgets(STDIN));

function my_find($a){
 $result = 0;
 $t_a = Array();
 foreach($a as $v){
  $t_a[$v] += 1;
  if($t_a[$v] == 2){
   $result+=1;
  }elseif($t_a[$v] > 2){
   return -1;
  }
 }
 return $result;
}
if($num == 1){
 echo '0';
}else{
 echo my_find($arr);
}
?>

<?php
$num = trim(fgets(STDIN));
$arr = explode(' ', fgets(STDIN));

function my_find($a){
 $result = 0;
 $t_a = Array();
 foreach($a as $v){
  if($v == 0)
   continue;
  $t_a[$v] += 1;
  if($t_a[$v] == 2){
   $result+=1;
  }elseif($t_a[$v] > 2){
   return -1;
  }
 }
 return $result;
}

if($num == 1){
 echo '0';
}elseif($num != count($arr)){
 echo '-1';
}else{
 echo my_find($arr);
}
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
//$num_sec = 3;
//$num_talk_array = array("1", "1", "1");
//$result = 0;
for ($i = 0; $i < $num_sec - 1; $i++) {
    $c = 0;
    for ($j = $i + 1; $j < $num_sec; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
            //echo "

\$i = " . $i . "
\$j = " . $j .
                //"
\$num_talk_array[\$i] = " . $num_talk_array[$i] . " -- \$num_talk_array[\$j] = " . $num_talk_array[$j] .
                //"
\$result = ";
        }
    }
    if ($c > 1) {
        $result = -1;
        echo $result;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
//$num_sec = 3;
//$num_talk_array = array("1", "1", "1");
$result = 0;
for ($i = 0; $i < $num_sec - 1; $i++) {
    $c = 0;
    for ($j = $i + 1; $j < $num_sec; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j] and $num_talk_array[i] != 0 and $num_talk_array[$j] != 0) {
            $c++;
            //echo "

\$i = " . $i . "
\$j = " . $j .
                //"
\$num_talk_array[\$i] = " . $num_talk_array[$i] . " -- \$num_talk_array[\$j] = " . $num_talk_array[$j] .
                //"
\$result = ";
        }
    }
    if ($c > 1) {
        $result = -1;
        echo $result;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
$result = 0;
$c = 0;
for ($i = 0; $i < $num_sec; $i++) {
    for ($j = $i + 1; $j < $num_sec - 1; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
        }
    }
    if ($c > 1) {
        $result = -1;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $num_sec;
?>

<?php
$num_sec = fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
$result = 0;
$c = 0;
/*for ($i = 0; $i < $num_sec; $i++) {
    for ($j = $i + 1; $j < $num_sec - 1; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
        }
    }
    if ($c > 1) {
        $result = -1;
        exit;
    } else {
        $result = $result + $c;
    }
}*/
echo $num_sec;
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
//$num_sec = 3;
//$num_talk_array = array("1", "1", "1");
$result = 0;
for ($i = 0; $i < $num_sec - 1; $i++) {
    $c = 0;
    for ($j = $i + 1; $j < $num_sec; $j++) {
        if (($num_talk_array[$i] == $num_talk_array[$j]) != "0") {
            $c++;
            //echo "

\$i = " . $i . "
\$j = " . $j .
                //"
\$num_talk_array[\$i] = " . $num_talk_array[$i] . " -- \$num_talk_array[\$j] = " . $num_talk_array[$j] .
                //"
\$result = ";
        }
    }
    if ($c > 1) {
        $result = -1;
        echo $result;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?php
$num_sec = fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
$result = 0;
$c = 0;
for ($i = 0; $i < $num_sec; $i++) {
    for ($j = $i + 1; $j < $num_sec - 1; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
        }
    }
    if ($c > 1) {
        $result = -1;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $num_sec;
?>

<?php
$num_sec = fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
$result = 0;
//$c = 0;
for ($i = 0; $i < $num_sec; $i++) {
    for ($j = $i + 1; $j < $num_sec - 1; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
        }
    }
    if ($c > 1) {
        $result = -1;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $num_sec;
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
//$num_sec = 3;
//$num_talk_array = array("1", "1", "1");
$result = 0;
for ($i = 0; $i < $num_sec - 1; $i++) {
    $c = 0;
    for ($j = $i + 1; $j < $num_sec; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j] and $num_talk_array[i] != 0) {
            $c++;
            //echo "

\$i = " . $i . "
\$j = " . $j .
                //"
\$num_talk_array[\$i] = " . $num_talk_array[$i] . " -- \$num_talk_array[\$j] = " . $num_talk_array[$j] .
                //"
\$result = ";
        }
    }
    if ($c > 1) {
        $result = -1;
        echo $result;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?php
$num_sec = fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
$result = 0;
$c = 0;
$end = $num_sec - 1;
for ($i = 0; $i < $num_sec; $i++) {
    for ($j = $i + 1; $j < $end; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
        }
    }
    if ($c > 1) {
        $result = -1;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $num_sec;
?>

<?php
$num_sec = fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
$result = 0;
$c = 0;
for ($i = 0; $i < $num_sec; $i++) {
    for ($j = $i + 1; $j < $num_sec - 1; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
        }
    }
    if ($c > 1) {
        $result = -1;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
//$num_sec = 6;
//$num_talk_array = array("0", "1", "7", "1", "7", "10");
$result = 0;
for ($i = 0; $i < $num_sec; $i++) {
    $c = 0;
    for ($j = $i + 1; $j < $num_sec - 1; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
        }
    }
    if ($c > 1) {
        $result = -1;
        echo $result;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
//$num_sec = 3;
//$num_talk_array = array("1", "1", "1");
$result = 0;
for ($i = 0; $i < $num_sec - 1; $i++) {
    $c = 0;
    for ($j = $i + 1; $j < $num_sec; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
            //echo "

\$i = " . $i . "
\$j = " . $j .
                //"
\$num_talk_array[\$i] = " . $num_talk_array[$i] . " -- \$num_talk_array[\$j] = " . $num_talk_array[$j] .
                //"
\$result = ";
        }
    }
    if ($c > 1) {
        $result = -1;
        echo $result;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
//$num_sec = 6;
//$num_talk_array = array("0", "1", "7", "1", "7", "10");
$result = 0;
for ($i = 0; $i < $num_sec; $i++) {
    $c = 0;
    for ($j = $i + 1; $j < $num_sec - 1; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
        }
    }
    if ($c > 1) {
        $result = -1;
        break;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
//$num_sec = 6;
//$num_talk_array = array("0", "1", "7", "1", "7", "10");
$result = 0;
for ($i = 0; $i < $num_sec; $i++) {
    $c = 0;
    for ($j = $i + 1; $j < $num_sec - 1; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
        }
    }
    if ($c > 1) {
        $result = -1;
        break 1;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
//$num_sec = 3;
//$num_talk_array = array("1", "1", "1");
$result = 0;
for ($i = 0; $i < $num_sec - 1; $i++) {
    $c = 0;
    for ($j = $i + 1; $j < $num_sec; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j] && $num_talk_array[i] <> 0) {
            $c++;
            //echo "

\$i = " . $i . "
\$j = " . $j .
                //"
\$num_talk_array[\$i] = " . $num_talk_array[$i] . " -- \$num_talk_array[\$j] = " . $num_talk_array[$j] .
                //"
\$result = ";
        }
    }
    if ($c > 1) {
        $result = -1;
        echo $result;
        exit;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?php
$num_sec = (int)fgets(STDIN);
$num_talk = trim(fgets(STDIN));
$num_talk_array = explode(" ", $num_talk);
//$num_sec = 6;
//$num_talk_array = array("0", "1", "7", "1", "7", "10");
$result = 0;
for ($i = 0; $i < $num_sec; $i++) {
    $c = 0;
    for ($j = $i + 1; $j < $num_sec - 1; $j++) {
        if ($num_talk_array[$i] == $num_talk_array[$j]) {
            $c++;
        }
    }
    if ($c > 1) {
        $result = -1;
        break 3;
    } else {
        $result = $result + $c;
    }
}
echo $result;
?>

<?
$c = 0;
$num = (int)(trim(fgets($handle))*1 / 2);
$arr = explode(" ", trim(fgets($handle)));
$t = array();
foreach($arr as $val) {
if ($val != 0) $t[$val]++;
}
$c = 0;
foreach($t as $k=>$id) {
if ($id > 2 ) die("-1");
if ($id == 2) $c++;
}
echo $c;
?>

<?php $fh = fopen('php://stdin','r') or die($php_errormsg);
$s = fgets($fh, 1000);
$s = substr($s, 0, -1);
$r = fgets($fh, 100000);
$r = explode(" ", $r);
$r = array_slice($r, 0, $s);
$r = array_count_values($r);
$counter = 0;
$flag = true;
foreach ($r as $item => $key)
{
if ($key == 2) $counter += 1;
if ($key > 2) $flag = false;
}

if ($flag) echo $counter; else echo "-1";

?>

<?php $fh = fopen('php://stdin','r') or die($php_errormsg);
$s = fgets($fh, 1500);
$s = substr($s, 0, -1);
$r = fgets($fh, 1000000);
$r = explode(" ", $r);
$r = array_slice($r, 0, $s);
$r = array_count_values($r);
$counter = 0;
$flag = true;
foreach ($r as $item => $key)
{

if ($item<>0) {
    if ($key == 2) $counter += 1;
    if ($key > 2) $flag = false;
}

}

if ($flag) echo $counter; else echo "-1";

?>

<?php

$fIn = fopen('input.txt', 'r');
$n = intval(fgets($fIn));
$str = explode(' ', fgets($fIn));
fclose($fIn);
$res = 0;
$a = array();
for ($i = 0; $i < $n; ++$i) {
    $num = intval($str[$i]);
    if ($num == 0)
        continue;
    if (isset($a[$num])) {
        $a[$num]++;
    } else {
        $a[$num] = 1;
    }
    if ($a[$num] == 2) {
        $res++;
    } else if ($a[$num] > 2) {
        $res = -1;
        break;
    }
}

echo $res, PHP_EOL;
?>

<?php

$fIn = fopen('php://stdin', 'r');
$n = intval(fgets($fIn));
$str = explode(' ', fgets($fIn));
fclose($fIn);
$res = 0;
$a = array();
for ($i = 0; $i < $n; ++$i) {
    $num = intval($str[$i]);
    if (isset($a[$num])) {
        $a[$num]++;
    }
    else
        $a[$num] = 1;
    if ($a[$num] == 2) {
        $res++;
    } else if ($a[$num] > 2) {
        $res = -1;
        break;
    }
}

echo $res, PHP_EOL;
?>

<?php
$f = fopen("php://stdin", "r");
$n = trim(fgets($f));
$text = trim(fgets($f));
fclose($f);
//$n = 1;
//$text = "0";
$list = explode(" ", $text);
sort($list);
$prev = -1;
$count = 0;
$result = 0;
foreach ($list as $val) {
	if ($val == $prev)
		$count++;
	else {
		if ($count == 2)
			$result++;
		elseif ($count > 2)
			die("-1");
		$count = 1;
		$prev = $val;
	}
}

if ($count == 2)
	$result++;
elseif ($count > 2)
	die("-1");
echo $result;

<?php

$sec_num = trim(fgets(STDIN))-1;
$sessions = trim(fgets(STDIN));

$sess = split(' ', $sessions);

$i=0;
$nope=0;
$pairs=0;
while ($i<$sec_num) {
	if ($sess[$i]>0) {
		$sessi[$sess[$i]]++;
		if ($sessi[$sess[$i]]==2) { $pairs++; } else if ($sessi[$sess[$i]]>2) { $i=$sec_num+10; }
	} else {
		$nope++;
	}
	$i++;
}

fwrite(STDOUT, "$pairs\n" );

?>

<?

$handle = fopen('php://stdin', 'r');
//$handle = fopen('in.txt', 'r');

$c = 0;

$num = (int)(trim(fgets($handle))*1 / 2);

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

$t = array();

foreach($arr as $val) {
    if ($val == 0) continue;
    $t[$val]++;
}

$c = 0;
foreach($t as $k=>$id) {

    if ($id > 2 ) die("-1");
    if ($id == 2) $c++;
}

?>

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

$c = 0;

$num = (int)(trim(fgets($handle))*1 / 2);

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

$t = array();

foreach($arr as $val) {
    $t[$val]++;
}

$c = 0;
foreach($t as $id) {
    if ($id > 2 ) die("-1");
    if ($id == 2) $c++;
}

echo $c;
?>

<?php

$n = intval(line());
$a = explode(' ', line());

$count = array();

for ($i = 0; $i < $n; $i ++) {
  if (isset($count[$a[$i]])) {
    $count[$a[$i]] ++;
  } else {
    $count[$a[$i]] = 1;
  }
}

$answer = 0;

foreach ($count as $cnt) {
  if ($cnt > 2) {
    $answer = -1;
    break;
  }
  $answer += ($cnt == 2);
}

print $answer;

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

<?php
# Открытие стандартного ввода
//$stdin = fopen('php://stdin','r');
$stdin = fopen(STDIN);

# Строка со входящими данными
$IN = '';
# Строка с исходящими данными
$OUT = 0;

# Считывание данных
//while(!feof($stdin))$IN .= fgets($stdin);
$IN = trim(fgets($stdin));

# Условие 1: Строгое соответствие шаблону
$cond1 = preg_match("/^(\d+?)\r\n([\d ]+?)$/s",$IN,$IN);
# Ра
$IN[2] = preg_split("/ /",$IN[2],-1,PREG_SPLIT_NO_EMPTY);
# Условие 2: Число секретарей
$cond2 = ($IN[1] >= 1 && $IN[1] <= 1000);
# Условие 3: Количество идентификаторов должно соответствовать числу секретарей
$cond3 = (count($IN[2]) == $IN[1]);
# Проверка условий
if($cond1 && $cond2 && $cond3){
	# Вычисление количества повторяющихся значений (идентификаторов)
	$acv = array_count_values($IN[2]);
	# Сортировка по значениям
	asort($acv);
	# Переход на последний элемент
	end($acv);
	# Значение последнего элемента не должно быть больше двух, если это не нулевой идентификатор
	if(current($acv) > 2 && key($acv) != 0){
		$OUT = -1;
	}else{
		# Вычисление количества типов соединений
		$acv = array_count_values($acv);
		# Возможно есть секретари, ведущие разговор между собой
		if(isset($acv[2])){
			$OUT = $acv[2];
		}else{
			$OUT = 0;
		}
	}
}else{
	$OUT = -1;
}

# Открытие стандартного вывода
//$stdout = fopen('php://stdout','w');
$stdout = fopen(STDOUT);
# Запись данных
fwrite($stdout,$OUT);
?>

<?php
# Строка со входящими данными
$num = trim(fgets(STDIN));
$ids = explode(' ',trim(fgets(STDIN)));

# Проверка условий
if(count($ids) == $num){
	# Вычисление количества повторяющихся значений (идентификаторов)
	$acv = array_count_values($ids);
	# Сортировка по значениям
	asort($acv);
	# Переход на последний элемент
	end($acv);
	# Значение последнего элемента не должно быть больше двух, если это не нулевой идентификатор
	if(current($acv) > 2 && key($acv) != 0){
		$OUT = -1;
	}else{
		# Вычисление количества типов соединений
		$acv = array_count_values($acv);
		# Возможно есть секретари, ведущие разговор между собой
		if(isset($acv[2])){
			$OUT = $acv[2];
		}else{
			$OUT = 0;
		}
	}
}else{
	$OUT = -1;
}

print $OUT;
?>

<?php

?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>

    </body>
</html>

<?php
# Открытие стандартного ввода
//$stdin = fopen('php://stdin','r');

# Строка со входящими данными
$IN = STDIN;
# Строка с исходящими данными
$OUT = 0;

# Считывание данных
//while(!feof($stdin))$IN .= fgets($stdin);

# Условие 1: Строгое соответствие шаблону
$cond1 = preg_match("/^(\d+?)\r\n([\d ]+?)$/s",$IN,$IN);
# Ра
$IN[2] = preg_split("/ /",$IN[2],-1,PREG_SPLIT_NO_EMPTY);
# Условие 2: Число секретарей
$cond2 = ($IN[1] >= 1 && $IN[1] <= 1000);
# Условие 3: Количество идентификаторов должно соответствовать числу секретарей
$cond3 = (count($IN[2]) == $IN[1]);
# Проверка условий
if($cond1 && $cond2 && $cond3){
	# Вычисление количества повторяющихся значений (идентификаторов)
	$acv = array_count_values($IN[2]);
	# Сортировка по значениям
	asort($acv);
	# Переход на последний элемент
	end($acv);
	# Значение последнего элемента не должно быть больше двух, если это не нулевой идентификатор
	if(current($acv) > 2 && key($acv) != 0){
		$OUT = -1;
	}else{
		# Вычисление количества типов соединений
		$acv = array_count_values($acv);
		# Возможно есть секретари, ведущие разговор между собой
		if(isset($acv[2])){
			$OUT = $acv[2];
		}else{
			$OUT = 0;
		}
	}
}else{
	$OUT = -1;
}

# Открытие стандартного вывода
/*$stdout = fopen('php://stdout','w');
# Запись данных
fwrite($stdout,$OUT);*/

echo $OUT;
?>

<?php
# Строка со входящими данными
$num = fgets(STDIN);
$ids = explode(' ',fgets(STDIN));
# Строка с исходящими данными
$OUT = 0;

# Проверка условий
if(count($ids) == $num){
	# Вычисление количества повторяющихся значений (идентификаторов)
	$acv = array_count_values($IN[2]);
	# Сортировка по значениям
	asort($acv);
	# Переход на последний элемент
	end($acv);
	# Значение последнего элемента не должно быть больше двух, если это не нулевой идентификатор
	if(current($acv) > 2 && key($acv) != 0){
		$OUT = -1;
	}else{
		# Вычисление количества типов соединений
		$acv = array_count_values($acv);
		# Возможно есть секретари, ведущие разговор между собой
		if(isset($acv[2])){
			$OUT = $acv[2];
		}else{
			$OUT = 0;
		}
	}
}else{
	$OUT = -1;
}

print $OUT;
?>

<?php
# Открытие стандартного ввода
$stdin = fopen('php://stdin','r');

# Строка со входящими данными
$IN = '';
# Строка с исходящими данными
$OUT = 0;

# Считывание данных
while(!feof($stdin))$IN .= fgets($stdin);

# Условие 1: Строгое соответствие шаблону
$cond1 = preg_match("/^(\d+?)\r\n([\d ]+?)$/s",$IN,$IN);
# Ра
$IN[2] = preg_split("/ /",$IN[2],-1,PREG_SPLIT_NO_EMPTY);
# Условие 2: Число секретарей
$cond2 = ($IN[1] >= 1 && $IN[1] <= 1000);
# Условие 3: Количество идентификаторов должно соответствовать числу секретарей
$cond3 = (count($IN[2]) == $IN[1]);
# Проверка условий
if($cond1 && $cond2 && $cond3){
	# Вычисление количества повторяющихся значений (идентификаторов)
	$acv = array_count_values($IN[2]);
	# Сортировка по значениям
	asort($acv);
	# Переход на последний элемент
	end($acv);
	# Значение последнего элемента не должно быть больше двух, если это не нулевой идентификатор
	if(current($acv) > 2 && key($acv) != 0){
		$OUT = -1;
	}else{
		# Вычисление количества типов соединений
		$acv = array_count_values($acv);
		# Возможно есть секретари, ведущие разговор между собой
		if(isset($acv[2])){
			$OUT = $acv[2];
		}else{
			$OUT = 0;
		}
	}
}else{
	$OUT = -1;
}

# Открытие стандартного вывода
/*$stdout = fopen('php://stdout','w');
# Запись данных
fwrite($stdout,$OUT);*/

echo $OUT;
?>

<?php
# Открытие стандартного ввода
$stdin = fopen('php://stdin','r');

# Строка со входящими данными
$IN = '';
# Строка с исходящими данными
$OUT = 0;

# Считывание данных
while(!feof($stdin))$IN .= fgets($stdin);

$IN = '1
0';

# Условие 1: Строгое соответствие шаблону
$cond1 = preg_match("/^(\d+?)\r\n([\d ]+?)$/s",$IN,$IN);
# Ра
$IN[2] = preg_split("/ /",$IN[2],-1,PREG_SPLIT_NO_EMPTY);
# Условие 2: Число секретарей
$cond2 = ($IN[1] >= 1 && $IN[1] <= 1000);
# Условие 3: Количество идентификаторов должно соответствовать числу секретарей
$cond3 = (count($IN[2]) == $IN[1]);
# Проверка условий
if($cond1 && $cond2 && $cond3){
	# Вычисление количества повторяющихся значений (идентификаторов)
	$acv = array_count_values($IN[2]);
	# Сортировка по значениям
	asort($acv);
	# Переход на последний элемент
	end($acv);
	# Значение последнего элемента не должно быть больше двух, если это не нулевой идентификатор
	if(current($acv) > 2 && key($acv) != 0){
		$OUT = -1;
	}else{
		# Вычисление количества типов соединений
		$acv = array_count_values($acv);
		# Возможно есть секретари, ведущие разговор между собой
		if(isset($acv[2])){
			$OUT = $acv[2];
		}else{
			$OUT = 0;
		}
	}
}else{
	$OUT = -1;
}

# Открытие стандартного вывода
$stdout = fopen('php://stdout','w');
# Запись данных
fwrite($stdout,(string)$OUT);

//echo $OUT;
?>

<?php
# Открытие стандартного ввода
//$stdin = fopen('php://stdin','r');

# Строка со входящими данными
$IN = fgets(STDIN);
# Строка с исходящими данными
$OUT = 0;

# Считывание данных
//while(!feof($stdin))$IN .= fgets($stdin);

# Условие 1: Строгое соответствие шаблону
$cond1 = preg_match("/^(\d+?)\r\n([\d ]+?)$/s",$IN,$IN);
# Ра
$IN[2] = preg_split("/ /",$IN[2],-1,PREG_SPLIT_NO_EMPTY);
# Условие 2: Число секретарей
$cond2 = ($IN[1] >= 1 && $IN[1] <= 1000);
# Условие 3: Количество идентификаторов должно соответствовать числу секретарей
$cond3 = (count($IN[2]) == $IN[1]);
# Проверка условий
if($cond1 && $cond2 && $cond3){
	# Вычисление количества повторяющихся значений (идентификаторов)
	$acv = array_count_values($IN[2]);
	# Сортировка по значениям
	asort($acv);
	# Переход на последний элемент
	end($acv);
	# Значение последнего элемента не должно быть больше двух, если это не нулевой идентификатор
	if(current($acv) > 2 && key($acv) != 0){
		$OUT = -1;
	}else{
		# Вычисление количества типов соединений
		$acv = array_count_values($acv);
		# Возможно есть секретари, ведущие разговор между собой
		if(isset($acv[2])){
			$OUT = $acv[2];
		}else{
			$OUT = 0;
		}
	}
}else{
	$OUT = -1;
}

# Открытие стандартного вывода
/*$stdout = fopen('php://stdout','w');
# Запись данных
fwrite($stdout,$OUT);*/

print $OUT;
?>

<?php
# Открытие стандартного ввода
$stdin = fopen('php://stdin','r');

# Строка со входящими данными
$IN = '';
# Строка с исходящими данными
$OUT = 0;

# Считывание данных
while(!feof($stdin))$IN .= fgets($stdin);

# Условие 1: Строгое соответствие шаблону
$cond1 = preg_match("/^(\d+?)\r\n([\d ]+?)$/s",$IN,$IN);
# Ра
$IN[2] = preg_split("/ /",$IN[2],-1,PREG_SPLIT_NO_EMPTY);
# Условие 2: Число секретарей
$cond2 = ($IN[1] >= 1 && $IN[1] <= 1000);
# Условие 3: Количество идентификаторов должно соответствовать числу секретарей
$cond3 = (count($IN[2]) == $IN[1]);
# Проверка условий
if($cond1 && $cond2 && $cond3){
	# Вычисление количества повторяющихся значений (идентификаторов)
	$acv = array_count_values($IN[2]);
	# Сортировка по значениям
	asort($acv);
	# Переход на последний элемент
	end($acv);
	# Значение последнего элемента не должно быть больше двух, если это не нулевой идентификатор
	if(current($acv) > 2 && key($acv) != 0){
		$OUT = -1;
	}else{
		# Вычисление количества типов соединений
		$acv = array_count_values($acv);
		# Возможно есть секретари, ведущие разговор между собой
		if(isset($acv[2])){
			$OUT = $acv[2];
		}else{
			$OUT = 0;
		}
	}
}else{
	$OUT = -1;
}

# Открытие стандартного вывода
$stdout = fopen('php://stdout','w');
# Запись данных
fwrite($stdout,(string)$OUT);
?>

<?php
# Строка со входящими данными
$num = fgets(STDIN);
$ids = explode(' ',fgets(STDIN));
# Строка с исходящими данными
$OUT = 0;

# Проверка условий
if(count($ids) == $num){
	# Вычисление количества повторяющихся значений (идентификаторов)
	$acv = array_count_values($ids);
	# Сортировка по значениям
	asort($acv);
	# Переход на последний элемент
	end($acv);
	# Значение последнего элемента не должно быть больше двух, если это не нулевой идентификатор
	if(current($acv) > 2 && key($acv) != 0){
		$OUT = -1;
	}else{
		# Вычисление количества типов соединений
		$acv = array_count_values($acv);
		# Возможно есть секретари, ведущие разговор между собой
		if(isset($acv[2])){
			$OUT = $acv[2];
		}else{
			$OUT = 0;
		}
	}
}else{
	$OUT = -1;
}

print $OUT;
?>


It is well known that Berland has n cities, which form the Silver ring — cities i and i + 1 (1 ≤ i < n) are connected by a road, as well as the cities n and 1. The goverment have decided to build m new roads. The list of the roads to build was prepared. Each road will connect two cities. Each road should be a curve which lies inside or outside the ring. New roads will have no common points with the ring (except the endpoints of the road).Now the designers of the constructing plan wonder if it is possible to build the roads in such a way that no two roads intersect (note that the roads may intersect at their endpoints). If it is possible to do, which roads should be inside the ring, and which should be outside?

The first line contains two integers n and m (4 ≤ n ≤ 100, 1 ≤ m ≤ 100). Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). No two cities will be connected by more than one road in the list. The list will not contain the roads which exist in the Silver ring.

If it is impossible to build the roads in such a way that no two roads intersect, output Impossible. Otherwise print m characters. i-th character should be i, if the road should be inside the ring, and o if the road should be outside the ring. If there are several solutions, output any of them.


Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.

For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

6

2

RG

RB

4

GRBG

GBGB

5

GGGGG

BBBBB

7

BBBBBBB

RRRRRRR

8

RGBRRGBR

RGGRRBGR

1

G

G

NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.

<?php

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

$g =  trim(fgets( $x ));

for($i = 0; $i < $g; $i++)
{
    $cols = trim(fgets( $x ));
    $row1 = trim(fgets( $x ));
    $row2 = trim(fgets( $x ));

    if(strtr($row1, ['B' => 'G']) == strtr($row2, ['B' => 'G'])){
        echo "Yes\n";
    }
    else{
        echo "No\n";
    }
}

?>

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

$cases =  trim(fgets( $f ));

while($cases--){
    $cols = trim(fgets( $f ));
    $firstRow = trim(fgets( $f ));
    $secondRow = trim(fgets( $f ));

    if(str_replace('G', 'B', $firstRow) == str_replace('G', 'B', $secondRow))
    {
        echo "YES\n";
    }
    else
    {
        echo "NO\n";
    }
}

?>

<?php

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

$cases =  trim(fgets( $f ));

for($i = 0; $i < $cases; $i++)
{
    $cols = trim(fgets( $f ));
    $row1 = trim(fgets( $f ));
    $row2 = trim(fgets( $f ));

    $row1 = str_replace('G', 'B', $row1);
    $row2 = str_replace('G', 'B', $row2);

    if($row1 == $row2)
    {
        echo "YES\n";
    }
    else
    {
        echo "NO\n";
    }
}

?>

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
    $len = 5;
   //RBG

   $n = IO::get();
   $s = IO::get();
   $d = IO::get();

        $b = true;
     for ($i=0; $i<$n; $i++) {
        if($s[$i] == 'R') {
             if($d[$i] != 'R') {
                  $b = false;
                  break;
             }
        } else {
           if($d[$i] == 'R') {
                  $b = false;
                  break;
             }
        }
     }

     IO::pr($b ? 'Yes' : 'No');

}

class IO {
    public static function get()
    {
        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;
    }
}

<?php

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

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

while ($t--) {
    fscanf($inp, '%d', $n);

    fscanf($inp, '%s', $a);
    fscanf($inp, '%s', $b);

    if (str_replace('G', 'B', $a) === str_replace('G', 'B', $b) ) {
        echo 'yes'.PHP_EOL;
    } else {
        echo 'no'.PHP_EOL;
    }
}

<?php

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

$g =  trim(fgets( $x ));

for($i = 0; $i < $g; $i++)
{
    $row1 = trim(fgets( $x ));
    $row2 = trim(fgets( $x ));

    if(strtr($row1, ['B' => 'G']) == strtr($row2, ['B' => 'G'])){
        echo "Yes\n";
    }
    else{
        echo "No\n";
    }
}

?>

<?php
list($t) = array_map('intval', explode(' ', trim(fgets(STDIN))));

while ($t--){
    list($i,$d) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    if(strtr($i, ['B' => 'G']) == strtr($d, ['B' => 'G'])){
        echo "Yes";
    }
    else{
        echo "No";
    }
}

<?php
    list($i,$d) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    if(strtr($i, ['B' => 'G']) == strtr($d, ['B' => 'G'])){
        echo "ДА";
    }
    else{
        echo "НЕТ";
    }

<?php
list($t) = array_map('intval', explode(' ', trim(fgets(STDIN))));

while ($t--){
    list($a,$b,$n) = array_map('intval', explode(' ', trim(fgets(STDIN))));

    if (substr_count($a,'R') === substr_count($b,'R')){
        echo 'YES';
    }
    else{
        echo 'NO';
    }
    echo "\n";
}

<?php
list($t) = array_map('intval', explode(' ', trim(fgets(STDIN))));

while ($t--){
    list($a,$b) = array_map('intval', explode(' ', trim(fgets(STDIN))));

    if (str_replace('G', 'B', $a) === str_replace('G', 'B', $b)){
        echo 'YES';
    }
    else{
        echo 'NO';
    }
    echo "\n";
}

<?php
list($t) = array_map('intval', explode(' ', trim(fgets(STDIN))));

while ($t--){
    list($a,$b) = array_map('intval', explode(' ', trim(fgets(STDIN))));

    if (substr_count($a,'R') === substr_count($b,'R')){
        echo 'YES';
    }
    else{
        echo 'NO';
    }
    echo "\n";
}

<?php

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

$cases =  trim(fgets( $f ));

for($i = 0; $i < $cases; $i++)
{
    $cols = trim(fgets( $f ));
    $row1 = trim(fgets( $f ));
    $row2 = trim(fgets( $f ));

    str_replace('G', 'B', $row1);
    str_replace('G', 'B', $row2);

    if($row1 == $row2)
    {
        echo "YES\n";
    }
    else
    {
        echo "NO\n";
    }
}

?>


The famous joke programming language HQ9+ has only 4 commands. In this problem we will explore its subset — a language called HQ...

The only line of the input is a string between 1 and 106 characters long.

NoteThe rest of the problem statement was destroyed by a stray raccoon. We are terribly sorry for the inconvenience.

<?php
// Retrieve input
$stdin = fopen('php://stdin', 'r');
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces April Fools Contest 2013 Problem E

// Actual problem:
// H outputs H. Q outputs source. Determine whether given string can be the output of a program.

// Basic idea:
// We know that there must be a square number of Q's (if the program has q Q's, each Q is printed q times to give q^2 Q's). If q = 0, output YES.
// We also know that the number of H's must be divisible by (q+1). (Each H is printed once on its own, and q more times by the Q's.)
// Now we know the number of H's and Q's in the program. Take this number as p.
// Before the first Q, there are only H's. Suppose there are k H's. Each of them is printed once on its own, and one more by the first Q, so there must be 2k H's before the first Q. That is, the number of H's before the first Q must be divisible by 2.
// Now we know all of these, we'll generate the program that produced the output. Remove the first k characters (they are the H's printed on their own), and take the next p characters (they are the program, printed by the first Q). Just simulate this program and match against the output.

function fin($verdict) {
	if ($verdict) {echo "Yes";} else {echo "No";}
	exit;
}

$raw = g();
$str = $raw[0];
$qsquared = 0;
$htimes1plusq = 0;
$doublek = 0;
$metfirstq = false;
for ($i = 0; $i < strlen($str); $i++) {
	$char[$i] = (substr($str,$i,1) == "H" ? 0 : 1);

	if ($char[$i]) {
		$qsquared++;
		if (!$metfirstq) {$doublek = $i; $metfirstq = true;}
	} else {
		$htimes1plusq++;
	}
}

if ($qsquared == 0) {fin(true);}
if (sqrt($qsquared) != floor(sqrt($qsquared))) {fin(false);}
$q = sqrt($qsquared);
if ($htimes1plusq % (1+$q) != 0) {fin(false);}
$h = $htimes1plusq / (1+$q);
if ($doublek % 2 != 0) {fin(false);}
$k = $doublek / 2;
$p = $h + $q;

for ($i = $k; $i < $k+$p; $i++) {
	$prog[$i-$k] = $char[$i];
}

$pointer = 0;
for ($i = 0; $i < $p; $i++) {
	if ($prog[$i]) {
		for ($j = 0; $j < $p; $j++) {
			if ($char[$pointer] != $prog[$j]) {fin(false);}
			$pointer++;
		}
	} else {
		if ($char[$pointer]) {fin(false);}
		$pointer++;
	}
}
fin(true);

// End of submission file
// Submission by chaotic_iak
?>


Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1,  a2,  ...,  an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i  -  1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you.

The first line contains integers n, w, h (1  ≤ n ≤ 5000, 1 ≤ w,  h  ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi — width and height of the i-th envelope (1 ≤ wi,  hi ≤ 106).

In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line.

<?php

class Envelope {
	public $w, $h, $i, $p;
	public function __construct($w, $h, $i) {
		$this->w = $w;
		$this->h = $h;
		$this->i = $i;
		$this->p = NULL;
	}
}

function cmp($a, $b) {
	if ($a->w != $b->w) {
		return $a->w < $b->w ? -1 : 1;
	} else if ($a->h != $b->h) {
		return $a->h > $b->h ? -1 : 1;
	} else {
		return 0;
	}
}

fscanf(STDIN, "%d%d%d", $n, $w, $h);
$a = Array();
for ($i = 1; $i <= $n; ++$i) {
	fscanf(STDIN, "%d%d", $wi, $hi);
	if ($wi > $w && $hi > $h) {
		array_push($a, new Envelope($wi, $hi, $i));
	}
}

usort($a, 'cmp');
$b = Array();
foreach ($a as $ai) {
	$l = 0;
	$r = count($b);
	while ($l < $r) {
		$m = ($l + $r) / 2;
		if ($ai->h > $b[$m]->h) {
			$l = $m + 1;
		} else {
			$r = $m;
		}
	}
	$ai->p = ($r == 0 ? NULL : $b[$r - 1]);
	$b[$r] = $ai;
}

echo count($b) . "\n";
if (count($b) > 0) {
	$c = Array();
	for ($p = array_pop($b); $p != NULL; $p = $p->p) {
		array_unshift($c, $p->i);
	}
	print implode($c, ' ') . "\n";
}

/*

*/


Consider a sequence of digits of length $$$2^k$$$ $$$[a_1, a_2, \ldots, a_{2^k}]$$$. We perform the following operation with it: replace pairs $$$(a_{2i+1}, a_{2i+2})$$$ with $$$(a_{2i+1} + a_{2i+2})\bmod 10$$$ for $$$0\le i<2^{k-1}$$$. For every $$$i$$$ where $$$a_{2i+1} + a_{2i+2}\ge 10$$$ we get a candy! As a result, we will get a sequence of length $$$2^{k-1}$$$.Less formally, we partition sequence of length $$$2^k$$$ into $$$2^{k-1}$$$ pairs, each consisting of 2 numbers: the first pair consists of the first and second numbers, the second of the third and fourth $$$\ldots$$$, the last pair consists of the ($$$2^k-1$$$)-th and ($$$2^k$$$)-th numbers. For every pair such that sum of numbers in it is at least $$$10$$$, we get a candy. After that, we replace every pair of numbers with a remainder of the division of their sum by $$$10$$$ (and don't change the order of the numbers).Perform this operation with a resulting array until it becomes of length $$$1$$$. Let $$$f([a_1, a_2, \ldots, a_{2^k}])$$$ denote the number of candies we get in this process. For example: if the starting sequence is $$$[8, 7, 3, 1, 7, 0, 9, 4]$$$ then:After the first operation the sequence becomes $$$[(8 + 7)\bmod 10, (3 + 1)\bmod 10, (7 + 0)\bmod 10, (9 + 4)\bmod 10]$$$ $$$=$$$ $$$[5, 4, 7, 3]$$$, and we get $$$2$$$ candies as $$$8 + 7 \ge 10$$$ and $$$9 + 4 \ge 10$$$.After the second operation the sequence becomes $$$[(5 + 4)\bmod 10, (7 + 3)\bmod 10]$$$ $$$=$$$ $$$[9, 0]$$$, and we get one more candy as $$$7 + 3 \ge 10$$$. After the final operation sequence becomes $$$[(9 + 0) \bmod 10]$$$ $$$=$$$ $$$[9]$$$. Therefore, $$$f([8, 7, 3, 1, 7, 0, 9, 4]) = 3$$$ as we got $$$3$$$ candies in total.You are given a sequence of digits of length $$$n$$$ $$$s_1, s_2, \ldots s_n$$$. You have to answer $$$q$$$ queries of the form $$$(l_i, r_i)$$$, where for $$$i$$$-th query you have to output $$$f([s_{l_i}, s_{l_i+1}, \ldots, s_{r_i}])$$$. It is guaranteed that $$$r_i-l_i+1$$$ is of form $$$2^k$$$ for some nonnegative integer $$$k$$$.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the sequence. The second line contains $$$n$$$ digits $$$s_1, s_2, \ldots, s_n$$$ ($$$0 \le s_i \le 9$$$). The third line contains a single integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. Each of the next $$$q$$$ lines contains two integers $$$l_i$$$, $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) — $$$i$$$-th query. It is guaranteed that $$$r_i-l_i+1$$$ is a nonnegative integer power of $$$2$$$.

Output $$$q$$$ lines, in $$$i$$$-th line output single integer — $$$f([s_{l_i}, s_{l_i + 1}, \ldots, s_{r_i}])$$$, answer to the $$$i$$$-th query.

NoteThe first example illustrates an example from the statement.$$$f([7, 3, 1, 7]) = 1$$$: sequence of operations is $$$[7, 3, 1, 7] \to [(7 + 3)\bmod 10, (1 + 7)\bmod 10]$$$ $$$=$$$ $$$[0, 8]$$$ and one candy as $$$7 + 3 \ge 10$$$ $$$\to$$$ $$$[(0 + 8) \bmod 10]$$$ $$$=$$$ $$$[8]$$$, so we get only $$$1$$$ candy.$$$f([9]) = 0$$$ as we don't perform operations with it.

<?php
#1189C
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$sums = [];
foreach ($arr as $i => $v) {
    $sums[] = ($sums[$i - 1] ?? 0) + $v;
}
$q = trim(fgets(STDIN));
while ($q--) {
    [$l, $r] = explode(' ', trim(fgets(STDIN)));
    $candies = 0;
    if ($r > $l) {
        $candies = floor(($sums[$r - 1] - ($sums[$l - 2] ?? 0)) / 10);
    }
    echo $candies . PHP_EOL;
}

<?php
#1189C
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$sums = [];
foreach ($arr as $i => $v) {
    $sums[] = ($sums[$i - 1] ?? 0) + $v;
}
$q = trim(fgets(STDIN));
while ($q--) {
    [$l, $r] = explode(' ', trim(fgets(STDIN)));
    $candies = 0;
    if ($r > $l) {
        $candies = floor(($sums[$r - 1] - $sums[$l - 1]) / 10);
    }
    echo $candies . PHP_EOL;
}


Sereja loves integer sequences very much. He especially likes stairs.Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 ≤ i ≤ |a|), that the following condition is met: a1 < a2 < ... < ai - 1 < ai > ai + 1 > ... > a|a| - 1 > a|a|.For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't.Sereja has m cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?

The first line contains integer m (1 ≤ m ≤ 105) — the number of Sereja's cards. The second line contains m integers bi (1 ≤ bi ≤ 5000) — the numbers on the Sereja's cards.

In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.

<?php
$in=fgets(STDIN);
$in=intval($in);
$str=fgets(STDIN);
$arr=explode(" ", $str);
foreach ($arr as &$va) {
	$va=intval($va);
}
rsort($arr);
$ans=array();
foreach($arr as $v){
	if(empty($ans[$v])){
		$ans+=array($v=>1);
	}else{
		$ans[$v]++;
	}
}
$i=0;
$tar=array();
foreach ($ans as $k=>&$v) {
	if($v!=0){
		$tar[$i]=$k;
		$v--;
		$i++;
	}
}
$i=0;
$car=array();
foreach ($ans as $k=>&$v) {
	if($v!=0){
		$car[$i]=$k;
		$v--;
		$i++;
	}
}
if($tar[0]==$car[0]) unset($tar[0]);
$car=array_reverse($car);

$num=count($tar)+count($car);
echo $num."\n";
foreach ($car as $v) {
	echo $v." ";
}
foreach ($tar as $v) {
	echo $v." ";
}

?>


Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.

The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.

In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.

NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.

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

$lines = explode("\r\n", $input);
unset($lines[0]);

$servers = array();
$servers[1] = $servers[2] = array('errors' => 0, 'success' => 0);

foreach($lines as $line)
{
    list($server, $success, $errors) = explode(' ', $line);
    $server = (int) $server;

    $servers[$server]['errors'] += (int) $errors;
    $servers[$server]['success'] += (int) $success;
}

echo ($servers[1]['success'] / $servers[1]['errors']) >= 1 ? 'LIVE' : 'DEAD';
echo PHP_EOL;
echo ($servers[2]['success'] / $servers[2]['errors']) >= 1 ? 'LIVE' : 'DEAD';

<?php

$servers = array(1 => 0, 0);
$cnt = getLine();
for ($i=0; $i<$cnt; $i++) {
    list($si, $x, $y) = explode(" ", getLine());
    $servers[$si] += $x - $y;
}

echo ($servers[1]>=0 ? 'LIVE' : 'DEAD') . PHP_EOL;
echo ($servers[2]>=0 ? 'LIVE' : 'DEAD') . PHP_EOL;

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

<?PHP
$n = fgets(STDIN);
$sa = 'DEAD';
$sb = 'DEAD';

$xa = 0;
$ya = 0;

for ($i = 0; $i < $n; $i++) {
    list($t, $x, $y) = explode(' ', fgets(STDIN));
    if ($t == 1)
        $xa = $xa + $x - intval($y);
    else
        $ya = $ya + $x - intval($y);
    //echo "lei: $t, $x, $y\n";
}

if ($xa >= 0)
    $sa = 'LIVE';
if ($ya >= 0)
    $sb = 'LIVE';

echo "$sa\n";
echo "$sb\n";

?>

<?php

$servers = array(1 => 0, 0);
$cnt = getLine();
for ($i=0; $i<$cnt; $i++) {
    list($si, $x, $y) = explode(" ", getLine());
    $servers[$si] += ($x>=$y) - ($x<$y);
}

echo ($servers[1]>0 ? 'LIVE' : 'DEAD') . PHP_EOL;
echo ($servers[2]>0 ? 'LIVE' : 'DEAD') . PHP_EOL;

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

<?php

$servers = array(1 => 0, 0);
$cnt = getLine();
for ($i=0; $i<$cnt; $i++) {
    list($si, $x, $y) = explode(" ", getLine());
    $servers[$si] += ($x>=$y) - ($x<$y);
}

echo ($servers[1]>=0 ? 'LIVE' : 'DEAD') . PHP_EOL;
echo ($servers[2]>=0 ? 'LIVE' : 'DEAD') . PHP_EOL;

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

<?PHP
$n = fgets(STDIN);
$sa = 'DEAD';
$sb = 'DEAD';

for ($i = 0; $i < $n; $i++) {
    list($t, $x, $y) = explode(' ', fgets(STDIN));
    //echo "lei: $t, $x, $y\n";
    if ($t == 1)
        if ($x >= intval($y))
            $sa = 'LIVE';
    if ($t == 2)
        if ($x >= intval($y))
            $sb = 'LIVE';
}

echo "$sa\n";
echo "$sb\n";

?>


One day, Vogons wanted to build a new hyperspace highway through a distant system with $$$n$$$ planets. The $$$i$$$-th planet is on the orbit $$$a_i$$$, there could be multiple planets on the same orbit. It's a pity that all the planets are on the way and need to be destructed.Vogons have two machines to do that.  The first machine in one operation can destroy any planet at cost of $$$1$$$ Triganic Pu.  The second machine in one operation can destroy all planets on a single orbit in this system at the cost of $$$c$$$ Triganic Pus. Vogons can use each machine as many times as they want.Vogons are very greedy, so they want to destroy all planets with minimum amount of money spent. Can you help them to know the minimum cost of this project?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then the test cases follow. Each test case consists of two lines. The first line contains two integers $$$n$$$ and $$$c$$$ ($$$1 \le n, c \le 100$$$) — the number of planets and the cost of the second machine usage. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the orbit of the $$$i$$$-th planet.

For each test case print a single integer — the minimum cost of destroying all planets.

NoteIn the first test case, the cost of using both machines is the same, so you can always use the second one and destroy all planets in orbit $$$1$$$, all planets in orbit $$$2$$$, all planets in orbit $$$4$$$, all planets in orbit $$$5$$$.In the second test case, it is advantageous to use the second machine for $$$2$$$ Triganic Pus to destroy all the planets in orbit $$$2$$$, then destroy the remaining two planets using the first machine.In the third test case, you can use the first machine twice or the second machine once.In the fourth test case, it is advantageous to use the first machine twice.

<?php

fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d %d", $n, $c);
    $a   = trim(fgets(STDIN));
    $arr = explode(" ", $a);
    $map = [];
    foreach ($arr as $ar) {
        $map[$ar]++;

    }
    $cost     = 0;
    $ex_count = 0;
    $o_count  = 0;
    $min      = 0;
    foreach ($map as $k => $v) {
        if ($c < $v) {
            $cost += $c;
        } else
            $cost += $v;

    }
    echo $cost."\n";
}

return;
?>

<?php

$n = trim(readLine());
for ($i = 1; $i <= $n; $i++) {
    list($planetCount, $price) = explode(' ', trim(readLine()));
    $price = (int)$price;
    $planetCount = (int)$planetCount;
    $planets = explode(' ', trim(readLine()));
    $planetsResult = [];
    $result = 0;
    foreach ($planets as $planet) {
        if (array_key_exists($planet, $planetsResult)) {
            $planetsResult[$planet] = $planetsResult[$planet] + 1;
            continue;
        }
        $planetsResult[$planet] = 1;
    }
    foreach ($planetsResult as $planetCount) {
        if ($planetCount > $price) {
            $result += $price;
            continue;
        }
        $result += $planetCount;
    }
    print $result . PHP_EOL;
}

<?php
$cin = fopen("php://stdin", "r"); // IO
$cout = fopen("php://stdout", "w"); // IO

$t;
fscanf($cin, "%d\n", $t);
for ($T = 0; $T < $t; $T++) {
	fscanf($cin, "%d %d\n", $n, $c);
  $bruh = array("hi"=>0);
  $arr = explode(" ", trim(fgets($cin)));
  foreach($arr as $val){
      $bruh[$val]+=1;
  }
  $ans = 0;
  foreach($bruh as $el){
    $ans += min($el, $c);

  }
  fprintf($cout, "%d\n", $ans);
}

?>

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

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

   list($n, $c) = IO::getArray();
      $a = IO::getArray();

    $ans = 0;
    $tt = [];
    for($i=0; $i<$n; $i++) {
        if(!isset($tt[$a[$i]])) {
          $tt[$a[$i]] = 1;
        } else {
            $tt[$a[$i]] += 1;
        }
    }
    $t = array_values($tt);
//    IO::prArray($t);
    for($i=0; $i<count($t); $i++) {
         if($t[$i]  > $c ) {
            $ans += $c;
         } else {
              $ans += $t[$i];
         }
    }

   IO::pr($ans);
}

class IO {
    public static function get()
    {
        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;
    }
}

<?php

fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d %d", $n,$c);
    $a   = trim(fgets(STDIN));
    $arr = explode(" ", $a);
    $map = [];
    foreach ($arr as $ar){
        $map[$ar]++;

    }
    $cost = 0;
    $ex_count = 0;
    $o_count = 0;
    $min = 0;
    if($c>1){
        foreach($map as $k=>$v){
            if($v>1){
                $ex_count+=$v;
            }else{
                $o_count++;
            }

        }
        $min= min($ex_count,$c);

        echo $cost = $min+$o_count."\n";
    }else{
        echo count($map)."\n";
    }
}

return;
?>

<?php

fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d %d", $n,$c);
    $a   = trim(fgets(STDIN));
    $arr = explode(" ", $a);
    $map = [];
    foreach ($arr as $ar){
        if(isset($map[$ar])){
            $map[$ar]++;
        }else{
            $map[$ar]=1;
        }

    }
    $cost = 0;
    $ex_count = 0;
    $o_count = 0;
    $min = 0;
    if($c>1){
        foreach($map as $k=>$v){
            if($v>1){
                $ex_count+=$v;
            }else{
                $o_count++;
            }

        }
        $min= min($ex_count,$c);

        echo $cost = $min+$o_count."\n";
    }else{
        echo count($map)."\n";
    }
}

return;
?>

<?php
$planetsResult = [];
$n = trim(readLine());
$result = 0;
for ($i = 1; $i <= $n; $i++) {
    list($planetCount, $price) = explode(' ', trim(readLine()));
    $price = (int)$price;
    $planetCount = (int)$planetCount;
    $planets = explode(' ', trim(readLine()));
    foreach ($planets as $planet) {
        if (array_key_exists($planet, $planetsResult)) {
            $planetsResult[$planet] = $planetsResult[$planet] + 1;
            continue;
        }
        $planetsResult[$planet] = 1;
    }
    foreach ($planetsResult as $planetCount) {
        if ($planetCount > $price) {
            $result += $price;
            continue;
        }
        $result += $planetCount;
    }
    print $result . PHP_EOL;
}


Monocarp has forgotten the password to his mobile phone. The password consists of $$$4$$$ digits from $$$0$$$ to $$$9$$$ (note that it can start with the digit $$$0$$$).Monocarp remembers that his password had exactly two different digits, and each of these digits appeared exactly two times in the password. Monocarp also remembers some digits which were definitely not used in the password.You have to calculate the number of different sequences of $$$4$$$ digits that could be the password for Monocarp's mobile phone (i. e. these sequences should meet all constraints on Monocarp's password).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 8$$$) — the number of digits for which Monocarp remembers that they were not used in the password. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots a_n$$$ ($$$0 \le a_i \le 9$$$) representing the digits that were not used in the password. Note that the digits $$$a_1, a_2, \dots, a_n$$$ are given in ascending order.

For each testcase, print one integer — the number of different $$$4$$$-digit sequences that meet the constraints.

NoteIn the first example, all possible passwords are: "3377", "3737", "3773", "7337", "7373", "7733".

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $a = IO::getArray();
   $ans = 0;
   $t = [
        '1' => 216,
        '2' => 168,
        '3' => 126,
        '4' => 90,
        '5' => 60,
        '6' => 36,
        '7' => 18,
        '8' => 6
        ];
        $ans = $t[$n];

   IO::pr($ans);
}

class IO {
    public static function get()
    {
        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;
    }
}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($j = 0; $j < $t; $j++) {
	$l = trim(fgets($handle));
	$s = trim(fgets($handle));
	$arr= explode( ' ', $s);
    $x = 10 - $l;
	echo $x * (($x - 1) * 3) . "\n";
}

<?php
function nCr( $n, $r)
{
    return fact($n) / (fact($r) *
            fact($n - $r));
}

// Returns factorial of n
function fact( $n)
{
    if($n == 0)
        return 1;
    $res = 1;
    for ( $i = 2; $i <= $n; $i++)
        $res = $res * $i;
    return $res;
}
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d", $n);
    $a   = trim(fgets(STDIN));
    echo (nCr(10-$n,2)*6)."\n";

}

return;
?>

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $a = IO::getArray();
   $ans = 0;
   $t = [
        '1' => 216,
        '2' => 162,
        '3' => 126,
        '4' => 90,
        '5' => 60,
        '6' => 36,
        '7' => 18,
        '8' => 6
        ];
        $ans = $t[$n];

   IO::pr($ans);
}

class IO {
    public static function get()
    {
        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;
    }
}


You are given $$$n$$$ words of equal length $$$m$$$, consisting of lowercase Latin alphabet letters. The $$$i$$$-th word is denoted $$$s_i$$$.In one move you can choose any position in any single word and change the letter at that position to the previous or next letter in alphabetical order. For example:  you can change 'e' to 'd' or to 'f';  'a' can only be changed to 'b';  'z' can only be changed to 'y'. The difference between two words is the minimum number of moves required to make them equal. For example, the difference between "best" and "cost" is $$$1 + 10 + 0 + 0 = 11$$$.Find the minimum difference of $$$s_i$$$ and $$$s_j$$$ such that $$$(i < j)$$$. In other words, find the minimum difference over all possible pairs of the $$$n$$$ words.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains $$$2$$$ integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 50$$$, $$$1 \leq m \leq 8$$$) — the number of strings and their length respectively. Then follows $$$n$$$ lines, the $$$i$$$-th of which containing a single string $$$s_i$$$ of length $$$m$$$, consisting of lowercase Latin letters.

For each test case, print a single integer — the minimum difference over all possible pairs of the given strings.

6

2 4

best

cost

6 3

abb

zba

bef

cdu

ooo

zzz

2 7

aaabbbc

bbaezfe

3 2

ab

ab

ab

2 8

aaaaaaaa

zzzzzzzz

3 1

a

u

y

NoteFor the second test case, one can show that the best pair is ("abb","bef"), which has difference equal to $$$8$$$, which can be obtained in the following way: change the first character of the first string to 'b' in one move, change the second character of the second string to 'b' in $$$3$$$ moves and change the third character of the second string to 'b' in $$$4$$$ moves, thus making in total $$$1 + 3 + 4 = 8$$$ moves.For the third test case, there is only one possible pair and it can be shown that the minimum amount of moves necessary to make the strings equal is $$$35$$$.For the fourth test case, there is a pair of strings which is already equal, so the answer is $$$0$$$.

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

  $t = getT();
//   $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = 0;
      list($n, $m) = getA();
      $a = [];
      $b = [];
      $c = [];
      for($i=0; $i<$n; $i++) {
          $tt = getT();
          $a[] = $tt;
          $c[$i] = 0;
          for($j=0; $j<$m; $j++) {
              $tm = ord($tt[$j]) - ord('a');
              $c[$i] += $tm;
              $b[$i][$j] = $tm;
          }
      }
       $min = 0;
       $d = [];
       $rr = 0;
       for($i=0; $i<$n; $i++) {
          for($j=$i+1; $j<$n; $j++) {
          	$count = 0;
          	for($ww=0; $ww<$m; $ww++) {
          		$count += abs($b[$j][$ww] - $b[$i][$ww]);
          	}
            $d[] = $count;
          }
       }

      pr(min($d));

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
function getDar($n) {
    $dar = [2];
    for($i=0; $i<$n; $i++) {
        $dar[] = $dar[$i] * 2;
    }
    return $dar;
}
function getDar2($n, $k) {
    if($k == 0) {
        return 1;
    }
    return bcmul($n, getDar2($n, $k-1));
}

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

  function is_prime($n) {
    $d = 2;
        while ($n % $d != 0) {
        	 $d += 1;
        }

        return $d == $n;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

    function getMaxValueBc($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    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;
    }
    function pr($s) {
        if(is_array($s)) {
            echo implode( ' ', $s), PHP_EOL;
        } else {
            echo $s, PHP_EOL;
        }
    }
    function fab2($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];
    }


Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.

The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n).

Print m integers — the answers to the queries in the order in which they are given in the input.

<?php
	$s = fgets(STDIN);
	$counts = array(0);
	for($i = 0; $i < strlen($s) - 1; ++$i)
	{
		$counts[$i + 1] = ($s[$i] !== $s[$i + 1]) ? $counts[$i] : $counts[$i] + 1;
	}

	$c = fgets(STDIN);

	for($i = 0; $i < $c; ++$i)
	{
		list($l, $r) = explode(' ', fgets(STDIN));
		echo $counts[$r - 1] - $counts[$l - 1] . "\n";
	}

<?php
$str = trim(fgets(STDIN));
for ($k=0;$k<strlen($str);$k++)
    $DP_arr[$k] = $DP_arr[$k-1]+($str[$k]==$str[$k+1]?1:0);

$n = fgets(STDIN);
for ($i=0;$i<$n;$i++){
    list($a,$b) = explode(' ',trim(fgets(STDIN)));
    echo ($DP_arr[$b-2]-$DP_arr[$a-2])."\n";
}

?>

<?php
	$s = fgets(STDIN);
	$counts = array(0);
	for($i = 0; $i < strlen($s) - 1; ++$i)
	{
		$counts[$i + 1] = ($s[$i] !== $s[$i + 1]) ? $counts[$i] : $counts[$i] + 1;
	}

	$c = fgets(STDIN);

	for($i = 0; $i < $c; ++$i)
	{
		list($l, $r) = explode(' ', fgets(STDIN));
		echo $counts[$r - 1] - $counts[$l - 1];
		echo '\n';
	}

<?php
	$s = fgets(STDIN);
	$counts = array(0);
	for($i = 0; $i < strlen($s) - 1; ++$i)
	{
		$counts[$i + 1] = ($s[$i] !== $s[$i + 1]) ? $counts[$i] : $counts[$i] + 1;
	}

	$c = fgets(STDIN);

	for($i = 0; $i < $c; ++$i)
	{
		list($l, $r) = explode(' ', fgets(STDIN));
		echo $counts[$r - 1] - $counts[$l - 1];
	}

<?php
	$s = fgets(STDIN);
	$counts = array(0);
	for($i = 0; $i < strlen($s) - 1; ++$i)
	{
		$counts[$i + 1] = ($s[$i] !== $s[$i + 1]) ? $counts[$i] : $counts[$i] + 1;
	}

	$c = fgets(STDIN);

	for($i = 0; $i < $c; ++$i)
	{
		list($l, $r) = explode(' ', fgets(STDIN));
		echo $counts[$r - 1] - $counts[$l - 1] . '\n';
	}


You are given an integer $$$n$$$. You have to construct a permutation of size $$$n$$$.A permutation is an array where each integer from $$$1$$$ to $$$s$$$ (where $$$s$$$ is the size of permutation) occurs exactly once. For example, $$$[2, 1, 4, 3]$$$ is a permutation of size $$$4$$$; $$$[1, 2, 4, 5, 3]$$$ is a permutation of size $$$5$$$; $$$[1, 4, 3]$$$ is not a permutation (the integer $$$2$$$ is absent), $$$[2, 1, 3, 1]$$$ is not a permutation (the integer $$$1$$$ appears twice).A subsegment of a permutation is a contiguous subsequence of that permutation. For example, the permutation $$$[2, 1, 4, 3]$$$ has $$$10$$$ subsegments: $$$[2]$$$, $$$[2, 1]$$$, $$$[2, 1, 4]$$$, $$$[2, 1, 4, 3]$$$, $$$[1]$$$, $$$[1, 4]$$$, $$$[1, 4, 3]$$$, $$$[4]$$$, $$$[4, 3]$$$ and $$$[3]$$$.The value of the permutation is the number of its subsegments which are also permutations. For example, the value of $$$[2, 1, 4, 3]$$$ is $$$3$$$ since the subsegments $$$[2, 1]$$$, $$$[1]$$$ and $$$[2, 1, 4, 3]$$$ are permutations.You have to construct a permutation of size $$$n$$$ with minimum possible value among all permutations of size $$$n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. Then, $$$t$$$ lines follow. The $$$i$$$-th of them contains one integer $$$n$$$ ($$$3 \le n \le 50$$$) representing the $$$i$$$-th test case.

For each test case, print $$$n$$$ integers — the permutation of size $$$n$$$ with minimum possible value. If there are multiple such permutations, print any of them.

NoteIn the first example, the permutation $$$[1, 4, 3, 5, 2]$$$ is one of the possible answers; its value is $$$2$$$.In the second example, the permutation $$$[4, 1, 6, 2, 5, 3]$$$ is one of the possible answers; its value is $$$2$$$.

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
//    $a = IO::getArray();
   $ans ='';

//    for($i=$n; $i>0; $i-=2) {
//         $temp = $n - $i + 1;
//         $ans .= $i . ' ' . $temp . ' ';
//    }
   for($i=1; $i <= $n / 2; $i++) {
        $temp = $n - $i + 1;
        $ans .= $i . ' ' . $temp . ' ';
   }
   if($n % 2 == 1) {
       $ans .= ceil($n / 2);
   }

   IO::pr($ans);
}

class IO {
    public static function get()
    {
        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;
    }
}


You are given a board of size $$$n \times n$$$, where $$$n$$$ is odd (not divisible by $$$2$$$). Initially, each cell of the board contains one figure.In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell $$$(i, j)$$$ you can move the figure to cells:   $$$(i - 1, j - 1)$$$;  $$$(i - 1, j)$$$;  $$$(i - 1, j + 1)$$$;  $$$(i, j - 1)$$$;  $$$(i, j + 1)$$$;  $$$(i + 1, j - 1)$$$;  $$$(i + 1, j)$$$;  $$$(i + 1, j + 1)$$$; Of course, you can not move figures to cells out of the board. It is allowed that after a move there will be several figures in one cell.Your task is to find the minimum number of moves needed to get all the figures into one cell (i.e. $$$n^2-1$$$ cells should contain $$$0$$$ figures and one cell should contain $$$n^2$$$ figures).You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$1 \le n < 5 \cdot 10^5$$$) — the size of the board. It is guaranteed that $$$n$$$ is odd (not divisible by $$$2$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$ ($$$\sum n \le 5 \cdot 10^5$$$).

For each test case print the answer — the minimum number of moves needed to get all the figures into one cell.

<?php

	//$input = fopen("input.txt", "r");
	//fscanf($input, "%d\n", $t);

	/*function cinarr($sz, $ty){
		$inp = $ty;
		for($i = 1 ; $i < $sz ; $i++)    $inp .= " " . $ty;
		$inp .= "\n";
		$ret = fscanf(STDIN, $inp);
		return $ret;
	}*/

	fscanf(STDIN, "%d\n", $t);
	while($t--){
        $ans = 0;
		fscanf(STDIN, "%d\n", $n);
		for($i = 3, $moves = 1; $i <= $n ; $i+=2, $moves++) $ans += $moves * ($i * $i - ($i - 2)*($i - 2));
		echo number_format($ans, 0, "", "") . "\n";
	}

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

for ($i = 1; $i <= $count; $i++) {
    $result = 0;
    $count2 = floor((int)fgets(STDIN) / 2);

    for ($j = 1; $j <= $count2; $j++) {
        $result += 8 * $j * $j;
    }

    echo number_format($result, 0, ',', '') . PHP_EOL;
}

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

for ($i = 1; $i <= $count; $i++) {
    $result = 0;
    $count2 = floor((int)fgets(STDIN) / 2);

    for ($j = 1; $j <= $count2; $j++) {
        $result += 8 * $j * $j;
    }

    echo number_format($result, 5) . PHP_EOL;
}

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

for ($i = 1; $i <= $count; $i++) {
    $result = 0;
    $count2 = floor((int)fgets(STDIN) / 2);

    for ($j = 1; $j <= $count2; $j++) {
        $result += 8 * $j * $j;
    }

    echo $result . PHP_EOL;
}

<?php

$count = trim(fgets(STDIN));

for ($i = 1; $i <= $count; $i++) {
    echo trim(fgets(STDIN));
}

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

for ($i = 1; $i <= $count; $i++) {
    $result = 0;
    $count2 = ceil((int)fgets(STDIN) / 2);

    for ($j = 1; $j <= $count2; $j++) {
        $result += 8 * $j * $j;
    }

    echo $result . PHP_EOL;
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers. Each $$$a_i$$$ is one of the six following numbers: $$$4, 8, 15, 16, 23, 42$$$.Your task is to remove the minimum number of elements to make this array good.An array of length $$$k$$$ is called good if $$$k$$$ is divisible by $$$6$$$ and it is possible to split it into $$$\frac{k}{6}$$$ subsequences $$$4, 8, 15, 16, 23, 42$$$.Examples of good arrays:  $$$[4, 8, 15, 16, 23, 42]$$$ (the whole array is a required sequence);  $$$[4, 8, 4, 15, 16, 8, 23, 15, 16, 42, 23, 42]$$$ (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements);  $$$[]$$$ (the empty array is good). Examples of bad arrays:   $$$[4, 8, 15, 16, 42, 23]$$$ (the order of elements should be exactly $$$4, 8, 15, 16, 23, 42$$$);  $$$[4, 8, 15, 16, 23, 42, 4]$$$ (the length of the array is not divisible by $$$6$$$);  $$$[4, 8, 15, 16, 23, 42, 4, 8, 15, 16, 23, 23]$$$ (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence).

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 5 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is one of the following numbers: $$$4, 8, 15, 16, 23, 42$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the minimum number of elements you have to remove to obtain a good array.

<?php
#1176B
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$amounts = [4 => 0, 8 => 0, 15 => 0, 16 => 0, 23 => 0, 42 => 0];
$delete = 0;
foreach ($arr as $value) {
    if (isset($amounts[$value])) {
        $amounts[$value]++;
    } else {
        $delete++;
    }
}
$min = min($amounts);
if ($min === 0) {
    $delete += array_sum($amounts);
} else {
    foreach ($amounts as $amount) {
        $delete += $amount - $min;
    }
}
echo $delete;

<?php
#1176C
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$amounts = [4 => 0, 8 => 0, 15 => 0, 16 => 0, 23 => 0, 42 => 0];
$prev = [8 => 4, 15 => 8, 16 => 15, 23 => 16, 42 => 23];
$delete = $group = 0;
foreach ($arr as $i => $value) {
    if ($value === '4') {
        $amounts[$value]++;
    } elseif (isset($amounts[$value]) && $amounts[$prev[$value]] > $amounts[$value]) {
        $amounts[$value]++;
    }
    if ($value === '42' && $amounts[42] > 0 && $amounts[$prev[$value]] === $amounts[$value]) {
        $group++;
    }
}
echo $n - $group * 6;

<?php
#1176C
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$amounts = [4 => 0, 8 => 0, 15 => 0, 16 => 0, 23 => 0, 42 => 0];
$prev = [8 => 4, 15 => 8, 16 => 15, 23 => 16, 42 => 23];
$delete = $group = 0;
foreach ($arr as $i => $value) {
    if ($value === '4') {
        $amounts[$value]++;
    } elseif (isset($amounts[$value]) && $amounts[$prev[$value]] > $amounts[$value]) {
        $amounts[$value]++;
    }
    if ($value === '42' && $amounts[$prev[$value]] === $amounts[$value]) {
        $group++;
    }
}
echo $n - $group * 6;

<?php
#1176C
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$amounts = [4 => 0, 8 => 0, 15 => 0, 16 => 0, 23 => 0, 42 => 0];
$prev = [8 => 4, 15 => 8, 16 => 15, 23 => 16, 42 => 23];
$delete = $group = 0;
foreach ($arr as $i => $value) {
    if ($value === 4) {
        $amounts[$value]++;
    } elseif (isset($amounts[$value]) && $amounts[$prev[$value]] > $amounts[$value]) {
        $amounts[$value]++;
    }
    if ($value === 42 && $amounts[$prev[$value]] === $amounts[$value]) {
        $group++;
    }
}
echo $n - $group * 6;

<?php
#1176C
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$amounts = [4 => 0, 8 => 0, 15 => 0, 16 => 0, 23 => 0, 42 => 0];
$prev = [8 => 4, 15 => 8, 16 => 15, 23 => 16, 42 => 23];
$delete = $group = 0;
foreach ($arr as $i => $value) {
    if ($value === '4') {
        $amounts[$value]++;
    } elseif (isset($amounts[$value]) && $amounts[$prev[$value]] > $amounts[$value]) {
        $amounts[$value]++;
    }
    if ($value === '42' && $amounts[42] > 0 && $amounts[$prev[$value]] === $amounts[$value]) {
        $group++;
    }
}
var_dump($amounts);
echo $n - $group * 6;


"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme.""Little Alena got an array as a birthday present..."The array b of length n is obtained from the array a of length n and two integers l and r (l ≤ r) using the following procedure:b1 = b2 = b3 = b4 = 0.For all 5 ≤ i ≤ n:   bi = 0 if ai, ai - 1, ai - 2, ai - 3, ai - 4 > r and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 1  bi = 1 if ai, ai - 1, ai - 2, ai - 3, ai - 4 < l and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 0  bi = bi - 1 otherwise You are given arrays a and b' of the same length. Find two integers l and r (l ≤ r), such that applying the algorithm described above will yield an array b equal to b'.It's guaranteed that the answer exists.

The first line of input contains a single integer n (5 ≤ n ≤ 105) — the length of a and b'. The second line of input contains n space separated integers a1, ..., an ( - 109 ≤ ai ≤ 109) — the elements of a. The third line of input contains a string of n characters, consisting of 0 and 1 — the elements of b'. Note that they are not separated by spaces.

Output two integers l and r ( - 109 ≤ l ≤ r ≤ 109), conforming to the requirements described above. If there are multiple solutions, output any of them. It's guaranteed that the answer exists.

NoteIn the first test case any pair of l and r pair is valid, if 6 ≤ l ≤ r ≤ 109, in that case b5 = 1, because a1, ..., a5 < l.


Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.In total the table Arthur bought has n legs, the length of the i-th leg is li.Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number di — the amount of energy that he spends to remove the i-th leg.A table with k legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5 legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.

The first line of the input contains integer n (1 ≤ n ≤ 105) — the initial number of legs in the table Arthur bought. The second line of the input contains a sequence of n integers li (1 ≤ li ≤ 105), where li is equal to the length of the i-th leg of the table. The third line of the input contains a sequence of n integers di (1 ≤ di ≤ 200), where di is the number of energy units that Arthur spends on removing the i-th leg off the table.

Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.

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

    $map = array();
    for ($i = 0; $i < $n; $i++) {
        $map[$a[$i]][] = $d[$i];
    }

    $f = array_fill(1, 200, 0);
    $ans = $sumd = array_sum($d);
    for ($i = 1; $i < 100001; $i++)
        if (isset($map[$i])) {
            $itr = &$map[$i];
            $cur = 0;
            foreach($itr as $v) $cur += $v;
            $count = count($itr) - 1;
            for ($j = 200; $j > 0; $j--) {
                if ($count == 0) break;
                if ($f[$j] == 0) continue;
                $min = min($count, $f[$j]);
                $cur += $min * $j;
                $count -= $min;
            }
            foreach($itr as $v) $f[$v]++;
            $ans = min($ans, $sumd - $cur);
            $map[$i] = null;
        }
    echo $ans;

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

    $map = array();
    for ($i = 0; $i < $n; $i++) {
        $map[$a[$i]][] = $d[$i];
    }

    $f = array_fill(1, 200, 0);
    $ans = $sumd = array_sum($d);
    for ($i = 1; $i < 100001; $i++)
        if (isset($map[$i])) {
            $itr = &$map[$i];
            $cur = 0;
            foreach($itr as $v) $cur += $v;
            $count = count($itr) - 1;
            for ($j = 200; $j > 0; $j--) {
                if ($count == 0) break;
                if ($f[$j] == 0) continue;
                $min = min($count, $f[$j]);
                $cur += $min * $j;
                $count -= $min;
            }
            foreach($itr as $v) $f[$v]++;
            $ans = min($ans, $sumd - $cur);
        }
    echo $ans;

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

    $map = array();
    for ($i = 0; $i < $n; $i++) {
        $map[$a[$i]][] = $d[$i];
    }

    $f = array_fill(1, 200, 0);
    $ans = $sumd = array_sum($d);
    for ($i = 1; $i < 100001; $i++)
        if (isset($map[$i])) {
            $itr = &$map[$i];
            $cur = 0;
            foreach($itr as $v) $cur += $v;
            $count = count($itr) - 1;
            for ($j = 200; $j > 0; $j--) {
                if ($count == 0) break;
                if ($f[$j] == 0) continue;
                $min = min($count, $f[$j]);
                $cur += $min * $j;
                $count -= $min;
            }
            foreach($itr as $v) $f[$v]++;
            $ans = min($ans, $sumd - $cur);
            $itr = null;
        }
    echo $ans;


Given an array $$$a$$$ of length $$$n$$$ and an integer $$$k$$$, find the number of indices $$$1 \leq i \leq n - k$$$ such that the subarray $$$[a_i, \dots, a_{i+k}]$$$ with length $$$k+1$$$ (not with length $$$k$$$) has the following property:   If you multiply the first element by $$$2^0$$$, the second element by $$$2^1$$$, ..., and the ($$$k+1$$$)-st element by $$$2^k$$$, then this subarray is sorted in strictly increasing order.  More formally, count the number of indices $$$1 \leq i \leq n - k$$$ such that $$$$$$2^0 \cdot a_i < 2^1 \cdot a_{i+1} < 2^2 \cdot a_{i+2} < \dots < 2^k \cdot a_{i+k}.$$$$$$

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$, $$$1 \leq k < n$$$) — the length of the array and the number of inequalities. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array. The sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the number of indices satisfying the condition in the statement.

NoteIn the first test case, both subarrays satisfy the condition:   $$$i=1$$$: the subarray $$$[a_1,a_2,a_3] = [20,22,19]$$$, and $$$1 \cdot 20 < 2 \cdot 22 < 4 \cdot 19$$$.  $$$i=2$$$: the subarray $$$[a_2,a_3,a_4] = [22,19,84]$$$, and $$$1 \cdot 22 < 2 \cdot 19 < 4 \cdot 84$$$.  In the second test case, three subarrays satisfy the condition:   $$$i=1$$$: the subarray $$$[a_1,a_2] = [9,5]$$$, and $$$1 \cdot 9 < 2 \cdot 5$$$.  $$$i=2$$$: the subarray $$$[a_2,a_3] = [5,3]$$$, and $$$1 \cdot 5 < 2 \cdot 3$$$.  $$$i=3$$$: the subarray $$$[a_3,a_4] = [3,2]$$$, and $$$1 \cdot 3 < 2 \cdot 2$$$.  $$$i=4$$$: the subarray $$$[a_4,a_5] = [2,1]$$$, but $$$1 \cdot 2 = 2 \cdot 1$$$, so this subarray doesn't satisfy the condition.


Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence a1, a2, ..., an, where ai is a band, which performs the i-th song. Polycarp likes bands with the numbers from 1 to m, but he doesn't really like others. We define as bj the number of songs the group j is going to perform tomorrow. Polycarp wants to change the playlist in such a way that the minimum among the numbers b1, b2, ..., bm will be as large as possible.Find this maximum possible value of the minimum among the bj (1 ≤ j ≤ m), and the minimum number of changes in the playlist Polycarp needs to make to achieve it. One change in the playlist is a replacement of the performer of the i-th song with any other group.

The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 2000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the performer of the i-th song.

In the first line print two integers: the maximum possible value of the minimum among the bj (1 ≤ j ≤ m), where bj is the number of songs in the changed playlist performed by the j-th band, and the minimum number of changes in the playlist Polycarp needs to make. In the second line print the changed playlist. If there are multiple answers, print any of them.

NoteIn the first sample, after Polycarp's changes the first band performs two songs (b1 = 2), and the second band also performs two songs (b2 = 2). Thus, the minimum of these values equals to 2. It is impossible to achieve a higher minimum value by any changes in the playlist. In the second sample, after Polycarp's changes the first band performs two songs (b1 = 2), the second band performs three songs (b2 = 3), and the third band also performs two songs (b3 = 2). Thus, the best minimum value is 2.