n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.You have to write a program which prints the number of the child to be eliminated on every step.

The first line contains two integer numbers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1). The next line contains k integer numbers a1, a2, ..., ak (1 ≤ ai ≤ 109).

Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step.

NoteLet's consider first example:   In the first step child 4 is eliminated, child 5 becomes the leader.  In the second step child 2 is eliminated, child 3 becomes the leader.  In the third step child 5 is eliminated, child 6 becomes the leader.  In the fourth step child 6 is eliminated, child 7 becomes the leader.  In the final step child 1 is eliminated, child 3 becomes the leader.


One day, Ahmed_Hossam went to Hemose and said "Let's solve a gym contest!". Hemose didn't want to do that, as he was playing Valorant, so he came up with a problem and told it to Ahmed to distract him. Sadly, Ahmed can't solve it... Could you help him?There is an Agent in Valorant, and he has $$$n$$$ weapons. The $$$i$$$-th weapon has a damage value $$$a_i$$$, and the Agent will face an enemy whose health value is $$$H$$$.The Agent will perform one or more moves until the enemy dies.In one move, he will choose a weapon and decrease the enemy's health by its damage value. The enemy will die when his health will become less than or equal to $$$0$$$. However, not everything is so easy: the Agent can't choose the same weapon for $$$2$$$ times in a row.What is the minimum number of times that the Agent will need to use the weapons to kill the enemy?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 10^5)$$$. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$H$$$ $$$(2 \leq n \leq 10^3, 1 \leq H \leq 10^9)$$$ — the number of available weapons and the initial health value of the enemy. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \leq a_i \leq 10^9)$$$ — the damage values of the weapons. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print a single integer — the minimum number of times that the Agent will have to use the weapons to kill the enemy.

NoteIn the first test case, the Agent can use the second weapon, making health value of the enemy equal to $$$4-7=-3$$$. $$$-3 \le 0$$$, so the enemy is dead, and using weapon $$$1$$$ time was enough.In the second test case, the Agent can use the first weapon first, and then the second one. After this, the health of enemy will drop to $$$6-4-2 = 0$$$, meaning he would be killed after using weapons $$$2$$$ times.In the third test case, the Agent can use the weapons in order (third, first, third), decreasing the health value of enemy to $$$11 - 7 - 2 - 7 = -5$$$ after using the weapons $$$3$$$ times. Note that we can't kill the enemy by using the third weapon twice, as even though $$$11-7-7<0$$$, it's not allowed to use the same weapon twice in a row.

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";

  $t = getT();
  for($q=0; $q <$t; $q++) {
      $res = 0;
      list($n, $h) = getA();
      $a = getA();

      if($n == 1 && $h <= $a[0]) {
        $res = 1;
      } else {
          sort($a);
          $max = $a[$n-1];
          $max2 = $a[$n-2];
          if( $h <= $max) {
            $res = 1;
          } else {
              $res = floor($h / ($max + $max2)) * 2;
              $kaldyk = $h % ($max + $max2);
              if($kaldyk > 0  ) {
                  if($kaldyk <= $max) {
                      $res += 1;
                  } else {
                      $res += 2;
                  }
              }
          }

      }
      echo $res, $inter;
  }

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

  function is_prime($n) {
    $d = 2;
    while ($n % $d != 0) {
    	 $d += 1;
    }

    return $d == $n;
}

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

  for($q=0; $q <$t; $q++) {
      list($n, $h) = explode(' ', trim(fgets(STDIN)));
      $a = explode(' ', trim(fgets(STDIN)));
      sort($a);
      $res = 0;
      $max = $a[$n-1];
      if($max >= $h) {
          $res = 1;
      } else {
          $res = ceil($h / (($max + $a[$n-2])/2));
      }

      echo $res . "\n";

  }

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

  for($q=0; $q <$t; $q++) {
      list($n, $h) = explode(' ', trim(fgets(STDIN)));
      $a = explode(' ', trim(fgets(STDIN)));
      arsort($a);
      $res = 0;
      $el = 0;
      while($h>0) {
          $res++;
         if($el == 0 ){
             $h = $h - $a[0];

             $el = 1;
         } else {
             $h = $h - $a[1];

             $el = 0;
         }
      }

      echo $res . "\n";
  }


A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand. One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed.

The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer a (1 ≤ a ≤ 2) which denotes the number of the rail at which the person was holding.

Print character "R" if the VIP is right-handed or "L" if he is left-handed.

<?php
$file=file("input.txt");
    $direction=trim($file[0]);
    $dver=trim($file[1]);

if ($direction=="front")
    if($dver==1) $pos = "L"; else $pos = "R";
if ($direction=="back")
   if($dver==1) $pos = "R"; else $pos = "L";

     $File = "output.txt";
 $Handle = fopen($File, 'w');
 fwrite($Handle, $pos);
?>

<?php
$input = fopen("input.txt","r");
$output = fopen("output.txt","w");
while(($line = fgets($input)) == true) {
$data[0] = sscanf($line, "%s");
if ($data[0] == "")break;
$line = fgets($input);
$data[1] = sscanf($line, "%d");
//echo $data[0] . " " . $data[1] . "\n";
if ($data[0][0] == "front")$data[1][0]++;
$data[1][0] = $data[1][0]%2;
if ($data[1][0] == 1)$res = "R\n";
else $res = "L\n";
fwrite($output, $res);
}
fclose($input);
fclose($output);
?>

<?
$lines=file_get_contents("input.txt");
$lines = trim($lines);

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

$dir=trim($lines[0]);
$por=trim($lines[1]);

if ($dir=="front")
    $res=($por==1)?"L":"R";
if ($dir=="back")
    $res=($por==1)?"R":"L";
file_put_contents("output.txt", $res);
?>

<?php
$file=file("input.txt");
    $direction=explode(" ",$file[0]);
    $dver=explode(" ",$file[1]);

if ($direction=="front")
    if($dver==1) $pos = "L"; else $pos = "R";
if ($direction=="back")
   if($dver==1) $pos = "R"; else $pos = "L";

     $File = "output.txt";
 $Handle = fopen($File, 'w');
 fwrite($Handle, $pos);
?>

<?php
$input = fopen("input.txt","r");
$output = fopen("output.txt","w");
while(($line = fgets($input)) == true) {
$data = sscanf($line, "%s %d");
if ($data[0] == "")break;
if ($data[0] == "front")$data[1]++;
$data[1] = $data[1]%2;
if ($data[1] == 1)$res = "L\n";
else $res = "R\n";
fwrite($output, $res);
}
fclose($input);
fclose($output);
?>


Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet:  if the letter number is single-digit number (less than $$$10$$$), then just writes it out;  if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows:  'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3);  'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150);  'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504);  'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$).

The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained.

For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique.

code
aj
abacaba
ll
codeforces
aaaak
aaaaj
aaaaa
zf

NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120.

<?php

$al = range('a', 'z');

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

$totalScan = 0;
$totalProc = 0;
$totalPrint = 0;

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

    $start = microtime(true);
    $chars = fscanf(STDIN, str_repeat('%c', $n));
    foreach ($chars as &$char) {
        $char = (int)$char;
    }
    unset($char);
    $totalScan += microtime(true) - $start;

    $res = [];

    $start = microtime(true);

    for ($i = 0; $i < $n; ++$i) {
        $char = $chars[$i];

        if ($char === 0) {
            if ($i + 1 < $n && $chars[$i + 1] === 0) {
                $res[] = $char;
            } else {
                $last = array_pop($res);
                $num = array_pop($res);

                $res [] = $num * 10 + $last;
            }
        } else {
            $res[] = $char;
        }
    }

    $totalProc += microtime(true) - $start;

    $start = microtime(true);
    $out = [];
    foreach ($res as $it) {
        $out[] = $al[$it - 1];
    }
    echo implode('', $out).PHP_EOL;

    $totalPrint += microtime(true) - $start;
}

//var_dump($totalScan, $totalProc, $totalPrint);

/*

315045

5 4 15

9
6
315045
4
1100
7
1213121
6
120120
18
315045615018035190
7
1111110
7
1111100
5
11111
4
2606

 */


You have a statistic of price changes for one product represented as an array of $$$n$$$ positive integers $$$p_0, p_1, \dots, p_{n - 1}$$$, where $$$p_0$$$ is the initial price of the product and $$$p_i$$$ is how the price was increased during the $$$i$$$-th month.Using these price changes you are asked to calculate the inflation coefficients for each month as the ratio of current price increase $$$p_i$$$ to the price at the start of this month $$$(p_0 + p_1 + \dots + p_{i - 1})$$$.Your boss said you clearly that the inflation coefficients must not exceed $$$k$$$ %, so you decided to increase some values $$$p_i$$$ in such a way, that all $$$p_i$$$ remain integers and the inflation coefficients for each month don't exceed $$$k$$$ %.You know, that the bigger changes — the more obvious cheating. That's why you need to minimize the total sum of changes.What's the minimum total sum of changes you need to make all inflation coefficients not more than $$$k$$$ %?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 100$$$; $$$1 \le k \le 100$$$) — the length of array $$$p$$$ and coefficient $$$k$$$. The second line of each test case contains $$$n$$$ integers $$$p_0, p_1, \dots, p_{n - 1}$$$ ($$$1 \le p_i \le 10^9$$$) — the array $$$p$$$.

For each test case, print the minimum total sum of changes you need to make all inflation coefficients not more than $$$k$$$ %.

NoteIn the first test case, you can, for example, increase $$$p_0$$$ by $$$50$$$ and $$$p_1$$$ by $$$49$$$ and get array $$$[20150, 50, 202, 202]$$$. Then you get the next inflation coefficients:   $$$\frac{50}{20150} \le \frac{1}{100}$$$;  $$$\frac{202}{20150 + 50} \le \frac{1}{100}$$$;  $$$\frac{202}{20200 + 202} \le \frac{1}{100}$$$; In the second test case, you don't need to modify array $$$p$$$, since the inflation coefficients are already good:   $$$\frac{1}{1} \le \frac{100}{100}$$$;  $$$\frac{1}{1 + 1} \le \frac{100}{100}$$$;

<?php

$times = (int)trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($ni[], $ki[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}

for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $k = &$ki[$idx];
    $a = &$ai[$idx];

    $sm = 0;
    $mx = 0;
    for ($i = 0; $i < $n - 1; ++$i) {
        $sm += $a[$i];
        $tmp = ceil(100 * $a[$i + 1] / $k - $sm);
        $mx < $tmp && $mx = $tmp;
    }
    echo $mx . PHP_EOL;
}

<?php

$times = (int)trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($ni[], $ki[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}

for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $k = &$ki[$idx];
    $a = &$ai[$idx];

    $sm = 0;
    $mx = 0;
    for ($i = 0; $i < $n - 1; ++$i) {
        $sm += $a[$i];
        $tmp = 100 * $a[$i + 1] / $k - $sm;
        $mx < $tmp && $mx = $tmp;
    }
    echo $mx . PHP_EOL;
}


It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known that character "*" occurs no more than once in the pattern.Also, n query strings are given, it is required to determine for each of them if the pattern matches it or not.Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning.A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string.The good letters are given to Petya. All the others are bad.

The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad. The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 105). It is guaranteed that character "*" occurs in s no more than once. The third line contains integer n (1 ≤ n ≤ 105) — the number of query strings. n lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string. It is guaranteed that the total length of all query strings is not greater than 105.

Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrary.

NoteIn the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.Explanation of the second example.   The first query: "NO", because character "*" can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string "ba", in which both letters are good.  The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "*" can be replaced with empty string, and the strings will coincide.  The third query: "NO", because characters "?" can't be replaced with bad letters.  The fourth query: "YES", because characters "?" can be replaced with good letters "a", and character "*" can be replaced with a string of bad letters "x".

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
for ($i = 0; $i < $c; $i++) {
    $d[$i] = trim(fgets(STDIN));
}
for ($k = 0; $k < $c; $k++) {
    $j = 0;
    $flag = true;
    for ($i = 0; $i < strlen($b); $i++) {
        if ($j == strlen($d[$k]) and $b[$i] != '*') {
            print "No\n";
            $flag = false;
            break;
        }
        if ($b[$i] == '?') {
            if (strpos($a, $d[$k][$j]) === false) {
                print "No\n";
                $flag = false;
                break;
            }
            $j++;
        } elseif ($b[$i] == '*') {
            $n = strlen($d[$k]) - strlen($b) + 1;
            if ($n < 0) {
                print "No\n";
                $flag = false;
                break;
            } else {
                for ($p = 0; $p < $n; $p++) {
                    if (strpos($a, $d[$k][$j]) !== false) {
                        print "No\n";
                        $flag = false;
                        break 2;
                    }
                    $j++;
                }
            }
        } else {
            if ($d[$k][$j] != $b[$i]) {
                print "No\n";
                $flag = false;
                break;
            }
            $j++;
        }
    }
    if ($flag) {
        if ($j == strlen($d[$k])) {
            print "Yes\n";
        } else {
            print "No\n";
        }
    }
}
?>


You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.You have to color this array in $$$k$$$ colors in such a way that:   Each element of the array should be colored in some color;  For each $$$i$$$ from $$$1$$$ to $$$k$$$ there should be at least one element colored in the $$$i$$$-th color in the array;  For each $$$i$$$ from $$$1$$$ to $$$k$$$ all elements colored in the $$$i$$$-th color should be distinct. Obviously, such coloring might be impossible. In this case, print "NO". Otherwise print "YES" and any coloring (i.e. numbers $$$c_1, c_2, \dots c_n$$$, where $$$1 \le c_i \le k$$$ and $$$c_i$$$ is the color of the $$$i$$$-th element of the given array) satisfying the conditions above. If there are multiple answers, you can print any.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the length of the array $$$a$$$ and the number of colors, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 5000$$$) — elements of the array $$$a$$$.

If there is no answer, print "NO". Otherwise print "YES" and any coloring (i.e. numbers $$$c_1, c_2, \dots c_n$$$, where $$$1 \le c_i \le k$$$ and $$$c_i$$$ is the color of the $$$i$$$-th element of the given array) satisfying the conditions described in the problem statement. If there are multiple answers, you can print any.

NoteIn the first example the answer $$$2~ 1~ 2~ 1$$$ is also acceptable.In the second example the answer $$$1~ 1~ 1~ 2~ 2$$$ is also acceptable.There exist other acceptable answers for both examples.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array();
for($x = 0; $x < $a; $x++)
{
     $d[$c[$x]]++;
}
$e = max($d);
if($e > $b)
{
     print "NO";
}
else
{
     print "YES\n";
     asort($c);
     $f = array_keys($c);
     $g = 1;
     for($x = 0; $x < $a; $x++)
     {
          if($g > $b)
          {
               $g = 1;
          }
          $c[$f[$x]] = $g;
          $g++;
     }
     ksort($c);
     print implode(" ", $c);
}
?>

<?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 readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

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

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

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

$ir = new InputReader();

/* TASK */

list($n, $k) = $ir->readArrayOfInt(2);
$a = $ir->readArrayOfInt($n);
$b = [];

for ($i=0; $i<$n; $i++) {
	if (!isset($b[$a[$i]])) {
		$b[$a[$i]] = [];
	}

	$b[$a[$i]][] = $i;
}

$d = 0;
$cs = $a;
foreach ($b as $v=>$g) {
	if (count($g) > $k) {
		echo "NO";
		exit();
	}

	foreach ($g as $ind) {
		$cs[$ind] = ($d%$k)+1;
		$d++;
	}
}

if ($d>=$k) {
	echo "YES\n";
	echo implode(' ', $cs);
} else {
	echo "NO\n";
}

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

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

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

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

$ir = new InputReader();

/* TASK */

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

$cs = [];
for ($i=0; $i<$n; $i++) {
	if (!isset($cs[$a[$i]])) {
		$cs[$a[$i]] = 1;
	}

	$cs[$a[$i]]++;
	$a[$i] = $cs[$a[$i]]-1;
}

$m = max($cs);
if ($m==$k+1) {
	echo "YES\n";
	echo implode(' ', $a);
} else {
	echo "NO\n";
}


In the $$$2022$$$ year, Mike found two binary integers $$$a$$$ and $$$b$$$ of length $$$n$$$ (both of them are written only by digits $$$0$$$ and $$$1$$$) that can have leading zeroes. In order not to forget them, he wanted to construct integer $$$d$$$ in the following way:   he creates an integer $$$c$$$ as a result of bitwise summing of $$$a$$$ and $$$b$$$ without transferring carry, so $$$c$$$ may have one or more $$$2$$$-s. For example, the result of bitwise summing of $$$0110$$$ and $$$1101$$$ is $$$1211$$$ or the sum of $$$011000$$$ and $$$011000$$$ is $$$022000$$$;  after that Mike replaces equal consecutive digits in $$$c$$$ by one digit, thus getting $$$d$$$. In the cases above after this operation, $$$1211$$$ becomes $$$121$$$ and $$$022000$$$ becomes $$$020$$$ (so, $$$d$$$ won't have equal consecutive digits). Unfortunately, Mike lost integer $$$a$$$ before he could calculate $$$d$$$ himself. Now, to cheer him up, you want to find any binary integer $$$a$$$ of length $$$n$$$ such that $$$d$$$ will be maximum possible as integer.Maximum possible as integer means that $$$102 > 21$$$, $$$012 < 101$$$, $$$021 = 21$$$ and so on.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of $$$a$$$ and $$$b$$$. The second line of each test case contains binary integer $$$b$$$ of length $$$n$$$. The integer $$$b$$$ consists only of digits $$$0$$$ and $$$1$$$. It is guaranteed that the total sum of $$$n$$$ over all $$$t$$$ test cases doesn't exceed $$$10^5$$$.

For each test case output one binary integer $$$a$$$ of length $$$n$$$. Note, that $$$a$$$ or $$$b$$$ may have leading zeroes but must have the same length $$$n$$$.

NoteIn the first test case, $$$b = 0$$$ and choosing $$$a = 1$$$ gives $$$d = 1$$$ as a result.In the second test case, $$$b = 011$$$ so:   if you choose $$$a = 000$$$, $$$c$$$ will be equal to $$$011$$$, so $$$d = 01$$$;  if you choose $$$a = 111$$$, $$$c$$$ will be equal to $$$122$$$, so $$$d = 12$$$;  if you choose $$$a = 010$$$, you'll get $$$d = 021$$$.  If you select $$$a = 110$$$, you'll get $$$d = 121$$$.  We can show that answer $$$a = 110$$$ is optimal and $$$d = 121$$$ is maximum possible.In the third test case, $$$b = 110$$$. If you choose $$$a = 100$$$, you'll get $$$d = 210$$$ and it's the maximum possible $$$d$$$.In the fourth test case, $$$b = 111000$$$. If you choose $$$a = 101101$$$, you'll get $$$d = 212101$$$ and it's maximum possible $$$d$$$.In the fifth test case, $$$b = 001011$$$. If you choose $$$a = 101110$$$, you'll get $$$d = 102121$$$ and it's maximum possible $$$d$$$.

<?php

/**
 * Соревнование http://codeforces.com/contest/1474
 */

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

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

for ($i=0; $i<$rowsNumber; $i++) {
    $n = trim(fgets($file));

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

    $string = "";

    for($y=0; $y<$n; $y++) {
        if ($y == 0) {
            $b[$y] = $b[$y] + 1;

            $string .= 1;

            continue;
        }

        if ($b[$y-1] != $b[$y] + 1 ) {
            $b[$y] = $b[$y] + 1;

            $string .= 1;

            continue;
        }

        $string .= 0;
    }

    echo $string;
    echo PHP_EOL;
}

<?php

$t = (int) trim(fgets(STDIN));
for ($i = 0; $i < $t; ++$i) {
    $n[] = (int) trim(fgets(STDIN));
    $b[] = trim(fgets(STDIN));
}
for ($i = 0; $i < $t; ++$i) {
    $ni = $n[$i];
    $bi = $b[$i];
    $bilen = strlen($bi);
    $a[0] = 1;
    $d = $bi[0] + 1;
    for ($j = 1; $j < $bilen; ++$j) {
        switch ($d) {
            case 2:
                $a[$j] = 1 - $bi[$j];
                break;
            case 1:
                $a[$j] = $bi[$j];
                break;
            default:
                $a[$j] = 1;
        }
        $d = $a[$j] + $bi[$j];
    }
    echo implode($a), PHP_EOL;
}

<?php
function solve() {
    $n = Read::int();
    $b = trim(fgets(STDIN));
    $res = '1';
    $a = [$b[0] + 1];
    for ($i = 1; $i < $n; $i++) {
        $count = intval($b[$i]) + 1;
        if ($count == $a[$i-1]) {
            $a[] = intval($b[$i]);
            $res .= '0';
        } else {
            $a[] = $count;
            $res .= '1';
        }
    }

    return $res;
}

#$t = 1;
$t = Read::int();
while ($t--) {
    echo solve();
    echo "\n";
}

class Read
{
    public static function string()
    {
        return trim(fgets(STDIN));
    }

    public static function int()
    {
        return intval(fgets(STDIN));
    }

    public static function array_int($sep = ' ')
    {
        $s = trim(fgets(STDIN));
        return preg_split("/[\s,]+/", $s);
    }

}

class Bigint
{
    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 / $bigint2
     */
    public static function div($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcmod($bigint1, $bigint2) == 0 ? bcdiv($bigint1, $bigint2) : bcadd(bcdiv($bigint1, $bigint2), 1);
            case 'floor':
                return bcdiv($bigint1, $bigint2);
            case 'round':
                $sResult = bcdiv($bigint1, $bigint2);
                return bcsub(bcdiv($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcdiv($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 + $bigint2
     */
    public static function add($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcadd($bigint1, $bigint2);
            case 'round':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcadd($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 - $bigint2
     */
    public static function sub($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcsub($bigint1, $bigint2);
            case 'round':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsub($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 * $bigint2
     */
    public static function mul($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcmul($bigint1, $bigint2);
            case 'round':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcmul ($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @return string $bigint1 % $bigint2
     */
    public static function mod($bigint1, $bigint2) {
        return bcmod($bigint1, $bigint2);
    }

    /**
     * @param string $bigint
     * @param string $scale (ceil or floor or round)
     * @return string sqrt($bigint)
     */
    public static function sqrt($bigint, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcadd(bcsqrt ($bigint), 1);
            case 'floor':
                return bcsqrt($bigint);
            case 'round':
                $sResult = bcsqrt($bigint);
                return bcsub(bcsqrt($bigint, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsqrt($bigint);
        }
    }

    /**
     * @param string $bigint
     * @param string $exponent
     * @param string $scale (ceil or floor or round)
     * @return string pow($bigint, $exponent)
     */
    public static function pow($bigint, $exponent, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcpow($bigint, $exponent);
            case 'round':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcpow ($bigint, $exponent);
        }
    }
}

class Algorithms
{

    /** Факторизация - Разложение числа на простые множители
     * @param int $n
     * @return array
     */
    public static function factorization($n)
    {
        $a = [];
        for ($i = 2; $i * $i <= $n; ++$i) {
            $cnt = 0;
            while (bcmod($n, $i) == 0) {
                ++$cnt;
                $n = bcdiv($n, $i);
            }
            if ($cnt > 0) {
                $a[$i] = $cnt;
            }
        }
        if ($n > 1) {
            $a[$n] = 1;
        }

        return $a;
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наибольший общий делитель (НОД)
     */
    public static function gcd($a, $b)
    {
        if ($b == 0) {
            return $a;
        } else {
            $a = $a % $b;
            return self::gcd($b, $a);
        }
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наименьшее общее кратное (НОК)
     */
    public static function lcm($a, $b)
    {
        return abs($a * $b) / self::gcd($a, $b);
    }

    /**Последовательность Фибоначчи =  0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987
     * return Фибоначчи{n}
     * @param int $n
     * @return int
     */
    public static function fibonacci($n)
    {
        $a = [0, 1];

        for ($i = 2; $i <= $n; $i++) {
            $a[$i] = $a[$i-1] + $a[$i-2];
        }

        return $a[$n];
    }

}

?>

<?php
$t = (int)fgets(STDIN);
for($i=0;$i<$t;$i++)
{
	$n = (int)fgets(STDIN);
	$b = trim(fgets(STDIN));
	$arr = str_split($b);
	$a = '';
	$LAST = -1;
	foreach($arr as $key => $value)
	{
		if($LAST == -1 || $LAST == 0)
			$X = 1;
		else if($LAST == 1)
		{
			if($value == 1)
				$X = 1;
			else
				$X = 0;
		}
		else if($LAST == 2)
		{
			if($value == 1)
				$X = 0;
			else
				$X = 1;
		}
		$a .= $X;
		$LAST = $value + $X;
	}
	print($a."\n");
}
//$end = readline();
?>

<?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 'NO' . PHP_EOL; }
    public static function no() { echo 'YES' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
}

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $b = str_split(IO::str());
    $last = -1;
    $res = '';
    for ($i = 0; $i < $n; $i++) {
        $r = 1;
        if ($last != -1) {
           if ($last == $r + $b[$i]) {
               $r = 0;
           }
        }
        $res .= $r;
        $last = $b[$i] + $r;
    }
    IO::line($res);
}

<?php

/**
 * Соревнование http://codeforces.com/contest/1474
 */

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

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

for ($i=0; $i<$rowsNumber; $i++) {
    $n = trim(fgets($file));

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

    $array = str_split($b);

    for($y=0; $y<$n; $y++) {
        if ($y == 0) {
            $array[$y] ++;

            continue;
        }

        if ($array[$y-1] != $array[$y] + 1 ) {
            $array[$y] ++;

            continue;
        }
    }

    $c = implode("", $array);

    printf("%0.0f", $c - $b);
    echo PHP_EOL;
}

<?php

/**
 * Соревнование http://codeforces.com/contest/1474
 */

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

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

for ($i=0; $i<$rowsNumber; $i++) {
    $n = trim(fgets($file));

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

    $array = str_split($b);

    for($y=0; $y<$n; $y++) {
        if ($y == 0) {
            $array[$y] ++;

            continue;
        }

        if ($array[$y-1] != $array[$y] + 1 ) {
            $array[$y] ++;

            continue;
        }
    }

    $c = implode("", $array);

    echo ($c - $b).PHP_EOL;
}


You are given three integers $$$n$$$, $$$d$$$ and $$$k$$$.Your task is to construct an undirected tree on $$$n$$$ vertices with diameter $$$d$$$ and degree of each vertex at most $$$k$$$, or say that it is impossible.An undirected tree is a connected undirected graph with $$$n - 1$$$ edges.Diameter of a tree is the maximum length of a simple path (a path in which each vertex appears at most once) between all pairs of vertices of this tree.Degree of a vertex is the number of edges incident to this vertex (i.e. for a vertex $$$u$$$ it is the number of edges $$$(u, v)$$$ that belong to the tree, where $$$v$$$ is any other vertex of a tree).

The first line of the input contains three integers $$$n$$$, $$$d$$$ and $$$k$$$ ($$$1 \le n, d, k \le 4 \cdot 10^5$$$).

If there is no tree satisfying the conditions above, print only one word "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), and then print $$$n - 1$$$ lines describing edges of a tree satisfying the conditions above. Vertices of the tree must be numbered from $$$1$$$ to $$$n$$$. You can print edges and vertices connected by an edge in any order. If there are multiple answers, print any of them.1


You are given an array $$$a[0 \ldots n-1]$$$ of length $$$n$$$ which consists of non-negative integers. Note that array indices start from zero.An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all $$$i$$$ ($$$0 \le i \le n - 1$$$) the equality $$$i \bmod 2 = a[i] \bmod 2$$$ holds, where $$$x \bmod 2$$$ is the remainder of dividing $$$x$$$ by 2.For example, the arrays [$$$0, 5, 2, 1$$$] and [$$$0, 17, 0, 3$$$] are good, and the array [$$$2, 4, 6, 7$$$] is bad, because for $$$i=1$$$, the parities of $$$i$$$ and $$$a[i]$$$ are different: $$$i \bmod 2 = 1 \bmod 2 = 1$$$, but $$$a[i] \bmod 2 = 4 \bmod 2 = 0$$$.In one move, you can take any two elements of the array and swap them (these elements are not necessarily adjacent).Find the minimum number of moves in which you can make the array $$$a$$$ good, or say that this is not possible.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case starts with a line containing an integer $$$n$$$ ($$$1 \le n \le 40$$$) — the length of the array $$$a$$$. The next line contains $$$n$$$ integers $$$a_0, a_1, \ldots, a_{n-1}$$$ ($$$0 \le a_i \le 1000$$$) — the initial array.

For each test case, output a single integer — the minimum number of moves to make the given array $$$a$$$ good, or -1 if this is not possible.

NoteIn the first test case, in the first move, you can swap the elements with indices $$$0$$$ and $$$1$$$, and in the second move, you can swap the elements with indices $$$2$$$ and $$$3$$$.In the second test case, in the first move, you need to swap the elements with indices $$$0$$$ and $$$1$$$.In the third test case, you cannot make the array good.

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

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

        $odd_cnt = 0 ;
        $even_cnt = 0 ;
        $err_cnt = 0 ;

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

            if($arr[$i] & 1) $odd_cnt ++ ;
            else $even_cnt ++ ;

            if(($i&1) == 0 && ($arr[$i]&1) != 0 ) $err_cnt ++ ;
        }

        $t_odd_cnt = intval($n / 2) ;
        $t_event_cnt = $n - $t_odd_cnt ;

        if($t_odd_cnt != $odd_cnt || $t_event_cnt != $even_cnt) echo "-1\n" ;
        else echo $err_cnt . "\n" ;
    }
?>


A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.Ahcl wants to construct a beautiful string. He has a string $$$s$$$, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!More formally, after replacing all characters '?', the condition $$$s_i \neq s_{i+1}$$$ should be satisfied for all $$$1 \leq i \leq |s| - 1$$$, where $$$|s|$$$ is the length of the string $$$s$$$.

The first line contains positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Next $$$t$$$ lines contain the descriptions of test cases. Each line contains a non-empty string $$$s$$$ consisting of only characters 'a', 'b', 'c' and '?'.  It is guaranteed that in each test case a string $$$s$$$ has at least one character '?'. The sum of lengths of strings $$$s$$$ in all test cases does not exceed $$$10^5$$$.

For each test case given in the input print the answer in the following format:   If it is impossible to create a beautiful string, print "-1" (without quotes);  Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.

NoteIn the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.In the second test case, it is impossible to create a beautiful string, because the $$$4$$$-th and $$$5$$$-th characters will be always equal.In the third test case, the only answer is "acbac".

<?php

// your code goes here

function getAllowed($arr, $i) {
	$avail = ['a' => true, 'b' => true, 'c' => true];
	if($i > 0) {
		if(isset($avail[$arr[$i - 1]])) {
			unset($avail[$arr[$i - 1]]);
		}
	}

	if($i < (strlen($arr) - 1)) {
		$q = $arr[$i + 1];
		if(isset($avail[$q])) {
			unset($avail[$q]);
		}
	}
	return array_keys($avail)[0];
}

fgets(STDIN);

while($f = trim(fgets(STDIN))){
	$a = [];
	//$f = str_explode($f);
    for($i = 0; $i < strlen($f); $i++) {
    	if($f[$i] != "?") {
    		$a[] = $f[$i];
    		if($i === 0) {
    			continue;
    		}

    		if($f[$i - 1] == $f[$i]) {
    			$a = null;
    			break;
    		}
    	} else {
    		$f[$i] = getAllowed($f, $i);
    		$a[] = $f[$i];
    	}
    }

    echo ($a) ? implode('', $a) : "-1";
    echo PHP_EOL;
}

<?php

$n = intval(fgets(STDIN));
$i = 0;
while($i < $n)
{
    $current = fgets(STDIN);
    if(!checkNice($current))
        $res = -1;
    else
    {
        $res = makeNice($current);
    }
    $i++;
    echo $res."\n";
}

function checkNice($string)
{
    $chars = str_split($string);
    $prev = $chars[0];
    unset($chars[count($chars) - 1]);
    foreach($chars as $k => $val)
    {
        if($k == 0 || $val == "?") {
            if($val == "?") $prev = "?";
            continue;
        }

        if($val == $prev && $prev != "?")
            return false;
        $prev = $chars[$k];
    }
    return true;
}

function makeNice($string)
{
    $chars = str_split($string);
    unset($chars[count($chars) - 1]);
    $prev = "";
    $lastChanged = -1;
    foreach($chars as $k => $val)
    {
        if($val == "?")
        {
            $first = "a";
            if($k != count($chars) - 1)
                $last = $chars[$k + 1];
            else
                $last = $first;

            if($k == 0)
                $first = $last;
            else
                $first = $chars[$k - 1];

            $fl = array($first, $last);
            if(!in_array("a", $fl))
                $val = "a";
            if(!in_array("b", $fl))
                $val = "b";
            if(!in_array("c", $fl))
                $val = "c";

            $chars[$k] = $val;
        }
        $prev = $val;
    }
    return implode("", $chars);
}
?>

<?php

$n = intval(fgets(STDIN));
$i = 0;
while($i < $n)
{
    $current = fgets(STDIN);
    if(!checkNice($current))
        $res = -1;
    else
    {
        $res = makeNice($current);
    }
    $i++;
    echo $res."\n";
}

function checkNice($string)
{
    $chars = str_split($string);
    $prev = $chars[0];
    unset($chars[count($chars) - 1]);
    //print_r($chars);
    foreach($chars as $k => $val)
    {
        if($k == 0 || $val == "?") continue;
        //echo $val." ".$prev;
        if($val == $prev && $prev != "?")
            return false;
        $prev = $chars[$k];
    }
    return true;
}

function makeNice($string)
{
    $chars = str_split($string);
    unset($chars[count($chars) - 1]);
    $prev = "";
    $lastChanged = -1;
    foreach($chars as $k => $val)
    {
        if($val == "?")
        {
            /*switch($prev)
            {
                case "":
                    $val = "a";
                    break;
                case "a":
                    $val = "b";
                    break;
                case "b":
                    $val = "c";
                    break;
                case "c":
                    $val = "a";
                    break;
            }     */
            if($k == 0)
                $val = "a";
            else {
                $first = $chars[$k - 1];
                $last = $chars[$k + 1];

                $fl = array($first, $last);
                if(!in_array("a", $fl))
                    $val = "a";
                if(!in_array("b", $fl))
                    $val = "b";
                if(!in_array("c", $fl))
                    $val = "c";

            }
            $chars[$k] = $val;
        }
        $prev = $val;
    }
    return implode("", $chars);
}
?>

<?php

$n = intval(fgets(STDIN));
$i = 0;
while($i < $n)
{
    $current = fgets(STDIN);
    if(!checkNice($current))
        $res = -1;
    else
    {
        $res = makeNice($current);
    }
    $i++;
    echo $res."\n";
}

function checkNice($string)
{
    $chars = str_split($string);
    $prev = $chars[0];
    unset($chars[count($chars) - 1]);
    foreach($chars as $k => $val)
    {
        if($val == "?") $prev = "?";
        if($k == 0 || $val == "?") continue;

        if($val == $prev && $prev != "?")
            return false;
        $prev = $chars[$k];
    }
    return true;
}

function makeNice($string)
{
    $chars = str_split($string);
    unset($chars[count($chars) - 1]);
    $prev = "";
    $lastChanged = -1;
    foreach($chars as $k => $val)
    {
        if($val == "?")
        {
            if($k == 0)
                $val = "a";
            else {
                $first = $chars[$k - 1];
                $last = $chars[$k + 1];

                $fl = array($first, $last);
                if(!in_array("a", $fl))
                    $val = "a";
                if(!in_array("b", $fl))
                    $val = "b";
                if(!in_array("c", $fl))
                    $val = "c";

            }
            $chars[$k] = $val;
        }
        $prev = $val;
    }
    return implode("", $chars);
}
?>

<?php

$n = intval(fgets(STDIN));
$i = 0;
while($i < $n)
{
    $current = fgets(STDIN);
    if(!checkNice($current))
        $res = -1;
    else
    {
        $res = makeNice($current);
    }
    $i++;
    echo $res."\n";
}

function checkNice($string)
{
    $chars = str_split($string);
    $prev = $chars[0];
    unset($chars[count($chars) - 1]);
    foreach($chars as $k => $val)
    {
        if($k == 0 || $val == "?") {
            if($val == "?") $prev = "?";
            continue;
        }

        if($val == $prev && $prev != "?")
            return false;
        $prev = $chars[$k];
    }
    return true;
}

function makeNice($string)
{
    $chars = str_split($string);
    unset($chars[count($chars) - 1]);
    $prev = "";
    $lastChanged = -1;
    foreach($chars as $k => $val)
    {
        if($val == "?")
        {
            if($k == 0)
                $val = "a";
            else {
                $first = $chars[$k - 1];
                if($k != count($chars) - 1)
                    $last = $chars[$k + 1];
                else
                    $last = $first;

                $fl = array($first, $last);
                if(!in_array("a", $fl))
                    $val = "a";
                if(!in_array("b", $fl))
                    $val = "b";
                if(!in_array("c", $fl))
                    $val = "c";

            }
            $chars[$k] = $val;
        }
        $prev = $val;
    }
    return implode("", $chars);
}
?>


Timur has a stairway with $$$n$$$ steps. The $$$i$$$-th step is $$$a_i$$$ meters higher than its predecessor. The first step is $$$a_1$$$ meters higher than the ground, and the ground starts at $$$0$$$ meters.   The stairs for the first test case. Timur has $$$q$$$ questions, each denoted by an integer $$$k_1, \dots, k_q$$$. For each question $$$k_i$$$, you have to print the maximum possible height Timur can achieve by climbing the steps if his legs are of length $$$k_i$$$. Timur can only climb the $$$j$$$-th step if his legs are of length at least $$$a_j$$$. In other words, $$$k_i \geq a_j$$$ for each step $$$j$$$ climbed.Note that you should answer each question independently.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains two integers $$$n, q$$$ ($$$1 \leq n, q \leq 2\cdot10^5$$$) — the number of steps and the number of questions, respectively. The second line of each test case contains $$$n$$$ integers ($$$1 \leq a_i \leq 10^9$$$) — the height of the steps. The third line of each test case contains $$$q$$$ integers ($$$0 \leq k_i \leq 10^9$$$) — the numbers for each question. It is guaranteed that the sum of $$$n$$$ does not exceed $$$2\cdot10^5$$$, and the sum of $$$q$$$ does not exceed $$$2\cdot10^5$$$.

For each test case, output a single line containing $$$q$$$ integers, the answer for each question. Please note, that the answer for some questions won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

NoteConsider the first test case, pictured in the statement.   If Timur's legs have length $$$1$$$, then he can only climb stair $$$1$$$, so the highest he can reach is $$$1$$$ meter.  If Timur's legs have length $$$2$$$ or $$$4$$$, then he can only climb stairs $$$1$$$, $$$2$$$, and $$$3$$$, so the highest he can reach is $$$1+2+1=4$$$ meters.  If Timur's legs have length $$$9$$$ or $$$10$$$, then he can climb the whole staircase, so the highest he can reach is $$$1+2+1+5=9$$$ meters.  In the first question of the second test case, Timur has no legs, so he cannot go up even a single step. :(

<?php

// 1742 E. Scuza (Stairs)
// _prefix_sum_, _binary_search_, _math_, _upper_bound_ , *1200

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

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

    $heights =
    $maxStairs = array_fill(-1, $n, 0);

    foreach ($ar as $k => $item) {
        $heights[$k] = $heights[$k - 1] + $item;
    }

    foreach ($ar as $k => $a) {
        $maxStairs[$k] = max($maxStairs[$k - 1], $a);
    }

    $res = [];

    foreach ($qr as $q) {
        // find last item, which is less than q + 1
        // find first item which is greater than
        // upper bound algorithm

        $ptr = 0;
        $count = $n;

        while ($count > 0) {
            $half = $count >> 1;
            $midPtr = $ptr + $half;

            if ($maxStairs[$midPtr] <= $q) {
                $ptr = $midPtr + 1;
                $count -= $half + 1;
            } else {
                $count = $half;
            }
        }

        $res[] = $heights[$ptr - 1];
    }

    fprintf(STDOUT, $qFormat.PHP_EOL, ...$res);
}

/*
1
3 1
100 7 10
8
// 0

2
1 1
1
1
3 1
1 1 1
0

// 1, 0

1
5 5
1 2 1 5 1
1 2 0 5 6
// 1 4 0 10 10

1
4 1
1 2 2 3
2
// 5

1
5 1
1 2 3 4 3
3
// 6

1
3 1
3 4 1
1
// 0

1
5 6
1 2 3 4 5
3 2 0 4 5 1

// 117 117 117 117 117 0

 */

<?php

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

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

    $heights =
    $maxStairs = array_fill(-1, $n, 0);

    foreach ($ar as $k => $item) {
        $heights[$k] = $heights[$k - 1] + $item;
    }

    foreach ($ar as $k => $a) {
        $maxStairs[$k] = max($maxStairs[$k - 1], $a);
    }

    $res = [];

    foreach ($qr as $q) {
        // find last item, which is less than q + 1
        // find first item which is greater than
        // upper bound algorithm

        $ptr = 0;
        $count = $n;

        while ($count > 0) {
            $half = $count >> 1;
            $midPtr = $ptr + $half;

            if ($maxStairs[$midPtr] <= $q) {
                $ptr = $midPtr + 1;
                $count -= $half + 1;
            } else {
                $count = $half;
            }
        }

        $res[] = $heights[$ptr - 1];
    }

    fprintf(STDOUT, $qFormat.PHP_EOL, ...$res);
}

/*
1
3 1
100 7 10
8
// 0

2
1 1
1
1
3 1
1 1 1
0

// 1, 0

1
5 5
1 2 1 5 1
1 2 0 5 6
// 1 4 0 10 10

1
4 1
1 2 2 3
2
// 5

1
5 1
1 2 3 4 3
3
// 6

1
3 1
3 4 1
1
// 0

1
5 6
1 2 3 4 5
3 2 0 4 5 1

// 117 117 117 117 117 0

 */

<?php

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

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

    $heights = array_fill(-1, $n, 0);
    foreach ($ar as $k => $item) {
        $heights[$k] = $heights[$k - 1] + $item;
    }

    // keep track of where new level starts the first time
    $newLevelStarts = array_flip(array_reverse($ar, true));
    ksort($newLevelStarts);

    $stairs = array_keys($newLevelStarts);

    $iL = 0;
    $iR = count($stairs) - 1;

    // for every question find the first item, which is greater than a $q

    $res = [];

    foreach ($qr as $q) {
        $l = $iL;
        $r = $iR;
        // what if null?
        $prevAltitude = end($stairs);

        // l is the result
        while ($l <= $r) {
            $m = ($l + $r) >> 1;
            $altitude = $stairs[$m];

            if ($altitude <= $q) {
                $l = $m + 1;
            } elseif ($prevAltitude > $q) {
                $r = $m - 1;
            } else {
                // found
                $l = $r = $m;
                break;
            }

            $prevAltitude = $altitude;
        }

        if ($l > $iR) {
            // out of bounds, max value
            $res[] = end($heights);
            continue;
        }

        $resId = $newLevelStarts[$stairs[$l]] - 1;

        $res[] = $heights[$resId];
    }

    fprintf(STDOUT, $qFormat . PHP_EOL, ...$res);
}

/*
2
1 1
1
1
3 1
1 1 1
0
// 1, 0

1
5 5
1 2 1 5 1
1 2 0 5 6
// 1 4 0 10 10

 */


There are one cat, $$$k$$$ mice, and one hole on a coordinate line. The cat is located at the point $$$0$$$, the hole is located at the point $$$n$$$. All mice are located between the cat and the hole: the $$$i$$$-th mouse is located at the point $$$x_i$$$ ($$$0 < x_i < n$$$). At each point, many mice can be located.In one second, the following happens. First, exactly one mouse moves to the right by $$$1$$$. If the mouse reaches the hole, it hides (i.e. the mouse will not any more move to any point and will not be eaten by the cat). Then (after that the mouse has finished its move) the cat moves to the right by $$$1$$$. If at the new cat's position, some mice are located, the cat eats them (they will not be able to move after that). The actions are performed until any mouse hasn't been hidden or isn't eaten.In other words, the first move is made by a mouse. If the mouse has reached the hole, it's saved. Then the cat makes a move. The cat eats the mice located at the pointed the cat has reached (if the cat has reached the hole, it eats nobody).Each second, you can select a mouse that will make a move. What is the maximum number of mice that can reach the hole without being eaten?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of two lines. The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le k \le 4 \cdot 10^5$$$). The second line contains $$$k$$$ integers $$$x_1, x_2, \dots x_k$$$ ($$$1 \le x_i < n$$$) — the initial coordinates of the mice. It is guaranteed that the sum of all $$$k$$$ given in the input doesn't exceed $$$4 \cdot 10^5$$$.

For each test case output on a separate line an integer $$$m$$$ ($$$m \ge 0$$$) — the maximum number of mice that can reach the hole without being eaten.

<?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;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }

    public static function res($res) {
        foreach ($res as $r) {
            echo $r . "\n";
        }
    }

    public static function dd($val){
        echo $val; exit;
    }
}

$t = IO::str();
$res = array();
while ($t--) {
    list ($n, $k) = IO::arr();
    $mv = $n;
    $arr = IO::arr();

    sort($arr);
    $farr = array_reverse($arr);

    $sv = 0;
    $cnt = 0;
    $s = 0;
    $turn = 1;
    $koshka = 0;
    foreach ($farr as $a) {
        if ($a > $koshka) {
            $cnt += 1;
            $koshka += $n - $a;
        }
    }
    $res[] = $cnt;
}

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

<?php
list($m) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $m; $j++) {
    list($n, $k) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    rsort($aArray);
    $k = 0;
    $iCount = 0;
    for ($i = 0; $i < count($aArray); $i++) {
        if ($k + $n - $aArray[$i] > $n - 1) {
            break;
        } else {
            $k += $n - $aArray[$i];
            $iCount++;
        }
    }
    echo $iCount . "\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;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }

    public static function res($res) {
        foreach ($res as $r) {
            echo $r . "\n";
        }
    }

    public static function dd($val){
        echo $val; exit;
    }
}

$t = IO::str();
$res = array();
while ($t--) {
    list ($n, $k) = IO::arr();
    $mv = $n;
    $arr = IO::arr();

    sort($arr);
    $farr = array_reverse($arr);

    $sv = 0;
    $cnt = 0;
    $s = 0;
    $turn = 1;
    foreach ($farr as $a) {

        if ($sv < $k) {
            $s = $mv - $a;
            $sv = $sv + $s;
            if ($sv > $k) {
                break;
            }
            $cnt++;
        } else {
            if ($sv == $k) {
                $s = $mv - $a;
                if ($s <= $mv - $sv) {
                    $cnt++;
                }
            }
            break;
        }

        $turn++;
        if ($turn == $n) {
            break;
        }
    }
    if ($cnt == 0) {
        $cnt = 1;
    }
    $res[] = $cnt;
}

foreach ($res as $r) {
    echo $r . "\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;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }

    public static function res($res) {
        foreach ($res as $r) {
            echo $r . "\n";
        }
    }

    public static function dd($val){
        echo $val; exit;
    }
}

$t = IO::str();
$res = array();
while ($t--) {
    list ($n, $k) = IO::arr();
    $mv = $n;
    $arr = IO::arr();

    sort($arr);
    $farr = array_reverse($arr);

    $sv = 0;
    $cnt = 0;
    $s = 0;
    $turn = 1;
    foreach ($farr as $a) {

        if ($sv < $k) {
            $s = $mv - $a;
            $sv = $sv + $s;
            if ($sv > $k) {
                break;
            }
            $cnt++;
        } else {
            if ($sv == $k) {
                $s = $mv - $a;
                if ($s <= $mv - $sv) {
                    $cnt++;
                }
            }
            break;
        }

        $turn++;
        if ($turn == $n) {
            break;
        }
    }
    $res[] = $cnt;
}

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


A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.

The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100).

Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.

<?php
fscanf(STDIN, "%d\n", $number);
$array = [];
$counterOne = 0;
$counterTwo = 0;
$counterThree = 0;

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

for ($i=0; $i < count($array); $i++) {
	$array[$i] = explode(' ', $array[$i]);
	$counterOne += intval($array[$i][0]);
	$counterTwo += intval($array[$i][1]);
	$counterThree += intval($array[$i][2]);
}

$counter = $counterOne + $counterTwo + $counterThree;

// NEED TESTING
if($counterOne !== 0 || $counterTwo !== 0 || $counterThree !== 0){
	echo "NO";
} else {
	echo "YES";
}

<?php

/**
 * @author Sunwarul
 */
error_reporting(0);
$sum = $asum = $bsum = $csum = 0;
$n = (int) fgets(STDIN);
while ($n--) {
    list($a, $b, $c) = explode(' ', fgets(STDIN));
    $asum += (int) $a;
    $bsum += (int) $b;
    $csum += (int) $c;
}
if ($asum == 0 && $bsum == 0 && $csum == 0) {
    echo "YES\n";
} else {
    echo "NO\n";
}

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

$sum_x=$sum_y=$sum_z=0;
for($i=1; $i<count($lines); $i++)
{
    list ($x, $y, $z)=explode (" ", trim ($lines[$i]));
    $sum_x+=$x;
    $sum_y+=$y;
    $sum_z+=$z;
}
if ($sum_x==0 and $sum_y==0 and $sum_z==0)
    echo 'YES';
else
    echo 'NO';
?>

<?php
$count = fgets(STDIN);
while ($line = fgets(STDIN)) {
	$lines[] = sscanf($line, '%d %d %d');
}

$sumx = 0;
$sumy = 0;
$sumz = 0;
for ($i=0; $i < $count; $i++) {
	$sumx += $lines[$i][0];
	$sumy += $lines[$i][1];
	$sumz += $lines[$i][2];
}

if ($sumx === 0 && $sumx === 0 && $sumz === 0) {
    echo 'YES';
} else {
    echo 'NO';
}

<?php
error_reporting("off");
//69A: Young Physicist
//$array = array("3 -1 7", "-5 2 -4", "2 -1 -3");
$n = trim(fgets(STDIN)); //$n = 3;
$multidimen = array();
for ($i = 0; $i < $n; $i++) {
    $multidimen[] = explode(" ", trim(fgets(STDIN)));
    //$multidimen[] = explode(" ", $array[$i]);
}
$xsum = 0;
$ysum = 0;
$zsum = 0;
for ($i = 0; $i < $n; $i++) {
    $xsum = $xsum + $multidimen[$i][0];
    $ysum = $ysum + $multidimen[$i][1];
    $zsum = $zsum + $multidimen[$i][2];
}
if ($xsum == 0 && $ysum == 0 && $zsum == 0) {
    echo "YES";
} else {
    echo "NO";
}
?>

<?php
	$loop = trim(fgets(STDIN));
	$x = $y = $z = 0;
	for ($i=0; $i < $loop; $i++) {
		$input = explode(' ', trim(fgets(STDIN)));
		$x += $input[0];
		$y += $input[1];
		$z += $input[2];
	}
	if($x==0 && $y==0 && $z==0) echo "YES";
	else echo "NO";

?>

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

<?php
	$input_line = trim(fgets(STDIN));
	$arr = array(0,0,0);
	while($i < $input_line)
	{
		$array2 = explode(" ",trim(fgets(STDIN)));
		$arr = array_map('array_sum', array_map(null, $arr, $array2));
		$i++;
	}
	if($arr[0]==0 && $arr[1]==0 && $arr[2]==0)
		echo "YES";
	else
		echo "NO";
?>

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function foo($x, $y, $z)
{
    $x_sum = array_sum($x);
    $y_sum = array_sum($y);
    $z_sum = array_sum($z);

    return $x_sum === 0 && $y_sum === 0 && $z_sum === 0;
}

$r = 0;
$x = $y = $z = [];

list($n) = fscanf($input, "%d\n");

for ($i = 0; $i < $n; $i++) {
    list($x[$i], $y[$i], $z[$i]) = fscanf($input, "%d %d %d\n");
}

$r = foo($x, $y, $z) ? 'YES' : 'NO';

fwrite($output, $r);

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

/* Program Code */

$x = 0; $y = 0; $z = 0;

fscanf($cin, "%d\n", $n);

for ($i = 1; $i <= $n; $i++) {
	fscanf($cin, "%d %d %d\n", $fx, $fy, $fz);
	$x += $fx; $y += $fy; $z += $fz;
}

if ($x == $y && $y == $z && $z == 0) {
	fprintf($cout, "YES");
} else {
	fprintf($cout, "NO");
}
?>

<?php
    define('DEBUG', 0);

    if(DEBUG) $GLOBALS['file'] = fopen('input.txt', 'r');
    function debug($var){echo '<pre>';print_r($var);echo '</pre>';}
    function read_line()
    {
        if(DEBUG) { $file = $GLOBALS['file'];$line = trim(fgets($file));}
        else $line = trim(fgets(STDIN));
        return $line;
    }
    function get_array($line){return explode(' ', $line);}
    function read_array(){return get_array(read_line());}
    //echo "$s\n";
    /*****************************************************************/

    $n = read_line();
    $x=0;
    $y=0;
    $z=0;

    for($i=1; $i<=$n; $i++)
    {
        $arr=read_array();
        $x+=$arr[0];
        $y+=$arr[1];
        $z+=$arr[2];
    }

    if(!($x||$y||$z)) echo 'YES';
    else echo 'NO';
?>

<?php
fscanf(STDIN, "%d", $n);
$tx = $ty = $tz = 0;
while($n--) {
	fscanf(STDIN, "%d%d%d", $x, $y, $z);
	$tx += $x;
	$ty += $y;
	$tz += $z;
}
if($tx == 0 AND $ty == 0 AND $tz == 0) {
	echo "YES";
}
else {
	echo "NO";
}

<?php
// 69A  Юный физик
$in = fopen("php://stdin", 'r');

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

$x = $y = $z = 0;

for ($i=0; $i < $n; $i++) {
    $input_line = fgets($in);
    list($xi, $yi, $zi) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);
    $xi = (int) $xi;
    $yi = (int) $yi;
    $zi = (int) $zi;

    $x += $xi;
    $y += $yi;
    $z += $zi;
}

if (($x == 0) and ($y == 0) and ($z == 0)) {
    echo "YES";
} else {
    echo "NO";
}

?>

<?php
$number = fgets(STDIN);
$lineOne = fgets(STDIN);
$lineOne = explode(' ', trim($lineOne));
$lineTwo = fgets(STDIN);
$lineTwo = explode(' ', trim($lineTwo));
$lineThree = fgets(STDIN);
$lineThree = explode(' ', trim($lineThree));

$array = array_merge($lineThree, $lineTwo, $lineOne);

if(array_sum($array) == 0){
	echo "YES";
} else {
	echo "NO";
}

<?php
fscanf(STDIN, "%d\n", $number);
$array = [];
$counterOne = 0;
$counterTwo = 0;
$counterThree = 0;

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

for ($i=0; $i < count($array); $i++) {
	$array[$i] = explode(' ', $array[$i]);
	$counterOne += intval($array[$i][0]);
	$counterTwo += intval($array[$i][1]);
	$counterThree += intval($array[$i][2]);
}

$counter = $counterOne + $counterTwo + $counterThree;

if($counter == 0){
	echo "YES";
} else {
	echo "NO";
}

<?php
fscanf(STDIN, "%d\n", $number);
$array = [];
$counter = 0;

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

for ($i=0; $i < count($array); $i++) {
	$array[$i] = explode(' ', $array[$i]);
	$counter += array_sum($array[$i]);
}

if($counter == 0){
	echo "YES";
} else {
	echo "NO";
}

<?php

/**
 * @autor Sunwarul
 */

$n = (int) fgets(STDIN);
while ($n--) {
    list($a, $b, $c) = explode(' ', fgets(STDIN));
    $sum += (int) $a + (int) $b + (int) $c;
}
if ($sum == 0) {
    echo "YES\n";
} else {
    echo "NO\n";
}

<?php

/**
 * @autor Sunwarul
 */

$n = (int) fgets(STDIN);
while ($n--) {
    list($a, $b, $c) = explode(' ', fgets(STDIN));
    $sum += (int) $a + (int) $b + (int) $c;
    echo "$n for $sum\n";
}
if ($sum == 0) {
    echo "YES\n";
} else {
    echo "NO\n";
}

<?php
while ($line = fgets(STDIN)) {
	$lines[] = $line;
}
$count = array_shift($lines);

$sum = 0;
for ($i=0; $i < $count; $i++) {
	list($x,$y,$z) = sscanf($lines[$i], '%d %d %d');
	$sum = $sum + $x + $y + $z;
}

if ($sum === 0) {
    echo 'YES';
} else {
    echo 'NO';
}

<?php
$line = fgets(STDIN);
while ($line = fgets(STDIN)) {
	$lines[] = $line;
}
$count = array_shift($lines);

$sum = 0;
for ($i=0; $i < $count; $i++) {
	list($x,$y,$z) = sscanf($lines[$i], '%d %d %d');
	$sum = $sum + $x + $y + $z;
}

if ($sum === 0) {
    echo 'YES';
} else {
    echo 'NO';
}

<?php
	$total = 0;
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		list($v1,$v2,$v3) = explode(' ',fgets(STDIN));
		$sub_total = sqrt( pow( sqrt( pow( $v1 ) + pow( $v2 ) ) ) + sqrt( pow( $v2 ) + pow( $v3 ) ) );
		$total += $sub_total;
	}
	if ($total == 0) echo 'YES';
	else echo 'NO';

<?php
	$total = 0;
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		list($v1,$v2,$v3) = explode(' ',fgets(STDIN));
		$sub_total = sqrt( pow( sqrt( pow( $v1 ) + pow( $v2 ) ) ) + pow( $v3 ) );
		$total += $sub_total;
	}
	if ($total == 0) echo 'YES';
	else echo 'NO';

<?php
	$input_line = trim(fgets(STDIN));
	$vector = 0;
	while($i < $input_line)
	{
		$vector = $vector + array_sum(explode(" ",trim(fgets(STDIN))));
		$i++;
	}
	echo ($vector==0)?"YES":"NO";
?>

<?php
$fp = fopen("php://stdin", "r");
$input = fgets($fp);
echo $input;
?>

<?php
$sum = 0;
$str = array();
fscanf(STDIN, '%d', $n);
for ($i = 0; $i < $n; $i++) {
    array_push($str, (explode(" ", fgets(STDIN))));
}
$i = 0;
while ($sum == 0 && $i < $n) {
    $sum = array_sum((array_column($str, $i)));
    $i = $i + 1;
}
if ($i == $n - 1) {
    print("YES");
} else {
    print("NO");
}

<?php
$sum = 0;
fscanf(STDIN, '%d', $n);
for ($i = 0; $i < $n; $i++) {
    $sum = array_sum(explode(" ", fgets(STDIN))) + $sum;
}
if ($sum == 0) {
    print("YES");
} else {
    print("NO");
}

<?php
$sum = 0;
$str = array();
fscanf(STDIN, '%d', $n);
for ($i = 0; $i < $n; $i++) {
    array_push($str, (explode(" ", fgets(STDIN))));
}
for ($i = 0; $i < $n; $i++) {
    $sum = array_sum((array_column($str, $i))) + $sum;
}
if ($sum == 0) {
    print("YES");
} else {
    print("NO");
}

<?php
$sum = 0;
$str = array();
fscanf(STDIN, '%d', $n);
for ($i = 0; $i < $n; $i++) {
    array_push($str, (explode(" ", fgets(STDIN))));
}
for ($i = 0; $i < $n; $i++) {
    $sum = array_sum((array_column($str, $i)));
}
if ($sum == 0) {
    print("YES");
} else {
    print("NO");
}

<?php
$sum = 0;
$str = array();
fscanf(STDIN, '%d', $n);
for ($i = 0; $i < $n; $i++) {
    array_push($str, (explode(" ", fgets(STDIN))));
}
$i = 0;
while ($sum == 0 && $i < $n) {
    $sum = array_sum((array_column($str, $i)));
    $i = $i + 1;
}
if ($i == $n) {
    print("YES");
} else {
    print("NO");
}

<?php
fscanf(STDIN, "%d", $n);
$tt = 0;
while($n--) {
	fscanf(STDIN, "%d%d%d", $x, $y, $z);
	$tt += ($x + $y + $z);
}
if($tt == 0) {
	echo "YES";
}
else {
	echo "NO";
}

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

while ($s = fgets(STDIN))
{
    $mas[] = explode(' ', trim($s));
}

for ($i = 0; $i < 3; $i++)
{
    for ($j = 0; $j < count($mas); $j++)
    {
        $sum[$i] += $mas[$j][$i];
    }
}

if (array_sum($sum) == 0)
    echo "YES";
else
    echo "NO";
?>


A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i < t.You are given a sequence b0, b1, ..., bn - 1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing?

The first line of the input contains two integer numbers n and d (2 ≤ n ≤ 2000, 1 ≤ d ≤ 106). The second line contains space separated sequence b0, b1, ..., bn - 1 (1 ≤ bi ≤ 106).

Output the minimal number of moves needed to make the sequence increasing.

<?php

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

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

    if ($die) {
        die();
    }

    echo '</pre>';
}

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

    return $stdin;
}

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

$stdin = stdin();
/****************************************************** Solving block *****************************************************/
list($n, $d) = explode(' ', g());
$b = explode(' ', g());

$a = 0;
$cnt = 0;

foreach($b as $item) {
    $inc = 0;
    if($a > $item) {
        $inc += ceil(($a - $item) / $d);

        if($item + $d * $inc == $a) {
            $inc++;
        }
    } else if($a == $item) {
        $inc++;
    }

    $cnt += $inc;
    $a = $item + $d * $inc;
}

echo $cnt;
?>

<?php

list($len, $inc) = sscanf(readline(), "%d %d");
$seq_string = readline();
$start = microtime(true);
$sequence = explode(' ', $seq_string);

$tries = 0;

for ($i = 0; $i < $len -1; $i++){
	$cur = $sequence[$i];
	$nxt = $sequence[$i+1];
	if($cur >= $nxt){
		$new_tries = floor(($cur - $nxt) / $inc) + 1;
		$tries += $new_tries;
		$sequence[$i+1]= $nxt + $new_tries * $inc;
	}
}
echo $tries;

<?php

list($len, $inc) = sscanf(readline(), "%d %d");
$seq_string = readline();
$start = microtime(true);
$sequence = explode(' ', $seq_string);

$tries = 0;

for ($i = 0; $i < $len -1; $i++){
	$cur = $sequence[$i];
	$nxt = $sequence[$i+1];
	if($cur >= $nxt){
		$new_tries = ceil(($cur - $nxt) / $inc) + $inc;
		$tries += $new_tries;
		$sequence[$i+1]= $nxt + $new_tries * $inc;
	}
}
echo $tries;


Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito's strength equals s.If Kirito starts duelling with the i-th (1 ≤ i ≤ n) dragon and Kirito's strength is not greater than the dragon's strength xi, then Kirito loses the duel and dies. But if Kirito's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by yi.Kirito can fight the dragons in any order. Determine whether he can move on to the next level of the game, that is, defeat all dragons without a single loss.

The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it.

On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.

NoteIn the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.In the second sample Kirito's strength is too small to defeat the only dragon and win.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = array();
$d = array();
$i = 0;
$j = 0;
for($x = 1; $x <= $b; $x++)
{
    list($e, $f) = explode(" ", trim(fgets(STDIN)));
    array_push($c, $e);
    array_push($d, $f);
}
asort($c);
$g = array_keys($c);
sort($c);
for($x = 0; $x < $b; $x++)
{
    $i++;
    if($a > $c[$x])
    {
        $j++;
        $a += $d[$g[$x]];
    }
}
if($i == $j)
{
    print "YES";
}
else
{
    print "NO";
}
?>

<?php

error_reporting(0);

solve();

function solve(){

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

	$S = (int)$Input->in();
	$N = (int)$Input->in();

	for ($i = 0; $i < $N; $i++)
	{
		//$X[(int)$Input->in()] = (int)$Input->in();
		$X[] = (int)$Input->in();
		$Y[] = (int)$Input->in();
	}

	asort($X);

	$flag = 0;

	foreach ($X as $key => $x)
	{
		if ($x >= $S)
		{
			$flag = 1;
			break;
		} else {
			$S += $Y[$key];
		}
	}

	if ($flag === 1) print("NO");
	else print("YES");

	$Input->close();
}

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

	public function __construct($localfile){

		if (is_file($localfile)) {

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

		} else {

			$contents = stream_get_contents(STDIN);

		}

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

	public function in(){

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

	}

	public function close(){

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

	}
}

?>

<?php

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

list($s, $n) = explode(" ", trim(fgets(STDIN)));
$a = array();
for($i=0;$i<$n;$i++){
  $a[] = explode(" ", trim(fgets(STDIN)));
}
usort($a, 'cmp');

foreach($a as $k=>$v){
  if ($s <= $v[0]){
    echo "NO" . PHP_EOL;
    exit();
  }
  $s+=$v[1];
}

echo "YES" . PHP_EOL;
//fclose($fp);

function cmp($a, $b){
  if ($a[0] > $b[0]) return 1;
  if ($a[0] < $b[0]) return -1;
  if ($a[1] > $b[1]) return -1;
  if($a[0] > $b[0]) return 1;
  return 0;
}

<?php
list ($power,$n) = explode(" ",trim(fgets(STDIN)));
$alive = true;
$powerArray = array();
for ($i=0;$i<$n;$i++)
{
    $powerArray[] = explode(" ",trim(fgets(STDIN)));
}
sort($powerArray);
for ($i=0;$i<$n;$i++)
{
    if ($power>$powerArray[$i][0])$power+=$powerArray[$i][1];
    else $alive=false;
}
if ($alive)echo "YES";
else echo "NO";

<?php

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

$s=$input[0];
$n=$input[1];
for($i=0;$i<$n;$i++)    {
	$input=explode(' ',trim(fgets(STDIN)));
	$ara[$i][0]=$input[0];
	$ara[$i][1]=$input[1];
}

sort($ara);

$sum=$s;

for($i=0;$i<$n;$i++)    {
	if($sum<=$ara[$i][0])        die("NO\n");
	$sum+=$ara[$i][1];
}
echo "YES\n";

?>

<?
error_reporting(0);

$fp = fopen("php://stdin",'r');
//$fp = fopen('D:\work\php\codeforce\div2(142)\AAA_data.php','r');
list($s, $n) = explode(' ', trim( fgets($fp) ) );

$dragons = array();
while($n--)
{
	list($sn, $add) = explode(' ', trim( fgets($fp) ) );
	$dragons[$sn] += $add;
}
ksort($dragons);
$result = true;
foreach($dragons as $k => $v)
{
	if($s > $k)
	{
		$s += $v;
	} else {
		$result = false;
		break;
	}
}
echo ($result) ? 'YES' : 'NO';
fclose($fp);
?>

<?php

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

$dragons = array();

list($power, $n) = fscanf($f, "%d %d");

for ($j = 0; $j < $n; $j++) {
    list($a, $b) = fscanf($f, "%d %d");
    $dragons[] = $a;
    $levels[] = $b;

}

fclose($f);

array_multisort($dragons, $levels);

foreach ($dragons as $j => $i) {
    if ($power > $i) {
        $power+= $levels[$j];
    } else {
        print 'NO';
        die();
    }
}

print 'YES';

<?php
// 230A     Драконы
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
list($s, $n) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);
$n = (int) $n;
$s = (int) $s;

$arr = array(array());

for ($i=0; $i < $n; $i++) {
    $input_line = fgets($in);
    $arr[$i] = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);
}

/* Двумерный массив  */
usort($arr, "compare"); // Вызываем пользовательскую сортировку
  /* Функция для нашей сортировки */
  function compare ($v1, $v2) {
    /* Сравниваем значение по ключу date_reg */
    if ($v1[0] == $v2[0]) return 0;
    return ((int) $v1[0] < (int) $v2[0])? -1: 1;
  }
  //print_r($arr); // Выводим отсортированный массив

$out = "YES";

for ($i=0; $i < $n; $i++) {
    if ($s > $arr[$i][0]) {
        $s += $arr[$i][1];
    } else {
        $out = "NO";
        break;
    }
}

echo $out;

?>

<?php

function cmp($a, $b) {
        if ($a[0] == $b[0]) {
                return 0;
        }
        return ($a[0] < $b[0]) ? -1 : 1;
}

$line = fgets(STDIN);
$expd = explode(" ",$line);
$s = $expd[0];
$n = $expd[1];
$arr = [];
for($i=0; $i<$n; $i++){
    $line = fgets(STDIN);
    $expd = explode(" ",$line);
    $arr[] = [$expd[0], $expd[1]];
}
usort($arr,"cmp");

foreach($arr as $a){
    if($s <= $a[0]){
        echo "NO";
        exit;
    }
    else $s += $a[1];
}

echo "YES";

<?PHP
list($s, $n) = explode(' ', fgets(STDIN));
for ($i = 0; $i < $n; $i++) {
    list($ds, $bo) = explode(' ', fgets(STDIN));
    $da[] = array('ds' => $ds, 'bo' => $bo);
}
//print_r($da);
foreach ($da as $key => $row) {
    $ds1[$key] = $row['ds'];
    $bo1[$key] = $row['bo'];
}

array_multisort($ds1, SORT_ASC, $bo1, SORT_ASC, $da);
//print_r($da);
$res = 'YES';
foreach ($da as $key => $row) {
    //print_r($row);
    if ($s <= $row['ds'])
        $res = 'NO';
    if ($res == 'YES')
        $s = $s + $row['bo'];
}
echo "$res\n";
?>

<?php
error_reporting("off");
//230A: Dragons
list($s, $n) = explode(" ", trim(fgets(STDIN))); //$s = 10; $n = 1;
//$array = array("100 100");
for ($i = 0; $i < $n; $i++) {
    list($a, $b) = explode(" ", trim(fgets(STDIN))); //list($a, $b) = explode(" ", $array[$i]);
    if ($a < $s) {
        $s += $b; //eliminate the dragons we can right off the bat, even increasing our strength
    } else {
        $x[] = $a;
        $y[] = $b;
    }
}
asort($x);
$echome = "YES";
foreach ($x as $key => $value) {
    if ($value >= $s) {
        $echome = "NO";
        break;
    } else {
        $s += $y[$key];
        unset($x[$key]);
    }
}

echo $echome;
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = array();
$d = array();
$i = 0;
$j = 0;
for($x = 1; $x <= $b; $x++)
{
    list($e, $f) = explode(" ", trim(fgets(STDIN)));
    array_push($c, $e);
    array_push($d, $f);
}
asort($c);
$g = array_keys($c);
$h = array_combine($g, $d);
sort($c);
for($x = 0; $x < $b; $x++)
{
    $i++;
    if($a > $c[$x])
    {
        $j++;
        $a += $h[$x];
    }
}
if($i == $j)
{
    print "YES";
}
else
{
    print "NO";
}
?>

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

<?php

error_reporting(0);

solve();

function solve(){

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

	$S = (int)$Input->in();
	$N = (int)$Input->in();

	for ($i = 0; $i < $N; $i++)
	{
		$X[(int)$Input->in()] = (int)$Input->in();
	}

	ksort($X);

	$flag = 0;

	foreach ($X as $x => $y)
	{
		if ($x >= $S)
		{
			$flag = 1;
			break;
		} else {
			$S += $y;
		}
	}

	if ($flag === 1) print("NO");
	else print("YES");

	$Input->close();
}

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

	public function __construct($localfile){

		if (is_file($localfile)) {

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

		} else {

			$contents = stream_get_contents(STDIN);

		}

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

	public function in(){

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

	}

	public function close(){

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

	}
}

?>

<?php
list ($power,$n) = explode(" ",trim(fgets(STDIN)));
$alive = true;
for ($i=0;$i<$n;$i++)
{
    list ($drakoPower,$drakoBonus)= explode(" ",trim(fgets(STDIN)));
    if ($power>$drakoPower)$power+=$drakoBonus;
    else $alive=false;
}
if ($alive)echo "YES";
else echo "NO";

<?php
list ($power,$n) = explode(" ",trim(fgets(STDIN)));
$alive = true;
$powerArray = array();
for ($i=0;$i<$n;$i++)
{
    $powerArray[] = explode(" ",trim(fgets(STDIN)));
}
sort($powerArray);
for ($i=0;$i<$n;$i++)
{
    if ($power>$powerArray[$i][0])$power+=$powerArray[$i][1];
    else $alive=false;
}
if ($alive)echo "YES";
echo "NO";

<?php
list ($power,$n) = explode(" ",trim(fgets(STDIN)));
$alive = true;
$powerArray = array();
for ($i=0;$i<$n;$i++)
{
    $tempCouple = explode(" ",trim(fgets(STDIN)));
    $powerArray[] = $tempCouple;
    sort($powerArray);
}
$max = $powerArray[$n-1][0];
$k=0;
while (($alive)&&($k<$n)&&($power<$max))
{
    if ($power<=$powerArray[$k][0])$alive = false;
    else
    {
        $power+=$powerArray[$k][1];
        $k++;
    }
}
if ($alive)echo "YES";
else echo "NO";

<?php
list ($power,$n) = explode(" ",trim(fgets(STDIN)));
$alive = true;
$powerArray = array();
for ($i=0;$i<$n;$i++)
{
    $tempCouple = explode(" ",trim(fgets(STDIN)));
    $powerArray[] = $tempCouple;
    sort($powerArray);
}
echo $max = $powerArray[count($powerArray)-1][0];
for ($i=0;$i<$n;$i++)
{
    if ($power > $max)break;
    else
    {
        if ($power > $powerArray[$i][0])
        {
            $power+=$powerArray[$i][1];
        }
        else
        {
            $alive = false;
            break;
        }
    }
}
if ($alive)echo "YES";
else echo "NO";

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

list($s,$n) =  explode(" ",trim(fgets($f)));

for($i=0;$i<$n;$i++){
    list($a,$b) = explode(" ",trim(fgets($f)));

    if ($s>=$a){
        $s = $s+$b;
    }
    if ($s<$a){
        echo "NO";
        exit;
    }
}

echo "YES";

<?php
$line = fgets(STDIN);
$expd = explode(" ",$line);
$s = $expd[0];
$n = $expd[1];
$arr = [];
for($i=0; $i<$n; $i++){
    $line = fgets(STDIN);
    $expd = explode(" ",$line);
    $arr[$expd[0]] = $expd[1];
}
ksort($arr);

foreach($arr as $key => $value){
    if($s < $key){
        echo "NO";
        exit;
    }
    else $s += $value;
}

echo "YES";

<?php
$line = fgets(STDIN);
$expd = explode(" ",$line);
$s = $expd[0];
$n = $expd[1];
$arr = [];
for($i=0; $i<$n; $i++){
    $line = fgets(STDIN);
    $expd = explode(" ",$line);
    $arr[$expd[0]] = $expd[1];
}
ksort($arr);

foreach($arr as $key => $value){
    if($s <= $key){
        echo "NO";
        exit;
    }
    else $s += $value;
}

echo "YES";

<?php
$line = fgets(STDIN);
$expd = explode(" ",$line);
$s = $expd[0];
$n = $expd[1];
$arr = [];
for($i=0; $i<$n; $i++){
    $line = fgets(STDIN);
    $expd = explode(" ",$line);
    $arr[$expd[0]] = $expd[1];
}
ksort($arr);

foreach($arr as $key => $value){
    if($s < $key){
        echo "NO";
        exit;
    }
    else $s = $value;
}

echo "YES";


The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator's objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered. Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.

The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x,  y,  r, where (x, y) are the coordinates of the stadium's center ( -  103 ≤ x,  y ≤ 103), and r (1 ≤ r  ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.

Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn't print anything. The output data should be left blank.


You are given $$$4n$$$ sticks, the length of the $$$i$$$-th stick is $$$a_i$$$.You have to create $$$n$$$ rectangles, each rectangle will consist of exactly $$$4$$$ sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be used in only one rectangle. Each stick should be used as a side, you cannot break the stick or use it not to the full length.You want to all rectangles to have equal area. The area of the rectangle with sides $$$a$$$ and $$$b$$$ is $$$a \cdot b$$$.Your task is to say if it is possible to create exactly $$$n$$$ rectangles of equal area or not.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of rectangles. The second line of the query contains $$$4n$$$ integers $$$a_1, a_2, \dots, a_{4n}$$$ ($$$1 \le a_i \le 10^4$$$), where $$$a_i$$$ is the length of the $$$i$$$-th stick.

For each query print the answer to it. If it is impossible to create exactly $$$n$$$ rectangles of equal area using given sticks, print "NO". Otherwise print "YES".

<?php

function rline(): array
{
    return explode(' ', trim(fgets(STDIN)));
}

function pline($var): void
{
    print(strval($var));
    print(PHP_EOL);
}

function plines(array $arr): void
{
    print(implode(PHP_EOL, $arr));
    print(PHP_EOL);
}

function fbool($var): string
{
    return $var ? 'Yes' : 'No';
}

function ints($arr): array
{
    return array_map(function ($elem) {
        return intval($elem);
    }, $arr);
}

function solve(): void
{
    list($q) = rline();
    $ans = [];
    for ($i = 0; $i < $q; $i++) {
        list($n) = ints(rline());
        $a = ints(rline());

        $subans = true;
        $sides = array_count_values($a);
        foreach (array_keys($sides) as $len) {
            if ($sides[$len] % 2 !== 0) {
                $subans = false;
                break;
            }
            $sides[$len] /= 2;
        }
        if (!$subans) {
            $ans[] = strtoupper(fbool($subans));
            continue;
        }

        $area = -1;
        $lens = array_keys($sides);
        sort($lens);
        while (!empty($lens)) {
            $h = array_shift($lens);
            if (empty($lens)) {
                $w = $h;
            } else {
                $w = array_pop($lens);
            }
            if ($area !== -1 && $h * $w !== $area) {
                $subans = false;
                break;
            }
            $area = $h * $w;
            if ($sides[$h] !== $sides[$w]) {
                $subans = false;
                break;
            }
        }

        $ans[] = strtoupper(fbool($subans));
    }

    // print here
    plines($ans);
}

solve();