<?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)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	list($daysCount, $needHour) = readStringExplodeNum($stream, ' ', true);
	$datesPlan = readStringExplodeNum($stream, ' ', true);
	$totalAddHours = 0;

	for ($i = 1; $i < $daysCount; $i++) {
		if ($datesPlan[$i] + $datesPlan[$i - 1] < $needHour) {
			$addHour = $needHour - ($datesPlan[$i] + $datesPlan[$i - 1]);
			$datesPlan[$i]+=$addHour;
			$totalAddHours+=$addHour;
		}
	}
	echo $totalAddHours . "\r\n";
	echo implode(' ', $datesPlan);
	/* / end body */
}

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

<?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)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	list($daysCount, $needHour) = readStringExplodeNum($stream, ' ', true);
	$datesPlan = readStringExplodeNum($stream, ' ', true);
	$totalAddHours = 0;

	for ($i = 0; $i < $daysCount - 1; $i++) {
		if ($datesPlan[$i] + $datesPlan[$i + 1] >= $needHour) {
			continue;
		} else {
			if ($i + 2 < $daysCount) {
				if ($datesPlan[$i + 1] + $datesPlan[$i + 2] >= $needHour) {
					$addHours = $needHour - ($datesPlan[$i] + $datesPlan[$i + 1]);
					$totalAddHours+=$addHours;
					$datesPlan[$i]+=$addHours;

				} else {
					$addForRight = $needHour - ($datesPlan[$i] + $datesPlan[$i + 1]);
					$addForLeft = $needHour - ($datesPlan[$i + 1] + $datesPlan[$i + 2]);
					$addHours = max($addForRight, $addForLeft);
					$totalAddHours+=$addHours;
					$datesPlan[$i+1]+=$addHours;

				}
			} else {
				$addHours = $needHour - ($datesPlan[$i] + $datesPlan[$i + 1]);
				$totalAddHours+=$addHours;
				$datesPlan[$i]+=$addHours;

			}
		}
	}
	echo $totalAddHours . "\r\n";
	echo implode(' ', $datesPlan);
	/* / end body */
}

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

<?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)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	list($daysCount, $needHour) = readStringExplodeNum($stream, ' ', true);
	$datesPlan = readStringExplodeNum($stream, ' ', true);
	$totalAddHours = 0;

	for ($i = 0; $i < $daysCount - 1; $i++) {
		if ($datesPlan[$i] + $datesPlan[$i + 1] >= $needHour) {
			continue;
		} else {
			if ($i + 2 < $daysCount) {
				$addForThis = $needHour - ($datesPlan[$i] + $datesPlan[$i + 1]);
				$addForNext = $needHour - ($datesPlan[$i + 1] + $datesPlan[$i + 2]);
				if ($datesPlan[$i + 1] + $datesPlan[$i + 2] >= $needHour) {
					$addHours = $needHour - ($datesPlan[$i] + $datesPlan[$i + 1]);
					$totalAddHours+=$addHours;
					$datesPlan[$i]+=$addHours;
				} else {
					if ($i == 0) {
						$addForRight = $needHour - ($datesPlan[$i] + $datesPlan[$i + 1]);
						$addForLeft = $needHour - ($datesPlan[$i + 1] + $datesPlan[$i + 2]);
						$addHours = max($addForRight, $addForLeft);
						$totalAddHours+=$addHours;
						$datesPlan[$i + 1]+=$addHours;
					} else {
						$addForRight = $needHour - ($datesPlan[$i] + $datesPlan[$i + 1]);
						$addForLeft = $needHour - ($datesPlan[$i + 1] + $datesPlan[$i + 2]);
						$addHours = min($addForRight, $addForLeft);
						$totalAddHours+=$addHours;
						$datesPlan[$i + 1]+=$addHours;
					}
				}
			} else {
				$addHours = $needHour - ($datesPlan[$i] + $datesPlan[$i + 1]);
				$totalAddHours+=$addHours;
				$datesPlan[$i]+=$addHours;
			}
		}
	}
	echo $totalAddHours . "\r\n";
	echo implode(' ', $datesPlan);
	/* / end body */
}

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


<?php
#1187C
[$n, $m] = fscanf(STDIN, '%u %u');
$arr = array_fill(0, $n, null);
$descIntervals = [];
while ($m--) {
    [$t, $l, $r] = fscanf(STDIN, '%u %u %u');
    if ($t === 1) {
        while ($l < $r) {
            $arr[$l] = true;
            $l++;
        }
    } else {
        $descIntervals[] = [$l, $r];
    }
}
foreach ($descIntervals as $interval) {
    $invalidInterval = true;
    for ($i = $interval[0]; $i < $interval[1]; $i++) {
        if ($arr[$i] === null) {
            $invalidInterval = false;
        }
    }
    if ($invalidInterval) {
        die('NO');
    }
}
echo 'YES' . PHP_EOL;
foreach ($arr as $i => $item) {
    if ($i && $item === null) {
        $n--;
    }
    $arr[$i] = $n;
}
echo implode(' ', $arr);

<?php
#1187C
[$n, $m] = fscanf(STDIN, '%u %u');
$arr = array_fill(0, $n, null);
$descIntervals = [];
while ($m--) {
    [$t, $l, $r] = fscanf(STDIN, '%u %u %u');
    if ($t === 1) {
        while ($l < $r) {
            $arr[$l] = true;
            $l++;
        }
    } else {
        $descIntervals[] = [$l, $r];
    }
}
foreach ($descIntervals as $interval) {
    $invalidInterval = true;
    for ($i = $interval[0]; $i < $interval[1]; $i++) {
        if ($arr[$i] === null) {
            $invalidInterval = false;
        }
    }
    if ($invalidInterval) {
        die('NO');
    }
}
unset($descIntervals);
foreach ($arr as $i => $item) {
    if ($i && $item === null) {
        $n--;
    }
    echo ($i ? ' ' : ('YES' . PHP_EOL)) . $n;
}

<?php
#1187C
[$n, $m] = fscanf(STDIN, '%u %u');
$arr = array_fill(0, $n, null);
$descIntervals = [];
while ($m--) {
    [$t, $l, $r] = fscanf(STDIN, '%u %u %u');
    if ($t === 1) {
        while ($l < $r) {
            $arr[$l] = true;
            $l++;
        }
    } else {
        $descIntervals[] = [$l, $r];
    }
}
foreach ($descIntervals as $interval) {
    $invalidInterval = true;
    for ($i = $interval[0]; $i < $interval[1]; $i++) {
        if ($arr[$i] === null) {
            $invalidInterval = false;
        }
    }
    if ($invalidInterval) {
        die('NO');
    }
}
unset($invalidInterval);
echo 'YES' . PHP_EOL;
foreach ($arr as $i => $item) {
    if ($i && $item === null) {
        $n--;
    }
    echo ($i ? ' ' : '') . $n;
}


<?php class InputReader{protected $_fh;public function __construct($fileHandler = STDIN)   {$this->_fh = $fileHandler;}
    public function readString(){$s = trim(fgets($this->_fh));return $s;}
    public function readInt(){$d = trim(fgets($this->_fh));return (int)$d;}
    public function readArrayOfInt($separator = ' ', $indexFrom = 0){$a = [];$ind = $indexFrom;foreach (explode($separator, fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
    public function readArrayOfFloat($separator = ' ', $indexFrom = 0) { $a = []; $ind = $indexFrom; foreach (explode($separator, fgets($this->_fh)) as $item) {  $a[$ind++] = (float)$item; } return $a; }
    public function readArrayOfString($separator = ' ', $indexFrom = 0) { $a = []; $ind = $indexFrom; foreach (explode($separator, fgets($this->_fh)) as $item) {  $a[$ind++] = $item; } return $a; }
}
/* Perform action N times. Can return values in array */
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. */
function cumsum(&$a){ $sum = 0; foreach ($a as $k => $v) { $a[$k] += $sum; $sum = $a[$k]; }}
/* Difference. Keys preserved. By reference. */
function diff(&$a){ $prev = 0; foreach ($a as $k => $v) { $buf = $a[$k]; $a[$k] -= $prev; $prev = $buf; }}
function bitCount($n){ $cnt = 0; for ($j = $n; $j; $j >>= 1) { $cnt += $j & 1; } return $cnt;}
/*****************************************/
$ir = new InputReader();

/* TASK */

$ts = $ir->readInt();

for ($t=0; $t<$ts; $t++) {
	$s = $ir->readString();
	$cumsum = 0;

	if ($s[-1] !== 'B') {
		echo "NO".PHP_EOL;
		continue;
	}

	for ($i = 0; $i < strlen($s); $i++) {
		$cumsum += ($s[$i]=='A' ? 1 : -1);

		if ($cumsum < 0) {
			echo "NO".PHP_EOL;
			continue 2;
		}
	}

	echo "YES".PHP_EOL;
}


<?php

$RESULT = false;
$arr=array();
$n=(int)trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
$UBOUND = $n/2;

function check($i,$offset) {
    global $arr,$n;
    for ($k = $offset ; $k<$n ; $k+=$i) {
        if ($arr[$k]==0) return false;
    }
    return true;
}

for ($i = 1; $i < $UBOUND ;$i++) {
    if ($n%$i==0) {
        //$nodes = $n/$i;
        for ($j = 0 ; $j < $i; $j++) {
            if (check($i,$j)) {
                $RESULT = true;
                break 2;
            }
        }
    }
}
echo $RESULT ? 'YES' : 'NO';

?>

<?php
class INPUT_HELP{
    public function read_array(){
        $a[0] = '';
        $j = 0;
        $input = fgets(STDIN);
        for ($i = 0; $i < strlen($input); $i++){
            if (preg_replace("/[0-9A-zА-я._-]/",null,$input[$i]) == false) {
                $a[$j] = $a[$j].$input[$i];
            } else {
                if ($a[$j] != '') {
                    ++$j;
                    $a[$j] = '';
                }
            }
        }
        return $a;
    }
    public function read_one(){
        $array = $this->read_array();
        return $array[0];
    }
}
?>
<?php
    $input_connect = new INPUT_HELP();
    $n = $input_connect->read_one();
    $a = $input_connect->read_array();
    for ($i = 0; $i < $n; $i++) {
        $num[$i] = $i;
    }
    for ($i = $n; $i < 2 * $n; $i++){
        $a[$i] = $a[$i - $n];
        $num[$i] = $num[$i - $n];
    }
    $h = -1;
    for ($j = 1; $j < $n; $j++){
        if ($n % $j != 0 || $n / $j < 3) continue;
        ++$h;
        $div[$h] = $j;
    }
    for ($i = 0; $i < $n; $i++){
        if ($a[$i] == 0) continue;
        for ($j = 0; $j <= $h; $j++){
            $k = $i + $div[$j];
            while ($a[$k] == 1 && $num[$k] != $i) $k += $div[$j];
            if ($num[$k] == $i) {
                echo "YES";
                die(0);
            }
        }
    }
    echo "NO";
?>

<?php
class INPUT_HELP{
    public function read_array(){
        $a[0] = '';
        $j = 0;
        $input = fgets(STDIN);
        for ($i = 0; $i < strlen($input); $i++){
            if (preg_replace("/[0-9A-zА-я._-]/",null,$input[$i]) == false) {
                $a[$j] = $a[$j].$input[$i];
            } else {
                if ($a[$j] != '') {
                    ++$j;
                    $a[$j] = '';
                }
            }
        }
        return $a;
    }
    public function read_one(){
        $array = $this->read_array();
        return $array[0];
    }
}
?>
<?php
    $input_connect = new INPUT_HELP();
    $n = $input_connect->read_one();
    $a = $input_connect->read_array();
    for ($i = 0; $i < $n; $i++) {
        $num[$i] = $i;
    }
    for ($i = $n; $i < 2 * $n; $i++){
        $a[$i] = $a[$i - $n];
        $num[$i] = $num[$i - $n];
    }
    $h = -1;
    for ($j = 1; $j < $n; $j++){
        if ($n % $j != 0 || $n / $j < 3) continue;
        ++$h;
        $div[$h] = $j;
    }
    for ($i = 0; $i < $n; $i++){
        if ($a[$i] == 0) continue;
        for ($j = 1; $j < $h; $j++){
            $k = $i + $div[$j];
            while ($a[$k] == 1 && $num[$k] != $i) $k += $div[$j];
            if ($num[$k] == $i) {
                echo "YES";
                die(0);
            }
        }
    }
    echo "NO";
?>

<?php
class INPUT_HELP{
    public function read_array(){
        $a[0] = '';
        $j = 0;
        $input = fgets(STDIN);
        for ($i = 0; $i < strlen($input); $i++){
            if (preg_replace("/[0-9A-zА-я._-]/",null,$input[$i]) == false) {
                $a[$j] = $a[$j].$input[$i];
            } else {
                if ($a[$j] != '') {
                    ++$j;
                    $a[$j] = '';
                }
            }
        }
        return $a;
    }
    public function read_one(){
        $array = $this->read_array();
        return $array[0];
    }
}
?>
<?php
    $input_connect = new INPUT_HELP();
    $n = $input_connect->read_one();
    $a = $input_connect->read_array();
    for ($i = 0; $i < $n; $i++) {
        $num[$i] = $i;
    }
    for ($i = $n; $i < 2 * $n; $i++){
        $a[$i] = $a[$i - $n];
        $num[$i] = $num[$i - $n];
    }
    $h = -1;
    for ($j = 1; $j < $n; $j++){
        if ($n % $j != 0 || $n / $j < 3) continue;
        ++$h;
        $div[$h] = $j;
    }
    for ($i = 0; $i < $n; $i++){
        if ($a[$i] == 0) continue;
        for ($j = 0; $j < $h; $j++){
            $k = $i + $div[$j];
            while ($a[$k] == 1 && $num[$k] != $i) $k += $div[$j];
            if ($num[$k] == $i) {
                echo "YES";
                die(0);
            }
        }
    }
    echo "NO";
?>

<?php
$arr=array();
$n=(int)trim(fgets(STDIN));
for ($i = 0; $i < $n ;$i++)
    fscanf(STDIN,'%d', $HZ[$i]);
$UBOUND = $n/2;

function check($i,$offset) {
    global $arr,$n;
    for ($k = $offset ; $k<$n ; $k+=$i) {
        if ($arr[$k]==0) return false;
    }
    return true;
}

for ($i = 1; $i < $UBOUND ;$i++) {
    if ($n%$i==0) {
        //$nodes = $n/$i;
        for ($j = 0 ; $j < $i; $j++) {
            if (check($i,$j)) {
                echo 'YES';
                die();
            }
        }
    }
}

echo 'NO';
?>


<?php
list ($n, $k, $q) = explode(" ", trim(fgets(STDIN)));

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

$online = [];

for ($i = 0; $i < $q; $i++) {
  list ($type, $id) = explode(" ", trim(fgets(STDIN)));

  if ($type == 1) {
    $online[$id] = $t[$id - 1];
    arsort($online);
    if (count($online) > $k) {
      array_pop($online);
    }
  } else {
    echo isset($online[$id]) ? "YES\n" : "NO\n";
  }
}

<?
$stdin = fopen('php://stdin', 'r');
$a = fgets($stdin);
$t = explode(" ", $a);
$n = trim($t[0]);
$k = trim($t[1]);
$q = trim($t[2]);
$a = fgets($stdin);
$friends = explode(" ", $a);
$show = array();

$stdout = fopen('php://stdout', 'w');
$onlines = 0;
$online = array();
for($i = 0; $i < $q; $i++){
    $a = fgets($stdin);
    $t = explode(" ", $a);
    $type = trim($t[0]);//type
    $id = trim($t[1]);//id
    if($type == 1){

        if($onlines < $k){
            $online[$onlines][0] = $id;
            $online[$onlines][1] = $friends[$id - 1];
            $show[$id] = "YES";
            $onlines++;
        }else{
            $min = -1;
            for($j = 0; $j < $onlines; $j++){
                if($online[$j][1] < $friends[$id - 1] and ($online[$j][1] < $online[$min][1] or $min == -1)) $min = $j;
            }

            if($min != -1){
                $show[$online[$min][0]] = "NO";
                $show[$id] = "YES";
                $online[$min][0] = $id;
                $online[$min][1] = $friends[$id - 1];
            }
        }
    }else{
        if($show[$id]) fwrite($stdout, $show[$id]."\n"); else fwrite($stdout, "NO\n");
    }
}

fclose($stdout);

?>

<?
$k=1;
$online=array();
$handle=fopen("php://stdin",'r');

$vars=explode(' ',trim(fgets($handle)));

$rep2=explode(' ',trim(fgets($handle)));

array_unshift($rep2, 0);

for($i=1;$i<=$vars[2];$i++) {
	$tokens[$i]=explode(' ',trim(fgets($handle)));
}

for($i=1;$i<=$vars[2];$i++) {
	if($tokens[$i][0]==1) {
		if(array_search($tokens[$i][1],$online)===FALSE) {
			if(count($online)==$vars[1]) {
			if($rep2[$tokens[$i][1]]>$rep2[$online[0]]) $online[0]=$tokens[$i][1];
			} else {
			array_push($online, $tokens[$i][1]);
			}
			//Ёбаная сортировка
			for($z=0;$z<count($online);$z++)
				for($y=$z+1;$y<count($online);$y++)
					if($rep2[$online[$y]]<$rep2[$online[$z]])
						list($online[$z], $online[$y]) = array($online[$y], $online[$z]);
			//
		}
	} else {
		if(array_search($tokens[$i][1],$online)!==FALSE) {
			echo "YES".PHP_EOL;
		} else echo "NO".PHP_EOL;
	}
}
?>

<?
$k=1;
$id_session=1;
$online=array();
$handle=fopen("php://stdin",'r');
$l1=trim(fgets($handle));

$vars=explode(' ',$l1);

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

$rep2=explode(' ',$l2);

for($i=1;$i<=$vars[2];$i++) {
	$tokens[$i]=explode(' ',trim(fgets($handle)));
}

for($i=1;$i<=$vars[0];$i++) {
	$friend[$i]=$rep2[$i-1];
}

for($i=1;$i<=$vars[2];$i++) {
	if($tokens[$i][0]==1) {
		if(array_search($tokens[$i][1],$online)===FALSE) {
			if(count($online)==$vars[1]) {
			if($friend[$tokens[$i][1]]>$friend[$online[0]]) $online[0]=$tokens[$i][1];
			} else {
			array_push($online, $tokens[$i][1]);
			}
			//Ёбаная сортировка
			for($z=0;$z<count($online);$z++)
				for($y=$z+1;$y<count($online);$y++)
					if($friend[$online[$y]]<$friend[$online[$z]])
						list($online[$z], $online[$y]) = array($online[$y], $online[$z]);
			//
		}
	} else {
		if(array_search($tokens[$i][1],$online)!==FALSE) {
			echo "YES".PHP_EOL;
		} else echo "NO".PHP_EOL;
	}
}
?>

<?
$k=1;
$id_session=1;
$online=array();
$handle=fopen("php://stdin",'r');
$l1=trim(fgets($handle));

$vars=explode(' ',$l1);

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

$rep2=explode(' ',$l2);

for($i=1;$i<=$vars[2];$i++) {
	$tokens[$i]=explode(' ',trim(fgets($handle)));
}

for($i=1;$i<=$vars[0];$i++) {
	$friend[$i]["online"]=0;
	$friend[$i]["rep"]=$rep2[$i-1];
}

for($i=1;$i<=$vars[2];$i++) {
	if($tokens[$i][0]==1) {
		if(array_search($tokens[$i][1],$online)===FALSE) {
			if(count($online)==$vars[1]) {
			if($friend[$tokens[$i][1]]["rep"]>$friend[$online[0]]["rep"]) $online[0]=$tokens[$i][1];
			} else {
			array_push($online, $tokens[$i][1]);
			}
			//Ёбаная сортировка
			for($z=0;$z<count($online);$z++) {
				$xer=$online[$z];
				for($y=$z+1;$y<count($online);$y++) {
					if($friend[$online[$y]]["rep"]<$friend[$online[$z]]["rep"])
						list($online[$z], $online[$y]) = array($online[$y], $online[$z]);
				}
			}
			//
		}
	} else {
		if(array_search($tokens[$i][1],$online)!==FALSE) {
			echo "YES".PHP_EOL;
		} else echo "NO".PHP_EOL;
	}
}
?>

<?
$k=1;
$id_session=1;
$online=array();
$handle=fopen("php://stdin",'r');
$l1=trim(fgets($handle));

$vars=explode(' ',$l1);

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

$rep2=explode(' ',$l2);

array_unshift($rep2, 0);

for($i=1;$i<=$vars[2];$i++) {
	$tokens[$i]=explode(' ',trim(fgets($handle)));
}

for($i=1;$i<=$vars[2];$i++) {
	if($tokens[$i][0]==1) {
		if(array_search($tokens[$i][1],$online)===FALSE) {
			if(count($online)==$vars[1]) {
			if($rep2[$tokens[$i][1]]>$rep2[$online[0]]) $online[0]=$tokens[$i][1];
			} else {
			array_push($online, $tokens[$i][1]);
			}
			//Ёбаная сортировка
			for($z=0;$z<count($online);$z++)
				for($y=$z+1;$y<count($online);$y++)
					if($rep2[$online[$y]]<$rep2[$online[$z]])
						list($online[$z], $online[$y]) = array($online[$y], $online[$z]);
			//
		}
	} else {
		if(array_search($tokens[$i][1],$online)!==FALSE) {
			echo "YES".PHP_EOL;
		} else echo "NO".PHP_EOL;
	}
}
?>

<?
$k=1;
$id_session=1;
$online=array();
$handle=fopen("php://stdin",'r');
$l1=trim(fgets($handle));

$vars=explode(' ',$l1);

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

$rep2=explode(' ',$l2);

for($i=1;$i<=$vars[2];$i++) {
	$tokens[$i]=explode(' ',trim(fgets($handle)));
}

for($i=1;$i<=$vars[0];$i++) {
	$friend[$i]["online"]=0;
	$friend[$i]["rep"]=$rep2[$i-1];
}

for($i=1;$i<=$vars[2];$i++) {
	if($tokens[$i][0]==1) {
		if(array_search($tokens[$i][1],$online)===FALSE) {
			if(count($online)==$vars[1]) {
			if($friend[$tokens[$i][1]]["rep"]>$friend[$online[0]]["rep"]) $online[0]=$tokens[$i][1];
			} else {
			array_push($online, $tokens[$i][1]);
			}
			//Ёбаная сортировка
			for($z=0;$z<count($online);$z++)
				for($y=$z+1;$y<count($online);$y++)
					if($friend[$online[$y]]["rep"]<$friend[$online[$z]]["rep"])
						list($online[$z], $online[$y]) = array($online[$y], $online[$z]);
			//
		}
	} else {
		if(array_search($tokens[$i][1],$online)!==FALSE) {
			echo "YES".PHP_EOL;
		} else echo "NO".PHP_EOL;
	}
}
?>

<?
$stdin = fopen('php://stdin', 'r');
$a = fgets($stdin);
$t = explode(" ", $a);
$n = trim($t[0]);
$k = trim($t[1]);
$q = trim($t[2]);
$a = fgets($stdin);
$friends = explode(" ", $a);
$show = array();

$stdout = fopen('php://stdout', 'w');
$onlines = 0;
$online = array();
for($i = 0; $i < $q; $i++){
    $a = fgets($stdin);
    $t = explode(" ", $a);
    $type = trim($t[0]);//type
    $id = trim($t[1]);//id
    if($type == 1){

        if($onlines < $k){
            $online[$onlines][0] = $id;
            $online[$onlines][1] = $friends[$id - 1];
            $show[$id] = "YES";
            $onlines++;
        }else{
            $min = -1;
            for($j = 0; $j < $onlines; $j++){
                if($online[$j][1] < $friends[$id - 1] and ($online[$j][1] < $min[1] or $min == -1)) $min = $online[$j];
            }

            if($min != -1){
                $show[$min[0]] = "NO";
                $show[$id] = "YES";
                $online[$min][0] = $id;
                $online[$min][1] = $friends[$id - 1];
            }
        }
    }else{
        if($show[$id]) fwrite($stdout, $show[$id]."\n"); else fwrite($stdout, "NO\n");
    }
}

fclose($stdout);

?>

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

$a = fgets($stdin);
$t = explode(" ", $a);
$n = trim($t[0]);//druzya
$k = trim($t[1]);//okno
$q = trim($t[2]);//zaprosy
$a = fgets($stdin);
$friends = explode(" ", $a);
$show = array();

$stdout = fopen('php://stdout', 'w');
$onlines = 0;
$online = array();
for($i = 0; $i < $q; $i++){
    $a = fgets($stdin);
    $t = explode(" ", $a);
    $type = trim($t[0]);//type
    $id = trim($t[1]);//id
    if($type == 1){
        $min = -1;
        for($j = 0; $j < $onlines; $j++){
            if($online[$j] < $friends[$id] and ($online[$j] < $online[$min] or $min == -1)) $min = $j;
        }
        if($min != -1){
            $show[$j] = "FALSE";
            $show[$id] = "TRUE";
            $online[$j] = $friends[$id];
        }else{
            if($onlines < $k){
                $online[$onlines] = $friends[$id];
                $show[$id] = "TRUE";
                $onlines++;
            }
        }
    }else{
        if($show[$id]) fwrite($stdout, $show[$id]."\n"); else fwrite($stdout, "FALSE\n");
    }
}

fclose($stdout);

?>

<?
$k=1;
$id_session=1;
$online=array();
$handle=fopen("php://stdin",'r');
$l1=trim(fgets($handle));

$vars=explode(' ',$l1);

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

$rep2=explode(' ',$l2);

for($i=1;$i<=$vars[2];$i++) {
	$tokens[$i]=explode(' ',trim(fgets($handle)));
}

for($i=1;$i<=$vars[0];$i++) {
	$friend[$i]["online"]=0;
	$friend[$i]["rep"]=$rep2[$i-1];
}

for($i=1;$i<=$vars[2];$i++) {
	if($tokens[$i][0]==1) {
		if(array_search($tokens[$i][1],$online)===FALSE) {
			if(count($online)==$vars[1]) {
			if($friend[$tokens[$i][1]]["rep"]>$friend[$online[0]]["rep"]) $online[0]=$tokens[$i][1];
			} else {
			array_push($online, $tokens[$i][1]);
			}
			//Ёбаная сортировка
			for($z=0;$z<count($online);$z++) {
				$xer=$online[$z];
				for($y=$z+1;$y<count($online);$y++) {
					if($friend[$online[$y]]["rep"]<$friend[$online[$z]]["rep"]) {
						list($online[$z], $online[$y]) = array($online[$y], $online[$z]);
						$z++;
					}
				}
			}
			//
		}
	} else {
		if(array_search($tokens[$i][1],$online)!==FALSE) {
			echo "YES".PHP_EOL;
		} else echo "NO".PHP_EOL;
	}
}
?>


<?php
/**
 * Created by PhpStorm.
 * User: wanghaixia01
 * Date: 2019/12/30
 * Time: 11:10
 */

class BAandB
{
    public function main(){
        $num = trim(fgets(STDIN));//接收用户输入
        for ($i=0; $i < $num; $i++){
            $arr = explode(" ", trim(fgets(STDIN)));//接收用户输入
            $steps = $this->compMinSteps($arr[0], $arr[1]);
            fwrite(STDOUT, $steps."\n");
        }
    }

    public function compMinSteps($num1, $num2){
        if($num1 == $num2){
            return 0;
        }
        $diff = abs($num1-$num2);
        $i = 1;
        while(true){
            $sum = $i * ($i + 1) / 2;
            if($sum % 2 == $diff % 2 && $sum >= $diff){
                break;
            }
            $i++;
        }
        return $i;
    }
}
$nyg = new BAandB();
$b = $nyg->main();

<?php
/**
 * Created by PhpStorm.
 * User: wanghaixia01
 * Date: 2019/12/30
 * Time: 11:10
 */

class BAandB
{
    public function main(){
        $num = trim(fgets(STDIN));//接收用户输入
        for ($i=0; $i < $num; $i++){
            $line = trim(fgets(STDIN));//接收用户输入
            $arr  = explode(" ", $line);
            $steps = $this->compMinSteps($arr[0], $arr[1]);
            fwrite(STDOUT, $steps."\n");
        }
    }
    //每执行一步就会加1
    public function compMinSteps($num1, $num2){
        if($num1 == $num2){
            return 0;
        }
        if($num1 > $num2){
            $minNum = $num2;
            $maxNum = $num1;
        }else{
            $minNum = $num1;
            $maxNum = $num2;
        }
        $i = 1;
        while($minNum != $maxNum){
            if($minNum + $i < $maxNum){
                $minNum += $i;
            }elseif($minNum + $i > $maxNum){
                $maxNum += $i;
            }elseif($minNum + $i == $maxNum){
                break;
            }
            $i++;
        }
        return $i;
    }
}
$nyg = new BAandB();
$b = $nyg->main();

<?php
/**
 * Created by PhpStorm.
 * User: wanghaixia01
 * Date: 2019/12/30
 * Time: 11:10
 */

class BAandB
{
    public function main(){
        $num = trim(fgets(STDIN));//接收用户输入
        $steps = array();
        for ($i=0; $i < $num; $i++){
            $line = trim(fgets(STDIN));//接收用户输入
            $arr  = explode(" ", $line);
            $steps[] = $this->compMinSteps($arr[0], $arr[1]);
        }
        for ($i = 0; $i < $num; $i++){
            fwrite(STDOUT, $steps[$i]."\n");
        }
    }
    //每执行一步就会加1
    public function compMinSteps($num1, $num2){
        if($num1 == $num2){
            return 0;
        }
        if($num1 > $num2){
            $minNum = $num2;
            $maxNum = $num1;
        }else{
            $minNum = $num1;
            $maxNum = $num2;
        }
        $i = 1;
        while($minNum != $maxNum){
            if($minNum + $i < $maxNum){
                $minNum += $i;
            }elseif($minNum + $i > $maxNum){
                $maxNum += $i;
            }elseif($minNum + $i == $maxNum){
                break;
            }
            $i++;
        }
        return $i;
    }
}
//$nyg = new BAandB();
//$b = $nyg->main();


<?php
$stdin = explode(' ', trim(fgets(STDIN)));
$people = $stdin[0];
$reg = $stdin[1];

$comands = array();

for ($i = 0; $i < $people; $i++) {
    $child = explode(' ', trim(fgets(STDIN)));
    $child_fio = $child[0];
    $child_reg = $child[1];
    $child_rang= $child[2];

    $top1 = $comands[$child_reg]['top1']['rang'] ? $comands[$child_reg]['top1']['rang'] : 0;
    $top2 = $comands[$child_reg]['top2']['rang'] ? $comands[$child_reg]['top2']['rang'] : 0;
    $comands[$child_reg][$child_rang] += 1;
    if ($child_rang >= $top1) {
        $comands[$child_reg]['top2']['rang'] = $top1;
        $comands[$child_reg]['top2']['fio'] = $comands[$child_reg]['top1']['fio'];
        $comands[$child_reg]['top1']['rang'] = $child_rang;
        $comands[$child_reg]['top1']['fio'] = $child_fio;
    } else if ($child_rang >= $top2) {
        $comands[$child_reg]['top2']['rang'] = $child_rang;
        $comands[$child_reg]['top2']['fio'] = $child_fio;
    }
}
$result = array();
for ($j = 1; $j <= $reg; $j++) {

    if ($comands[$j][$comands[$j]['top1']['rang']] > 2) {
        echo "?\n";
    } else if ( $comands[$j][$comands[$j]['top1']['rang']] == 2) {
        echo $comands[$j]['top1']['fio'] . ' ' . $comands[$j]['top2']['fio'] . "\n";
    } else if ($comands[$j][$comands[$j]['top2']['rang']] == 1 ) {
        echo $comands[$j]['top1']['fio'] . ' ' . $comands[$j]['top2']['fio'] . "\n";
    } else {
        echo "?\n";
    }
}

?>

<?php
$stdin = explode(' ', trim(fgets(STDIN)));
$people = $stdin[0];
$reg = $stdin[1];

$comands = array();

for ($i = 0; $i < $people; $i++) {
    $child = explode(' ', trim(fgets(STDIN)));
    $child_fio = $child[0];
    $child_reg = $child[1];
    $child_rang= $child[2];

    if (!isset($comands[$child_reg])) {

        $comands[$child_reg] = array('can' => 1, 'users' => array(0 => $child));
    } else {
        if (count($comands[$child_reg]['users']) == 1) {
            $comands[$child_reg]['users'][] = $child;

        } else {
            if ($comands[$child_reg]['can'] == 1) {

                $rang_1 = $comands[$child_reg]['users'][0][2] + $child_rang;
                $rang_2 = $comands[$child_reg]['users'][1][2] + $child_rang;
                if ($rang_1 == $rang_2 && $rang_1 != 1600) {
                    $comands[$child_reg]['can'] = 0;
                } else if ($rang_1 >= $rang_2) {
                    $comands[$child_reg]['users'][1] = $child;
                } else {
                    $comands[$child_reg]['users'][0] = $child;
                }

            }

        }
    }

}
$result = array();
for ($j = 1; $j <= $reg; $j++) {
    if ($comands[$j]['can']) {
        $result[] = $comands[$j]['users'][0][0] . ' ' . $comands[$j]['users'][1][0];
    } else {
       $result[] = '?';
    }
}

echo implode('
', $result);

?>

<?php
$stdin = explode(' ', trim(fgets(STDIN)));
$people = $stdin[0];
$reg = $stdin[1];

$comands = array();

for ($i = 0; $i < $people; $i++) {
    $child = explode(' ', trim(fgets(STDIN)));
    $child_fio = $child[0];
    $child_reg = $child[1];
    $child_rang= $child[2];

    if (!isset($comands[$child_reg])) {

        $comands[$child_reg] = array('can' => 1, 'users' => array(0 => $child));
    } else {
        if (count($comands[$child_reg]['users']) == 1) {
            $comands[$child_reg]['users'][] = $child;

        } else {
            if ($comands[$child_reg]['can'] == 1) {

                $rang_1 = $comands[$child_reg]['users'][0][2] + $child_rang;
                $rang_2 = $comands[$child_reg]['users'][1][2] + $child_rang;
                if ($rang_1 == $rang_2) {
                    $comands[$child_reg]['can'] = 0;
                } else if ($rang_1 > $rang_2) {
                    $comands[$child_reg]['users'][1] = $child;
                } else {
                    $comands[$child_reg]['users'][0] = $child;
                }

            }

        }
    }

}
$result = array();
for ($j = 1; $j <= $reg; $j++) {
    if ($comands[$j]['can']) {
        $result[] = $comands[$j]['users'][0][0] . ' ' . $comands[$j]['users'][1][0];
    } else {
       $result[] = '?';
    }
}

echo implode('
', $result);

<?php
$stdin = explode(' ', trim(fgets(STDIN)));
$people = $stdin[0];
$reg = $stdin[1];

$comands = array();

for ($i = 0; $i < $people; $i++) {
    $child = explode(' ', trim(fgets(STDIN)));
    $child_fio = $child[0];
    $child_reg = $child[1];
    $child_rang= $child[2];

    $top1 = $comands[$child_reg]['top1']['rang'] ? $comands[$child_reg]['top1']['rang'] : 0;
    $top2 = $comands[$child_reg]['top2']['rang'] ? $comands[$child_reg]['top2']['rang'] : 0;

    $comands[$child_reg][$child_rang] += 1;
    if ($child_rang >= $top1) {
        $comands[$child_reg]['top2']['rang'] = $top1;
        $comands[$child_reg]['top2']['fio'] = $comands[$child_reg]['top1']['fio'];
        $comands[$child_reg]['top1']['rang'] = $child_rang;
        $comands[$child_reg]['top1']['fio'] = $child_fio;
    } else if ($comands[$child_reg][$child_rang] >= $top2) {
        $comands[$child_reg]['top2'] = $comands[$child_reg][$child_rang];
    }
}
$result = array();
for ($j = 1; $j <= $reg; $j++) {
    if ($comands[$j][$comands[$j]['top1']['rang']] > 2) {
        echo "?\n";
    } else if ( $comands[$j][$comands[$j]['top1']['rang']] == 2) {
        echo $comands[$j]['top1']['fio'] . ' ' . $comands[$j]['top2']['fio'] . "\n";
    } else if ($comands[$j][$comands[$j]['top2']['rang']] == 1 ) {
        echo $comands[$j]['top1']['fio'] . ' ' . $comands[$j]['top2']['fio'] . "\n";
    } else {
        echo "?\n";
    }
}

?>

<?php
$stdin = explode(' ', trim(fgets(STDIN)));
$people = $stdin[0];
$reg = $stdin[1];

$comands = array();

for ($i = 0; $i < $people; $i++) {
    $child = explode(' ', trim(fgets(STDIN)));
    $child_fio = $child[0];
    $child_reg = $child[1];
    $child_rang= $child[2];

    if (!isset($comands[$child_reg])) {

        $comands[$child_reg] = array('can' => 1, 'users' => array(0 => $child));
    } else {
        if (count($comands[$child_reg]['users']) == 1) {
            $comands[$child_reg]['users'][] = $child;

        } else {
            if ($comands[$child_reg]['can'] == 1) {

                $rang_1 = $comands[$child_reg]['users'][0][2] + $child_rang;
                $rang_2 = $comands[$child_reg]['users'][1][2] + $child_rang;
                if ($rang_1 == $rang_2) {
                    $comands[$child_reg]['can'] = 0;
                } else if ($rang_1 > $rang_2) {
                    $comands[$child_reg]['users'][1] = $child;
                } else {
                    $comands[$child_reg]['users'][0] = $child;
                }

            }

        }
    }

}

for ($j = 1; $j <= $reg; $j++) {
    if ($comands[$j]['can']) {
        echo $comands[$j]['users'][0][0] . ' ' . $comands[$j]['users'][1][0];
    } else {
        echo '?';
    }
}

?>


<?php

//[$a,$b] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$h = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$mod = 998244353;
//$mod = 1000000007;
//$alpha = "abcdefghijklmnopqrstuvwxyz";

[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));

for($i=0;$i<$t;$i++){
    [$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $cnt = [];
    if($n %  2 == 0){
        $nh = intdiv($n, 2);
        for($j=0;$j<$nh;$j++){
            $cnt[] = $nh-$j;
            $cnt[] = $nh-$j+$nh;
        }
    }else{
        $nh = intdiv($n, 2);
        $nh = intdiv($n, 2);
        for($j=0;$j<$nh;$j++){
            $cnt[] = $nh-$j;
            $cnt[] = ($nh-$j)+$nh;
        }
        $cnt[] = $n;
    }
    $ans[] = implode(" ", $cnt);
}
echo implode(PHP_EOL,$ans);

<?php

//[$a,$b] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$h = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$mod = 998244353;
//$mod = 1000000007;
//$alpha = "abcdefghijklmnopqrstuvwxyz";

[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));

for($i=0;$i<$t;$i++){
    [$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $cnt = [];
    if($n %  2 == 0){
        $nh = intdiv($n, 2);
        for($j=0;$j<$nh;$j++){
            $cnt[] = $j+1;
            $cnt[] = $j+$nh+1;
        }
    }else{
        $nh = intdiv($n, 2);
        $nh = intdiv($n, 2);
        for($j=0;$j<$nh;$j++){
            $cnt[] = $j+1;
            $cnt[] = $j+$nh+2;
        }
        $cnt[] = $nh+1;
    }
    $ans[] = implode(" ", $cnt);
}
echo implode(PHP_EOL,$ans);


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

list($n, $m, $k) = $ir->readArrayOfInt(2);
$a = $ir->readArrayOfInt($n, 1);

arsort($a);
$b = [];
$i = $m*$k;
$s = '0';
foreach ($a as $key=>$v) {
	$s = bcadd($s, $v);
	$b[] = $key;
	if (--$i<=0){
		break;
	}
}

sort($b);
echo $s."\n";
$i=1;
$kk = $k-1;
foreach ($b as $key=>$v) {
	if ($i%$m==0 && $kk) {
		echo ($v).' ';
		$kk--;
	}
	$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 */

list($n, $m, $k) = $ir->readArrayOfInt(2);
$a = $ir->readArrayOfInt($n, 1);

arsort($a);
$b = [];
$i = $m*$k;
$s = 0;
foreach ($a as $key=>$v) {
	$s += $v;
	$b[] = $key;
	if (--$i<=0){
		break;
	}
}

sort($b);
echo $s."\n";
$i=1;
$kk = $k-1;
foreach ($b as $key=>$v) {
	if ($i%$m==0 && $kk) {
		echo ($v).' ';
		$kk--;
	}
	$i++;
}


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

// Codeforces Problem 217A
// Codeforces Contest 134 Div 2 Problem C
$raw = g();
$n = $raw[0];
$ct = 0;
for ($x = 0; $x < $n; $x++) {
	$raw = g();
	$xp[$x] = $raw[0];
	$yp[$x] = $raw[1];
	$found = false;
	for ($y = 0; $y < $ct; $y++) {
		if ($ys[$y][0] == $yp[$x]) {
			$found = true;
		}
	}
	if (!$found) {
		$ys[$ct][0] = $yp[$x];
		$ct++;
	}
}

for ($x = 0; $x < $n; $x++) {
	for ($y = 0; $y < $n; $y++) {
		if ($xp[$x] == $xp[$y]) {
			for ($q = 0; $q < $ct; $q++) {
				for ($w = 0; $w < count($ys[$q]); $w++) {
					if ($ys[$q][$w] == $yp[$x]) {
						$group1 = $q;
					}
					if ($ys[$q][$w] == $yp[$y]) {
						$group2 = $q;
					}
				}
			}
			if ($group1 != $group2) {
				for ($q = 0; $q < count($ys[$group2]); $q++) {
					$ys[$group1][] = $ys[$group2][$q];
				}
				unset($ys[$group2]);
			}
		}
	}
}
echo (count($ys) - 1);

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

<?php
$STDIN = fopen('./data.txt', 'r');
define('STDIN', $STDIN);
$n = trim(fgets(STDIN));
$a = array();
$b = array();
$par = array();
function find($num) {
	global $par;
	return $num == $par[$num] ? $num : $par[$num] = find($par[$num]);
}
for($i = 0; $i < $n; ++$i) {
	$par[$i] = $i;
	list($a[], $b[]) = explode(' ',trim(fgets(STDIN)));
}
$ans = $n - 1;
for($i = 0; $i < $n; ++$i) {
	for($j = $i + 1; $j < $n; ++$j) {
		if($a[$i] == $a[$j] || $b[$i] == $b[$j]) {
			$fi = find($i);
			$fj = find($j);
			if($fi != $fj) {
				--$ans;
				$par[$fi] = $fj;
			}
		}
	}
}
echo $ans."\n";
?>

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int x[110], y[110], z[110];
int n, cnt = 0;
void dfs(int k)
{
    z[k] = 1;
    for (int j = 0; j < n; j++)
    {
        if (z[j]!=1 && (x[k]==x[j] || y[k]==y[j]))
        {
            dfs(j);
        }

    }

}
int main()
{
    cin >> n;
    for(int i = 0; i<n; ++i)
    {
        cin >> x[i] >> y[i];
    }
        for (int i = 0; i < n; i++)
        {
            if (z[i]!=1)
            {
                dfs(i);
                cnt++;
            }
        }
    cout << cnt-1 << endl;
    return 0;
}


<?php

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

const MOD = 998244353;

$n = rtrim(fgets($in));

$line = explode(" ", rtrim(fgets($in)));

for($i = 0; $i<$n; ++$i){
    $a[$i] = $line[$i];
    $mp[$a[$i]] = $i;
}

$ans = 1;
$cmp = 0;

for ($i = 0; $i < $n; $i++) {
    if ($cmp < $i)
        $ans = ( 2 * $ans ) % MOD;
    $cmp = max($cmp, $mp[$a[$i]]);
}

echo $ans . "\n";

function what($x){fprintf(STDERR, $x . "\n");}

?>

<?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();
$a = $ir->readArrayOfInt($n);

$cnt = 0;
$R = 0;
$ends = [];

for ($l=0; $l<$n; $l++) {
	if ($l>$R) {
		$cnt++;
		//echo "edge: $R\n";
	}

	// find right position
	if (!isset($ends[$a[$l]])) {
		//$ends[$a[$l]] = $R;
		for ($r=$n-1; $r>$R; $r--) {
			if (!isset($ends[$a[$r]])) {
				$ends[$a[$r]] = $r;
			}

			if ($a[$l] == $a[$r]) {
				break;
			}
		}
	}

	if (!isset($ends[$a[$l]])) {
		$ends[$a[$l]] = $R;
	}

	$R = max([$ends[$a[$l]], $R]);
}

// var_dump($ends);
// echo "count: " . ($cnt+1) . "\n";
// echo "answer: " . (1<<$cnt) . "\n";
echo bcpowmod(2, $cnt, 998244353);

<?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();
$a = $ir->readArrayOfInt($n);

$cnt = 0;
$R = 0;
$ends = [];

for ($l=0; $l<$n; $l++) {
	if ($l>$R) {
		$cnt++;
		//echo "edge: $R\n";
	}

	// find right position
	if (!isset($ends[$a[$l]])) {
		$ends[$a[$l]] = $R;
		for ($r=$n-1; $r>$R; $r--) {
			if (!isset($ends[$a[$r]])) {
				$ends[$a[$r]] = $r;
			}

			if ($a[$l] == $a[$r]) {
				break;
			}
		}
	}

	$R = max([$ends[$a[$l]], $R]);
}

//var_dump($ends);
//echo "count: " . $cnt+1 . "\n";
//echo "answer: " . (1<<$cnt) . "\n";
echo bcpowmod(2, $cnt, 998244353);


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$q = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));

foreach ($aArray as &$t) {
    $t /= pow(3,powCounter($t, 3));
    $t /= pow(2,powCounter($t, 2));
}
function powCounter($x, $p)
{
    $c = 0;
    while ($x > 1) {
        if ($x % $p == 0) {
            $x /= $p;
            $c++;
        } else {
            break;
        }

    }
    return $c;
}

$r = array_count_values($aArray);
$r = count($r);

echo $r > 1 ? "No" : "Yes";

<?php
$n = trim(fgets(STDIN));
$arr = explode(" ",trim(fgets(STDIN)));
for($i=0;$i<count($arr);$i+=1)
{
    $x = $arr[$i];
    while($x%2==0){$x/=2;}
    while($x%3==0){$x/=3;}
    $arr[$i]=$x;
}
sort($arr);
if($arr[0]==$arr[count($arr)-1])
{
    print('Yes');
}
else
{
    print('No');
}
?>

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$q = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
sort($aArray);

$t = $aArray[0];
$t /= pow(2,powCounter($t, 2));
$t /= pow(3,powCounter($t, 3));
function powCounter($x, $p)
{
    $c = 0;
    while ($x > 1) {
        if ($x % $p == 0) {
            $x /= $p;
            $c++;
        } else {
            break;
        }

    }
    return $c;
}

$x = 0;
for ($i = 1; $i < $q; $i++) {

        if ($aArray[$i]%$t !=0) {
            $x = 1;
            break;
        }

}
echo $x == 1 ? "No" : "Yes";

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$q = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
sort($aArray);
$pArray = array();
$t = $aArray[0];
$t2 = $t;
while ($t > 1) {
    $x = 0;
    if (!empty($pArray)) {
        sort($pArray);
        foreach ($pArray as $prime) {
            $x = $prime;
        }
    } else {
        $x = 1;
    }
    $sqrt = floor(sqrt($t))+1;
    for ($i = $x + 1; $i <= $sqrt; $i++) {
        $p = powCounter($t, $i);
        if ($p > 0) {
            $pArray[$i] = $p;
            $t /= pow($i, $p);
        }
    }
    if ($t2 == $t && $t != 1) {
        $pArray[$t] = 1;
        break;
    }
    $t2 = $t;
}
function powCounter($x, $p)
{
    $c = 0;
    while ($x > 1) {
        if ($x % $p == 0) {
            $x /= $p;
            $c++;
        } else {
            break;
        }

    }
    return $c;
}

if (isset($pArray[2])) {
    unset($pArray[2]);
}
if (isset($pArray[3])) {
    unset($pArray[3]);
}
$x = 0;
for ($i = 1; $i < $q; $i++) {
    foreach ($pArray as $prime => $pow) {
        if (powCounter($aArray[$i], $prime) != $pow) {
            $x = 1;
            break;
        }
    }
    if ($x == 1) {
        break;
    }
}
echo $x == 1 ? "No" : "Yes";

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$q = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
sort($aArray);
$pArray = array();
$t = $aArray[0];
$t2 = $t;
while ($t > 1) {
    $x = 0;
    if (!empty($pArray)) {
        foreach ($pArray as $prime) {
            $x = $prime;
        }
    } else {
        $x = 1;
    }
    $sqrt = floor(sqrt($t));
    for ($i = $x + 1; $i <= $sqrt; $i++) {
        $p = powCounter($t, $i);
        if ($p > 0) {
            $pArray[$i] = $p;
            $t /= pow($i, $p);
        }
    }
    if ($t2 == $t && $t != 1) {
        $pArray[$t] = 1;
        break;
    }
    $t2 = $t;
}
function powCounter($x, $p)
{
    $c = 0;
    while ($x > 1) {
        if ($x % $p == 0) {
            $x /= $p;
            $c++;
        } else {
            break;
        }

    }
    return $c;
}

if (isset($pArray[2])) {
    unset($pArray[2]);
}
if (isset($pArray[3])) {
    unset($pArray[3]);
}
$x = 0;
for ($i = 1; $i < $q; $i++) {
    foreach ($pArray as $prime => $pow) {
        if (powCounter($aArray[$i], $prime) != $pow) {
            $x = 1;
            break;
        }
    }
    if ($x == 1) {
        break;
    }
}
echo $x == 1 ? "No" : "Yes";


<?
$colCount = fgets (STDIN);
$colHeight = fgets (STDIN);
$colHeight = explode (' ', $colHeight);
$lastIteration = $minIteration = 0;

foreach ($colHeight as $key => &$value) {
  $minIteration = $key + 1;

  $lastIteration ++;
  if ($minIteration > $lastIteration) { $minIteration = $lastIteration; }

  if ($minIteration > $value) { $minIteration = $value; }

  $rowLength = $colCount - $key;
  if ($minIteration > $rowLength) { $minIteration = $rowLength; }

  $value = $lastIteration = $minIteration;
}

$result = $lastIteration = 0;
$maxIndex = $colCount - 1;

for ($i = $maxIndex; $i >= 0; $i--) {
  $minIteration = $maxIndex - $i + 1;

  $lastIteration ++;
  if ($minIteration > $lastIteration) { $minIteration = $lastIteration; }

  if ($minIteration > $colHeight [$i]) { $minIteration = $colHeight [$i]; }

  $rowLength = $i + 1;
  if ($minIteration > $rowLength) { $minIteration = $rowLength; }

  $lastIteration = $minIteration;

  if ($minIteration > $result) { $result = $minIteration; }
}

echo "$result\n";


<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
		$str=trim(fgets(STDIN));
		$str2="";
		$flag=0;
		$alpha="abcdefghijklmnopqrstuvwxyz";
		for ($i=0; $i <strlen($alpha) ; $i++)
		 {
			 	$cnt=0;
				for ($j=0; $j <strlen($str) ; $j++)
				 {
						if($alpha[$i]==$str[$j])
						{
			                 $cnt++;
			                if($cnt%2==1&&$j==strlen($str)-1)
			                 {
			                 	$str2.=$alpha[$i];
			                 	$flag=1;
			                 	break;
			                 }

						}
			             else
			             {

			                if($cnt%2==1)
			                 {
			                 	$str2.=$alpha[$i];
			                 	$flag=1;
			                 	break;
			                 }
			                 $cnt=0;

			             }

				 }
		 }
		 if($flag==0)
		 	echo " \n";
		 else
		 {
		 	$split=str_split($str2);
		 	sort($split);
		 	echo implode($split)."\n";
		 }
}


<?php
error_reporting(E_ALL);
ini_set("memory_limit", "256M");
ini_set("max_execution_time", 1);

const BRACKET_OPEN  = "[";
const BRACKET_CLOSE = "]";

const MATRIX_SPACE = " ";
const MATRIX_LINE  = "|";
const MATRIX_PLUS  = "+";
const MATRIX_MINUS = "-";

$fd = fopen("php://stdin", 'r');
$length   = (int) fgets($fd);
$brackets = trim(fgets($fd));

$brackets = str_split($brackets, 1);
$bracketsDepth = [];
$maxDepth = 0;
$depth = 0;

foreach ($brackets as $bracket) {
    if ($bracket == BRACKET_OPEN) {
        $depth++;
        $maxDepth = max($maxDepth, $depth);
    }
    $bracketsDepth[] = [
        $bracket,
        $depth,
    ];
    if ($bracket == BRACKET_CLOSE) {
        $depth--;
    }
}

$matrix = [0 => []];
foreach ($bracketsDepth as $position => list($bracket, $depth)) {
    if ($position > 0) {
        list($prevBracket, $prevDepth) = $bracketsDepth[$position - 1];
        if ($bracket == BRACKET_CLOSE && $prevBracket == BRACKET_OPEN) {
            $matrix[0][] = MATRIX_SPACE;
            $matrix[0][] = MATRIX_SPACE;
            $matrix[0][] = MATRIX_SPACE;
        }
    }
    $matrix[0][] = MATRIX_LINE;
}

for($i = 1; $i <= $maxDepth; $i++) {
    $matrix[$i] = array_fill(0, count($matrix[0]), MATRIX_SPACE);
}

$bracketPtr = 0;
foreach ($matrix[0] as $position => $item) {
    if ($item == MATRIX_LINE) {
        list($bracket, $depth) = $bracketsDepth[$bracketPtr];
        $row = $maxDepth + 1 - $depth;
        $matrix[$row][$position] = MATRIX_PLUS;
        if ($bracket == BRACKET_OPEN) {
            $matrix[$row][$position + 1] = MATRIX_MINUS;
        } else {
            $matrix[$row][$position - 1] = MATRIX_MINUS;
        }
        for ($i = 1; $i < $row; $i++) {
            $matrix[$i][$position] = MATRIX_LINE;
        }
        $bracketPtr++;
    }
}

for($i = -$maxDepth; $i <= $maxDepth; $i++) {
    $ofs = abs($i);
    echo implode("", $matrix[$ofs]);
    if ($i != $maxDepth) echo "\n";
}


<?php
$num=trim(fgets(STDIN));
$array=array();
for ($i=0; $i < $num; $i++) {
    $array[$i]=trim(fgets(STDIN));
}
$finalresult=array_count_values($array);
print_r(array_search(max($finalresult), $finalresult));
?>

<?php
fscanf(STDIN,"%d",$n);
$teams=array();
for ($i=0; $i <$n ; $i++)
 {
	$teams[$i]=trim(fgets(STDIN));

 }
 if(count($teams)==1)
 	echo "$teams[0]";
 else
 {

 $unique[0]=$teams[0];
 for ($i=1; $i <count($teams)-1 ; $i++)
 {
 	if($unique[0]!=$teams[$i])
 	{
 		$unique[1]=$teams[$i];
 		break;
 	}

 }

//$unique=array_unique($teams);
 	//echo $unique[1]."hi\n";

//print_r($unique);

$fG=0;
$sG=0;
for ($i=0; $i <count($teams) ; $i++)
 {
	if($unique[0]==$teams[$i])
		$fG++;
	else
		$sG++;
 }
 if($fG>$sG)
 	echo $unique[0];
 else
 	echo $unique[1];
}

<?php
$n = intval(trim(fgets(STDIN)));
$arr = [];
for($i = 0; $i < $n; $i++){
    $arr[] = trim(fgets(STDIN));
}
$a = array_count_values($arr);
$a = array_flip($a);
$max = max(array_keys($a));
echo $a[$max] .PHP_EOL;
exit;

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

    $goals = array();
    for ($i = 0; $i < $n; ++$i) {
        $str = trim(fgets(STDIN));

        if (array_key_exists($str, $goals))
                $goals[$str] += 1;
        else
                $goals[$str] = 1;
    }

    asort($goals);
    foreach ($goals as $key => $value);

    echo $key;
?>

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
foreach($arr as $v)
    $newarr[$v]++;
$m=max($newarr);
foreach($newarr as $k=>$v)
    if($v==$m) $winner=$k;
echo $winner;
?>

<?php
    $n = trim(fgets(STDIN));
    $temp=array("value"=>array(),"score"=>array());
    for($i=0;$i<$n;$i++){
        $input = strtoupper(trim(fgets(STDIN)));
        if(!in_array($input,$temp["value"])){
            $temp["value"][]=$input;
            $temp["score"][]=0;
        }
        $temp["score"][array_search($input,$temp["value"])]++;
    }
    echo $temp["value"][array_keys($temp["score"], max($temp["score"]))[0]];
?>

<?php
fscanf(STDIN,"%d",$n);
$teams=array();
for ($i=0; $i <$n ; $i++)
 {
	$teams[$i]=trim(fgets(STDIN));
 }
 $unique=array_unique($teams);

 if(count($unique)==1)
     echo "$teams[0]";
 else
  {
  	$firstTeamGoal=0;
  	$secondTeamGoal=0;
    for ($i=0; $i <count($teams) ; $i++)
    {
    	if($unique[0]==$teams[$i])
    		$firstTeamGoal++;
    	else
    		$secondTeamGoal++;

    }
    if($firstTeamGoal>$secondTeamGoal)

    	echo "$unique[0]";
    else
    	echo "$unique[1]";
  }

//print_r($str);

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
foreach($arr as $v)
    $newarr[$v]++;
$m=max($newarr);
foreach($newarr as $k=>$v)
    if($v==$m) $k;
echo $k;
?>


<?php

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

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

for($i=1;$i<=$n;$i++)    $visited[$i]=0;

function dfs($cell)    {
	global $t;
	global $visited;
	global $rail;
	global $n;
	//echo $cell."\n";

	if($cell==$t)    return 1;
	if($visited[$cell])    return 0;
	if($cell==$n)    return 0;

	$visited[$cell]=1;
	return dfs($cell+$rail[$cell-1]);
}

$ans=dfs(1);

if($ans)    echo "YES\n";
else    echo "NO\n";

?>

<?php
fscanf(STDIN,"%d %d\n",$n,$m);
$arr = explode(' ',trim(fgets(STDIN)));
   $t=1;

  while($t<$m){
  $t=$arr[$t-1]+$t;

  if($t==$m){echo "YES";break;}
  else
  if($t>$m){echo "NO";break;}

  }

    ?>

<?php
$n = explode(" ",trim(fgets(STDIN)));
$line = explode(" ",trim(fgets(STDIN)));
$key=0;
while ($key<=$n[1]-1)
{
    $key = $line[$key]+$key;
    if ($key==$n[1]-1)break;
}
if ($key==$n[1]-1)echo "YES";
else echo "NO";

<?php
$n = explode(" ", trim(fgets(STDIN)));
$x = explode(" ", trim(fgets(STDIN)));
$s = "NO";
$i = 1;
while($i < $n[0]){
	$i = $i + $x[$i-1];
	if ($i == $n[1]){
		$s = "YES";
		break;
	}
}
print ($s);
?>

<?php
// 500A  Транспорт на Новый год
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
list($n, $t) = preg_split('/ /', $input_line, -1, PREG_SPLIT_NO_EMPTY);
$n = (int) $n;
$t = (int) $t;

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

$out = 'NO';

$i = 0;
array_push($arr, 1);

while ( $i <= $n - 1) {
    if (($i + 1) == $t) {
        $out = 'YES';
        break;
    }
    if ($i >= $t) {
        break;
    }
    $i = $i + $arr[$i];
}

echo $out;

?>

<?php

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

$numberOfArraysElements = $array1[0];
$transIndex = $array1[1];
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $array[$index] == $transIndex && $index < $numberOfArraysElements) {
		echo "YES";
		break;
	} elseif ($index + 1 + $array[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $array[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php
$n = explode(" ", trim(fgets(STDIN)));
$x = explode(" ", trim(fgets(STDIN)));
$s = "NO";
for ($i=1;$i<=$n[0]-1;$i++){
	$portal = $i+$x[$i-1];
	if ($portal == $n[1]){
		$s = "YES";
		break;
	}
}
print ($s);
?>

<?php
// 500A  Транспорт на Новый год
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
list($n, $t) = preg_split('/ /', $input_line, -1, PREG_SPLIT_NO_EMPTY);
$n = (int) $n;
$t = (int) $t;

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

$out = 'NO';

$i = 0;
while ( $i < $n - 1) {
    if (($i + 1) == $t) {
        $out = 'YES';
        break;
    }
    if ($i >= $t) {
        break;
    }
    $i = $i + $arr[$i];
}

echo $out;

?>

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $array[$index] == $transIndex && $index < $numberOfArraysElements) {
		if($transIndex == 5) echo $index . " " . $array[$index]; else echo "YES";
		break;
	} elseif ($index + 1 + $array[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $array[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $array[$index] == $transIndex && $index < $numberOfArraysElements) {
		echo "YES"; if($transIndex == 5) echo $index . " " . $array[$index];
		break;
	} elseif ($index + 1 + $array[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $array[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $array[$index] == $transIndex && $index < $numberOfArraysElements) {
		echo "YES";
		break;
	} elseif ($index + 1 + $array[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $array[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));
echo $transIndex;
$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $array[$index] == $transIndex && $index < $numberOfArraysElements) {
		if($transIndex == 5) echo $index . " " . $array[$index]; else echo "YES";
		break;
	} elseif ($index + 1 + $array[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $array[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $item[$index] == $transIndex && $index < $numberOfArraysElements) {
		echo "YES";
		break;
	} elseif ($index + 1 + $item[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $item[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

foreach ($array as $item) {
    if ($index + $item[$index] == $transIndex && $index <= $numberOfArraysElements) {
		echo "YES";
		break;
	} elseif ($index + $item[$index] < $transIndex && $index <= $numberOfArraysElements) {
		$index += $item[$index];
	} else {
		echo "NO";
		break;
	}
}

?>


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

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

   for($q=0; $q <$t; $q++) {
       $ans = 0;
       $n = IO::getInt();
       $s = IO::getInt();

       $l = floor($n / 2);
       while ($l > 0 && $s[$l-1] == $s[$l]) {
           $l--;
       }
       $r = $n - 1 - $l;
       $ans = $r - $l + 1;
       IO::pr($ans);

   }

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

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

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

        return $d == $n;
    }

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

         return $a[$n];
     }

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

}

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

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

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

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

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

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

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

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($j = 0; $j < $t; $j++) {
    $l = trim(fgets($handle));
    $s = trim(fgets($handle));

    $mid = (int)($l/2);
    $e=$mid-1;
    $x=$mid+1;
    $target = $s[$mid];
    $count = 1;
    while ($e >= 0 || $x<$l) {
        if($s[$e] === $target ) {
            $e--;
        }

        if($s[$x] === $target) {
            $x++;
        }

        if($s[$e] !== $target && $s[$x] !== $target ){
            break;
        }

    }

    echo ($x-$e) -1 . "\n";
}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($j = 0; $j < $t; $j++) {
    $l = trim(fgets($handle));
    $s = trim(fgets($handle));
    echo (int) ($l/2) . "\n";
    //echo $count . "\n";
}


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

list($n, $q) = explode(" ", trim(fgets($file)));
$a = explode(" ", trim(fgets($file)));

$aa = array_count_values($a);
$c = $aa[1];

for ($i = 0; $i < $q; $i++) {
  list($t, $xk) = explode(" ", trim(fgets($file)));

  if ($t == 1) {
    $a[$xk - 1] = 1 - $a[$xk - 1];
    if ($a[$xk - 1] == 1) { $c++; }
    else { $c--; }
  } else {
    if ($c >= $xk) { echo '1'.PHP_EOL; }
    else { echo '0'.PHP_EOL; }
  }
}

?>

<?php

list($n, $q) = array_map('intval', explode(' ', trim(fgets(STDIN))));
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
for ($i = 0; $i < $q; ++$i) {
    list($t[$i], $k[$i]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
$cnt = count(array_keys($a, 1));
for ($i = 0; $i < $q; ++$i) {
    if (1 == $t[$i]) {
        $a[$k[$i] - 1] = 1 - $a[$k[$i] - 1];
        $a[$k[$i] - 1] ? ++$cnt : --$cnt;
    } else {
        echo (int) ($cnt >= $k[$i]).PHP_EOL;
    }
}

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

list($n, $q) = explode(" ", trim(fgets($file)));
$a = explode(" ", trim(fgets($file)));

for ($i = 0; $i < $q; $i++) {
  list($t, $xk) = explode(" ", trim(fgets($file)));

  if ($t == 1) {
    $a[$xk - 1] = 1 - $a[$xk - 1];
    echo $a[$xk - 1].PHP_EOL;
  } else {
    $aa = array_count_values($a);
    if ($aa[1] >= $xk) { echo '1'.PHP_EOL; }
    else { echo '0'.PHP_EOL; }
  }
}

?>


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$result = 0;
while($n--){
    $aArray = explode(" ", trim(fgets($file)));
    array_unshift($aArray, 0);
    for ($i = 1; $i <= $m; $i++) {
        if ($aArray[2*$i]==1 || $aArray[2*$i-1]==1) {
            $result++;
        }
    }
}
echo $result;

<?php
list($floor, $count) = explode(' ', fgets(STDIN));
$floor = (int)$floor;
$count = (int)$count*=2;

$isHome = 0;

if ($floor > 0 && $count > 0) {

    $data = [];
    $i = 0;
    while (($s = fgets(STDIN)) && ($i < $floor)) {
        $data = explode(" ", $s);
        if(count($data) !== $count) {
            echo 'window limit' . count($data) . $count;
            break;
        }

        $i++;

        for($j = 0; $j < $count; $j++) {
            if((int)$data[$j] === 1) {
                ++$isHome;
                if(($j % 2) === 0) {
                    ++$j;
                }
            }
        }

        if($i === $floor) { break; }

    }

    echo $isHome . PHP_EOL;

} else {
    echo 0;
}

<?php
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$result = 0;
while($n--){
    $aArray = explode(" ", trim(fgets($file)));
    for ($i = 0; $i < $m; $i++) {
        if ($aArray[2*$i] + $aArray[2*$i+1] > 0) {
            $result++;
        }
    }
}
echo $result;
?>

<?php
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$ans = 0;
while($n--)
{
    $a = explode(" ", trim(fgets($file)));
    for($i = 0; $i < $m; $i++)
    {
        if($a[2 * $i] + $a[2 * $i + 1] > 0)
            $ans++;
    }
}
echo $ans;
?>

<?php
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$ans = 0;
while($n--)
{
    $a = explode(" ", trim(fgets($file)));
    for($i = 0; $i < $m; $i++)
    {
        if($a[2 * $i] + $a[2 * $i + 1] > 0)
            $ans++;
    }
    echo $ans;
}
?>

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$result = 0;
while($n--){
    $aArray = explode(" ", trim(fgets($file)));
    array_unshift($aArray, 0);
    print_r($aArray);
    for ($i = 1; $i <= $m; $i++) {
        if ($aArray[2*$i]==1 || $aArray[2*$i-1]==1) {
            $result++;
        }
    }
}
echo $result;

<?php
list($floor, $count) = explode(' ', fgets(STDIN));
$floor = (int)$floor;
$count = (int)$count*=2;

$isHome = 0;

if ($floor > 0 && $count > 0) {

    $data = [];
    $i = 0;
    while (($s = fgets(STDIN)) && ($i < $floor)) {
        $data = explode(" ", $s);
        if(count($data) !== $count) {
            echo 'window limit' . count($data) . $count;
            break;
        }

        $i++;

        for($j = 0; $j < $count; $j++) {
            if((int)$data[$j] === 1) {
                ++$isHome;
                if(($j % 2) === 0) {
                    ++$j;
                }
                ++$j;
            }
        }

        if($i === $floor) { break; }
    }

    echo $isHome . PHP_EOL;

} else {
    echo 0;
}


<?php

$n = readline();
$n = intval($n);

$a = readline();
$a = explode(" ", $a);

$count = $n;
$result = [$n];
while($count != 1) {
    $count = $a[$count - 2];
    $result[] = $count;
}

for ($i = sizeof($result) - 1; $i >= 0; $i--) {
    echo $result[$i] . ' ';
}

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array($a);
$d = $a - 2;
for($x = $a - 2; $x >= 0; $x--)
{
     if($x == $d)
     {
          $c[count($c)] = $b[$d];
          $d = $b[$d] - 2;
     }
}
$e = array_reverse($c);
print implode(" ", $e);
?>


<?php
while($s = fgets(STDIN)){
$input .= $s;
}
$input = explode("\r\n", $input);
$n = $input[0];
$a = $input[1][0];
$result = 0;
for ($s = 0; $s < strlen($input[1]); $s++) {
    for ($i=1; $i < (count($input)-1); $i++) {
        if ($a != $input[$i][$s]) {
            echo $result;

            die();
        }

    }
    $result++;
    $o = $s + 1;
    $a = "{$input[1][$o]}";
}
?>

<?php

function common_prefix_len($str1, $str2, $limit = 20) {
  $len1 = strlen($str1);
  $len2 = strlen($str2);
  $len_min = min($len1, $len2, $limit);

  for($i=0; $i < $len_min; $i++) {
    if ($str1[$i] != $str2[$i]) return $i;
  }
  return $len_min;
}

function find_prefix_len($str_list) {
  $list_count = count($str_list);
  $result = 20;
  for($i=0; $i < $list_count - 1; $i++) {
    $result = min(common_prefix_len($str_list[$i], $str_list[$i+1], $result), $result);
  }

  return $result;
}

function read_input() {
  $count = intval(fgets(STDIN));
  $str = array();
  for ($i=0; $i<$count; $i++) {
    $str[] = trim(fgets(STDIN));
  }

  return $str;
}

print (find_prefix_len(read_input())) ."\n";

<?php
//считываем
$n=fgets(STDIN);
$a=array();
for($i=0;$i<$n;$i++) $a[$i]=fgets(STDIN);
//обрабатываем
$b=array();
$buf;$size=0;$one;
for($i=0;$i<strlen($a[0]);$i++) {
$one=1;
$buf=$a[0][$i];
foreach($a as $k=>$v) {
if($v[$i]!=$buf) goto out;
elseif($one) {
$one=0;
$size++;
}
}
}
out:
$size--;
echo $size;
?>

<?php

$flag = 1; //must be not zero for STDIN
$in = 'php://stdin';
if (!$flag)
{
    $in = "input.txt";
}
$fd = fopen($in, "r");
fscanf($fd, "%d\n", $n);

$phones=array($n);
$result=0;
for ($c=0;$c<$n;$c++)
{
   fscanf($fd, "%s\n",$phones[$c]);
}
fclose($fd);

for ($c=0 ,$prefix=$phones[0];$c<$n;$c++ )
{

  for ($l=0 ;$l<=strlen($prefix);$l++ )
    {
  $cmp=strncmp($prefix,$phones[$c],(strlen($prefix)-$l));
  if ($cmp!=0)
  {
     continue;
  }
  $prefix=substr($prefix , 0 ,(strlen($prefix)-$l) );
  $result=strlen($prefix);

  break;
    }
  }

print "$result\n";
?>

<?php
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$x=explode("\n",$n);
$count=$x[0];
$len=strlen($x[(int)$count]);
for($t=0;$t<$len;){
    $cnt=0;
    for($i=1;$i<$count;$i++){
        if((int)$x[$i][$t]==(int)$x[$i+1][$t]){
            $cnt++;
        }

    }
    if(($cnt+1)==$count){
        $t++;
    }
    else{
        echo $t;
        break;
    }
}
?>

<?php
    define ("TEST", false);
    if (TEST) $GLOBALS['file'] = fopen('input.txt', 'r');
    else $GLOBALS['file'] = fopen('php://stdin', 'r');
    function debug($var){echo '<pre>'; print_r($var); echo '</pre>';}
    function read_str(){return trim(fgets($GLOBALS['file']));}
    function read_array(){return explode(' ', read_str());}
    /***************************************************************/
    $n = read_str();
    $s = read_str();

    function compare($s1, $s2)
    {
        $s = '';
        $len = strlen($s1);
        for($i=0; $i < $len; $i++)
        {
            if($s1[$i] == $s2[$i]) $s.= $s1[$i];
            else return $s;
        }

        return $s;
    }

    for($i=2; $i<=$n; $i++)
    {
        $s2 = read_str();

        $s = compare($s, $s2);
        if($s==='')
        {
            echo 0; die();
        }
    }

    echo strlen($s);

<?php
$fp = fopen('php://stdin', 'r');
$tmp='';
while($line = fgets($fp)) $tmp.=$line;

$tmp=explode("\n",$tmp);
$count=(int)$tmp[0];
$current=trim($tmp[1]);
$len=strlen($current);
for ($i=2;$i<=$count&&$len>0;$i++){
  while (strpos($tmp[$i],$current )!==0 && $len>0){
      $len--;
      $current=substr($current,0,$len);
  }
}
echo $len;
?>

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

$a = array();
for($i=0;$i<$n;$i++) $a[$i] = trim(fgets(STDIN));

sort($a, SORT_STRING);

$r = 0;
for($i=0;$i<strlen($a[0]);$i++) if($a[0][$i] == $a[$n - 1][$i]) $r ++; else break;

print $r;
?>

<?php

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

$prefix = array(0 => "");

$s = "a".trim(fgets($f));

$answer = strlen($s);
for($i=1; $i<=$answer; $i++)
{
    $prefix[$i] = substr($s,0, $i);
}

for($i=1; $i<$n; $i++)
{
    $s = "a".trim(fgets($f));
    while($answer>0)
    {
        if(substr($s, 0, $answer)==$prefix[$answer]) break;
        $answer--;
    }
}

echo $answer-1;

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

<?php
while($s = fgets(STDIN)){
$input .= $s;
}
$input = explode("\r\n", $input);
$n = $input[0];
$a = $input[1][0];
$result = 0;
for ($s = 0; $s < strlen($input[1]); $s++) {
    for ($i=1; $i < count($input); $i++) {
        if ($a != $input[$i][$s]) {
            echo $result;

            die();
        }

    }
    $result++;
    $o = $s + 1;
    $a = "{$input[1][$o]}";
}
?>

<?php

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

$prefix = array(0 => "");

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

$answer = strlen($s);
for($i=1; $i<=$answer; $i++)
{
    $prefix[$i] = substr($s,0, $i);
}

for($i=1; $i<$n; $i++)
{
    $s = trim(fgets($f));
    while($answer>0)
    {
        if(substr($s, 0, $answer)==$prefix[$answer]) break;
        $answer--;
    }
}

echo $answer;


<?php
$n = (int)trim(fgets(STDIN));
$susi = explode(" ", trim(fgets(STDIN)));

$count = 1;
$max = 0;
$last = 0;
for ($i = 0; $i < $n - 1; $i++) {
    if ($susi[$i] == $susi[$i + 1]) {
        $count++;
    } else {
        $max = max(min($count, $last), $max);
        $last = $count;
        $count = 1;
    }
}
$max = max(min($count, $last), $max);
$last = $count;
print $max * 2;

<?php
$n = (int)trim(fgets(STDIN));
$susi = explode(" ", trim(fgets(STDIN)));

$count = 1;
$counts = [];
for ($i = 0; $i < $n - 1; $i++) {
    if ($susi[$i] == $susi[$i + 1]) {
        $count++;
    } else {
        $counts[] = $count;
        $count = 1;
    }
}
$counts[] = $count;
if (count($counts) < 2) {
    print 0;
    die;
}
$max = 1;
for ($i = 0; $i < count($counts) - 1; $i++) {
    $max = max(min($counts[$i], $counts[$i + 1]), $max);
}
print $max * 2;

<?php
$n = (int)trim(fgets(STDIN));
$susi = explode(" ", trim(fgets(STDIN)));

$count = 1;
$counts = [];
for ($i = 0; $i < $n - 1; $i++) {
    if ($susi[$i] == $susi[$i + 1]) {
        $count++;
    } else {
        $counts[] = $count;
        $count = 1;
    }
}
$counts[] = $count;
if (count($counts) < 2) {
    print 0;
    die;
}
$max = 1;
print_r($counts);
for ($i = 0; $i < count($counts) - 1; $i++) {
    $max = max(min($counts[$i], $counts[$i + 1]), $max);
}
print $max * 2;


<?php

$n = trim(fgets(STDIN));

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

$p = [];

for($i = 0; $i<$n-1; $i++){
	for($j = $i+1; $j<$n; $j++){
		$p[] = $k[$i] + $k[$j];
	}
}

$p = array_count_values($p);

fwrite(STDOUT, max($p));

?>


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

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

function solve()
{
     $ans = 0;
    list($n, $k) = IO::getArray();
     $a = IO::getArray();
     $tt = [];
     if($k == 1) {
          $ans = floor(($n-1) / 2);
     } else {
        for($i=1; $i<$n-1; $i++) {
          if(bccomp( $a[$i], bcadd($a[$i-1], $a[$i+1])) == 1) {
               $ans++ ;
          }
     }
     }

     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
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

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

function solve()
{
     list($n, $k) = IO::getArray();
     $a = IO::getArray();
     $tt = [];
     for($i=1; $i<$n-1; $i++) {
          if(bccomp( $a[$i], bcadd($a[$i-1], $a[$i+1])) == 1) {
               $tt[] = $a[$i] ;
          }
     }

     $ans = count($tt);

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