<?php
list($num, $size, $waste)=explode(" ", trim(fgets(STDIN)));
$unit=explode(" ", trim(fgets(STDIN)));
for ($i=0; $i < $num; $i++) {
    if ($unit[$i] > $size) {
        $unit[$i] = 0;
    }
   }
$u=0;
foreach ($unit as $val) {
    $runningSum += $val;
    if ($runningSum > $waste) {
        $runningSum =0;
        $u++;
    }
}
echo $u;
?>

<?php

//=====================================
// link: http://codeforces.com/contest/709/problem/A
//=====================================

// get inputs
list($n_oranges, $max_size, $waste_size) = explode(' ', trim(fgets(STDIN)));
$oranges                                 = explode(' ', trim(fgets(STDIN)));

// solution
$collect_waste = 0;
$empty_wastes  = 0;

foreach ($oranges as $key => $orange) {
    if ($orange > $max_size) {
        continue;
    }

    $collect_waste += $orange;

    if ($collect_waste > $waste_size) {
        $empty_wastes++;
        $collect_waste = 0;
    }
}

echo "$empty_wastes\n";

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	list(, $b, $d) = readStringExplodeNum($f, ' ', true);
	$sizes = readStringExplodeNum($f, ' ', true);
	$poll = 0;
	$answer = 0;
	foreach ($sizes as $a) {
		if ($a > $b) {
			continue;
		}
		$poll+=$a;
		if ($poll > $d) {
			$poll = 0;
			$answer++;
		}
	}
	echo $answer;
	/* / end body */
}

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

<?php

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

fscanf($stdin, "%d %d %d" , $n , $b , $d ) ;

$count = 0 ;
$waste = 0 ;

fscanf($stdin , "%[^\n]" , $test );
$arr = array_map( 'intval' , preg_split( "/ /" , $test , -1 , PREG_SPLIT_NO_EMPTY ) );

for( $i=0 ; $i<$n ; $i++ )
{
     if( $arr[$i] <= $b )
     {
          if( $arr[$i] + $waste > $d )
          {
               $count++ ;
               $waste = 0 ;
          }
          else
          {
               $waste += $arr[$i] ;
          }
     }
}
echo $count ;

fwrite($stdout);

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

?>

<?php

$stdin = fopen('php://stdin', 'r');
list($n,$b,$d)=sscanf(fgets($stdin),"%d %d %d");
$astr=fgets($stdin);
$arr = explode(" ",$astr);
$v=0;
$v_count=0;
for($i=0;$i<$n;$i++)
{
    if ($arr[$i]<=$b)
        $v+=$arr[$i];
    if ($v>$d)
    {
        $v_count+=1;
        $v=0;
//        $v=$v%$d;
    }
}
echo $v_count;
?>

<?php

class Solution
{
    protected function solve($p, $b, $d)
    {
        $count = $sum = 0;
        foreach ($p as $w) {
            if ($w > $b) {
                continue;
            }

            $sum += $w;

            if ($sum > $d) {
                $sum = 0;
                $count++;
                continue;
            }
        }

        return $count;
    }

    public function run()
    {
        fscanf(STDIN, '%d %d %d', $n, $b, $d);
        $p = explode(' ', trim(fgets(STDIN)));

        echo $this->solve($p, $b, $d) . PHP_EOL;
    }
}

$sol = new Solution();
$sol->run();

<?php

class Solution
{
    public function solve()
    {
        fscanf(STDIN, '%d %d %d', $n, $b, $d);
        $arr = explode(' ', trim(fgets(STDIN)));

        $sum = 0;
        $count = 0;
        foreach ($arr as $w) {
            $w = (int) $w;

            if ($w > $b) {
                continue;
            }

            $sum += $w;

            if ($sum > $d) {
                while ($sum > $d) {
                    $count++;
                    $sum = 0;
                    continue;
                }
            }
        }

        if ($sum > $d) {
            $count++;
        }

        echo $count . PHP_EOL;
    }
}

$sol = new Solution();
$sol->solve();

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

for($i=0;$i<$n;$i++){
	if($oranges[$i]<=$max_orange_size){
		$current_level+=$oranges[$i];
	}
	if($current_level>$container_volume){
		$oporodj+=1;
		//$current_level-=$container_volume;
		$current_level=0;

	}
}

echo $oporodj;

?>

<?php
      $t = array();
      list($n, $x, $y) = explode(' ', trim(fgets(STDIN)));
      $t = explode(' ', trim(fgets(STDIN)));
      $ans = 0;
      $s = 0;
      for($i = 0; $i < $n; $i ++)
      {
          if($t[$i] > $x)
            continue;
          $s += $t[$i];
          if($s > $y)
          {
              $ans ++;
              $s = 0;
          }
      }
      echo $ans;
?>

<?php

//=====================================
// link: http://codeforces.com/contest/709/problem/A
//=====================================

// get inputs
list($n_oranges, $max_size, $waste_size) = explode(' ', trim(fgets(STDIN)));
$oranges                                 = explode(' ', trim(fgets(STDIN)));

// solution
$collect_waste = 0;
$empty_wastes  = 0;

foreach ($oranges as $key => $orange) {
    if ($orange > $max_size) {
        continue;
    }

    $collect_waste += $orange;

    if ($collect_waste > $waste_size) {
        $empty_wastes++;
        $waste_size += $waste_size;
    }
}

echo "$empty_wastes\n";

<?php

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

fscanf($stdin, "%d %d %d" , $n , $b , $d ) ;

$count = 0 ;
$waste = 0 ;

fscanf($stdin , "%[^\n]" , $test );
$arr = array_map( 'intval' , preg_split( "/ /" , $test , -1 , PREG_SPLIT_NO_EMPTY ) );

for( $i=0 ; $i<$n ; $i++ )
{
     if( $arr[$i] <= $b )
     {
          if( $arr[$i] + $waste > $d )
          {
               $count++ ;
               $waste = $arr[$i] ;
          }
          else
          {
               $waste += $arr[$i] ;
          }
     }
}
echo $count ;

fwrite($stdout);

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

?>

<?php

$stdin = fopen('php://stdin', 'r');
list($n,$b,$d)=sscanf(fgets($stdin),"%d %d %d");
$astr=fgets($stdin);
$arr = explode(" ",$astr);
$v=0;
$v_count=0;
for($i=0;$i<$n;$i++)
{
    if ($arr[$i]<$b)
        $v+=$arr[$i];
    if ($v>=$d)
    {
        $v_count=(int)($v/$d);
        $v=$v%$d;
    }
}
echo $v_count;
?>

<?php

$stdin = fopen('php://stdin', 'r');
list($n,$b,$d)=sscanf(fgets($stdin),"%d %d %d");
$astr=fgets($stdin);
$arr = explode(" ",$astr);
$v=0;
$v_count=0;
for($i=0;$i<$n;$i++)
{
    if ($arr[$i]<$b)
        $v+=$arr[$i];
    if ($v>$d)
    {
        $v_count+=1;
        $v=0;
//        $v=$v%$d;
    }
}
echo $v_count;
?>

<?php

$stdin = fopen('php://stdin', 'r');
list($n,$b,$d)=sscanf(fgets($stdin),"%d %d %d");
$astr=fgets($stdin);
$arr = explode(" ",$astr);
$v=0;
$v_count=0;
for($i=0;$i<$n;$i++)
{
    if ($arr[$i]<$b)
        $v+=$arr[$i];
    if ($v>$d)
    {
        $v_count=(int)($v/$d);
        $v=0;
//        $v=$v%$d;
    }
}
echo $v_count;
?>

<?php

class Solution
{
    public function solve()
    {
        fscanf(STDIN, '%d %d %d', $n, $b, $d);
        $arr = explode(' ', trim(fgets(STDIN)));

        $sum = 0;
        $count = 0;
        foreach ($arr as $w) {
            $w = (int) $w;

            if ($w > $b) {
                continue;
            }

            if ($sum > $d) {
                $count++;
                $sum = 0;
                continue;
            }

            $sum += $w;
        }

        if ($sum > $d) {
            $count++;
        }

        echo $count . PHP_EOL;
    }
}

$sol = new Solution();
$sol->solve();

<?php

class Solution
{
    public function solve()
    {
        fscanf(STDIN, '%d %d %d', $n, $b, $d);
        $arr = explode(' ', trim(fgets(STDIN)));

        $sum = 0;
        $count = 0;
        foreach ($arr as $w) {
            $w = (int) $w;

            if ($w > $b) {
                continue;
            }

            if ($sum > $d) {
                $count++;
                $sum %= $d;
                continue;
            }

            $sum += $w;
        }

        if ($sum > $d) {
            $count++;
        }

        echo $count . PHP_EOL;
    }
}

$sol = new Solution();
$sol->solve();

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

for($i=0;$i<$n;$i++){
	if($oranges[$i]<$max_orange_size){
		$current_level+=$oranges[$i];
	}
	if($current_level>$container_volume){
		$oporodj+=1;
		//$current_level-=$container_volume;
		$current_level=0;

	}
}

echo $oporodj;

<?
$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

for($i=0;$i<$n;$i++){
	if($oranges[$i]<$max_orange_size){
		$current_level+=$oranges[$i];
	}
	if($current_level>$container_volume){
		$oporodj+=1;
		$current_level-=$container_volume;
	}
}

echo $oporodj;

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

for($i=0;$i<$n;$i++){
	if($oranges[$i]<$max_orange_size){
		$current_level+=$oranges[$i];
	}else{
		continue;
	}
	while($current_level>$container_volume){
		$oporodj+=1;
		$current_level-=$container_volume;
	}
}

echo $oporodj;

?>

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

for($i=0;$i<$n;$i++){
	if($oranges[$i]<$max_orange_size){
		$current_level+=$oranges[$i];
	}
	while($current_level>$container_volume){
		$oporodj+=1;
		$current_level-=$container_volume;
	}
}

echo $oporodj;

?>

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$arr = explode(' ',$s);
$n = $arr[0];
$max_orange_size = (int)$arr[1];
$container_volume = (int)$arr[2];

$s =  trim(fgets($stdin));
$oranges = explode(' ',$s);
$oporodj=0;
$current_level = 0;

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

	if($oranges[$i]<=$max_orange_size){

		$current_level+=$oranges[$i];

		while($current_level>$container_volume){
			$oporodj+=1;
			$current_level-=$container_volume;
		}
	}
}

echo $oporodj;

?>

<?php
      $t = array();
      list($n, $x, $y) = explode(' ', trim(fgets(STDIN)));
      $t = explode(' ', trim(fgets(STDIN)));
      $ans = 0;
      $s = 0;
      for($i = 0; $i < $n; $i ++)
      {
          $s += $t[$i] % $x;
          if($s > $y)
          {
              $ans ++;
              $s = 0;
          }
      }
      echo $ans;
?>


<?php $t = (int)readline();
for ($T = 0; $T < $t; $T++) {
    $n = (int)readline();
    $ymx = 0;
    $ymn = 0;
    $xmx = 0;
    $xmn = 0;
    for ($i = 0; $i < $n; $i++) {
        $point = explode(" ", readline());
        $curx = (int)$point[0];
        $cury = (int)$point[1];
        if ($curx == 0) {
            $ymn = min($ymn, $cury);
            $ymx = max($ymx, $cury);
        } else {
            $xmn = min($xmn, $curx);
            $xmx = max($xmx, $curx);
        }
    }
    echo 2 * ($ymx - $ymn + $xmx - $xmn);
    echo "\n";
} ?>

<?php
function read() {
  return trim(fgets($GLOBALS['file'])) ;
}
function readInt() {
  return (int) read() ;
}
function readStrs() {
  return explode(" ",read()) ;
}
function readIntArray() {
  return array_map('intval', readStrs());
}
function readAsArray() {
  return str_split(read()) ;
}
function puts($arg) {
  if($arg === true) print_r("true");
  elseif($arg === false) print_r("false");
  else {
    print_r($arg) ;
  }
  print_r("\n") ;
}
$file = (file_exists("input.txt")) ? fopen("input.txt","r") : STDIN ;

//-----------------------------------//

$t = readInt() ;
while($t--) {
    $l = readInt() ;
    $ny = $py = $nx = $px = 0 ;
    for($i=0;$i<$l;$i++) {
        [$a,$b] = readIntArray() ;
        if($a == 0) {
            if($b < 0) {
                $ny = max($ny,-$b);
            }
            else {
                $py = max($py,$b);
            }
        }
        else{
            if($a < 0) {
                $nx = max($nx,-$a);
            }
            else {
                $px = max($px,$a);
            }
        }
    }
    puts(array_sum([$px*2,$py*2,$nx*2,$ny*2]));
}

<?php

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

while ($t--) {
    fscanf(STDIN, '%u', $n);

    $minX = 0;
    $maxX = 0;
    $minY = 0;
    $maxY = 0;

    for ($i = 0; $i < $n; ++$i) {
        fscanf(STDIN, '%d %d', $x, $y);

        $minX = min($minX, $x);
        $maxX = max($maxX, $x);
        $minY = min($minY, $y);
        $maxY = max($maxY, $y);
    }

    $res = 2 * ($maxX + $maxY - $minX - $minY);

    echo $res.PHP_EOL;
}


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

<?php
	$t = trim(fgets(STDIN));
	$ans = "";
	for ($o = 0; $o < $t; $o++) {
		$data = explode(" ", trim(fgets(STDIN)));
		$n = $data[0];
		$m = $data[1];
		if ($n % $m == 0)
			$ans .= "YES\n";
		else
			$ans .= "NO\n";
	}
	print $ans;
?>


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

for ($i = 0; $i < $t; $i++) {
    $n = trim(fgets((STDIN)));
    $status = false;
    for ($a = 2; $a <= (intval(sqrt($n))+1); $a++) {
        if (bcmod($n, $a) == 0) {
            $k = bcdiv($n, $a);
            for ($b = 2; $b <= (intval(sqrt($k))+1); $b++) {
                if ($a != $b && bcmod ($k ,$b) == 0) {
                    $c = bcdiv($k, $b);
                    if ($a != $c && $b != $c){
                        echo "YES\n";
                        echo $a. " ".$b. " ".$c."\n";
                        $status = true;
                        break;
                    }
                }
            }
        }

        if ($status) {
            break;
        }
    }
    if (!$status) {
        echo "NO\n";
    }

}

?>


<?php

function readVocab($n)
{
    $result = [];
    foreach (range(1, $n) as $i) {
        $result[] = fgets(STDIN);
    }
    return $result;
}

$vocabLength = explode(' ', fgets(STDIN));
$p           = readVocab((int)$vocabLength[0]);
$w           = readVocab((int)$vocabLength[1]);

$shared = array_values(array_intersect($p, $w));
$uniqp = array_values(array_diff($p, $w));
$uniqw = array_values(array_diff($w, $p));
$even = count($shared) % 2 == 0;

//var_dump($uniqp);
//var_dump($uniqw);
//var_dump($shared);

if (count($uniqp) > count($uniqw)) {
    echo 'YES';
} else if (count($uniqp) == count($uniqw) && !$even) {
    echo 'YES';
} else {
    echo 'NO';
}

//echo (count($uniqp) > count($uniqw) && (count($shared) % 2 == 0))  ? 'YES' : 'NO';

<?php
    fscanf(STDIN, "%d %d", $a, $b);

    // define('DEBUG', true);
    define('DEBUG', false);

    $arrA = array();
    $arrB = array();
    for ($i = 0; $i < $a; $i++) {
        fscanf(STDIN, "%s", $aa);
        $arrA[$aa] = 1;
    }
    for ($i = 0; $i < $b; $i++) {
        fscanf(STDIN, "%s", $aa);
        $arrB[$aa] = 1;
    }
    if (DEBUG) var_dump($arrA);
    if (DEBUG) var_dump($arrB);

    foreach ($arrA as $k => $v) {
        if (isset($arrB[$k])) {
            $cntA++;
        }
    }
    foreach ($arrB as $k => $v) {
        if (isset($arrA[$k])) {
            $cntB++;
        }
    }

    $uniA = $a - $cntA;
    $uniB = $b - $cntB;

    for ($i = 0; $i < 100000; $i++) {
        switch ($i % 2) {
            case 0:
                if ($cntA > 0) {
                    $cntA--;
                    $cntB--;
                    if ($uniB < 0) {
                        exit('YES');
                    }
                } else {
                    $uniA--;
                    if ($uniA < 0) {
                        exit('NO');
                    }
                }
                break;

            case 1:
                if ($cntB > 0) {
                    $cntA--;
                    $cntB--;
                    if ($cntA < 0) {
                        exit('NO');
                    }
                } else {
                    $uniB--;
                    if ($uniB < 0) {
                        exit('YES');
                    }
                }
                break;
        }
        if (DEBUG) echo "A:{$uniA}-{$cntA}\n";
        if (DEBUG) echo "B:{$uniB}-{$cntB}\n";
        if (DEBUG) echo "-------\n";
    }

<?php
    fscanf(STDIN, "%d %d", $a, $b);

    $arrA = array();
    $arrB = array();
    for ($i = 0; $i < $a; $i++) {
        fscanf(STDIN, "%s", $aa);
        $arrA[$aa] = 1;
    }
    for ($i = 0; $i < $b; $i++) {
        fscanf(STDIN, "%s", $aa);
        $arrB[$aa] = 1;
    }
    // var_dump($arrA);
    // var_dump($arrB);

    foreach ($arrA as $k => $v) {
        if (isset($arrB[$k])) {
            $cntA++;
        }
    }
    foreach ($arrB as $k => $v) {
        if (isset($arrA[$k])) {
            $cntB++;
        }
    }

    $uniA = $a - $cntA;
    $uniB = $b - $cntB;

    for ($i = 0; $i < 100000; $i++) {
        switch ($i % 2) {
            case 0:
                if ($uniA > 0) {
                    $uniA--;
                    $uniB--;
                    if ($uniB < 0) {
                        exit('YES');
                    }
                } else {
                    $cntA--;
                    if ($cntA < 0) {
                        exit('NO');
                    }
                }
                break;

            case 1:
                if ($uniB > 0) {
                    $uniA--;
                    $uniB--;
                    if ($uniA < 0) {
                        exit('NO');
                    }
                } else {
                    $cntB--;
                    if ($cntB < 0) {
                        exit('YES');
                    }
                }
                break;
        }
        // echo "A:{$uniA} {$cntA}\n";
        // echo "B:{$uniB} {$cntB}\n";
        // echo "-------\n";
    }

<?php

function readVocab($n)
{
    $result = [];
    foreach (range(1, $n) as $i) {
        $result[] = fgets(STDIN);
    }
    return $result;
}

$vocabLength = explode(' ', fgets(STDIN));
$p           = readVocab((int)$vocabLength[0]);
$w           = readVocab((int)$vocabLength[1]);

$shared = array_intersect($p, $w);
$uniqp = array_diff($p, $w);
$uniqw = array_diff($w, $p);
echo (count($uniqp) >= count($uniqw) || (count($shared) % 2 == 0))  ? 'YES' : 'NO';

<?php

function readVocab($n)
{
    $result = [];
    foreach (range(1, $n) as $i) {
        $result[] = fgets(STDIN);
    }
    return $result;
}

$vocabLength = explode(' ', fgets(STDIN));
$p           = readVocab((int)$vocabLength[0]);
$w           = readVocab((int)$vocabLength[1]);

$uniqp = array_diff($p, $w);
$uniqw = array_diff($w, $p);

echo count($uniqp) >= count($uniqw) ? 'YES' : 'NO';

<?php

function readVocab($n)
{
    $result = [];
    foreach (range(1, $n) as $i) {
        $result[] = fgets(STDIN);
    }
    return $result;
}

$vocabLength = explode(' ', fgets(STDIN));
$p           = readVocab((int)$vocabLength[0]);
$w           = readVocab((int)$vocabLength[1]);

$shared = array_intersect($p, $w);
$uniqp = array_diff($p, $w);
$uniqw = array_diff($w, $p);
echo (count($uniqp) > count($uniqw) || (count($shared) % 2 == 0))  ? 'YES' : 'NO';


<?php

    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    ini_set('memory_limit', '512M');

    define('MMAX', pow(10, 5));

    // define('DEBUG', true);
    define('DEBUG', false);

    $arrP = array();

    $rt = floor(sqrt(MMAX));
    for ($i = 2; $i < MMAX; $i++) {
        if (isset($arrP[$i])) continue;
        // echo "{$i} ";
        $arrP[$i][] = $i;
        $loop = floor(MMAX / $i);
        for ($j = 2; $j <= $loop; $j++) {
            $arrP[$i*$j][] = $i;
        }
    }
    for ($i = 4; $i <= MMAX; $i++) {
        if (!isset($arrP[$i])) {
            $arrP[$i][] = $i;
        }
    }

    if (DEBUG) {
        $tm1 = microtime(true);
    }

    fscanf(STDIN, "%d", $N);
    $a = explode(" ", trim(fgets(STDIN)));
    // var_dump($a);

    // for TEST
    // $a = range(1, 100000);
    // $N = count($a);

    $sum = array(1 => 1);

    for ($i = 0; $i < $N; $i++) {
        // echo "\nRET:\n";
        // var_dump($ret);
        if (DEBUG) var_dump($arrP[$a[$i]]);
        if (is_array($arrP[$a[$i]])) {
            $cnt = count($arrP[$a[$i]]);
            for ($j = 0; $j < $cnt; $j++) {
                $sum[$arrP[$a[$i]][$j]]++;
            }
        }
    }

    // var_dump($sum);
    // echo "answer:";

    echo max($sum);

    if (DEBUG) {
        $tm2 = microtime(true);
        echo PHP_EOL . "Time: " . ($tm2 - $tm1);
    }

<?php

    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    ini_set('memory_limit', '512M');

    define('MMAX', pow(10, 5));

    // define('DEBUG', true);
    define('DEBUG', false);

    $arrP = array();

    $rt = floor(sqrt(MMAX));
    for ($i = 2; $i < $rt; $i++) {
        if (isset($arrP[$i])) continue;
        // echo "{$i} ";
        $arrP[$i][] = $i;
        $loop = floor(MMAX / $i);
        for ($j = 2; $j <= $loop; $j++) {
            $arrP[$i*$j][] = $i;
        }
    }
    for ($i = 4; $i <= MMAX; $i++) {
        if (!isset($arrP[$i])) {
            $arrP[$i] = $i;
        }
    }

    if (DEBUG) {
        $tm1 = microtime(true);
    }

    fscanf(STDIN, "%d", $N);
    $a = explode(" ", trim(fgets(STDIN)));
    // var_dump($a);

    // for TEST
    // $a = range(1, 100000);
    // $N = count($a);

    $sum = array(1 => 1);

    for ($i = 0; $i < $N; $i++) {
        // echo "\nRET:\n";
        // var_dump($ret);
        // var_dump($arrP[$a[$i]]);
        if (is_array($arrP[$a[$i]])) {
            $cnt = count($arrP[$a[$i]]);
            for ($j = 0; $j < $cnt; $j++) {
                $sum[$arrP[$a[$i]][$j]]++;
            }
        }
    }

    // var_dump($sum);
    // echo "answer:";

    echo max($sum);

    if (DEBUG) {
        $tm2 = microtime(true);
        echo PHP_EOL . "Time: " . ($tm2 - $tm1);
    }

<?php
    // $tm1 = microtime(true);

    $erat = array();
    $arrP = array();
    define('MMAX', pow(10, 5));
    for ($i = 2; $i <= sqrt(MMAX); $i++) {
        $erat[$i] = 1;
    }
    for ($i = 2; $i <= sqrt(MMAX); $i++) {
        for ($j = 2; $j <= sqrt(MMAX); $j++) {
            unset($erat[$i*$j]);
        }
    }
    $arrP = array_keys($erat);

    fscanf(STDIN, "%d", $N);
    $a = explode(" ", trim(fgets(STDIN)));
    // $a = range(1, 100000);
    $cnt = count($a);
    $sum = array();

    for ($i = 0; $i < $cnt; $i++) {
        foreach ($arrP as $pnum) {
            // echo "{$a[$i]} {$pnum}\n";
            // if ($pnum > $a[$i]) break;
            if ($a[$i] % $pnum == 0) {
                $sum[$pnum]++;
            }
        }
    }

    // var_dump($sum);

    echo max($sum);

    // $tm2 = microtime(true);

    // echo PHP_EOL . ($tm2 - $tm1);

<?php

    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    ini_set('memory_limit', '512M');

    define('MMAX', pow(10, 5));

    // define('DEBUG', true);
    define('DEBUG', false);

    $arrP = array();

    $rt = floor(sqrt(MMAX));
    for ($i = 2; $i < $rt; $i++) {
        if (isset($arrP[$i])) continue;
        // echo "{$i} ";
        $arrP[$i][] = $i;
        $loop = floor(MMAX / $i);
        for ($j = 2; $j <= $loop; $j++) {
            $arrP[$i*$j][] = $i;
        }
    }
    for ($i = 4; $i <= MMAX; $i++) {
        if (!isset($arrP[$i])) {
            $arrP[$i][] = $i;
        }
    }

    if (DEBUG) {
        $tm1 = microtime(true);
    }

    fscanf(STDIN, "%d", $N);
    $a = explode(" ", trim(fgets(STDIN)));
    // var_dump($a);

    // for TEST
    // $a = range(1, 100000);
    // $N = count($a);

    $sum = array(1 => 1);

    for ($i = 0; $i < $N; $i++) {
        // echo "\nRET:\n";
        // var_dump($ret);
        // if (DEBUG) var_dump($arrP[$a[$i]]);
        if (is_array($arrP[$a[$i]])) {
            $cnt = count($arrP[$a[$i]]);
            for ($j = 0; $j < $cnt; $j++) {
                $sum[$arrP[$a[$i]][$j]]++;
            }
        }
    }

    // var_dump($sum);
    // echo "answer:";

    echo max($sum);

    if (DEBUG) {
        $tm2 = microtime(true);
        echo PHP_EOL . "Time: " . ($tm2 - $tm1);
    }


<?php
// 490A     Командная олимпиада
$in = fopen("php://stdin", 'r');

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

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

$arr1 = $arr2 = $arr3 = array();

for ($i=0; $i < $n; $i++) {
    switch ($arr[$i]) {
        case '1':
            array_push($arr1, $i + 1);
            break;
        case '2':
            array_push($arr2, $i + 1);
            break;
        case '3':
            array_push($arr3, $i + 1);
            break;
    }
}

$min = min(count($arr1), count($arr2), count($arr3));

echo $min."\n";

for ($i=0; $i < $min; $i++) {
    echo $arr1[$i]." ".$arr2[$i]." ".$arr3[$i]."\n";
}

?>

<?php
$fp = fopen("php://STDIN", "r");
$n = fgets($fp);
$member = explode(" ", fgets($fp));

$memberA = array();
$memberB = array();
$memberC = array();

for($i=0;$i<count($member);$i++){
    switch ($member[$i]) {
        case 1:
            $memberA[] = $i;
            break;
        case 2:
            $memberB[] = $i;
            break;
        case 3:
            $memberC[] = $i;
            break;
    }
}
$minPos = min(count($memberA),count($memberB),count($memberC));
echo $minPos."\n";
for($m=0;$m<$minPos;$m++){
    $posA = $memberA[$m]+1;
    $posB = $memberB[$m]+1;
    $posC = $memberC[$m]+1;
    echo $posA." ".$posB." ".$posC." "."\n";
}

?>

<?php

$n = readline();
$uchastniki = readline();

//$n = 4;
//$uchastniki = '2 1 1 2';
$uchastniki = explode(' ',$uchastniki);
$prog = array();
$mat = array();
$sport = array();
$i = 0;
$skills = array();
foreach ($uchastniki as $v) {
    if ($v == 1) {
        $skills['кодер'] += 1;
        $prog[] = $i+1;
    } elseif ($v == 2) {
        $skills['математик'] += 1;
        $mat[] = $i+1;
    } else {
        $skills['физкультурник'] += 1;
        $sport[] = $i+1;
    }
    $i += 1;
}

if (count($skills) < 3) {
    echo 0;
} else {
    $teams = min($skills);
    echo $teams . "\n";
    $i = 0;

    while ($i < $teams) {
        echo $prog[$i] . ' ' . $mat[$i] . ' ' . $sport[$i] . "\n";
        $i += 1;
    }
}

<?php

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

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

$numbers = array_map( "intval" , preg_split( "/ /" , $test , -1 , PREG_SPLIT_NO_EMPTY )  );
$ones = [] ;
$twos = [] ;
$threes = [] ;

for( $i=0 ; $i<$n ; $i++ )
{
     switch( $numbers[$i] )
     {
          case 1:
               $ones[] = $i+1 ;
               break ;
          case 2:
               $twos[] = $i+1 ;
               break ;
          default:
               $threes[] = $i+1 ;
               break ;
     }
}

$w = min( count( $ones ) , count( $twos ) , count( $threes ) ) ;

echo $w ."\n";

for( $i=0 ; $i<$w ; $i++ )
{
     echo $ones[$i] . " " . $twos[$i] . " " . $threes[$i] . "\n" ;
}

fwrite($stdout);

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

?>

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

    $cnt = $used = array();
    $cnt[] = $used[] = array();
    for($i=0; $i<sizeof($vals); $i++)
    {
        $cnt[$vals[$i]][] = $i+1;
        $used[$vals[$i]]++;
    }

    rsort($used);

    echo (!$used[3]) ? 0 : $used[3] . PHP_EOL;
    for($i=0; $i<$used[3]; $i++)
        echo $cnt[1][$i] . " " . $cnt[2][$i] . " " . $cnt[3][$i] . PHP_EOL;
?>

<?php

$n = readline();
$uchastniki = readline();
$uchastniki = explode(' ',$uchastniki);
$prog = array();
$mat = array();
$sport = array();
$i = 0;
$skills = array();
foreach ($uchastniki as $v) {
    if ($v == 1) {
        $skills['кодер'] += 1;
        $prog[] = $i+1;
    } elseif ($v == 2) {
        $skills['математик'] += 1;
        $mat[] = $i+1;
    } else {
        $skills['физкультурник'] += 1;
        $sport[] = $i+1;
    }
    $i += 1;
}

$teams = min($skills);
echo $teams . "\n";
$i = 0;

while ($i < $teams) {
    echo $prog[$i] . ' ' . $mat[$i] . ' ' . $sport[$i] . "\n";
    $i += 1;
}


<?php
function next_char ($a) {
  return chr(ord($a)+1);
}
function prev_char ($a) {
  return chr(ord($a)-1);
}
$nt = intval(readline());
for ($i = 0; $i < $nt; ++$i)
{
	$l = intval(readline())-1;
	$s = readline();
	$t = true;
	for ($a = 0, $z = $l; $a < $l; ++$a, $z = $l-$a)
	{
		if ((next_char($s[$a]) == next_char($s[$z]))
		 || (next_char($s[$a]) == prev_char($s[$z]))
		 || (prev_char($s[$a]) == next_char($s[$z]))
		 || (prev_char($s[$a]) == prev_char($s[$z])))
		{
			continue;
		}
		echo "NO\n";
		$t = false;
		break;
	}
	if ($t) echo "YES\n";
}


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

<?php
$n = readline();
$ara = explode(' ', readline());
echo (max($ara)*$n)-array_sum($ara)."\n";

<?php

$n = readline();

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

rsort($ara);
$add = 0;

for($i=0; $i<$n; $i++)
	$add += $ara[$i];
echo ($ara[0]*$n)-$add."\n";

<?php

    ini_set('error_reporting', E_ALL & ~E_NOTICE);

    // define('DEBUG', true);
    define('DEBUG', false);

    fscanf(STDIN, "%d", $n);
    $a = explode(" ", trim(fgets(STDIN)));

    $a_max = max($a);
    $a_sum = array_sum($a);

    $target = $a_max * $n;
    echo $target - $a_sum;

<?php
$peoples = readline();
$many = readline();
//$peoples = 5;
//$many = '1 1 0 1 1';
$many = explode(' ', $many);
$max_many = max($many);
$summa = 0;
  foreach ($many as $v) {
      if($v<$max_many){
        $summa = $summa + ($max_many-$v);
      }
  }
echo $summa;

<?php
fscanf(STDIN, "%d", $n);
$a = explode(" ", trim(fgets(STDIN)));
$x = max($a);
echo ($x*count($a)) - array_sum($a);
?>

<?
$dir = fopen("php://stdin", 'r');
$string =  stream_get_contents($dir);

$parametros = explode(PHP_EOL,$string);
//var_dump($parametros);

$n=$parametros[0];
$welfare=$parametros[1];

$welfareI = explode(" ",$welfare);
$max_welfare = max($welfareI);

foreach($welfareI as $w) {
    $total += $max_welfare - $w;
}

echo $total;
?>

<?php
    $stdin = fopen("php://stdin", "r");
    trim(fgets(STDIN));
    $arr = explode(' ', trim(fgets(STDIN)));
    fclose($stdin);

    sort($arr);

    foreach($arr as $x)
        $ans += $arr[sizeof($arr)-1] - $x;

    echo $ans . PHP_EOL;
?>


<?php
	$list = array();
	$out = 0;
	$fr = fopen("php://stdin","r");
	while ( $input = fgets($fr) )
	{
		$input = trim($input);
		switch ( $input[0] )
		{
			case '+':
				$input = substr($input, 1);
				$list[$input] = true;
				break;
			case '-':
				$input = substr($input, 1);
				unset( $list[$input] );
				break;
			default:
				$input = explode(':', $input, 2);
				$input = ltrim($input[1]);
				$out+= strlen($input) * count($list);
		}
	}
	fclose ($fr);

	echo $out;
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt ="Input
// +Mike
// Mike:hello
// +Kate
// +Dmitry
// -Dmitry
// Kate:hi
// -Kate
// ";

$text = explode("\n",$datatxt);
$users = array();
$length = 0;
foreach ($text as $value) {
if (strlen($value)>0){
if (preg_match("/^\+/",$value)){
$user = substr($value,1);
if (!isset($users[$user])) $users[$user] = $user;
} else if (preg_match("/^\-/",$value)){
$user = substr($value,1);
if (isset($users[$user])) unset($users[$user]);
} else {
$send = preg_split("/:/",$value,2);
$length+=strlen(trim($send[1]))*count($users);
}
}
}
echo $length;
?>

<?php
    $data = '';
    $inputData = fopen('php://stdin','r');
    while(!feof($inputData)) {
        $data .= fgetc($inputData);
    }
    fclose($inputData);

    $dataRaw = explode(PHP_EOL, $data);

    $users = array();
    $usersCount = 0;
    $totalBytes = 0;
    foreach($dataRaw as $str) {
         if(empty($str)) continue;
         if($str[0] == '+') {
              $userName = substr($str, 1, strlen($str));
              $users[$userName] = 0;
              $usersCount++;
         } elseif($str[0] == '-') {
             $userName = substr($str, 1, strlen($str));
             unset($users[$userName]);
             $usersCount--;
         }  else {
             $tmp = explode(':', $str);
             $msg = $tmp[1];
             if($msg[0]==" " || substr($msg,0,-1) == " ") {
                 continue;
             }  else {
//                 if(isset($users[$tmp[0]])) {
//                     $mn = $usersCount - 1;
//                 }  else {
                     $mn = $usersCount;
                 //}
                 $totalBytes += strlen($msg)*$mn;
             }
         }
    }
    echo $totalBytes;

<?php
$u = 0;
$l = 0;
while($c = fgets(STDIN)){
 $c = trim($c);
 switch($c[0]){
  case '+': $u ++; break;
  case '-': $u --; break;
  default: list($user, $message) = explode(':',$c);
           $l += strlen($message) * $u;
           break;
 }
}
print $l;
?>

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

$lines=explode("\n", $lines);

$size=0;
$users=0;
foreach ($lines as $line)
{
    $line=trim($line);
    if ($line{0}=="+")
        $users++;
    elseif ($line{0}=="-")
        $users--;
    else
    {
        list($from, $mess)=explode(":", $line);
        $size+=strlen($mess)*$users;

    }
}
echo $size;
?>

<?php

error_reporting(0);

solve();

function solve(){

	$user = 0;
	$bytes = 0;

	//$fp = @fopen("input.txt", "r");
	while(true)
	{
		//$com = rtrim(fgets($fp));
		$com = rtrim(fgets(STDIN));
		if ($com === "") break;

		if (strpos($com, "+") === 0) $user++;
		else if (strpos($com, "-") === 0) $user--;
		else $bytes += (strlen($com) - strpos($com, ":") - 1) * $user;
	}

	printf("%d",$bytes);
}
?>

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

$data = explode("\r\n", $data);
$bytes = 0;
$users = 0;

foreach($data as $line) {
    $line = trim($line);
    if(substr($line, 0, 1) == '+') {
        $users++;
        continue;
    }

    if(substr($line, 0, 1) == '-') {
        $users--;
        continue;
    }

    list($author, $message) = explode(":", $line);
    $bytes += strlen($message) * $users;
}

echo $bytes;

<?php
$input = file_get_contents("php://stdin");

$e = explode("\r\n",$input);

$count=0;
$data = 0;
foreach($e as $a)
{
    if($a[0]=="+")
    {
        $count++;
    }
    else if($a[0]=="-")
    {
        $count--;
    }
    else
    {
        $r = explode(":",$a);
        $data+=strlen($r[1])*$count;
    }
}
echo $data;
?>

<?php
function getName($item){
    $name = FALSE;
    if ($item{0} == "+"){
        $name = trim(ltrim(stristr($item, '+'), '+'));
    }elseif($item{0} == "-"){
        $name = trim(ltrim(stristr($item, '-'), '-'));
    }elseif(isMessage($item)){
        $name = trim(stristr($item, ':', true));
    }

    return $name;
}

function getMessageSize($item){
    $message = trim(ltrim(stristr($item, ':'), ":"));
    $size = strlen($message);
    return $size;
}

function isMessage($item){
    if (($item{0} != '+') && ($item{0} != '-') && (strpos($item, ":") != FALSE)){
        return TRUE;
    }else{
        return FALSE;
    }
}

function checkUser(&$arrUsers, $item){
    $name = getName($item);
    $res  = FALSE;
    foreach ($arrUsers as $login) {
        if ($login === $name){
            $res = TRUE;
        }
    }
    return $res;
}

function addUser(&$arrUsers, $name){
    $arrUsers[] = $name;
}

function deleteUser(&$arrUsers, $name){
    $res = FALSE;
    foreach ($arrUsers as $index =>$login) {
        if ($name === $login){
            unset($arrUsers[$index]);
            $res = TRUE;
            sort($arrUsers);
        }
    }
    return $res;
}

#получить файл и сформировать из него массив
$chat = file_get_contents("php://stdin");

//$chat = file_get_contents("test.txt");
$arrLogChat = explode("\n", $chat);

$arrActUser = array();
$size = 0;

foreach ($arrLogChat as $logItem) {
    if ($logItem{0} == "+"){
        addUser($arrActUser, getName($logItem));
        next;
    }elseif($logItem{0} == "-"){
        deleteUser($arrActUser, getName($logItem));
        next;
    }else{
        if (isMessage($logItem)){
            if (checkUser($arrActUser, $logItem)){
                $size = $size + (getMessageSize($logItem) * count($arrActUser));
            }else{
                next;
            }
        }else{
            next;
        }
    }
}

fwrite(STDOUT, $size);
//echo $size;
?>

<?php

error_reporting(0);

solve();

function solve(){
	//$Input = new Input("input.txt");
	$Input = new Input();

	$user = 0;
	$bytes = 0;

	while(true)
	{
		$com = $Input->in();
		if ($com === "") break;

		if (strpos($com, "+") === 0) $user++;
		else if (strpos($com, "-") === 0) $user--;
		else $bytes += (strlen($com) - strpos($com, ":") - 1) * $user;
	}

	print($bytes);
}

class Input{
	private $handle = "";
	private $values = array();
	private $index = 0;

	public function __construct($localfile){

		if (is_file($localfile)) {

			$this->handle = fopen($localfile, "r");
			$contents = stream_get_contents($this->handle);

		} else {

			$contents = stream_get_contents(STDIN);

		}

		$no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->values = explode(" ", $no_newlines);
	}

	public function in(){

		return $this->values[$this->index++];

	}

	public function close(){

		if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

	}
}

?>

<?php
function getName($item){
    $name = FALSE;
    if ($item{0} == "+"){
        $name = trim(ltrim(stristr($item, '+'), '+'));
    }elseif($item{0} == "-"){
        $name = trim(ltrim(stristr($item, '-'), '-'));
    }elseif(isMessage($item)){
        $name = trim(stristr($item, ':', true));
    }

    return $name;
}

function getMessageSize($item){
    $message = trim(ltrim(stristr($item, ':'), ":"));
    $size = strlen($message);
    return $size;
}

function isMessage($item){
    if (($item{0} != '+') && ($item{0} != '-') && (strpos($item, ":") != FALSE)){
        return TRUE;
    }else{
        return FALSE;
    }
}

function checkUser(&$arrUsers, $item){
    $name = getName($item);
    $res  = FALSE;
    foreach ($arrUsers as $login) {
        if ($login === $name){
            $res = TRUE;
        }
    }
    return $res;
}

function addUser(&$arrUsers, $name){
    $arrUsers[] = $name;
}

function deleteUser(&$arrUsers, $name){
    $res = FALSE;
    foreach ($arrUsers as $index =>$login) {
        if ($name === $login){
            unset($arrUsers[$index]);
            $res = TRUE;
            sort($arrUsers);
        }
    }
    return $res;
}

#получить файл и сформировать из него массив
$chat = file_get_contents("php://stdin");

//$chat = file_get_contents("test.txt");
$arrLogChat = explode("\n", $chat);

$arrActUser = array();
$size = 0;

foreach ($arrLogChat as $logItem) {
    if ($logItem{0} == "+"){
        addUser($arrActUser, getName($logItem));
        next;
    }elseif($logItem{0} == "-"){
        deleteUser($arrActUser, getName($logItem));
        next;
    }else{
        if (isMessage($logItem)){
            if (checkUser($arrActUser, $logItem)){
                $size = $size + getMessageSize($logItem);
            }else{
                next;
            }
        }else{
            next;
        }
    }
}

echo $size;
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt ="h1
// b2";
$text = explode("\n",$datatxt);
$users = array();
$length = 0;
foreach ($text as $value) {
if (strlen($value)>0){
if (preg_match("/^\+/",$value)){
$user = substr($value,1);
if (!isset($users[$user])) $users[] = $user;
} else if (preg_match("/^\-/",$value)){
$user = substr($value,1);
if (isset($users[$user])) unset($users[$user]);
} else {
$send = preg_split("/:/",$value,2);
$length+=strlen(trim($send[1]))*count($users);
}
}
}
echo $length;
exit;
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt ="h1
// b2";
$text = explode("\n",$datatxt);
$users = array();
$length = 0;
foreach ($text as $value) {
if (strlen($value)>0){
if (preg_match("/^\+/",$value)){
$user = substr($value,1);
if (!isset($users[$user])) $users[] = $user;
} else if (preg_match("/^\-/",$value)){
$user = substr($value,1);
if (isset($users[$user])) unset($users[$user]);
} else {
$send = preg_split("/:/",$value,2);
$length+=strlen(trim($send[1]))*count($users);
}
}
}
echo $length;
?>

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

$lines=explode("\n", $lines);

$size=0;
foreach ($lines as $line)
{
    $line=trim($line);
    if ($line{0}=="+")
        $users[]=$line;
    elseif ($line{0}=="-")
        unset($users[array_search(line, $users)]);
    else
    {
        list($from, $mess)=explode(":", $line);
        $size+=strlen($mess)*(count($users));

    }

}
echo $size;
?>


<?php
while($s = fgets(STDIN)){
    $input .= $s;
}
$input = explode("\r\n", $input);
$a=explode(" ", $input[1]);
$fl=0;
foreach($a as $number) {
    if ($number < 0) {
        $i++ ;
    }
    elseif ($number > 0) {
        $n++;
    }
}

foreach($a as $number) {
    if($number == 0) {
        $b[3][]=$number;
    }
    elseif ($number < 0) {
        if ($fl == 0) {
            $b[1][]=$number;
            $fl++;
        }
        elseif ($n == 0) {
            if ($i % 2 != 0) {
                $b[2][]=$number;
            }
            elseif (count($b[2]) == 0 || count($b[2]) % 2 != 0) {
                $b[2][]=$number;
            }
            else $b[3][]=$number;
        }
        else $b[3][]=$number;
    }
    else $b[2][]=$number;
}
echo count($b[1])." ";
foreach($b[1] as $number) {
    echo $number." ";
}
echo "\r\n".count($b[2])." ";
foreach($b[2] as $number) {
    echo $number." ";
}
echo "\r\n".count($b[3])." ";
foreach($b[3] as $number) {
    echo $number." ";
}
?>

<?php
while($s = fgets(STDIN)){
    $input .= $s;
}
$input = explode("\r\n", $input);
$a=explode(" ", $input[1]);
$fl=0;
foreach($a as $number) {
    if ($number < 0) {
        $i++ ;
    }
    elseif ($number > 0) {
        $n++;
    }
}

foreach($a as $number) {
    if($number == 0) {
        $b[3][]=$number;
    }
    elseif ($number < 0) {
        if ($fl == 0) {
            $b[1][]=$number;
            $fl++;
        }
        elseif ($n==0) {
            $b[2][]=$number;
        }
        else $b[3][]=$number;
    }
    else $b[2][]=$number;
}
echo count($b[1])." ";
foreach($b[1] as $number) {
    echo $number." ";
}
echo "\r\n".count($b[2])." ";
foreach($b[2] as $number) {
    echo $number." ";
}
echo "\r\n".count($b[3])." ";
foreach($b[3] as $number) {
    echo $number." ";
}
?>


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = array($b);
$e = array($b);
for($x = 1; $x < $a; $x++)
{
    $d = trim(fgets(STDIN));
    if($d == $c[$x - 1])
    {
        array_push($c, $d);
    }
    elseif($d < $c[$x - 1])
    {
        array_push($c, $d);
        array_push($e, $c[$x - 1] - $d);
    }
    elseif($d > $c[$x - 1])
    {
        array_push($c, $d);
        array_push($e, $d - $c[$x - 1]);
    }
}
print array_sum($e) + $a + $a - 1;
?>

<?php

function cin()
{
	$row = explode(" ", trim(fgets(STDIN)));
	return $row[0];
}
$n = cin();
$last = 0;
$ans = 2 * $n - 1;
for($i = 0; $i < $n; ++$i)
{
	$a[$i] = cin();
	$ans += abs($a[$i] - $last);
	$last = $a[$i];
}
echo $ans."\n";

?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = array($b);
$e = array($b);
for($x = 1; $x < $a; $x++)
{
    $d = trim(fgets(STDIN));
    if($d == $c[$x - 1])
    {
        array_push($d);
    }
    elseif($d > $c[$x - 1])
    {
        array_push($c, $d);
        array_push($e, $d - $c[$x - 1]);
    }
    elseif($d < $c[$x - 1])
    {
        array_push($c, $d);
        array_push($e, $c[$x - 1] - $d);
    }
}
print array_sum($e) + $a + $a - 1;
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = array($b);
for($x = 1; $x < $a; $x++)
{
    $d = trim(fgets(STDIN));
    if($d == $c[$x - 1])
    {
        array_push($c);
    }
    elseif($d > $c[$x - 1])
    {
        array_push($c, $d - $c[$x - 1]);
    }
    elseif($d < $c[$x - 1])
    {
        array_push($c, $c[$x - 1] - $d);
    }
}
print array_sum($c) + $a + $a - 1;
?>


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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   if($n == 3) {
        $ans = -1;
   } elseif($n == 1) {
        $ans = '1';
   } else {
        $ans = '';
        $temp = $n;
        $z = false;
        if($n == 5) {
            $ans = '5 4 1 2 3';
        } else {
           for($i=1; $i<= $n; $i++) {
             if($i == $temp ) {
                  $z = true;
                  $r = $temp -1;
                  $ans .= $r . ' ';
             } else {
                  if($z) {
                    $ans .= $temp + 1 . ' ';
                    $z = false;
                  } else {
                     $ans .= $temp . ' ';
                  }

             }
             $temp--;

        }
        }

   }
   IO::pr($ans);
}

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

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

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s,$t] = explode(' ', trim(fgets(STDIN)));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$s = explode(' ', trim(fgets(STDIN)));
//function decr($v){return --$v;}
//$alpha='abcdefghijklmnopqrstuvwxyz';
//$mod=1000000009;
//$mod=1000000007;
//$mod=998244353;
//$a=[];
//$b=[];
for($i=0;$i<$n;$i++){
    [$p] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    if($p==2){
        $ans[] = "2 1";
        continue;
    }
    if($p==3){
        $ans[] = -1;
        continue;
    }
    $str = "";
    for($j=$p-1;$j<=$p;$j++){
        $str .= $j." ";
    }
    for($j=1;$j<=$p-2;$j++){
        $str .= $j." ";
    }
    $ans[] = substr($str,0,strlen($str)-1);
}
echo implode(PHP_EOL,$ans);

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   if($n == 3 || $n==1) {
        $ans = -1;
   } else {
        $ans = '';
        $temp = $n;
        $z = false;
        for($i=1; $i<= $n; $i++) {
             if($i == $temp ) {
                  $z = true;
                  $r = $temp -1;
                  $ans .= $r . ' ';
             } else {
                  if($z) {
                    $ans .= $temp + 1 . ' ';
                    $z = false;
                  } else {
                     $ans .= $temp . ' ';
                  }

             }
             $temp--;

        }
   }
   IO::pr($ans);
}

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

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


<?php

function debug($data, $die = true) {
    echo '<pre>';

    if (is_array($data)) {
        print_r($data);
    } else {
        var_dump($data);
    }

    if ($die) {
        die();
    }

    echo '</pre>';
}

function stdin() {
    $stdin = @fopen('data.txt', 'r');
    if (!$stdin) {
        $stdin = fopen('php://stdin', 'r');
    }

    return $stdin;
}

function g() {
    global $stdin;
    return trim(fgets($stdin));
}

$stdin = stdin();
/****************************************************** Solving block *****************************************************/
$n = g();

$teams = array();
for ($i = 0; $i < $n; $i++) {
    $teams[g()] = array('score' => 0, 'diffr' => 0, 'goals' => 0);
}

$games = $n * ($n - 1) / 2;
for ($i = 0; $i < $games; $i++) {
    list($team, $score) = explode(' ', g());
    list($team1, $team2) = explode('-', $team);
    list($score1, $score2) = explode(':', $score);

    $teams[$team1]['score'] += $score1 > $score2 ? 3 : ($score1 == $score2 ? 1 : 0);
    $teams[$team1]['diffr'] += $score1 - $score2;
    $teams[$team1]['goals'] += $score1;

    $teams[$team2]['score'] += $score2 > $score1 ? 3 : ($score1 == $score2 ? 1 : 0);
    $teams[$team2]['diffr'] += $score2 - $score1;
    $teams[$team2]['goals'] += $score2;
}

$list = array_keys($teams);

$size = sizeof($list);
for($i = 0; $i < $size; $i++) {
    for($j = $i+1; $j < $size; $j++) {
        $team1 = $list[$i];
        $team2 = $list[$j];
        $score1 = $teams[$team1]['score'];
        $score2 = $teams[$team2]['score'];
        $diffr1 = $teams[$team1]['diffr'];
        $diffr2 = $teams[$team2]['diffr'];
        $goals1 = $teams[$team1]['goals'];
        $goals2 = $teams[$team2]['goals'];

        $swap = $score1 < $score2 || $score1 == $score2 && $diffr1 < $diffr2 || $score1 == $score2 && $diffr1 == $diffr2 && $goals1 < $goals2;
        if($swap) {
            $list[$i] = $team2;
            $list[$j] = $team1;
        }
    }
}

$off = $n / 2;
$play = array();
for($i = 0; $i < $off; $i++) {
    $play[] = $list[$i];
}

sort($play);

echo implode("\n", $play)

?>


<?php

function main() {
    # I/O stream.
    define('INSTREAM', STDIN, FALSE);
    define('OUTSTREAM', STDOUT, FALSE);
    // define('INSTREAM', fopen("in.txt", "r"), FALSE);
    // define('OUTSTREAM', fopen("out.txt", "w"), FALSE);

    fscanf(INSTREAM, "%d %d", $n, $m);

    for($i = 0; $i < $m; ++$i) {
        fscanf(INSTREAM, "%*d %*d");
    }

    for($i = 0; $i < $n; ++$i) {
        echo ($i & 1)? '0' : '1';
    }

    echo "\n";
}

main();

?>

<?php
$dir                    = fopen("php://stdin", 'r');
$contents               = stream_get_contents($dir);
$inputs                 = explode("\n",$contents);
$flowersCount           = (int) explode(' ', $inputs[0])[0];
$visitorsCount          = (int) explode(' ', $inputs[0])[1];
getString($flowersCount, $visitorsCount);
function getString($flowersCount, $visitorsCount)
{
    $arr = [];
    for($i = 0; $i < $flowersCount; $i++)
    {
        if($i % 2 == 0)
        {
            $arr[] = 0;
        } else{
            $arr[] = 1;
        }
    }
    echo implode('',$arr);
}
?>


<?php
$a = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = ($b - 1) * 9 + $c;
     printf("%.0f", $d);
     print "\n";
}
?>


<?php

$tests = getLineInt();

for ($test = 0; $test < $tests; $test++)
{
    $n = getLineInt();

    $s = getLineInts();

    $result = array();

    list($max1, $max2) = max2($s);

    for ($index = 0; $index < $n; $index++)
    {
        $result[] = $s[$index] - ($s[$index] < $max1 ? $max1 : $max2);
    }

    echo(implode(' ', $result) . PHP_EOL);
}

// Helpers

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

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

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

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

function max2(array $array)
{
    $max1 = $max2 = 0;

    for ($index = 0; $index < count($array); $index++)
    {
        if ($array[$index] > $max1)
        {
            $max2 = $max1;
            $max1 = $array[$index];
        }

        else if ($array[$index] > $max2)
        {
            $max2 = $array[$index];
        }
    }

    return array($max1, $max2);
}

<?php
$t = trim(fgets(STDIN));
for($i=0; $i <$t; $i++) {
    $n =  trim(fgets(STDIN));
	$a =  explode(' ', trim(fgets(STDIN)));
    $max = max($a);
    $copyArr = $a;
    sort($copyArr);
    $max2 = $copyArr[sizeof($copyArr)-2];
    for($j = 0; $j < $n; $j++){
            if ($a[$j] == $max)
            {
                $diff = $max - $max2;
            } else {
                $diff = $a[$j] - $max;
            }
        echo $diff . " ";
    }
    echo "\n";
}

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

    $iMax = max($a);
    $newArr = [];
    $aCach = [];
    for ($i = 0; $i < $n; $i++) {
        $iNum = $a[$i];
        unset($a[$i]);

        if (isset($aCach[$iNum])) {
            $newArr[$i] = $aCach[$iNum];
        } else {
            if ($iMax == $iNum) {
                $iMax2 = max($a);
                $newArr[$i] = $iNum - $iMax2;
            } else {
                $newArr[$i] = $iNum - $iMax;
            }
        }

        $a[$i] = $iNum;
        $aCach[$iNum] = $newArr[$i];
    }

    echo implode(' ', $newArr) . PHP_EOL;
}

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

for($i=0; $i <$iter; $i++) {
    $iterA = InOutPut::get();
    $arr = InOutPut::getArr();
    $max = max($arr);
    $copyArr = $arr;
    sort($copyArr);
    $max2 = $copyArr[sizeof($copyArr)-2];
    for($j = 0; $j < $iterA; $j++){
            if ($arr[$j] == $max)
            {
                $diff = $max - $max2;
            } else {
                $diff = $arr[$j] - $max;
            }
        echo $diff . " ";
    }
    echo "\n";
}

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

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    $n = getLineInt();

    $s = getLineInts();

    list($max1, $max2) = max2($s);

    for ($index = 0; $index < $n; $index++)
    {
        $results[$test][] = $s[$index] - ($s[$index] < $max1 ? $max1 : $max2);
    }

    $results[$test] = implode(' ', $results[$test]);
}

echo(implode(PHP_EOL, $results));

// Helpers

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

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

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

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

function max2(array $array)
{
    $max1 = $max2 = 0;

    for ($index = 0; $index < count($array); $index++)
    {
        if ($array[$index] > $max1)
        {
            $max2 = $max1;
            $max1 = $array[$index];
        }

        else if ($array[$index] > $max2)
        {
            $max2 = $array[$index];
        }
    }

    return array($max1, $max2);
}

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

    $iMax = max($a);
    $newArr = [];
    $aCach = [];
    for ($i = 0; $i < $n; $i++) {
        $iNum = $a[$i];
        unset($a[$i]);

        if (isset($aCach[$iNum])) {
            $newArr[$i] = $aCach[$iNum];
        } else {
            if ($iMax == $iNum) {
                $iMax2 = max($a);
                $newArr[$i] = $iNum - $iMax2;
            } else {
                $newArr[$i] = $iNum - $iMax;
            }
        }

        $a[$i] = $iNum;
        $aCach[$iNum] = $iNum;
    }

    echo implode(' ', $newArr) . PHP_EOL;
}

<?php
$t = trim(fgets(STDIN));
for($i=0; $i <$iter; $i++) {
    $n =  trim(fgets(STDIN));
	$a =  explode(' ', trim(fgets(STDIN)));
    $max = max($a);
    $copyArr = $a;
    sort($copyArr);
    $max2 = $copyArr[sizeof($copyArr)-2];
    for($j = 0; $j < $n; $j++){
            if ($a[$j] == $max)
            {
                $diff = $max - $max2;
            } else {
                $diff = $a[$j] - $max;
            }
        echo $diff . " ";
    }
    echo "\n";
}


<?php
list($n,$k)=explode(' ',trim(fgets(STDIN)));
$A=explode(' ',trim(fgets(STDIN)));
for ($i=1;$i<=$n;$i++){
	if ($k<=$i){
		echo $A[$k-1];
		return;
	} else $k-=$i;
}
?>


<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$s = $ir->readString();
$not = [
	'R' => 'G',
	'G' => 'B',
	'B' => 'R',
	'R.R' => 'G',
	'G.G' => 'B',
	'B.B' => 'R',
	'R.G' => 'B',
	'G.R' => 'B',
	'G.B' => 'R',
	'B.G' => 'R',
	'R.B' => 'G',
	'B.R' => 'G',
];

$cnt = 0;
$s = $s . $not[$s[$n-1]];
for ($i=1; $i<$n; $i++) {
	if ($s[$i]==$s[$i-1]) {
		$cnt++;
		$s[$i] = $not[$s[$i] .'.'. $s[$i+1]];
	}
}

echo $cnt."\n";
echo substr($s, 0, $n);


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = ceil($d / $b);
$g = $c - $e;
$h = 0;
while(TRUE)
{
     $i = ceil($a / $e);
     if($i >= $f)
     {
          break;
     }
     else
     {
          $a += $g;
          $h++;
     }
}
print ($f + $h) . "\n";
for($x = 0; $x < $h; $x++)
{
     print "HEAL\n";
}
for($x = 0; $x < $f; $x++)
{
     print "STRIKE\n";
}
?>

<?php

list($h1,$a1,$c1) = explode(" ",trim(fgets(STDIN)));
list($h2,$a2) = explode(" ",trim(fgets(STDIN)));

$liparitBagvashi = "";
$demnaUfliswuli = 0;

while($h2>0){
    $demnaUfliswuli++;

    if($h2-$a1<=0){
        $liparitBagvashi .= "STRIKE"."\n";
        $h2-=$a1;
    }

    elseif($h1 - $a2 > 0){
        $liparitBagvashi .= "STRIKE"."\n";
        $h2-=$a1;
    }

    else{
        $liparitBagvashi .= "HEAL"."\n";
        $h1+=$c1;
    }
    $h1-=$a2;
}

echo $demnaUfliswuli."\n".$liparitBagvashi;

?>

<?php

list($h1, $a1, $c1) = explode(' ', trim(fgets(STDIN)));
list($h2, $a2) = explode(' ', trim(fgets(STDIN)));

$action_list = [];
while (true)
{
	if ($h1 - $a2 <= 0 && ($h2 - $a1) > 0)
	{
		$h1 += $c1;
		$action_list[] = 'HEAL';
	}
	else
	{
		$h2 -= $a1;
		$action_list[] = 'STRIKE';
	}

	if ($h2 <= 0)
	{
		break;
	}
	$h1 -= $a2;
}

echo count($action_list).PHP_EOL;
foreach ($action_list as $action)
{
	echo $action.PHP_EOL;
}

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = array();
while(TRUE)
{
     $g = $a - $e;
     $h = $d - $b;
     if($g <= 0)
     {
          $a += $c;
          $f[count($f)] = "HEAL";
     }
     else
     {
          $a -= $e;
          $d -= $b;
          if($h <= 0)
          {
               $f[count($f)] = "STRIKE";
               break;
          }
          else
          {
               $f[count($f)] = "STRIKE";
          }
     }
}
print count($f) . "\n";
for($x = 0; $x < count($f); $x++)
{
     print $f[$x] . "\n";
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = array();
while(TRUE)
{
     $g = $d - $b;
     $h = $a - $e;
     if($h <= 0)
     {
          $a += $c;
          $f[count($f)] = "HEAL";
     }
     elseif($h > 0)
     {
          $a -= $e;
          if($g <= 0)
          {
               $f[count($f)] = "STRIKE";
               break;
          }
          else
          {
               $d -= $b;
               $f[count($f)] = "STRIKE";
          }
     }
}
print count($f) . "\n";
for($x = 0; $x < count($f); $x++)
{
     print $f[$x] . "\n";
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = array();
while(TRUE)
{
     $g = $d - $b;
     $h = $a - $e;
     if($h <= 0)
     {
          if($g <= 0)
          {
               $f[count($f)] = "STRIKE";
               break;
          }
          else
          {
               $a += $c;
               $f[count($f)] = "HEAL";
          }
     }
     elseif($h > 0)
     {
          $a -= $e;
          if($g <= 0)
          {
               $f[count($f)] = "STRIKE";
               break;
          }
          else
          {
               $d -= $b;
               $f[count($f)] = "STRIKE";
          }
     }
}
print count($f) . "\n";
for($x = 0; $x < count($f); $x++)
{
     print $f[$x] . "\n";
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = array();
while(TRUE)
{
     $g = $d - $b;
     $h = $a - $e;
     if($g <= 0)
     {
          $f[count($f)] = "STRIKE";
          break;
     }
     elseif($g > 0)
     {
          $d -= $b;
          $f[count($f)] = "STRIKE";
     }
     if($h <= 0)
     {
          $a += $c;
          $f[count($f)] = "HEAL";
     }
     elseif($h > 0)
     {
          $a -= $e;
     }
}
print count($f) . "\n";
for($x = 0; $x < count($f); $x++)
{
     print $f[$x] . "\n";
}
?>

<?php

list($h1, $a1, $c1) = explode(' ', trim(fgets(STDIN)));
list($h2, $a2) = explode(' ', trim(fgets(STDIN)));

$action_list = [];
while (true)
{
	if ($h1 - $a2 <= 0)
	{
		$h1 += $c1;
		$action_list[] = 'HEAL';
	}
	else
	{
		$h2 -= $a1;
		$action_list[] = 'STRIKE';
	}

	if ($h2 <= 0)
	{
		break;
	}
	$h1 -= $a2;
}

echo count($action_list).PHP_EOL;
foreach ($action_list as $action)
{
	echo $action.PHP_EOL;
}

<?php

//while coding listening to this => https://youtu.be/ZenkI6QvosE
//ჩამოთოვა ისევ მამუკა ჩარკვიანი

list($h1,$a1,$c1) = explode(" ",trim(fgets(STDIN)));
list($h2,$a2) = explode(" ",trim(fgets(STDIN)));

$liparitBagvashi = "";
$demnaUfliswuli = 0;

while($h2>0){
    $demnaUfliswuli++;

    if($h2-$a1<0){
        $liparitBagvashi .= "STRIKE"."\n";
        $h2-=$a1;
    }

    elseif($h1 - $a2 > 0){
        $liparitBagvashi .= "STRIKE"."\n";
        $h2-=$a1;
    }

    else{
        $liparitBagvashi .= "HEAL"."\n";
        $h1+=$c1;
    }
    $h1-=$a2;
}

echo $demnaUfliswuli."\n".$liparitBagvashi;

?>


<?php
$f = file('php://stdin');
$n = $f[0] + 0;
$f_out = fopen('php://stdout', 'w+');
for ($i = 1; $i <= $n; $i++) {
	$data = $f[$i];
	$a = $data + 0;
	$b = substr($data, strpos($data, ' ') + 1) + 0;
	$count = 0;
	while ($a && $b) {
		if ($a > $b) {
			$count2 = floor($a / $b);
			$a -= $b * $count2;
			$count += $count2;
		} else {
			$count2 = floor($b / $a);
			$b -= $a * $count2;
			$count += $count2;
		}
	};
	fwrite($f_out, $count . "\n");
}
fclose($f_out);

<?php
$f = file('input.txt');
$n = $f[0] + 0;
$f_out = fopen('output.txt', 'w+');
for ($i = 1; $i <= $n; $i++) {
	$data = $f[$i];
	$a = $data + 0;
	$b = substr($data, strpos($data, ' ') + 1) + 0;
	$count = 0;
	while ($a && $b) {
		if ($a > $b) {
			$count2 = floor($a / $b);
			$a -= $b * $count2;
			$count += $count2;
		} else {
			$count2 = floor($b / $a);
			$b -= $a * $count2;
			$count += $count2;
		}
	};
	fwrite($f_out, $count . "\n");
}
fclose($f_out);


<?php
// $n=fgets(STDIN);
// settype($n,'int');
// $array=explode(' ',fgets(STDIN));
// $max=max($array);
// $s=0;
// $min=min($array);
// $smin=0;
// $smax=1000;
// settype($array[0],'int');
// settype($array[$n-1],'int');
// settype($max,'int');
// settype($min,'int');
// for ($i=0; $i <count($array) ; $i++) {
//       if($array[$i] == $min){
//             $smin=$i;
//       }
// }
// if ($array[0] == max($array) && $array[count($array)-1] ==$min) {
//       echo '0';
//       exit;
// }
// for ($i=$smin; $i <count($array) ; $i++) {
//       if($i !=count($array)-1 and $array[$i] < @$array[$i+1]){
//             $x=$array[$i];
//             $array[$i]=$array[$i+1];
//             $array[$i+1]=$x;
//             $s++;
//       }
// }
// for ($i=0; $i <count($array)-1 ; $i++) {
//       settype($array[$i],'int');
//       if(max($array) == $array[$i]){
//           $smax=$i;
//           break;
//       }
// }

// for ($i=$smax; $i >= 0 ; $i--) {
// if($i !=0){
//       $x=$array[$i];
//       $array[$i]=$array[$i-1];
//       $array[$i-1]=$x;
//       $s++;
// }
// }
// echo $s;

$n=fgets(STDIN);
$one=0;
$zero=0;
$input=str_split(fgets(STDIN),1);
foreach ($input as $key => $value) {
      if ($value == 1) {
            $one++;
      }else if($value == 0){
         $zero++;
      }
}
$zero-=2;
echo max($zero,$one)-min($zero,$one);
# thanks danial !

<?php
$stdin = fopen("php://stdin", 'r');
fscanf($stdin, "%d\n", $n);
$s = fgets($stdin);
fclose($stdin);

$stack = [];
for ($i = 0; $i < $n; ++$i)
{
    $m = count($stack);
    $cur = $s[$i] + 0;
    if ($m == 0 || ($stack[$m - 1] xor $cur) == 0)
    {
        $stack[] = $cur;
    }
    else
    {
        array_pop($stack);
    }
}
echo count($stack);
?>

<?php

$len = trim(fgets(STDIN));
$str = trim(fgets(STDIN));

// $len = 200000;
// $str = '';

// for ($i = 0; $i < 100000; $i++)
// {
//     $str = $str . 0;
// }

// for ($i = 0; $i < 100000; $i++)
// {
//     $str = $str . 1;
// }

$arr = str_split($str);
$numOne = 0;
$numZero = 0;

foreach ($arr as $key => $value)
{
    if ($value == 1)
    {
        $numOne++;
    }
    else
    {
        $numZero++;
    }
}

echo abs($numZero - $numOne);

<?php
    $length = trim(fgets(STDIN));
    $val = trim(fgets(STDIN));

    $arr = array();

    for($i=0; $i<$length; $i++)
        $arr[$val[$i]]++;

    echo $length - min( $arr[0], $arr[1] ) * 2 . PHP_EOL;
?>

<?php

$n = trim(fgets(STDIN));
$str = trim(fgets(STDIN));

$len = strlen($str);

$cnt = 0;

for($i = 0; $i < $len; $i++) {
    if($str[$i] == '0') {
        $cnt++;
    } else {
        $cnt--;
    }
}

echo $cnt < 0 ? -1*$cnt : $cnt;

?>

<?php
    $length = trim(fgets(STDIN));
    $val = trim(fgets(STDIN));
    $res = 0;
    $initLength = $length;

    $val = str_replace('01', '', $val, $cnt);
    $res += $cnt;
    $val = str_replace("10", '', $val, $cnt);
    $res += $cnt;
    $val = str_replace("01", '', $val, $cnt);
    $res += $cnt;
    $val = str_replace("10", '', $val, $cnt);
    $res += $cnt;

    echo $initLength - $res * 2 . PHP_EOL;
?>

<?php
    $length = trim(fgets(STDIN));
    $val = trim(fgets(STDIN));
    $res = 0;
    $cnt = 1;
    $initLength = $length;

    $flag = true;

    while($flag)
    {
        $val = str_replace('01', '', $val, $cnt);
            $res += $cnt;

        if($cnt)
            $flag = true;
        else $flag = false;

        $val = str_replace("10", '', $val, $cnt);
            $res += $cnt;

        if($cnt)
            $flag = true;
        else $flag = false;
    }

    echo $initLength - $res * 2 . PHP_EOL;
?>


<?php
// 463B     Caisa и колонны
$in = fopen("php://stdin", 'r');

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

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

$energy = 0;
$price = $arrH[0];
$height = $arrH[0];

for ($i=0; $i < $n-1; $i++) {
    $energy += $height - $arrH[$i];
    $height = $arrH[$i];
    if (($energy + ($height - $arrH[$i+1])) < 0) {
        $price += - ($energy + ($height - $arrH[$i+1]));
        $energy = - ($height - $arrH[$i+1]);
    }
}

echo $price;

?>


<?php
# 1165D

$start = microtime(true);

function getPrimeNumbersViaErastofen($n)
{
    /** @var int[] $result */
    $result[2] = 2;
    for ($i = 3; $i <= $n; $i += 2) {
        if ($i >= 10 && (($i % 5) === 0)) {
            continue;
        }
        $result[$i] = $i;
    }

    $i = reset($result);
    while ($i !== false) {
        if (isset($result[$i])) {
            /** @var int $j */
            $j = $i * 2;
            while ($j < $n) {
                unset($result[$j]);
                $j += $i;
            }
        }
        $i = next($result);
    }
    return $result;
}

$primes = getPrimeNumbersViaErastofen(1000);

$stdin = STDIN;
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    sort($delimiters);
    $minDelimiter = $delimiters[0];
    $maxDelimiter = $delimiters[$n - 1];

    $digit = (float)$minDelimiter * (float)$maxDelimiter;
    $halfOfDigit = $digit / 2;

    $baseDelimiters = [$minDelimiter => $minDelimiter];
    foreach ($primes as $prime) {
        $prime = (string)$prime;
        if ($prime >= $halfOfDigit) {
            break;
        }
        if (bcmod($digit, $prime) === '0') {
            $baseDelimiters[$prime] = $prime;
        }
    }

    if (count($baseDelimiters) > $n) {
        echo '-1' . PHP_EOL;
        continue;
    }

    $tmp = [];
    while ($tmp !== $baseDelimiters) {
        $tmp = $baseDelimiters;
        foreach ($baseDelimiters as $a) {
            foreach ($baseDelimiters as $b) {
                $result = $a * $b;
                $strResult = sprintf('%.0f', $result);
                if ($result < $digit && !isset ($baseDelimiters[$strResult]) && bcmod($digit, $result) === '0') {
                    $baseDelimiters[$result] = $result;
                }
            }
        }
    }
    foreach ($baseDelimiters as $delimiter) {
        $result = sprintf('%.0f', $digit / $delimiter);
        if (!isset($baseDelimiters[$result]) && bcmod($digit, $delimiter) === '0') {
            $baseDelimiters[$result] = $result;
        }
    }
    sort($baseDelimiters);

    echo ($baseDelimiters == $delimiters ? $digit : '-1') . PHP_EOL;
}

<?php
# 1165D

$start = microtime(true);

function getPrimeNumbersViaErastofen($n)
{
    /** @var int[] $result */
    $result[2] = 2;
    for ($i = 3; $i <= $n; $i += 2) {
        if ($i >= 10 && (($i % 5) === 0)) {
            continue;
        }
        $result[$i] = $i;
    }

    $i = reset($result);
    while ($i !== false) {
        if (isset($result[$i])) {
            /** @var int $j */
            $j = $i * 2;
            while ($j < $n) {
                unset($result[$j]);
                $j += $i;
            }
        }
        $i = next($result);
    }
    return $result;
}

$primes = getPrimeNumbersViaErastofen(1000);

$stdin = STDIN;
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    sort($delimiters);
    $minDelimiter = $delimiters[0];
    $maxDelimiter = $delimiters[$n - 1];

    $digit = (float)$minDelimiter * (float)$maxDelimiter;
    $halfOfDigit = $digit / 2;

    $baseDelimiters = [$minDelimiter => $minDelimiter];
    foreach ($primes as $prime) {
        $prime = (string)$prime;
        if ($prime >= $halfOfDigit) {
            break;
        }
        if (bcmod($digit, $prime) === '0') {
            $baseDelimiters[$prime] = $prime;
        }
    }

    if (count($baseDelimiters) > $n) {
        echo '-1' . PHP_EOL;
        continue;
    }

    $tmp = [];
    while ($tmp !== $baseDelimiters) {
        $tmp = $baseDelimiters;
        foreach ($baseDelimiters as $a) {
            foreach ($baseDelimiters as $b) {
                $result = $a * $b;
                if ($result < $digit && bcmod($digit, $result) === '0') {
                    $result = sprintf('%.0f', $result);
                    $baseDelimiters[$result] = $result;
                }
            }
        }
    }
    foreach ($baseDelimiters as $delimiter) {
        if (bcmod($digit, $delimiter) === '0') {
            $result = sprintf('%.0f', $digit / $delimiter);
            $baseDelimiters[$result] = $result;
        }
    }
    sort($baseDelimiters);

    echo ($baseDelimiters == $delimiters ? $digit : '-1') . PHP_EOL;
}

<?php
# 1165D
declare(strict_types=1);

$start = microtime(true);

function getPrimeNumbersViaErastofen($n)
{
    /** @var int[] $result */
    $result[2] = 2;
    for ($i = 3; $i <= $n; $i += 2) {
        if ($i >= 10 && (($i % 5) === 0)) {
            continue;
        }
        $result[$i] = $i;
    }

    $i = reset($result);
    while ($i !== false) {
        if (isset($result[$i])) {
            /** @var int $j */
            $j = $i * 2;
            while ($j < $n) {
                unset($result[$j]);
                $j += $i;
            }
        }
        $i = next($result);
    }
    return $result;
}

$primes = [];

$stdin = STDIN;
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    $wrongDigit = true;
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    $delimitersMap = array_keys($delimiters);
    sort($delimiters);
    $maxDelimiter = $delimiters[$n - 1];

    $digit = bcmul($delimiters[0], $maxDelimiter);
    $halfOfDigit = bcdiv($digit, '2');

    if ($primes === []) {
        $primes = getPrimeNumbersViaErastofen(10000);
    }
    $baseDelimiters = [$delimiters[0] => $delimiters[0]];
    foreach ($primes as $prime) {
        $prime = (string)$prime;
        if ($prime >= $halfOfDigit) {
            break;
        }
        if (bcmod($digit, $prime) === '0') {
            $baseDelimiters[$prime] = $prime;
        }
    }

    if (count($baseDelimiters) > $n) {
        echo '-1' . PHP_EOL;
        continue;
    }

    $tmp = [];
    while ($tmp !== $baseDelimiters) {
        $tmp = $baseDelimiters;
        foreach ($baseDelimiters as $a) {
            foreach ($baseDelimiters as $b) {
                $result = bcmul($a, $b);
                if ($result < $digit && bcmod($digit, $result) === '0') {
                    $baseDelimiters[$result] = $result;
                }
            }
        }
    }
    foreach ($baseDelimiters as $delimiter) {
        if (bcmod($digit, $delimiter) === '0') {
            $result = bcdiv($digit, $delimiter);
            $baseDelimiters[$result] = $result;
        }
    }
    sort($baseDelimiters);

    echo ($baseDelimiters == $delimiters ? $digit : '-1') . PHP_EOL;
}

<?php
# 1165D
declare(strict_types=1);

$start = microtime(true);

function getPrimeNumbersViaErastofen($n)
{
    /** @var int[] $result */
    $result[2] = 2;
    for ($i = 3; $i <= $n; $i += 2) {
        if ($i >= 10 && (($i % 5) === 0)) {
            continue;
        }
        $result[$i] = $i;
    }

    $i = reset($result);
    while ($i !== false) {
        if (isset($result[$i])) {
            /** @var int $j */
            $j = $i * 2;
            while ($j < $n) {
                unset($result[$j]);
                $j += $i;
            }
        }
        $i = next($result);
    }
    return $result;
}

$primes = [];

$stdin = STDIN;
//$stdin = fopen('/home/vilnitskiy/.PhpStorm2019.1/config/scratches/data.txt', 'rb');
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    $wrongDigit = true;
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    $delimitersMap = array_keys($delimiters);
    sort($delimiters);
    $maxDelimiter = $delimiters[$n - 1];

    $digit = bcmul($delimiters[0], $maxDelimiter);

    if ($primes === []) {
        $primes = getPrimeNumbersViaErastofen(100000);
    }
    $baseDelimiters = [$delimiters[0] => $delimiters[0]];
    foreach ($primes as $prime) {
        $prime = (string)$prime;
        if ($prime >= $digit) {
            break;
        }
        if (bcmod($digit, $prime) === '0') {
            $baseDelimiters[$prime] = $prime;
        }
    }

    if (count($baseDelimiters) > $n) {
        echo '-1' . PHP_EOL;
        continue;
    }

    foreach ($baseDelimiters as $delimiter) {
        $i = 2;
        $result = $delimiter;
        $valid = true;
        $result = bcpow($delimiter, (string)$i);
        $valid = $result < $digit;
        while ($valid) {
            $result = bcpow($delimiter, (string)$i);
            $valid = $result < $digit;
            if ($valid && bcmod($digit, $result) === '0') {
                $baseDelimiters[$result] = $result;
            }
            $i++;
        }
    }
    $tmp = [];
    while ($tmp !== $baseDelimiters) {
        $tmp = $baseDelimiters;
        foreach ($baseDelimiters as $a) {
            foreach ($baseDelimiters as $b) {
                $result = bcmul($a, $b);
                if ($result < $digit && bcmod($digit, $result) === '0') {
                    $baseDelimiters[$result] = $result;
                }
            }
        }
    }
    foreach ($baseDelimiters as $delimiter) {
        if (bcmod($digit, $delimiter) === '0') {
            $result = bcdiv($digit, $delimiter);
            $baseDelimiters[$result] = $result;
        }
    }
    sort($baseDelimiters);

    echo ($baseDelimiters == $delimiters ? $digit : '-1') . PHP_EOL;
}

//echo microtime(true) - $start;

<?php
# 1165D
declare(strict_types=1);

$start = microtime(true);

function getPrimeNumbersViaErastofen($n)
{
    /** @var int[] $result */
    $result[2] = 2;
    for ($i = 3; $i <= $n; $i += 2) {
        if ($i >= 10 && (($i % 5) === 0)) {
            continue;
        }
        $result[$i] = $i;
    }

    $i = reset($result);
    while ($i !== false) {
        if (isset($result[$i])) {
            /** @var int $j */
            $j = $i * 2;
            while ($j < $n) {
                unset($result[$j]);
                $j += $i;
            }
        }
        $i = next($result);
    }
    return $result;
}

$primes = [];

$stdin = STDIN;
//$stdin = fopen('/home/vilnitskiy/.PhpStorm2019.1/config/scratches/data.txt', 'rb');
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    $wrongDigit = true;
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    $delimitersMap = array_keys($delimiters);
    sort($delimiters);
    $maxDelimiter = $delimiters[$n - 1];

    if ($n <= 2) {
        echo bcmul($delimiters[0], $maxDelimiter) . PHP_EOL;
        continue;
    }

    for ($i = 0; $i < $n; $i++) {
        if (bcmod($maxDelimiter, $delimiters[$i]) !== '0') {
            $wrongDigit = false;
            break;
        }
    }
    if ($wrongDigit === true) {
        echo '-1' . PHP_EOL;
        continue;
    }

    $digit = bcmul($delimiters[0], $maxDelimiter);

    if ($primes === []) {
        $primes = getPrimeNumbersViaErastofen(100000);
    }
    $baseDelimiters = [];
    foreach ($primes as $prime) {
        $prime = (string)$prime;
        if ($prime >= $digit) {
            break;
        }
        if (bcmod($digit, $prime) === '0') {
            $baseDelimiters[$prime] = $prime;
        }
    }

    foreach ($baseDelimiters as $prime) {
        $i = 2;
        $result = $prime;
        $valid = true;
        do {
            $result = bcpow($prime, (string)$i);
            $valid = $result <= $digit;
            if ($valid && bcmod($digit, $result) === '0') {
                $baseDelimiters[$result] = $result;
            }
            $i++;
        } while ($valid);
    }
    $tmp = [];
    while ($tmp !== $baseDelimiters) {
        $tmp = $baseDelimiters;
        foreach ($baseDelimiters as $a) {
            foreach ($baseDelimiters as $b) {
                $result = bcmul($a, $b);
                if ($result < $digit && bcmod($digit, $result) === '0') {
                    $baseDelimiters[$result] = $result;
                }
            }
        }
    }
    sort($baseDelimiters);

    echo ($baseDelimiters === $delimiters ? $digit : '-1') . PHP_EOL;
}

//echo microtime(true) - $start;

<?php
# 1165D
declare(strict_types=1);

$stdin = STDIN;
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    sort($delimiters);
    $digit = bcmul($delimiters[0], $delimiters[$n - 1]);
    for ($i = 0; $i < $n; $i++) {
        if (bcmod($digit, $delimiters[$i]) !== '0') {
            $digit = bcmul($digit, $delimiters[$i]);
        }
    }
    for ($i = 0; $i < $n; $i++) {
        if ($digit === $delimiters[$i]) {
            $digit = '-1';
            break;
        }
    }

    echo $digit . PHP_EOL;
}

<?php
# 1165D
declare(strict_types=1);

$stdin = STDIN;
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    sort($delimiters);
    $maxDelimiter = $delimiters[$n - 1];
    $digit = bcmul($delimiters[0], $maxDelimiter);
    for ($i = 0; $i < $n; $i++) {
        if (bcmod($digit, $delimiters[$i]) !== '0') {
            $digit = '-1';
            break;
        }
    }
    if ($digit === '-1') {
        $digit = bcmul($maxDelimiter, $maxDelimiter);
        for ($i = 0; $i < $n; $i++) {
            if (bcmod($digit, $delimiters[$i]) !== '0') {
                $digit = '-1';
                break;
            }
        }
    }

    echo $digit . PHP_EOL;
}

<?php
# 1165D
//declare(strict_types=1);

function getPrimeNumbersViaErastofen($n)
{
    /** @var int[] $result */
    $result[2] = 2;
    for ($i = 3; $i <= $n; $i += 2) {
        if ($i >= 10 && (($i % 5) === 0)) {
            continue;
        }
        $result[$i] = $i;
    }

    $i = reset($result);
    while ($i !== false) {
        if (isset($result[$i])) {
            /** @var int $j */
            $j = $i * 2;
            while ($j < $n) {
                unset($result[$j]);
                $j += $i;
            }
        }
        $i = next($result);
    }
    return $result;
}

$stdin = STDIN;
[$t] = fscanf($stdin, '%u');

$primes = getPrimeNumbersViaErastofen(1000000);

for ($tI = 0; $tI < $t; $tI++) {
    $wrongDigit = true;
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    $delimitersMap = array_keys($delimiters);
    sort($delimiters);
    $minDelimiter = $delimiters[0];
    $maxDelimiter = $delimiters[$n - 1];

    if ($n <= 2) {
        echo bcmul($delimiters[0], $maxDelimiter) . PHP_EOL;
        continue;
    }

    for ($i = 0; $i < $n; $i++) {
        if (bcmod($maxDelimiter, $delimiters[$i]) !== '0') {
            $wrongDigit = false;
            break;
        }
    }
    if ($wrongDigit === true) {
        echo '-1' . PHP_EOL;
        continue;
    }

    $multiPlies = bcmul($minDelimiter, $maxDelimiter);

    $primeDelimiters = [];
    foreach ($primes as $prime) {
        if (bccomp($prime, $multiPlies) === 1) {
            break;
        }
        if (bcmod($multiPlies, $prime) === '0') {
            $primeDelimiters[] = $prime;
        }
    }
    $primeDelimitersCount = count($primeDelimiters);

    $powerMask = [];
    $maxPower = $primeDelimitersCount * $primeDelimitersCount;
    $baseMask = $arrayMask = array_fill(0, $primeDelimitersCount, 0);
    for ($j = 0; $j < $primeDelimitersCount; $j++) {
        $arrayMask = $baseMask;
        $arrayMask[$j] = 1;
        for($i = 0; $i <= $maxPower; $i++) {
            $powerMask[] = implode(' ', $arrayMask);
            $ind = $i % $primeDelimitersCount;
            $arrayMask[$ind]++;
            $tmp = $baseMask;
            $tmp[$ind] = $arrayMask[$ind];
            $powerMask[] = implode(' ', $tmp);
        }
        $powerMask[] = implode(' ', $arrayMask);
    }
    $powerMask = array_unique($powerMask);
    sort($powerMask);
    $baseDelimiters = [];

    foreach ($powerMask as $m) {
        $m = explode(' ', $m);
        $baseDelimiter = 1;
        foreach ($primeDelimiters as $i => $prime) {
            $baseDelimiter = bcmul($baseDelimiter, bcpow($prime, $m[$i]));
        }
        if (bcmod($multiPlies, $baseDelimiter) === '0') {
            $baseDelimiters[] = $baseDelimiter;
        }
    }
    unset($powerMask, $baseMask, $arrayMask, $tmp);
    sort($baseDelimiters);
    if ($delimiters === $baseDelimiters) {
        echo $multiPlies . PHP_EOL;
    } else {
        echo '-1' . PHP_EOL;
    }
}

<?php
# 1165D
declare(strict_types=1);

$start = microtime(true);

function getPrimeNumbersViaErastofen($n)
{
    /** @var int[] $result */
    $result[2] = 2;
    for ($i = 3; $i <= $n; $i += 2) {
        if ($i >= 10 && (($i % 5) === 0)) {
            continue;
        }
        $result[$i] = $i;
    }

    $i = reset($result);
    while ($i !== false) {
        if (isset($result[$i])) {
            /** @var int $j */
            $j = $i * 2;
            while ($j < $n) {
                unset($result[$j]);
                $j += $i;
            }
        }
        $i = next($result);
    }
    return $result;
}

$primes = [];

$stdin = STDIN;
//$stdin = fopen('/home/vilnitskiy/.PhpStorm2019.1/config/scratches/data.txt', 'rb');
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    $wrongDigit = true;
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    $delimitersMap = array_keys($delimiters);
    sort($delimiters);
    $maxDelimiter = $delimiters[$n - 1];

    if ($n <= 2) {
        echo bcmul($delimiters[0], $maxDelimiter) . PHP_EOL;
        continue;
    }

    for ($i = 0; $i < $n; $i++) {
        if (bcmod($maxDelimiter, $delimiters[$i]) !== '0') {
            $wrongDigit = false;
            break;
        }
    }
    if ($wrongDigit === true) {
        echo '-1' . PHP_EOL;
        continue;
    }

    $digit = bcmul($delimiters[0], $maxDelimiter);

    if ($primes === []) {
        $primes = getPrimeNumbersViaErastofen(1000000);
    }
    $baseDelimiters = [];
    foreach ($primes as $prime) {
        $prime = (string)$prime;
        if ($prime >= $digit) {
            break;
        }
        if (bcmod($digit, $prime) === '0') {
            $baseDelimiters[$prime] = $prime;
        }
    }

    foreach ($baseDelimiters as $prime) {
        $i = 2;
        $result = $prime;
        $valid = true;
        do {
            $result = bcpow($prime, (string)$i);
            $valid = $result <= $digit;
            if ($valid && bcmod($digit, $result) === '0') {
                $baseDelimiters[$result] = $result;
            }
            $i++;
        } while ($valid);
    }
    $tmp = [];
    while ($tmp !== $baseDelimiters) {
        $tmp = $baseDelimiters;
        foreach ($baseDelimiters as $a) {
            foreach ($baseDelimiters as $b) {
                $result = bcmul($a, $b);
                if ($result < $digit && bcmod($digit, $result) === '0') {
                    $baseDelimiters[$result] = $result;
                }
            }
        }
    }
    sort($baseDelimiters);

    echo ($baseDelimiters === $delimiters ? $digit : '-1') . PHP_EOL;
}

echo microtime(true) - $start;

<?php
# 1165D
declare(strict_types=1);
$start = microtime(true);

$stdin = STDIN;
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    if ($n === 1) {
        $digit = $delimiters[0] ** 2;
    } else {
        $digit = max($delimiters) * 2;
        for ($i = 0; $i < $n; $i++) {
            if (($digit % $delimiters[$i]) !== 0) {
                $digit = -1;
                break;
            }
        }
    }
    echo $digit . PHP_EOL;
}

<?php
# 1165D
declare(strict_types=1);
$start = microtime(true);

$stdin = STDIN;
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    sort($delimiters);
    $digit = (float)$delimiters[0] * (float)$delimiters[$n - 1];
    for ($i = 0; $i < $n; $i++) {
        if (($digit % (float)$delimiters[$i]) !== 0) {
            $digit *= (float)$delimiters[$i];
        }
    }
    for ($i = 0; $i < $n; $i++) {
        if ($digit === (float)$delimiters[$i]) {
            $digit = '-1';
            break;
        }
    }

    echo sprintf('%.0f', $digit) . PHP_EOL;
}

<?php
# 1165D
declare(strict_types=1);

$start = microtime(true);

function getPrimeNumbersViaErastofen($n)
{
    /** @var int[] $result */
    $result[2] = 2;
    for ($i = 3; $i <= $n; $i += 2) {
        if ($i >= 10 && (($i % 5) === 0)) {
            continue;
        }
        $result[$i] = $i;
    }

    $i = reset($result);
    while ($i !== false) {
        if (isset($result[$i])) {
            /** @var int $j */
            $j = $i * 2;
            while ($j < $n) {
                unset($result[$j]);
                $j += $i;
            }
        }
        $i = next($result);
    }
    return $result;
}

$primes = [];

$stdin = STDIN;
//$stdin = fopen('/home/vilnitskiy/.PhpStorm2019.1/config/scratches/data.txt', 'rb');
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    $wrongDigit = true;
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    $delimitersMap = array_keys($delimiters);
    sort($delimiters);
    $maxDelimiter = $delimiters[$n - 1];

    if ($n <= 2) {
        echo bcmul($delimiters[0], $maxDelimiter) . PHP_EOL;
        continue;
    }

    for ($i = 0; $i < $n; $i++) {
        if (bcmod($maxDelimiter, $delimiters[$i]) !== '0') {
            $wrongDigit = false;
            break;
        }
    }
    if ($wrongDigit === true) {
        echo '-1' . PHP_EOL;
        continue;
    }

    $digit = bcmul($delimiters[0], $maxDelimiter);

    if ($primes === []) {
        $primes = getPrimeNumbersViaErastofen(100000);
    }
    $baseDelimiters = [];
    foreach ($primes as $prime) {
        $prime = (string)$prime;
        if ($prime >= $digit) {
            break;
        }
        if (bcmod($digit, $prime) === '0') {
            $baseDelimiters[$prime] = $prime;
        }
    }

    foreach ($baseDelimiters as $delimiter) {
        $i = 2;
        $result = $delimiter;
        $valid = true;
        do {
            $result = bcpow($delimiter, (string)$i);
            $valid = $result <= $digit;
            if ($valid && bcmod($digit, $result) === '0') {
                $baseDelimiters[$result] = $result;
            }
            $i++;
        } while ($valid);
    }
    $tmp = [];
    while ($tmp !== $baseDelimiters) {
        $tmp = $baseDelimiters;
        foreach ($baseDelimiters as $a) {
            foreach ($baseDelimiters as $b) {
                $result = bcmul($a, $b);
                if ($result < $digit && bcmod($digit, $result) === '0') {
                    $baseDelimiters[$result] = $result;
                }
            }
        }
    }
    foreach ($baseDelimiters as $delimiter) {
        if (bcmod($digit, $delimiter) === '0') {
            $result = bcdiv($digit, $delimiter);
            $baseDelimiters[$result] = $result;
        }
    }
    sort($baseDelimiters);

    echo ($baseDelimiters == $delimiters ? $digit : '-1') . PHP_EOL;
}

//echo microtime(true) - $start;

<?php
# 1165D
declare(strict_types=1);
$start = microtime(true);

$stdin = STDIN;
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    $digit = max($delimiters) * 2;
    for ($i = 0; $i < $n; $i++) {
        if (($digit % $delimiters[$i]) !== 0) {
            $digit = -1;
            break;
        }
    }
    echo $digit . PHP_EOL;
}

<?php
# 1165D
declare(strict_types=1);

$start = microtime(true);

function getPrimeNumbersViaErastofen($n)
{
    /** @var int[] $result */
    $result[2] = 2;
    for ($i = 3; $i <= $n; $i += 2) {
        if ($i >= 10 && (($i % 5) === 0)) {
            continue;
        }
        $result[$i] = $i;
    }

    $i = reset($result);
    while ($i !== false) {
        if (isset($result[$i])) {
            /** @var int $j */
            $j = $i * 2;
            while ($j < $n) {
                unset($result[$j]);
                $j += $i;
            }
        }
        $i = next($result);
    }
    return $result;
}

$primes = [];

$stdin = STDIN;
//$stdin = fopen('/home/vilnitskiy/.PhpStorm2019.1/config/scratches/data.txt', 'rb');
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    $wrongDigit = true;
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    $delimitersMap = array_keys($delimiters);
    sort($delimiters);
    $maxDelimiter = $delimiters[$n - 1];

    if ($n <= 2) {
        echo bcmul($delimiters[0], $maxDelimiter) . PHP_EOL;
        continue;
    }

    for ($i = 0; $i < $n; $i++) {
        if (bcmod($maxDelimiter, $delimiters[$i]) !== '0') {
            $wrongDigit = false;
            break;
        }
    }
    if ($wrongDigit === true) {
        echo '-1' . PHP_EOL;
        continue;
    }

    $digit = bcmul($delimiters[0], $maxDelimiter);

    if ($primes === []) {
        $primes = getPrimeNumbersViaErastofen(100000);
    }
    $baseDelimiters = [];
    foreach ($primes as $prime) {
        $prime = (string)$prime;
        if (bccomp($prime, $digit) > -1) {
            break;
        }
        if (bcmod($digit, $prime) === '0') {
            $baseDelimiters[$prime] = $prime;
        }
    }

    foreach ($baseDelimiters as $prime) {
        $i = 2;
        $result = $prime;
        $valid = true;
        do {
            $result = bcpow($prime, (string)$i);
            $valid = bccomp($result, $digit) < 1;
            if ($valid && bcmod($digit, $result) === '0') {
                $baseDelimiters[$result] = $result;
            }
            $i++;
        } while ($valid);
    }
    $tmp = [];
    while ($tmp !== $baseDelimiters) {
        $tmp = $baseDelimiters;
        foreach ($baseDelimiters as $a) {
            foreach ($baseDelimiters as $b) {
                $result = bcmul($a, $b);
                if (bccomp($result, $digit) < 0 && bcmod($digit, $result) === '0') {
                    $baseDelimiters[$result] = $result;
                }
            }
        }
    }
    sort($baseDelimiters);

    echo ($baseDelimiters === $delimiters ? $digit : '-1') . PHP_EOL;
}

//echo microtime(true) - $start;

<?php
# 1165D
declare(strict_types=1);

$start = microtime(true);

function getPrimeNumbersViaErastofen($n)
{
    /** @var int[] $result */
    $result[2] = 2;
    for ($i = 3; $i <= $n; $i += 2) {
        if ($i >= 10 && (($i % 5) === 0)) {
            continue;
        }
        $result[$i] = $i;
    }

    $i = reset($result);
    while ($i !== false) {
        if (isset($result[$i])) {
            /** @var int $j */
            $j = $i * 2;
            while ($j < $n) {
                unset($result[$j]);
                $j += $i;
            }
        }
        $i = next($result);
    }
    return $result;
}

$primes = [];

$stdin = STDIN;
[$t] = fscanf($stdin, '%u');

for ($tI = 0; $tI < $t; $tI++) {
    $wrongDigit = true;
    [$n] = fscanf($stdin, '%u');
    $delimiters = explode(' ', trim(fgets($stdin)));
    $delimitersMap = array_keys($delimiters);
    sort($delimiters);
    $maxDelimiter = $delimiters[$n - 1];

    $digit = bcmul($delimiters[0], $maxDelimiter);

    if ($primes === []) {
        $primes = getPrimeNumbersViaErastofen(100000);
    }
    $baseDelimiters = [];
    foreach ($primes as $prime) {
        $prime = (string)$prime;
        if ($prime >= $digit) {
            break;
        }
        if (bcmod($digit, $prime) === '0') {
            $baseDelimiters[$prime] = $prime;
        }
    }

    foreach ($baseDelimiters as $delimiter) {
        $i = 2;
        $result = $delimiter;
        $valid = true;
        $result = bcpow($delimiter, (string)$i);
        $valid = $result < $digit;
        while ($valid) {
            $result = bcpow($delimiter, (string)$i);
            $valid = $result < $digit;
            if ($valid && bcmod($digit, $result) === '0') {
                $baseDelimiters[$result] = $result;
            }
            $i++;
        }
    }
    $tmp = [];
    while ($tmp !== $baseDelimiters) {
        $tmp = $baseDelimiters;
        foreach ($baseDelimiters as $a) {
            foreach ($baseDelimiters as $b) {
                $result = bcmul($a, $b);
                if ($result < $digit && bcmod($digit, $result) === '0') {
                    $baseDelimiters[$result] = $result;
                }
            }
        }
    }
    foreach ($baseDelimiters as $delimiter) {
        if (bcmod($digit, $delimiter) === '0') {
            $result = bcdiv($digit, $delimiter);
            $baseDelimiters[$result] = $result;
        }
    }
    sort($baseDelimiters);

    echo ($baseDelimiters == $delimiters ? $digit : '-1') . PHP_EOL;
}

//echo microtime(true) - $start;