Little time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there are n players in "Losewille Rangers". Each player on the team has a number — a unique integer from 1 to n. To prepare for the championship, the coach Mr. Floppe decided to spend some number of practices.Mr. Floppe spent some long nights of his holiday planning how to conduct the practices. He came to a very complex practice system. Each practice consists of one game, all n players of the team take part in the game. The players are sorted into two teams in some way. In this case, the teams may have different numbers of players, but each team must have at least one player.The coach wants to be sure that after the series of the practice sessions each pair of players had at least one practice, when they played in different teams. As the players' energy is limited, the coach wants to achieve the goal in the least number of practices.Help him to schedule the practices.

A single input line contains integer n (2 ≤ n ≤ 1000).

In the first line print m — the minimum number of practices the coach will have to schedule. Then print the descriptions of the practices in m lines. In the i-th of those lines print fi — the number of players in the first team during the i-th practice (1 ≤ fi < n), and fi numbers from 1 to n — the numbers of players in the first team. The rest of the players will play in the second team during this practice. Separate numbers on a line with spaces. Print the numbers of the players in any order. If there are multiple optimal solutions, print any of them.

 <?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,$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]['���'],++$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);


All techniques in the ninja world consist of hand seals. At the moment Naruto is learning a new technique, which consists of $$$n\cdot m$$$ different seals, denoted by distinct numbers. All of them were written in an $$$n\times m$$$ table.The table is lost now. Naruto managed to remember elements of each row from left to right, and elements of each column from top to bottom, but he doesn't remember the order of rows and columns. Please restore the table consistent with this data so that Naruto will be able to learn the new technique.

The first line of the input contains the only integer $$$t$$$ ($$$1\leq t\leq 100\,000$$$) denoting the number of test cases. Their descriptions follow. The first line of each test case description consists of two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 500$$$) standing for the number of rows and columns in the table, respectively. All hand seals are encoded by the positive integers from $$$1$$$ to $$$n\cdot m$$$. The following $$$n$$$ lines contain $$$m$$$ space separated integers each, denoting elements of an arbitrary row in the table left to right. The following $$$m$$$ lines contain $$$n$$$ space separated integers each, denoting elements of an arbitrary column in the table top to bottom. Sum of $$$nm$$$ over all test cases does not exceed $$$250\,000$$$. It is guaranteed that each row occurs in the input exactly once, as well as each column. It is also guaranteed that each number from $$$1$$$ to $$$nm$$$ occurs exactly once in all rows, as well as in all columns. Finally, it is guaranteed that a table consistent with the input exists.

For each test case, output $$$n$$$ lines with $$$m$$$ space-separated integers each, denoting the restored table. One can show that the answer is always unique.

NoteConsider the first test case. The matrix is $$$2 \times 3$$$. You are given the rows and columns in arbitrary order.One of the rows is $$$[6, 5, 4]$$$. One of the rows is $$$[1, 2, 3]$$$.One of the columns is $$$[1, 6]$$$. One of the columns is $$$[2, 5]$$$. One of the columns is $$$[3, 4]$$$.You are to reconstruct the matrix. The answer is given in the output.


Two players A and B have a list of $$$n$$$ integers each. They both want to maximize the subtraction between their score and their opponent's score. In one turn, a player can either add to his score any element from his list (assuming his list is not empty), the element is removed from the list afterward. Or remove an element from his opponent's list (assuming his opponent's list is not empty).Note, that in case there are equal elements in the list only one of them will be affected in the operations above. For example, if there are elements $$$\{1, 2, 2, 3\}$$$ in a list and you decided to choose $$$2$$$ for the next turn, only a single instance of $$$2$$$ will be deleted (and added to the score, if necessary). The player A starts the game and the game stops when both lists are empty. Find the difference between A's score and B's score at the end of the game, if both of the players are playing optimally.Optimal play between two players means that both players choose the best possible strategy to achieve the best possible outcome for themselves. In this problem, it means that each player, each time makes a move, which maximizes the final difference between his score and his opponent's score, knowing that the opponent is doing the same.

The first line of input contains an integer $$$n$$$ ($$$1 \le n \le 100\,000$$$) — the sizes of the list. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^6$$$), describing the list of the player A, who starts the game. The third line contains $$$n$$$ integers $$$b_i$$$ ($$$1 \le b_i \le 10^6$$$), describing the list of the player B.

Output the difference between A's score and B's score ($$$A-B$$$) if both of them are playing optimally.

NoteIn the first example, the game could have gone as follows:   A removes $$$5$$$ from B's list.  B removes $$$4$$$ from A's list.  A takes his $$$1$$$.  B takes his $$$1$$$. Hence, A's score is $$$1$$$, B's score is $$$1$$$ and difference is $$$0$$$.There is also another optimal way of playing:  A removes $$$5$$$ from B's list.  B removes $$$4$$$ from A's list.  A removes $$$1$$$ from B's list.  B removes $$$1$$$ from A's list. The difference in the scores is still $$$0$$$.In the second example, irrespective of the moves the players make, they will end up with the same number of numbers added to their score, so the difference will be $$$0$$$.


There are $$$n$$$ left boots and $$$n$$$ right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings $$$l$$$ and $$$r$$$, both of length $$$n$$$. The character $$$l_i$$$ stands for the color of the $$$i$$$-th left boot and the character $$$r_i$$$ stands for the color of the $$$i$$$-th right boot.A lowercase Latin letter denotes a specific color, but the question mark ('?') denotes an indefinite color. Two specific colors are compatible if they are exactly the same. An indefinite color is compatible with any (specific or indefinite) color.For example, the following pairs of colors are compatible: ('f', 'f'), ('?', 'z'), ('a', '?') and ('?', '?'). The following pairs of colors are not compatible: ('f', 'g') and ('a', 'z').Compute the maximum number of pairs of boots such that there is one left and one right boot in a pair and their colors are compatible.Print the maximum number of such pairs and the pairs themselves. A boot can be part of at most one pair.

The first line contains $$$n$$$ ($$$1 \le n \le 150000$$$), denoting the number of boots for each leg (i.e. the number of left boots and the number of right boots). The second line contains the string $$$l$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th left boot. The third line contains the string $$$r$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th right boot.

Print $$$k$$$ — the maximum number of compatible left-right pairs of boots, i.e. pairs consisting of one left and one right boot which have compatible colors. The following $$$k$$$ lines should contain pairs $$$a_j, b_j$$$ ($$$1 \le a_j, b_j \le n$$$). The $$$j$$$-th of these lines should contain the index $$$a_j$$$ of the left boot in the $$$j$$$-th pair and index $$$b_j$$$ of the right boot in the $$$j$$$-th pair. All the numbers $$$a_j$$$ should be distinct (unique), all the numbers $$$b_j$$$ should be distinct (unique). If there are many optimal answers, print any of them.

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

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


Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.Its most important components are a button and a line of n similar gears. Each gear has n teeth containing all numbers from 0 to n - 1 in the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise, the the third gear rotates clockwise an so on.Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5, and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active, or the counter-clockwise rotating makes the tooth number 4 active.Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1. Write a program that determines whether the given puzzle is real or fake.

The first line contains integer n (1 ≤ n ≤ 1000) — the number of gears. The second line contains n digits a1, a2, ..., an (0 ≤ ai ≤ n - 1) — the sequence of active teeth: the active tooth of the i-th gear contains number ai.

In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without the quotes) otherwise.

NoteIn the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second time, you get 0 1 2.

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


Andre has very specific tastes. Recently he started falling in love with arrays.Andre calls an nonempty array $$$b$$$ good, if sum of its elements is divisible by the length of this array. For example, array $$$[2, 3, 1]$$$ is good, as sum of its elements — $$$6$$$ — is divisible by $$$3$$$, but array $$$[1, 1, 2, 3]$$$ isn't good, as $$$7$$$ isn't divisible by $$$4$$$. Andre calls an array $$$a$$$ of length $$$n$$$ perfect if the following conditions hold:   Every nonempty subarray of this array is good.  For every $$$i$$$ ($$$1 \le i \le n$$$), $$$1 \leq a_i \leq 100$$$. Given a positive integer $$$n$$$, output any perfect array of length $$$n$$$. We can show that for the given constraints such an array always exists.An array $$$c$$$ is a subarray of an array $$$d$$$ if $$$c$$$ can be obtained from $$$d$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).

For every test, output any perfect array of length $$$n$$$ on a separate line.

NoteArray $$$[19, 33]$$$ is perfect as all $$$3$$$ its subarrays: $$$[19]$$$, $$$[33]$$$, $$$[19, 33]$$$, have sums divisible by their lengths, and therefore are good.

<?php

ob_start(null, 65536);

$__ln = explode("\n", file_get_contents("php://stdin"));
$__lc = 0;

function nl() {
    global $__ln, $__lc;
    return $__ln[$__lc++];
}

function nla() {
    global $__ln, $__lc;
    return explode(" ", $__ln[$__lc++]);
}

function asInt($x) {
    return (int)$x;
}

function asDouble($x) {
    return (double)$x;
}

$tc = asInt(nl());
for($cc=0; $cc<$tc; $cc++) {
    $n = asInt(nl());
    for($i=0; $i<$n; $i++) {
        echo 1 . " ";
    }
    echo "\n";
}


A sequence $$$a_1, a_2, \dots, a_n$$$ is called good if, for each element $$$a_i$$$, there exists an element $$$a_j$$$ ($$$i \ne j$$$) such that $$$a_i+a_j$$$ is a power of two (that is, $$$2^d$$$ for some non-negative integer $$$d$$$).For example, the following sequences are good:  $$$[5, 3, 11]$$$ (for example, for $$$a_1=5$$$ we can choose $$$a_2=3$$$. Note that their sum is a power of two. Similarly, such an element can be found for $$$a_2$$$ and $$$a_3$$$),  $$$[1, 1, 1, 1023]$$$,  $$$[7, 39, 89, 25, 89]$$$,  $$$[]$$$. Note that, by definition, an empty sequence (with a length of $$$0$$$) is good.For example, the following sequences are not good:  $$$[16]$$$ (for $$$a_1=16$$$, it is impossible to find another element $$$a_j$$$ such that their sum is a power of two),  $$$[4, 16]$$$ (for $$$a_1=4$$$, it is impossible to find another element $$$a_j$$$ such that their sum is a power of two),  $$$[1, 3, 2, 8, 8, 8]$$$ (for $$$a_3=2$$$, it is impossible to find another element $$$a_j$$$ such that their sum is a power of two). You are given a sequence $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you need to remove to make it good? You can delete an arbitrary set of elements.

The first line contains the integer $$$n$$$ ($$$1 \le n \le 120000$$$) — the length of the given sequence. The second line contains the sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).

Print the minimum number of elements needed to be removed from the given sequence in order to make it good. It is possible that you need to delete all $$$n$$$ elements, make it empty, and thus get a good sequence.

NoteIn the first example, it is enough to delete one element $$$a_4=5$$$. The remaining elements form the sequence $$$[4, 7, 1, 4, 9]$$$, which is good.


Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.

Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.

NoteConsider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3.In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal.In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.

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


Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:   name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;  ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters. For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.

The input data consists of a single string s, its length is from 1 to 4·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').

In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them. If the solution does not exist, then print in a single line "NO" (without the quotes).

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


Поликарп мечтает стать программистом и фанатеет от степеней двойки. Среди двух чисел ему больше нравится то, которое делится на большую степень числа 2. По заданной последовательности целых положительных чисел a1, a2, ..., an требуется найти r — максимальную степень числа 2, на которую делится хотя бы одно из чисел последовательности. Кроме того, требуется вывести количество чисел ai, которые делятся на r.

В первой строке записано целое число n (1 ≤ n ≤ 100) — длина последовательности a. Во второй строке записана последовательность целых чисел a1, a2, ..., an (1 ≤ ai ≤ 109).

Выведите два числа:   r — максимальную степень двойки, на которую делится хотя бы одно из чисел заданной последовательности,  количество элементов последовательности, которые делятся на r.

ПримечаниеВ первом тестовом примере максимальная степень двойки, на которую делится хотя бы одно число, равна 16 = 24, на неё делятся числа 80, 16 и 48.Во втором тестовом примере все четыре числа нечётные, поэтому делятся только на 1 = 20. Это и будет максимальной степенью двойки для данного примера.

<?php
trim(fgets(STDIN)); // For spend count of numbers

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

$power = 0;
$max = max($arr);
$maxpower = count(str_split(decbin($max)))-1;

$count = 0;

foreach ($arr as $a){
	for($i=$maxpower; $i >= 0; $i--){
		$mod = $a % pow(2, $i);
		if($mod == '0' && $i == $power){
			$count++;
			continue;
		}
		if($mod == '0' && $i > $power) {
			$count = 1;
			$power = $i;
			continue;
		}
	}
}

fwrite(STDOUT, pow(2, $power).' '.$count.PHP_EOL);


Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right.Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting balls (one at a time) to the boxes with numbers i + 1, i + 2, i + 3 and so on. If Vasya puts a ball into the box number n, then the next ball goes to box 1, the next one goes to box 2 and so on. He did it until he had no balls left in his hands. It is possible that Vasya puts multiple balls to the same box, and it is also possible that one or more balls will go to the box number i. If i = n, Vasya puts the first ball into the box number 1, then the next ball goes to box 2 and so on. For example, let's suppose that initially Vasya had four boxes, and the first box had 3 balls, the second one had 2, the third one had 5 and the fourth one had 4 balls. Then, if i = 3, then Vasya will take all five balls out of the third box and put them in the boxes with numbers: 4, 1, 2, 3, 4. After all Vasya's actions the balls will lie in the boxes as follows: in the first box there are 4 balls, 3 in the second one, 1 in the third one and 6 in the fourth one.At this point Vasya has completely forgotten the original arrangement of the balls in the boxes, but he knows how they are arranged now, and the number x — the number of the box, where he put the last of the taken out balls.He asks you to help to find the initial arrangement of the balls in the boxes.

The first line of the input contains two integers n and x (2 ≤ n ≤ 105, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a1, a2, ..., an, where integer ai (0 ≤ ai ≤ 109, ax ≠ 0) represents the number of balls in the box with index i after Vasya completes all the actions.  Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them.


«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.

The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.

Output the required default value for the next test index.

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

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


You have a board represented as a grid with $$$2 \times n$$$ cells.The first $$$k_1$$$ cells on the first row and first $$$k_2$$$ cells on the second row are colored in white. All other cells are colored in black.You have $$$w$$$ white dominoes ($$$2 \times 1$$$ tiles, both cells are colored in white) and $$$b$$$ black dominoes ($$$2 \times 1$$$ tiles, both cells are colored in black).You can place a white domino on the board if both board's cells are white and not occupied by any other domino. In the same way, you can place a black domino if both cells are black and not occupied by any other domino.Can you place all $$$w + b$$$ dominoes on the board if you can place dominoes both horizontally and vertically?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$k_1$$$ and $$$k_2$$$ ($$$1 \le n \le 1000$$$; $$$0 \le k_1, k_2 \le n$$$). The second line of each test case contains two integers $$$w$$$ and $$$b$$$ ($$$0 \le w, b \le n$$$).

For each test case, print YES if it's possible to place all $$$w + b$$$ dominoes on the board and NO, otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

NoteIn the first test case, $$$n = 1$$$, $$$k_1 = 0$$$ and $$$k_2 = 1$$$. It means that $$$2 \times 1$$$ board has black cell $$$(1, 1)$$$ and white cell $$$(2, 1)$$$. So, you can't place any white domino, since there is only one white cell.In the second test case, the board of the same size $$$2 \times 1$$$, but both cell are white. Since $$$w = 0$$$ and $$$b = 0$$$, so you can place $$$0 + 0 = 0$$$ dominoes on the board.In the third test case, board $$$2 \times 3$$$, but fully colored in black (since $$$k_1 = k_2 = 0$$$), so you can't place any white domino.In the fourth test case, cells $$$(1, 1)$$$, $$$(1, 2)$$$, $$$(1, 3)$$$, and $$$(2, 1)$$$ are white and other cells are black. You can place $$$2$$$ white dominoes at positions $$$((1, 1), (2, 1))$$$ and $$$((1, 2), (1, 3))$$$ and $$$2$$$ black dominoes at positions $$$((1, 4), (2, 4))$$$ $$$((2, 2), (2, 3))$$$.

<?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
	$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
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

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

}


Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases by $$$1$$$. If he manages to finish the level successfully then the number of clears increases by $$$1$$$ as well. Note that both of the statistics update at the same time (so if the player finishes the level successfully then the number of plays will increase at the same time as the number of clears).Polycarp is very excited about his level, so he keeps peeking at the stats to know how hard his level turns out to be.So he peeked at the stats $$$n$$$ times and wrote down $$$n$$$ pairs of integers — $$$(p_1, c_1), (p_2, c_2), \dots, (p_n, c_n)$$$, where $$$p_i$$$ is the number of plays at the $$$i$$$-th moment of time and $$$c_i$$$ is the number of clears at the same moment of time. The stats are given in chronological order (i.e. the order of given pairs is exactly the same as Polycarp has written down).Between two consecutive moments of time Polycarp peeked at the stats many players (but possibly zero) could attempt the level.Finally, Polycarp wonders if he hasn't messed up any records and all the pairs are correct. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then he considers his records correct.Help him to check the correctness of his records.For your convenience you have to answer multiple independent test cases.

The first line contains a single integer $$$T$$$ $$$(1 \le T \le 500)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of moments of time Polycarp peeked at the stats. Each of the next $$$n$$$ lines contains two integers $$$p_i$$$ and $$$c_i$$$ ($$$0 \le p_i, c_i \le 1000$$$) — the number of plays and the number of clears of the level at the $$$i$$$-th moment of time. Note that the stats are given in chronological order.

For each test case print a single line. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then print "YES". Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first test case at the third moment of time the number of clears increased but the number of plays did not, that couldn't have happened.The second test case is a nice example of a Super Expert level.In the third test case the number of plays decreased, which is impossible.The fourth test case is probably an auto level with a single jump over the spike.In the fifth test case the number of clears decreased, which is also impossible.Nobody wanted to play the sixth test case; Polycarp's mom attempted it to make him feel better, however, she couldn't clear it.

<?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
    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
$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" ;
    }
?>


Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai  ≤  bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!

The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans.

Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower).

NoteIn the first sample, there are already 2 cans, so the answer is "YES".

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


You are given an array $$$a_1, a_2, \dots , a_n$$$. Array is good if for each pair of indexes $$$i < j$$$ the condition $$$j - a_j \ne i - a_i$$$ holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).For example, if $$$a = [1, 1, 3, 5]$$$, then shuffled arrays $$$[1, 3, 5, 1]$$$, $$$[3, 5, 1, 1]$$$ and $$$[5, 3, 1, 1]$$$ are good, but shuffled arrays $$$[3, 1, 5, 1]$$$, $$$[1, 1, 3, 5]$$$ and $$$[1, 1, 5, 3]$$$ aren't.It's guaranteed that it's always possible to shuffle an array to meet this condition.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 100$$$).

For each test case print the shuffled version of the array $$$a$$$ which is good.

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

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


You are given two integers $$$n$$$ and $$$k$$$.You should create an array of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ such that the sum $$$(a_1 + a_2 + \dots + a_n)$$$ is divisible by $$$k$$$ and maximum element in $$$a$$$ is minimum possible.What is the minimum possible maximum element in $$$a$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^9$$$; $$$1 \le k \le 10^9$$$).

For each test case, print one integer — the minimum possible maximum element in array $$$a$$$ such that the sum $$$(a_1 + \dots + a_n)$$$ is divisible by $$$k$$$.

NoteIn the first test case $$$n = 1$$$, so the array consists of one element $$$a_1$$$ and if we make $$$a_1 = 5$$$ it will be divisible by $$$k = 5$$$ and the minimum possible.In the second test case, we can create array $$$a = [1, 2, 1, 2]$$$. The sum is divisible by $$$k = 3$$$ and the maximum is equal to $$$2$$$.In the third test case, we can create array $$$a = [1, 1, 1, 1, 1, 1, 1, 1]$$$. The sum is divisible by $$$k = 8$$$ and the maximum is equal to $$$1$$$.

<?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
$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
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

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

$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) {
            $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));
    }
}


This problem is actually a subproblem of problem G from the same contest.There are $$$n$$$ candies in a candy box. The type of the $$$i$$$-th candy is $$$a_i$$$ ($$$1 \le a_i \le n$$$).You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type $$$1$$$ and two candies of type $$$2$$$ is bad). It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift.Your task is to find out the maximum possible size of the single gift you can prepare using the candies you have.You have to answer $$$q$$$ independent queries.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Each query is represented by two lines. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of candies. The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the type of the $$$i$$$-th candy in the box. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.

For each query print one integer — the maximum possible size of the single gift you can compose using candies you got in this query with the restriction described in the problem statement.

NoteIn the first query, you can prepare a gift with two candies of type $$$8$$$ and one candy of type $$$5$$$, totalling to $$$3$$$ candies.Note that this is not the only possible solution — taking two candies of type $$$4$$$ and one candy of type $$$6$$$ is also valid.

<?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
    $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";
    }


You are given a following process. There is a platform with $$$n$$$ columns. $$$1 \times 1$$$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column. When all of the $$$n$$$ columns have at least one square in them, the bottom row is being removed. You will receive $$$1$$$ point for this, and all the squares left will fall down one row. You task is to calculate the amount of points you will receive.

The first line of input contain 2 integer numbers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the length of the platform and the number of the squares. The next line contain $$$m$$$ integer numbers $$$c_1, c_2, \dots, c_m$$$ ($$$1 \le c_i \le n$$$) — column in which $$$i$$$-th square will appear.

Print one integer — the amount of points you will receive.

NoteIn the sample case the answer will be equal to $$$2$$$ because after the appearing of $$$6$$$-th square will be removed one row (counts of the squares on the platform will look like $$$[2~ 3~ 1]$$$, and after removing one row will be $$$[1~ 2~ 0]$$$).After the appearing of $$$9$$$-th square counts will be $$$[2~ 3~ 1]$$$, and after removing one row it will look like $$$[1~ 2~ 0]$$$.So the answer will be equal to $$$2$$$.

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

$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(" ", trim(fgets(STDIN)));

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

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

    echo "\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";


In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.

The first line contains three integers n, m, k (1 ≤ m ≤ n ≤ 1000, 0 ≤ k ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow n lines, each containing two integers: r (1 ≤ r ≤ m) — index of the row, where belongs the corresponding tooth, and c (0 ≤ c ≤ 106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth.

In the first line output the maximum amount of crucians that Valerie can consume for dinner.

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


There is a river of width $$$n$$$. The left bank of the river is cell $$$0$$$ and the right bank is cell $$$n + 1$$$ (more formally, the river can be represented as a sequence of $$$n + 2$$$ cells numbered from $$$0$$$ to $$$n + 1$$$). There are also $$$m$$$ wooden platforms on a river, the $$$i$$$-th platform has length $$$c_i$$$ (so the $$$i$$$-th platform takes $$$c_i$$$ consecutive cells of the river). It is guaranteed that the sum of lengths of platforms does not exceed $$$n$$$.You are standing at $$$0$$$ and want to reach $$$n+1$$$ somehow. If you are standing at the position $$$x$$$, you can jump to any position in the range $$$[x + 1; x + d]$$$. However you don't really like the water so you can jump only to such cells that belong to some wooden platform. For example, if $$$d=1$$$, you can jump only to the next position (if it belongs to the wooden platform). You can assume that cells $$$0$$$ and $$$n+1$$$ belong to wooden platforms.You want to know if it is possible to reach $$$n+1$$$ from $$$0$$$ if you can move any platform to the left or to the right arbitrary number of times (possibly, zero) as long as they do not intersect each other (but two platforms can touch each other). It also means that you cannot change the relative order of platforms.Note that you should move platforms until you start jumping (in other words, you first move the platforms and then start jumping).For example, if $$$n=7$$$, $$$m=3$$$, $$$d=2$$$ and $$$c = [1, 2, 1]$$$, then one of the ways to reach $$$8$$$ from $$$0$$$ is follow:    The first example: $$$n=7$$$.

The first line of the input contains three integers $$$n$$$, $$$m$$$ and $$$d$$$ ($$$1 \le n, m, d \le 1000, m \le n$$$) — the width of the river, the number of platforms and the maximum distance of your jump, correspondingly. The second line of the input contains $$$m$$$ integers $$$c_1, c_2, \dots, c_m$$$ ($$$1 \le c_i \le n, \sum\limits_{i=1}^{m} c_i \le n$$$), where $$$c_i$$$ is the length of the $$$i$$$-th platform.

If it is impossible to reach $$$n+1$$$ from $$$0$$$, print NO in the first line. Otherwise, print YES in the first line and the array $$$a$$$ of length $$$n$$$ in the second line — the sequence of river cells (excluding cell $$$0$$$ and cell $$$n + 1$$$). If the cell $$$i$$$ does not belong to any platform, $$$a_i$$$ should be $$$0$$$. Otherwise, it should be equal to the index of the platform ($$$1$$$-indexed, platforms are numbered from $$$1$$$ to $$$m$$$ in order of input) to which the cell $$$i$$$ belongs. Note that all $$$a_i$$$ equal to $$$1$$$ should form a contiguous subsegment of the array $$$a$$$ of length $$$c_1$$$, all $$$a_i$$$ equal to $$$2$$$ should form a contiguous subsegment of the array $$$a$$$ of length $$$c_2$$$, ..., all $$$a_i$$$ equal to $$$m$$$ should form a contiguous subsegment of the array $$$a$$$ of length $$$c_m$$$. The leftmost position of $$$2$$$ in $$$a$$$ should be greater than the rightmost position of $$$1$$$, the leftmost position of $$$3$$$ in $$$a$$$ should be greater than the rightmost position of $$$2$$$, ..., the leftmost position of $$$m$$$ in $$$a$$$ should be greater than the rightmost position of $$$m-1$$$. See example outputs for better understanding.

NoteConsider the first example: the answer is $$$[0, 1, 0, 2, 2, 0, 3]$$$. The sequence of jumps you perform is $$$0 \rightarrow 2 \rightarrow 4 \rightarrow 5 \rightarrow 7 \rightarrow 8$$$.Consider the second example: it does not matter how to place the platform because you always can jump from $$$0$$$ to $$$11$$$.Consider the third example: the answer is $$$[0, 0, 0, 0, 1, 1, 0, 0, 0, 0]$$$. The sequence of jumps you perform is $$$0 \rightarrow 5 \rightarrow 6 \rightarrow 11$$$.

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