Given a sequence $$$a_1, a_2, \ldots, a_n$$$, find the minimum number of elements to remove from the sequence such that after the removal, the sum of every $$$2$$$ consecutive elements is even.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2,\dots,a_n$$$ ($$$1\leq a_i\leq10^9$$$) — elements of the sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print a single integer — the minimum number of elements to remove from the sequence such that the sum of every $$$2$$$ consecutive elements is even.

NoteIn the first test case, after removing $$$3$$$, the sequence becomes $$$[2,4,6,8]$$$. The pairs of consecutive elements are $$$\{[2, 4], [4, 6], [6, 8]\}$$$. Each consecutive pair has an even sum now. Hence, we only need to remove $$$1$$$ element to satisfy the condition asked.In the second test case, each consecutive pair already has an even sum so we need not remove any element.

<?php
$iter = InOutPut::get();

for($i=0; $i <$iter; $i++) {
       $ans = 12;
       $n = InOutPut::get();
       $a = InOutPut::getArr();

       $even = 0; $odd = 0;

       for($j=0; $j < $n; $j++){
           if($a[$j]%2==0){
             $even++;
           } else {
             $odd++;
           }
       }
       $ans = $even > $odd ? $odd : $even;
       InOutPut::print($ans);
}

class InOutPut {
      public static function get()
      {
          return trim(fgets(STDIN));
      }

     public static function getArr()
     {
         return explode(' ', trim(fgets(STDIN)));
     }
     public static function print($string)
     {
      echo $string . "\n";
     }
 }
 ?>

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

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

 function solve()
 {

     $n = IO::getInt();
     $a = IO::getArray();
     $ans = 0;
     $count= 0;
     for($i=0; $i<$n; $i++) {
        if($a[$i] % 2 == 1) {
             $count++;
        }  else {
            $ans++;
        }
     }
     //  var_dump($a);
       IO::pr(IO::getMinValue($count, $ans));
 }

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

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

 class Algor {
     public static function efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    public static function isPrime($n) {
         $d = 2;
         while ($n % $d != 0) {
         $d += 1;
         }

        return $d == $n;
    }

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

         return $a[$n];
     }

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

}

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

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

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

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

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

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

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

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d", $n);
    $odd = 0;
    foreach ($arr = fgetcsv(STDIN, 0, ' ') as $value) {
        $odd += $value & 1;
    }
    printf("%d\n", min($odd, $n-$odd));
}

<?php
$iter = InOutPut::get();

for($i=0; $i <$iter; $i++) {
       $ans = 12;
       $n = InOutPut::get();
       $a = InOutPut::getArr();

       $even = 0; $odd = 0;

       for($j=0; $j < $n; $j++){
	       	if($a[$j]%2==0){
	       		$even++;
	       	} else {
	       		$odd++;
	       	}
	       	if($even==$n || $odd==$n){
	       		$ans=0;
	       		break;
	       	} else if (abs($even-$odd) <= 1 ){
	       		$ans = abs($even-$odd);
	       	}

       }

       InOutPut::print($ans);
}

class InOutPut {
      public static function get()
      {
          return trim(fgets(STDIN));
      }

     public static function getArr()
     {
         return explode(' ', trim(fgets(STDIN)));
     }
     public static function print($string)
     {
      echo $string . "\n";
     }
 }
 ?>


Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$-th people in the line form a couple.

Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.

NoteIn the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps.The second sample case already satisfies the constraints; therefore we need $$$0$$$ swaps.


The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.

The first line contains integer n (2 ≤ n ≤ 300) — the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 300). It is guaranteed that at least one ai is positive.

Print the sequence that consists of k (1 ≤ k ≤ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.

<?php

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

$n = count($a);

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

while (true) {
  $done = true;
  for ($i = 0; $i+1 < $n; $i ++) {
    if ($a[$i] > 0) {
      $done = false;
      print 'P';
      $a[$i] --;
    }
    print 'R';
  }
  for ($i = $n-1; $i-1 >= 0; $i --) {
    if ($a[$i] > 0) {
      $done = false;
      print 'P';
      $a[$i] --;
    }
    print 'L';
  }
  if ($done) break;
}

<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;

$current= explode(' ', $arr[1]);

$count = $arr[0];
$pos_last = $arr[0] - 1;
$count_puts = 0;
for( $i = 0; $i < $count; $i++){
    $count_puts += $current[$i];
}
$pos = 0;
$puts = 0;
while( true ){
    if(++$count_steps > 1000000)
        exit;
    if($current[ $pos ] > 0){
        $current[ $pos ]--;
        $puts++;
        echo 'P';
    }
    if($puts == $count_puts){
        exit;
    }
    if($pos > 0){
        if($current[ $pos - 1 ]  > 0){
            $pos--;
            echo 'L';
            continue;
        }
    }
    if ($pos_last > $pos) {
        echo 'R';
        $pos++;
        continue;
    }
    if ($pos_last == $pos) {
        echo 'L';
        $pos--;
        continue;
    }
}


Along the railroad there are stations indexed from $$$1$$$ to $$$10^9$$$. An express train always travels along a route consisting of $$$n$$$ stations with indices $$$u_1, u_2, \dots, u_n$$$, where ($$$1 \le u_i \le 10^9$$$). The train travels along the route from left to right. It starts at station $$$u_1$$$, then stops at station $$$u_2$$$, then at $$$u_3$$$, and so on. Station $$$u_n$$$ — the terminus.It is possible that the train will visit the same station more than once. That is, there may be duplicates among the values $$$u_1, u_2, \dots, u_n$$$.You are given $$$k$$$ queries, each containing two different integers $$$a_j$$$ and $$$b_j$$$ ($$$1 \le a_j, b_j \le 10^9$$$). For each query, determine whether it is possible to travel by train from the station with index $$$a_j$$$ to the station with index $$$b_j$$$.For example, let the train route consist of $$$6$$$ of stations with indices [$$$3, 7, 1, 5, 1, 4$$$] and give $$$3$$$ of the following queries:   $$$a_1 = 3$$$, $$$b_1 = 5$$$It is possible to travel from station $$$3$$$ to station $$$5$$$ by taking a section of the route consisting of stations [$$$3, 7, 1, 5$$$]. Answer: YES.  $$$a_2 = 1$$$, $$$b_2 = 7$$$You cannot travel from station $$$1$$$ to station $$$7$$$ because the train cannot travel in the opposite direction. Answer: NO.  $$$a_3 = 3$$$, $$$b_3 = 10$$$It is not possible to travel from station $$$3$$$ to station $$$10$$$ because station $$$10$$$ is not part of the train's route. Answer: NO.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case is empty. The second line of each test case contains two integers: $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le k \le 2 \cdot 10^5$$$) —the number of stations the train route consists of and the number of queries. The third line of each test case contains exactly $$$n$$$ integers $$$u_1, u_2, \dots, u_n$$$ ($$$1 \le u_i \le 10^9$$$). The values $$$u_1, u_2, \dots, u_n$$$ are not necessarily different. The following $$$k$$$ lines contain two different integers $$$a_j$$$ and $$$b_j$$$ ($$$1 \le a_j, b_j \le 10^9$$$) describing the query with index $$$j$$$. It is guaranteed that the sum of $$$n$$$ values over all test cases in the test does not exceed $$$2 \cdot 10^5$$$. Similarly, it is guaranteed that the sum of $$$k$$$ values over all test cases in the test also does not exceed $$$2 \cdot 10^5$$$

For each test case, output on a separate line:   YES, if you can travel by train from the station with index $$$a_j$$$ to the station with index $$$b_j$$$ NO otherwise.  You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

NoteThe first test case is explained in the problem statement.

<?php

function solve($q,$st) {
    $ans = [] ;
    $n = (int) $q[0] ;
    $l = (int) $q[1] ;
    $posf = array() ;
    $posl = array() ;
    $arr = array_map('intval',explode(" ",$st));
    for($i=0; $i<$n; $i++) {
        if($posf[$arr[$i]] === null) {
            $posf[$arr[$i]] = $i ;
        }
    }
    for($j=$n-1; $j > -1; $j--) {
        if($posl[$arr[$j]] === null) {
            $posl[$arr[$j]] = $j ;
        }
    }
//    print_r($posf);
//    print_r($posl);
    while($l--) {
        [$lo,$up] = array_map('intval',explode(" ",trim(fgets(STDIN)))) ;
        if( ($posf[$lo] !== null & $posl[$up] !== null ) && ($posf[$lo] < $posl[$up])) {
            $ans[] = "YES" ;
        }
        else {
            $ans[] = "NO" ;
        }
    }

    print_r(implode("\n",$ans)) ;
}

$t = (int) fgets(STDIN);
$ans = [] ;
while($t--) {
    $emp = fgets(STDIN) ;
    $que = explode(" ",trim(fgets(STDIN)));
    $st = trim(fgets(STDIN)) ;
    solve($que,$st);
    print_r("\n");
}

<?php

$tc = (int)trim(fgets(STDIN));

while ($tc-- > 0) {
    fgets(STDIN); // discard one line

    $n = 0; $q = 0;

    fscanf(STDIN, "%d %d", $n, $q);

    $instr = trim(fgets(STDIN));
    $stations = array_map('intval', explode(' ', $instr));

    $l = array(); $r = array();
    foreach($stations as $id => $st) {
        if (!array_key_exists($st, $l)) {
            $l[$st] = $id;
        }
        $r[$st] = $id;
    }

    $s1; $s2;
    for ($i = 0; $i < $q; $i++) {
        fscanf(STDIN, "%d %d", $s1, $s2);
        $reachable = false;
        if (array_key_exists($s1, $r) && array_key_exists($s2, $r)) {
            if ($l[$s1] < $r[$s2]) $reachable = true;
        }
        if ($reachable) echo "YES\n";
        else echo "NO\n";
    }
}

<?php

function solve($q,$st) {
    $ans = [] ;
    $n = (int) $q[0] ;
    $l = (int) $q[1] ;
    $posf = array() ;
    $posl = array() ;
    $arr = array_map('intval',explode(" ",$st));
    for($i=0; $i<$n; $i++) {
        if($posf[$arr[$i]] === null) {
            $posf[$arr[$i]] = $i ;
        }
    }
    for($j=$n-1; $j > -1; $j--) {
        if($posl[$arr[$j]] === null) {
            $posl[$arr[$j]] = $j ;
        }
    }
//    print_r($posf);
//    print_r($posl);
    while($l--) {
        [$lo,$up] = array_map('intval',explode(" ",trim(fgets(STDIN)))) ;
        if($posf[$lo] < $posl[$up]) {
            $ans[] = "YES" ;
        }
        else {
            $ans[] = "NO" ;
        }
    }

    print_r(implode("\n",$ans)) ;
}

$t = (int) fgets(STDIN);
$ans = [] ;
while($t--) {
    $emp = fgets(STDIN) ;
    $que = explode(" ",trim(fgets(STDIN)));
    $st = trim(fgets(STDIN)) ;
    solve($que,$st);
    print_r("\n");
}

<?php

function brings($a,$b,$arr) {
    /*
    if($arr[$a] === 0) {
        return false ;
    }
    if($arr[$a] === $b) {
        return true ;
    }
    else {
        return brigns($arr[$a],$b,$arr) ;
    }
    */
    $cur = $a ;
    $mark = [];
    //print_r($a);
    //print_r($b);
    while(true) {
//        print_r($cur);
        if($arr[$cur] === null || $mark[$cur] === true) {
            return false ;
        }
        else if(in_array($b,$arr[$cur])) {
            return true ;
        }
        else {
            $mark[$cur] = true;
            $cur = $arr[$cur][0] ;
        }
    }

}
function solve($q,$st) {
    $ans = [] ;
    $n = (int) $q[0] ;
    $l = (int) $q[1] ;
    $lok = array();
    $arr = array_map('intval',explode(" ",$st));
//    var_dump($lok);
    for($i=1;$i<$n;$i++) {
        //print_r($i);
        if(!isset($lok[$arr[$i-1]])) {
            $lok[$arr[$i-1]] = array() ;
            if((!in_array($arr[$i],$lok[$arr[$i-1]])) && $arr[$i] !== $arr[$i-1]) {
                array_push($lok[$arr[$i-1]],$arr[$i]) ;
            }
//            print_r($lok[$arr[$i-1]]);
        }
        else {
            if((!in_array($arr[$i],$lok[$arr[$i-1]])) && $arr[$i] !== $arr[$i-1]) {
                array_push($lok[$arr[$i-1]],$arr[$i]) ;
            }
        }
        //print_r("okay");
//        print_r($lok[$arr[$i-1]]);
    }
//    print_r($lok);
    //print_r($arr) ;
    //print_r($n) ;
    //print_r($l) ;

    for($i=0;$i<$l;$i++) {
        $inp1 = array_map('intval',explode(" ",trim(fgets(STDIN)))) ;
        //print_r($inp1[0]);
        //print_r($inp1[1]);

        if(brings($inp1[0],$inp1[1],$lok)) {
            $ans[] = "YES" ;
        }
        else {
            $ans[] = "NO" ;
        }
    }
    print_r(implode("\n",$ans)) ;
}

$t = (int) fgets(STDIN);
$ans = [] ;
while($t--) {
    $emp = fgets(STDIN) ;
    $que = explode(" ",trim(fgets(STDIN)));
    $st = trim(fgets(STDIN)) ;
    solve($que,$st);
    print_r("\n");
}


Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:   Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).  For any two indices i and j (i < j), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.

The input contains a single integer: n (1 ≤ n ≤ 105).

Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    print $a + $x . " ";
}
print $a + $x;
?>

<?php
    fscanf(STDIN,"%d",$n);
    for($i=$n ; $i<$n*2 ; $i++)
        fprintf(STDOUT,"%d ",$i);
?>

<?

error_reporting(false);
//error_reporting(E_ALL);

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

if (file_exists("in.txt")) {
    $handle = fopen('in.txt', 'r');
    set_time_limit(0);
};

$map = array();

$n = 0;

$num = trim(fgets($handle));;
$i = $num;

while(1){

    $i++;
    $n++;

    echo $i." ";

    //$map[$i] = 1;
    //del($i);

    if ($n >= $num) break;
}


Chef Monocarp has just put $$$n$$$ dishes into an oven. He knows that the $$$i$$$-th dish has its optimal cooking time equal to $$$t_i$$$ minutes.At any positive integer minute $$$T$$$ Monocarp can put no more than one dish out of the oven. If the $$$i$$$-th dish is put out at some minute $$$T$$$, then its unpleasant value is $$$|T - t_i|$$$ — the absolute difference between $$$T$$$ and $$$t_i$$$. Once the dish is out of the oven, it can't go back in.Monocarp should put all the dishes out of the oven. What is the minimum total unpleasant value Monocarp can obtain?

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of testcases. Then $$$q$$$ testcases follow. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of dishes in the oven. The second line of the testcase contains $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$1 \le t_i \le n$$$) — the optimal cooking time for each dish. The sum of $$$n$$$ over all $$$q$$$ testcases doesn't exceed $$$200$$$.

Print a single integer for each testcase — the minimum total unpleasant value Monocarp can obtain when he puts out all the dishes out of the oven. Remember that Monocarp can only put the dishes out at positive integer minutes and no more than one dish at any minute.

NoteIn the first example Monocarp can put out the dishes at minutes $$$3, 1, 5, 4, 6, 2$$$. That way the total unpleasant value will be $$$|4 - 3| + |2 - 1| + |4 - 5| + |4 - 4| + |6 - 5| + |2 - 2| = 4$$$.In the second example Monocarp can put out the dishes at minutes $$$4, 5, 6, 7, 8, 9, 10$$$.In the third example Monocarp can put out the dish at minute $$$1$$$.In the fourth example Monocarp can put out the dishes at minutes $$$5, 1, 2, 4, 3$$$.In the fifth example Monocarp can put out the dishes at minutes $$$1, 3, 4, 5$$$.

<?php

ob_start(null, 65536);

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

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

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

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

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

$tc = asInt(nl());
for($cc=0; $cc<$tc; $cc++) {
    $n = asInt(nl());
    $buf = array_map(asInt::class, nla());
    sort($buf);
    $m = $n * 2;
    $a = new SplFixedArray($n+2);
    $dp = new SplFixedArray($n+2);
    $x = 1;
    foreach($buf as $v) {
        $dp[$x] = new SplFixedArray($m+2);
        $a[$x++] = $v;
    }
    $dp[0] = new SplFixedArray($m+2);
    $inf = 1000000007;
    for($i=0; $i<=$n; $i++) {
        $dp[$i][0] = $inf;
        $dp[0][$i] = 0;
    }
    for($i=1; $i<=$n; $i++) {
        for($j=1; $j<=$m; $j++) {
            $dp[$i][$j] = min($dp[$i-1][$j-1] + abs($a[$i]-$j), $dp[$i][$j-1]);
        }
    }
    echo $dp[$n][$m] . "\n";
}


Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.A substring of a string is a nonempty sequence of consecutive characters.For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9.

Print integer a — the number of substrings of the string s that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.


Ivan wants to play a game with you. He picked some string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from $$$1$$$ to $$$n-1$$$), but he didn't tell you which strings are prefixes and which are suffixes.Ivan wants you to guess which of the given $$$2n-2$$$ strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin!

The first line of the input contains one integer number $$$n$$$ ($$$2 \le n \le 100$$$) — the length of the guessed string $$$s$$$. The next $$$2n-2$$$ lines are contain prefixes and suffixes, one per line. Each of them is the string of length from $$$1$$$ to $$$n-1$$$ consisting only of lowercase Latin letters. They can be given in arbitrary order. It is guaranteed that there are exactly $$$2$$$ strings of each length from $$$1$$$ to $$$n-1$$$. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length $$$n$$$.

Print one string of length $$$2n-2$$$ — the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The $$$i$$$-th character of this string should be 'P' if the $$$i$$$-th of the input strings is the prefix and 'S' otherwise. If there are several possible answers, you can print any.

NoteThe only string which Ivan can guess in the first example is "ababa".The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable.In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.


Amugae has a hotel consisting of $$$10$$$ rooms. The rooms are numbered from $$$0$$$ to $$$9$$$ from left to right.The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance.One day, Amugae lost the room assignment list. Thankfully Amugae's memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae's memory.

The first line consists of an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of events in Amugae's memory. The second line consists of a string of length $$$n$$$ describing the events in chronological order. Each character represents:    'L': A customer arrives from the left entrance.  'R': A customer arrives from the right entrance.  '0', '1', ..., '9': The customer in room $$$x$$$ ($$$0$$$, $$$1$$$, ..., $$$9$$$ respectively) leaves.  It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room $$$x$$$ when $$$x$$$ ($$$0$$$, $$$1$$$, ..., $$$9$$$) is given. Also, all the rooms are initially empty.

In the only line, output the hotel room's assignment status, from room $$$0$$$ to room $$$9$$$. Represent an empty room as '0', and an occupied room as '1', without spaces.

NoteIn the first example, hotel room's assignment status after each action is as follows.   First of all, all rooms are empty. Assignment status is 0000000000.  L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.  L: one more customer from the left entrance. Assignment status is 1100000000.  R: one more customer from the right entrance. Assignment status is 1100000001.  L: one more customer from the left entrance. Assignment status is 1110000001.  1: the customer in room $$$1$$$ leaves. Assignment status is 1010000001.  R: one more customer from the right entrance. Assignment status is 1010000011.  L: one more customer from the left entrance. Assignment status is 1110000011.  1: the customer in room $$$1$$$ leaves. Assignment status is 1010000011. So after all, hotel room's final assignment status is 1010000011.In the second example, hotel room's assignment status after each action is as follows.   L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.  0: the customer in room $$$0$$$ leaves. Assignment status is 0000000000.  L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000 again.  0: the customer in room $$$0$$$ leaves. Assignment status is 0000000000.  L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.  L: one more customer from the left entrance. Assignment status is 1100000000.  R: one more customer from the right entrance. Assignment status is 1100000001.  R: one more customer from the right entrance. Assignment status is 1100000011.  9: the customer in room $$$9$$$ leaves. Assignment status is 1100000010. So after all, hotel room's final assignment status is 1100000010.

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$aArrays = trim(fgets(STDIN));
$aTest = [];
for ($i = 0; $i < 10; $i++){
    $aTest[$i] = 0;
}
for ($i = 0; $i < strlen($aArrays); $i++){
    if($aArrays[$i] == 'L') {
        $iKey = array_search(0,$aTest);
        $aTest[$iKey] = 1;
    } elseif($aArrays[$i] == 'R'){
        $aTest = array_reverse($aTest);
        $iKey = array_search(0,$aTest);
        $aTest[$iKey] = 1;
        $aTest = array_reverse($aTest);
    } else {
        $aTest[$aArrays[$i]] = 0;
    }
}

echo implode($aTest);
//1010000011
//1100000010

<?php

	$in = 'php://stdin';
//	$in = 'input.txt';

     $input = fopen($in,"r");
     list($i)=explode(" ",trim(fgets($input)));
     $c=str_split(trim(fgets($input)),1);
     $k=0;
     $str="0000000000";
     $count=0;
     foreach($c as $item)
     {
          if($item=='L'){
               while($count<10)
               {
                    if($str[$count] == 1)
                    {
                                             $count++;
                    }else
                    {
                        $str[$count] = 1;
                        break;
                    }

               }
          }
          if($item=='R'){
               $count = 9;
               while($count>=0)
               {
                    if($str[$count] == 1)
                    {
                         $count--;
                    }else
                    {
                        $str[$count] = 1;
                        break;
                    }

               }
          }
          if(($item<>'L')&&($item<>'R'))
          {
               $str[$item]= 0 ;
          }
          $count = 0;
     }
     echo $str;

     // // $output = explode(" ",trim(fgets($input)));
     // $output = str_split($input);
     // foreach ($output as $key){
     //      echo $key." ";
     // }
     ?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$aArrays = trim(fgets(STDIN));
$aTest = [];
for ($i = 0; $i < 10; $i++){
    $aTest[$i] = 0;
}
echo array_search(0,$aTest) . "\n";
for ($i = 0; $i < strlen($aArrays); $i++){
    if($aArrays[$i] == 'L') {
        $iKey = array_search(0,$aTest);
        $aTest[$iKey] = 1;
    } elseif($aArrays[$i] == 'R'){
        $aTest = array_reverse($aTest);
        $iKey = array_search(0,$aTest);
        $aTest[$iKey] = 1;
        $aTest = array_reverse($aTest);
    } else {
        $aTest[$aArrays[$i]] = 0;
    }
}

echo implode($aTest);
//1010000011
//1100000010

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$aArrays = trim(fgets(STDIN));
$aTest = [];
for ($i = 0; $i < $n; $i++){
    $aTest[$i] = 0;
}
echo array_search(0,$aTest) . "\n";
for ($i = 0; $i < strlen($aArrays); $i++){
    if($aArrays[$i] == 'L') {
        $iKey = array_search(0,$aTest);
        $aTest[$iKey] = 1;
    } elseif($aArrays[$i] == 'R'){
        $aTest = array_reverse($aTest);
        $iKey = array_search(0,$aTest);
        $aTest[$iKey] = 1;
        $aTest = array_reverse($aTest);
    } else {
        $aTest[$aArrays[$i]] = 0;
    }
}

echo implode($aTest);


At the school where Vasya is studying, preparations are underway for the graduation ceremony. One of the planned performances is a ball, which will be attended by pairs of boys and girls.Each class must present two couples to the ball. In Vasya's class, $$$a$$$ boys and $$$b$$$ girls wish to participate. But not all boys and not all girls are ready to dance in pairs.Formally, you know $$$k$$$ possible one-boy-one-girl pairs. You need to choose two of these pairs so that no person is in more than one pair.For example, if $$$a=3$$$, $$$b=4$$$, $$$k=4$$$ and the couples $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 2)$$$, $$$(3, 4)$$$ are ready to dance together (in each pair, the boy's number comes first, then the girl's number), then the following combinations of two pairs are possible (not all possible options are listed below):   $$$(1, 3)$$$ and $$$(2, 2)$$$;  $$$(3, 4)$$$ and $$$(1, 3)$$$; But the following combinations are not possible:   $$$(1, 3)$$$ and $$$(1, 2)$$$ — the first boy enters two pairs;  $$$(1, 2)$$$ and $$$(2, 2)$$$ — the second girl enters two pairs; Find the number of ways to select two pairs that match the condition above. Two ways are considered different if they consist of different pairs.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$k$$$ ($$$1 \le a, b, k \le 2 \cdot 10^5$$$) — the number of boys and girls in the class and the number of couples ready to dance together. The second line of each test case contains $$$k$$$ integers $$$a_1, a_2, \ldots a_k$$$. ($$$1 \le a_i \le a$$$), where $$$a_i$$$ is the number of the boy in the pair with the number $$$i$$$. The third line of each test case contains $$$k$$$ integers $$$b_1, b_2, \ldots b_k$$$. ($$$1 \le b_i \le b$$$), where $$$b_i$$$ is the number of the girl in the pair with the number $$$i$$$. It is guaranteed that the sums of $$$a$$$, $$$b$$$, and $$$k$$$ over all test cases do not exceed $$$2 \cdot 10^5$$$. It is guaranteed that each pair is specified at most once in one test case.

For each test case, on a separate line print one integer — the number of ways to choose two pairs that match the condition above.

NoteIn the first test case, the following combinations of pairs fit:   $$$(1, 2)$$$ and $$$(3, 4)$$$;  $$$(1, 3)$$$ and $$$(2, 2)$$$;  $$$(1, 3)$$$ and $$$(3, 4)$$$;  $$$(2, 2)$$$ and $$$(3, 4)$$$. There is only one pair in the second test case.In the third test case, the following combinations of pairs fit:   $$$(1, 1)$$$ and $$$(2, 2)$$$;  $$$(1, 2)$$$ and $$$(2, 1)$$$.

<?php

$times = (int)trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($ai[], $bi[], $ki[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $xi[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $yi[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $a = &$ai[$idx];
    $b = &$bi[$idx];
    $k = &$ki[$idx];
    $x = &$xi[$idx];
    $y = &$yi[$idx];

    $cntarrayx = array_count_values($x);
    $cntarrayy = array_count_values($y);
    $sm = $k * ($k + 1);
    for ($i = 0; $i < $k; ++$i) {
        $sm -= $cntarrayx[$x[$i]] + $cntarrayy[$y[$i]];
    }
    echo $sm / 2 , PHP_EOL;
}


Everyone knows that computers become faster and faster. Recently Berland scientists have built a machine that can move itself back in time!More specifically, it works as follows. It has an infinite grid and a robot which stands on one of the cells. Each cell of the grid can either be empty or contain 0 or 1. The machine also has a program which consists of instructions, which are being handled one by one. Each instruction is represented by exactly one symbol (letter or digit) and takes exactly one unit of time (say, second) to be performed, except the last type of operation (it's described below). Here they are:  0 or 1: the robot places this number into the cell he is currently at. If this cell wasn't empty before the operation, its previous number is replaced anyway.  e: the robot erases the number into the cell he is at.  l, r, u or d: the robot goes one cell to the left/right/up/down.  s: the robot stays where he is for a unit of time.  t: let $$$x$$$ be $$$0$$$, if the cell with the robot is empty, otherwise let $$$x$$$ be one more than the digit in this cell (that is, $$$x = 1$$$ if the digit in this cell is $$$0$$$, and $$$x = 2$$$ if the digit is $$$1$$$). Then the machine travels $$$x$$$ seconds back in time. Note that this doesn't change the instructions order, but it changes the position of the robot and the numbers in the grid as they were $$$x$$$ units of time ago. You can consider this instruction to be equivalent to a Ctrl-Z pressed $$$x$$$ times. For example, let the board be completely empty, and the program be sr1t0. Let the robot initially be at $$$(0, 0)$$$.  [now is the moment $$$0$$$, the command is s]: we do nothing.  [now is the moment $$$1$$$, the command is r]: we are now at $$$(1, 0)$$$.  [now is the moment $$$2$$$, the command is 1]: we are at $$$(1, 0)$$$, and this cell contains $$$1$$$.  [now is the moment $$$3$$$, the command is t]: we travel $$$1 + 1 = 2$$$ moments back, that is, to the moment $$$1$$$.  [now is the moment $$$1$$$, the command is 0]: we are again at $$$(0, 0)$$$, and the board is clear again, but after we follow this instruction, this cell has $$$0$$$ in it. We've just rewritten the history. The consequences of the third instruction have never happened. Now Berland scientists want to use their machine in practice. For example, they want to be able to add two integers.Assume that the initial state of the machine is as follows:  One positive integer is written in binary on the grid in such a way that its right bit is at the cell $$$(0, 1)$$$, from left to right from the highest bit to the lowest bit.  The other positive integer is written in binary on the grid in such a way that its right bit is at the cell $$$(0, 0)$$$, from left to right from the highest bit to the lowest bit.  All the other cells are empty.  The robot is at $$$(0, 0)$$$.  We consider this state to be always in the past; that is, if you manage to travel to any negative moment, the board was always as described above, and the robot was at $$$(0, 0)$$$ for eternity. You are asked to write a program after which  The robot stands on a non-empty cell,  If we read the number starting from the cell with the robot and moving to the right until the first empty cell, this will be $$$a + b$$$ in binary, from the highest bit to the lowest bit. Note that there are no restrictions on other cells. In particular, there may be a digit just to the left to the robot after all instructions.In each test you are given up to $$$1000$$$ pairs $$$(a, b)$$$, and your program must work for all these pairs. Also since the machine's memory is not very big, your program must consist of no more than $$$10^5$$$ instructions.

The first line contains the only integer $$$t$$$ ($$$1\le t\le 1000$$$) standing for the number of testcases. Each of the next $$$t$$$ lines consists of two positive integers $$$a$$$ and $$$b$$$ ($$$1\le a, b < 2^{30}$$$) in decimal.

Output the only line consisting of no more than $$$10^5$$$ symbols from 01eslrudt standing for your program. Note that formally you may output different programs for different tests.


Slavic has an array of length $$$n$$$ consisting only of zeroes and ones. In one operation, he removes either the first or the last element of the array. What is the minimum number of operations Slavic has to perform such that the total sum of the array is equal to $$$s$$$ after performing all the operations? In case the sum $$$s$$$ can't be obtained after any amount of operations, you should output -1.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$s$$$ ($$$1 \leq n, s \leq 2 \cdot 10^5$$$) — the length of the array and the needed sum of elements. The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$0 \leq a_i \leq 1$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the minimum amount of operations required to have the total sum of the array equal to $$$s$$$, or -1 if obtaining an array with sum $$$s$$$ isn't possible.

NoteIn the first test case, the sum of the whole array is $$$1$$$ from the beginning, so we don't have to make any operations.In the second test case, the sum of the array is $$$2$$$ and we want it to be equal to $$$1$$$, so we should remove the first element. The array turns into $$$[1, 0]$$$, which has a sum equal to $$$1$$$.In the third test case, the sum of the array is $$$5$$$ and we need it to be $$$3$$$. We can obtain such a sum by removing the first two elements and the last element, doing a total of three operations. The array turns into $$$[0, 1, 1, 1, 0, 0]$$$, which has a sum equal to $$$3$$$.

<?php

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

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

    $ar = fscanf(STDIN, str_repeat('%u ', $n));

//    $en = [$ar[0]];
//    $enC = array_fill(0, $n, 1); // every element is at least once
//    $enL = 0;
//
//    for ($i = 1; $i < $n; ++$i) {
//        if ($ar[$i] === $en[$enL]) {
//            ++$enC[$enL];
//        } else {
//            $en[++$enL] = $ar[$i];
//        }
//    }

    $s = 0;
    for ($j = 0; $j < $n; ++$j) {
        $newS = $s + $ar[$j];

        if ($newS > $sum) {
            break;
        }

        $s = $newS;
    }

    if ($s !== $sum) {
        echo -1 .PHP_EOL;
        continue;
    }

    $l = 0;
    $r = $j - 1;
    $maxLen = $r - $l + 1;

    while (true) {
        $s -= $ar[$l++];

        for ($j = $r + 1; $j < $n; ++$j) {
            $newS = $s + $ar[$j];

            if ($newS > $sum) {
                break;
            }

            $s = $newS;
        }

        $r = $j - 1;

        if ($s !== $sum) {
            break;
        }

        $maxLen = max($maxLen, $r - $l + 1);
    }

    echo ($n - $maxLen).PHP_EOL;
}
/*

Find the longest possible subarray which makes up desired sum.
1. Initialize sum from array prefix. The subarray is [0, K];
2. Shift Left pointer by one and Right pointer by necessary amount;
3. Check if current length greater than calculated up to moment.

1
5 1
1 0 1 0 0
1

1
14 2
1 1 1 1 1 0 0 0 1 1 0 0 0 1
6

1
3 1
1 0 0

 */


Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.

The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.

Print the sought minimum number of people

<?php
$a = trim(fgets(STDIN));
$b = str_split($a);
$c = 1;
$d = array();
for($x = 0; $x < count($b); $x++)
{
    if($b[$x] == $b[$x + 1])
    {
        $c++;
        array_push($d, $c);
    }
    else
    {
        $c = 1;
        array_push($d, $c);
    }
}
rsort($d);
print $d[0];
?>


There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns.   You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster.  Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally.

The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) — the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster.

Print one integer — the maximum number of points you can gain if you use the secret technique optimally.

<?
$consoleInput = fopen('php://stdin','r');
$variables = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));
$monsters = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));

//$variables = array(7,4,2,1);
//$monsters = array(1,3,5,4,2,7,6);

$n = $variables[0];
$a = $variables[1];
$b = $variables[2];
$k = $variables[3];
$killCount = 0;
$m = array();

foreach ($monsters as $monster){
  $m[ceil((($monster % ($a+$b)))/$a)-1] ++;
}
if (array_key_exists(-1,$m)){
    //print "hello";
    $m[ceil($b/$a)] += $m[-1];
    unset($m[-1]);
}
ksort($m);

foreach ($m as $keyPerMonster => $numberOfMonsters){
    //print $keyPerMonster . "   " . $numberOfMonsters . "\n";
    if($k<$keyPerMonster*$numberOfMonsters){
        $killCount += floor($k/$keyPerMonster);
        break;
    }
    $k -= $keyPerMonster*$numberOfMonsters;
    $killCount += $numberOfMonsters;
    //print "k count is: " . $k . "\n";
    //print "kill count is: " . $killCount . "\n";
}
print $killCount;
?>

<?php

namespace io {
	$input_file_content = file_get_contents("php://stdin");
	$input_buf = explode("\r\n", $input_file_content);
	unset($input_file_content);
}

namespace main {
	error_reporting(E_ALL);
	ini_set('display_errors', true);
	ini_set('html_errors', false);

	use function io\next_line as next_line;
	use function io\next_ as next;
	use function io\next_int as next_int;
	use function io\next_double as next_double;

	$n = next_int();
	$a = next_int();
	$b = next_int();
	$k = next_int();

	$hh = [];
	$z = $a + $b;
	for($i=0; $i<$n; $i++) {
		$h = next_int();
		$t = (($h - 1) % $z) + 1;
		$hh[] = intdiv($t-1, $a);
	}

	sort($hh);

	$c = 0; $ans = 0;
	for($i=0; $i<$n; $i++) {
		if($c + $hh[$i] <= $k) {
			$c += $hh[$i];
			$ans++;
		}
		else break;
	}

	printf("%d\n", $ans);
}

namespace io {
	function next_line() {
		static $cnt = 0;
		global $input_buf;
		// while($input_buf[$cnt] == "") $cnt++;
		return $input_buf[$cnt++];
		// return trim($input_buf[$cnt++]);
	}
	function next_() {
		static $tk = [];
		static $tk_cnt = 0;
		if($tk_cnt == count($tk)) {
			$tk = explode(" ", next_line());
			$tk_cnt = 0;
		}
		return $tk[$tk_cnt++];
	}
	function next_int() {
		return (int)next_();
	}
	function next_double() {
		return (double)next_();
	}
}

?>

<?
$consoleInput = fopen('php://stdin','r');
$variables = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));
$monsters = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));

//$variables = array(7,4,2,1);
//$monsters = array(1,3,5,4,2,7,6);

$n = $variables[0];
$a = $variables[1];
$b = $variables[2];
$k = $variables[3];
$killCount = 0;
$m = array();

foreach ($monsters as $monster){
  $m[ceil((($monster % ($a+$b)))/$a)-1] ++;
}
if (array_key_exists(-1,$m)){
    //print "hello";
    $m[ceil($b/$a)] += $m[-1];
    unset($m[-1]);
}
ksort($m);

foreach ($m as $keyPerMonster => $numberOfMonsters){
    //print $keyPerMonster . "   " . $numberOfMonsters . "\n";
    if($k<$keyPerMonster*$numberOfMonsters){
        $killCount += floor($k/$keyPerMonster);
        break;
    }
    $k -= $keyPerMonster*$numberOfMonster;
    $killCount += $numberOfMonsters;
}
print $killCount;
?>

<?
$consoleInput = fopen('php://stdin','r');
$variables = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));
$monsters = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));

//$variables = array(7,4,2,1);
//$monsters = array(1,3,5,4,2,7,6);

$n = $variables[0];
$a = $variables[1];
$b = $variables[2];
$k = $variables[3];
$killCount = 0;
$m = array();

foreach ($monsters as $monster){
  $m[ceil((($monster % ($a+$b)))/$a)-1] ++;
}

$m[ceil($b/$a)] += $m[-1];
unset($m[-1]);
ksort($m);

foreach ($m as $keyPerMonster => $numberOfMonsters){
    if($k<$keyPerMonster*$numberOfMonsters){
        $killCount += floor($k/$keyPerMonster);
        break;
    }
    $k -= $keyPerMonster*$numberOfMonster;
    $killCount += $numberOfMonsters;
}

print $killCount;
?>

<?
$consoleInput = fopen('php://stdin','r');
$variables = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));
$monsters = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));

//$variables = array(7,4,2,1);
//$monsters = array(1,3,5,4,2,7,6);

$n = $variables[0];
$a = $variables[1];
$b = $variables[2];
$k = $variables[3];
$killCount = 0;
$m = array();

foreach ($monsters as $monster){
  $m[ceil((($monster % ($a+$b)))/$a)-1] ++;
}
if (array_key_exists(-1,$m)){
    $m[ceil($b/$a)] += $m[-1];
    unset($m[-1]);
}
ksort($m);

foreach ($m as $keyPerMonster => $numberOfMonsters){
    if($k<$keyPerMonster*$numberOfMonsters){
        $killCount += floor($k/$keyPerMonster);
        break;
    }
    $k -= $keyPerMonster*$numberOfMonster;
    $killCount += $numberOfMonsters;
}
print $killCount;
?>

<?
$consoleInput = fopen('php://stdin','r');
$variables = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));
$monsters = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));

//$variables = array(7,4,2,1);
//$monsters = array(1,3,5,4,2,7,6);

$n = $variables[0];
$a = $variables[1];
$b = $variables[2];
$k = $variables[3];
$killCount = 0;
$m = array();

foreach ($monsters as $monster){
    //print "attacks are " . ($a+$b) . "\n";
    //print "Mod is " . ($monster % ($a+$b)) . "\n";
    //print "Ceil is: " . ceil((($monster % ($a+$b)))/$a) . "\n";
  $kNeeded = ceil((($monster % ($a+$b)))/$a)-1;
  //print $kNeeded;
  if ($kNeeded == -1){
      $kNeeded = ceil($b/$a);
  }
  $m[$kNeeded] ++;
  print $kNeeded . "  " . $m[$kNeeded] . "\n";
}

for ($i=0;$k>$i*$m[$i];$i++){
    $k -= $m[$i]*$i;
    $killCount += $m[$i];
    if ($killCount == $n){
        $k = 0;
        break;
    }
}
$killCount += floor($k/$i);
print $killCount;
?>

<?
$consoleInput = fopen('php://stdin','r');
$variables = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));
$monsters = explode(" ",rtrim(fgets($consoleInput)," \t\n\r\0\x0B"));

//$variables = array(7,4,2,1);
//$monsters = array(1,3,5,4,2,7,6);

$n = $variables[0];
$a = $variables[1];
$b = $variables[2];
$k = $variables[3];
$killCount = 0;
$m = array();

foreach ($monsters as $monster){
  $m[ceil((($monster % ($a+$b)))/$a)-1] ++;
}
if (array_key_exists($m[-1])){
    $m[ceil($b/$a)] += $m[-1];
    unset($m[-1]);
}
ksort($m);

foreach ($m as $keyPerMonster => $numberOfMonsters){
    print $keyPerMonster . "  " . $numberOfMonsters . "\n";
    if($k<$keyPerMonster*$numberOfMonsters){
        $killCount += floor($k/$keyPerMonster);
        break;
    }
    $k -= $keyPerMonster*$numberOfMonster;
    $killCount += $numberOfMonsters;
}

print $killCount;
?>


Ehab loves number theory, but for some reason he hates the number $$$x$$$. Given an array $$$a$$$, find the length of its longest subarray such that the sum of its elements isn't divisible by $$$x$$$, or determine that such subarray doesn't exist.An array $$$a$$$ is a subarray of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

The first line contains an integer $$$t$$$ $$$(1 \le t \le 5)$$$ — the number of test cases you need to solve. The description of the test cases follows. The first line of each test case contains 2 integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le x \le 10^4$$$) — the number of elements in the array $$$a$$$ and the number that Ehab hates. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$0 \le a_i \le 10^4$$$) — the elements of the array $$$a$$$.

For each testcase, print the length of the longest subarray whose sum isn't divisible by $$$x$$$. If there's no such subarray, print $$$-1$$$.

NoteIn the first test case, the subarray $$$[2,3]$$$ has sum of elements $$$5$$$, which isn't divisible by $$$3$$$.In the second test case, the sum of elements of the whole array is $$$6$$$, which isn't divisible by $$$4$$$.In the third test case, all subarrays have an even sum, so the answer is $$$-1$$$.

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

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

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $in_str = explode(" ", trim(fgets(STDIN))) ;

        $n = intval($in_str[0]) ;
        $x = intval($in_str[1]) ;

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

        $sum = array_fill(0, $n, 0) ;
        $sum[0] = intval($in_str[0]) ;
        $f = false ;
        $ans = 0 ;

        if($sum[0]%$x)
        {
            $f = true ;
            $ans = 1 ;
        }

        for($i = 1; $i < $n; $i ++)
        {
            $in_str[$i] = intval($in_str[$i]) ;

            $sum[$i] = $sum[$i - 1] + $in_str[$i] ;
            if($sum[$i]%$x)
            {
                $f = true ;
                $ans = $i + 1 ;
            }
        }

        if(!$f) echo "-1\n" ;
        else
        {
            for($i = $n - 1; $i > 0; $i --)
            {
                if(($sum[$n - 1] - $sum[$i - 1])%$x)
                {
                    $ans = max($ans, $n - $i) ;
                }
            }

            echo $ans . "\n" ;
        }
    }
?>


Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive.Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages.You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct.

The first line contains two integers n, m (1 ≤ n, m ≤ 105) — the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 106) — the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≤ yi ≤ 106) — the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≤ 106.

Print the maximum number of files the intercepted array could consist of.

NoteIn the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8.In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100.In the third example the only possibility is that the archive contains a single file of size 4.


The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.

Print a single number — the required maximum possible number of pairs.

<?php
$n = trim(fgets(STDIN));
$ar = explode(" ", trim(fgets(STDIN)));
$m = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));

sort($ar);
sort($b);

function isPair($ar,$b){
if (($ar+1==$b)||($ar==$b+1)||($ar==$b))
return true;
return false;
}

$pairs = 0;
$used = -1;
for($i=0;$i<$n;$i++){
for($j=$used+1;$j<$m;$j++)
if ( isPair($ar[$i],$b[$j]) ){
$pairs++;
$used = $j;
break;
}
}
echo $pairs;
?>

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

sort($a);
sort($b);

function is_pair($a, $b){
    if (($a+1 == $b) or ($a == $b+1) or ($a == $b)) {
        return true;
    }
    return false;
}

$count = 0;
$used = -1;
for ($i = 0; $i < $n; $i++) {
    for ($j = $used+1; $j < $m; $j++) {
        if (is_pair($a[$i], $b[$j])) {
            $count++;
            $used = $j;
            break;
        }
    }
}
echo $count;
?>

 <?php

$n = intval(trim(fgets(STDIN)));
$boySkills = strval(trim(fgets(STDIN)));
$boySkills = explode(" ",$boySkills);
$m = intval(trim(fgets(STDIN)));
$girlSkills = strval(trim(fgets(STDIN)));
$girlSkills = explode(" ",$girlSkills);

sort($boySkills);
sort($girlSkills);

$bannedCols=[];
$pairCnt = 0;

for ($i=0; $i < $n; $i++) {
	for ($j=0; $j < $m; $j++) {
		if(abs($boySkills[$i]-$girlSkills[$j])<=1&&!in_array($j, $bannedCols)){
			$pairCnt++;
			$bannedCols[]=$j;
			break;
		}
	}
}

echo $pairCnt;

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

sort($a);
sort($b);

function isPair($a,$b){
	if (($a+1==$b)||($a==$b+1)||($a==$b))
		return true;
	return false;
}

$pairs = 0;
$used = -1;
for($i=0;$i<$n;$i++){
	for($j=$used+1;$j<$m;$j++)
		if ( isPair($a[$i],$b[$j]) ){
			$pairs++;
			$used = $j;
			break;
		}
}
echo $pairs;
?>

<?php

$n = (int) trim(fgets(STDIN));
$boys = array_map('intval', explode(' ', trim(fgets(STDIN))));
$m = (int) trim(fgets(STDIN));
$girls = array_map('intval', explode(' ', trim(fgets(STDIN))));

sort($boys);
sort($girls);

$gi = 0;
$bi =0;
$matches =0;
while($gi < $m && $bi < $n){
    if($boys[$bi] < $girls[$gi] - 1){
        $bi++;
    }elseif($boys[$bi] -1 > $girls[$gi]){
        $gi++;
    }else{
        $matches++;
        $bi++;
        $gi++;
    }

}
echo $matches;

 <?php

$n = intval(trim(fgets(STDIN)));
$boySkills = strval(trim(fgets(STDIN)));
$boySkills = explode(" ",$boySkills);
$m = intval(trim(fgets(STDIN)));
$girlSkills = strval(trim(fgets(STDIN)));
$girlSkills = explode(" ",$girlSkills);

$bannedCols=[];
$pairCnt = 0;

for ($i=0; $i < $n; $i++) {
	for ($j=0; $j < $m; $j++) {
		if(abs($boySkills[$i]-$girlSkills[$j])<=1&&!in_array($j, $bannedCols)){
			$pairCnt++;
			$bannedCols[]=$j;
			break;
		}
	}
}

echo $pairCnt;

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

sort($a);
sort($b);

function isPair($a,$b){
	if (($a+1==$b)||($a==$b+1)||($a==$b))
		return true;
	return false;
}

$pairs = 0;

for($i=0;$i<$n;$i++){
	for($j=0;$j<$m;$j++)
		if ( isPair($a[$i],$b[$j]) ){
			$pairs++;
			$b[$j] = null;
			break;
		}
}
echo $pairs;
/*
1 2 4 6
1 5 5 7 9

*/
?>

<?php

$n = (int) trim(fgets(STDIN));
$boys = array_map('intval', explode(' ', trim(fgets(STDIN))));
$m = (int) trim(fgets(STDIN));
$girls = array_map('intval', explode(' ', trim(fgets(STDIN))));

sort($boys);
sort($girls);

$gi = 0;
$matches =0;

foreach($boys as $boy){
    if(abs($boy - $girls[$gi]) <= 1){
        $matches++;
    }
    $gi ++;
    if($gi >= $m){
        break;
    }
}

echo $matches;


There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $$$n$$$ packets with inflatable balloons, where $$$i$$$-th of them has exactly $$$a_i$$$ balloons inside.They want to divide the balloons among themselves. In addition, there are several conditions to hold:  Do not rip the packets (both Grigory and Andrew should get unbroken packets);  Distribute all packets (every packet should be given to someone);  Give both Grigory and Andrew at least one packet;  To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions.

The first line of input contains a single integer $$$n$$$ ($$$1 \le n \le 10$$$) — the number of packets with balloons. The second line contains $$$n$$$ integers: $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \le a_i \le 1000$$$) — the number of balloons inside the corresponding packet.

If it's impossible to divide the balloons satisfying the conditions above, print $$$-1$$$. Otherwise, print an integer $$$k$$$ — the number of packets to give to Grigory followed by $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$ — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them.

NoteIn the first test Grigory gets $$$3$$$ balloons in total while Andrey gets $$$1$$$.In the second test there's only one way to divide the packets which leads to equal numbers of balloons.In the third test one of the boys won't get a packet at all.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
if($a == 1)
{
     print "-1";
}
elseif(($a == 2) && ($b[0] == $b[1]))
{
     print "-1";
}
else
{
     asort($b);
     $c = array_keys($b);
     print "1\n";
     print $c[0] + 1;
}
?>

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

asort($a);
list($k, $v) = each($a);

if ($n == 1) {
    echo "-1";
} else if ($n == 2 && $a[0] == $a[1]) {
    echo "-1";
} else {
    echo 1 . "\n";
    echo $k + 1;
}

<?php
	$dir                    = fopen("php://stdin", 'r');
	$contents               = stream_get_contents($dir);
	$inputs                 = explode("\n",$contents);
	$packetsCount           = explode(' ', $inputs[0])[0];
	$ballonsForEachPacket   = array_map('intval', explode(' ', $inputs[1]));
	getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket);

	function getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket)
	{
	    if($packetsCount == 2 && $ballonsForEachPacket[0] == $ballonsForEachPacket[1]) {
		echo -1;
	    }elseif($packetsCount <= 1) {
		echo -1;
	    } else {
		$minimumNumber  = min($ballonsForEachPacket);
		$numbersSum     = array_sum($ballonsForEachPacket);
		if($minimumNumber != $numbersSum - $minimumNumber)
		{
		     echo 1;
		     echo PHP_EOL;
		     echo array_keys($ballonsForEachPacket, $minimumNumber)[0] + 1;
		}
	    }
	}
?>

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

rsort($a);
if ($n == 1) {
    echo "-1";
} else if ($n == 2 && $a[0] == $a[1]) {
    echo "-1";
} else {
    echo 1 . "\n";
    echo $a[0];
}

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

rsort($a);
if ($n == 1) {
    echo "-1";
} else if ($n == 2 && $a[0] == $a[1]) {
    echo "-1";
} else {
    echo $n - 1 . "\n";
    array_pop($a);
    echo implode(" ", $a);
}

<?php
$dir                    = fopen("php://stdin", 'r');
$contents               = stream_get_contents($dir);
$inputs                 = explode("\n",$contents);
$packetsCount           = explode(' ', $inputs[0])[0];
$ballonsForEachPacket   = array_map('intval', explode(' ', $inputs[1]));
getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket);

function getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket)
{
    $firstPlayerPackets['count'] = 0;
    $firstPlayerPackets['ballonsConut'] = 0;
    $firstPlayerPackets['ballons'] = [];
    $secondPlayerPackets['count'] = 0;
    $secondPlayerPackets['ballonsConut'] = 0;
    $secondPlayerPackets['ballons'] = [];
    if($packetsCount <= 1)
    {
        echo -1;
    } else {
        for($i=0; $i < $packetsCount; $i++)
        {
            if($i+1 == 1 || ($packetsCount!=2 && $firstPlayerPackets['ballonsConut'] + $ballonsForEachPacket[$i] == $secondPlayerPackets['ballonsConut'])){
                $secondPlayerPackets['count']++;
                $secondPlayerPackets['ballonsConut'] += $ballonsForEachPacket[$i] ;
                $secondPlayerPackets['ballons'] = [$i => $ballonsForEachPacket[$i]];
            } else {
                //echo $i;
                $firstPlayerPackets['count']++;
                $firstPlayerPackets['ballonsConut'] += $ballonsForEachPacket[$i] ;
                $firstPlayerPackets['ballons'][$i] = $ballonsForEachPacket[$i];

            }
        }

        if($secondPlayerPackets['count'] == $firstPlayerPackets['count'])
        {
            echo -1;
        } else{
            echo $firstPlayerPackets['count'].PHP_EOL;
            foreach($firstPlayerPackets['ballons'] as  $key=>$ballons)
            {
                echo ($key+1).' ';
            }
        }
    }
}
?>

<?php
$dir                    = fopen("php://stdin", 'r');
$contents               = stream_get_contents($dir);
$inputs                 = explode("\n",$contents);
$packetsCount           = explode(' ', $inputs[0])[0];
$ballonsForEachPacket   = array_map('intval', explode(' ', $inputs[1]));
getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket);

function getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket)
{
    $firstPlayerPackets['count'] = 0;
    $firstPlayerPackets['ballonsConut'] = 0;
    $firstPlayerPackets['ballons'] = [];
    $secondPlayerPackets['count'] = 0;
    $secondPlayerPackets['ballonsConut'] = 0;
    $secondPlayerPackets['ballons'] = [];
    if($packetsCount <= 1)
    {
        echo -1;
    } else {
        for($i=0; $i < $packetsCount; $i++)
        {
            if($i+1 == 1 || ($packetsCount!=2 && $firstPlayerPackets['ballonsConut'] + $ballonsForEachPacket[$i] == $secondPlayerPackets['ballonsConut'])){
                $secondPlayerPackets['count']++;
                $secondPlayerPackets['ballonsConut'] += $ballonsForEachPacket[$i] ;
                $secondPlayerPackets['ballons'] = [$i => $ballonsForEachPacket[$i]];
            } else {
                //echo $i;
                $firstPlayerPackets['count']++;
                $firstPlayerPackets['ballonsConut'] += $ballonsForEachPacket[$i] ;
                $firstPlayerPackets['ballons'][$i] = $ballonsForEachPacket[$i];

            }
        }

        if($secondPlayerPackets['ballonsConut']  === $firstPlayerPackets['ballonsConut'])
        {
            echo -1;
        } else{
            echo $firstPlayerPackets['count'].PHP_EOL;
            foreach($firstPlayerPackets['ballons'] as  $key=>$ballons)
            {
                echo ($key+1).' ';
            }
        }
    }
}
?>

<?php
	$dir                    = fopen("php://stdin", 'r');
	$contents               = stream_get_contents($dir);
	$inputs                 = explode("\n",$contents);
	$packetsCount           = explode(' ', $inputs[0])[0];
	$ballonsForEachPacket   = array_map('intval', explode(' ', $inputs[1]));
	getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket);

	function getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket)
	{
	    if($packetsCount == 2 && $ballonsForEachPacket[0] == $ballonsForEachPacket[1]) {
		echo -1;
	    }elseif($packetsCount <= 1) {
		echo -1;
	    } else {
		$minimumNumber  = min($ballonsForEachPacket);
		$numbersSum     = array_sum($ballonsForEachPacket);
		if($minimumNumber != $numbersSum - $minimumNumber)
		{
		     echo $minimumNumber;
		     echo PHP_EOL;
		     echo array_keys($ballonsForEachPacket, $minimumNumber)[0] + 1;
		}
	    }
	}
?>

<?php
$dir                    = fopen("php://stdin", 'r');
$contents               = stream_get_contents($dir);
$inputs                 = explode("\n",$contents);
$packetsCount           = explode(' ', $inputs[0])[0];
$ballonsForEachPacket   = array_map('intval', explode(' ', $inputs[1]));
getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket);

function getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket)
{
    $firstPlayerPackets['count'] = 0;
    $firstPlayerPackets['ballons'] = [];
    $secondPlayerPackets['count'] = 0;
    $secondPlayerPackets['ballons'] = [];
    if($packetsCount <= 1)
    {
        echo -1;
    } else {
        for($i=0; $i < $packetsCount; $i++)
        {
            if($i+1 == 1){
                $secondPlayerPackets['count']++;
                $secondPlayerPackets['ballons'] = [$i => $ballonsForEachPacket[$i]];
            } else {
                //echo $i;
                $firstPlayerPackets['count']++;
                $firstPlayerPackets['ballons'][] = $ballonsForEachPacket[$i];

            }
        }

        if($secondPlayerPackets['count'] == $firstPlayerPackets['count'])
        {
            echo -1;
        } else{
            echo $firstPlayerPackets['count'].PHP_EOL;
            for($i = 0; $i < count($firstPlayerPackets['ballons']); $i++)
            {
                echo $firstPlayerPackets['ballons'][$i].' ';
            }
        }
    }
}
?>

<?php
$dir                    = fopen("php://stdin", 'r');
$contents               = stream_get_contents($dir);
$inputs                 = explode("\n",$contents);
$packetsCount           = explode(' ', $inputs[0])[0];
$ballonsForEachPacket   = array_map('intval', explode(' ', $inputs[1]));
getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket);

function getPacketsNumberForFirstPlayer($packetsCount, $ballonsForEachPacket)
{
    $firstPlayerPackets['count'] = 0;
    $firstPlayerPackets['ballonsConut'] = 0;
    $firstPlayerPackets['ballons'] = [];
    $secondPlayerPackets['count'] = 0;
    $secondPlayerPackets['ballonsConut'] = 0;
    $secondPlayerPackets['ballons'] = [];
    if($packetsCount <= 1)
    {
        echo -1;
    } else {
        for($i=0; $i < $packetsCount; $i++)
        {
            if($i+1 == 1 || ($packetsCount!=2 && $firstPlayerPackets['ballonsConut'] + $ballonsForEachPacket[$i] == $secondPlayerPackets['ballonsConut'])){
                $secondPlayerPackets['count']++;
                $secondPlayerPackets['ballonsConut'] += $ballonsForEachPacket[$i] ;
                $secondPlayerPackets['ballons'] = [$i => $ballonsForEachPacket[$i]];
            } else {
                //echo $i;
                $firstPlayerPackets['count']++;
                $firstPlayerPackets['ballonsConut'] += $ballonsForEachPacket[$i] ;
                $firstPlayerPackets['ballons'][] = $ballonsForEachPacket[$i];

            }
        }

        if($secondPlayerPackets['count'] == $firstPlayerPackets['count'])
        {
            echo -1;
        } else{
            echo $firstPlayerPackets['count'].PHP_EOL;
            for($i = 0; $i < count($firstPlayerPackets['ballons']); $i++)
            {
                echo $firstPlayerPackets['ballons'][$i].' ';
            }
        }
    }
}
?>


Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?Note: uppercase and lowercase letters are considered different.

Input contains a single line containing a string s (1  ≤  |s|  ≤  105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s. The string s contains lowercase and uppercase English letters, i.e. .

Output a single integer, the answer to the problem.

NoteIn the first case, you could pick: Bulbbasaur.In the second case, there is no way to pick even a single Bulbasaur.In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".

<?php
    fscanf(STDIN, "%s", $s);

    $arr = str_split($s);
    $len = count($arr);

    $w = "Bulbasaur";
    $arrW = str_split($w);
    $sample = array();
    // var_dump($arrW);

    for ($i = 0; $i < count($arrW); $i++) {
        $sample[$arrW[$i]]++;
    }
    // var_dump($sample);

    $sum = array();
    $curr = $arrW;

    $ans = PHP_INT_MAX;

    for ($i = 0; $i < $len; $i++) {
        $sum[$arr[$i]]++;
    }
    // var_dump($sum);

    foreach ($sample as $key => $val) {
        // echo "key:{$key} val:{$val}\n";
        $tmp = floor($sum[$key] / $sample[$key]);
        $ans = min($tmp, $ans);
    }

    echo $ans;


You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which:  Any number in this field is in range $$$[1; 9]$$$;  each row contains at least two equal elements;  each column contains at least two equal elements;  each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle.

For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.