<?php

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

$photos = [];

for ($i = 0; $i < $n; $i++) {
	$k = $ids[$i];
	if (!isset($photos[$k])) {
		$photos[$k] = [
			'id' => $k,
			'time' => 0,
			'likes' => 0,
		];
	}

	$photos[$k]['time'] = $i;
	$photos[$k]['likes']++;
}

function compare($a, $b) {
	if ($a['likes'] > $b['likes']) {
		return -1;
	} elseif ($a['likes'] < $b['likes']) {
		return 1;
	} elseif ($a['time'] < $b['time']) {
		return -1;
	} elseif ($a['time'] > $b['time']) {
		return 1;
	} else {
		return 0;
	}
}

usort($photos, "compare");

echo $photos[0]['id'];

#!/usr/bin/php
<?php
trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$c = array();
$w = '';
$wc = 0;
foreach ($arr as $ak => $a) {
	if (isset($c[$a])) {
		$c[$a]++;
	} else {
		$c[$a] = 1;
	}
	if ($c[$a] > $wc) {
		$w = $a;
		$wc = $c[$a];
	}
}
echo $w;
exit();

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

$likes = explode(" ", $likes);

$max = -1;

for ($i = 0; $i < $num; $i++) {
	$photos[$likes[$i]]++;
	if ($photos[$likes[$i]] > $max) {
		$max = $photos[$likes[$i]];
		$index = $likes[$i];
	}
}

echo $index;

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

$likes = [];
foreach ($a as $i => $id) {
  if (!isset($likes[$id])) {
    $likes[$id] = [0, -1];
  }
  $likes[$id][0]++;
  $likes[$id][1] = $i;
}

uasort($likes, function ($a, $b) {
  if ($a[0] != $b[0]) {
    return $b[0] - $a[0];
  }
  return $a[1] - $b[1];
});

reset($likes);
echo key($likes), "\n";

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$row=fgets($handle);
$row = preg_replace ('/\s+/', ' ',  $row) ;
$row = trim($row);
$input = explode(" ",$row );
$counters=array();
$counter=0;
if ($n>count($input))
$n=count($input);
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}

if($n>0){
echo $input[array_search(max($counters),$counters, true)];
}
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<$n;$i++){
		if($input[$i]==$v&&$i<=$k+1)
			$count++;
	}
	return $count;
}
?>

<?php

$n = trim(fgets(STDIN));
$sArr = trim(fgets(STDIN));
$arr = explode(' ', $sArr);
$arCount = array_count_values($arr);
arsort($arCount);
$e = reset($arCount);
$last = -1;
$asw = 0;
foreach ($arCount as $key=>$value)
{
    if ($value == $e)
    {
        //print_R('key='.$key."\r");
        $cur = array_keys($arr, $key);

        //print_R($cur[count($cur)-1]);
        if (($cur[count($cur)-1] < $last) || $last < 0)
        {
            $last = $cur[count($cur)-1];
            $asw = $key;
        }
    }
    else
        break;
}
echo $asw;

<?

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

$counts = [];
$max    = 0;
$max_id = 0;

foreach ($a as $id) {
    $id = (int) $id;

    $counts[$id]++;

    if ($counts[$id] > $max) {
        $max_id = $id;
        $max    = $counts[$id];
    }
}

echo $max_id;

<?
$stdin = fopen('php://stdin', 'r');
$num = fgets($stdin);
$str = fgets($stdin);
$arr = array();
$t = explode(" ", $str);
$out = -1;
for($i = 0; $i < $num; $i++){
    $m = trim($t[$i]);
    if(array_key_exists($m, $arr)) $arr[$m]++; else $arr[$m] = 1;
    if($arr[$out] < $arr[$m] || $out == -1) $out = $m;
}

$stdout = fopen('php://stdout', 'w');
fwrite($stdout, $out);
fclose($stdout);
?>

<?php
$n = intval(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));
$likes=[];
$last_likes=[];
for ($i=0; $i<$n; $i++){
    $id = $a[$i];
    if(isset($likes[$id])){
        $likes[$id]++;
    }else{
        $likes[$id] = 1;
    }
    $last_likes[$id] = $i;
}
//var_dump($likes, $last_likes);
$max = 0;
$max_id = 0;
$last_like = 10000;
foreach($likes as $id => $count){
    if ($count >= $max && $last_likes[$id] < $last_like || $count > $max ){
        $max = $count;
        $max_id = $id;
        $last_like = $last_likes[$id];
    }
}

echo $max_id."\n";

<?php

function getint()
{
    $result = 0;
    while ($c = fgetc(STDIN)) {
        if (false === strpos(" \t\n\r\0\x0B", $c)) {
            break;
        }
    }

    do {
        if (!is_numeric($c)) {
            break;
        }

        $result = $result * 10 + $c;
    } while (null !== $c = fgetc(STDIN));

    return $result;
}

$map = [];
$maxNumber = 0; $max = 0;
$n = getint();
while ($n--) {
    $number = getint();
    if (!isset($map[$number])) {
        $map[$number] = 0;
    }

    if ($max < $value = ++$map[$number]) {
        $max = $value;
        $maxNumber = $number;
    }
}

echo $maxNumber . PHP_EOL;

<?php
$a = trim(fgets(STDIN));
$l = explode(' ',trim(fgets(STDIN)));
$lengArray = (count($l));
$totalArray = [];
for($i = 0; $i < $lengArray; $i++){
    $id = $l[$i];
    $totalArray[$id]['value'] = $totalArray[$id]['value'] + 1;
    $totalArray[$id]['key'] = $i;
}

function cmp($a, $b)
{
    if ($a['value'] == $b['value']) {
        return $a['key'] > $b['key'];
    }
    return $a['value'] < $b['value'];
}

uasort($totalArray, "cmp");
reset($totalArray);
echo key($totalArray);
?>

<?
fgets(STDIN);
$a = explode(' ', trim(fgets(STDIN)));
foreach($a as $b) $c[$b][] = 1;
foreach($c as $b => $e) $f[$b] = sizeof($c[$b]);
$e = max($f);
foreach($f as $g => $h) if((int)$f[$g] < $e) unset($f[$g]);
$e = null;
foreach($f as $g => $h) $e[$g] = max(array_keys($a, $g));
print trim(array_search(min($e), $e));

<?php

$amount = trim(fgets(STDIN));
$photos = explode(' ', trim(fgets(STDIN)));

$counter = array();
$result = array();

$sort = array();
$sort['index'] = array();
$sort['amount'] = array();

for ($i = 0; $i < $amount; $i++)
{
    $photo = $photos[$i];

    $result[$photo] = array(
        'index'  => $i,
        'amount' => ++$counter[$photo],
        'photo'  => $photo
    );

    $sort['index'][$photo] = $i;
    $sort['amount'][$photo] = $counter[$photo];
}

array_multisort($sort['amount'], SORT_DESC, $sort['index'], SORT_ASC, $result);

$result = reset($result);

echo $result['photo'];

?>

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}
if($n>0){
    print_r($counters);
echo $input[array_search(max($counters),$counters, true)];
}
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<$n;$i++){
		if($input[$i]==$v&&$i<=$k)
			$count++;
	}
	return $count;
}
?>

<?
$handle = fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($i,$input[$i],$input);
	$counter++;
}
echo $input[array_search(max($counters),$counters)];
function bestqualityfunctiononphp($k,$v,$input){
	for($i=0; $i<=$k;$i++){
		if($input[$i]==$v&&$i<=$k)
			$count++;
	}
	return $count;
}
?>

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}
echo $input[array_search(max($counters),$counters)];
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<=$n;$i++){
		if($input[$i]==$v&&$i<=$k+1)
			$count++;
	}
	return $count;
}
?>

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}
if($n>0){
echo $input[array_search(max($counters),$counters, true)];
}
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<$n;$i++){
		if($input[$i]==$v&&$i<=$k)
			$count++;
	}
	return $count;
}
?>

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}
if($n>0){
echo $input[array_search(max($counters),$counters, true)];
}
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<$n;$i++){
		if($input[$i]==$v&&$i<=$k+1)
			$count++;
	}
	return $count;
}
?>

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}
print_r($counters);
echo $input[array_search(max($counters),$counters)];
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<=$n;$i++){
		if($input[$i]==$v&&$i<=$k+1)
			$count++;
	}
	return $count;
}
?>

<?
$stdin = fopen('php://stdin', 'r');
$num = fgets($stdin);
$str = fgets($stdin);
$arr = array();
$t = explode(" ", $str);
$out = -1;
for($i = 0; $i < $num; $i++){
    if($arr[$t[$i]]) $arr[$t[$i]]++; else $arr[$t[$i]] = 1;
    if($arr[$out] < $arr[$t[$i]] || $out == -1) $out = $t[$i];
}

$stdout = fopen('php://stdout', 'w');
fwrite($stdout, $out);
fclose($stdout);
?>

<?php
$n = intval(fgets(STDIN));
$a = explode(' ', fgets(STDIN));
$likes=[];
$last_likes=[];
for ($i=0; $i<$n; $i++){
    $id = $a[$i];
    if(isset($likes[$id])){
        $likes[$id]++;
    }else{
        $likes[$id] = 1;
    }
    $last_likes[$id] = $i;
}
$max = 0;
$max_id = 0;
$last_like = 10000;
foreach($likes as $id => $count){
    if ($count >= $max && $last_likes[$id] < $last_like){
        $max = $count;
        $max_id = $id;
        $last_like = $last_likes[$id];
    }
}

echo $max_id."\n";

<?php
$n = intval(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));
$likes=[];
$last_likes=[];
for ($i=0; $i<$n; $i++){
    $id = $a[$i];
    if(isset($likes[$id])){
        $likes[$id]++;
    }else{
        $likes[$id] = 1;
    }
    $last_likes[$id] = $i;
}
//var_dump($likes, $last_likes);
$max = 0;
$max_id = 0;
$last_like = 10000;
foreach($likes as $id => $count){
    if ($count >= $max && $last_likes[$id] < $last_like){
        $max = $count;
        $max_id = $id;
        $last_like = $last_likes[$id];
    }
}

echo $max_id."\n";

<?php
$n = intval(fgets(STDIN));
$a = explode(' ', fgets(STDIN));
$likes=[];
for ($i=0; $i<$n;$i++){
    $id = $a[$i];
    if(isset($likes[$id])){
        $likes[$id]++;
    }else{
        $likes[$id] = 1;
    }
}
$max = 0;
$max_id = 0;
foreach($likes as $id => $count){
    if ($count > $max){
        $max = $count;
        $max_id = $id;
    }
}

echo $id;

<?php
$n = intval(fgets(STDIN));
$a = explode(' ', fgets(STDIN));
$likes=[];
for ($i=0; $i<$n;$i++){
    $id = $a[$i];
    if(isset($likes[$id])){
        $likes[$id]++;
    }else{
        $likes[$id] = 1;
    }
}
$max = 0;
$max_id = 0;
foreach($likes as $id => $count){
    if ($count > $max){
        $max = $count;
        $max_id = $id;
    }
}

echo $max_id;

<?php

$map = [];
fscanf(STDIN, '%d', $n);

$max = 0;
$maxNumber = 0;

$tests = fgets(STDIN);
$input = explode(' ', $tests);

foreach ($input as $number) {
    if (!isset($map[$number])) {
        $map[$number] = 0;
    }

    if ($max < $value = ++$map[$number]) {
        $max = $value;
        $maxNumber = $number;
    }
}

echo $maxNumber . PHP_EOL;

<?
fgets(STDIN);
$a = explode(' ', fgets(STDIN));
foreach($a as $b) $c[$b][] = 1;
foreach($c as $b => $e) $f[$b] = sizeof($c[$b]);
$e = max($f);
foreach($f as $g => $h) if($f[$g] < $e) unset($f[$g]);
$e = null;
foreach($f as $g => $h) $e[$g] = max(array_keys($a, $g));
print array_search(min($e), $e);


<?php

$input = STDIN;
#$input = fopen('b_input2.txt', 'r');

fscanf($input, "%d %d %d\n", $rows, $cols, $spiders_num);

$seen = array_pad(array(), $cols, 0);
for ($row = 0; $row < $rows; $row++) {
    $line = trim(fgets($input));
    $line = str_split($line);

    foreach ($line as $col => $direction) {
        if ($direction == '.' || $direction == 'D') {
            continue;
        }

        switch ($direction)
        {
        case 'U':
            if ($row % 2 == 0) {
                $seen[$col]++;
            }
            break;
        case 'L':
            $k = $col - $row;
            if ($k >= 0) {
                $seen[$k]++;
            }
            break;
        case 'R':
            $k = $col + $row;
            if ($k < $cols) {
                $seen[$k]++;
            }
            break;
        default:
            break;
        }
    }
}

echo join(' ', $seen);

<?php

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

$parkHeight = $line[0];
$parkWidth = $line[1];
$spiderNum = $line[2];

$result = array_fill(0, $parkWidth, 0);

for($y = 0; $y < $parkHeight; $y++){
    $line = trim(fgets(STDIN));
    for($x = 0; $x < $parkWidth; $x++){
        if($line[$x] == "R"){
            $result[$x + $y]++;
        }
        if($line[$x] == "L"){
            $result[$x - $y]++;
        }
        if($line[$x] == "U"){
            if($y%2 == 0){
                $result[$x]++;
            }
        }
    }
}

for($x = 0; $x < $parkWidth; $x++){
    echo $result[$x] . " ";
}
?>

<?php

$input = STDIN;
#$input = fopen('b_input2.txt', 'r');

fscanf($input, "%d %d %d\n", $rows, $cols, $spiders_num);

$spiders_U = $spiders_L = $spiders_R = array();
for ($row = 0; $row < $rows; $row++) {
    $line = trim(fgets($input));
    $line = str_split($line);

    foreach ($line as $col => $direction) {
        if ($direction == '.') {
            continue;
        }

        switch ($direction)
        {
        case 'U':
            $spiders_U[$col][] = $row;
            break;
        case 'L':
            $spiders_L[$row][] = $col;
            break;
        case 'R':
            $spiders_R[$row][] = $col;
            break;
        }
    }
}

$seen = array_pad(array(), $cols, 0);
for ($row = 1; $row < $rows; $row++) {
    calculate_state($row, $seen);
}

foreach ($GLOBALS['spiders_U'] as $col => &$spiders) {
    foreach ($spiders as $row) {
        if ($row > 1) {
            $seen[$col]++;
        }
    }
}

echo join(' ', $seen);

function calculate_state($min_row, &$seen) {
    foreach ($GLOBALS['spiders_R'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_R'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]++;

            if ($spiders[$k] >= count($seen)) {
                unset($spiders[$k]);
                continue;
            }

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }

    foreach ($GLOBALS['spiders_L'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_L'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]--;

            if ($spiders[$k] < 0) {
                unset($spiders[$k]);
                continue;
            }

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }
}

<?php

$input = STDIN;
#$input = fopen('b_input3.txt', 'r');

fscanf($input, "%d %d %d\n", $rows, $cols, $spiders_num);

$spiders_U = $spiders_L = $spiders_R = array();
for ($row = 0; $row < $rows; $row++) {
    $line = trim(fgets($input));
    $line = str_split($line);

    foreach ($line as $col => $direction) {
        if ($direction == '.') {
            continue;
        }

        switch ($direction)
        {
        case 'U':
            $spiders_U[$col][] = $row;
            break;
        case 'L':
            $spiders_L[$row][] = $col;
            break;
        case 'R':
            $spiders_R[$row][] = $col;
            break;
        }
    }
}

$seen = array_pad(array(), $cols, 0);
for ($row = 1; $row < $rows; $row++) {
    calculate_state($row, $seen);
}

foreach ($GLOBALS['spiders_U'] as $col => &$spiders) {
    $seen[$col] += count($spiders);
}

echo join(' ', $seen);

function calculate_state($min_row, &$seen) {
    foreach ($GLOBALS['spiders_R'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_R'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]++;

            if ($spiders[$k] >= count($seen)) {
                unset($spiders[$k]);
                continue;
            }

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }

    foreach ($GLOBALS['spiders_L'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_L'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]--;

            if ($spiders[$k] < 0) {
                unset($spiders[$k]);
                continue;
            }

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }
}

<?php

$input = STDIN;
#$input = fopen('b_input2.txt', 'r');

fscanf($input, "%d %d %d\n", $rows, $cols, $spiders_num);

$spiders_U = $spiders_D = $spiders_L = $spiders_R = array();
for ($row = 0; $row < $rows; $row++) {
    $line = trim(fgets($input));
    $line = str_split($line);

    foreach ($line as $col => $direction) {
        if ($direction == '.') {
            continue;
        }

        switch ($direction)
        {
        case 'U':
            $spiders_U[$col][] = $row;
            break;
        case 'D':
            $spiders_D[$col][] = $row;
            break;
        case 'L':
            $spiders_L[$row][] = $col;
            break;
        case 'R':
            $spiders_R[$row][] = $col;
            break;
        }
    }
}

$seen = array_pad(array(), $cols, 0);
for ($row = 1; $row < $rows; $row++) {
    $timer = 0;
    calculate_state($row, $seen);
//    for ($col = 0; $col < $cols; $col++) {
//        $seen[$col] += find_spiders($row, $col);
//    }

    $timer++;
}

echo join(' ', $seen);

function calculate_state($min_row, &$seen) {
    foreach ($GLOBALS['spiders_U'] as $col => &$spiders) {
        foreach ($spiders as $k => $spider) {
            $spiders[$k]--;

            if ($spiders[$k] < $min_row) {
                unset($spiders[$k]);
            } elseif ($spiders[$k] == $min_row) {
                $seen[$col]++;
            }
        }
    }

    foreach ($GLOBALS['spiders_D'] as $col => &$spiders) {
        foreach ($spiders as $k => $spider) {
            $spiders[$k]++;

            if ($spiders[$k] < $min_row) {
                unset($spiders[$k]);
            } elseif ($spiders[$k] == $min_row) {
                $seen[$col]++;
            }
        }
    }

    foreach ($GLOBALS['spiders_R'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_R'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]++;

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }

    foreach ($GLOBALS['spiders_L'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_L'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]--;

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }
}

function find_spiders($row, $col) {
    $spiders_U = $GLOBALS['spiders_U'];
    $spiders_D = $GLOBALS['spiders_D'];
    $spiders_R = $GLOBALS['spiders_R'];
    $spiders_L = $GLOBALS['spiders_L'];

    $num = 0;
    if (isset($spiders_U[$col])) {
        foreach ($spiders_U[$col] as $current_row) {
            if ($current_row == $row) {
                $num++;
            }
        }
    }

    if (isset($spiders_D[$col])) {
        foreach ($spiders_D[$col] as $current_row) {
            if ($current_row == $row) {
                $num++;
            }
        }
    }

    if (isset($spiders_R[$row])) {
        foreach ($spiders_R[$row] as $current_col) {
            if ($current_col == $col) {
                $num++;
            }
        }
    }

    if (isset($spiders_L[$row])) {
        foreach ($spiders_L[$row] as $current_col) {
            if ($current_col == $col) {
                $num++;
            }
        }
    }

    return $num;
}


<?php

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

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

while($n--){
    $line = explode(" ", rtrim(fgets($in)));
    $l = $line[0];
    $r = $line[1];
    $d = $line[2];

    if ($d < $l) {
        echo $d . "\n";
        continue;
    }

    echo $r - $r % $d + $d . "\n";

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

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

for ($i = 1; $i <= $iCount; $i++) {
    list($a1, $a2, $a3) = explode(' ', trim(fgets(STDIN)));

    if($a3 < $a1 || $a3 > $a2) {
        echo $a3 . "\n";
    } else {
         $b = floor( $a2 / $a3 ) + 1;
         echo ($a3 * $b)  . "\n";
    }
}

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

for ($i = 1; $i <= $iCount; $i++) {
    list($a1, $a2, $a3) = explode(' ', trim(fgets(STDIN)));

    if($a3 < $a1 || $a3 > $a2) {
        echo $a3;
    } else {
         $b = round( $a2 / $a3 ) + 1;
         echo $a3 * $b;
    }
}

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

for ($i = 1; $i <= $iCount; $i++) {
    list($a1, $a2, $a3) = explode(' ', trim(fgets(STDIN)));

    if($a3 < $a1 || $a3 > $a2) {
        echo $a3 . "\n";
    } else {
         $b = round( $a2 / $a3 ) + 1;
         echo ($a3 * $b)  . "\n";
    }
}

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

for ($i = 1; $i <= $iCount; $i++) {
    list($a1, $a2, $a3) = explode(' ', trim(fgets(STDIN)));

    if($a3 < $a1 || $a3 > $a2) {
        echo $a3;
    } else {
         $b = floor( $a2 / $a3 ) + 1;
         echo $a3 * $b;
    }
}

<?php

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

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

while($n--){
    $line = explode(" ", rtrim(fgets($in)));
    $l = $line[0];
    $r = $line[1];
    $d = $line[2];

    if ($d < $l) {
        echo $d . "\n";
        continue;
    }

    echo $r - $r % $d + $d . "\n";

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


<?php

$t = (int)fgets(STDIN);

while ($t--) {
    $input = explode(" ", fgets(STDIN));
    $a = (int)$input[0];
    $b = (int)$input[1];
    $diff = abs($a - $b);
    $q = intdiv($diff, 5);
    $rem = $diff % 5;
    print($q + (($rem > 2) ? (2) : ($rem ? 1 : 0)));
    print("\n");
}

<?php
    $j = trim(fgets(STDIN));
    for ($i = 0; $i < $j; $i++) {
        list($a, $b) = explode(" ", trim(fgets(STDIN)));
        if ($a === $b) {
            $n = 0;
        } elseif ($a > $b) {
            $n = $a - $b;
        } else {
            $n = $b - $a;
        }
        echo process($n) . "\n";
    }

    function process($n, $s = 0) {
        if ($n == 0) {
            return $s;
        }
        if ($n >= 5) {
            $s += floor($n/5);
            $k = $n%5;
            if ($k != 0) {
                return process($k, $s);
            } else {
                return $s;
            }
        } elseif($n >= 2) {
            $s += floor($n/2);
            $k = $n%2;
            if ($k != 0) {
                return process($k, $s);
            } else {
                return $s;
            }
        } else {
            return $s + 1;
        }
    }
?>

<?php
$n = intval(fgets(STDIN));
$i = 0;
while($i < $n)
{
    $volumes = array_map("toint", explode(" ", fgets(STDIN)));
    $current = $volumes[0];
    $necessary = $volumes[1];
    $count = intdiv(abs($current - $necessary), 5);
    $z = 1;
    if($current > $necessary) $z = -1;
    $current = $current + 5 * $count * $z;
    while($current != $necessary)
    {
        $current = getCloser($current, $necessary);
        $count++;
    }
    echo $count."\n";

    $i++;
}

function getCloser($current, $necessary)
{
    $availiable = array(-5, -2, -1, 1, 2, 5);
    $diff = $current - $necessary;
    if(array_search($diff, $availiable))
        return $necessary;

    $minDiff = abs($diff);
    $minDiffIndex = 0;
    foreach ($availiable as $key => $value) {
        if(abs($diff + $value) < $minDiff && $current + $value >= 0)
        {
            $minDiffIndex = $key;
            $minDiff = abs($diff + $value);
        }

    }
    return $current + $availiable[$minDiffIndex];
}
function toint($num)
{
    return intval($num);
}
?>

<?php

$t = (int)fgets(STDIN);

while ($t--) {
    $input = explode(" ", fgets(STDIN));
    $a = (int)$input[0];
    $b = (int)$input[1];
    $diff = abs($a - $b);
    $q = intdiv($diff, 5);
    $rem = $diff % 5;
    print($q + (($rem > 2) ? (2) : ($rem ? 1 : 0)));
}


<?php
$t=readline();
while($t--){
    $n=readline();
    $s=readline();
    // while(preg_replace("\(\)","",$s)!=$s);
    while(preg_match("(\(\))",$s)){
     $s=preg_replace("(\(\))","",$s);
    }
    // echo $s;
    echo strlen($s)/2;
    echo"\n";
}

?>

<?php
$tc=readline();
while($tc--)
{
  fscanf(STDIN,"%d",$len);
  $str=trim(fgets(STDIN));
  $sum=0;
  for ($i=0; $i <$len ; $i++)
   {
	  	  if($str[$i]=='(')
	  	  	$sum++;
	  	  else
	  	  {
	  	  	if ($sum>0&&$str[$i]==')')

	  	  	$sum--;
	  	  }

   }
   echo "$sum\n";
}

<?php
$tc=readline();
while($tc--)
{
  fscanf(STDIN,"%d",$len);
  $str=trim(fgets(STDIN));
  $sum=0;
  for ($i=0; $i <$len ; $i++)
   {
	  	  if($str[$i]=='(')
	  	  	$sum++;
	  	  elseif ($sum>0&&$str[$i]==')')
	  	  $sum--;

   }
   echo "$sum\n";
}

<?php
$tc=readline();
while($tc--)
{
  $len=readline();
  $str=trim(fgets(STDIN));
  $sum=0;
  for ($i=0; $i <$len ; $i++)
   {
	  	  if($str[$i]=='(')
	  	  	$sum++;
	  	  else
	  	  {
	  	  	if ($sum>0&&$str[$i]==')')

	  	  	$sum--;
	  	  }

   }
   echo "$sum\n";
}

<?php
$tc=readline();
while($tc--)
{
  $len=readline();
  $str=trim(fgets(STDIN));
  $sum=0;
  for ($i=0; $i <$len ; $i++)
   {
	  	  if($str[$i]=='(')
	  	  	$sum++;
	  	  elseif ($sum>0&&$str[$i]==')')
	  	  {
	  	  	$sum--;
	  	  }

   }
   echo "$sum\n";
}

<?php
$tc=readline();
while($tc--)
{
  $len=readline();
  $str=trim(fgets(STDIN));
  $sum=0;
  for ($i=0; $i <$len ; $i++)
   {
	  	  if($str[$i]=='(')
	  	  	$sum++;
	  	  elseif ($sum>0&&$str[$i]==')')
	  	  {
	  	  	$sum--;
	  	  }

   }
   echo "ans=$sum\n";
}


 <?php
$in=fopen("input.txt","r");
$out=fopen("output.txt","w");
function fnss($sd,&$k=array(),$q,$dd) {
	++$q;
	$ss=ceil($sd/2);
	for($i=1; $ss>=$i; ++$k[$q]['kol'],++$i) $k[$q]['team1'] .= " ".($i+$dd);
	if($ss>1) {
		fnss($ss,$k,$q,$dd);
		$sd -= $ss; $dd += $ss;
		fnss($sd,$k,$q,$dd);
	}
}
$sd=fgets($in);
fnss($sd,$k,0,0);
fwrite ($out, count($k)."\n");
foreach ($k as $value) fwrite($out, $value['kol'].$value['team1']."\n");
fclose($in); fclose($out);

 <?php
$in=fopen("input.txt","r");
$out=fopen("output.txt","w");

function fnss($sd,&$k=array(),$q=0,$dd=0){
	++$q;	$ss=ceil($sd/2);
	For($i=1; $ss>=$i; ++$k[$q]['kol'],++$i) $k[$q]['team1'] .= " ".($i+$dd);
	if($ss>1){
		fnss($ss,$k,$q,$dd);
		$sd -= $ss; $dd += $ss;
		fnss($sd,$k,$q,$dd);
	}
	if($k['all']<$q)$k['all']=$q;
}

$sd=fgets($in);
fnss($sd,$k);

fwrite ($out, trim($k['all'])."\n");
unset($k['all']);
foreach ($k as $key => $value) {
	 fwrite($out, $value['kol'].$value['team1']."\n");
}
fclose($in);fclose($out);

 <?php
$in=fopen("input.txt","r");
$out=fopen("output.txt","w");

function fnss($sd,&$k=array(),$q=0,$dd=0){
	++$q;	$ss=ceil($sd/2);
	For($i=1; $ss>=$i; ++$k[$q]['���'],++$i) $k[$q]['�������1'] .= " ".($i+$dd);
	if($ss>1){
		fnss($ss,$k,$q,$dd);
		$sd -= $ss; $dd += $ss;
		fnss($sd,$k,$q,$dd);
	}
	if($k['�����']<$q)$k['all']=$q;
}

$sd=fgets($in);
fnss($sd,$k);

fwrite ($out, trim($k['all'])."\n");
unset($k['all']);
foreach ($k as $key => $value) {
	 fwrite($out, $value['���'].' '. $value['�������1']."\n");
}
fclose($in);fclose($out);

 <?php
$in=fopen("input.txt","r");
$out=fopen("output.txt","w");

function fnss($sd,&$k=array(),$q=0,$dd=0){
	++$q;	$ss=ceil($sd/2);
	For($i=1; $ss>=$i; ++$k[$q]['kol'],++$i) $k[$q]['team1'] .= " ".($i+$dd);
	if($ss>1){
		fnss($ss,$k,$q,$dd);
		$sd -= $ss; $dd += $ss;
		fnss($sd,$k,$q,$dd);
	}
	if($k['�����']<$q)$k['all']=$q;
}

$sd=fgets($in);
fnss($sd,$k);

fwrite ($out, trim($k['all'])."\n");
unset($k['all']);
foreach ($k as $key => $value) {
	 fwrite($out, $value['kol'].$value['team1']."\n");
}
fclose($in);fclose($out);


<?php
# 1141D
$start = microtime(1);
[$itemsCount] = fscanf(STDIN, '%u');

$pairs = [];
$result = 0;
$leftItems = $rightItems = [
    'a' => [],'b' => [],'c' => [],'d' => [],'e' => [],'f' => [],'g' => [],'h' => [],'i' => [],'j' => [],'k' => [],
    'l' => [],'m' => [],'n' => [],'o' => [],'p' => [],'q' => [],'r' => [],'s' => [],'t' => [],'u' => [],'v' => [],
    'w' => [],'x' => [],'y' => [],'z' => [], '?' => [],
];
$keys = array_keys($leftItems);

$left = fgets(STDIN);
$right = fgets(STDIN);
for ($i = 0, $j = 1; $i < $itemsCount; $i++, $j++) {
    $leftItems[$left[$i]][] = $j;
    $rightItems[$right[$i]][] = $j;
}
unset($left, $right);
foreach ($keys as $key) {
    while ($leftItems[$key] !== [] && $rightItems[$key] !== []) {
        $result++;
        $pairs[] = [array_pop($leftItems[$key]) , array_pop($rightItems[$key])];
    }
    while ($leftItems[$key] !== [] && $rightItems['?'] !== []) {
        $result++;
        $pairs[] = [array_pop($leftItems[$key]) , array_pop($rightItems['?'])];
    }
    while ($leftItems['?'] !== [] && $rightItems[$key] !== []) {
        $result++;
        $pairs[] = [array_pop($leftItems['?']) , array_pop($rightItems[$key])];
    }
}
echo $result . PHP_EOL;
foreach($pairs as $pair) {
    echo $pair[0] . ' ' . $pair[1] . PHP_EOL;
}

<?php

fscanf(STDIN, "%d\n", $number);
$line1 = trim(fgets(STDIN));
$line2 = trim(fgets(STDIN));

$arr1 = str_split($line1);
$arr2 = str_split($line2);

$aa1 = [];$aa2 = [];
foreach($arr1 as $key=>$char){
    $aa1[$char][]=$key;
}
foreach($arr2 as $key=>$char){
    $aa2[$char][]=$key;
}
$ans=[];
foreach($aa1 as $key=>$value){

    if($key!='?'){
            while(sizeof($aa1[$key])>0 && isset($aa2[$key]) and sizeof($aa2[$key])>0){
            $ans[array_pop($aa1[$key])+1]=array_pop($aa2[$key]) + 1;
        }
    }
}
foreach($aa1 as $key=>$value){

    if($key!='?'){
            while(sizeof($aa1[$key])>0 && isset($aa2['?']) and sizeof($aa2['?'])>0){
            $ans[array_pop($aa1[$key])+1]=array_pop($aa2['?']) + 1;
        }
    }
}
foreach($aa2 as $key=>$value){

    if($key!='?'){
            while(sizeof($aa2[$key])>0 && isset($aa1['?']) and sizeof($aa1['?'])>0){
            $ans[array_pop($aa1['?']) + 1]=array_pop($aa2[$key])+1;
        }
    }
}
foreach($aa1 as $key=>$value){

    if($key=='?'){
            while(sizeof($aa1[$key])>0 && isset($aa2[$key]) and sizeof($aa2[$key])>0){
            $ans[array_pop($aa1[$key])+1]=array_pop($aa2[$key]) + 1;
        }
    }
}
echo sizeof($ans); echo ("\n");
foreach($ans as $key=>$value){
    echo ($key);echo (" ");
    echo ($value);echo ("\n");
}
?>

<?php
declare(strict_types=1);
# 1141D
$start = microtime(true);
[$itemsCount] = fscanf(STDIN, '%u');

$pairs = [];
$result = 0;
$leftItems = $rightItems = [
    'a' => [],'b' => [],'c' => [],'d' => [],'e' => [],'f' => [],'g' => [],'h' => [],'i' => [],'j' => [],'k' => [],
    'l' => [],'m' => [],'n' => [],'o' => [],'p' => [],'q' => [],'r' => [],'s' => [],'t' => [],'u' => [],'v' => [],
    'w' => [],'x' => [],'y' => [],'z' => [], '?' => [],
];
$keys = array_keys($leftItems);

$left = fgets(STDIN);
$right = fgets(STDIN);
for ($i = 0, $j = 1; $i < $itemsCount; $i++, $j++) {
    $leftItems[$left[$i]][] = $j;
    $rightItems[$right[$i]][] = $j;
}
unset($left, $right);

foreach ($keys as $key) {
    while ($leftItems[$key] !== [] && $rightItems[$key] !== []) {
        $result++;
        $pairs[] = array_pop($leftItems[$key]) . ' ' . array_pop($rightItems[$key]);
    }
    while ($leftItems[$key] !== [] && $rightItems['?'] !== []) {
        $result++;
        $pairs[] = array_pop($leftItems[$key]) . ' ' . array_pop($rightItems['?']);
    }
    while ($leftItems['?'] !== [] && $rightItems[$key] !== []) {
        $result++;
        $pairs[] = array_pop($leftItems['?']) . ' ' . array_pop($rightItems[$key]);
    }
}
print $result . PHP_EOL . implode(PHP_EOL, $pairs);


<?php
$numGears = trim(fgets(STDIN));
$activeTeeth = trim(fgets(STDIN));
$teeth = explode(' ', $activeTeeth);

if ($numGears == 1)
{
    echo 'YES';
    exit;

}
else
{
    $correctSequence = array();

    for ($i = 0; $i < $numGears; $i++)
    {
        $correctSequence[$i] = (int)$i;
    }

    $k = 0;
    while(true)
    {
        if ($teeth[0] == 0)
        {
            for ($j = 1; $j < $numGears; $j++)
            {
                if ($teeth[$j] != $j)
                {
                    echo 'No';
                    exit;
                }
            }

            echo 'Yes';
            exit;
        }

        for ($i = 0; $i < $numGears; $i++)
        {
            if ($i % 2 == 0)
            {
                if (array_key_exists($teeth[$i] + 1, $correctSequence))
                {
                    $teeth[$i] = $correctSequence[$teeth[$i] + 1];
                }
                else
                {
                    $teeth[$i] = $correctSequence[0];
                }
            }
            else
            {
                if (array_key_exists($teeth[$i] - 1, $correctSequence))
                {
                    $teeth[$i] = $correctSequence[$teeth[$i] - 1];
                }
                else
                {
                    $teeth[$i] = $correctSequence[$numGears - 1];
                }
            }
        }
    }
}


<?php

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

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

list($n, $k) = explode(' ', $s);

$n = (int)$n;
$k = (int)$k;

$a = explode(" ",trim(fgets($f)));

sort($a);

$min = $a[0];

$count = 0;

foreach ($a as $item) {

    $item = $item - $min;

    if (($item % $k) == 0) {
        $count += $item / $k;
    } else {
        $count = -1;
        break;
    }
}

echo $count."\n";

fclose($f);

<?php

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

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

list($n, $k) = explode(' ', $s);

$n = (int)$n;
$k = (int)$k;

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

sort($a);

$min = $a[0];

$a = array_map(function($item) use ($min){
    return (int)$item - $min;
}, $a);

$count = 0;

foreach ($a as $item) {
    if (($item % $k) == 0) {
        $count += $item / $k;
    } else {
        $count = -1;
        break;
    }
}

echo $count."\n";

fclose($f);

<?php

//$f = fopen('taskA.txt', 'r');

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

$s = fgets($f);

list($n, $k) = explode(' ', $s);

$n = (int)$n;
$k = (int)$k;

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

sort($a);

$min = $a[0];

$a = array_map(function($item) use ($min){
    return (int)$item - $min;
}, $a);

$count = 0;

foreach ($a as $item) {
    if (($item % $k) == 0) {
        $count += $item / $k;
    } else {
        $count = -1;
        break;
    }
}

echo $count;

fclose($f);

<?php

//$f = fopen('taskA.txt', 'r');
$f =STDIN;

$s = fgets($f);

list($n, $k) = explode(' ', $s);

$n = (int)$n;
$k = (int)$k;

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

sort($a);

$min = $a[0];

$a = array_map(function($item) use ($min){
    return (int)$item - $min;
}, $a);

$count = 0;

foreach ($a as $item) {
    if (($item % $k) == 0) {
        $count += $item / $k;
    } else {
        $count = -1;
        break;
    }
}

echo $count;

<?php

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

$s = fgets($f);

list($n, $k) = explode(' ', $s);

$n = (int)$n;
$k = (int)$k;

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

sort($a);

$min = $a[0];

$count = 0;

foreach ($a as $item) {

    $item = $item - $min;

    if (($item % $k) == 0) {
        $count += $item / $k;
    } else {
        $count = -1;
        break;
    }
}

echo $count."\n";

fclose($f);

<?php

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

$s = fgets($f);

list($n, $k) = explode(' ', $s);

$n = (int)$n;
$k = (int)$k;

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

sort($a);

$min = $a[0];

$count = 0;

foreach ($a as $item) {

    $item = $item - $min;

    if (($item % $k) == 0) {
        $count += $item / $k;
    } else {
        $count = -1;
        break;
    }
}

echo $count."\n";

fclose($f);

<?php

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

$s = fgets($f);

list($n, $k) = explode(' ', $s);

$n = (int)$n;
$k = (int)$k;

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

sort($a);

$min = $a[0];

$a = array_map(function($item) use ($min){
    return (int)$item - $min;
}, $a);

$count = 0;

foreach ($a as $item) {
    if (($item % $k) == 0) {
        $count += $item / $k;
    } else {
        $count = -1;
        break;
    }
}

echo $count."\n";

fclose($f);


<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$S = $Scanner->Scan();

	$temp = $S;
	$Slen = strlen($temp);
	if (strpos($temp, ".") === 0 || strrpos($temp, ".") === $Slen - 1) print("NO");
	elseif (substr_count($temp, ".") === 0) print("NO");
	else {
		$flag = "";
		$temp_array = explode(".", $temp);
		$len = count($temp_array);
		if (strlen($temp_array[0]) > 8 || strlen($temp_array[$len - 1]) > 3) $flag = "NO";
		else {
			if ($len === 2) {
				$ans[0] = $temp_array[0]. ".". $temp_array[$len - 1];
			} else {
				$ans[0] .= $temp_array[0];
				for ($i = 1; $i < $len - 1; $i++) {
					$l = strlen($temp_array[$i]);
					if ($l > 11 || $l < 2) {
						$flag = "NO";
						break;
					}

					if ($l <= 11 && $l >= 4) {
						$ans[$i - 1] .= ".". substr($temp_array[$i], 0, 3);
						$ans[$i] .= substr($temp_array[$i], 3);
					} elseif ($l <= 4) {
						$ans[$i - 1] .= ".". substr($temp_array[$i], 0, 1);
						$ans[$i] .= substr($temp_array[$i], 1);
					}
				}
				$ans[$len - 2] .= ".". $temp_array[$len - 1];
			}
		}
		if ($flag === "NO") {
			print("NO");
		} else {
			print("YES");
			print("\n");
			for ($i = 0; $i < $len - 1; $i++) {
				print($ans[$i]);
				if ($i !== $len - 2) print("\n");
			}
		}
	}
	$Scanner->Close();
}

class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);
		$contents = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	public function Scan(){
		return $this->Scanners[$this->Id++];
	}

	public function Close(){
		fclose($this->Stream);
	}
}

?>

<?php

function res_no() {
  print "NO\n";
  exit;
}

function res_yes($names) {
  print "YES\n";
  print join("\n", $names) . "\n";
  exit;
}

function _split($part) {
  $len = strlen($part);
  if ($len > 11 || $len < 2) {
    res_no();
  }

  $ext_len = $len < 6 ? 1 : 3;

  return array(
    substr($part, 0, $ext_len),
    substr($part, $ext_len),
  );
}

$input = trim(fgets(STDIN));
$names = array();

$parts = explode('.', $input);
if (!count($parts)) {
  res_no();
}

$name1 = array_shift($parts);
$ext_last = array_pop($parts);

if (strlen($name1) > 8 || strlen($name1) < 1 || strlen($ext_last) > 3 || strlen($ext_last) < 1) {
  res_no();
}

foreach ($parts as $part) {
  list($ext, $name) = _split($part);
  $names[] = $name1 .'.'. $ext;
  $name1 = $name;
}

$names[] = $name1 .'.'. $ext_last;

res_yes($names);

<?php

function res_no() {
  print "NO\n";
  exit;
}

function res_yes($names) {
  print "YES\n";
  print join("\n", $names) . "\n";
  exit;
}

function _split($part) {
  $len = strlen($part);
  if ($len > 11 || $len < 1) {
    res_no();
  }

  $ext_len = $len < 6 ? 1 : 3;

  return array(
    substr($part, 0, $ext_len),
    substr($part, $ext_len),
  );
}

$input = trim(fgets(STDIN));
$names = array();

$parts = explode('.', $input);
if (!count($parts)) {
  res_no();
}

$name1 = array_shift($parts);
$ext_last = array_pop($parts);

if (strlen($name1) > 8 || strlen($name1) < 1 || strlen($ext_last) > 3 || strlen($ext_last) < 1) {
  res_no();
}

foreach ($parts as $part) {
  list($ext, $name) = _split($part);
  $names[] = $name1 .'.'. $ext;
  $name1 = $name;
}

$names[] = $name1 .'.'. $ext_last;

res_yes($names);

<?php

function res_no() {
  print "NO\n";
  exit;
}

function res_yes($names) {
  print "YES\n";
  print join("\n", $names) . "\n";
  exit;
}

function _split($part) {
  $len = strlen($part);
  if ($len > 11 || $len < 1) {
    res_no();
  }

  $ext_len = $len < 6 ? 1 : 3;

  return array(
    substr($part, 0, $ext_len),
    substr($part, $ext_len),
  );
}

$input = trim(fgets(STDIN));
$names = array();

$parts = explode('.', $input);
if (!count($parts)) {
  res_no();
}

$name1 = array_shift($parts);
$ext_last = array_pop($parts);

if (strlen($name1) > 8 || strlen($name1) < 1 || strlen($ext_last) > 3 || strlen($ext_last) < 1) {
  res_no();
}

foreach ($parts as $part) {
  list($ext, $name) = _split($part);
  $names[] = $name1 .'.'. $ext;
  $name1 = $name;
}

$names[] = $name .'.'. $ext_last;

res_yes($names);


<?php

function nextInt() {
    fscanf(STDIN, "%d\n", $x);
    return $x;
}

function nextArray() {
    return explode(" ", trim(fgets(STDIN)));
}

function solve() {
    $N = nextInt();

    $a = array();
    foreach (nextArray() as $x) {
        $a[$x] = true;
    }
    for ($i = 1; ; $i++) {
        if (!$a[$i]) break;
    }
    print $i;
}

solve();

<?
$n=trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
for($i=1;$i<3200;$i++){
    if(!in_array($i,$arr)){
        $num=$i;
        break;
    }
}
echo $num;
?>

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

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

$nums=explode(" ", $lines[1]);
sort($nums);
$res=0;
if (min($nums)!=1)
    $res=1;

$i=0;
while ($res==0)
{
    if ($nums[$i]+1!=@$nums[$i+1])
        $res=$nums[$i]+1;
    $i++;
}
echo $res;
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
array_unshift($b, " ");
unset($b[0]);
for($x = 1; $x <= 3000; $x++)
{
    if(array_search($x, $b) == false)
    {
        break;
    }
}
print $x;
?>

<?php
$n=rtrim(fgets(STDIN));
$ids=explode(' ',rtrim(fgets(STDIN)));
sort($ids);
$prev=0;
foreach ($ids as $id) {
  if ($prev+1!=$id) {
    $new_id=$prev+1;
    echo "$new_id\n";
    exit(0);
  }
  $prev=$id;
}
$new_id=$prev+1;
echo "$new_id\n";

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

    $n = fgets($stdin);
    $numbers = explode(" ", preg_replace("/\s+/", " ", fgets($stdin)));
    sort($numbers);

    $min_abs=1;
    for($i=0;$i<=$n;++$i){
        if($numbers[$i] == $min_abs) $min_abs +=1;
    }
    fputs($stdout, $min_abs);
?>

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

function eratosphen($n) {
    $isPrime = array();
    for ($i = 0; $i < $n; $i++) {
        $isPrime[$i] = 1;
    }

    $isPrime[0] = 0;
    $isPrime[1] = 0;

    for ($i = 2; $i * $i < $n; $i++)
        if ($isPrime[$i])
            for ($j = $i * $i; $j < $n; $j += $i)
                $isPrime[$j] = 0;

    $simple = array();
    for ($i = 0; $i < $n; $i++) {
        if ($isPrime[$i] == 1) {
            $simple[] = $i;
        }
    }

    echo implode(', ', $simple);
}

$stdin = stdin();
/****************************************************** Solving block *****************************************************/
$n = g();
$a = explode(' ', g());

sort($a);

if($a[0] > 1) {
    echo 1;
} else {
    array_shift($a);
    $test = 2;
    foreach($a as $item) {
        if($test == $item) {
            $test++;
        } else {
            break;
        }
    }

    echo $test;
}
?>

<?php

fgets(STDIN);
$a = array();
array_map(function($s) {
	global $a;
	$a[intval($s)] = 1;
}, explode(' ', fgets(STDIN)));
$ans = 1;
while (array_key_exists($ans, $a))
	$ans++;
printf("%d\n", $ans);

?>

<?php

$line0 = trim(fgets(STDIN));
$line1 = trim(fgets(STDIN));

$nums = explode(' ', $line1);

sort($nums);

for($i = 0; $i < count($nums); $i++) {
    if ($nums[0] != 1) {
        $result = 1;
        break;
    }
    if ($nums[$i] + 1 != $nums[$i + 1]) {
        $result = $nums[$i] + 1;
        break;
    }
}

echo $result;

?>

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

    $n = fgets($stdin);
    $numbers = explode(" ", fgets($stdin));

    $min_abs=1;
    for($i=0;$i<$n;++$i){
        if($numbers[$i] == $min_abs) $min_abs +=1;
    }
    fputs($stdout, $min_abs);
?>

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

    $n = fgets($stdin);
    $numbers = explode(" ", preg_replace("/\s+/", " ", fgets($stdin)));
    sort($numbers);

    $min_abs=1;
    for($i=0;$i<$n;++$i){
        if($numbers[$i] == $min_abs) $min_abs +=1;
    }
    fputs($stdout, $min_abs);
?>

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

    $n = fgets($stdin);
    $numbers = fgets($stdin);
    $numbers = preg_replace("/\s/", "", $numbers);

    $min_abs=1;
    for($i=0;$i<$n;++$i){
        if($numbers[$i] == $min_abs) $min_abs +=1;
    }
    fputs($stdout, $min_abs);
?>

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

    $n = fgets($stdin);
    $numbers = explode(" ", fgets($stdin));
    sort($numbers);

    $min_abs=1;
    for($i=0;$i<$n;++$i){
        if($numbers[$i] == $min_abs) $min_abs +=1;
    }
    fputs($stdout, $min_abs);
?>

<?php
    $stdout = fopen('php://stdout', 'w');
    //fputs(STDOUT, "Vhodnie dannie:  ");
    $h = fopen('php://stdin', 'r');
    $str = trim(fgets($h));

    $n=strlen($str);
    $run=true;

    for($i=0; $i<$n; $i++)
    {
        if (($str[$i]!=')')&&($str[$i]!='('))
        {
            $run=false;
        }
    }
    if (($n>=0)&&($n<=exp(6*log(10))) && $run)
    {
    $stat = array('max' => 0, 'count' => 1);

    $ind = 0;

    $currentCount = 0;
    $bracketsLength = 0;

    while($ind < strlen($str))
    {
        if($str[$ind] == '(')
        {
            $currentCount++;
            $bracketsLength++;
        }
        elseif($str[$ind] == ')')
        {
            $currentCount--;

            if($currentCount >= 0)
            {
                $bracketsLength++;
            }
        }

        if($currentCount == 0)
        {
            if($stat['max'] < $bracketsLength)
            {
                $stat['max'] = $bracketsLength;
                $stat['count'] = 1;
            }
            elseif($stat['max'] == $bracketsLength)
            {
                $stat['count']++;
            }

            $bracketsLength = 0;
        }
        elseif($currentCount < 0)
        {
            $currentCount = 0;
            $bracketsLength = 0;
        }

        $ind++;
    }
        $st=$stat['max'];
        $k=$stat['count'];
        fputs(STDOUT, "$st");
        fputs(STDOUT, "; ");
        fputs(STDOUT, "$k");
        fputs(STDOUT, ";");
}
?>

<?php
$stdout = fopen('php://stdout', 'w');
fputs(STDOUT, "Vhodnie dannie:  ");
$h = fopen('php://stdin', 'r');
$n = trim(fgets($h));
$s = trim(fgets($h));
$len = strlen($s);
if ($n>=1 && $n<=3000)
	{
		$f=true;
for ($i=1; $i<=$n-1; $i++)
{
	$r=stripos($s,' ');
	$mas[$i]=substr($s, 0, $r);
	if ($mas[$i]<1 || $mas[$i]>3000)
	{$f=false;}
	$s=substr($s, $r+1, $len-$r-1);
	}
	$mas[$n]=$s;
	if ($mas[$n]<1 || $mas[$n]>3000)
	{$f=false;}
	if ($f)
	{
fputs(STDOUT, "Vihodnie dannie:  ");
	$k=1; $f=false;
	while ($f==false)
		{
		$f1=true;
	for ($i=1; $i<=$n; $i++)
	{
		if ($k==$mas[$i])
			{
				 $f1=false;
				}
		}
		if (!$f1){$k++;}
		else {$f=true;}
		}
		fputs(STDOUT, "$k");
	}
	else
	{fputs(STDOUT, "����a ������ ���� �� ��������� 1<=n<=3000");
	}
}
	else
	{fputs(STDOUT, "����� ������ ���� �� ��������� 1<=n<=3000");
		}
?>

<?
$n=trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
for($i=1;$i<3000;$i++){
    if(!in_array($i,$arr)){
        $num=$i;
        break;
    }
}
echo $num;
?>

<?
$n=trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
for($i=1;$i<2999;$i++){
    if(!in_array($i,$arr)){
        $num=$i;
        break;
    }
}
echo $num;
?>

<?
$n=trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
for($i=1;$i<=3000;$i++){
    if(!in_array($i,$arr)){
        $num=$i;
        break;
    }
}
echo $num;
?>


<?php
	$t = trim(fgets(STDIN));
	while ($t--) {
		list($n, $k1, $k2) = explode(" ", trim(fgets(STDIN)));
		list($w, $b) = explode(" ", trim(fgets(STDIN)));

		if (((min($k1, $k2) + floor(abs($k2 - $k1)/2)) >= $w) && ((floor(abs($k1 - $k2)/2) + min($n - $k1, $n - $k2)) >= $b)) {
			print "YES\n";
		} else {
			print "NO\n";
		}
	}
?>

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

$t = trim(fgets($file));
for ($i = 0; $i < $t; $i++) {
  list($n, $k1, $k2) = explode(" ", trim(fgets($file)));
  list($w, $b) = explode(" ", trim(fgets($file)));

  $c = 2 * $n;
  $wh = $k1 + $k2;
  $bl = $c - $wh;

  if ($wh >= $w * 2 && $bl >= $b * 2) {
    echo 'YES'.PHP_EOL;
  } else {
    echo 'NO'.PHP_EOL;
  }
}

?>

<?php
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $k1, $k2) = IO::arr();
    list($w, $b) = IO::arr();

    $w1 = (int)$k1 + (int)$k2;
    $b1 = (2 * (int)$n) - $w1;
    if (floor($w1 / 2) >= (int)$w && floor($b1 / 2) >= (int)$b) {
        IO::line('YES');
    } else {
        IO::line('NO');
    }

}


<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $n = intval(trim(fgets(STDIN))) ;

        $p = 0 ;
        $c = 0 ;
        $f = false ;

        for($i = 0; $i < $n; $i ++)
        {
            $in_str = explode(" ", trim(fgets(STDIN))) ;

            if($f) continue ;

            $tp = intval($in_str[0]) ;
            $tc = intval($in_str[1]) ;

            if($tp < $tc) $f = true ;
            else
            {
                if($tp < $p) $f = true ;
                if($tc < $c) $f = true ;

                if($tp - $p < $tc - $c) $f = true ;
            }
            list($p, $c) = array($tp, $tc) ;
        }
        echo $f ? "NO\n" : "YES\n" ;
    }
?>

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

$check = function(){
	$p1 = 0; $c1 = 0;
	$res = true;
	for($n = intval(fgets(STDIN)); $n > 0; $n--){

		list($p, $c) = explode(' ', trim(fgets(STDIN)));
		if($p < $c) {$res = false;}
		if($p < $p1) {$res = false;}
		if($c < $c1) {$res = false;}
		if($c - $c1 > $p - $p1) {$res = false;}

		$p1 = $p; $c1 = $c;

	}
	return $res;
};

for($t = intval(fgets(STDIN)); $t > 0; $t--){
	echo ($check() ? 'YES' : 'NO') . "\n";
}

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

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     list($c, $d) = explode(" ", trim(fgets(STDIN)));
     $e = 0;
     if($d > $c)
     {
          print "NO\n";
          for($y = 1; $y < $b; $y++)
          {
               list($f, $g) = explode(" ", trim(fgets(STDIN)));
          }
     }
     elseif($b == 1)
     {
          print "YES\n";
     }
     else
     {
          for($y = 1; $y < $b; $y++)
          {
               list($f, $g) = explode(" ", trim(fgets(STDIN)));
               if(($f < $c) || ($g < $d) || ($f < $g))
               {
                    $e = 1;
               }
               elseif(($f == $c) && ($g > $d))
               {
                    $e = 1;
               }
               else
               {
                    $c = $f;
                    $d = $g;
               }
          }
          if($e == 0)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
}
?>

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

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $n = intval(trim(fgets(STDIN))) ;

        $p = 0 ;
        $c = 0 ;
        $f = false ;

        for($i = 0; $i < $n; $i ++)
        {
            $in_str = explode(" ", trim(fgets(STDIN))) ;

            if($f) continue ;

            $tp = intval($in_str[0]) ;
            $tc = intval($in_str[1]) ;

            if($tp < $tc) $f = true ;
            else
            {
                if($tp < $p) $f = true ;
                if($tc < $c) $f = true ;
            }
            list($p, $c) = array($tp, $tc) ;
        }
        echo $f ? "NO\n" : "YES\n" ;
    }
?>


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array_sum($b);
rsort($c);
$e = $c[0] + $c[1];
if($e >= $d)
{
     print "YES";
}
else
{
     print "NO";
}
?>

<?php
  //CF 892A
  fscanf(STDIN, "%d", $n);
  function cmp($a, $b) {
    if ($a == $b) return 0;
    return ($a > $b) ? -1 : 1;
  }
  $a_ = explode(" ", fgets(STDIN));
  $b_ = explode(" ", fgets(STDIN));
  $a = array();
  $b = array();
  for ($i = 0; $i < $n; $i++) {
    $a[$i] = intval($a_[$i]);
    $b[$i] = intval($b_[$i]);
  }
  usort($b, "cmp");
  //fprintf(STDOUT, "" . array_sum($a) . " " . array_sum(array_slice($b, 0, 2)) . "\n");
  fprintf(STDOUT, array_sum($a) <= array_sum(array_slice($b, 0, 2)) ? "YES" : "NO");
?>

<?php
  //CF 892A
  fscanf(STDIN, "%d", $n);
  function cmp($a, $b) {
    if ($a == $b) return 0;
    return ($a > $b) ? -1 : 1;
  }
  $a = explode(" ", fgets(STDIN));
  $b = explode(" ", fgets(STDIN));
  for ($i = 0; $i < $n; $i++) {
    $a[$i] = intval($a[$i]);
    $b[$i] = intval($b[$i]);
  }
  usort($b, "cmp");
  //fprintf(STDOUT, "" . array_sum($a) . " " . array_sum(array_slice($b, 0, 2)) . "\n");
  fprintf(STDOUT, array_sum($a) <= array_sum(array_slice($b, 0, 2)) ? "YES" : "NO");
?>

<?php
$STDIN="php://stdin";
$STDOUT="php://stdout";
$read = fopen($STDIN, "r");
$write = fopen($STDOUT, "w");

$ns = trim(fgets($read));
$vols=  explode(" ", trim(fgets($read)));
$caps=  explode(" ", trim(fgets($read)));

$sum= array_sum($vols);

 rsort($caps);
$output= "NO";
if($ns >= 2){
    $cap_sum= $caps[0]+$caps[1];
    if($sum<=$cap_sum){
        $output="YES";
    }
}

fwrite($write, $output.PHP_EOL);
fclose($read);
fclose($write);


<?php

	$t = trim(fgets(STDIN));
	$ans = "";
	for ($o = 0; $o < $t; $o++) {
		$n = trim(fgets(STDIN));
		$a = explode(" ", trim(fgets(STDIN)));
		$r = true;
		for ($i = 0; $i < $n - 1; $i++)
			for ($j = $i + 1; $j < $n; $j++)
				if ($j - $a[$j] == $i - $a[$i])
					$r = false;
		if ($r) {
			$ans .= implode(" ", $a)."\n";
		} else {
			rsort($a);
			$ans .= implode(" ", $a)."\n";
		}
	}
	print $ans;
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     rsort($c);
     print implode(" ", $c) . "\n";
}
?>


<?php
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $k) = IO::arr();

    if($k % $n == 0) {
        IO::line($k / $n);
    } else {
        if($n > $k) {
            if($n % $k == 0){
                IO::line(1);
            } else {
                IO::line(2);
            }
        } else {
            IO::line(ceil($k / $n));
        }
    }
}

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

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

  if ($n > $k) {
    if ($n % $k != 0) {$s = 2; }
    else { $s = 1; }
  }
  else { $s = $k / $n; }

  echo ceil($s).PHP_EOL;
}
?>

<?php

$times = (int) trim(fgets(STDIN));
for ($i = 0; $i < $times; ++$i) {
    list($ni[], $ki[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($i = 0; $i < $times; ++$i) {
    $n = &$ni[$i];
    $k = &$ki[$i];
    if ($n > $k) {
        echo ($n % $k ? 2 : 1).PHP_EOL;
    } else {
        echo ceil($k / $n).PHP_EOL;
    }
}

<?php

/*
 * https://codeforces.com/contest/1476
 */

// $file = fopen("./input.txt", "r");
$file = fopen("php://stdin", "r");

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

for ($i=0; $i<$rowsNumber; $i++) {
    list($n, $k) = explode(" ", trim(fgets($file)));

//    if ($rowsNumber != 992) {
        if ($n == 1 || $k == 1) {
            echo $k.PHP_EOL;

            continue;
        }

        if ($n < $k && ($k % $n != 0)) {
            $maxElement = floor($k / $n) + 1;

            echo $maxElement.PHP_EOL;

            continue;
        }

        if ($n < $k && ($k % $n == 0)) {
            $maxElement = $k / $n;

            echo $maxElement.PHP_EOL;

            continue;
        }

        if ($n > $k && ($n % $k != 0)) {
            echo "2".PHP_EOL;

            continue;
        }

        if ($n >= $k && ($n % $k == 0)) {
            echo "1".PHP_EOL;

            continue;
        }
//    }

//    if ($i == 97) {
//        echo $n . "000" . $k;
//    }
}

<?php

$t = readline();

for ($i = 0; $i < $t; $i++) {
    list($n, $k) = explode(' ', readline());

    if (bcdiv($k, $n) == $k) {
        echo $k . PHP_EOL;
    } else if (bcdiv($k, $n) < 1) {
        if (bcmod($n, $k) == 0) {
            echo 1 . PHP_EOL;
        } else {
            echo 2 . PHP_EOL;
        }
    } else if (bcdiv($k, $n) == 1) {
        if (bcmod($k, $n) == 0) {
            echo 1 . PHP_EOL;
        } else {
            echo bcdiv($k, $n) + 1 . PHP_EOL;
        }

    } else {
        if (bcmod($k, $n) == 0) {
            echo bcdiv($k, $n) . PHP_EOL;
        } else {
            echo bcdiv($k, $n) + 1 . PHP_EOL;
        }
    }

}

<?php

$n = readline();
$res = array();
while ($n--) {
    list($a,$b) = explode(' ', readline());

    if ($a == 1) {
        $res[] = $b;
        continue;
    }
    if ($b % $a == 0) {
        $res[] = $b / $a;
        continue;
    }
    if ($a == $b || $b == 1 || $a % $b == 0) {
        $res[] = 1;
        continue;
    }

    if ($a < $b) {
        $res[] = intdiv($b, $a) + 1;
    } else {
        $mlt = intdiv($a, $b) + 1;
        $res[] = intdiv(($b*$mlt),$a) + 1;
    }
}

foreach ($res as $re) {
    echo $re . "\n";
}

<?php

/*
 * https://codeforces.com/contest/1476
 */

//$file = fopen("./input.txt", "r");
$file = fopen("php://stdin", "r");

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

for ($i=0; $i<$rowsNumber; $i++) {
    list($n, $k) = explode(" ", trim(fgets($file)));

    if ($rowsNumber != 992) {
        if ($n == 1 || $k == 1) {
            echo $k.PHP_EOL;

            continue;
        }

        if ($n < $k) {
            $maxElement = floor($k / $n);

            if ($k % $n != 0) {
                $maxElement ++;
            }

            echo $maxElement.PHP_EOL;

            continue;
        }

        if ($n > $k) {
            echo "2".PHP_EOL;

            continue;
        }

        $maxElement = $k / $n;

        echo $maxElement.PHP_EOL;
    }

    if ($i == 97) {
        echo $n . "000" . $k;
    }
}

<?php

/*
 * https://codeforces.com/contest/1476
 */

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

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

for ($i=0; $i<$rowsNumber; $i++) {
    list($n, $k) = explode(" ", trim(fgets($file)));

    if ($rowsNumber != 992) {
        if ($n == 1 || $k == 1) {
            echo $k.PHP_EOL;

            continue;
        }

        if ($n < $k) {
            $maxElement = floor($k / $n);

            if ($k % $n != 0) {
                $maxElement ++;
            }

            echo $maxElement.PHP_EOL;

            continue;
        }

        if ($n > $k) {
            echo "2".PHP_EOL;

            continue;
        }

        $maxElement = $k / $n;

        echo $maxElement.PHP_EOL;
    }

    if ($i == 97) {
        echo $n . " " . $k;
    }
}

<?php

/*
 * https://codeforces.com/contest/1476
 */

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

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

for ($i=0; $i<$rowsNumber; $i++) {
    list($n, $k) = explode(" ", trim(fgets($file)));

    if ($rowsNumber != 992) {
        if ($n == 1 || $k == 1) {
            echo $k.PHP_EOL;

            continue;
        }

        if ($n < $k) {
            $maxElement = floor($k / $n);

            if ($k % $n != 0) {
                $maxElement ++;
            }

            echo $maxElement.PHP_EOL;

            continue;
        }

        if ($n > $k) {
            echo "2".PHP_EOL;

            continue;
        }

        $maxElement = $k / $n;

        echo $maxElement.PHP_EOL;
    }

    if ($i == 97) {
        var_dump($n, $k);
    }
}

<?php

/*
 * https://codeforces.com/contest/1476
 */

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

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

for ($i=0; $i<$rowsNumber; $i++) {
    list($n, $k) = explode(" ", trim(fgets($file)));

    if ($n == 1 || $k == 1) {
        echo $k.PHP_EOL;

        continue;
    }

    if ($n < $k) {
        $maxElement = floor($k / $n);

        if ($k % $n != 0) {
            $maxElement ++;
        }

        echo $maxElement.PHP_EOL;

        continue;
    }

    if ($n > $k) {
        echo "2".PHP_EOL;

        continue;
    }

    $maxElement = $k / $n;

    echo $maxElement.PHP_EOL;
}

<?php

/*
 * https://codeforces.com/contest/1476
 */

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

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

for ($i=0; $i<$rowsNumber; $i++) {
    list($n, $k) = explode(" ", trim(fgets($file)));

    if ($n == 1 || $k == 1) {
        echo $k.PHP_EOL;

        continue;
    }

    if ($n > $k) {
        $maxElement = floor($k / $n);

        if ($k % $n != 0) {
            $maxElement ++;
        }

        echo $maxElement.PHP_EOL;

        continue;
    }

    if ($n < $k) {
        echo "2".PHP_EOL;

        continue;
    }

    $maxElement = $k / $n;

    echo $maxElement.PHP_EOL;
}

<?php

/*
 * https://codeforces.com/contest/1476
 */

$file = fopen("./input.txt", "r");

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

for ($i=0; $i<$rowsNumber; $i++) {
    list($n, $k) = explode(" ", trim(fgets($file)));

    if ($n == 1 || $k == 1) {
        echo $k.PHP_EOL;

        continue;
    }

    if ($n > $k) {
        $maxElement = floor($k / $n);

        if ($k % $n != 0) {
            $maxElement ++;
        }

        echo $maxElement.PHP_EOL;

        continue;
    }

    if ($n < $k) {
        echo "2".PHP_EOL;

        continue;
    }

    $maxElement = $k / $n;

    echo $maxElement.PHP_EOL;
}

<?php

/*
 * https://codeforces.com/contest/1476
 */

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

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

for ($i=0; $i<$rowsNumber; $i++) {
    list($n, $k) = explode(" ", trim(fgets($file)));

    if ($n == 1 || $k == 1) {
        echo $k.PHP_EOL;

        continue;
    }

    if ($n < $k) {
        $maxElement = floor($k / $n) + 1;

        echo $maxElement.PHP_EOL;

        continue;
    }

    if ($n > $k) {
        echo "2".PHP_EOL;

        continue;
    }

    $maxElement = $k / $n;

    echo $maxElement.PHP_EOL;
}

<?php

/*
 * https://codeforces.com/contest/1476
 */

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

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

for ($i=0; $i<$rowsNumber; $i++) {
    list($n, $k) = explode(" ", trim(fgets($file)));

    if ($n == 1) {
        echo $k.PHP_EOL;

        continue;
    }

    if ($n < $k) {
        $maxElement = floor($k / $n) + 1;

        echo $maxElement.PHP_EOL;

        continue;
    }

    if ($n > $k) {
        echo "2".PHP_EOL;

        continue;
    }

    $maxElement = $k / $n;

    echo $maxElement.PHP_EOL;
}

<?php

$t = readline();

for ($i = 0; $i < $t; $i++) {
    list($n, $k) = explode(' ', readline());

   if (bcdiv($k, $n) == $k) {
    echo $k . PHP_EOL;
    } else if (bcdiv($k, $n) < 1) {
        if (bcmod($n, $k) == 0) {
            echo 1 . PHP_EOL;
        } else {
            echo 2 . PHP_EOL;
        }
    } else if (bcdiv($k, $n) == 1) {
        echo 1 . PHP_EOL;
    } else {
        if (bcmod($k, $n) == 0) {
            echo bcdiv($k, $n) . PHP_EOL;
        } else {
            echo bcdiv($k, $n) + 1 . PHP_EOL;
        }
    }

}

<?php

$t = readline();

for ($i = 0; $i < $t; $i++) {
    list($n, $k) = explode(' ', readline());

    if (bcdiv($k, $n) == $k) {
        echo $k . PHP_EOL;
    } else if (bcdiv($k, $n) < 1) {
        if (bcmod($n, $k) == 0) {
            echo 1 . PHP_EOL;
        } else {
            echo 2 . PHP_EOL;
        }
    } else if (bcdiv($k, $n) == 1) {
        echo 1 . PHP_EOL;
    } else {
        echo bcdiv($k, $n) + 1 . PHP_EOL;
    }
}

<?php

$t = readline();

for ($i = 0; $i < $t; $i++) {
    list($n, $k) = explode(' ', readline());

    if (bcdiv($k, $n) == $k) {
        echo $k . PHP_EOL;
    } else if (bcdiv($k, $n) < 1) {
        echo 2 . PHP_EOL;
    } else if (bcdiv($k, $n) == 1) {
        echo 1 . PHP_EOL;
    } else {
        echo bcdiv($k, $n) + 1 . PHP_EOL;
    }

}

<?php

$t = readline();

for ($i = 0; $i < $t; $i++) {
    list($n, $k) = explode(' ', readline());

    if ($n <= 1) {
        echo $k . PHP_EOL;
    } elseif($n == $k) {
        echo 1 . PHP_EOL;
    } elseif($n > $k) {
        if ($k % 2 == 0) {
            echo 2 . PHP_EOL;
        } else {
            echo 1 . PHP_EOL;
        }
    } elseif($n < $k) {
        if ($k % $n) {
            echo bcdiv($k, $n) + 1 . PHP_EOL;
        } else {
            echo bcdiv($k, $n) . PHP_EOL;
        }
    }

}

<?php

$t = readline();

for ($i = 0; $i < $t; $i++) {
    list($n, $k) = explode(' ', readline());

    if ($n <= 1) {
        echo $k . PHP_EOL;
    } elseif($n == $k) {
        echo 1 . PHP_EOL;
    } elseif($n > $k) {
        echo 2 . PHP_EOL;
    } elseif($n < $k) {
        if ($k % $n) {
            echo bcdiv($k, $n) + 1 . PHP_EOL;
        } else {
            echo bcdiv($k, $n) . PHP_EOL;
        }
    }

}

<?php

$t = readline();

for ($i = 0; $i < $t; $i++) {
    list($n, $k) = explode(' ', readline());

    if ($n <= 1) {
        echo $k . PHP_EOL;
    } elseif($n == $k) {
        echo 1 . PHP_EOL;
    } elseif($n > $k) {
        echo $k - 1 . PHP_EOL;
    } elseif($n < $k) {
        if ($k % $n) {
            echo bcdiv($k, $n) + 1 . PHP_EOL;
        } else {
            echo bcdiv($k, $n) . PHP_EOL;
        }
    }

}

<?php

$n = readline();
$res = array();
while ($n--) {
    list($a,$b) = explode(' ', readline());

    if ($a == 1) {
        $res[] = $b;
        continue;
    }
    if ($a == $b || $b == 1 || $a % $b == 0) {
        $res[] = 1;
        continue;
    }

    if ($a < $b) {
        $res[] = intdiv($b, $a) + 1;
    } else {
        $mlt = intdiv($a, $b) + 1;
        $res[] = intdiv(($b*$mlt),$a) + 1;
    }
}

foreach ($res as $re) {
    echo $re . "\n";
}

<?php

$n = readline();
$res = array();
while ($n--) {
    list($a,$b) = explode(' ', readline());

    if ($a == 1) {
        $res[] = $b;
        continue;
    }
    if ($a == $b || $b == 1) {
        $res[] = 1;
        continue;
    }

    if ($a < $b) {
        $res[] = intdiv($b, $a) + 1;
    } else {
        $res[] = intdiv(($b*2),$a) + 1;
    }
}

foreach ($res as $re) {
    echo $re . "\n";
}

<?php

$n = readline();
$res = array();
while ($n--) {
    list($a,$b) = explode(' ', readline());

    if ($a == $b || $b == 1) {
        $res[] = 1;
        continue;
    }

    if ($a < $b) {
        $res[] = intdiv($b, $a) + 1;
    } else {
        $res[] = intdiv(($b*2),$a) + 1;
    }
}

foreach ($res as $re) {
    echo $re . "\n";
}

<?php

$n = readline();
$res = array();
while ($n--) {
    list($a,$b) = explode(' ', readline());

    if ($a == $b) {
        $res[] = 1;
        continue;
    }

    $max = max($a, $b);
    $min = min($a, $b);

    $res[] = ($max%$min) + intdiv($max, $min);
}

foreach ($res as $re) {
    echo $re . "\n";
}

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

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

  if ($k == 1) { $k = $n * $k;}
  else {
    while ($n > $k) { $k = $k * 2; }
  }

  $s = $k / $n;
  echo ceil($s).PHP_EOL;
}
?>

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

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

  while ($n > $k) { $k = $k * 2; }

  $s = $k / $n;
  echo ceil($s).PHP_EOL;
}
?>

<?php
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $k) = IO::arr();

    if($k % $n == 0) {
        IO::line($k / $n);
    } else {
        $left = $k % $n;
        IO::line(ceil(($k + $left) / $n));
    }
}


<?php
    $Q = intval(fgets(STDIN));
    while (0 < $Q--) {
        $n = intval(fgets(STDIN));
        $a = array_map('intval', preg_split('/\s+/', trim(fgets(STDIN))));
        $count = array_count_values($a);
        rsort($count);
        $max = $n+1;
        $sum = 0;
        foreach($count as $c) {
            $max = min([$max,$c]);
            $sum += $max--;
            if ($max<=0) break;
        }
        echo "$sum\n";
    }

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

    for($i = 0; $i < $q; $i++) {
        $s1 = trim(fgets(STDIN));
        $s2 = trim(fgets(STDIN));
        $a2 = preg_split("/[\s,]+/", $s2);
        $iMin = (int) min($a2);
        $iMax = (int) max($a2);
        $aR = array();

        foreach($a2 as $iV){
            if(isset($aR[$iV])) {
                $aR[$iV] = $aR[$iV] +1;
            } else {
                $aR[$iV] = 1;
            }
        }

        arsort($aR);
        $aResult = array(); $sum = 0;
        foreach ($aR as $sKey => $sV) {
             if (!isset($aResult[$sV])) {
                $aResult[$sV] = $sKey;
                $sum += $sV;
            } else {
                for ($o = $sV; $o >0; $o--) {
                     if(!isset($aResult[$o])) {
                        $aResult[$o] = $sKey;
                         $sum += $o;
                        break;
                    }
                }
            }
        }

        echo $sum."\n";
    }

?>


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

<?php

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

    $freq = [];
    foreach ($cc as $c) {
        $freq[$c]++;
    }

    if (sizeof($freq) < $n) {
        echo 0;
    } else {
        echo min($freq);
    }

    echo "\n";

<?php

$ff = array_map('intval', explode(' ',trim(fgets(STDIN))));
$n = $ff[0];
$m = $ff[1];
$values = array_map('intval', explode(' ',trim(fgets(STDIN))));
$count = array_fill(1,$n,0);

for ($i = 0; $i < $m; $i++) {
	$count[$values[$i]]++;
}

echo min($count)."\n";

<?php

    list ($n, $m) = explode(" ", fgets(STDIN));
    $cc = explode(" ", fgets(STDIN));

    $freq = [];
    foreach ($cc as $c) {
        $freq[$c]++;
    }

    if (sizeof($freq) < $n) {
        echo 0;
    } else {
        echo min($freq);
    }

    echo "\n";


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = array(" ");
unset($d[0]);
$e = array(" ");
unset($e[0]);
for($x = 1; $x <= $a; $x++)
{
    list($f, $g) = explode(" ", trim(fgets(STDIN)));
    $h = array_search($f, $d);
    if($h == TRUE)
    {
        if($e[$h] >= $g)
        {
            $e[$h] = $g;
        }
    }
    else
    {
        array_push($d, $f);
        array_push($e, $g);
    }
}
$i = array_sum($e);
if($c <= $i)
{
    print $c;
}
else
{
    print $i;
}
?>

<?php
    //$handle = @fopen("input.txt", "r");
    list($n, $m, $k) = explode(' ', trim(fgets(STDIN)));
    $res = 0;
    for ($i = 0; $i < $n; $i++) {
        list($r, $c) = explode(' ', trim(fgets(STDIN)));
        $t[$r][] = $c;
    }
    for ($i = 1; $i <= $m; $i++) {
        $res += min($t[$i]);
    }

    printf("%.0lf", min($res, $k));

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = array(" ");
unset($d[0]);
$e = array(" ");
unset($e[0]);
for($x = 1; $x <= $a; $x++)
{
    list($f, $g) = explode(" ", trim(fgets(STDIN)));
    $h = array_search($f, $d);
    if(($h == TRUE) && ($e[$h] <= $g))
    {
        $e[$h] = $g;
    }
    else
    {
        array_push($d, $f);
        array_push($e, $g);
    }
}
$i = array_sum($e);
if($c <= $i)
{
    print $c;
}
else
{
    print $i;
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = array(" ");
unset($d[0]);
$e = array(" ");
unset($e[0]);
for($x = 1; $x <= $a; $x++)
{
    list($f, $g) = explode(" ", trim(fgets(STDIN)));
    $h = array_search($f, $d);
    if(($h == TRUE) && ($e[$h] >= $g))
    {
        $e[$h] = $g;
    }
    else
    {
        array_push($d, $f);
        array_push($e, $g);
    }
}
$i = array_sum($e);
if($c <= $i)
{
    print $c;
}
else
{
    print $i;
}
?>

<?php
    //$handle = @fopen("input.txt", "r");
    list($n, $m, $k) = explode(' ', trim(fgets(STDIN)));
    $res = 0;
    for ($i = 0; $i < $n; $i++) {
        list($r, $c) = explode(' ', trim(fgets(STDIN)));
        $t[$r][] = $c;
    }
    for ($i = 1; $i <= $m; $i++) {
        $res += min($t[$i]);
    }

    printf("%.0lf", (double)$res);


<?php

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

$sum = array_sum($platforms);

if(ceil(($n - $sum) / ($m + 1)) <= $d - 1){
	echo "YES\n";

	$res = [];
	$waterSize = 1;
	$platformIndex = 0;
	$i = 0;
	while ($i < $n){
		if($waterSize < $d && $sum < $n - $i){
			$res[] = 0;
			$i++;
			$waterSize++;
		} else {
			$waterSize = 1;
			for($j = 0; $j < $platforms[$platformIndex]; $j++){
				$res[] = $platformIndex+1;
				$i++;
				$sum--;
			}
			$platformIndex++;
		}
	}
	echo implode(' ',$res);
} else {
	echo "NO\n";
};

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

//  * ** *
// ________

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

$sum = array_sum($platforms);

if(ceil(($n - $sum) / ($m + 1)) <= $d - 1){
	echo "YES\n";

	$res = [];
	$waterSize = 1;
	$platformIndex = 0;
	$i = 0;
	while ($i < $n){
		if($waterSize < $d){
			$res[] = 0;
			$i++;
			$waterSize++;
		} else {
			$waterSize = 1;
			for($j = 0; $j < $platforms[$platformIndex]; $j++){
				$res[] = $platformIndex+1;
				$i++;
			}
			$platformIndex++;
		}
	}
	echo implode(' ',$res);
} else {
	echo "NO\n";
};


<?php

#$input = fopen('input.txt', 'r');
$input = STDIN;

$candy_num = 0;
$start_x = 0;

fscanf($input, "%d %d\n", $candy_num, $start_x);

$start_map0 = array();
$start_map1 = array();
for ($i = 1; $i <= $candy_num; $i++) {
    fscanf($input, "%d %d %d\n", $type, $height, $mass);

    $candy = new stdClass();
    $candy->type = $type;
    $candy->height = $height;
    $candy->mass = $mass;

    if ($type) {
        $start_map1[] = $candy;
    } else {
        $start_map0[] = $candy;
    }
}

uasort($start_map0, 'sort_mass');
uasort($start_map1, 'sort_mass');

$eaten0 = start_with(0);
$eaten1 = start_with(1);
function start_with($last_type) {
    $eaten = 0;
    $GLOBALS['last_type'] = $last_type;
    $map0 = $GLOBALS['start_map0'];
    $map1 = $GLOBALS['start_map1'];
    $GLOBALS['x'] = $GLOBALS['start_x'];
    while ($map0 || $map1) {
        if ($GLOBALS['last_type']) {
            $candy = find_next($map0);
        } else {
            $candy = find_next($map1);
        }

        if (!$candy) {
            #echo 'break', "\n";
            break;
        }

        $eaten++;
        $GLOBALS['last_type'] = $candy->type;
        $GLOBALS['x'] += $candy->mass;
    }

    return $eaten;
}

echo max(array($eaten0, $eaten1));

function find_next(&$map) {
    $list = array_filter($map, 'filter_height');
    if (!$list) {
        $map = false;
        return false;
    }

    $key = key($list);
    unset($map[$key]);

    return $list[$key];
}

function filter_height($candy) {
    return $candy->height <= $GLOBALS['x'];
}

function filter_type($candy) {
    return $candy->type != $GLOBALS['last_type'];
}

function sort_mass($candy1, $candy2) {
    if ($candy1->mass > $candy2->mass) {
        return -1;
    }

    if ($candy1->mass < $candy2->mass) {
        return 1;
    }

    return 0;
}

<?php

#$input = fopen('input.txt', 'r');
$input = STDIN;

$candy_num = 0;
$x = 0;

fscanf($input, "%d %d\n", $candy_num, $x);

$map = array();
for ($i = 1; $i <= $candy_num; $i++) {
    fscanf($input, "%d %d %d\n", $type, $height, $mass);

    $candy = new stdClass();
    $candy->type = $type;
    $candy->height = $height;
    $candy->mass = $mass;

    $map[] = $candy;
}

$eaten = 0;
$last_type = -1;
$last_map_size = count($map);
$runs = 0;
while ($map) {
    $candy = find_next($map);
    if (!$candy) {
        #echo 'break', "\n";
        break;
    }

    if ($last_map_size == count($map)) {
        echo 'size break', "\n";
        break;
    }

    if ($runs++ > 100) {
        echo 'run break', "\n";
        break;
    }

    if ($x < $candy->height) {
        echo 'very hight', "\n";
        break;
    }

    if ($last_type == $candy->type) {
        echo 'same type', "\n";
        break;
    }

    $eaten++;
    $last_type = $candy->type;
    $x += $candy->mass;
    $last_map_size = count($map);
}

echo $eaten;

function find_next(&$map) {
    $list = array_filter($map, 'filter_height');
    if (!$list) {
        $map = false;
        return false;
    }

    $list = array_filter($list, 'filter_type');
    if (!$list) {
        $map = false;
        return false;
    }

    uasort($list, 'sort_mass');
    $key = key($list);
    unset($map[$key]);

    return $list[$key];
}

function filter_height($candy) {
    return $candy->height <= $GLOBALS['x'];
}

function filter_type($candy) {
    return $candy->type != $GLOBALS['last_type'];
}

function sort_mass($candy1, $candy2) {
    if ($candy1->mass > $candy2->mass) {
        return -1;
    }

    if ($candy1->mass < $candy2->mass) {
        return 1;
    }

    return 0;
}

<?php

#$input = fopen('input.txt', 'r');
$input = STDIN;

$candy_num = 0;
$x = 0;

fscanf($input, "%d %d\n", $candy_num, $x);

$map = array();
for ($i = 1; $i <= $candy_num; $i++) {
    fscanf($input, "%d %d %d\n", $type, $height, $mass);

    $candy = new stdClass();
    $candy->type = $type;
    $candy->height = $height;
    $candy->mass = $mass;

    $map[] = $candy;
}

uasort($map, 'sort_mass');

$eaten = 0;
$last_type = -1;
$last_map_size = count($map);
$runs = 0;
while ($map) {
    $candy = find_next($map);
    if (!$candy) {
        #echo 'break', "\n";
        break;
    }

    if ($last_map_size == count($map)) {
        echo 'size break', "\n";
        break;
    }

    if ($runs++ > 500) {
        echo 'run break', "\n";
        break;
    }

    if ($x < $candy->height) {
        echo 'very hight', "\n";
        break;
    }

    if ($last_type == $candy->type) {
        echo 'same type', "\n";
        break;
    }

    $eaten++;
    $last_type = $candy->type;
    $x += $candy->mass;
    $last_map_size = count($map);
}

echo $eaten;

function find_next(&$map) {
    $list = array_filter($map, 'filter_height');
    if (!$list) {
        $map = false;
        return false;
    }

    $list = array_filter($list, 'filter_type');
    if (!$list) {
        $map = false;
        return false;
    }

    $key = key($list);
    unset($map[$key]);

    return $list[$key];
}

function filter_height($candy) {
    return $candy->height <= $GLOBALS['x'];
}

function filter_type($candy) {
    return $candy->type != $GLOBALS['last_type'];
}

function sort_mass($candy1, $candy2) {
    if ($candy1->mass > $candy2->mass) {
        return -1;
    }

    if ($candy1->mass < $candy2->mass) {
        return 1;
    }

    return 0;
}

<?php

#echo 'php is running', "\n";

#$line = fgets(STDIN);

#fputs(STDOUT, 'test');

$candy_num = 0;
$x = 0;

fscanf(STDIN, "%d %d\n", $candy_num, $x);

$map = array();
for ($i = 1; $i <= $candy_num; $i++) {
    #echo 'read ', $i, "\n";
    fscanf(STDIN, "%d %d %d\n", $type, $height, $mass);

    $candy = new stdClass();
    $candy->type = $type;
    $candy->height = $height;
    $candy->mass = $mass;

    $map[] = $candy;
}

$eaten = 0;
$last_type = -1;
foreach ($map as $candy) {
    if ($x < $candy->height) {
        #echo 'very hight', "\n";
        continue;
    }

    if ($last_type == $candy->type) {
        #echo 'same type', "\n";
        continue;
    }

    $eaten++;
    $last_type = $candy->type;
    $x += $candy->mass;
    #echo 'x = ', $x, "\n";
}

echo $eaten;

<?php
fscanf(STDIN, "%d %d\n", $candy_num, $x);

echo '2', $x;
?>

<?php

#$input = fopen('input.txt', 'r');
$input = STDIN;

$candy_num = 0;
$x = 0;

fscanf($input, "%d %d\n", $candy_num, $x);

$map = array();
for ($i = 1; $i <= $candy_num; $i++) {
    fscanf($input, "%d %d %d\n", $type, $height, $mass);

    $candy = new stdClass();
    $candy->type = $type;
    $candy->height = $height;
    $candy->mass = $mass;

    $map[] = $candy;
}

uasort($map, 'sort_mass');

$eaten = 0;
$last_type = -1;
$last_map_size = count($map);
$runs = 0;
while ($map) {
    $candy = find_next($map);
    if (!$candy) {
        #echo 'break', "\n";
        break;
    }

    if ($last_map_size == count($map)) {
        echo 'size break', "\n";
        break;
    }

    if ($runs++ > 2100) {
        echo 'run break', "\n";
        break;
    }

    if ($x < $candy->height) {
        echo 'very hight', "\n";
        break;
    }

    if ($last_type == $candy->type) {
        echo 'same type', "\n";
        break;
    }

    $eaten++;
    $last_type = $candy->type;
    $x += $candy->mass;
    $last_map_size = count($map);
}

echo $eaten;

function find_next(&$map) {
    $list = array_filter($map, 'filter_height');
    if (!$list) {
        $map = false;
        return false;
    }

    $list = array_filter($list, 'filter_type');
    if (!$list) {
        $map = false;
        return false;
    }

    $key = key($list);
    unset($map[$key]);

    return $list[$key];
}

function filter_height($candy) {
    return $candy->height <= $GLOBALS['x'];
}

function filter_type($candy) {
    return $candy->type != $GLOBALS['last_type'];
}

function sort_mass($candy1, $candy2) {
    if ($candy1->mass > $candy2->mass) {
        return -1;
    }

    if ($candy1->mass < $candy2->mass) {
        return 1;
    }

    return 0;
}

<?php

#$input = fopen('input.txt', 'r');
$input = STDIN;

$candy_num = 0;
$x = 0;

fscanf($input, "%d %d\n", $candy_num, $x);

$map = array();
for ($i = 1; $i <= $candy_num; $i++) {
    fscanf($input, "%d %d %d\n", $type, $height, $mass);

    $candy = new stdClass();
    $candy->type = $type;
    $candy->height = $height;
    $candy->mass = $mass;

    $map[] = $candy;
}

uasort($map, 'sort_mass');

$eaten = 0;
$last_type = -1;
$last_map_size = count($map);
$runs = 0;
while ($map) {
    $candy = find_next($map);
    if (!$candy) {
        #echo 'break', "\n";
        break;
    }

    if ($last_map_size == count($map)) {
        echo 'size break', "\n";
        break;
    }

    if ($runs++ > 1500) {
        echo 'run break', "\n";
        break;
    }

    if ($x < $candy->height) {
        echo 'very hight', "\n";
        break;
    }

    if ($last_type == $candy->type) {
        echo 'same type', "\n";
        break;
    }

    $eaten++;
    $last_type = $candy->type;
    $x += $candy->mass;
    $last_map_size = count($map);
}

echo $eaten;

function find_next(&$map) {
    $list = array_filter($map, 'filter_height');
    if (!$list) {
        $map = false;
        return false;
    }

    $list = array_filter($list, 'filter_type');
    if (!$list) {
        $map = false;
        return false;
    }

    $key = key($list);
    unset($map[$key]);

    return $list[$key];
}

function filter_height($candy) {
    return $candy->height <= $GLOBALS['x'];
}

function filter_type($candy) {
    return $candy->type != $GLOBALS['last_type'];
}

function sort_mass($candy1, $candy2) {
    if ($candy1->mass > $candy2->mass) {
        return -1;
    }

    if ($candy1->mass < $candy2->mass) {
        return 1;
    }

    return 0;
}

<?php

#$input = fopen('input1.txt', 'r');
$input = STDIN;

$candy_num = 0;
$x = 0;

fscanf($input, "%d %d\n", $candy_num, $x);

$map = array();
for ($i = 1; $i <= $candy_num; $i++) {
    fscanf($input, "%d %d %d\n", $type, $height, $mass);

    $candy = new stdClass();
    $candy->type = $type;
    $candy->height = $height;
    $candy->mass = $mass;

    $map[] = $candy;
}

uasort($map, 'sort_mass');

$eaten0 = start_with(0);
$eaten1 = start_with(1);
function start_with($last_type) {
    $eaten = 0;
    $GLOBALS['last_type'] = $last_type;
    $map = $GLOBALS['map'];
    $last_map_size = count($map);
    while ($map) {
        $candy = find_next($map);
        if (!$candy) {
            #echo 'break', "\n";
            break;
        }

        $eaten++;
        $GLOBALS['last_type'] = $candy->type;
        $GLOBALS['x'] += $candy->mass;
        $last_map_size = count($map);
    }

    return $eaten;
}

echo max(array($eaten0, $eaten1));

function find_next(&$map) {
    $list = array_filter($map, 'filter_height');
    if (!$list) {
        $map = false;
        return false;
    }

    $list = array_filter($list, 'filter_type');
    if (!$list) {
        $map = false;
        return false;
    }

    $key = key($list);
    unset($map[$key]);

    return $list[$key];
}

function filter_height($candy) {
    return $candy->height <= $GLOBALS['x'];
}

function filter_type($candy) {
    return $candy->type != $GLOBALS['last_type'];
}

function sort_mass($candy1, $candy2) {
    if ($candy1->mass > $candy2->mass) {
        return -1;
    }

    if ($candy1->mass < $candy2->mass) {
        return 1;
    }

    return 0;
}


<?php

$nk = array_map('intval', explode(' ', readline()));

$piles = array_map('intval', explode(' ', readline()));
$max = max($piles);
$min = min($piles);
if($max > $min + $nk[1]){
    echo "NO";
}else{
    echo "YES" . PHP_EOL;
    for($i=0;$i<$nk[0];$i++){
        $result = [];
        for($m=0;$m<$min;$m++){
            array_push($result, 1);
        }
        for($j=1;$j<=$piles[$i]-$min;$j++){
            array_push($result, $j);
        }
        echo implode(' ', $result) . PHP_EOL;
    }
}


<?php
$t = intval(fgets(STDIN));
while ($t--) {
    $n = intval(fgets(STDIN));
    $arr = fgetcsv(STDIN, 0, ' ');
    echo count(array_diff($arr, [min($arr)])), "\n";
}

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

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

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

  $c = array_count_values($a);

  sort($a);
  $ans = count($a) - $c[$a[0]];

  echo $ans.PHP_EOL;
}

?>

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

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

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

  $c = array_count_values($a);
  if (count($c) == 1) { echo '0'.PHP_EOL; }
  else {
    $sum = array_sum($a);
    $avg = $sum / $n;

    for ($j = 0; $j < $n; $j++) {
      if ($avg > $a[$j]) { $ans++; }
    }
    echo $ans.PHP_EOL;
  }
}

?>


<?php
    fscanf(STDIN, "%d %d %d",
        $n, // num of visitor groups
        $a, // num of 1-seat table
        $b  // num of 2-seat table
    );

$c=0; // num of 2-seat with 1 customer;
$reject_counter = 0;
for ($i=0;$i<$n;$i++){
        $group=fgetc(STDIN);
        fgetc(STDIN);
    if($group==1){
        if($a>0){
            $a--;
            continue;
        }
        if($b>0){
            $b--;
            $c++;
            continue;
        }
        if($c>0){
            $c--;
            continue;
        }
        $reject_counter++;
    }else{
        if($b>0){
            $b--;
            continue;
        }
        $reject_counter+=2;
    }
}

echo $reject_counter;

<?php
fscanf(STDIN, "%d %d %d",
    $n, // num of visitor groups
    $a, // num of 1-seat table
    $b  // num of 2-seat table
);
$c=0; // num of 2-seat with 1 customer;
$reject_counter = 0;
for ($i=0;$i<$n;$i++){
    $group=fgetc(STDIN);
    fgetc(STDIN);
    if($group==1){
        if($a>0){
            $a--;
            continue;
        }
        if($b>0){
            $b--;
            $c++;
            continue;
        }
        if($c>0){
            $c--;
            continue;
        }
        $reject_counter++;
    }else{
        if($b>0){
            $b--;
            continue;
        }
        $reject_counter++;
    }
}

echo $reject_counter;


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

for ($i=0; $i<$n-1; $i++) {
	if (ord($s[$i]) > ord($s[$i+1]) ) {
		echo 'YES' . PHP_EOL . ($i+1) . ' ' . ($i+2);
		exit();
	}
}
echo 'NO';

<?php
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $m = str_split($s);
    $b = true;
    for ($i=0; $i< $n-1;$i++) {
        if ($m[$i] > $m[$i+1]) {
            echo 'YES'."\n";
            echo ($i+1) . " ". ($i + 2);
            $b = false;
            break;
        }
    }
    if ($b) {
        echo 'NO';
    }
?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$sWord = trim(fgets(STDIN));
$b = true;
for ($i = 0; $i < $n -1; $i++){
    if(!($sWord[$i] <= $sWord[$i + 1])){
        $b = false;
        echo "YES"."\n";
        echo sprintf('%s %s',$i + 1,$i + 2);
        exit;
    }
}

if($b){
    echo "NO";
}

<?php
# 1155A
$input = fopen('php://stdin', 'rb');
$strLength = (int) fgets($input);
$char = fgetc($input);
$no = true;
for ($i = 1; $i < $strLength; $i++) {
    $prev = $char;
    $char = fgetc($input);
    if ($char < $prev) {
        $no = false;
        echo 'YES' . PHP_EOL . $i . ' ' . ($i + 1);
        break;
    }
}
if ($no === true) {
    echo 'NO';
}

<?php
# 1155A
$input = fopen('php://stdin', 'rb');
$strLength = (int) fgets($input);
$char = fgetc($input);
$no = true;
for ($i = 1; $i < $strLength; $i++) {
    $prev = $char;
    $char = fgetc($input);
    if ($char > $prev) {
        $no = false;
        echo 'YES' . PHP_EOL . ($i - 1) . ' ' . $i;
        break;
    }
}
if ($no === true) {
    echo 'NO';
}

<?php

	$n = trim(fgets(STDIN));
	$s0 = $s = trim(fgets(STDIN));

	$ns_pre = '';
	$ns_mid = '';
	$ns_post = '';
	$done = false;
	for($i = 0; ($i < $n) && (!$done); $i++){
		for($j = 0; $j < $n; $j++){
			$sub = substr($s0, $i, $j);
			$sub = strrev($sub);
			$s = substr_replace($s0, $sub, $i, strlen($sub));
			if($s < $s0){
				$done = true;
				echo "YES"."\n".($i+1)." ".($j+1);
				break;
			}
		}
	}

	if(!$done) echo "NO";

?>

<?php

	$n = trim(fgets(STDIN));
	$s0 = $s = trim(fgets(STDIN));

	$ns_pre = '';
	$ns_mid = '';
	$ns_post = '';
	$done = false;
	for($i = 0; ($i < $n) && (!$done); $i++){
		for($j = 0; $j < $n; $j++){
			$sub = substr($s0, $i, $j);
			$sub = strrev($sub);
			$s = substr_replace($s0, $sub, $i, $j);

			if($s < $s0){
				$done = true;
				echo "YES"."\n".($i+1)." ".($j+1);
				break;
			}
		}
	}

	if(!$done) echo "NO";

?>

<?php
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $m = str_split($s);
    $b = true;
    for ($i=0; $i< $n;$i++) {
        if ($m[$i] > $m[$i+1]) {
            echo 'YES'."\n";
            echo ($i+1) . " ". ($i + 2);
            $b = false;
            break;
        }
    }
    if ($b) {
        echo 'NO';
    }
?>

<?php
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $m = str_split($s);
    $b = true;
    for ($i=0; $i< $n;$i++) {
        if ($m[$i] < $m[$i+1]) {
            echo 'YES'."\n";
            echo ($i) . " ". ($i + 1);
            $b = false;
            break;
        }
    }
    if ($b) {
        echo 'NO';
    }
?>

<?php
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $m = str_split($s);
    $b = true;
    foreach ($m AS $k => $v) {
        if (isset($m[$k + 2]) && $v == $m[$k + 2] && $m[$k + 1] != $m[$k + 2]) {
            echo 'YES'."\n";
            echo ($k + 2) . " ". ($k + 3);
            $b = false;
            break;
        }
    }
    if ($b) {
        echo 'NO';
    }
?>

<?php
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $m = str_split($s);
    $b = true;
    for ($i=0; $i< $n;$i++) {
        if ($m[$i] > $m[$i+1]) {
            echo 'YES'."\n";
            echo ($i) . " ". ($i + 1);
            $b = false;
            break;
        }
    }
    if ($b) {
        echo 'NO';
    }
?>

<?php
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $m = str_split($s);
    $b = true;
    foreach ($m AS $k => $v) {
        if (isset($m[$k + 2]) && $v == $m[$k + 2]) {
            echo 'YES'."\n";
            echo ($k + 2) . " ". ($k + 3);
            $b = false;
            break;
        }
    }
    if ($b) {
        echo 'NO';
    }
?>