The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem.  One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)?

The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump.  Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop.

Print a single integer — the maximum number of candies Om Nom can eat.

NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario:  Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7.  Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12.  At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15.  Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4.

<?php

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

$candy_num = 0;
$start_x = 0;

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

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

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

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

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

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

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

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

    return $eaten;
}

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

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

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

    return $list[$key];
}

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

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

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

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

    return 0;
}

<?php

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

$candy_num = 0;
$x = 0;

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

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

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

    $map[] = $candy;
}

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

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

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

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

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

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

echo $eaten;

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

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

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

    return $list[$key];
}

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

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

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

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

    return 0;
}

<?php

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

$candy_num = 0;
$x = 0;

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

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

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

    $map[] = $candy;
}

uasort($map, 'sort_mass');

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

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

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

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

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

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

echo $eaten;

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

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

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

    return $list[$key];
}

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

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

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

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

    return 0;
}

<?php

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

#$line = fgets(STDIN);

#fputs(STDOUT, 'test');

$candy_num = 0;
$x = 0;

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

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

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

    $map[] = $candy;
}

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

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

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

echo $eaten;

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

echo '2', $x;
?>

<?php

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

$candy_num = 0;
$x = 0;

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

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

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

    $map[] = $candy;
}

uasort($map, 'sort_mass');

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

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

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

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

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

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

echo $eaten;

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

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

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

    return $list[$key];
}

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

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

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

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

    return 0;
}

<?php

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

$candy_num = 0;
$x = 0;

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

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

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

    $map[] = $candy;
}

uasort($map, 'sort_mass');

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

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

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

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

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

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

echo $eaten;

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

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

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

    return $list[$key];
}

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

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

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

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

    return 0;
}

<?php

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

$candy_num = 0;
$x = 0;

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

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

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

    $map[] = $candy;
}

uasort($map, 'sort_mass');

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

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

    return $eaten;
}

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

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

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

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

    return $list[$key];
}

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

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

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

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

    return 0;
}


There are n piles of pebbles on the table, the i-th pile contains ai pebbles. Your task is to paint each pebble using one of the k given colors so that for each color c and any two piles i and j the difference between the number of pebbles of color c in pile i and number of pebbles of color c in pile j is at most one.In other words, let's say that bi, c is the number of pebbles of color c in the i-th pile. Then for any 1 ≤ c ≤ k, 1 ≤ i, j ≤ n the following condition must be satisfied |bi, c - bj, c| ≤ 1. It isn't necessary to use all k colors: if color c hasn't been used in pile i, then bi, c is considered to be zero.

The first line of the input contains positive integers n and k (1 ≤ n, k ≤ 100), separated by a space — the number of piles and the number of colors respectively. The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) denoting number of pebbles in each of the piles.

If there is no way to paint the pebbles satisfying the given condition, output "NO" (without quotes) . Otherwise in the first line output "YES" (without quotes). Then n lines should follow, the i-th of them should contain ai space-separated integers. j-th (1 ≤ j ≤ ai) of these integers should be equal to the color of the j-th pebble in the i-th pile. If there are several possible answers, you may output any of them.

<?php

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

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


You are given a string $$$s=s_1s_2\dots s_n$$$ of length $$$n$$$, which only contains digits $$$1$$$, $$$2$$$, ..., $$$9$$$.A substring $$$s[l \dots r]$$$ of $$$s$$$ is a string $$$s_l s_{l + 1} s_{l + 2} \ldots s_r$$$. A substring $$$s[l \dots r]$$$ of $$$s$$$ is called even if the number represented by it is even. Find the number of even substrings of $$$s$$$. Note, that even if some substrings are equal as strings, but have different $$$l$$$ and $$$r$$$, they are counted as different substrings.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 65000$$$) — the length of the string $$$s$$$. The second line contains a string $$$s$$$ of length $$$n$$$. The string $$$s$$$ consists only of digits $$$1$$$, $$$2$$$, ..., $$$9$$$.

Print the number of even substrings of $$$s$$$.

NoteIn the first example, the $$$[l, r]$$$ pairs corresponding to even substrings are:   $$$s[1 \dots 2]$$$ $$$s[2 \dots 2]$$$ $$$s[1 \dots 4]$$$ $$$s[2 \dots 4]$$$ $$$s[3 \dots 4]$$$ $$$s[4 \dots 4]$$$ In the second example, all $$$10$$$ substrings of $$$s$$$ are even substrings. Note, that while substrings $$$s[1 \dots 1]$$$ and $$$s[2 \dots 2]$$$ both define the substring "2", they are still counted as different substrings.


Eshag has an array $$$a$$$ consisting of $$$n$$$ integers.Eshag can perform the following operation any number of times: choose some subsequence of $$$a$$$ and delete every element from it which is strictly larger than $$$AVG$$$, where $$$AVG$$$ is the average of the numbers in the chosen subsequence.For example, if $$$a = [1 , 4 , 3 , 2 , 4]$$$ and Eshag applies the operation to the subsequence containing $$$a_1$$$, $$$a_2$$$, $$$a_4$$$ and $$$a_5$$$, then he will delete those of these $$$4$$$ elements which are larger than $$$\frac{a_1+a_2+a_4+a_5}{4} = \frac{11}{4}$$$, so after the operation, the array $$$a$$$ will become $$$a = [1 , 3 , 2]$$$.Your task is to find the maximum number of elements Eshag can delete from the array $$$a$$$ by applying the operation described above some number (maybe, zero) times.A sequence $$$b$$$ is a subsequence of an array $$$c$$$ if $$$b$$$ can be obtained from $$$c$$$ by deletion of several (possibly, zero or all) elements.

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

For each test case print a single integer — the maximum number of elements Eshag can delete from the array $$$a$$$.

NoteConsider the first test case.Initially $$$a = [1, 1, 1, 2, 2, 3]$$$.In the first operation, Eshag can choose the subsequence containing $$$a_1$$$, $$$a_5$$$ and $$$a_6$$$, their average is equal to $$$\frac{a_1 + a_5 + a_6}{3} = \frac{6}{3} = 2$$$. So $$$a_6$$$ will be deleted.After this $$$a = [1, 1, 1, 2, 2]$$$.In the second operation, Eshag can choose the subsequence containing the whole array $$$a$$$, the average of all its elements is equal to $$$\frac{7}{5}$$$. So $$$a_4$$$ and $$$a_5$$$ will be deleted.After this $$$a = [1, 1, 1]$$$.In the second test case, Eshag can't delete any element.

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

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

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

  $c = array_count_values($a);

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

  echo $ans.PHP_EOL;
}

?>

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

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

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

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

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

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

?>


Hemose was shopping with his friends Samez, AhmedZ, AshrafEzz, TheSawan and O_E in Germany. As you know, Hemose and his friends are problem solvers, so they are very clever. Therefore, they will go to all discount markets in Germany.Hemose has an array of $$$n$$$ integers. He wants Samez to sort the array in the non-decreasing order. Since it would be a too easy problem for Samez, Hemose allows Samez to use only the following operation:Choose indices $$$i$$$ and $$$j$$$ such that $$$1 \le i, j \le n$$$, and $$$\lvert i - j \rvert \geq x$$$. Then, swap elements $$$a_i$$$ and $$$a_j$$$.Can you tell Samez if there's a way to sort the array in the non-decreasing order by using the operation written above some finite number of times (possibly $$$0$$$)?

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 $$$x$$$ $$$(1 \leq x \leq n \leq 10^5)$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ $$$(1 \leq a_i \leq 10^9)$$$. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, you should output a single string.  If Samez can sort the array in non-decreasing order using the operation written above, output "YES" (without quotes). Otherwise, output "NO" (without quotes). You can print each letter of "YES" and "NO" in any case (upper or lower).

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

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

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

  if ($n >= 2 * $x) {
    echo 'YES'.PHP_EOL;
  } else {
    $f = 0;
    $b = $a;
    sort($b);

    for ($j = $n - $x; $j < $x; $j++) {
      if ($a[$j] !== $b[$j]) {
        $f = 1;
        break;
      }
    }

    if ($f !== 1) {
      echo 'YES'.PHP_EOL;
    } else {
      echo 'NO'.PHP_EOL;
    }
  }
}

?>

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

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

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

  if ($n >= 2 * $x) {
    echo 'YES'.PHP_EOL;
  } else {
    $f = 0;
    $b = $a;
    sort($b);

    for ($j = $n - $x + 2; $j <= $x + 1; $j++) {
      if ($a[$j] !== $b[$j]) {
        $f = 1;
        break;
      }
    }

    if ($f !== 1) {
      echo 'YES'.PHP_EOL;
    } else {
      echo 'NO'.PHP_EOL;
    }
  }
}

?>

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

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

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

  if ($n >= 2 * $x) {
    echo 'YES'.PHP_EOL;
  } else {
    $f = 0;
    $b = $a;
    sort($b);

    for ($j = $n - $x + 2; $j <= $x + 2; $j++) {
      if ($a[$j] !== $b[$j]) {
        $f = 1;
        echo 'NO'.PHP_EOL;
        break;
      }
    }

    if ($f !== 1) {
      echo 'YES'.PHP_EOL;
    }
  }
}

?>

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

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

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

  if ($n >= 2 * $x) {
    echo 'YES'.PHP_EOL;
  } else {
    $f = 0;
    $b = $a;
    sort($b);

    for ($j = $n - $x + 2; $j <= $x; $j++) {
      if ($a[$j] !== $b[$j]) {
        $f = 1;
        echo 'NO'.PHP_EOL;
        break;
      }
    }

    if ($f !== 1) {
      echo 'YES'.PHP_EOL;
    }
  }
}

?>

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

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

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

  if ($n >= 2 * $x) {
    echo 'YES'.PHP_EOL;
  } else {
    $f = 0;
    $b = $a;
    sort($b);

    for ($j = $n - $x + 2; $j <= $x + 1; $j++) {
      if ($a[$j] !== $b[$j]) {
        $f = 1;
        echo 'NO'.PHP_EOL;
        break;
      }
    }

    if ($f !== 1) {
      echo 'YES'.PHP_EOL;
    }
  }
}

?>

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

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

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

  $f = 0;
  $b = $a;
  sort($b);

  for ($j = $n - $x + 1; $j <= $x; $j++) {
    if ($a[$j] !== $b[$j]) {
      $f = 1;
      echo 'NO'.PHP_EOL;
      break;
    }
  }

  if ($f !== 1) {
    echo 'YES'.PHP_EOL;
  }
}

?>

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

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

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

  if ($n >= 2 * $x) {
    echo 'YES'.PHP_EOL;
  } else {
    $f = 0;
    $b = $a;
    sort($b);

    for ($j = $n - $x + 1; $j <= $x; $j++) {
      if ($a[$j] !== $b[$j]) {
        $f = 1;
        echo 'NO'.PHP_EOL;
        break;
      }
    }

    if ($f !== 1) {
      echo 'YES'.PHP_EOL;
    }
  }
}

?>


In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.

The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 2) — the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.

Print the total number of people the restaurant denies service to.

NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.

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

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

echo $reject_counter;

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

echo $reject_counter;


You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position $$$3$$$ and ends in position $$$6$$$), but "aa" or "d" aren't substrings of this string. So the substring of the string $$$s$$$ from position $$$l$$$ to position $$$r$$$ is $$$s[l; r] = s_l s_{l + 1} \dots s_r$$$.You have to choose exactly one of the substrings of the given string and reverse it (i. e. make $$$s[l; r] = s_r s_{r - 1} \dots s_l$$$) to obtain a string that is less lexicographically. Note that it is not necessary to obtain the minimum possible string.If it is impossible to reverse some substring of the given string to obtain a string that is less, print "NO". Otherwise print "YES" and any suitable substring.String $$$x$$$ is lexicographically less than string $$$y$$$, if either $$$x$$$ is a prefix of $$$y$$$ (and $$$x \ne y$$$), or there exists such $$$i$$$ ($$$1 \le i \le min(|x|, |y|)$$$), that $$$x_i < y_i$$$, and for any $$$j$$$ ($$$1 \le j < i$$$) $$$x_j = y_j$$$. Here $$$|a|$$$ denotes the length of the string $$$a$$$. The lexicographic comparison of strings is implemented by operator < in modern programming languages.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the length of $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters.

If it is impossible to reverse some substring of the given string to obtain a string which is lexicographically less, print "NO". Otherwise print "YES" and two indices $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le n$$$) denoting the substring you have to reverse. If there are multiple answers, you can print any.

NoteIn the first testcase the resulting string is "aacabba".

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

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

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

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$s = $ir->readString();

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

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

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

<?php

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

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

	if(!$done) echo "NO";

?>

<?php

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

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

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

	if(!$done) echo "NO";

?>

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

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

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

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

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


The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!

The first line contains two integers, n and k (1 ≤ k ≤ n ≤ 100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.

In t lines, print the actions the programmers need to make. In the i-th line print:   "LEFT" (without the quotes), if the i-th action was "move the ladder to the left";  "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right";  "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder".  The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.

RIGHT
RIGHT
PRINT !
LEFT
PRINT O
LEFT
PRINT G
LEFT
PRINT ?
LEFT
PRINT O
LEFT
PRINT G

NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.

<?php

list($si, $p) = explode(" ", trim(fgets(STDIN)));
$sl = str_split(trim(fgets(STDIN)));

$m = ($p > ($si / 2)) ? 1 : -1;
while($p != 1 && $p != $si)
{
	echo ($m == -1) ? "LEFT" : "RIGHT";
	echo PHP_EOL;

	$p += $m;
}

$m = ($m == -1) ? 1 : -1;
while ($si > 0)
{
	echo "PRINT " . $sl[($p - 1)] . PHP_EOL;
	$si--;
	$p += $m;
	if($si > 0)
	{
		echo ($m == -1) ? "LEFT" : "RIGHT";
		echo PHP_EOL;
	}
}

<?php

list($si, $p) = explode(" ", trim(fgets(STDIN)));
$sl = str_split(trim(fgets(STDIN)));

$m = ($p > ($si / 2)) ? 1 : -1;
while($p != 0 && $p != $si)
{
	echo ($m == -1) ? "LEFT" : "RIGHT";
	echo PHP_EOL;

	$p += $m;
}

$m = ($m == -1) ? 1 : -1;
while ($si > 0)
{
	echo "PRINT " . $sl[($p - 1)] . PHP_EOL;
	$si--;
	$p += $m;
	if($si > 0)
	{
		echo ($m == -1) ? "LEFT" : "RIGHT";
		echo PHP_EOL;
	}
}


Businessman Divan loves chocolate! Today he came to a store to buy some chocolate. Like all businessmen, Divan knows the value of money, so he will not buy too expensive chocolate. At the same time, too cheap chocolate tastes bad, so he will not buy it as well.The store he came to has $$$n$$$ different chocolate bars, and the price of the $$$i$$$-th chocolate bar is $$$a_i$$$ dollars. Divan considers a chocolate bar too expensive if it costs strictly more than $$$r$$$ dollars. Similarly, he considers a bar of chocolate to be too cheap if it costs strictly less than $$$l$$$ dollars. Divan will not buy too cheap or too expensive bars.Divan is not going to spend all his money on chocolate bars, so he will spend at most $$$k$$$ dollars on chocolates.Please determine the maximum number of chocolate bars Divan can buy.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The description of each test case consists of two lines. The first line contains integers $$$n$$$, $$$l$$$, $$$r$$$, $$$k$$$ ($$$1 \le n \le 100$$$, $$$1 \le l \le r \le 10^9$$$, $$$1 \le k \le 10^9$$$) — the lowest acceptable price of a chocolate, the highest acceptable price of a chocolate and Divan's total budget, respectively. The second line contains a sequence $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) integers — the prices of chocolate bars in the store.

For each test case print a single integer — the maximum number of chocolate bars Divan can buy.

NoteIn the first example Divan can buy chocolate bars $$$1$$$ and $$$3$$$ and spend $$$100$$$ dollars on them.In the second example Divan can buy chocolate bars $$$3$$$ and $$$4$$$ and spend $$$7$$$ dollars on them.In the third example Divan can buy chocolate bars $$$3$$$, $$$4$$$, and $$$5$$$ for $$$12$$$ dollars.In the fourth example Divan cannot buy any chocolate bar because each of them is either too cheap or too expensive.In the fifth example Divan cannot buy any chocolate bar because he considers the first bar too cheap, and has no budget for the second or third.In the sixth example Divan can buy all the chocolate bars in the shop.

<?php

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

function solve()
{
    global $file;

    list($n, $l, $r, $k) = array_map('intval', explode(' ', trim(fgets($file))));

    $chocos = array_map('intval', explode(' ', trim(fgets($file))));

    $buyables = [];

    foreach($chocos as $choco)
    {
        if($choco >= $l && $choco <= $r)
        {
            $buyables []= $choco;
        }
    }

    sort($buyables);

    $canBuy = 0;
    $price = 0;

    for($i=0; $i < count($buyables); $i++)
    {
        if($price + $buyables[$i] > $k)
        {
            break;
        }
        else
        {
            $price+= $buyables[$i];
            $canBuy++;
        }
    }

    echo $canBuy . PHP_EOL;
}

$t = + fgets($file);

while($t--) solve();

<?php
ini_set("display_errors", "Off");
error_reporting(0);
$stdin = fopen('php://stdin', 'r');
fscanf($stdin, "%d\n", $caseCount);
$caseResult=[];
for($caseNo=0;$caseNo<$caseCount;$caseNo++){
    fscanf($stdin, "%d %d %d %d\n", $n,$l,$r,$k);
    $an=array();$str="";
    for ($i=0;$i<$n;$i++){$str.="%d ";}
    $an=fscanf($stdin, rtrim($str));
//    var_dump($an);
//    echo "-------------------";
    asort($an);
//    echo 3;
//    foreach ($an as $ark=>$arval){
//        if($arval<$l){}
//    }
    $an1=array_filter($an,function($var)use($l,$r){
//        echo $var.".($l,$r)";
        //        var_dump($rt);
        return ($var>=$l)? ($var<=$r?true:false):false;});
//    print_r($an1);
    $total=0;$count=0;
    foreach ($an1 as $ak=>$aval){
        if(($total+=$aval) >$k){break;}else{$count++;}
//        echo "[$total][$aval]\n";
    }
//    echo "[$count]";
    $caseResult[]=$count;
}
//print_r($caseResult);
$co=0;
foreach ($caseResult as $item) {
    echo "$item";if($co++<$caseCount-1){echo "\n";}
}


Let's say string $$$s$$$ has period $$$k$$$ if $$$s_i = s_{i + k}$$$ for all $$$i$$$ from $$$1$$$ to $$$|s| - k$$$ ($$$|s|$$$ means length of string $$$s$$$) and $$$k$$$ is the minimum positive integer with this property.Some examples of a period: for $$$s$$$="0101" the period is $$$k=2$$$, for $$$s$$$="0000" the period is $$$k=1$$$, for $$$s$$$="010" the period is $$$k=2$$$, for $$$s$$$="0011" the period is $$$k=4$$$.You are given string $$$t$$$ consisting only of 0's and 1's and you need to find such string $$$s$$$ that:  String $$$s$$$ consists only of 0's and 1's;  The length of $$$s$$$ doesn't exceed $$$2 \cdot |t|$$$;  String $$$t$$$ is a subsequence of string $$$s$$$;  String $$$s$$$ has smallest possible period among all strings that meet conditions 1—3. Let us recall that $$$t$$$ is a subsequence of $$$s$$$ if $$$t$$$ can be derived from $$$s$$$ by deleting zero or more elements (any) without changing the order of the remaining elements. For example, $$$t$$$="011" is a subsequence of $$$s$$$="10101".

The first line contains single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of test cases. Next $$$T$$$ lines contain test cases — one per line. Each line contains string $$$t$$$ ($$$1 \le |t| \le 100$$$) consisting only of 0's and 1's.

Print one string for each test case — string $$$s$$$ you needed to find. If there are multiple solutions print any one of them.

NoteIn the first and second test cases, $$$s = t$$$ since it's already one of the optimal solutions. Answers have periods equal to $$$1$$$ and $$$2$$$, respectively.In the third test case, there are shorter optimal solutions, but it's okay since we don't need to minimize the string $$$s$$$. String $$$s$$$ has period equal to $$$1$$$.

<?php
    define("MAXN", 200001) ;

    function solve($x, $y, $a, $b)
    {
    }

    $a = intval(fgets(STDIN));
    while($a --)
    {
        $Period = fgets(STDIN) ;

        $len = strlen($Period) - 2 ;

        $cnt1 = 0 ;
        $cnt0 = 0 ;

        for($i = 0; $i < $len; $i ++)
        {
            if($Period[$i] == '0') $cnt0 ++ ;
            else $cnt1 ++ ;
        }

        if($cnt0 == 0 || $cnt1 == 0) echo $Period ;
        else echo str_repeat("10", $len) . "\n" ;
    }
?>

<?php
    define("MAXN", 200001) ;

    function solve($x, $y, $a, $b)
    {
    }

    $a = intval(fgets(STDIN));
    while($a --)
    {
        $Period = fgets(STDIN) ;

        $len = strlen($Period) - 1 ;

        $cnt1 = 0 ;
        $cnt0 = 0 ;

        for($i = 0; $i < $len; $i ++)
        {
            if($Period[$i] == '0') $cnt0 ++ ;
            else $cnt1 ++ ;
        }

        if($cnt0 == 0 || $cnt1 == 0) echo $Period ;
        else echo str_repeat("10", $len) . "\n" ;
    }
?>

<?php
    define("MAXN", 200001) ;

    function solve($x, $y, $a, $b)
    {
    }

    $a = intval(fgets(STDIN));
    while($a --)
    {
        $Period = fgets(STDIN) ;

        $len = strlen($Period) - 1 ;

        $cnt1 = 0 ;
        $cnt0 = 0 ;

        for($i = 0; $i < $len; $i ++)
        {
            if($Period[$i] == '0') $cnt0 ++ ;
            else $cnt1 ++ ;
        }

        if($cnt0 == 0 || $cnt1 == 0) echo $Period . "\n" ;
        else echo str_repeat("10", $len) . "\n" ;
    }
?>


Hanh lives in a shared apartment. There are $$$n$$$ people (including Hanh) living there, each has a private fridge. $$$n$$$ fridges are secured by several steel chains. Each steel chain connects two different fridges and is protected by a digital lock. The owner of a fridge knows passcodes of all chains connected to it. A fridge can be open only if all chains connected to it are unlocked. For example, if a fridge has no chains connected to it at all, then any of $$$n$$$ people can open it.    For exampe, in the picture there are $$$n=4$$$ people and $$$5$$$ chains. The first person knows passcodes of two chains: $$$1-4$$$ and $$$1-2$$$. The fridge $$$1$$$ can be open by its owner (the person $$$1$$$), also two people $$$2$$$ and $$$4$$$ (acting together) can open it. The weights of these fridges are $$$a_1, a_2, \ldots, a_n$$$. To make a steel chain connecting fridges $$$u$$$ and $$$v$$$, you have to pay $$$a_u + a_v$$$ dollars. Note that the landlord allows you to create multiple chains connecting the same pair of fridges. Hanh's apartment landlord asks you to create exactly $$$m$$$ steel chains so that all fridges are private. A fridge is private if and only if, among $$$n$$$ people living in the apartment, only the owner can open it (i.e. no other person acting alone can do it). In other words, the fridge $$$i$$$ is not private if there exists the person $$$j$$$ ($$$i \ne j$$$) that the person $$$j$$$ can open the fridge $$$i$$$.For example, in the picture all the fridges are private. On the other hand, if there are $$$n=2$$$ fridges and only one chain (which connects them) then both fridges are not private (both fridges can be open not only by its owner but also by another person).Of course, the landlord wants to minimize the total cost of all steel chains to fulfill his request. Determine whether there exists any way to make exactly $$$m$$$ chains, and if yes, output any solution that minimizes the total cost.

Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 10$$$). Then the descriptions of the test cases follow. The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$2 \le n \le 1000$$$, $$$1 \le m \le n$$$) — the number of people living in Hanh's apartment and the number of steel chains that the landlord requires, respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^4$$$) — weights of all fridges.

For each test case:   If there is no solution, print a single integer $$$-1$$$.  Otherwise, print a single integer $$$c$$$ — the minimum total cost. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \ne v_i$$$), meaning that the $$$i$$$-th steel chain connects fridges $$$u_i$$$ and $$$v_i$$$. An arbitrary number of chains can be between a pair of fridges.  If there are multiple answers, print any.


You have two positive integers $$$a$$$ and $$$b$$$.You can perform two kinds of operations:  $$$a = \lfloor \frac{a}{b} \rfloor$$$ (replace $$$a$$$ with the integer part of the division between $$$a$$$ and $$$b$$$)  $$$b=b+1$$$ (increase $$$b$$$ by $$$1$$$) Find the minimum number of operations required to make $$$a=0$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The only line of the description of each test case contains two integers $$$a$$$, $$$b$$$ ($$$1 \le a,b \le 10^9$$$).

For each test case, print a single integer: the minimum number of operations required to make $$$a=0$$$.

NoteIn the first test case, one of the optimal solutions is:  Divide $$$a$$$ by $$$b$$$. After this operation $$$a = 4$$$ and $$$b = 2$$$.  Divide $$$a$$$ by $$$b$$$. After this operation $$$a = 2$$$ and $$$b = 2$$$.  Increase $$$b$$$. After this operation $$$a = 2$$$ and $$$b = 3$$$.  Divide $$$a$$$ by $$$b$$$. After this operation $$$a = 0$$$ and $$$b = 3$$$.

<?php

$times = (int) trim(fgets(STDIN));
for ($i = 0; $i < $times; ++$i) {
    list($ai[], $bi[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($i = 0; $i < $times; ++$i) {
    $a = &$ai[$i];
    $b = &$bi[$i];
    $mn = PHP_INT_MAX;
    for ($j = $b;; ++$j) {
        if (1 == $j) {
            continue;
        }
        $cnt = $j - $b;
        $tmp = $a;
        while ($tmp > 0) {
            $tmp = floor($tmp / $j);
            ++$cnt;
        }
        if ($mn > $cnt) {
            $mn = $cnt;
        } elseif ($mn < $cnt) {
            break;
        }
    }
    echo $mn.PHP_EOL;
}

<?php

$times = (int) trim(fgets(STDIN));
for ($i = 0; $i < $times; ++$i) {
    list($ai[], $bi[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($i = 0; $i < $times; ++$i) {
    $a = &$ai[$i];
    $b = &$bi[$i];
    $mn = PHP_INT_MAX;
    for ($j = $b;; ++$j) {
        if (1 == $j) {
            continue;
        }
        $cnt = $j - $b + floor(log($a, $j)) + 1;
        if ($mn > $cnt) {
            $mn = $cnt;
        } elseif ($mn < $cnt) {
            break;
        }
    }
    echo $mn.PHP_EOL;
}


You are a coach at your local university. There are $$$n$$$ students under your supervision, the programming skill of the $$$i$$$-th student is $$$a_i$$$.You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than $$$5$$$.Your task is to report the maximum possible number of students in a balanced team.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is a programming skill of the $$$i$$$-th student.

Print one integer — the maximum possible number of students in a balanced team.

NoteIn the first example you can create a team with skills $$$[12, 17, 15]$$$.In the second example you can take all students in a team because their programming skills are equal.In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).


Today, Yasser and Adel are at the shop buying cupcakes. There are $$$n$$$ cupcake types, arranged from $$$1$$$ to $$$n$$$ on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type $$$i$$$ is an integer $$$a_i$$$. There are both tasty and nasty cupcakes, so the tastiness can be positive, zero or negative.Yasser, of course, wants to try them all, so he will buy exactly one cupcake of each type.On the other hand, Adel will choose some segment $$$[l, r]$$$ $$$(1 \le l \le r \le n)$$$ that does not include all of cupcakes (he can't choose $$$[l, r] = [1, n]$$$) and buy exactly one cupcake of each of types $$$l, l + 1, \dots, r$$$.After that they will compare the total tastiness of the cupcakes each of them have bought. Yasser will be happy if the total tastiness of cupcakes he buys is strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel's choice.For example, let the tastinesses of the cupcakes be $$$[7, 4, -1]$$$. Yasser will buy all of them, the total tastiness will be $$$7 + 4 - 1 = 10$$$. Adel can choose segments $$$[7], [4], [-1], [7, 4]$$$ or $$$[4, -1]$$$, their total tastinesses are $$$7, 4, -1, 11$$$ and $$$3$$$, respectively. Adel can choose segment with tastiness $$$11$$$, and as $$$10$$$ is not strictly greater than $$$11$$$, Yasser won't be happy :(Find out if Yasser will be happy after visiting the shop.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$), where $$$a_i$$$ represents the tastiness of the $$$i$$$-th type of cupcake. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

For each test case, print "YES", if the total tastiness of cupcakes Yasser buys will always be strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel's choice. Otherwise, print "NO".

NoteIn the first example, the total tastiness of any segment Adel can choose is less than the total tastiness of all cupcakes.In the second example, Adel will choose the segment $$$[1, 2]$$$ with total tastiness $$$11$$$, which is not less than the total tastiness of all cupcakes, which is $$$10$$$.In the third example, Adel can choose the segment $$$[3, 3]$$$ with total tastiness of $$$5$$$. Note that Yasser's cupcakes' total tastiness is also $$$5$$$, so in that case, the total tastiness of Yasser's cupcakes isn't strictly greater than the total tastiness of Adel's cupcakes.


Inflation has occurred in Berlandia, so the store needs to change the price of goods.The current price of good $$$n$$$ is given. It is allowed to increase the price of the good by $$$k$$$ times, with $$$1 \le k \le m$$$, k is an integer. Output the roundest possible new price of the good. That is, the one that has the maximum number of zeros at the end.For example, the number 481000 is more round than the number 1000010 (three zeros at the end of 481000 and only one at the end of 1000010).If there are several possible variants, output the one in which the new price is maximal.If it is impossible to get a rounder price, output $$$n \cdot m$$$ (that is, the maximum possible price).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. Each test case consists of one line. This line contains two integers: $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^9$$$). Where $$$n$$$ is the old price of the good, and the number $$$m$$$ means that you can increase the price $$$n$$$ no more than $$$m$$$ times.

For each test case, output on a separate line the roundest integer of the form $$$n \cdot k$$$ ($$$1 \le k \le m$$$, $$$k$$$ — an integer). If there are several possible variants, output the one in which the new price (value $$$n \cdot k$$$) is maximal. If it is impossible to get a more rounded price, output $$$n \cdot m$$$ (that is, the maximum possible price).

NoteIn the first case $$$n = 6$$$, $$$m = 11$$$. We cannot get a number with two zeros or more at the end, because we need to increase the price $$$50$$$ times, but $$$50 > m = 11$$$. The maximum price multiple of $$$10$$$ would be $$$6 \cdot 10 = 60$$$.In the second case $$$n = 5$$$, $$$m = 43$$$. The maximum price multiple of $$$100$$$ would be $$$5 \cdot 40 = 200$$$.In the third case, $$$n = 13$$$, $$$m = 5$$$. All possible new prices will not end in $$$0$$$, then you should output $$$n \cdot m = 65$$$.In the fourth case, you should increase the price $$$15$$$ times.In the fifth case, increase the price $$$12000$$$ times.

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s,$t] = explode(' ', trim(fgets(STDIN)));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$s = explode(' ', trim(fgets(STDIN)));
//function decr($v){return --$v;}
//$alpha='abcdefghijklmnopqrstuvwxyz';
//$mod=1000000009;
//$mod=1000000007;
//$mod=998244353;
//$a=[];
//$b=[];
for($i=0;$i<$t;$i++){
    [$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $now = 1000000000000000000;
    while(true){
        $gcd=intval(gcd($n,$now));
        $p = $now / $gcd;
        if($p <= $m){
            $ans[] = $p * intdiv($m, $p) * $n;
            break;
        }
        $now /= 10;
    }
}

echo implode(PHP_EOL, $ans);

// 最小公約数（２つ）（ユークリッドの互除法）
function gcd($a, $b){
    if($b===0){
      return $a;
    }
    return gcd($b, $a%$b);
  }


Dasha logged into the system and began to solve problems. One of them is as follows:Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: ci = bi - ai.About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≤ ai ≤ r and l ≤ bi ≤ r. About sequence c we know that all its elements are distinct.  Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test.Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that pi equals to the number of integers which are less than or equal to ci in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively.Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct.

The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ 109) — the length of the sequence and boundaries of the segment where the elements of sequences a and b are. The next line contains n integers a1,  a2,  ...,  an (l ≤ ai ≤ r) — the elements of the sequence a. The next line contains n distinct integers p1,  p2,  ...,  pn (1 ≤ pi ≤ n) — the compressed sequence of the sequence c.

If there is no the suitable sequence b, then in the only line print "-1". Otherwise, in the only line print n integers — the elements of any suitable sequence b.

NoteSequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1,  - 2,  - 6, 0] (note that ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].


Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once.Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that.

The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@».

If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them.

<?php

$r = '/^([^@]+@[^@]+)*$/';
$s = trim(fgets(STDIN));
preg_match($r, $s, $matches);
if (count($matches) == 0) {
	print("No solution\n");
} else {
	$res = array();
	while (strlen($s) > 0) {
		preg_match($r, $s, $matches);
		$x = $matches[1];
		array_push($res, $x);
		$s = substr($s, 0, strlen($s) - strlen($x));
	}
	print(implode(',',array_reverse($res))."\n");
}

?>

<?

$r = fopen('php://stdin','r');
$s = '';
while (!feof($r))
{
    $s .= fgets($r);
}
$s = trim($s);

function getEmails($s)
{
    if(substr($s,0,1) == '@')
    {
        echo 'No solution';
        exit;
    }

    if(substr($s,-1) == '@')
    {
        echo 'No solution';
        exit;
    }

    $aOut = array();
    if(strpos($s, '@') === false)
    {
        echo 'No solution';
        exit;
    }

    $iPos = strpos($s, '@');
    $iL = strlen($s);
    $sNew = substr($s, 0,($iPos+2));
    if(substr($sNew,-1) == '@')
    {
        echo 'No solution';
        exit;
    }
    $s = substr($s, ($iPos+2),$iL);

    if(strpos($s, '@') === false)
    {
        $sNew .= $s;
        $s = '';
    }

    $aOut[] = $sNew;
    if(strlen($s))
    {
        $aOut[] = getEmails($s);
    }
    return implode(',',$aOut);
}

echo getEmails($s);

<?php
$a = trim(fgets(STDIN));
$b = str_split($a);
$c = array();
$d = 0;
$f = array();
if($b[0] == "@")
{
    print "No solution";
}
else
{
    for($x = 0; $x < count($b); $x++)
    {
        if($b[$x] == "@")
        {
            array_push($c, $x);
        }
    }
    for($x = count($c) - 1; $x > 0; $x--)
    {
        if(($c[$x] - $c[$x - 1]) <= 2)
        {
            $d = 1;
            break;
        }
    }
    if($d == 1)
    {
        print "No solution";
    }
    else
    {
        for($x = 0; $x < count($c); $x++)
        {
            $e = implode(array_slice($b, 0, $c[$x] + 2)) . ",";
            array_push($f, $e);
            array_splice($b, 0, $c[$x] + 2);
        }
    }
    print substr(implode($f), 0, strlen(implode($f)) - 1);
}
?>

<?php

$r = '/^([^@]+@[^@]+)*$/';
$s = fgets(STDIN);
preg_match($r, $s, $matches);
if (count($matches) == 0) {
	print("No solution\n");
} else {
	$res = array();
	while (strlen($s) > 0) {
		preg_match($r, $s, $matches);
		$x = $matches[1];
		array_push($res, $x);
		$s = substr($s, 0, strlen($s) - strlen($x));
	}
	print(implode(',',array_reverse($res))."\n");
}

?>

<?

$r = fopen('php://stdin','r');
$s = '';
while (!feof($r))
{
    $s .= fgets($r);
}

function getEmails($s)
{
    if(substr($s,0,1) == '@')
    {
        echo 'No solution';
        exit;
    }

    if(substr($s,-1) == '@')
    {
        echo 'No solution';
        exit;
    }

    $aOut = array();
    if(strpos($s, '@') === false)
    {
        echo 'No solution';
        exit;
    }

    $iPos = strpos($s, '@');
    $sNew = substr($s, ($iPos+2));
    $s = substr($s, -1*strlen($sNew));
    if(strpos($sNew, '@') === false)
    {
        $s .= $sNew;
        $sNew = '';
    }
    $aOut[] = $s;
    if(strlen($sNew))
    {
        $aOut[] = getEmails($sNew);
    }
    return implode(',',$aOut);
}

echo getEmails($s);

<?

$r = fopen('php://stdin','r');
$s = '';
while (!feof($r))
{
    $s .= fgets($r);
}
$s = trim($s);

function getEmails($s)
{
    if(substr($s,0,1) == '@')
    {
        echo 'No solution';
        exit;
    }

    if(substr($s,-1) == '@')
    {
        echo 'No solution';
        exit;
    }

    $aOut = array();
    if(strpos($s, '@') === false)
    {
        echo 'No solution';
        exit;
    }

    $iPos = strpos($s, '@');
    $sNew = substr($s, ($iPos+2));
    $s = substr($s, -1*strlen($sNew));
    if(strpos($sNew, '@') === false)
    {
        $s .= $sNew;
        $sNew = '';
    }
    $aOut[] = $s;
    if(strlen($sNew))
    {
        $aOut[] = getEmails($sNew);
    }
    return implode(',',$aOut);
}

echo getEmails($s);


You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index.

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$.

For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number.

NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it.

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

  $t = getT();
  $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = 0;
      $s = getT();
      $b = getT();
      if(strlen($b) == 1 && $b == 'a') {
            $ans +=1;
      } else {
         if(strpos($b, 'a') !== false) {
            $ans = -1;
         } else {

             $len = strlen($s);
             $ans = 1;
             for($jt = 0; $jt < $len; $jt++) {
                 $ans = bcmul($ans, 2);
             }

         }
      }

        echo $ans, $inter;

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
  function ComandR($aCordinate) {
      return [$aCordinate[0] + 1, $aCordinate[1]];
  }
  function ComandL($aCordinate) {
      return [$aCordinate[0] - 1, $aCordinate[1]];
  }
  function ComandU($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] + 1];
  }
  function ComandD($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] - 1];
  }

  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;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

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

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

        return $a[$n];
    }

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

  $t = getT();
  $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = 0;
      $s = getT();
      $b = getT();
      if(strlen($b) == 1 && $b == 'a') {
            $ans +=1;
      } else {
         if(strpos($b, 'a') !== false) {
            $ans = -1;
         } else {

             $len = strlen($s);
             $ans = 1;
             for($jt = 0; $jt < $len; $jt++) {
                 $ans = $ans * 2;
             }

         }
      }

        echo $ans, $inter;

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
  function ComandR($aCordinate) {
      return [$aCordinate[0] + 1, $aCordinate[1]];
  }
  function ComandL($aCordinate) {
      return [$aCordinate[0] - 1, $aCordinate[1]];
  }
  function ComandU($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] + 1];
  }
  function ComandD($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] - 1];
  }

  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;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

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

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

        return $a[$n];
    }

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

  $t = getT();
  $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = 1;
      $s = getT();
      $b = getT();
      if(strlen($b) == 1) {
          if($b != 'a') {
            $ans +=1;
          }

      } else {
         if(strpos($b, 'a') >= 0) {
            $ans = -1;
         } else {
             $len = strlen($s);
             $ans = fab2($len, [0, 1]) + 2;
         }
      }

        echo $ans, $inter;

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
  function ComandR($aCordinate) {
      return [$aCordinate[0] + 1, $aCordinate[1]];
  }
  function ComandL($aCordinate) {
      return [$aCordinate[0] - 1, $aCordinate[1]];
  }
  function ComandU($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] + 1];
  }
  function ComandD($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] - 1];
  }

  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;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

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

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

        return $a[$n];
    }

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

  $t = getT();
  $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = 1;
      $s = getT();
      $b = getT();
      if(strlen($b) == 1) {
          if($b != 'a') {
            $ans +=1;
          }

      } else {
         if(strpos($b, 'a') >= 0) {
            $ans = -1;
         } else {
             $ans = strlen($s) + 2;
         }
      }

        echo $ans, $inter;

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
  function ComandR($aCordinate) {
      return [$aCordinate[0] + 1, $aCordinate[1]];
  }
  function ComandL($aCordinate) {
      return [$aCordinate[0] - 1, $aCordinate[1]];
  }
  function ComandU($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] + 1];
  }
  function ComandD($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] - 1];
  }

  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;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

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

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

  $t = getT();
  $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = 1;
      $s = getT();
      $b = getT();
      if(strlen($b) == 1) {
          if($b != 'a') {
            $ans +=1;
          }

      } else {
         if(strpos($b, 'a') >= 0) {
            $ans = -1;
         } else {
             $ans = strlen($s);
         }
      }

        echo $ans, $inter;

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
  function ComandR($aCordinate) {
      return [$aCordinate[0] + 1, $aCordinate[1]];
  }
  function ComandL($aCordinate) {
      return [$aCordinate[0] - 1, $aCordinate[1]];
  }
  function ComandU($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] + 1];
  }
  function ComandD($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] - 1];
  }

  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;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

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


Vova's house is an array consisting of $$$n$$$ elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The $$$i$$$-th element of the array is $$$1$$$ if there is a heater in the position $$$i$$$, otherwise the $$$i$$$-th element of the array is $$$0$$$.Each heater has a value $$$r$$$ ($$$r$$$ is the same for all heaters). This value means that the heater at the position $$$pos$$$ can warm up all the elements in range $$$[pos - r + 1; pos + r - 1]$$$.Vova likes to walk through his house while he thinks, and he hates cold positions of his house. Vova wants to switch some of his heaters on in such a way that each element of his house will be warmed up by at least one heater. Vova's target is to warm up the whole house (all the elements of the array), i.e. if $$$n = 6$$$, $$$r = 2$$$ and heaters are at positions $$$2$$$ and $$$5$$$, then Vova can warm up the whole house if he switches all the heaters in the house on (then the first $$$3$$$ elements will be warmed up by the first heater and the last $$$3$$$ elements will be warmed up by the second heater).Initially, all the heaters are off.But from the other hand, Vova didn't like to pay much for the electricity. So he wants to switch the minimum number of heaters on in such a way that each element of his house is warmed up by at least one heater.Your task is to find this number of heaters or say that it is impossible to warm up the whole house.

The first line of the input contains two integers $$$n$$$ and $$$r$$$ ($$$1 \le n, r \le 1000$$$) — the number of elements in the array and the value of heaters. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$) — the Vova's house description.

Print one integer — the minimum number of heaters needed to warm up the whole house or -1 if it is impossible to do it.

NoteIn the first example the heater at the position $$$2$$$ warms up elements $$$[1; 3]$$$, the heater at the position $$$3$$$ warms up elements $$$[2, 4]$$$ and the heater at the position $$$6$$$ warms up elements $$$[5; 6]$$$ so the answer is $$$3$$$.In the second example the heater at the position $$$1$$$ warms up elements $$$[1; 3]$$$ and the heater at the position $$$5$$$ warms up elements $$$[3; 5]$$$ so the answer is $$$2$$$.In the third example there are no heaters so the answer is -1.In the fourth example the heater at the position $$$3$$$ warms up elements $$$[1; 5]$$$, the heater at the position $$$6$$$ warms up elements $$$[4; 8]$$$ and the heater at the position $$$10$$$ warms up elements $$$[8; 10]$$$ so the answer is $$$3$$$.

<?php
    $str =fgets(STDIN);

    $str = explode(' ',$str);
    $n = (int)$str[0];
    $r = (int)$str[1];
    $r--;

    $str=fgets(STDIN);
    $str = explode(' ',$str);
    $elm = [];
    $i = 0;

    $s = '';
    while($i<$n) {
        $elm[$i]=(int)$str[$i];
        $s.=$str[$i]; //вся строка
        $i++;
    }

    //недопустимая строка
    $i=0;
    $nstr = '';
    while($i++<$r) {
        $nstr.='00';
    }
    $nstr.='0';

    //не допустимо в середине строки
    if (strstr($s, $nstr) || !strstr($s, '1')) {
        echo '-1';
        die();
    }

    //не допустимо в начале и в конце строки
    $i=0;
    $nstr = '';
    while($i++<$r) {
        $nstr.='0';
    }
    $nstr.='0';

    $start = substr($s, 0, ($r+1));
    $fin = substr($s, $n-($r+1), ($r+1));

    if ($nstr==$start || $fin == $nstr) {
        echo '-1';
        die();
    }

    $count = 0;

    //смотрим с чего начинать первый отрезок
    $i=$r;
    while ($elm[$i]!=1) {
        $i--;
    }
    $start = $i;

    $count++;

    //начинаем искать, идти пошагово
    while ( ($i+$r) <= ($n-2)) {

        $i+=($r*2+1);
        while (!isset($elm[$i]) || $elm[$i]!=1) {
            $i--;
        }
        $count++;
    }
    echo $count;
?>


Formula 1 officials decided to introduce new competition. Cars are replaced by space ships and number of points awarded can differ per race.Given the current ranking in the competition and points distribution for the next race, your task is to calculate the best possible ranking for a given astronaut after the next race. It's guaranteed that given astronaut will have unique number of points before the race.

The first line contains two integer numbers $$$N$$$ ($$$1 \leq N \leq 200000$$$) representing number of F1 astronauts, and current position of astronaut $$$D$$$ ($$$1 \leq D \leq N$$$) you want to calculate best ranking for (no other competitor will have the same number of points before the race). The second line contains $$$N$$$ integer numbers $$$S_k$$$ ($$$0 \leq S_k \leq 10^8$$$, $$$k=1...N$$$), separated by a single space, representing current ranking of astronauts. Points are sorted in non-increasing order. The third line contains $$$N$$$ integer numbers $$$P_k$$$ ($$$0 \leq P_k \leq 10^8$$$, $$$k=1...N$$$), separated by a single space, representing point awards for the next race. Points are sorted in non-increasing order, so winner of the race gets the maximum number of points.

Output contains one integer number — the best possible ranking for astronaut after the race. If multiple astronauts have the same score after the race, they all share the best ranking.

NoteIf the third ranked astronaut wins the race, he will have 35 points. He cannot take the leading position, but he can overtake the second position if the second ranked astronaut finishes the race at the last position.


You are given an array $$$a$$$ of $$$n$$$ integers and an integer $$$s$$$. It is guaranteed that $$$n$$$ is odd.In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to $$$s$$$.The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array $$$6, 5, 8$$$ is equal to $$$6$$$, since if we sort this array we will get $$$5, 6, 8$$$, and $$$6$$$ is located on the middle position.

The first line contains two integers $$$n$$$ and $$$s$$$ ($$$1\le n\le 2\cdot 10^5-1$$$, $$$1\le s\le 10^9$$$) — the length of the array and the required value of median. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1\le a_i \le 10^9$$$) — the elements of the array $$$a$$$. It is guaranteed that $$$n$$$ is odd.

In a single line output the minimum number of operations to make the median being equal to $$$s$$$.

NoteIn the first sample, $$$6$$$ can be increased twice. The array will transform to $$$8, 5, 8$$$, which becomes $$$5, 8, 8$$$ after sorting, hence the median is equal to $$$8$$$.In the second sample, $$$19$$$ can be increased once and $$$15$$$ can be increased five times. The array will become equal to $$$21, 20, 12, 11, 20, 20, 12$$$. If we sort this array we get $$$11, 12, 12, 20, 20, 20, 21$$$, this way the median is $$$20$$$.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
sort($c);
$d = 0;
if($c[floor($a / 2)] < $b)
{
     for($x = floor($a / 2); $x < $a; $x++)
     {
          if($c[$x] < $b)
          {
               $d += $b - $c[$x];
          }
          else
          {
               break;
          }
     }
     print $d;
}
elseif($c[floor($a / 2)] == $b)
{
     print $d;
}
elseif($c[floor($a / 2)] > $b)
{
     for($x = floor($a / 2); $x >= 0; $x--)
     {
          if($c[$x] > $b)
          {
               $d += $c[$x] - $b;
          }
          else
          {
               break;
          }
     }
     print $d;
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
sort($c);
$d = 0;
if($c[floor($a / 2)] < $b)
{
     for($x = floor($a / 2); $x < $a; $x++)
     {
          if($c[$x] < $b)
          {
               $d += $b - $c[$x];
          }
          else
          {
               break;
          }
     }
     print $d;
}
elseif($c[floor($a / 2)] == $b)
{
     print $d;
}
elseif($c[floor($a / 2)] > $b)
{
     for($x = floor($a / 2); $x >= 0; $x--)
     {
          if($c[$x] < $b)
          {
               $d += $b - $c[$x];
          }
          else
          {
               break;
          }
     }
     print $d;
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
sort($c);
$d = 0;
if($c[floor($a / 2)] < $b)
{
     for($x = floor($a / 2); $x < $a; $x++)
     {
          if($c[$x] < $b)
          {
               $d += $b - $c[$x];
          }
          else
          {
               break;
          }
     }
     print $d;
}
elseif($c[floor($a / 2)] == $b)
{
     print $d;
}
elseif($c[floor($a / 2)] > $b)
{
     for($x = floor($a / 2); $x >= 0; $x--)
     {
          if($c[$x] > $b)
          {
               $d += $b - $c[$x];
          }
          else
          {
               break;
          }
     }
     print $d;
}
?>


A telephone number is a sequence of exactly $$$11$$$ digits such that its first digit is 8.Vasya and Petya are playing a game. Initially they have a string $$$s$$$ of length $$$n$$$ ($$$n$$$ is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it from the current string. For example, if the current string 1121, after the player's move it may be 112, 111 or 121. The game ends when the length of string $$$s$$$ becomes 11. If the resulting string is a telephone number, Vasya wins, otherwise Petya wins.You have to determine if Vasya has a winning strategy (that is, if Vasya can win the game no matter which characters Petya chooses during his moves).

The first line contains one integer $$$n$$$ ($$$13 \le n < 10^5$$$, $$$n$$$ is odd) — the length of string $$$s$$$. The second line contains the string $$$s$$$ ($$$|s| = n$$$) consisting only of decimal digits.

If Vasya has a strategy that guarantees him victory, print YES. Otherwise print NO.

NoteIn the first example Vasya needs to erase the second character. Then Petya cannot erase a character from the remaining string 880011223344 so that it does not become a telephone number.In the second example after Vasya's turn Petya can erase one character character 8. The resulting string can't be a telephone number, because there is no digit 8 at all.

<?php
  $n = trim(fgets(STDIN));
  $m = trim(fgets(STDIN));
  $m = substr($m, 0, -10);
  $arr = str_split($m, 1);
  $hod = ($n-11)/2;
  $i = 0;
  foreach ($arr as $sK => $sV) {
      if($sV == 8){
          $i++;
      }
      if($i > $hod) {
              echo "YES";
              exit;
        }
  }
  echo "NO";
?>

<?php
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $m = str_split($s);
    $b = true;
    $s = substr($s, 0, strlen($s) - 10);
    preg_match_all("/8/", $s, $a);
    if (count($a[0]) >= strlen($s)/2) {
        echo 'YES';
    } else {
        echo 'NO';
    }

?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$sWord = trim(fgets(STDIN));
$i = $j = 0;
foreach (str_split(substr($sWord, 0,$n - 10)) as $sK => $sV){
    if($sV == '8'){
        $i++;
    } else {
        $j++;
    }
}
if($i >= $j){
    echo 'YES';
} else {
    echo 'NO';
}

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$s = $ir->readString();

$cnt = 0;
for ($i=0; $i<$n-10; $i++) {
	if ($s[$i] == '8') {
		$cnt++;
	} else {
		$cnt--;
	}
}

if ($cnt>0) {
	echo 'YES';
} else {
	echo 'NO';
}

<?php

$n = trim(fgets(STDIN));
$s = str_split(trim(fgets(STDIN)));
$c = 0;
for ($i=0; $i<$n-10; $i++) if ($s[$i] == '8') $c++; else $c--;
echo ($cnt > 0 ? "YES" : "NO");

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$sWord = trim(fgets(STDIN));
$i = 0;
foreach (str_split(substr($sWord, 0,$n -11)) as $sK => $sV){
    if($sV == '8'){
        $i++;
    }
}
if($i >= ($n - 11)/2){
    echo 'YES';
} else {
    echo 'NO';
}


You're given an array $$$a$$$ of length $$$2n$$$. Is it possible to reorder it in such way so that the sum of the first $$$n$$$ elements isn't equal to the sum of the last $$$n$$$ elements?

The first line contains an integer $$$n$$$ ($$$1 \le n \le 1000$$$), where $$$2n$$$ is the number of elements in the array $$$a$$$. The second line contains $$$2n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{2n}$$$ ($$$1 \le a_i \le 10^6$$$) — the elements of the array $$$a$$$.

If there's no solution, print "-1" (without quotes). Otherwise, print a single line containing $$$2n$$$ space-separated integers. They must form a reordering of $$$a$$$. You are allowed to not change the order.

NoteIn the first example, the first $$$n$$$ elements have sum $$$2+1+3=6$$$ while the last $$$n$$$ elements have sum $$$1+1+2=4$$$. The sums aren't equal.In the second example, there's no solution.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = array_sum(array_slice($b, 0, $a));
$d = array_sum(array_slice($b, $a));
if($c == $d)
{
     print "-1";
}
else
{
     print implode(" ", $b);
}
?>

<?php
list($k) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));

list($aArray1,$aArray2) = array_chunk($aArray, ceil(count($aArray) / 2));
$iMin = min($aArray1);
$iMinIndex = array_keys($aArray1, min($aArray1));
$iMax = max($aArray2);
$iMaxIndex = array_keys($aArray2, max($aArray2));
if(array_sum($aArray1) != array_sum($aArray2) && $iMin != $iMax){
    echo implode(' ', $aArray);
} elseif(array_sum($aArray1) == array_sum($aArray2) && $iMin == $iMax){
    echo '-1';
} else {
    $aArray1[$iMinIndex[0]] = $iMax;
    $aArray2[$iMaxIndex[0]] = $iMin;
    echo implode(' ',$aArray1) . ' ' . implode(' ',$aArray2);

}

<?php
# 1174A
$stdin = STDIN;

$n = trim(fgets($stdin));
$a = explode(' ', trim(fgets($stdin)));
sort($a);

if (array_sum(array_slice($a, 0, $n)) === array_sum(array_slice($a, $n, $n))) {
    echo '-1';
} else {
    echo implode(' ', $a);
}

<?php

$fp = fopen('php://stdin', 'r');
$n = trim(fgets($fp)) + 0;
$numbers = explode(" ", trim(fgets($fp)));
foreach ($numbers as $key => $number) {
    $numbers[$key] = $number + 0;
}
sort($numbers, SORT_NUMERIC);
$check = $numbers[0];
$check_flg = false;
foreach ($numbers as $number) {
    if ($check != $number) {
        $check_flg = true;
        break;
    }
}
if ($check_flg) {
    foreach ($numbers as $number) {
        echo "$number ";
    }
} else {
    echo "-1";
}

<?php
$s = file_get_contents('php://stdin');
$init = explode("\n", $s);
$n = $init[0];
$s = $init[1];

function merge_sort($my_array){
	if(count($my_array) == 1 ) return $my_array;
	$mid = count($my_array) / 2;
    $left = array_slice($my_array, 0, $mid);
    $right = array_slice($my_array, $mid);
	$left = merge_sort($left);
	$right = merge_sort($right);
	return merge($left, $right);
}

function merge($left, $right){
	$res = array();
	while (count($left) > 0 && count($right) > 0){
		if($left[0] > $right[0]){
			$res[] = $right[0];
			$right = array_slice($right , 1);
		}else{
			$res[] = $left[0];
			$left = array_slice($left, 1);
		}
	}
	while (count($left) > 0){
		$res[] = $left[0];
		$left = array_slice($left, 1);
	}
	while (count($right) > 0){
		$res[] = $right[0];
		$right = array_slice($right, 1);
	}
	return $res;
}

$a = explode(' ', $s);
$sorted = merge_sort($a);
if (array_sum($sorted)/$sorted[0] == 2 * $n) {
    echo '-1';
} else {
    echo implode(' ', $sorted);
}

<?php

$fp = fopen('php://stdin', 'r');
//$fp = fopen('input.txt', 'r');
$n = trim(fgets($fp)) + 0;
$numbers = explode(" ", trim(fgets($fp)));
$left = [
    "max" => 0,
    "sum" => 0,
    "numbers" => [],
    "count" => 0

];
$right = [
    "sum" => 0,
    "numbers" => [],
    "count" => 0
];
foreach ($numbers as $number) {
    $number += 0;
    if (!$left["sum"]) {
        $left["max"] = $number;
        $left["sum"] = $number;
        array_push($left["numbers"], $number);
        $left["count"]++;
        continue;
    }

    if (!$right["sum"]) {
        $right["sum"] = $number;
        array_push($right["numbers"], $number);
        $right["count"]++;
        continue;
    }

    if (($number >= $left["max"] || $right["count"] == $n ) && $left["count"] < $n) {
        $left["max"] = $number;
        $left["sum"] += $number;
        array_push($left["numbers"], $number);
        $left["count"]++;
    } else {
        $right["sum"] += $number;
        array_push($right["numbers"], $number);
        $right["count"]++;
    }

}

if ($left["sum"] == $right["sum"]) {
    echo "-1";
} else {
    foreach($left["numbers"] as $number) {
        echo "$number ";
    }
    foreach($right["numbers"] as $number) {
        echo "$number ";
    }
}