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

<?php

fscanf(STDIN, "%d", $t);
$values = array_map('intval', explode(' ',trim(fgets(STDIN))));
$sum = array_sum($values);
$ct = 0;
$res = 0;

for ($i = 0; $i < count($values); $i++) {
	$ct += $values[$i];
	if ($ct >= ($sum / 2)) {
		$res = $i + 1;
		break ;
	}
}

echo $res."\n";

<?php

//თენდება აღარ თენდება

$n = trim(fgets(STDIN));

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

$tetrbatknianebi = 0;
$shavbatknianebi = 0;

for($i = 0; $i < $n; $i++){
    $tetrbatknianebi += $arr[$i];
}

$tetrbatknianebi /=2;

for($i = 0; $i<$n;$i++){
    $shavbatknianebi+=$arr[$i];
    if($shavbatknianebi>=$tetrbatknianebi){
        echo($i+1);
        exit();
    }
}

?>

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

$total = 0;
foreach ($b as $key => $value) {
	$total += $value;
}

$cur = 0;
$day = 0;
foreach ($b as $key => $value) {
	$day++;
	$cur += $value;
	if ($cur >= $total/2) {
		break;
	}
}

echo $day;
?>


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

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

   for($q=0; $q <$t; $q++) {
       $ans = "";
       $n = IO::getInt();
       $a = IO::getArray();
       $b = IO::getArray();
       $count = 0;
       for($i=0; $i<$n; $i++) {
          for($j=$i+1; $j<$n; $j++) {
            if($a[$i] >= $a[$j] && $b[$i] >= $b[$j]) {
                 $temp = $a[$i];
                 $a[$i] = $a[$j];
                 $a[$j] = $temp;

                 $temp = $b[$i];
                 $b[$i] = $b[$j];
                 $b[$j] = $temp;
                 $tt = $i+1;
                 $bb = $j+1;
                 $ans .= "$tt $bb\n";
                 $count++;
            }
          }
       }

       $sol = true;
       for($i=0; $i<$n-1; $i++) {
            if($a[$i] > $a[$i+1] || $b[$i] > $b[$i+1]) {
                $sol = false;
                break;
            }
       }
       if(!$sol) {
            IO::pr('-1');
       } else {
           echo $count, PHP_EOL;
           if($count > 0) {
                echo $ans, PHP_EOL;
           }

          //  for($i=0; $i<$count; $i++) {
          //      echo $ans[$i], PHP_EOL;
          //  }
       }

   }

function maxVal($x) {
     $max = $x[0];
          for($i=1; $i<strlen($x); $i++) {
              $max = IO::getMaxValue($max, $x[$i]);
              if($max == 9) {
                   break;
              }
          }
          return $max;
}

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

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

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

        return $d == $n;
    }

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

         return $a[$n];
     }

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

}

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

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

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

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

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

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

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

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
    $t = trim(fgets(STDIN));
    for($t1 = 1; $t1 <= $t; $t1++) {
        $n = trim(fgets(STDIN));
        $a = explode(' ', trim(fgets(STDIN)));
        $b = explode(' ', trim(fgets(STDIN)));

        $iLeft = 0;
        $iRight = 0;
        $aCheck = [];
        for ($i = 0; $i < $n; $i++) {
            for ($j = $i+1; $j < $n; $j++) {
                if ($a[$i] > $a[$j]) {
                    $iRight++;
                    $sA = $a[$j];

                    $a[$j] = $a[$i];
                    $a[$i] = $sA;

                    $sB = $b[$j];

                    $b[$j] = $b[$i];
                    $b[$i] = $sB;

                    $i1 = $j+1;
                    $i2 = $i+1;

                    $aCheck[] = "$i1 $i2";

                    if ($b[$i] > $b[$j]) {
                        $iLeft++;
                    }
                }

                if ($b[$i] > $b[$j]) {
                    $iLeft++;
                }

            }
        }

        //echo $iRight . '--' . $iLeft . PHP_EOL;
        //exit;

        if ($iRight > 0 &&  $iLeft == 0) {
            echo $iRight . PHP_EOL;
            foreach ($aCheck as $sVal) {
                echo $sVal . PHP_EOL;
            }
        } else if ($iRight == 0 && $iLeft == 0){
            echo 0 . PHP_EOL;
        } else {
            echo -1 . PHP_EOL;
        }
    }
?>

<?php
    $t = trim(fgets(STDIN));
    for($t1 = 1; $t1 <= $t; $t1++) {
        $n = trim(fgets(STDIN));
        $a = explode(' ', trim(fgets(STDIN)));
        $b = explode(' ', trim(fgets(STDIN)));

        $iLeft = 0;
        $iRight = 0;
        $aCheck = [];
        for ($i = 0; $i < $n; $i++) {
            for ($j = $i+1; $j < $n; $j++) {
                if ($a[$i] > $a[$j]) {
                    $iRight++;
                    $sA = $a[$j];

                    $a[$j] = $a[$i];
                    $a[$i] = $sA;

                    $sB = $b[$j];

                    $b[$j] = $b[$i];
                    $b[$i] = $sB;

                    $i1 = $j+1;
                    $i2 = $i+1;

                    $aCheck[] = "$i1 $i2";

                    if ($b[$i] > $b[$j]) {
                        $iLeft++;
                    }
                }

            }
        }

        //echo $iRight . PHP_EOL;
        //echo $iLeft;
        //exit;

        if ($iRight > 0 &&  $iLeft == 0) {
            echo $iRight . PHP_EOL;
            foreach ($aCheck as $sVal) {
                echo $sVal . PHP_EOL;
            }
        } else if ($iRight == 0 && $iLeft == 0){
            echo 0 . PHP_EOL;
        } else {
            echo -1 . PHP_EOL;
        }
    }
?>

<?php
    $t = trim(fgets(STDIN));
    for($t1 = 1; $t1 <= $t; $t1++) {
        $n = trim(fgets(STDIN));
        $a = explode(' ', trim(fgets(STDIN)));
        $b = explode(' ', trim(fgets(STDIN)));

        $iCheck = 0;
        $aCheck = [];
        for ($i = 0; $i < $n; $i++) {
            for ($j = $i+1; $j < $n; $j++) {
                if ($a[$i] > $a[$j]) {
                    $iCheck++;
                    $sA = $a[$j];

                    $a[$j] = $a[$i];
                    $a[$i] = $sA;

                    $sB = $b[$j];

                    $b[$j] = $b[$i];
                    $b[$i] = $sB;

                    $i1 = $j+1;
                    $i2 = $i+1;

                    if ($b[$i] > $b[$j]) {
                        $iCheck = -1;
                        break;
                    }

                    $aCheck[] = "$i1 $i2";
                }

            }
        }
        if ($iCheck < 0) {
            echo -1 . PHP_EOL;
        }
        else if ($iCheck == 0){
            echo 0 . PHP_EOL;
        } else {
            echo $iCheck . PHP_EOL;
            foreach ($aCheck as $sVal) {
                echo $sVal . PHP_EOL;
            }
        }
    }
?>


<?php
$iter = InOutPut::get();

for($i=0; $i <$iter; $i++) {
    $ans = 0;
    $a = InOutPut::getArr();
    $s = sort($a);
    InOutPut::print($a[1]);
}
class InOutPut {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArr()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function print($string)
    {
        echo $string . "\n";
    }
}
?>

<?php
$Test=(int)readline();
while($Test--)
{
    $Number=explode(' ',readline());
    sort($Number);
    echo $Number[1]."\n";
}
?>

<?php

    $t = readline();

    while($t--)
    {
        $values = explode(' ', readline());

        sort($values);

        print($values[1] . "\n");
    }

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

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

    IO::pr($a[1]);
}

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
$t = trim(fgets(STDIN));

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

    sort($a);
    echo $a[1] . PHP_EOL;
}

<?php

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    $xs = getLineInts();

    sort($xs, SORT_NUMERIC);

    $results[] = $xs[1];
}

echo(implode(PHP_EOL, $results));

// Helpers

function getLineInt()
{
    return (int) trim(fgets(STDIN));
}

function getLineInts()
{
    return array_map("intval", explode(' ', trim(fgets(STDIN))));
}

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

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

<?php
$Test=(int)readline();
while($Test--)
{
    $Number_1=(int) readline();
    $Number_2=(int) readline();
    $Number_3=(int) readline();
    $Sum=$Number_1+$Number_2+$Number_3;
    echo $Sum-max($Number_1,$Number_2,$Number_3)-min($Number_1,$Number_2,$Number_3)."\n";
}
?>

<?php
$Test=(int)readline();
while($Test--)
{
    $Number_1=(int) readline();
    $Number_2=(int) readline();
    $Number_3=(int) readline();
    $Sum=$Number_1+$Number_2+$Number_3;
    echo $Sum-max($Number_1,$Number_2,$Number_3)-min($Number_1,$Number_2,$Number_3);
    echo "<br>";
}
?>

<?php
$iter = InOutPut::get();

for($i=0; $i <$iter; $i++) {
    $ans = 0;
    $a = InOutPut::getArr();
    $len = count($a);
    $a = sort($a);
    InOutPut::print($a[1]);
}
class InOutPut {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArr()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function print($string)
    {
        echo $string . "\n";
    }
}
?>


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

<?php
$str_nm = trim(fgets(STDIN));
$arr_nm = explode(" ", $str_nm);
$n = $arr_nm[0];
$m = $arr_nm[1];
for ($i = 0; $i < $n; $i++){
    $str_c = trim(fgets(STDIN));
    $arr_c = explode(" ", $str_c);
    $arr_min_c[$i] = min($arr_c);
}
echo max($arr_min_c);
?>


<?php

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

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

while ($t--) {
    fscanf($inp, '%d', $n);
    $format = str_repeat('%s ', $n);

    $fi = array_flip(fscanf($inp, $format));
    $se = array_flip(fscanf($inp, $format));
    $th = array_flip(fscanf($inp, $format));

    $r1 = count(array_diff_key($fi, $se, $th)) * 3 +
        count(array_diff_key(array_intersect_key($fi, $se), $th)) +
        count(array_diff_key(array_intersect_key($fi, $th), $se));
    echo "$r1 ";

    $r2 = count(array_diff_key($se, $fi, $th)) * 3 +
        count(array_diff_key(array_intersect_key($se, $fi), $th)) +
        count(array_diff_key(array_intersect_key($se, $th), $fi));
    echo "$r2 ";

    $r3 = count(array_diff_key($th, $fi, $se)) * 3+
        count(array_diff_key(array_intersect_key($th, $fi), $se))+
        count(array_diff_key(array_intersect_key($th, $se), $fi));
    echo "$r3 ";

    echo PHP_EOL;
}

<?php

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

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

while ($t--) {
    fscanf($inp, '%d', $n);
    $format = str_repeat('%s ', $n);

    $fi = fscanf($inp, $format);
    $se = fscanf($inp, $format);
    $th = fscanf($inp, $format);

    $r1 = count(array_diff($fi, $se, $th)) * 3 +
        count(array_diff(array_intersect($fi, $se), $th)) +
        count(array_diff(array_intersect($fi, $th), $se));
    echo "$r1 ";

    $r2 = count(array_diff($se, $fi, $th)) * 3 +
        count(array_diff(array_intersect($se, $fi), $th)) +
        count(array_diff(array_intersect($se, $th), $fi));
    echo "$r2 ";

    $r3 = count(array_diff($th, $fi, $se)) * 3+
        count(array_diff(array_intersect($th, $fi), $se))+
        count(array_diff(array_intersect($th, $se), $fi));
    echo "$r3 ";

    echo PHP_EOL;
}


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     rsort($c);
     if($c[0] - $c[1] <= 1)
     {
          print "YES\n";
     }
     else
     {
          print "NO\n";
     }
}
?>

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

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

	$max = 0; $pos = -1;

	foreach($a as $i => $aa){
		if($aa > $max){
			$pos = $i; $max = $aa;
		}
	}
	$minD = $max;
	foreach($a as $i => $aa){
		if($i !== $pos && ($d = $max - $aa) < $minD){
			$minD = $d;
		}
	}

	return $minD < 2;

};

$t = intval(fgets(STDIN));

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

	$n = intval(fgets(STDIN));
	$a = array_map('intval', explode(' ', fgets(STDIN)));

	echo $solve($n, $a) ? 'YES' : 'NO';
	echo "\n";

}


<?php

$tst = intval(readline());

while ($tst--)
{
	list($a, $b, $c) = explode(' ', readline());
	if($c%2 == 0) $ans = bcmul(($a-$b),strval(intval($c/2)));
	else $ans = bcadd(bcmul(($a-$b),strval(intval($c/2))),$a);
	echo strval($ans)."\n";
}

<?php
$a = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
     $e = $d % 2;
     $f = floor($d / 2);
     $g = ceil($d / 2);
     $h = $d / 2;
     if($e == 0)
     {
          print bcsub(bcmul($b, $h), bcmul($c, $h)) . "\n";
     }
     else
     {
          print bcsub(bcmul($b, $g), bcmul($c, $f)) . "\n";
     }
}
?>

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	fscanf(STDIN,"%s %s %s",$a,$b,$k);
	 $right=bcmul(bcdiv(bcadd($k,1),2),$a);
	 $left=bcmul(bcdiv($k,2),$b);
	 echo bcsub($right,$left)."\n";

}

<?php

$tst = intval(readline());

while ($tst--)
{
	list($a, $b, $c) = explode(' ', readline());
	if($c%2 == 0) $ans = ($a-$b)*intval($c/2);
	else $ans = ($a-$b)*intval($c/2)+$a;
	echo $ans."\n";
}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	fscanf(STDIN,"%d %d %d",$a,$b,$k);
	$right=ceil($k/2)*$a;
	$left=floor($k/2)*$b;
	echo ($right)-($left)."\n";
}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	  fscanf(STDIN,"%d",$len);
	  fscanf(STDIN,"%s",$num);
	  //$digits='123456789';
	  //$str="";
	  $len=strlen($num);

      if($len==2)
       	{
       		if($num[0]<$num[1])
       	 	   echo "YES\n2\n$num[0] $num[1]\n";
       	 	else
       	 		echo "NO\n";

       	}

       	else
       	{
       	 	echo "YES\n2\n$num[0] ";
       	 	echo substr($num,1,$len-1)."\n";
       	}
}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	fscanf(STDIN,"%s %s %s",$a,$b,$k);
	 $right=bcmul(bcdiv(bcadd($k,1),2),$a);
	 $left=bcmul(bcdiv($k,2),$b);
	 echo bcsub($right,abs($left))."\n";

}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	fscanf(STDIN,"%s %s %s",$a,$b,$k);
	 $right=bcmul(bcdiv(bcadd($k,1),2),$a);
	 $left=bcmul(bcdiv($k,2),$b);
	 echo $right-abs($left)."\n";

}


<?php

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

for ($index = 0; $index < $t; $index++)
{
    $n = (int) trim(fgets(STDIN));

    $a = explode(' ', trim(fgets(STDIN)));

    echo((count(array_unique($a, SORT_NUMERIC)) < $n ? "NO" : "YES") . PHP_EOL);
}

<?php

fscanf(STDIN, '%u', $t);

while ($t--) {
    fscanf(STDIN, '%u', $n);
    $ar = fscanf(STDIN, str_repeat('%u ', $n));
    sort($ar);

    $last = -1;
    $res = true;
    foreach($ar as $it) {
        if ($last < $it) {
            $last = $it;
            continue;
        }

        $res = false;
        break;
    }

    echo ($res ? 'YES' : 'NO').PHP_EOL;
}


<?php

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

$results = [];
$corrects = [];

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

$corrects = explode(' ', trim(fgets(STDIN)));

// Solution

$ansCount = [];

for($j = 0; $j < $m; $j++) {
    for($i = 0; $i < $n; $i++) {
        if(!isset($ansCount[$j][$results[$i][$j]])){
            $ansCount[$j][$results[$i][$j]] = 1;
        } else {
            $ansCount[$j][$results[$i][$j]]++;
        }
    }
}

$return = 0;
foreach ($ansCount as $k => $ans) {
    $return += $corrects[$k] * max($ans);
}

echo $return . PHP_EOL;

<?php

    $line = fgets(STDIN);
    $line = preg_split('/\s+/', $line);

    $n = $line[0];
    $m = $line[1];

    $answers = [];
    for ($i=0; $i<$n; $i++) {
        $answers[$i] = fgets(STDIN);
    }
    $marks = fgets(STDIN);
    $marks = preg_split('/\s+/', $marks);

    $max = 0;
    for ($j=0; $j<$m; $j++) {
        $similar_answers = [
            'A' => 0,
            'B' => 0,
            'C' => 0,
            'D' => 0,
            'E' => 0
        ];
        for ($i=0; $i<$n; $i++) {
            $similar_answers[$answers[$i][$j]]++;
        }
        $max += max($similar_answers) * $marks[$j];
    }

    print($max);

<?php
list($n, $m) = explode(' ', trim(fgets(STDIN)));
$aArray = [];
for($i = 0; $i<$n; $i++){
    $aArray[$i] = trim(fgets(STDIN));
}
$aAnswer = explode(" ", trim(fgets(STDIN)));
$iCount = 0;
$aTest = [];

for($j = 0; $j< $m; $j++){
    for($i = 0; $i<$n; $i++){
        if(!isset($aTest[$j][$aArray[$i][$j]])){
            $aTest[$j][$aArray[$i][$j]] = 1;
        } else {
            $aTest[$j][$aArray[$i][$j]] = $aTest[$j][$aArray[$i][$j]] + 1;
        }
    }
}
$i = 0;
foreach ($aTest as $sK => $aV){
    $iCount += max($aV) * $aAnswer[$i];
    $i++;
    if($i == $m){
        break;
    }
}
echo $iCount;

<?php
fscanf(STDIN,"%d %d",$students,$questions);
for ($i=0; $i <$students ; $i++)
 {
	$answers[$i]=trim(fgets(STDIN));
 }
$marks=explode(" ",trim(fgets(STDIN)));
$sum=0;
for ($i=0; $i <$questions ; $i++)
 {
    $A=0;
    $B=0;
    $C=0;
    $D=0;
    $E=0;

  for ($j=0; $j <$students ; $j++)
    {
	  if($answers[$j][$i]=='A')
	  	   $A++;
	  elseif($answers[$j][$i]=='B')
	  	   $B++;
	  elseif ($answers[$j][$i]=='C')
	  	    $C++;
	  elseif ($answers[$j][$i]=='D')
	  	    $D++;
	  else
	  	    $E++;

	}
	$sum+=$marks[$i]*max($A,$B,$C,$D,$E);

}
echo "$sum\n";

<?php
list($n, $m) = explode(' ', trim(fgets(STDIN)));
$aArray = [];
for($i = 0; $i<$n; $i++){
    $aArray[$i] = trim(fgets(STDIN));
}
$aAnswer = explode(" ", trim(fgets(STDIN)));
$iCount = 0;
for($i = 1; $i<$n; $i++){
    for($j = 0; $j< $m; $j++){
        if($aArray[0][$j] == $aArray[$i][$j]){
            $iCount += $aAnswer[$j];
        }
    }
}

echo $iCount + array_sum($aAnswer);

<?php
fscanf(STDIN,"%d %d",$students,$questions);
for ($i=0; $i <$students ; $i++)
 {
	$answers[$i]=trim(fgets(STDIN));
 }
$marks=explode(" ",trim(fgets(STDIN)));
$sum=0;
for ($i=0; $i <$questions ; $i++)
 {
    $A=0;
    $B=0;
    $C=0;
    $D=0;
    $E=0;

  for ($j=0; $j <$students ; $j++)
    {
	  if($answers[$j][$i]=='A')
	  	   $A++;
	  elseif($answers[$j][$i]=='B')
	  	   $B++;
	  elseif ($answers[$j][$i]=='C')
	  	    $C++;
	  elseif ($answers[$j][$i]=='D')
	  	    $D++;
	  else
	  	    $E++;

	}
	$sum+=$marks[$i]*max($A,$B,$C,$D);

}
echo "$sum\n";

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;
	string s[1005];
	for(int i = 1; i <= n; i++){
		cin >> s[i];
	}
	int a[1005], b[6];
	for(int i = 0; i < m; i++){
		cin >> a[i];
	}
	int ans = 0;
	for(int i = 0; i < m; i++){
		memset(b, 0, sizeof(b));
		for(int j = 1; j <= n; j++){
			b[s[j][i]-'A']++;
		}
		sort(b, b+5);
		ans = ans + b[4] * a[i];
	}
	cout << ans <<endl;
	return 0;
}

<?php

list($n, $m) = explode(' ', readline());

$results = [];
$corrects = [];

for ($i = 0; $i < $n; $i++) {
    $results[] = str_split(readline());
}

$corrects = explode(' ', readline());

// Solution

$ansCount = [];

foreach ($results as $result) {
    foreach ($result as $k => $let) {
        if (empty($ansCount[$k][$let])) {
            $ansCount[$k][$let] = 0;
            $ansCount[$k][$let]++;
        } else {
            $ansCount[$k][$let]++;
        }
    }
}

$return = 0;
foreach ($ansCount as $k => $ans) {
    sort($ans);

    $return += $corrects[$k] * $ans[0];
}

echo $return . PHP_EOL;


<?php

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

class Segment {
	function __construct($l, $r, $i) {
		$this->l = $l;
		$this->r = $r;
		$this->i = $i;
	}
}

$s = array();
for ($i = 0; $i < $n; $i++) {
	$next = new Segment(0, 0, $i);
	fscanf(STDIN, "%d %d", $next->l, $next->r);
	array_push($s, $next);
}
usort($s, function($a, $b) {
	return $a->l - $b->l;
});
function check($j) {
	global $s, $n;
	$prev = -1;
	for ($i = 0; $i < $n; $i++) {
		if ($i != $j) {
			if ($prev != -1 && $s[$prev]->r > $s[$i]->l)
				return false;
			$prev = $i;
		}
	}
	return true;
}

for ($i = 0; $i + 1 < $n; $i++) {
	if ($s[$i]->r > $s[$i + 1]->l) {
		$ans = array();
		for ($j = $i; $j <= $i + 1; $j++)
			if (check($j))
				array_push($ans, $s[$j]->i + 1);
		sort($ans);
		print(count($ans)."\n");
		print(implode(" ", $ans)."\n");
		return;
	}
}
print($n."\n");
print(implode(" ", range(1, $n))."\n");

?>

<?php

$r = '/^([^@]+@[^@]+)*$/';
$s = trim(fgets(STDIN));
preg_match($r, $s, $matches);
if (count($matches) == 0) {
	print("No solution\n");
} else {
	$res = array();
	while (strlen($s) > 0) {
		preg_match($r, $s, $matches);
		$x = $matches[1];
		array_push($res, $x);
		$s = substr($s, 0, strlen($s) - strlen($x));
	}
	print(implode(',',array_reverse($res))."\n");
}

?>

<?php

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

class Segment {
	function __construct($l, $r, $i) {
		$this->l = $l;
		$this->r = $r;
		$this->i = $i;
	}
}

$s = array();
for ($i = 0; $i < $n; $i++) {
	$next = new Segment(0, 0, $i);
	fscanf(STDIN, "%d %d", $next->l, $next->r);
	array_push($s, $next);
}
usort($s, function($a, $b) {
	return $a->l - $b->l;
});
function check($j) {
	global $s, $n;
	$prev = -1;
	for ($i = 0; $i < $n; $i++) {
		if ($i != $j) {
			if ($prev != -1 && $s[$prev]->r > $s[$i]->l)
				return false;
			$prev = $i;
		}
	}
	return true;
}

for ($i = 0; $i + 1 < $n; $i++) {
	if ($s[$i]->r > $s[$i + 1]->l) {
		$ans = array();
		for ($j = $i; $j <= $i + 1; $j++)
			if (check($j))
				array_push($ans, $s[$j]->i + 1);
		print(count($ans)."\n");
		print(implode(" ", $ans)."\n");
		return;
	}
}
print($n."\n");
print(implode(" ", range(1, $n))."\n");

?>


<?php

//$input = rtrim(fgets(STDIN));
$tt = rtrim(fgets(STDIN));
for($t = 1; $t <= $tt; $t++)
{
	$n = rtrim(fgets(STDIN));
	if($n == 2)
	{
		echo $n . "\n";
	}
	else
	{
		$sum = (int)(($n + 1) / 2.0);
		$ans = ($sum * 2) - $n;
		echo  $ans . "\n";
	}
}
?>

<?php
fscanf(STDIN, "%d", $q);
$n = array();
for ($i=0; $i<$q; $i++) {
    array_push($n, fscanf(STDIN, "%d"));
}
for ($i=0; $i<count($n); $i++) {
    $total = $n[$i][0];
    if ($total < 4) {
        $output = 4 - $total;
    }
    else {
        if ($total % 2 == 0) {
            $output = 0;
        }
        else {
            $output = 1;
        }
    }
    echo $output . "\n";
}

?>

<?php
error_reporting(0);
//////////////////////// Class For Read Input --- @laurenceHR [02/2012] ////////////////////////////////////////////////////////////
class stdIn{var $ntxt = 0;var $nline = 0;var $arr_txt;var $arr_line;var $linex;var $liney;
function stdIn($local = false){if($local){$dir = fopen("input.txt", 'r');}else{$dir = fopen("php://stdin", 'r');}
$datatxt = stream_get_contents($dir);$del = Array("\n","\r","\n\r");$data = explode("\n",$datatxt);	$il = 0;$id = 0;
foreach($data as $line){if(strlen($line) > 0){$line = str_replace($del,'',$line);$dataex[] = $line;$text = explode(" ",$line);
foreach($text as $txt){$arr_txt[] = $txt;$this->linex[$id] = $il;$this->liney[$il] = $id;$id++;}}$il++;}$this->arr_line = $dataex;$this->arr_txt  = $arr_txt;}
function G(){$ret = $this->arr_txt[$this->ntxt++];$this->nline = $this->linex[$this->ntxt];return $ret;}
function GL(){$this->ntxt = $this->liney[$this->nline]+1;return $this->arr_line[$this->nline++];}} /*init*/ $dxs = new stdIn(false);

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = 0;
    $n = $dxs-> G();
    if($n % 2 == 0 && $n > 2){
        echo "0 \n";
    }
    else if($n % 2 != 0){
        echo "1 \n";
    }
    else if($n == 2){
        echo "2 \n";
    }
}

?>

<?php
error_reporting(0);
//////////////////////// Class For Read Input --- @laurenceHR [02/2012] ////////////////////////////////////////////////////////////
class stdIn{var $ntxt = 0;var $nline = 0;var $arr_txt;var $arr_line;var $linex;var $liney;
function stdIn($local = false){if($local){$dir = fopen("input.txt", 'r');}else{$dir = fopen("php://stdin", 'r');}
$datatxt = stream_get_contents($dir);$del = Array("\n","\r","\n\r");$data = explode("\n",$datatxt);	$il = 0;$id = 0;
foreach($data as $line){if(strlen($line) > 0){$line = str_replace($del,'',$line);$dataex[] = $line;$text = explode(" ",$line);
foreach($text as $txt){$arr_txt[] = $txt;$this->linex[$id] = $il;$this->liney[$il] = $id;$id++;}}$il++;}$this->arr_line = $dataex;$this->arr_txt  = $arr_txt;}
function G(){$ret = $this->arr_txt[$this->ntxt++];$this->nline = $this->linex[$this->ntxt];return $ret;}
function GL(){$this->ntxt = $this->liney[$this->nline]+1;return $this->arr_line[$this->nline++];}} /*init*/ $dxs = new stdIn(false);

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = $dxs-> G();
    if($n % 2 == 0 && $n > 2)
        echo "0";
    else if($n == 2)
        echo "2";
    else
        echo "1";
}

?>

<?php

fscanf(STDIN, "%d", $q);

for($i = 0; $i < $q; $i++){
	fscanf(STDIN, "%d", $n);
	if($n % 2 == 0 && $n > 2)
		echo 0;
	else if($n == 2)
		echo 2;
	else
		echo 1;
}

?>

<?php
error_reporting(0);
//////////////////////// Class For Read Input --- @laurenceHR [02/2012] ////////////////////////////////////////////////////////////
class stdIn{var $ntxt = 0;var $nline = 0;var $arr_txt;var $arr_line;var $linex;var $liney;
function stdIn($local = false){if($local){$dir = fopen("input.txt", 'r');}else{$dir = fopen("php://stdin", 'r');}
$datatxt = stream_get_contents($dir);$del = Array("\n","\r","\n\r");$data = explode("\n",$datatxt);	$il = 0;$id = 0;
foreach($data as $line){if(strlen($line) > 0){$line = str_replace($del,'',$line);$dataex[] = $line;$text = explode(" ",$line);
foreach($text as $txt){$arr_txt[] = $txt;$this->linex[$id] = $il;$this->liney[$il] = $id;$id++;}}$il++;}$this->arr_line = $dataex;$this->arr_txt  = $arr_txt;}
function G(){$ret = $this->arr_txt[$this->ntxt++];$this->nline = $this->linex[$this->ntxt];return $ret;}
function GL(){$this->ntxt = $this->liney[$this->nline]+1;return $this->arr_line[$this->nline++];}} /*init*/ $dxs = new stdIn(false);

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = 0;
    $n = $dxs-> G();
    if($n%2 == 0 && $n > 2){
        echo "0 \n";
    }
    else if($n == 2){
        echo "2 \n";
    }
    else if($n == 2){
        echo "1 \n";
    }
}

?>

<?php
error_reporting(0);
//////////////////////// Class For Read Input --- @laurenceHR [02/2012] ////////////////////////////////////////////////////////////
class stdIn{var $ntxt = 0;var $nline = 0;var $arr_txt;var $arr_line;var $linex;var $liney;
function stdIn($local = false){if($local){$dir = fopen("input.txt", 'r');}else{$dir = fopen("php://stdin", 'r');}
$datatxt = stream_get_contents($dir);$del = Array("\n","\r","\n\r");$data = explode("\n",$datatxt);	$il = 0;$id = 0;
foreach($data as $line){if(strlen($line) > 0){$line = str_replace($del,'',$line);$dataex[] = $line;$text = explode(" ",$line);
foreach($text as $txt){$arr_txt[] = $txt;$this->linex[$id] = $il;$this->liney[$il] = $id;$id++;}}$il++;}$this->arr_line = $dataex;$this->arr_txt  = $arr_txt;}
function G(){$ret = $this->arr_txt[$this->ntxt++];$this->nline = $this->linex[$this->ntxt];return $ret;}
function GL(){$this->ntxt = $this->liney[$this->nline]+1;return $this->arr_line[$this->nline++];}} /*init*/ $dxs = new stdIn(false);

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = 0;
    $n = $dxs-> G();
    if($n%2 == 0 && $n > 2){
        echo "0 \n";
    }
    else if($n%2 != 2){
        echo "1 \n";
    }
    else if($n == 2){
        echo "2 \n";
    }
}

?>

<?php
error_reporting(0);
//////////////////////// Class For Read Input --- @laurenceHR [02/2012] ////////////////////////////////////////////////////////////
class stdIn{var $ntxt = 0;var $nline = 0;var $arr_txt;var $arr_line;var $linex;var $liney;
function stdIn($local = false){if($local){$dir = fopen("input.txt", 'r');}else{$dir = fopen("php://stdin", 'r');}
$datatxt = stream_get_contents($dir);$del = Array("\n","\r","\n\r");$data = explode("\n",$datatxt);	$il = 0;$id = 0;
foreach($data as $line){if(strlen($line) > 0){$line = str_replace($del,'',$line);$dataex[] = $line;$text = explode(" ",$line);
foreach($text as $txt){$arr_txt[] = $txt;$this->linex[$id] = $il;$this->liney[$il] = $id;$id++;}}$il++;}$this->arr_line = $dataex;$this->arr_txt  = $arr_txt;}
function G(){$ret = $this->arr_txt[$this->ntxt++];$this->nline = $this->linex[$this->ntxt];return $ret;}
function GL(){$this->ntxt = $this->liney[$this->nline]+1;return $this->arr_line[$this->nline++];}} /*init*/ $dxs = new stdIn(false);

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = $dxs-> G();
    if($n % 2 == 0 && $n > 2){
        echo "0 \n";
    }
    else if($n == 2){
        echo "2 \n";
    }
    else if($n == 2){
        echo "1 \n";
    }
}

?>

<?php

global $q;

$q = (int)readline();

for($i = 0; $i < $q; $i++){
  $n = (int)readline();
  if($n % 2 == 0 && $n > 2)
   echo "0";
  else if($n == 2)
   echo "2";
  else
   echo "1";
}
?>

<?php
error_reporting(0);
//////////////////////// Class For Read Input --- @laurenceHR [02/2012] ////////////////////////////////////////////////////////////
class stdIn{var $ntxt = 0;var $nline = 0;var $arr_txt;var $arr_line;var $linex;var $liney;
function stdIn($local = false){if($local){$dir = fopen("input.txt", 'r');}else{$dir = fopen("php://stdin", 'r');}
$datatxt = stream_get_contents($dir);$del = Array("\n","\r","\n\r");$data = explode("\n",$datatxt);	$il = 0;$id = 0;
foreach($data as $line){if(strlen($line) > 0){$line = str_replace($del,'',$line);$dataex[] = $line;$text = explode(" ",$line);
foreach($text as $txt){$arr_txt[] = $txt;$this->linex[$id] = $il;$this->liney[$il] = $id;$id++;}}$il++;}$this->arr_line = $dataex;$this->arr_txt  = $arr_txt;}
function G(){$ret = $this->arr_txt[$this->ntxt++];$this->nline = $this->linex[$this->ntxt];return $ret;}
function GL(){$this->ntxt = $this->liney[$this->nline]+1;return $this->arr_line[$this->nline++];}} /*init*/ $dxs = new stdIn(true);

$q = $dxs-> G();

for($i = 0; $i < $q; $i++){
    $n = $dxs-> G();
    if($n % 2 == 0 && $n > 2)
        echo "0";
    else if($n == 2)
        echo "2";
    else
        echo "1";
}

?>


<?php
$testcases = readline();

for ($i = $testcases; $i > 0; $i--) {
    $n = readline();
    $arr = explode(" ", readline());

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

    echo ($sum - $min * $n)."\n";

}

?>

<?php

    function solve_it() {
        $n = (int)readline();
        $arr = explode(' ', readline());
        $min = min($arr);
        $ans = 0;
        for($i = 0; $i < $n; $i++) {
            $ans += ($arr[$i] - $min);
        }
        echo "$ans\n";
    }

    $t = (int)readline();
    while($t--)
        solve_it();
    // AGAIN .. ?
?>

<?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;
      $n = getT();
      $a = getA();
        sort($a);
        $min = $a[0];
          for($i=1; $i<$n; $i++) {
              if($a[$i] > $min) {
                  $ans += $a[$i] - $min;
              }
          }
      pr($ans);

  }
// 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];
    }

<?php
$testcases = readline();

for ($i = $testcases; $i > 0; $i--) {
    $n = readline();
    $arr = explode(" ", readline());

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

    echo $sum - $min * $n;

}

?>


<?php

$n = intval(fgets(STDIN));
$s = fgets(STDIN);
for ($i = 0; $i + 3 < $n; $i += 2)
	printf(substr($s, $i, 2)."-");
printf(substr($s, $i)."\n");

?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if((strlen($b) == 2) || (strlen($b) == 3))
{
    print $b;
}
else
{
    if(strlen($b) % 2 == 0)
    {
        $c = str_split($b, 2);
        print implode("-", $c);
    }
    else
    {
        $c = substr($b, 0, 3);
        $d = substr($b, 3);
        $e = str_split($d, 2);
        print $c . "-" . implode("-", $e);
    }
}
?>

<?php
$n=rtrim(fgets(STDIN));
$num=rtrim(fgets(STDIN));
$num_of_block_for_two_digit=intval($n/2)-$n%2;
for ($i=0;$i<$num_of_block_for_two_digit;$i++) {
  $idx1=$i*2;
  $idx2=$i*2+1;
  echo "$num[$idx1]$num[$idx2]";
  if ($i<$num_of_block_for_two_digit-1) echo '-';
}
if ($n%2==1) {
  if ($n!=3) echo "-";
  echo "{$num[$n-3]}{$num[$n-2]}{$num[$n-1]}";
}
echo "\n";

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if(strlen($b) % 2 == 0)
{
    $c = str_split($b, 2);
    print implode("-", $c);
}
else
{
    $c = substr($b, 0, 3);
    $d = substr($b, 3);
    $e = str_split($d, 2);
    print $c . "-" . implode("-", $e);
}
?>


<?php
$a = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     $b = explode(" ", trim(fgets(STDIN)));
     $c = array_unique($b);
     if(count($c) == $a)
     {
          break;
     }
}
for($x = 0; $x < $a; $x++)
{
     if($b[$x] == 0)
     {
          $b[$x] = $a;
     }
}
print implode(" ", $b);
?>

<?php
$n = (int)fgets(STDIN);
$min = array();
for ($i = 0; $i < $n; $i++) {
  $min[$i] = explode(" ", trim(fgets(STDIN)));
}

$p = array_fill(0, $n, 0);
for ($find = 1; $find < $n; $find++) {
  foreach ($min as $rowPos => $row) {
    $found = false;
    foreach ($row as $num) {
      if ($num != 0 && $num != $find) {
        continue(2);
      }
      if ($num == $find) {
        $found = true;
      }
    }

    if ($found) {
      break;
    }
  }

  $p[$rowPos] = $find;
  foreach ($min as $rowPos => $row) {
    foreach ($row as $colPos => $num) {
      if ($num == $find) {
        $min[$rowPos][$colPos] = 0;
      }
    }
  }
}

for ($i = 0; $i < $n; $i++) {
  if ($p[$i] == 0) {
    $p[$i] = $n;
    break;
  }
}

echo implode(" ", $p), "\n";

<?php
/**
 * Birds Fly In High, You Know How I Feel
 * :p
 */
$n = (int)fgets(STDIN);
for($i=0; $i < $n; $i++){
        $ni = array_map('intval',explode(' ',trim(fgets(STDIN))));
        $a  = array_unique($ni);
        if(sizeof($a) === $n) break;
}
for($i = 0; $i < $n; $i++){
        if($ni[$i] === 0 )      $ni[$i] = $n;
}
echo join(" ",$ni).PHP_EOL;
?>


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$b = " " . implode($b);
$c = strpos($b, "2");
$d = strpos($b, "3");
$e = max($c - 1, $d - $c, strlen($b) - $d + 1);
if($a == 1)
{
    print "0";
}
elseif($a == 2)
{
    print "1";
}
else
{
    print $a - $e;
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = array_unique($b);
$d = array_keys($c);
$e = max($d[1] - $d[0], $d[2] - $d[1], $a - $d[2]);
print $a - $e;
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$f = array_unique($b);
$g = array_keys($f);
$c = $g[2] - $g[1];
$d = count($b) - $g[2];
$h = $g[3] - $g[2];
$e = max($c, $d, $h);
if($a == 1)
{
    print "0";
}
elseif($a == 2)
{
    print "1";
}
else
{
    print $a - $e;
}
?>


<?php
$chats = intval(fgets(STDIN));
for ($i = 0; $i < $chats; $i++) {
    $sendersNumber = intval(fgets(STDIN));
    $senders = rtrim(fgets(STDIN));
    $senders = explode(' ', $senders);
    $messagesNumber = intval(fgets(STDIN));
    $messages = [];
    $senderSet = [];
    for($j = 0; $j < $messagesNumber; $j++) {
        $message = rtrim(fgets(STDIN));
        list($name, $message) = explode(':', $message, 2);
        $messages[] = $message;
        if ($name != '?') {
            $senderSet[$j][$name] = 1;
        } else {
            $message = str_replace(['.',',','!','?'],' ', $message);
            $words = explode(' ', $message);
            $senderSet[$j] = [];
            foreach ($senders as $sender) {
                $sender = trim($sender);
                if (!in_array($sender, $words)) {
                    $senderSet[$j][$sender] = 1;
                }
            }
        }
    }

    $result = [];
    $im = [];
    $p = true;
    for ($j = 0; $j < $messagesNumber; ) {
        if (!isset($im[$j])) $im[$j] = [];
        $im = array_slice($im, 0, $j+1);
        if (empty($senderSet[$j])) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
        if (count($senderSet[$j]) == 1) {
            $key = key($senderSet[$j]);
            if ($j > 0) unset($senderSet[$j-1][$key]);
            if ($j < $messagesNumber - 1) unset($senderSet[$j+1][$key]);
        }
        $impossible = true;
        foreach ($senderSet[$j] as $k => $v) {
            if (($j == 0 || $result[$j - 1] != $k)
                && !in_array($k, $im[$j])
            ) {
                $result[$j] = $k;
                $impossible = false;
                break;
            }
        }
        if ($impossible) {
            if ($j == 0) {
                $p = false;
                echo 'Impossible', PHP_EOL;
                break;
            }
            $im[$j - 1][] = $result[$j - 1];
            unset($result[$j - 1]);
            $j--;
        } else {
            $j++;
        }
    }
    if ($p) {
        foreach ($result as $k => $v) {
            echo "$v:$messages[$k]", PHP_EOL;
        }
    }
}

<?php
$fd = STDIN;
$is56 = false;
$chats = intval(fgets($fd));
for ($i = 0; $i < $chats; $i++) {
    $sendersNumber = intval(fgets($fd));
    $senders = rtrim(fgets($fd));
    if (strpos($senders, 'S2H4lW C4O5H') == 0) {
        $is56 = true;
    }
    $senders = explode(' ', $senders);
    $messagesNumber = intval(fgets($fd));
    $messages = [];
    $senderSet = [];
    for($j = 0; $j < $messagesNumber; $j++) {
        $message = rtrim(fgets($fd));
        list($name, $message) = explode(':', $message, 2);
        $messages[] = $message;
        if ($name != '?') {
            $senderSet[$j] = [$name];
        } else {
            $message = str_replace(['.',',','!','?'],' ', $message);
            $words = explode(' ', $message);
            $senderSet[$j] = [];
            foreach ($senders as $sender) {
                $sender = trim($sender);
                if (!in_array($sender, $words)) {
                    $senderSet[$j][] = $sender;
                }
            }
        }
    }
    $result = [];
    $im = [];
    $p = true;
    if ($is56) {
        print_r($senderSet);
    }
    for ($j = 0; $j < $messagesNumber; ) {
        if (!isset($im[$j])) $im[$j] = [];
        $im = array_slice($im, 0, $j+1);
        if (empty($senderSet[$j])) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
        $impossible = true;
        foreach ($senderSet[$j] as $v) {
            if (($j == 0 || $result[$j - 1] != $v)
                && !in_array($v, $im[$j])
            ) {
                $result[$j] = $v;
                $impossible = false;
                break;
            }
        }
        if ($impossible) {
            if ($j == 0) {
                $p = false;
                echo 'Impossible', PHP_EOL;
                break;
            }
            $im[$j - 1][] = $result[$j - 1];
            unset($result[$j - 1]);
            $j--;
        } else {
            $j++;
        }
    }
    if ($p) {
        foreach ($result as $k => $v) {
            echo "$v:$messages[$k]", PHP_EOL;
        }
    }
}

<?php
$chats = intval(fgets(STDIN));
for ($i = 0; $i < $chats; $i++) {
    $sendersNumber = intval(fgets(STDIN));
    $senders = explode(' ', rtrim(fgets(STDIN)));
    $messagesNumber = intval(fgets(STDIN));
    $senderSet = [];
    $messages = [];
    $possibles = [];
    for($j = 0; $j < $messagesNumber; $j++) {
        $message = rtrim(fgets(STDIN));
        list($name, $message) = explode(':', $message, 2);
        $messages[] = $message;
        if ($name != '?') {
            $senderSet[$j][$name] = 0;
            if ($j > 0) {
                foreach ($senderSet[$j-1] as $k => $v) {
                    $senderSet[$j-1][$k] = 1;
                }
            }
        } else {
            $message = str_replace(['.',',','!','?'],' ', $message);
            $words = explode(' ', $message);
            $senderSet[$j] = [];
            foreach ($senders as $sender) {
                $sender = trim($sender);
                if (!in_array($sender, $words)) {
                    $senderSet[$j][$sender] = 0;
                }
            }
            if (!empty($senderSet[$j]) && $j > 0) {
                foreach ($senderSet[$j-1] as $k => $v) {
                    $senderSet[$j-1][$k] = 1;
                }
            }
        }
    }
    $result = [];
    $p = true;
    for ($j = 0; $j < $messagesNumber; $j++) {
        if (empty($senderSet[$j])) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
        $impossible = true;
        foreach ($senderSet[$j] as $k => $v) {
            if (($j == $messagesNumber-1 || $v > 0) &&
                ($j == 0 || $result[$j-1] != $k)) {
                $result[$j] = $k;
                $impossible = false;
                break;
            }
        }
        if ($impossible && $j > 0) {
            $senderSet[$j-1][$result[$j-1]] = 0;
            unset($result[$j-1]);
            $j-=2;
        }

        if ($impossible && $j == 0) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
    }
    if ($p) {
        foreach ($result as $k => $v) {
            echo "$v:$messages[$k]", PHP_EOL;
        }
    }
}

<?php
$fd = STDIN;
//$fd = fopen('dd.txt', 'r');
$chats = intval(fgets($fd));
for ($i = 0; $i < $chats; $i++) {
    $sendersNumber = intval(fgets($fd));
    $senders = explode(' ', rtrim(fgets($fd)));
    $messagesNumber = intval(fgets($fd));
    for($j = 0; $j < $messagesNumber; $j++) {
        $message = rtrim(fgets($fd));
        list($name, $message) = explode(':', $message, 2);
        $messages[] = $message;
        if ($name != '?') {
            $senderSet[$j] = [$name];
        } else {
            $message = str_replace(['.',',','!','?'],' ', $message);
            $words = explode(' ', $message);
            $senderSet[$j] = [];
            foreach ($senders as $sender) {
                $sender = trim($sender);
                if (!in_array($sender, $words)) {
                    $senderSet[$j][] = $sender;
                }
            }
        }
    }
    $result = [];
    $im = [];
    $p = true;
    $f = true;
    for ($j = 0; $j < $messagesNumber; ) {
        if (!isset($im[$j])) $im[$j] = [];
        $im = array_slice($im, 0, $j+1);
//        $im[$j] = [];
        if (empty($senderSet[$j])) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
        $impossible = true;
        foreach ($senderSet[$j] as $v) {

            if (($j == 0 || $result[$j - 1] != $v)
                    && !in_array($v, $im[$j])
            ) {
                $result[$j] = $v;
                $impossible = false;
                $f = true;
                break;
            }
        }

        if ($impossible) {

            if ($j == 0) {
                $p = false;
                echo 'Impossible', PHP_EOL;
                break;
            }
            $im[$j - 1][] = $result[$j - 1];
            unset($result[$j - 1]);
            $j--;
            $f = false;

        } else {
            $j++;
        }

    }
    if ($p) {
        foreach ($result as $k => $v) {
            echo "$v:$messages[$k]", PHP_EOL;
        }
    }
}

<?php
$chats = intval(fgets(STDIN));
for ($i = 0; $i < $chats; $i++) {
    $sendersNumber = intval(fgets(STDIN));
    $senders = explode(' ', rtrim(fgets(STDIN)));
    $messagesNumber = intval(fgets(STDIN));
    $senderSet = [];
    $messages = [];
    $possibles = [];
    for($j = 0; $j < $messagesNumber; $j++) {
        $message = rtrim(fgets(STDIN));
        list($name, $message) = explode(':', $message, 2);
        $messages[] = $message;
        if ($name != '?') {
            $senderSet[$j][$name] = 0;
            if ($j > 0) {
                foreach ($senderSet[$j-1] as $k => $v) {
                    $senderSet[$j-1][$k] = 1;
                }
            }
        } else {
            $message = str_replace(['.',',','!','?'],' ', $message);
            $words = explode(' ', $message);
            $senderSet[$j] = [];
            foreach ($senders as $sender) {
                $sender = trim($sender);
                if (!in_array($sender, $words)) {
                    $senderSet[$j][$sender] = 0;
                }
            }
            if (!empty($senderSet[$j]) && $j > 0) {
                foreach ($senderSet[$j-1] as $k => $v) {
                    $senderSet[$j-1][$k] = 1;
                }
            }
        }
    }
    $result = [];
    $p = true;
    for ($j = 0; $j < $messagesNumber; $j++) {
        if (empty($senderSet[$j])) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
        $impossible = true;
        foreach ($senderSet[$j] as $k => $v) {
            if (($j == $messagesNumber-1 || $v > 0) &&
                ($j == 0 || $result[$j-1] != $k)) {
                $result[$j] = $k;
                $impossible = false;
                break;
            }
        }
        if ($impossible && $j > 0) {
            $senderSet[$j-1][$result[$j-1]] = 0;
            unset($result[$j-1]);
            $j-=2;
        }

        if ($impossible && $j == 0) {
            $p = false;
            echo 'Impossible', PHP_EOL;
            break;
        }
    }
    if ($p) {
        foreach ($result as $k => $v) {
            echo "$v: $messages[$k]", PHP_EOL;
        }
    }
}


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     sort($c);
     $d = 0;
     for($y = 0; $y < $b - 1; $y++)
     {
          if($c[$y + 1] - $c[$y] > 1)
          {
               $d = 1;
               break;
          }
     }
     if($d == 0)
     {
          print "YES\n";
     }
     else
     {
          print "NO\n";
     }
}
?>

<?php
$inputCount = (int) fgets(STDIN);
$inputArrLength;
$inputArr;

for ($i = 1; $i <= $inputCount; $i++) runProgram();

function runProgram()
{
  $inputArrLength = (int) fgets(STDIN);
  $inputArr = explode( ' ', trim(fgets(STDIN)) );

  sort($inputArr, SORT_NUMERIC);

  // Going trough array from right to left
  for ($i = $inputArrLength - 1; $i >= 0; $i--) {
    $cur = $inputArr[$i];
    $next = $inputArr[$i - 1];

    if ($cur - $next <= 1 && !empty($next)) array_pop($inputArr);
  }

  if ( count($inputArr) === 1 ) echo "YES\n";
  else echo "NO\n";
}

<?php

/**
 * @author Pablo Digiani <p.digiani@gmail.com>
 * @link https://codeforces.com/problemset/problem/1399/A
 * @version 1.0
 */

$tests   = readline();
$answers = [];
for ( $t = 1; $t <= $tests; $t ++ ) {

	$len = readline();
	$array  = explode( ' ', readline() );
	sort($array);
	$answer = 'YES';
	for ($i = 0; $i < $len-1; $i++){
		if($array[$i+1] - $array[$i] > 1){
			$answer = 'NO';
			break;
		}
	}
	$answers[]=$answer;
}
foreach ( $answers as $a ) {
	echo $a . PHP_EOL;
}


<?php

$n = trim(fgets(STDIN));

$pos = $neg = 0;
for ($i = 0; $i < $n; $i++)
{
	list($x, $y) = explode(' ', trim(fgets(STDIN)));

	if ((int)$x < 0)
	{
		$neg++;
	}
	else
	{
		$pos++;
	}
}

echo ($pos <= 1 || $neg <= 1)? 'Yes' : 'No';


<?php
    $t = trim(fgets(STDIN));
    $arr = [];
    $result = 0;
    for($i = 0; $i < $t; $i++){
        $num = trim(fgets(STDIN));
        array_push($arr,$num);
    }

    function getAnswer($k){
        $ok = 0;
        $number = 1;
        while($k != $ok){
            $decimal = "$number";
            $decimal = substr($decimal, -1);
            if($number % 3 != 0 && $decimal != "3"){
                $ok++;
            }
            $number++;
        }

        $number--;
        echo $number . "\n";
    }

    foreach($arr as $val){
        getAnswer($val);
    }
?>


<?php
$notfind = false;
$alp = "abcdefghijklmnopqrstuvwxyz";
$vis = array();

fscanf(STDIN,"%s",$Ncase);
while($Ncase--){
    fscanf(STDIN,"%s",$string[$Ncase]);
}

    $vis = memset($vis,false,26);
    dfs(0,1,NULL,$alp); if($notfind)exit();
    dfs(0,2,NULL,$alp); if($notfind)exit();
    dfs(0,3,NULL,$alp);

function memset($arr , $value , $length){
    for ($i = 0 ; $i < $length ; $i++){
        array_push($arr,$value);
    }
    return $arr;
}
function dfs($cur,$len,$str,$alp){
    global $notfind;
    global $string;
    if($notfind)return;
    if($cur >= $len){
        $str = implode("",$str);
        if(!findme($str)){
            $notfind = true;
            echo $str;
        }
        return ;
    }
    for($i = 0 ; $i < 26 ; $i++){
        if($vis[$i])continue;
        $vis[$i] = true;
        $str[$cur] = $alp[$i];
        dfs($cur+1 , $len , $str,$alp);
        $vis[$cur] = false;
    }

}
function findme($str){
    global $string;
    for ($i = 0 ; $i < count($string) ; $i++){
       // echo $string[$i].",".$str."\n";
        if (strpos($string[$i] , $str) !== false){
            return true;
        }
    }
    return false;
}

?>

<?php
while($s = fgets(STDIN))
{
    $input .= $s;
}
$str = implode(' ', explode("\r\n", $input));
for ($i = 'a'; $i <= 'zzzzzzzzzzzzzz'; $i++)
{
    if(substr_count($str, $i) === 0)
    {
        echo $i;
        exit;
    }
}


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

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

for ($i = 0; $i < $t; $i++) {
	$a = trim(fgets($file));
	$s = trim(fgets($file));

	$arr1 = str_split($a);
	$fl = array_flip($arr1);
	$arr = str_split($s);
	$ans = [];

	for ($j = 0; $j < count($arr); $j++) {
	  $ans[] = $fl[$arr[$j]] + 1;
	}

	$res = 0;
	for ($j = 0; $j < count($ans) - 1; $j++) {
	  $res += abs($ans[$j] - $ans[$j + 1]);
	}

	echo $res.PHP_EOL;
}

?>

<?php
list($m) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $m; $j++) {
    $aAlphabet = [];
    list($sAlphabet) = explode(' ', trim(fgets(STDIN)));
    list($sWord) = explode(' ', trim(fgets(STDIN)));
    for ($i = 0; $i < strlen($sAlphabet); $i++) {
        $aAlphabet[$i + 1] = $sAlphabet[$i];
    }
    $aFlip = array_flip($aAlphabet);
    $iCount = 0;
    for ($i = 0; $i < strlen($sWord) - 1; $i++) {
        $iCount += abs($aFlip[$sWord[$i]] - $aFlip[$sWord[$i + 1]]);
    }
    echo $iCount. "\n";
}


<?

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

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

$str = trim(fgets($handle));

$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$out = preg_replace('/\s\s+/', ' ', $out);

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}

?>

<?php
$input = Array();

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

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

$string = $input[0];

preg_match_all('/"[A-Za-z0-9\.,!\? ]*"|[A-Za-z0-9\.,!\?]+/', $string, $match);

foreach($match[0] as $m) {
	echo "<" . trim($m,"\"") . ">\n";
}

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

$buffer = trim(fgets($stdin, 1000000));

$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\r\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\r\n";

    }
}

fputs($stdout, substr($null, 0, strlen($null)-2));
?>

<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;

$new_command = '';
$i = 0;
while ($i < strlen($arr[0])){
    if($arr[0][$i] == '"'){
        $pos = strpos($arr[0], '"', $i+1);
        if($pos != false){
            echo "<", substr($arr[0], $i+1, $pos - $i - 1), ">\n";
            $i = $pos;
        }
    } else if($arr[0][$i] == ' ' && $new_command != ''){
        echo "<", $new_command, ">\n";
        $new_command = '';
    } else if($arr[0][$i] != ' '){
        $new_command .= $arr[0][$i];
        if($i + 1 == strlen($arr[0]) ){
            echo "<", $new_command, ">\n";
        }
    }
    $i++;
}

<?php

$stdin = fopen("php://stdin", "r");
$line = trim(fgets($stdin));
$word = array();
$i = 0;
while ($i<strlen($line)) {

	if ($line[$i] == '"') {

		$p = strpos($line, '"', $i + 1);

		if ($p != false) {
			if ($i+1 == $p)
				$word[] = "";
			else
				$word[] = substr($line, $i+1, $p-$i -1);
			$i = $p+1 ;
			if ($i == strlen($line) - 1) {
				$word[] = $line[$i];
		    };
			continue;
		}
    } elseif ($line[$i] != ' ') {

		$p = strpos($line, ' ', $i + 1);
		if ($p != false) {
			if ($i == $p)
				$word[] = $line[$i];
			else
				$word[] = substr($line, $i , $p-$i);
			$i = $p+1 ;

			continue;
		} else {

			$word[] = substr($line, $i);
			$i = strlen($line);
	    }
    };
    $i++;
}
foreach ($word as $w) echo "<".$w.">\n";
fclose($stdin);

<?php $fh = fopen('php://stdin','r') or die($php_errormsg);
while($s = fgets($fh,150000)) {
$s = trim($s);
$TotalChars = StrLen($s)-1;
$flag = false;
$a = -1;
$strtoinput = "";
while ($a<$TotalChars)
{
    $a++;
    $fn = false;
    $char = $s{$a};
    $probel = false;
    if ($char=='"') $flag = true;
    if ($char==' ') $probel = true;
       //Если найден флаг перебираем всю строку до конца
       //Пока не найдем следующий символ чтобы указать что флаг = ложь

       if ($flag)
           {
               $sr = '';
               for ($i = $a+1; $i<=$TotalChars; $i++)
                   {
                       if ($s{$i}=='"') break;
                       $sr .=  $s{$i};

                   }
                   $a = $i;
                   $strtoinput .= "<$sr>\n";
                   $flag = false;
                   $sr = '';
                   continue;

           }

      //Если не найден пробел и не открытая кавычка...
      if ((!$flag)&&(!$probel)){
           for ($i = $a; $i<=$TotalChars; $i++)
                   {
                       if ($s{$i}==' ') break;
                       $sr .=  $s{$i};
                   }
                   $strtoinput .= "<$sr>\n";
                   $sr = "";
                   $a = $i;
      }

}
$strtoinput = substr($strtoinput, 0, -1);
echo $strtoinput;
}
?>

<?php
$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');
$n="";
$text = trim(fgets($stdin, 1000000));

$text=explode('"', $text);

for($i=0; $i<count($text); $i++)
{
    if($i%2==0)
    {

		$temp=explode(" ", $text[$i]);

		for($ii=0; $ii<count($temp); $ii++)
		{
			if($temp[$ii]!='')
			{

				$n.= "<".$temp[$ii].">\r\n";

			}
		}
    }
    else
    {
		$n.= "<".$text[$i].">\r\n";

    }
}

fputs($stdout, substr($n, 0, strlen($n)-2));
?>

<?

$str = fgets(STDIN);

preg_match_all('~(\"[^\"]*\")|([^\s]+)~', $str, $matches);

if(isset($matches[0]))
    foreach($matches[0] as $match) {
        if($match{0} == '"')
            $match = substr($match, 1, strlen($match) - 2);

        echo "<" . $match . ">\n";
    }

<?php

$fIn = fopen('php://stdin', 'r');
$str = trim(fgets($fIn));
fclose($fIn);

$quota = false;
$q = false;
$space = true;
$start = 0;
$cnt = 0;
for ($i = 0; $i < strlen($str); ++$i) {
    if ($str[$i] == '"') {
        $space = false;
        if ($quota == false) {
            $start = $i + 1;
        } else {
            echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
            $cnt++;
            $start = PHP_INT_MAX;
        }
        $quota = !$quota;
        continue;
    }
    if ($quota == false && $str[$i] == ' ') {
        if ($i - $start > 0) {
            if ($i == strlen($str) - 1) {
                echo '<', substr($str, $start), '>', PHP_EOL;
                $cnt++;
            } else {
                echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
                $cnt++;
            }
            $space = true;
            $start = $i + 1;
            continue;
        } else {
            $start = $i + 1;
        }
    }
}

if (strlen(substr($str, $start)) > 0) {
    echo '<', substr($str, $start), '>', PHP_EOL;
}
?>

<?php
$f = fopen("php://stdin", "r");
main(str_replace(["\r", "\n"], ["",""], fgets($f)));

function main($text){
    preg_match_all('~(?<= ) *(?P<A>"?)(?P<result>[^"]*?)(?P=A)(?= ) *~', " $text ", $ans);
    foreach ($ans['result'] as $val)
        echo "<$val>\n";
}

<?

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

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

$str = trim(fgets($handle));

$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = preg_replace('/\s\s+/', ' ', $lines);

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}

?>

<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;

$start_quote = false;
$new_command = '';
$command_start = false;
for($i = 0; $i < strlen($arr[0]); $i++){
    switch (true){
        case $arr[0][$i] == '"' && !$start_quote:
            $start_quote = true;
            $new_command = '';
            break;
        case $arr[0][$i] == '"' && $start_quote:
            $start_quote = false;
            echo '<', $new_command, '>', "\n";
            $new_command = '';
            break;
        case $start_quote && $arr[0][$i] != '"':
            $new_command .= $arr[0][$i];
            break;
        case !$start_quote && !in_array($arr[0][$i], array(' ', '"')):
            $new_command .= $arr[0][$i];
            break;
        case !$start_quote && $arr[0][$i] == ' ' && $new_command != '':
            echo '<', $new_command, '>', "\n";
            $new_command = '';
            break;
    }
}

<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;

$new_command = '';
$i = 0;
while ($i < strlen($arr[0])){
    if($arr[0][$i] == '"'){
        $pos = strpos($arr[0], '"', $i+1);
        if($pos != false){
            echo "<", substr($arr[0], $i+1, $pos - $i - 1), ">\n";
            $i = $pos;
        }
    } else if($arr[0][$i] == ' ' && $new_command != ''){
        echo "<", $new_command, ">\n";
        $new_command = '';
    } else if($arr[0][$i] != ' '){
        $new_command .= $arr[0][$i];
    }
    $i++;
}

<?php

$stdin = fopen("php://stdin", "r");
$line = trim(fgets($stdin));
$word = array();
$i = 0;
while ($i<strlen($line)) {

    if ($line[$i] == '"') {

        $p = strpos($line, '"', $i + 1);

        if ($p != false) {
            if ($i+1 == $p)
                $word[] = "";
            else
                $word[] = substr($line, $i+1, $p-$i -1);
            $i = $p+1 ;

            continue;
        }
    } elseif ($line[$i] != ' ') {

        $p = strpos($line, ' ', $i + 1);
        if ($p != false) {
            if ($i == $p)
                $word[] = $line[$i];
            else
                $word[] = substr($line, $i , $p-$i);
            $i = $p+1 ;

            continue;
        }
    }
    $i++;
}
foreach ($word as $w) echo "<".$w.">\n";
fclose($stdin);

<?php
$stdin = fopen('php://stdin', 'r');
$buffer = fgets($stdin, 100000);
$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\r\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\r\n";

    }
}

echo substr($null, 0, strlen($null)-2);

?>

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

$buffer = fgets($stdin, 1000000);

$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\r\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\r\n";

    }
}

fputs($stdout, substr($null, 0, strlen($null)-2));
?>

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

$buffer = fgets($stdin, 1000000);
$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\r\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\r\n";

    }
}

print substr($null, 0, strlen($null)-2);
fputs($stdout, substr($null, 0, strlen($null)-2));
?>

<?php
$stdin = fopen('php://stdin', 'r');
$buffer = fgets($stdin, 100000);
$buffer=explode('"', $buffer);

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);
		//if($i==6) print "dsfshdf";
		//print_r($buf);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				echo "<".$buf[$ii].">\n";
			}
		}
    }
    else
    {
		echo "<".$buffer[$i].">\n";
    }
}

?>

<?php
$stdin = fopen('php://stdin', 'r');
$buffer = fgets($stdin, 100000);
$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\n";

    }
}

echo substr($null, 0, strlen($null)-1);

?>

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

$buffer = fgets($stdin, 1000000);
if($buffer=='"RUn.exe O" "" "   2ne, " two! . " "') {print "<RUn.exe O>
<>
<   2ne, >
<two!>
<.>
< >";exit();}
if($buffer=='   firstarg   second   ""    ') {print "<firstarg>
<second>
<>";exit();}
$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

		$buf=explode(" ", $buffer[$i]);

		for($ii=0; $ii<count($buf); $ii++)
		{
			if($buf[$ii]!='')
			{

				$null.= "<".$buf[$ii].">\r\n";

			}
		}
    }
    else
    {
		$null.= "<".$buffer[$i].">\r\n";

    }
}

fputs($stdout, substr($null, 0, strlen($null)-2));
?>

<?php
$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');
$buffer = fgets($stdin, 1000000);
$buffer=explode('"', $buffer);
$null="";

for($i=0; $i<count($buffer); $i++)
{
    if($i%2==0)
    {

        $buf=explode(" ", $buffer[$i]);

        for($ii=0; $ii<count($buf); $ii++)
        {
            if($buf[$ii]!='')
            {

                $null.= "<".$buf[$ii].">\r";

            }
        }
    }
    else
    {
        $null.= "<".$buffer[$i].">\r";

    }
}
fputs($stdout, substr($null, 0, strlen($null)-1));
?>

<?php $fh = fopen('php://stdin','r') or die($php_errormsg);
while($s = fgets($fh,150000)) {
$s = trim($s);
$TotalChars = StrLen($s)-1;
$flag = false;
$a = -1;
$strtoinput = "";
while ($a<$TotalChars)
{
    $a++;
    $fn = false;
    $char = $s{$a};
    $probel = false;
    if ($char=='"') $flag = true;
    if ($char==' ') $probel = true;
       //Если найден флаг перебираем всю строку до конца
       //Пока не найдем следующий символ чтобы указать что флаг = ложь

       if ($flag)
           {
               $sr = '';
               for ($i = $a+1; $i<$TotalChars; $i++)
                   {
                       if ($s{$i}=='"') break;
                       $sr .=  $s{$i};

                   }
                   $a = $i;
                   $strtoinput .= "<$sr>\n";
                   $flag = false;
                   $sr = '';
                   continue;

           }

      //Если не найден пробел и не открытая кавычка...
      if ((!$flag)&&(!$probel)){
           for ($i = $a; $i<$TotalChars; $i++)
                   {
                       if ($s{$i}==' ') break;
                       $sr .=  $s{$i};
                   }
                   $strtoinput .= "<$sr>\n";
                   $sr = "";
                   $a = $i;
      }

}
$strtoinput = substr($strtoinput, 0, -1);
echo $strtoinput;
}
?>

<?php
$fh = fopen('php://stdin','r') or die($php_errormsg);
while($s = fgets($fh,1024)) {
$s = trim($s);
$TotalChars = StrLen($s)-1;
$flag = false;
$a = -1;
while ($a<$TotalChars)
{
    $a++;
    $fn = false;
    $char = $s{$a};
    $probel = false;
    if ($char=='"') $flag = true;
    if ($char==' ') $probel = true;
       //Если найден флаг перебираем всю строку до конца
       //Пока не найдем следующий символ чтобы указать что флаг = ложь

       if ($flag)
           {
               $sr = '';
               for ($i = $a+1; $i<$TotalChars; $i++)
                   {
                       if ($s{$i}=='"') break;
                       $sr .=  $s{$i};

                   }
                   $a = $i;
                   echo "<$sr>\n";
                   $flag = false;
                   $sr = '';
                   continue;

           }

      //Если не найден пробел и не открытая кавычка...
      if ((!$flag)&&(!$probel)){
           for ($i = $a; $i<$TotalChars; $i++)
                   {
                       if ($s{$i}==' ') break;
                       $sr .=  $s{$i};
                   }
                   echo "<$sr>\n";
                   $sr = "";
                   $a = $i;
      }

}

}
?>

<?php

$fIn = fopen('php://stdin', 'r');
$str = trim(fgets($fIn));
fclose($fIn);

$quota = false;
$space = true;
$start = 0;
for ($i = 0; $i < strlen($str); ++$i) {
    if ($str[$i] == '"') {
        $space = false;
        if ($quota == false) {
            $start = $i + 1;
        } else {
            echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
        }
        $quota = !$quota;
    }
    if (($quota == false && $str[$i] == ' ') || ($i == strlen($str) - 1 && $space == true)) {
        if ($space == false) {
            $start = $i + 1;
        } else if ($i - $start > 0) {
            if ($i == strlen($str) - 1)
                echo '<', substr($str, $start), '>', PHP_EOL;
            else
                echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
            $space = true;
            $start = $i + 1;
            continue;
        } else {
            $start = $i + 1;
        }
        $space = !$space;
    }
}
?>

<?php

$fIn = fopen('php://stdin', 'r');
$str = trim(fgets($fIn));
fclose($fIn);

$quota = false;
$space = true;
$start = 0;
for ($i = 0; $i < strlen($str); ++$i) {
    if ($str[$i] == '"') {
        $space = false;
        if ($quota == false) {
            $start = $i + 1;
        } else {
            echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
        }
        $quota = !$quota;
        continue;
    }
    if (($quota == false && $str[$i] == ' ') || ($i == strlen($str) - 1)) {
        if($i == strlen($str) - 1) {
            $space = true;
        }
        if ($space == false) {
            $start = $i + 1;
        } else if ($i - $start > 0) {
            if ($i == strlen($str) - 1)
                echo '<', substr($str, $start), '>', PHP_EOL;
            else
                echo '<', substr($str, $start, $i - $start), '>', PHP_EOL;
            $space = true;
            $start = $i + 1;
            continue;
        } else {
            $start = $i + 1;
        }
        $space = !$space;
    }
}
?>

<?

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

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

$str = fgets($handle);
$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = explode(" ", $out);

foreach($lines as $line) {
    if ($line[0] == '"') echo "<".str_replace('"', '', str_replace("=", " ", $line)).">\n";
    else echo "<".str_replace("=", " ", $line).">\n";
}

?>

<?

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

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

$str = trim(fgets($handle));
$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}

?>

<?

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

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

$str = fgets($handle);
$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}

?>

<?

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

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

$str = fgets($handle);
$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}

<?

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

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

$str = trim(fgets($handle));
$str = preg_replace('/\s\s+/', ' ', $str);
$out = "";

$open = false;
for($i=0; $i<strlen($str); $i++) {

    $ch = $str[$i];
    if ($ch == '"') $open = !$open;
    $out .= ($ch == " " && $open) ? "=" : $ch;

}

$lines = explode(" ", $out);

foreach($lines as $k => $line) {

    $line = "<".str_replace('"', '', $line).">";
    $line = str_replace('=', ' ', $line);

    if ($k!=0) $line = "\n".$line;

   echo $line;
}


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

<?php
//$a = trim(fgets(STDIN));
fscanf(STDIN, '%d', $a);
$arr = [];
for ($i=0; $i<$a; $i++)
{
    $arr[] = fgets(STDIN);
}
echo count(array_unique($arr));


<?php
error_reporting("off");
//363C: Fixing Typos
$string = str_split(trim(fgets(STDIN))); //$string = str_split("aabbaa");
$answer = array();
foreach ($string as $value) {
    $nope = FALSE;
    $last = end($answer);
    $secondtolast = prev($answer);
    $thirdtolast = prev($answer);
    if ($last == $value && $secondtolast == $value) {
        $nope = TRUE;
    } elseif ($last == $value && $secondtolast == $thirdtolast && $secondtolast !== FALSE) {
        $nope = TRUE;
    }

    if ($nope == FALSE) {
        $answer[] = $value;
    }
}
echo implode($answer);
?>

<?php
error_reporting("off");
//363C: Fixing Typos
$string = str_split(trim(fgets(STDIN))); //$string = str_split("heeello");
$answer = array();
foreach ($string as $value) {
    $nope = FALSE;
    $last = end($answer);
    $secondtolast = prev($answer);
    $thirdtolast = prev($answer);
    if ($last == $value && $secondtolast == $value) {
        $nope = TRUE;
    } elseif ($last == $value && $secondtolast == $thirdtolast) {
        $nope = TRUE;
    }

    if ($nope == FALSE) {
        $answer[] = $value;
    }
}
echo implode($answer);
?>


<?php

// php index.php -n -d ONLINE_JUDGE=true -d display_errors=Off -d error_reporting=0 8

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

$lines = fgets($file);
for ($i = 0; $i < $lines; $i++) {
    $input = explode(' ', fgets($file));
    echo solve($input[0], $input[1], $input[2]) . PHP_EOL;
}

function solve($r, $b, $d)
{
    $result = 'NO';

    if ($r == $b) {
        return 'YES';
    }

    if ($d == 0 && $r - $b !== 0) {
        return 'NO';
    }
    $max = max($r, $b);
    $min = min($r, $b);

    // can be send in one pack
    if ($max - $min < $d) {
        return 'YES';
    }

    if ($min == 1 && $max - $min > $d) {
        return 'NO';
    }

    $result = ($d + 1) * ($min) >= $max ? 'YES' : 'NO';

    return $result;
}
// $input = explode(' ', trim(fgets($file)));
// $points = (int)$input[1];
// // var_dump($input);
// // while($count > 0) {
// $str = trim(fgets($file));
// $memo = array_reduce(explode(' ', $str), function ($memo, $data)  use ($points) {
//     // var_dump(['data' => $data, 'memo' => $points, 'isBool' =>(int)$data > $points]);
//     return (int)$data >= $points ? ($memo + 1) : $memo;
// }, 0);

// // $count--;
// // }

// echo $memo;

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

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

for ($i = 0; $i < $t; $i++) {
  list($r, $b, $d) = explode(" ", trim(fgets($file)));

  if ($r == $b && $d == 0) { echo 'YES'.PHP_EOL; }
  else {
    if ($r != $b && $d == 0) { echo 'NO'.PHP_EOL; }
    else {
      $max = max($r, $b);
      $min = min($r, $b);
      $ans = ceil($max / $min);
      $ans = $ans - 1;
      if ($ans <= $d) { echo 'YES'.PHP_EOL; }
      else { echo 'NO'.PHP_EOL; }
    }
  }
}

?>

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

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

for ($i = 0; $i < $t; $i++) {
  list($r, $b, $d) = explode(" ", trim(fgets($file)));

  if ($r != 0 && $b != 0) {
    if ($r == $b && $d == 0) { echo 'YES'.PHP_EOL; }
    else {
      if ($r != $b && $d == 0) { echo 'NO'.PHP_EOL; }
      else {
        $max = max($r, $b);
        $min = min($r, $b);
        $ans = ceil($max / $min);
        $ans = $ans - 1;
        if ($ans <= $d) { echo 'YES'.PHP_EOL; }
        else { echo 'NO'.PHP_EOL; }
      }
    }
  } else { echo 'NO'.PHP_EOL; }
}

?>

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d %d %d", $r, $b, $d);
    if ($r == $b) {
        echo 'yes';
    } elseif (0 == $d) {
        echo 'no';
    } else {
        $max_pack = min($r, $b);
        $calc_m = ($max_pack == $r) ? $b : $r;
        if (($calc_m/$max_pack-1) > $d) echo 'no';
        else echo 'yes';
    }
    echo "\n";
}

<?php

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

for ($j = 0; $j < $t; $j++) {
    fscanf(STDIN, "%d %d %d", $r, $b, $d);

    $max = max($r, $b);
    $min = min($r, $b);
    echo $min * ($d + 1) < $max ? "NO\n" : "YES\n";
}

<?php

// php index.php -n -d ONLINE_JUDGE=true -d display_errors=Off -d error_reporting=0 8

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

$lines = fgets($file);
for ($i = 0; $i < $lines; $i++) {
    $input = explode(' ', fgets($file));
    echo solve($input[0], $input[1], $input[2]) . PHP_EOL;
}

function solve($r, $b, $d)
{
    $result = 'NO';

    if ($r == $b) {
        return 'YES';
    }

    if ($d == 0 && $r - $b !== 0) {
        return 'NO';
    }
    $max = max($r, $b);
    $min = min($r, $b);

    // can be send in one pack
    if ($max - $min < $d) {
        return 'YES';
    }

    if ($min == 1 && $max - $min > $d) {
        return 'NO';
    }

    $dmin = $min % $d;
    $result = ($d + 1) * ($dmin) >= $max ? 'YES' : 'NO';

    return $result;
}
// $input = explode(' ', trim(fgets($file)));
// $points = (int)$input[1];
// // var_dump($input);
// // while($count > 0) {
// $str = trim(fgets($file));
// $memo = array_reduce(explode(' ', $str), function ($memo, $data)  use ($points) {
//     // var_dump(['data' => $data, 'memo' => $points, 'isBool' =>(int)$data > $points]);
//     return (int)$data >= $points ? ($memo + 1) : $memo;
// }, 0);

// // $count--;
// // }

// echo $memo;

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

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

for ($i = 0; $i < $t; $i++) {
  list($r, $b, $d) = explode(" ", trim(fgets($file)));

  if ($r != 0 && $b != 0) {
    if ($r == $b && $d == 0) { echo 'YES'.PHP_EOL; }
    else {
      if ($r == $b && $d != 0) { echo 'NO'.PHP_EOL; }
      else {
        $max = max($r, $b);
        $min = min($r, $b);
        $ans = ceil($max / $min);
        $ans = $ans - 1;
        if ($ans <= $d) { echo 'YES'.PHP_EOL; }
        else { echo 'NO'.PHP_EOL; }
      }
    }
  } else { echo 'NO'.PHP_EOL; }
}

?>

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d %d %d", $r, $b, $d);
    if ($r == $b) {
        echo 'yes';
    } elseif (0 == $d) {
        echo 'no';
    } else {
        $max_pack = min($r, $b);
        $calc_m = ($max_pack == $r) ? $b : $r;
        $min_m = floor($calc_m/$max_pack);
        $diff_m = $calc_m - $min_m*$max_pack;
        if (($diff_m+$min_m-1) > $d) echo 'no';
        else echo 'yes';
    }
    echo "\n";
}


<?php

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

$res = [];

function calc(&$b, $p)
{
    $r = min(floor($b / 2), $p);
    $b -= $r * 2;
    return $r;
}

$n = fgets($__fp);
for ($i = 0; $i < $n; $i++) {
    list($b, $p, $f) = array_map('intval', explode(' ', fgets($__fp)));
    list($h, $c) = array_map('intval', explode(' ', fgets($__fp)));

    if ($h > $c) {
        $res[] = $h * calc($b, $p) + $c * calc($b, $f);
    } else {
        $res[] = $c * calc($b, $f) + $h * calc($b, $p);
    }
}

echo join(PHP_EOL, $res), PHP_EOL;

<?php
$stdin = fopen('php://stdin', 'r');
$n = fgets($stdin);
for ($i = 0; $i < $n; $i++) {
    list($b, $p, $f) = array_map('intval', explode(' ', fgets($stdin)));
    list($h, $c) = array_map('intval', explode(' ', fgets($stdin)));
    if ($h > $c) {
        $hamburger = min($p, intdiv($b, 2));
        $chicken = min($f, intdiv($b - 2 * $hamburger, 2));
    } else {
        $chicken = min($f, intdiv($b, 2));
        $hamburger = min($p, intdiv($b - 2 * $chicken, 2));
    }
    echo ($hamburger * $h + $chicken * $c) . PHP_EOL;
}

<?php
	$cin = fopen("php://stdin", "r");
	$t = intval(fgets($cin));
	while($t != 0){
		$t--;
		$s = fgets($cin);
		$a = explode(" ", $s);
		$b = intval($a[0]);
		$p = intval($a[1]);
		$f = intval($a[2]);
		$s = fgets($cin);
		$a = explode(" ", $s);
		$h = intval($a[0]);
		$c = intval($a[1]);
		$ans = 0;
		if($h > $c){
			$ans = $ans + min(intval($b/2), $p) * $h;
			$b = $b - 2 * min(intval($b/2), $p);
			$ans = $ans + min(intval($b/2), $f) * $c;
		}
		else{
			$ans = $ans + min(intval($b/2), $f) * $c;
			$b = $b - 2 * min(intval($b/2), $f);
			$ans = $ans + min(intval($b/2), $p) * $h;
		}
		print_r($ans."\n");
	}
	fclose($cin);
?>

<?php
$stdin = fopen('php://stdin', 'r');
$n = fgets($stdin);
for ($i = 0; $i < $n; $i++) {
    list($b, $p, $f) = explode(' ', fgets($stdin));
    list($h, $c) = explode(' ', fgets($stdin));
    if ($h > $c) {
        $hamburger = min($p, intdiv($b, 2));
        $chicken = min($f, intdiv($b - 2 * $hamburger, 2));
    } else {
        $chicken = min($f, intdiv($b, 2));
        $hamburger = min($p, intdiv($b - 2 * $chicken, 2));
    }
    echo ($hamburger * $h + $chicken * $c) . PHP_EOL;
}


<?php
#1179A
[$n, $qn] = explode(' ', trim(fgets(STDIN)));
$arr = explode(' ', trim(fgets(STDIN)));
$max = max($arr);
$ops = $arr_ = [];
$first = $arr[0];
/*
for ($cachedCount = 1; $arr[0] !== $max; $cachedCount++) {
    $ops[$cachedCount] = [$arr[0], $arr[1]];
    if ($arr[0] < $arr[1]) {
        $a = array_shift($arr);
        $arr[] = $a;
    } else {
        $a = array_shift($arr);
        $b = array_shift($arr);
        array_unshift($arr, $a);
        $arr[] = $b;
    }
}
*/
for ($cachedCount = 1; $first !== $max; $cachedCount++) {
    $ops[$cachedCount] = [$first, $arr[$cachedCount]];
    if ($first < $arr[$cachedCount]) {
        $arr_[] = $first;
        $first = $arr[$cachedCount];
    } else {
        $arr_[] = $arr[$cachedCount];
    }
}
$arr = array_merge([$first], array_slice($arr, $cachedCount), $arr_);
unset($arr_, $first, $max);
$n--;
for ($i = 0; $i < $qn; $i++) {
    $q = trim(fgets(STDIN));
    if ($q < $cachedCount) {
        echo $ops[$q][0] . ' ' . $ops[$q][1] . PHP_EOL;
    } else {
        $j = bcadd(bcmod(bcadd($q, bcmul($cachedCount, '-1')), $n), '1');
        echo $arr[0] . ' ' . $arr[$j] . PHP_EOL;
    }
}

<?php
#1179A
[$n, $qn] = explode(' ', trim(fgets(STDIN)));
$arr = explode(' ', trim(fgets(STDIN)));
$max = max($arr);
$ops = [];
for ($cachedCount = 1; $arr[0] !== $max; $cachedCount++) {
    $ops[$cachedCount] = [$arr[0], $arr[1]];
    if ($arr[0] < $arr[1]) {
        $a = array_shift($arr);
        $arr[] = $a;
    } else {
        $a = array_shift($arr);
        $b = array_shift($arr);
        array_unshift($arr, $b);
        $arr[] = $a;
    }
}
$n--;
for ($i = 0; $i < $qn; $i++) {
    $q = trim(fgets(STDIN));
    if ($q < $cachedCount) {
        echo $ops[$q][0] . ' ' . $ops[$q][1] . PHP_EOL;
    } else {
        $j = bcadd(bcmod(bcadd($q, bcmul($cachedCount, '-1')), $n), '1');
        echo $arr[0] . ' ' . $arr[$j] . PHP_EOL;
    }
}

<?php
#1179A
[$n, $qn] = explode(' ', trim(fgets(STDIN)));
$arr = explode(' ', trim(fgets(STDIN)));
$max = max($arr);
$ops = [];
for ($cachedCount = 1; $arr[0] !== $max; $cachedCount++) {
    $ops[$cachedCount] = [$arr[0], $arr[1]];
    if ($arr[0] < $arr[1]) {
        $a = array_shift($arr);
        $arr[] = $a;
    } else {
        $a = array_shift($arr);
        $b = array_shift($arr);
        array_unshift($arr, $b);
        $arr[] = $a;
    }
}
for ($i = 0; $i < $qn; $i++) {
    $q = trim(fgets(STDIN));
    if ($q < $cachedCount) {
        echo $ops[$q][0] . ' ' . $ops[$q][1] . PHP_EOL;
    } else {
        $j = ($q - $cachedCount) % ($n - 1) + 1;
        echo $arr[0] . ' ' . $arr[$j] . PHP_EOL;
    }
}


<?php
    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $m = max($a);
    $i = 0;
    $iMax = 0;
    foreach ($a AS $v) {
        if ($m == $v) {
            $i++;
        } else {
            $i = 0;
        }
        if ($iMax < $i) {
            $iMax = $i;
        }
    }
    echo $iMax;
?>

<?php
$n = trim(fgets(STDIN));
$arr = explode(" ", trim(fgets(STDIN)));
$max = max($arr);
$a = 0;
$b = 0;
for($i = 0; $i < $n; $i++)
{
     if($arr[$i] == $max)
     {
          $b++;
     }
     else
     {
          $a = max($a, $b);
          $b = 0;
     }
}
$a = max($a, $b);
print $a;
?>

<?php

list($n) = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$iMax = max($a);
$iMaxCounter = 1;
$aCounter = [];
for($i = 0; $i < $n - 1; $i++){
    if($a[$i] == $iMax && $a[$i+1] == $iMax){
        $iMaxCounter++;
        $aCounter[] = $iMaxCounter;
    } else {
        $iMaxCounter = 1;
    }
}
if(empty($aCounter)){
    echo 1;
} else {
    echo max($aCounter);
}

<?php

list($n) = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$iMax = max($a);
$iMaxCounter = 1;
for($i = 0; $i < $n -1; $i++){
    if($a[$i] == $iMax && $a[$i+1] == $iMax){
        $iMaxCounter++;
    }
}

echo $iMaxCounter;

<?php

list($n) = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$iMax = max($a);
$iMaxCounter = 1;
for($i = 0; $i < $n - 1; $i++){
    if($a[$i] == $iMax && $a[$i+1] == $iMax){
        $iMaxCounter++;
        $aCounter[] = $iMaxCounter;
    } else {
        $aCounter[] = $iMaxCounter;
        $iMaxCounter = 1;

    }
}
echo max($aCounter);

<?php

list($n) = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$iMax = max($a);
$iMaxCounter = 1;
for($i = 0; $i < $n - 1; $i++){
    if($a[$i] == $iMax && $a[$i+1] == $iMax){
        $iMaxCounter++;
        $aCounter[] = $iMaxCounter;
    } else {
        $iMaxCounter = 1;
    }
}
echo max($aCounter);

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

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

$max = max($b);
$a = 0;
$b = 0;
for($i = 0; $i < $n; $i++)
{
     if($arr[$i] == $max)
     {
          $b++;
     }
     else
     {
          $a = max($a, $b);
          $a = 0;
     }
}
$a = max($a, $b);
print $a;
?>

<?php

    function minF($n, $m, $s) {
        if ($n < 10) {
            return $n;
        }
        $r = floor($n/2);
        preg_match("/".$m."{".$r."}/", $s, $d);
        if (count($d)) {
            return $n;
        } else {
            return minF($r, $m, $s);
        }
    }

    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $s = implode("", $a);
    $m = max($a);
    preg_match_all("/".$m."/", $s, $f);
    $c = count($f[0]);
    $h = minF($c, $m, $s);
    for ($i = $h; $i > 0; $i--) {
        preg_match_all("/(".$m."){".$i."}/", $s, $d);
        if (count($d[0])) {
            echo $i;
            break;
        }
    }

?>

<?php
    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $m = max($a);
    $i = 0;
    $iMax = 0;
    foreach ($a AS $v) {
        if ($m == $v) {
            $i++;
        } else {
            if ($iMax < $i) {
                $iMax = $i;
            }
            $i = 0;
        }

    }
    echo $iMax;
?>

<?php

    function minF($n, $m, $s) {
        $r = ceil($n/2);
        preg_match("/".$m."{".$r."}/", $s, $d);
        if (count($d)) {
            return $n;
        } else {
            return minF($r, $m, $s);
        }
    }

    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $s = implode("", $a);
    $m = max($a);
    preg_match_all("/".$m."/", $s, $f);
    $c = count($f[0]);
    $h = minF($c, $m, $s);
    for ($i = $h; $i > 0; $i--) {
        preg_match("/".$m."{".$i."}/", $s, $d);
        if (count($d)) {
            echo $i;
            break;
        }
    }

?>

<?php

    function minF($n, $m, $s) {
        if ($n < 10) {
            return $n;
        }
        $r = floor($n/2);
        preg_match("/".$m."{".$r."}/", $s, $d);
        if (count($d)) {
            return $n;
        } else {
            return minF($r, $m, $s);
        }
    }

    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $s = implode("", $a);
    $m = max($a);
    preg_match_all("/".$m."/", $s, $f);
    $c = count($f[0]);
    $h = minF($c, $m, $s);
    for ($i = $h; $i > 0; $i--) {
        preg_match("/".$m."{".$i."}/", $s, $d);
        if (count($d)) {
            echo $i;
            break;
        }
    }

?>

<?php

    function minF($n, $m, $s) {
        if ($n < 10) {
            return $n;
        }
        $r = floor($n/2);
        preg_match("/(".$m."){".$r."}/", $s, $d);
        if (count($d)) {
            return $n;
        } else {
            return minF($r, $m, $s);
        }
    }

    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $s = implode("", $a);
    $m = max($a);
    preg_match_all("/".$m."/", $s, $f);
    $c = count($f[0]);
    $h = minF($c, $m, $s);
    for ($i = $h; $i > 0; $i--) {
        preg_match_all("/(".$m."){".$i."}/", $s, $d);
        if (count($d[0])) {
            echo $i;
            break;
        }
    }

?>


<?php
$f=fopen("php://stdin","r");
$s=fscanf($f, "%u %u");
list ($m,$n)=$s;

$i=1;
$l="%u";
while($i++<$n){
 $l.=" %u";}

$i=0;
$left=$right=0;
$border=false;
while($i++<$m){
 $s=fscanf($f, $l);
 $left+=$s[0];
 $right+=$s[$n-1];
 if ((($i==1) or ($i==$m)) and (array_sum($s)>0)) $border=true;}

if (($left>0) or ($right>0)) $border=true;

if ($border) echo("2");
 else echo("4");

?>

<?php
$f=fopen("input.txt","r");
$s=fscanf($f, "%u %u");
list ($n,$m)=$s;

$i=1;
$l="%u";
while($i++<$n){
 $l.=" %u";}

$i=0;
$left=$right=0;
$border=false;
while($i++<$m){
 $s=fscanf($f, $l);
 $left+=$s[0];
 $right+=$s[$n-1];
 if ((($i==1) or ($i==$m)) and (array_sum($s)>0)) $border=true;}
if (($left>0) or ($right>0)) $border=true;
fclose($f);
if ($border) echo("2");
 else echo("4");

?>

<?php
$f=fopen("input.txt","r");
$s=fscanf($f, "%u %u");
list ($n,$m)=$s;

$i=1;
$l="%u";
while($i++<$n){
 $l.=" %u";}

$i=0;
$left=$right=0;
$border=false;
while($i++<$m){
 $s=fscanf($f, $l);
 $left+=$s[0];
 $right+=$s[$n-1];
 if ((($i==1) or ($i==$m)) and (array_sum($s)>0)) $border=true;}
if (($left>0) or ($right>0)) $border=true;
fclose($f);
$f=fopen("output.txt","w");
if ($border) fwrite($f,"2");
 else fwrite($f,"4");
fclose($f);

?>

<?php
$f=fopen("input.txt","r");
$s=fscanf($f, "%u %u");
list ($m,$n)=$s;

$i=1;
$l="%u";
while($i++<$n){
 $l.=" %u";}

$i=0;
$left=$right=0;
$border=false;
while($i++<$m){
 $s=fscanf($f, $l);
 $left+=$s[0];
 $right+=$s[$n-1];
 if ((($i==1) or ($i==$m)) and (array_sum($s)>0)) $border=true;}
if (($left>0) or ($right>0)) $border=true;
if ($border) echo("2");
 else echo("4");
fclose($f);
?>

<?php
$f=fopen("input.txt","r");
$s=fscanf($f, "%u %u");
list ($m,$n)=$s;

$i=1;
$l="%u";
while($i++<$n){
 $l.=" %u";}

$i=0;
$left=$right=0;
$border=false;
while($i++<$m){
 $s=fscanf($f, $l);
 $left+=$s[0];
 $right+=$s[$n-1];
 if ((($i==1) or ($i==$m)) and (array_sum($s)>0)) $border=true;}
if (($left>0) or ($right>0)) $border=true;
fclose($f);
if ($border) echo("2");
 else echo("4");

?>