Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with $$$n$$$ elements. The $$$i$$$-th element is $$$a_i$$$ ($$$i$$$ = $$$1, 2, \ldots, n$$$). He gradually takes the first two leftmost elements from the deque (let's call them $$$A$$$ and $$$B$$$, respectively), and then does the following: if $$$A > B$$$, he writes $$$A$$$ to the beginning and writes $$$B$$$ to the end of the deque, otherwise, he writes to the beginning $$$B$$$, and $$$A$$$ writes to the end of the deque. We call this sequence of actions an operation.For example, if deque was $$$[2, 3, 4, 5, 1]$$$, on the operation he will write $$$B=3$$$ to the beginning and $$$A=2$$$ to the end, so he will get $$$[3, 4, 5, 1, 2]$$$.The teacher of the course, seeing Valeriy, who was passionate about his work, approached him and gave him $$$q$$$ queries. Each query consists of the singular number $$$m_j$$$ $$$(j = 1, 2, \ldots, q)$$$. It is required for each query to answer which two elements he will pull out on the $$$m_j$$$-th operation.Note that the queries are independent and for each query the numbers $$$A$$$ and $$$B$$$ should be printed in the order in which they will be pulled out of the deque.Deque is a data structure representing a list of elements where insertion of new elements or deletion of existing elements can be made from both sides.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \leq n \leq 10^5$$$, $$$0 \leq q \leq 3 \cdot 10^5$$$) — the number of elements in the deque and the number of queries. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$, where $$$a_i$$$ $$$(0 \leq a_i \leq 10^9)$$$ — the deque element in $$$i$$$-th position. The next $$$q$$$ lines contain one number each, meaning $$$m_j$$$ ($$$1 \leq m_j \leq 10^{18}$$$).

For each teacher's query, output two numbers $$$A$$$ and $$$B$$$ — the numbers that Valeriy pulls out of the deque for the $$$m_j$$$-th operation.

<?php
#1179A
[$n, $qn] = explode(' ', trim(fgets(STDIN)));
$arr = explode(' ', trim(fgets(STDIN)));
$max = max($arr);
$ops = $arr_ = [];
$first = $arr[0];
/*
for ($cachedCount = 1; $arr[0] !== $max; $cachedCount++) {
    $ops[$cachedCount] = [$arr[0], $arr[1]];
    if ($arr[0] < $arr[1]) {
        $a = array_shift($arr);
        $arr[] = $a;
    } else {
        $a = array_shift($arr);
        $b = array_shift($arr);
        array_unshift($arr, $a);
        $arr[] = $b;
    }
}
*/
for ($cachedCount = 1; $first !== $max; $cachedCount++) {
    $ops[$cachedCount] = [$first, $arr[$cachedCount]];
    if ($first < $arr[$cachedCount]) {
        $arr_[] = $first;
        $first = $arr[$cachedCount];
    } else {
        $arr_[] = $arr[$cachedCount];
    }
}
$arr = array_merge([$first], array_slice($arr, $cachedCount), $arr_);
unset($arr_, $first, $max);
$n--;
for ($i = 0; $i < $qn; $i++) {
    $q = trim(fgets(STDIN));
    if ($q < $cachedCount) {
        echo $ops[$q][0] . ' ' . $ops[$q][1] . PHP_EOL;
    } else {
        $j = bcadd(bcmod(bcadd($q, bcmul($cachedCount, '-1')), $n), '1');
        echo $arr[0] . ' ' . $arr[$j] . PHP_EOL;
    }
}

<?php
#1179A
[$n, $qn] = explode(' ', trim(fgets(STDIN)));
$arr = explode(' ', trim(fgets(STDIN)));
$max = max($arr);
$ops = [];
for ($cachedCount = 1; $arr[0] !== $max; $cachedCount++) {
    $ops[$cachedCount] = [$arr[0], $arr[1]];
    if ($arr[0] < $arr[1]) {
        $a = array_shift($arr);
        $arr[] = $a;
    } else {
        $a = array_shift($arr);
        $b = array_shift($arr);
        array_unshift($arr, $b);
        $arr[] = $a;
    }
}
$n--;
for ($i = 0; $i < $qn; $i++) {
    $q = trim(fgets(STDIN));
    if ($q < $cachedCount) {
        echo $ops[$q][0] . ' ' . $ops[$q][1] . PHP_EOL;
    } else {
        $j = bcadd(bcmod(bcadd($q, bcmul($cachedCount, '-1')), $n), '1');
        echo $arr[0] . ' ' . $arr[$j] . PHP_EOL;
    }
}

<?php
#1179A
[$n, $qn] = explode(' ', trim(fgets(STDIN)));
$arr = explode(' ', trim(fgets(STDIN)));
$max = max($arr);
$ops = [];
for ($cachedCount = 1; $arr[0] !== $max; $cachedCount++) {
    $ops[$cachedCount] = [$arr[0], $arr[1]];
    if ($arr[0] < $arr[1]) {
        $a = array_shift($arr);
        $arr[] = $a;
    } else {
        $a = array_shift($arr);
        $b = array_shift($arr);
        array_unshift($arr, $b);
        $arr[] = $a;
    }
}
for ($i = 0; $i < $qn; $i++) {
    $q = trim(fgets(STDIN));
    if ($q < $cachedCount) {
        echo $ops[$q][0] . ' ' . $ops[$q][1] . PHP_EOL;
    } else {
        $j = ($q - $cachedCount) % ($n - 1) + 1;
        echo $arr[0] . ' ' . $arr[$j] . PHP_EOL;
    }
}


You are given array $$$a_1, a_2, \dots, a_n$$$. Find the subsegment $$$a_l, a_{l+1}, \dots, a_r$$$ ($$$1 \le l \le r \le n$$$) with maximum arithmetic mean $$$\frac{1}{r - l + 1}\sum\limits_{i=l}^{r}{a_i}$$$ (in floating-point numbers, i.e. without any rounding).If there are many such subsegments find the longest one.

The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the array $$$a$$$.

Print the single integer — the length of the longest subsegment with maximum possible arithmetic mean.

NoteThe subsegment $$$[3, 4]$$$ is the longest among all subsegments with maximum arithmetic mean.

<?php

list($n) = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$iMax = max($a);
$iMaxCounter = 1;
$aCounter = [];
for($i = 0; $i < $n - 1; $i++){
    if($a[$i] == $iMax && $a[$i+1] == $iMax){
        $iMaxCounter++;
        $aCounter[] = $iMaxCounter;
    } else {
        $iMaxCounter = 1;
    }
}
if(empty($aCounter)){
    echo 1;
} else {
    echo max($aCounter);
}

<?php
$n = trim(fgets(STDIN));
$arr = explode(" ", trim(fgets(STDIN)));
$max = max($arr);
$a = 0;
$b = 0;
for($i = 0; $i < $n; $i++)
{
     if($arr[$i] == $max)
     {
          $b++;
     }
     else
     {
          $a = max($a, $b);
          $b = 0;
     }
}
$a = max($a, $b);
print $a;
?>

<?php
    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $m = max($a);
    $i = 0;
    $iMax = 0;
    foreach ($a AS $v) {
        if ($m == $v) {
            $i++;
        } else {
            $i = 0;
        }
        if ($iMax < $i) {
            $iMax = $i;
        }
    }
    echo $iMax;
?>

<?php

list($n) = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$iMax = max($a);
$iMaxCounter = 1;
for($i = 0; $i < $n -1; $i++){
    if($a[$i] == $iMax && $a[$i+1] == $iMax){
        $iMaxCounter++;
    }
}

echo $iMaxCounter;

<?php

list($n) = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$iMax = max($a);
$iMaxCounter = 1;
for($i = 0; $i < $n - 1; $i++){
    if($a[$i] == $iMax && $a[$i+1] == $iMax){
        $iMaxCounter++;
        $aCounter[] = $iMaxCounter;
    } else {
        $aCounter[] = $iMaxCounter;
        $iMaxCounter = 1;

    }
}
echo max($aCounter);

<?php

list($n) = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$iMax = max($a);
$iMaxCounter = 1;
for($i = 0; $i < $n - 1; $i++){
    if($a[$i] == $iMax && $a[$i+1] == $iMax){
        $iMaxCounter++;
        $aCounter[] = $iMaxCounter;
    } else {
        $iMaxCounter = 1;
    }
}
echo max($aCounter);

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

$arr = explode(' ', $str);

$max = max($b);
$a = 0;
$b = 0;
for($i = 0; $i < $n; $i++)
{
     if($arr[$i] == $max)
     {
          $b++;
     }
     else
     {
          $a = max($a, $b);
          $a = 0;
     }
}
$a = max($a, $b);
print $a;
?>

<?php

    function minF($n, $m, $s) {
        if ($n < 10) {
            return $n;
        }
        $r = floor($n/2);
        preg_match("/".$m."{".$r."}/", $s, $d);
        if (count($d)) {
            return $n;
        } else {
            return minF($r, $m, $s);
        }
    }

    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $s = implode("", $a);
    $m = max($a);
    preg_match_all("/".$m."/", $s, $f);
    $c = count($f[0]);
    $h = minF($c, $m, $s);
    for ($i = $h; $i > 0; $i--) {
        preg_match_all("/(".$m."){".$i."}/", $s, $d);
        if (count($d[0])) {
            echo $i;
            break;
        }
    }

?>

<?php
    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $m = max($a);
    $i = 0;
    $iMax = 0;
    foreach ($a AS $v) {
        if ($m == $v) {
            $i++;
        } else {
            if ($iMax < $i) {
                $iMax = $i;
            }
            $i = 0;
        }

    }
    echo $iMax;
?>

<?php

    function minF($n, $m, $s) {
        $r = ceil($n/2);
        preg_match("/".$m."{".$r."}/", $s, $d);
        if (count($d)) {
            return $n;
        } else {
            return minF($r, $m, $s);
        }
    }

    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $s = implode("", $a);
    $m = max($a);
    preg_match_all("/".$m."/", $s, $f);
    $c = count($f[0]);
    $h = minF($c, $m, $s);
    for ($i = $h; $i > 0; $i--) {
        preg_match("/".$m."{".$i."}/", $s, $d);
        if (count($d)) {
            echo $i;
            break;
        }
    }

?>

<?php

    function minF($n, $m, $s) {
        if ($n < 10) {
            return $n;
        }
        $r = floor($n/2);
        preg_match("/".$m."{".$r."}/", $s, $d);
        if (count($d)) {
            return $n;
        } else {
            return minF($r, $m, $s);
        }
    }

    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $s = implode("", $a);
    $m = max($a);
    preg_match_all("/".$m."/", $s, $f);
    $c = count($f[0]);
    $h = minF($c, $m, $s);
    for ($i = $h; $i > 0; $i--) {
        preg_match("/".$m."{".$i."}/", $s, $d);
        if (count($d)) {
            echo $i;
            break;
        }
    }

?>

<?php

    function minF($n, $m, $s) {
        if ($n < 10) {
            return $n;
        }
        $r = floor($n/2);
        preg_match("/(".$m."){".$r."}/", $s, $d);
        if (count($d)) {
            return $n;
        } else {
            return minF($r, $m, $s);
        }
    }

    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $s = implode("", $a);
    $m = max($a);
    preg_match_all("/".$m."/", $s, $f);
    $c = count($f[0]);
    $h = minF($c, $m, $s);
    for ($i = $h; $i > 0; $i--) {
        preg_match_all("/(".$m."){".$i."}/", $s, $d);
        if (count($d[0])) {
            echo $i;
            break;
        }
    }

?>


Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$).   If $$$a_i = a_j$$$, change one of them to $$$0$$$.  Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.

The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.

For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.

NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 < a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 < a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 < a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.

<?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;
      $n = getT();
      $a = getA();
    $b = [];
    $zero = 0;
    for($i=0; $i<$n; $i++) {
        if($a[$i] != 0) {
          if(!isset($b[$a[$i]])) {
                $b[$a[$i]] = $i;
            } else {
                $tt = $b[$a[$i]];
                $a[$i] = 0;
                $b[$a[$i]] = $i;
                $ans++;
                $zero++;
            }
        } else {
            $zero++;
        }
    }
     if($zero == 0) {
         $ans = $n+1;
     } else {
         $ans += $n-$zero;
     }
    pr($ans);

  }
// 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 getDar($n) {
    $dar = [2];
    for($i=0; $i<$n; $i++) {
        $dar[] = $dar[$i] * 2;
    }
    return $dar;
}
function getDar2($n, $k) {
    if($k == 0) {
        return 1;
    }
    return bcmul($n, getDar2($n, $k-1));
}
  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 pr($s) {
        if(is_array($s)) {
            echo implode( ' ', $s), PHP_EOL;
        } else {
            echo $s, PHP_EOL;
        }
    }
    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];
    }


You are given $$$k$$$ sequences of integers. The length of the $$$i$$$-th sequence equals to $$$n_i$$$.You have to choose exactly two sequences $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $$$i$$$ (its length will be equal to $$$n_i - 1$$$) equals to the sum of the changed sequence $$$j$$$ (its length will be equal to $$$n_j - 1$$$).Note that it's required to remove exactly one element in each of the two chosen sequences.Assume that the sum of the empty (of the length equals $$$0$$$) sequence is $$$0$$$.

The first line contains an integer $$$k$$$ ($$$2 \le k \le 2 \cdot 10^5$$$) — the number of sequences. Then $$$k$$$ pairs of lines follow, each pair containing a sequence. The first line in the $$$i$$$-th pair contains one integer $$$n_i$$$ ($$$1 \le n_i < 2 \cdot 10^5$$$) — the length of the $$$i$$$-th sequence. The second line of the $$$i$$$-th pair contains a sequence of $$$n_i$$$ integers $$$a_{i, 1}, a_{i, 2}, \dots, a_{i, n_i}$$$. The elements of sequences are integer numbers from $$$-10^4$$$ to $$$10^4$$$. The sum of lengths of all given sequences don't exceed $$$2 \cdot 10^5$$$, i.e. $$$n_1 + n_2 + \dots + n_k \le 2 \cdot 10^5$$$.

If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $$$i$$$, $$$x$$$ ($$$1 \le i \le k, 1 \le x \le n_i$$$), in the third line — two integers $$$j$$$, $$$y$$$ ($$$1 \le j \le k, 1 \le y \le n_j$$$). It means that the sum of the elements of the $$$i$$$-th sequence without the element with index $$$x$$$ equals to the sum of the elements of the $$$j$$$-th sequence without the element with index $$$y$$$. Two chosen sequences must be distinct, i.e. $$$i \ne j$$$. You can print them in any order. If there are multiple possible answers, print any of them.

NoteIn the first example there are two sequences $$$[2, 3, 1, 3, 2]$$$ and $$$[1, 1, 2, 2, 2, 1]$$$. You can remove the second element from the first sequence to get $$$[2, 1, 3, 2]$$$ and you can remove the sixth element from the second sequence to get $$$[1, 1, 2, 2, 2]$$$. The sums of the both resulting sequences equal to $$$8$$$, i.e. the sums are equal.


Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the x-th row and the y-th column as a pair of numbers (x, y). The table corners are cells: (1, 1), (n, 1), (1, m), (n, m).Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table. Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (x1, y1), an arbitrary corner of the table (x2, y2) and color all cells of the table (p, q), which meet both inequations: min(x1, x2) ≤ p ≤ max(x1, x2), min(y1, y2) ≤ q ≤ max(y1, y2).Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times.

The first line contains exactly two integers n, m (3 ≤ n, m ≤ 50). Next n lines contain the description of the table cells. Specifically, the i-th line contains m space-separated integers ai1, ai2, ..., aim. If aij equals zero, then cell (i, j) isn't good. Otherwise aij equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.

Print a single number — the minimum number of operations Simon needs to carry out his idea.

NoteIn the first sample, the sequence of operations can be like this:    For the first time you need to choose cell (2, 2) and corner (1, 1).  For the second time you need to choose cell (2, 2) and corner (3, 3).  For the third time you need to choose cell (2, 2) and corner (3, 1).  For the fourth time you need to choose cell (2, 2) and corner (1, 3). In the second sample the sequence of operations can be like this:    For the first time you need to choose cell (3, 1) and corner (4, 3).  For the second time you need to choose cell (2, 3) and corner (1, 1).

<?php
$f=fopen("php://stdin","r");
$s=fscanf($f, "%u %u");
list ($m,$n)=$s;

$i=1;
$l="%u";
while($i++<$n){
 $l.=" %u";}

$i=0;
$left=$right=0;
$border=false;
while($i++<$m){
 $s=fscanf($f, $l);
 $left+=$s[0];
 $right+=$s[$n-1];
 if ((($i==1) or ($i==$m)) and (array_sum($s)>0)) $border=true;}

if (($left>0) or ($right>0)) $border=true;

if ($border) echo("2");
 else echo("4");

?>

<?php
$f=fopen("input.txt","r");
$s=fscanf($f, "%u %u");
list ($n,$m)=$s;

$i=1;
$l="%u";
while($i++<$n){
 $l.=" %u";}

$i=0;
$left=$right=0;
$border=false;
while($i++<$m){
 $s=fscanf($f, $l);
 $left+=$s[0];
 $right+=$s[$n-1];
 if ((($i==1) or ($i==$m)) and (array_sum($s)>0)) $border=true;}
if (($left>0) or ($right>0)) $border=true;
fclose($f);
if ($border) echo("2");
 else echo("4");

?>

<?php
$f=fopen("input.txt","r");
$s=fscanf($f, "%u %u");
list ($n,$m)=$s;

$i=1;
$l="%u";
while($i++<$n){
 $l.=" %u";}

$i=0;
$left=$right=0;
$border=false;
while($i++<$m){
 $s=fscanf($f, $l);
 $left+=$s[0];
 $right+=$s[$n-1];
 if ((($i==1) or ($i==$m)) and (array_sum($s)>0)) $border=true;}
if (($left>0) or ($right>0)) $border=true;
fclose($f);
$f=fopen("output.txt","w");
if ($border) fwrite($f,"2");
 else fwrite($f,"4");
fclose($f);

?>

<?php
$f=fopen("input.txt","r");
$s=fscanf($f, "%u %u");
list ($m,$n)=$s;

$i=1;
$l="%u";
while($i++<$n){
 $l.=" %u";}

$i=0;
$left=$right=0;
$border=false;
while($i++<$m){
 $s=fscanf($f, $l);
 $left+=$s[0];
 $right+=$s[$n-1];
 if ((($i==1) or ($i==$m)) and (array_sum($s)>0)) $border=true;}
if (($left>0) or ($right>0)) $border=true;
if ($border) echo("2");
 else echo("4");
fclose($f);
?>

<?php
$f=fopen("input.txt","r");
$s=fscanf($f, "%u %u");
list ($m,$n)=$s;

$i=1;
$l="%u";
while($i++<$n){
 $l.=" %u";}

$i=0;
$left=$right=0;
$border=false;
while($i++<$m){
 $s=fscanf($f, $l);
 $left+=$s[0];
 $right+=$s[$n-1];
 if ((($i==1) or ($i==$m)) and (array_sum($s)>0)) $border=true;}
if (($left>0) or ($right>0)) $border=true;
fclose($f);
if ($border) echo("2");
 else echo("4");

?>


Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 ≤ xi ≤ yi ≤ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.

The first line contains integers n, m, k (1 ≤ n, m, k ≤ 105). The second line contains n integers: a1, a2, ..., an (0 ≤ ai ≤ 105) — the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 ≤ li ≤ ri ≤ n), (0 ≤ di ≤ 105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 ≤ xi ≤ yi ≤ m). The numbers in the lines are separated by single spaces.

On a single line print n integers a1, a2, ..., an — the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.


In the Bus of Characters there are $$$n$$$ rows of seat, each having $$$2$$$ seats. The width of both seats in the $$$i$$$-th row is $$$w_i$$$ centimeters. All integers $$$w_i$$$ are distinct.Initially the bus is empty. On each of $$$2n$$$ stops one passenger enters the bus. There are two types of passengers:   an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it;  an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it. You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of rows in the bus. The second line contains the sequence of integers $$$w_1, w_2, \dots, w_n$$$ ($$$1 \le w_i \le 10^{9}$$$), where $$$w_i$$$ is the width of each of the seats in the $$$i$$$-th row. It is guaranteed that all $$$w_i$$$ are distinct. The third line contains a string of length $$$2n$$$, consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the $$$j$$$-th character is '0', then the passenger that enters the bus on the $$$j$$$-th stop is an introvert. If the $$$j$$$-th character is '1', the the passenger that enters the bus on the $$$j$$$-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal $$$n$$$), and for each extrovert there always is a suitable row.

Print $$$2n$$$ integers — the rows the passengers will take. The order of passengers should be the same as in input.

NoteIn the first example the first passenger (introvert) chooses the row $$$2$$$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $$$1$$$, because it is the only empty row now. The third passenger (extrovert) chooses the row $$$1$$$, because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row $$$2$$$, because it is the only row with an empty place.


Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.Vova knows that there are n characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; i-th character wants ci gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.The quest is finished when all n characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?Take a look at the notes if you think you haven't understood the problem completely.

The first line contains two integer numbers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of characters in Overcity and the number of pairs of friends. The second line contains n integer numbers ci (0 ≤ ci ≤ 109) — the amount of gold i-th character asks to start spreading the rumor. Then m lines follow, each containing a pair of numbers (xi, yi) which represent that characters xi and yi are friends (1 ≤ xi, yi ≤ n, xi ≠ yi). It is guaranteed that each pair is listed at most once.

Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.

NoteIn the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.In the second example Vova has to bribe everyone.In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters.


You have an axis-aligned rectangle room with width $$$W$$$ and height $$$H$$$, so the lower left corner is in point $$$(0, 0)$$$ and the upper right corner is in $$$(W, H)$$$.There is a rectangular table standing in this room. The sides of the table are parallel to the walls, the lower left corner is in $$$(x_1, y_1)$$$, and the upper right corner in $$$(x_2, y_2)$$$.You want to place another rectangular table in this room with width $$$w$$$ and height $$$h$$$ with the width of the table parallel to the width of the room.The problem is that sometimes there is not enough space to place the second table without intersecting with the first one (there are no problems with tables touching, though).You can't rotate any of the tables, but you can move the first table inside the room.   Example of how you may move the first table. What is the minimum distance you should move the first table to free enough space for the second one?

The first line contains the single integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of the test cases. The first line of each test case contains two integers $$$W$$$ and $$$H$$$ ($$$1 \le W, H \le 10^8$$$) — the width and the height of the room. The second line contains four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$ and $$$y_2$$$ ($$$0 \le x_1 < x_2 \le W$$$; $$$0 \le y_1 < y_2 \le H$$$) — the coordinates of the corners of the first table. The third line contains two integers $$$w$$$ and $$$h$$$ ($$$1 \le w \le W$$$; $$$1 \le h \le H$$$) — the width and the height of the second table.

For each test case, print the minimum distance you should move the first table, or $$$-1$$$ if there is no way to free enough space for the second table. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.

NoteThe configuration of the first test case is shown in the picture. But the movement of the first table is not optimal. One of the optimal movement, for example, is to move the table by $$$(0, -1)$$$, so the lower left corner will move from $$$(2, 1)$$$ to $$$(2, 0)$$$. Then you can place the second table at $$$(0, 3)-(4, 5)$$$.In the second test case, there is no way to fit both tables in the room without intersecting.In the third test case, you can move the first table by $$$(0, 2)$$$, so the lower left corner will move from $$$(0, 3)$$$ to $$$(0, 5)$$$.

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($ww, $hh) = IO::arr();
    list($x1, $y1, $x2, $y2) = IO::arr();
    list($w, $h) = IO::arr();
    $mw = $ww - ($x2 - $x1);
    $mh = $hh - ($y2 - $y1);
    if ($mw < $w && $mh < $h) {
        $res = -1;
    } else {
        $wg = max([$ww - $x2, $x1]);
        $hg = max([$hh - $y2, $y1]);
        $nx = $wg - $w;
        if ($nx < 0) {
            $nx = abs($nx);
        } else {
            $nx = 0;
        }
        $ny = $hg - $h;
        if ($ny < 0) {
            $ny = abs($ny);
        } else {
            $ny = 0;
        }

        if($mw < $w) {
            $nx = 999999999999999999999;
        }
        if ($mh < $h) {
            $ny = 999999999999999999999;
        }
        $res = min([$nx, $ny]);
    }

    IO::line($res);

}

?>


Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than $$$k$$$ other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.Now each knight ponders: how many coins he can have if only he kills other knights?You should answer this question for each knight.

The first line contains two integers $$$n$$$ and $$$k$$$ $$$(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$$$ — the number of knights and the number $$$k$$$ from the statement. The second line contains $$$n$$$ integers $$$p_1, p_2 ,\ldots,p_n$$$ $$$(1 \le p_i \le 10^9)$$$ — powers of the knights. All $$$p_i$$$ are distinct. The third line contains $$$n$$$ integers $$$c_1, c_2 ,\ldots,c_n$$$ $$$(0 \le c_i \le 10^9)$$$ — the number of coins each knight has.

Print $$$n$$$ integers — the maximum number of coins each knight can have it only he kills other knights.

NoteConsider the first example.   The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has.  The second knight can kill the first knight and add his coin to his own two.  The third knight is the strongest, but he can't kill more than $$$k = 2$$$ other knights. It is optimal to kill the second and the fourth knights: $$$2+11+33 = 46$$$.  The fourth knight should kill the first and the second knights: $$$33+1+2 = 36$$$. In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.In the third example there is only one knight, so he can't kill anyone.


In this problem, a $$$n \times m$$$ rectangular matrix $$$a$$$ is called increasing if, for each row of $$$i$$$, when go from left to right, the values strictly increase (that is, $$$a_{i,1}<a_{i,2}<\dots<a_{i,m}$$$) and for each column $$$j$$$, when go from top to bottom, the values strictly increase (that is, $$$a_{1,j}<a_{2,j}<\dots<a_{n,j}$$$).In a given matrix of non-negative integers, it is necessary to replace each value of $$$0$$$ with some positive integer so that the resulting matrix is increasing and the sum of its elements is maximum, or find that it is impossible.It is guaranteed that in a given value matrix all values of $$$0$$$ are contained only in internal cells (that is, not in the first or last row and not in the first or last column).

The first line contains integers $$$n$$$ and $$$m$$$ ($$$3 \le n, m \le 500$$$) — the number of rows and columns in the given matrix $$$a$$$. The following lines contain $$$m$$$ each of non-negative integers — the values in the corresponding row of the given matrix: $$$a_{i,1}, a_{i,2}, \dots, a_{i,m}$$$ ($$$0 \le a_{i,j} \le 8000$$$). It is guaranteed that for all $$$a_{i,j}=0$$$, $$$1 < i < n$$$ and $$$1 < j < m$$$ are true.

If it is possible to replace all zeros with positive numbers so that the matrix is increasing, print the maximum possible sum of matrix elements. Otherwise, print -1.

NoteIn the first example, the resulting matrix is as follows: 1 3 5 6 73 6 7 8 95 7 8 9 108 9 10 11 12In the second example, the value $$$3$$$ must be put in the middle cell.In the third example, the desired resultant matrix does not exist.


Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given in two lines. The first line contains two integers $$$a_1$$$ and $$$b_1$$$ ($$$1 \le a_1, b_1 \le 100$$$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers $$$a_2$$$ and $$$b_2$$$ ($$$1 \le a_2, b_2 \le 100$$$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).

Print $$$t$$$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     list($d, $e) = explode(" ", trim(fgets(STDIN)));
     if(($b == $d) && ($c + $e == $b))
     {
          print "Yes\n";
     }
     elseif(($b == $e) && ($c + $d == $b))
     {
          print "Yes\n";
     }
     elseif(($c == $d) && ($b + $e == $c))
     {
          print "Yes\n";
     }
     elseif(($c == $e) && ($b + $d == $c))
     {
          print "Yes\n";
     }
     else
     {
          print "No\n";
     }
}
?>


You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries.  Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.

Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.

NoteIn the first example here are how teams are formed:  the only team of 1 coder, 1 mathematician and 1 without specialization;  all three teams consist of 1 coder and 2 mathematicians;  no teams can be formed;  no teams can be formed;  one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team;  one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.


Recall that a permutation of length $$$n$$$ is an array where each element from $$$1$$$ to $$$n$$$ occurs exactly once.For a fixed positive integer $$$d$$$, let's define the cost of the permutation $$$p$$$ of length $$$n$$$ as the number of indices $$$i$$$ $$$(1 \le i < n)$$$ such that $$$p_i \cdot d = p_{i + 1}$$$.For example, if $$$d = 3$$$ and $$$p = [5, 2, 6, 7, 1, 3, 4]$$$, then the cost of such a permutation is $$$2$$$, because $$$p_2 \cdot 3 = p_3$$$ and $$$p_5 \cdot 3 = p_6$$$.Your task is the following one: for a given value $$$n$$$, find the permutation of length $$$n$$$ and the value $$$d$$$ with maximum possible cost (over all ways to choose the permutation and $$$d$$$). If there are multiple answers, then print any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$). The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print the value $$$d$$$ in the first line, and $$$n$$$ integers in the second line — the permutation itself. If there are multiple answers, then print any of them.

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d", $n);
    $b = [];
    for ($i = 1; $i <= $n; $i++) {
        if (isset($b[$i])) continue;
        $value = $i;
        while ($value <= $n) {
            $b[$value] = $value;
            $value *= 2;
        }
    }
    printf("2\n%s\n", implode(' ', $b));
}

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

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

function solve()
{
     $n = IO::get();

              $a = [];
               $tt = [];
               $d = 2;
               $count = 0;
               for($i=1; $i<=$n/2; $i++) {
               if(!isset($tt[$i])) {
                    $temp = $i * $d;
                     $a[] = $i;
                    $tt[$i] = $i;
                         while($temp <= $n) {
                            if(!isset($tt[$temp]) && $temp <= $n) {
                                 $tt[$temp] = $temp;
                                  $a[] = $temp;
                                  $count++;
                            }
                            $temp = $temp * $d;
                         }

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

          // IO::pr($count);
          IO::pr($d);
          IO::prArray($a);

}

class IO {
    public static function get()
    {
        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;
    }
}

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

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

function solve()
{
     $n = IO::get();
     if($n == 1) {
       IO::pr($n);
       IO::prArray([$n]);
     } else {
          $dur = 0;
         $max = 0;
          $ans = [];
         for($j=2; $j < 5; $j++ ) {
              $a = [];
               $tt = [];
               $d = $j;
               $count = 0;
               for($i=1; $i<=$n/2; $i++) {
               if(!isset($tt[$i])) {
                    $temp = $i * $d;
                       $a[] = $i;
                       $tt[$i] = $i;
                       if($temp <= $n) {
                            $tt[$temp] = $temp;
                             $a[] = $temp;
                             $count ++;
                       }
                    }
               }
               for($i=1; $i<=$n; $i++) {
                    if(!isset($tt[$i])) {
                       $a[] = $i;
                       $tt[$i] = $i;
                    }
               }
               if($count > $max) {
                    $ans = $a;
                    $max = $count;
                    $dur = $d;
               }
               $count = 0;
         }

          IO::pr($dur);
          IO::prArray($ans);
     }

}

class IO {
    public static function get()
    {
        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;
    }
}

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

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

function solve()
{
     $n = IO::get();

          $a = [];
          $tt = [];
          $d = 2;
          $count = 0;
          for($i=1; $i<=$n/2; $i++) {
          if(!isset($tt[$i])) {
               $temp = $i * $d;
                  $a[] = $i;
                  $tt[$i] = $i;
                  if($temp <= $n) {
                       $tt[$temp] = $temp;
                        $a[] = $temp;

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

     IO::pr($d);
     IO::prArray($a);

}

class IO {
    public static function get()
    {
        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;
    }
}

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

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

function solve()
{
     $n = IO::get();
     $a = [];
     $tt = [];
     $d = 2;
     for($i=1; $i<$n/2; $i++) {
          if(!isset($tt[$i])) {
               $temp = $i * $d;
             $a[] = $i;
             $tt[$i] = $i;
             if($temp <= $n) {
                  $tt[$temp] = $temp;
                   $a[] = $temp;
             }
          }
     }
     for($i=1; $i<=$n; $i++) {
          if(!isset($tt[$i])) {
             $a[] = $i;
             $tt[$i] = $i;
          }
     }

     IO::pr($d);
     IO::prArray($a);

}

class IO {
    public static function get()
    {
        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;
    }
}


Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Makes has chosen n problems to solve on Decoforces with difficulties a1, a2, ..., an. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty ai only if he had already solved some problem with difficulty  (no matter on what online judge was it).Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty k.With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list. For every positive integer y there exist some problem with difficulty y on at least one judge besides Decoforces.Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another.Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.

The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).

Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.

NoteIn the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.In the second example he can solve every problem right from the start.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
sort($c);
$d = 0;
for($x = 0; $x < $a; $x++)
{
     if(bcmul($b, 2) < $c[$x])
     {
          while(TRUE)
          {
               $b = bcmul($b, 2);
               $d++;
               if(bcmul($b, 2) >= $c[$x])
               {
                    $b = $c[$x];
                    break;
               }
          }
     }
     elseif(bcmul($b, 2) == $c[$x])
     {
          $b = bcmul($b, 2);
     }
     elseif(bcmul($b, 2) > $c[$x])
     {
          $b = max($b, $c[$x]);
     }

}
print $d;
?>

<?php
define("_DEBUG", 0);

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

if (!_DEBUG) $str = trim(fgets($fp));
else
	$str = '3 3';

$s = explode(' ', $str);
$n = (int)$s[0];
$k = (int)$s[1];

if (!_DEBUG)
{
	$str = trim(fgets($fp));
}
else
{
	$str = '2 1 9';
}

$a = explode(' ', $str);
for ($i = 0; $i < sizeof($a); $i++)
{
	$a[$i] = (int)$a[$i];
}
sort($a);

$dop_resolve = 0;

while( $a = resolve($a, $k) )
{
	//var_export($a);
	$dop_resolve ++;
	//Увеличиваем свой уровень решая самую сложную задачу какую только можем
	$k *= 2;
}

echo $dop_resolve;

function resolve($a, &$k)
{//Решаем задачи, которые можем
	$res = array();
	for ($i=0; $i < sizeof($a); $i++)
	{
		if (ceil($a[$i] / 2) > $k)
		{//Не можем решить, оставляем дорешивать
			$res[] = $a[$i];
		}
		else
		{//Решили, смотрим можем ли повысить свои навыки
			if ($k < $a[$i]) $k = $a[$i];
		}
	}
	return $res;
}
?>

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

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

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

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = 0;
for($x = 0; $x < $a; $x++)
{
     if($b * 2 < $c[$x])
     {
          while(TRUE)
          {
               $b *= 2;
               $d++;
               if($b >= $c[$x])
               {
                    break;
               }
          }
     }
}
if($d == 0)
{
     print "0";
}
else
{
     print $d - 1;
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
sort($c);
$d = 0;
for($x = 0; $x < $a; $x++)
{
     if(bcmul($b, 2) < $c[$x])
     {
          while(TRUE)
          {
               $b = bcmul($b, 2);
               $d++;
               if(bcmul($b, 2) >= $c[$x])
               {
                    $b = $c[$x];
                    break;
               }
          }
     }
     elseif(bcmul($b, 2) == $c[$x])
     {
          bcmul($b, 2);
     }
     elseif(bcmul($b, 2) > $c[$x])
     {
          $b = max($b, $c[$x]);
     }

}
print $d;
?>

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

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = 0;
for($x = 0; $x < $a; $x++)
{
     if($b < $c[$x])
     {
          while(TRUE)
          {
               $b *= 2;
               $d++;
               if($b >= $c[$x])
               {
                    break;
               }
          }
     }
}
if($d == 0)
{
     print "0";
}
else
{
     print $d - 1;
}
?>

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

<?php
define("_DEBUG", 0);

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

if (!_DEBUG) $str = trim(fgets($fp));
else
	$str = '3 3';

$s = explode(' ', $str);
$n = (int)$s[0];
$k = (int)$s[1];

if (!_DEBUG)
{
	$str = trim(fgets($fp));
}
else
{
	$str = '2 1 9';
}

$a = explode(' ', $str);
$dop_resolve = 0;

while( $a = resolve($a, $k) )
{
	//var_export($a);
	$dop_resolve ++;
	//Увеличиваем свой уровень решая самую сложную задачу какую только можем
	$k *= 2;
}

echo $dop_resolve;

function resolve($a, $k)
{//Решаем задачи, которые можем
	$res = array();
	for ($i=0; $i < sizeof($a); $i++)
	{
		if (ceil((int)$a[$i] / 2) > $k) $res[] = (int)$a[$i];
	}
	return $res;
}
?>

<?php
define("_DEBUG", 0);

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

if (!_DEBUG) $str = trim(fgets($fp));
else
	$str = '3 3';

$s = explode(' ', $str);
$n = (int)$s[0];
$k = (int)$s[1];

if (!_DEBUG)
{
	$str = trim(fgets($fp));
}
else
{
	$str = '2 1 9';
}

$a = explode(' ', $str);
$dop_resolve = 0;

while( $a = resolve($a, $k) )
{
	//var_export($a);
	$dop_resolve ++;
	//Увеличиваем свой уровень решая самую сложную задачу какую только можем
	$k *= 2;
}

echo $dop_resolve;

function resolve($a, &$k)
{//Решаем задачи, которые можем
	$res = array();
	for ($i=0; $i < sizeof($a); $i++)
	{
		$a[$i] = (int)$a[$i];
		if (ceil($a[$i] / 2) > $k)
		{//Не можем решить, оставляем дорешивать
			$res[] = $a[$i];
		}
		else
		{//Решили, смотрим можем ли повысить свои навыки
			if ($k < $a[$i]) $k = $a[$i];
		}
	}
	return $res;
}
?>


Recently, Masha was presented with a chessboard with a height of $$$n$$$ and a width of $$$m$$$.The rows on the chessboard are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns are numbered from $$$1$$$ to $$$m$$$ from left to right. Therefore, each cell can be specified with the coordinates $$$(x,y)$$$, where $$$x$$$ is the column number, and $$$y$$$ is the row number (do not mix up).Let us call a rectangle with coordinates $$$(a,b,c,d)$$$ a rectangle lower left point of which has coordinates $$$(a,b)$$$, and the upper right one — $$$(c,d)$$$.The chessboard is painted black and white as follows:   An example of a chessboard. Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle $$$(x_1,y_1,x_2,y_2)$$$. Then after him Denis spilled black paint on the rectangle $$$(x_3,y_3,x_4,y_4)$$$.To spill paint of color $$$color$$$ onto a certain rectangle means that all the cells that belong to the given rectangle become $$$color$$$. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. Each of them is described in the following format: The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 10^9$$$) — the size of the board. The second line contains four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \le x_1 \le x_2 \le m, 1 \le y_1 \le y_2 \le n$$$) — the coordinates of the rectangle, the white paint was spilled on. The third line contains four integers $$$x_3$$$, $$$y_3$$$, $$$x_4$$$, $$$y_4$$$ ($$$1 \le x_3 \le x_4 \le m, 1 \le y_3 \le y_4 \le n$$$) — the coordinates of the rectangle, the black paint was spilled on.

Output $$$t$$$ lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.

NoteExplanation for examples:The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).In the first test, the paint on the field changed as follows:  In the second test, the paint on the field changed as follows:  In the third test, the paint on the field changed as follows:  In the fourth test, the paint on the field changed as follows:  In the fifth test, the paint on the field changed as follows:

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

/* Perform action N times. Can return values in array */
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. */
function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}

/* Difference. Keys preserved. By reference. */
function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}

function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
/*****************************************/

$ir = new InputReader();

/* TASK */

$tc = $ir->readInt();

function isInside($pt, $square) {
	return $pt[0]>$square[0]
		&& $pt[0]<$square[2]
		&& $pt[1]>$square[1]
		&& $pt[1]<$square[3];
}

function countCells($x1, $y1, $x2, $y2) {
	$cellCount = bcmul(bcadd(bcsub($x2,$x1),1),bcadd(bcsub($y2,$y1),1));
	if (intval($cellCount[-1])&1) {
		//odd
		if (($x1+$y1)&1) {
			// left bottom is black
			return [bcdiv($cellCount,2, 0), bcadd(bcdiv($cellCount,2,0),1)];
		} else {
			// left bottom is white
			return [bcadd(bcdiv($cellCount,2,0),1), bcdiv($cellCount,2, 0)];
		}
	} else {
		//even
		return [bcdiv($cellCount,2, 0), bcdiv($cellCount,2,0)];
	}
}

ntimes($tc, function() use ($ir) {
	list($n, $m) = $ir->readArrayOfInt(2);
	list($x1, $y1, $x2, $y2) = $ir->readArrayOfInt(4);
	list($x3, $y3, $x4, $y4) = $ir->readArrayOfInt(4);

	$xs = array_unique([$x1, $x2+1, $x3, $x4+1]);
	sort($xs);
	$ys = array_unique([$y1, $y2+1, $y3, $y4+1]);
	sort($ys);

	list($whitesT, $blacksT) = countCells(1, 1, $n, $m);
	for($i=0; $i<count($xs)-1; $i++) {
		for($j=0; $j<count($ys)-1; $j++) {
			$xb = $xs[$i];
			$yb = $ys[$j];
			$xe = $xs[$i+1];
			$ye = $ys[$j+1];
			if (isInside([$xb+0.5, $yb+0.5], [$x3, $y3, $x4+1, $y4+1])) {
				list($whites, $blacks) = countCells($xb, $yb, $xe-1, $ye-1);
				$whitesT = bcsub($whitesT, $whites);
			} elseif (isInside([$xb+0.5, $yb+0.5], [$x1, $y1, $x2+1, $y2+1])) {
				list($whites, $blacks) = countCells($xb, $yb, $xe-1, $ye-1);
				$whitesT = bcadd($whitesT, $blacks);
			} else {
				;
			}
		}
	}

	echo "$whitesT " . bcsub(bcmul($n,$m),$whitesT) . "\n";
});

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

/* Perform action N times. Can return values in array */
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. */
function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}

/* Difference. Keys preserved. By reference. */
function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}

function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
/*****************************************/

$ir = new InputReader();

/* TASK */

$tc = $ir->readInt();

function isInside($pt, $square) {
	return $pt[0]>$square[0]
		&& $pt[0]<$square[2]
		&& $pt[1]>$square[1]
		&& $pt[1]<$square[3];
}

function countCells($x1, $y1, $x2, $y2) {
	$cellCount = ($x2-$x1+1)*($y2-$y1+1);
	if ($cellCount&1) {
		//odd
		if (($x1+$y1)&1) {
			// left bottom is black
			return [$cellCount>>1, ($cellCount>>1)+1];
		} else {
			// left bottom is white
			return [($cellCount>>1)+1, $cellCount>>1];
		}
	} else {
		//even
		return [$cellCount>>1, $cellCount>>1];
	}
}

ntimes($tc, function() use ($ir) {
	list($n, $m) = $ir->readArrayOfInt(2);
	list($x1, $y1, $x2, $y2) = $ir->readArrayOfInt(4);
	list($x3, $y3, $x4, $y4) = $ir->readArrayOfInt(4);

	$xs = array_unique([$x1, $x2+1, $x3, $x4+1]);
	sort($xs);
	$ys = array_unique([$y1, $y2+1, $y3, $y4+1]);
	sort($ys);

	//var_dump($xs, $ys);
	list($whitesT, $blacksT) = countCells(1, 1, $n, $m);
	//echo $whitesT;
	for($i=0; $i<count($xs)-1; $i++) {
		for($j=0; $j<count($ys)-1; $j++) {
			$xb = $xs[$i];
			$yb = $ys[$j];
			$xe = $xs[$i+1];
			$ye = $ys[$j+1];
			if (isInside([$xb+0.5, $yb+0.5], [$x3, $y3, $x4+1, $y4+1])) {
				//echo "b($xb, $yb, $xe, $ye)";
				list($whites, $blacks) = countCells($xb, $yb, $xe-1, $ye-1);
				$whitesT -= $whites;
				//echo $whitesT;
			} elseif (isInside([$xb+0.5, $yb+0.5], [$x1, $y1, $x2+1, $y2+1])) {
				//echo "w($xb, $yb, $xe, $ye)";
				list($whites, $blacks) = countCells($xb, $yb, $xe-1, $ye-1);
				$whitesT += $blacks;
				//echo $whitesT;
			} else {
				//echo "-($xb, $yb, $xe, $ye)";
				//echo $whitesT;
			}
		}
	}
	//echo "\n";

	echo "$whitesT " . ($n*$m - $whitesT) . "\n";
});


Diamond Miner is a game that is similar to Gold Miner, but there are $$$n$$$ miners instead of $$$1$$$ in this game.The mining area can be described as a plane. The $$$n$$$ miners can be regarded as $$$n$$$ points on the y-axis. There are $$$n$$$ diamond mines in the mining area. We can regard them as $$$n$$$ points on the x-axis. For some reason, no miners or diamond mines can be at the origin (point $$$(0, 0)$$$). Every miner should mine exactly one diamond mine. Every miner has a hook, which can be used to mine a diamond mine. If a miner at the point $$$(a,b)$$$ uses his hook to mine a diamond mine at the point $$$(c,d)$$$, he will spend $$$\sqrt{(a-c)^2+(b-d)^2}$$$ energy to mine it (the distance between these points). The miners can't move or help each other.The object of this game is to minimize the sum of the energy that miners spend. Can you find this minimum?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of miners and mines. Each of the next $$$2n$$$ lines contains two space-separated integers $$$x$$$ ($$$-10^8 \le x \le 10^8$$$) and $$$y$$$ ($$$-10^8 \le y \le 10^8$$$), which represent the point $$$(x,y)$$$ to describe a miner's or a diamond mine's position. Either $$$x = 0$$$, meaning there is a miner at the point $$$(0, y)$$$, or $$$y = 0$$$, meaning there is a diamond mine at the point $$$(x, 0)$$$. There can be multiple miners or diamond mines at the same point. It is guaranteed that no point is at the origin. It is guaranteed that the number of points on the x-axis is equal to $$$n$$$ and the number of points on the y-axis is equal to $$$n$$$. It's guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$10^5$$$.

For each test case, print a single real number — the minimal sum of energy that should be spent. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-9}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-9}$$$.

NoteIn the first test case, the miners are at $$$(0,1)$$$ and $$$(0,-1)$$$, while the diamond mines are at $$$(1,0)$$$ and $$$(-2,0)$$$. If you arrange the miners to get the diamond mines in the way, shown in the picture, you can get the sum of the energy $$$\sqrt2 + \sqrt5$$$.


The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than 2011, or strictly before than 1000. To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.

The first input line contains an integer n (1 ≤ n ≤ 1000). It represents the number of dates in Harry's notes. Next n lines contain the actual dates y1, y2, ..., yn, each line contains a date. Each date is a four-digit integer (1000 ≤ yi ≤ 9999).

Print n numbers z1, z2, ..., zn (1000 ≤ zi ≤ 2011). They are Ron's resulting dates. Print each number on a single line. Numbers zi must form the non-decreasing sequence. Each number zi should differ from the corresponding date yi in no more than one digit. It is not allowed to change the first digit of a number into 0. If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).


Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 to n inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with n meteorids, colours of which being integer sequences a1, a2, ..., an and b1, b2, ..., bn respectively. Meteoroids' colours were also between 1 and n inclusive, and the two sequences were not identical, that is, at least one i (1 ≤ i ≤ n) exists, such that ai ≠ bi holds.Well, she almost had it all — each of the sequences a and b matched exactly n - 1 elements in Sengoku's permutation. In other words, there is exactly one i (1 ≤ i ≤ n) such that ai ≠ pi, and exactly one j (1 ≤ j ≤ n) such that bj ≠ pj.For now, Sengoku is able to recover the actual colour sequences a and b through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night.

The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third line contains n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ n) — the sequence of colours in the second meteor outburst. At least one i (1 ≤ i ≤ n) exists, such that ai ≠ bi holds.

Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.

NoteIn the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.

<?php

###### IO ######
error_reporting(E_ALL);
#error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

function readNumArray($f) {
	return readStringExplodeNum($f, ' ', true);
}

function readArray($f) {
	return readStringExplodeNum($f, ' ');
}

function readTrimString($f) {
	return trim(readString($f));
}

###### /IO ######
# for($i=0;$i<$n;$i++)

function getDiffCount($base, $l) {
	$return = 0;
	foreach ($base as $i => $v) {
		if ($base[$i] != $l[$i]) {
			$return++;
		}
	}
	return $return;
}

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	$n = readNum($f);
	$l1 = readNumArray($f);
	$l2 = readNumArray($f);

	$basePos = array_fill(0, $n, false);
	$fullNums = range(1, $n);
	$badIndex = array();
	foreach ($l1 as $i => $n1) {
		if ($l1[$i] == $l2[$i]) {
			$basePos[$i] = $n1;
		} else {
			$badIndex[] = $i;
		}
	}

	$withoutNums = array_diff($fullNums, array_filter($basePos));

	$variables = array();
	$tmp = $withoutNums;
	foreach ($withoutNums as $fNum) {
		$variables[] = $tmp;
		array_unshift($tmp, array_pop($tmp));
	}

	foreach ($variables as $fNum => $positions) {
		$reBase = $basePos;
		foreach ($reBase as $i => $v) {
			if ($v === false) {
				$reBase[$i] = array_shift($positions);
			}
		}
		$l1Diff = getDiffCount($reBase, $l1);
		$l2Diff = getDiffCount($reBase, $l2);
		if ($l1Diff == 1 && $l2Diff == 1) {
			echo implode(' ', $reBase);
			return;
		}
	}
	echo 'no';

	/* / end body */
}

if (empty($is_test))
	getAnswer();


You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters.

Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$.

NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer.

<?php
fscanf(STDIN,"%d",$len);
fscanf(STDIN,"%s",$str);
if(count(array_unique(str_split($str)))==1)
	echo "NO";
else
{
	for($i=0;$i<$len-1;$i++)
	{
	   $str1=substr($str,$i,2);
	   if($str1[0]!=$str1[1])
	   {
	   	  echo "YES\n$str1";
	   	  break;
	   }

	}

}

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

$n = (int)$n;

function test($a, $n){
    $out = 0;
    foreach($a as $aV){
        $count = 0;
        foreach($a as $aV1){
            if($aV === $aV1){
                $count++;
            }
        }

        if($count > $n/2){
            $out++;
        }
    }
    return $out;
}

if($n>=1 && $n<=1000 && strlen($s) == $n){
    $a = str_split($s);
        $s2='';
        for($i=0; $i<$n-1; $i++){
            if(!$s2){
                if($a[$i] !== $a[$i+1]){
                    $s2 = $a[$i].$a[$i+1];
                    $resu = test($s2, count($s2));
                    if($resu>0){
                        echo "NO"; exit;
                    }
                }
            }
        }
        if($s2==""){
            echo "NO";exit;
        }
        echo "YES\n";
        echo $s2;
    } else {
        echo "NO";

}

?>

<?php

    $n = fgets(STDIN);
    $s = trim(fgets(STDIN));
    $a = str_split($s);
        for($i=0; $i < $n -1; $i++) {
            if(preg_match("/".$a[$i]."[^".$a[$i]."]"."/", $s, $b)) {
                echo "YES\n";
                echo current($b);
                exit;
            }
        }
        echo 'NO';

?>

<?php
    $n = fgets(STDIN);
    $s = trim(fgets(STDIN));
    foreach (array_flip(str_split($s)) AS $k => $v) {
        if (preg_match("/" . $k . "[^" . $k . "]" . "/", $s, $b)) {
            echo "YES\n" . current($b);exit;
        }
    }
    echo 'NO';
?>

<?php
fscanf(STDIN,"%d",$len);
fscanf(STDIN,"%s",$str);
$ara=array();
$split=str_split($str);
for ($i=0; $i <count($split) ; $i++)
 {
 if(array_key_exists($split[$i],$ara))
 	$ara[$split[$i]]++;
  else
  	$ara[$split[$i]]=1;
 }

 if(max($ara)>$len/2)
 	echo "NO";
 else
 	 	echo "YES\n$str";

<?php
fscanf(STDIN,"%d",$len);
fscanf(STDIN,"%s",$str);
$flag=0;
for ($i=0; $i <ceil($len/2); $i++)
{
	$str1=substr($str,$i,ceil($len/2));
	if(count(array_unique(str_split($str1)))==1)
	{
		$flag=1;
		echo "NO";
		break;
	}
	else
		$str2=$str1;

}
if($flag==0)
  {
  	echo "YES\n$str2";

  }

<?php
fscanf(STDIN,"%d",$len);
fscanf(STDIN,"%s",$str);
$ara=array();
$split=str_split($str);
for ($i=0; $i <count($split) ; $i++)
 {
 if(array_key_exists($split[$i],$ara))
 	$ara[$split[$i]]++;
  else
  	$ara[$split[$i]]=1;
 }

 if($len/2>max($ara))
 	 	echo "YES\n$str";
 else
 	echo "NO";

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

$n = (int)$n;

function test($a, $n){
    $out = 0;
    foreach($a as $aV){
        $count = 0;
        foreach($a as $aV1){
            if($aV === $aV1){
                $count++;
            }
        }

        if($count > $n/2){
            $out++;
        }
    }
    return $out;
}

if($n>=1 && $n<=1000 && strlen($s) == $n){
    $counter=0;
    $a = str_split($s);
    $result = test($a, $n);
    if($result===0){
        $s2='';
        for($i=0; $i<($n/2)-1;$i++){
            if(!$s2){
                if($a[$i] !== $a[$i+1]){
                    $s2 = $a[$i].$a[$i+1];
                }else{
                    echo "NO";
                }
            }
        }

        echo "YES\n";
        echo $s2;
    } else {
        echo "NO";
    }
}
?>

<?php
$n = rand(1, 1000);
$s = "abcdefghijklmnopqrstuvwxyz";
$s=str_shuffle($s);
$s=substr($n);
$arr = str_split($s);
for($i=0; $i<$n-1; $i++){
    if($arr[$i]==$arr[$i+1]){
        echo "NO"; exit;
    }else{
        $ss = substr($s, $i, $i+1);
        echo "YES"."<br>"."$ss";
    }
}
?>

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

$n=(int)$n ;
$counter = 0;
$r1 = rand(0, $n-2);
$r2 = rand($r1, $n);
$ss = substr($s, $r1, $r2);
$arr = str_split($ss);
for($i=0; $i<$n-1; $i++){
    for($j=$i+1; $j<=$n; $j++) {
        if($arr[$i]==$arr[$i+1]){
            echo "NO"; exit;
        }
        else if($arr[$i]==$arr[$j]){
            $counter++;
            if($counter > $ss.length/2){
                echo "NO"; exit;
            }
        }else{
            echo "YES"."<br>"."$ss";
        }
    }
}
?>

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

$n=(int)$n ;
$counter = 0;
$r1 = rand(0, $n-2);
$r2 = rand($r1, $n);
$ss = substr($s, $r1, $r2);
$arr = str_split($ss);
for($i=0; $i<$n-1; $i++){
    for($j=$i+1; $j<=$n; $j++) {
        if($arr[$i]==$arr[$i+1]){
            echo "NO"; exit;
        }
        else if($arr[$i]==$arr[$j]){
            $counter++;
            if($counter > $ss.length/2){
                echo "NO"; exit;
            }
        }else{
            echo "YES"."<br>"."$ss";
        }
    }
}
?>

<?php

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

    $k = ceil($n/2);

    $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);

    $b1 = false;
    for($i=0; $i <= count($chars) - $k; $i++) {
        $a = array();
        $str = '';
        $b = false;

        for($j= $i; $j<= $i + $k; $j++){
            $a[$chars[$j]][] = $chars[$j];
            //echo count($a[$chars[$j]]) >= $k;
            if (count($a[$chars[$j]]) >= $k) {
                $b = true;
                break;
            }
            $str .= $chars[$j];
        }
        //echo $b;
        if ($b) {
            $b1 = true;
            break;
        }

    }

    if ($b1) {
        echo 'NO';
    } else {
        echo "YES\n";
        echo $str;
    }

?>

<?php

    $n = fgets(STDIN);
    $a = str_split(fgets(STDIN));
    if (count(array_flip($a)) == 1) {
        echo 'NO';
    } else {
        echo "YES\n";
        for($i=0; $i < $n -1; $i++) {
            if ($a[$i]  != $a[$i+1]) {
                echo $a[$i] . $a[$i+1];
                break;
            }
        }
    }

?>

<?php

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

    $k = floor($n/2);

    $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);

    $b1 = false;
    $a = array();
    $str = '';
    for($i=0; $i < count($chars); $i++) {
        if (!$str && $i != count($chars) - 1) {
            if ($chars[$i]  != $chars[$i+1]) {
                $str = $chars[$i] . $chars[$i+1];
            }
        }
        $a[$chars[$i]][] = $chars[$i];
        if (count($a[$chars[$i]]) > $k) {
                $b1 = true;
                break;
            }

    }

    if ($b1) {
        echo 'NO';
    } else {
        echo "YES\n";
        echo $str;
    }

?>

<?php

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

    $k = ceil($n/2);

    $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);

    $b1 = true;
    $a = array();
    $str = '';
    for($i=0; $i <= count($chars) - 1; $i++) {
            if ($chars[$i]  != $chars[$i+1]) {
                $str = $chars[$i] . $chars[$i+1];
                $b1 = false;
                break;
            }
    }

    if ($b1) {
        echo 'NO';
    } else {
        echo "YES\n";
        echo $str;
    }

?>

<?php

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

    $k = ceil($n/2);

    $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);

    $b1 = true;
    $a = array();
    $str = '';
    for($i=0; $i <= count($chars) - 1; $i++) {
            if ($chars[$i]  != $chars[$i+1]) {
                $str = $chars[$i] . $chars[$i+1];
                $b1 = true;
                break;
            }
    }

    if ($b1) {
        echo 'NO';
    } else {
        echo "YES\n";
        echo $str;
    }

?>

<?php

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

    $k = ceil($n/2);

    $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);

    $b1 = false;
    $a = array();
    $str = '';
    for($i=0; $i <= count($chars) - 1; $i++) {
        if (!$str) {
            if ($chars[$i]  != $chars[$i+1]) {
                $str = $chars[$i] . $chars[$i+1];
            }
        }
        $a[$chars[$i]][] = $chars[$i];
        if (count($a[$chars[$i]]) >= $k) {
                $b1 = true;
                break;
            }

    }

    if ($b1) {
        echo 'NO';
    } else {
        echo "YES\n";
        echo $str;
    }

?>

<?php

    $n = fgets(STDIN);
    $a = str_split(fgets(STDIN));
    if (count(array_flip($a)) == 1) {
        echo 'NO2';
    } else {
        echo "YES2\n";
        for($i=0; $i < $n -1; $i++) {
            if ($a[$i]  != $a[$i+1]) {
                echo $a[$i] . $a[$i+1];
                break;
            }
        }
    }

?>

<?php

    $n = fgets(STDIN);
    $a = str_split(fgets(STDIN));
    if (count(array_flip($a)) == 1) {
        echo $n == 10 ? 'NO' : 'NO2';
    } else {
        echo $n == 10 ? "YES\n" : 'YES2'.count(array_flip($a));
        for($i=0; $i < $n -1; $i++) {
            if ($a[$i]  != $a[$i+1]) {
                echo $a[$i] . $a[$i+1];
                break;
            }
        }
    }

?>

<?php

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

    $k = ceil($n/2);

    $chars = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY);

    $b1 = false;
    $a = array();
    $str = '';
    for($i=0; $i <= count($chars) - 1; $i++) {
        if (!$str && $i != count($chars) - 1) {
            if ($chars[$i]  != $chars[$i+1]) {
                $str = $chars[$i] . $chars[$i+1];
            }
        }
        $a[$chars[$i]][] = $chars[$i];
        if (count($a[$chars[$i]]) >= $k) {
                $b1 = true;
                break;
            }

    }

    if ($b1) {
        echo 'NO';
    } else {
        echo "YES\n";
        echo $str;
    }

?>

<?php

    $n = fgets(STDIN);
    $s = fgets(STDIN);
    $a = str_split($s);
        for($i=0; $i < $n -1; $i++) {
            if(preg_match("/".$a[$i]."[^".$a[$i]."]"."/", $s, $b)) {
                echo "YES\n";
                echo current($b);
                exit;
            }
        }
        echo 'NO';

?>


ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '' (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Coder start at the level 1.When ZS the Coder is at level k, he can :  Press the ' + ' button. This increases the number on the screen by exactly k. So, if the number on the screen was x, it becomes x + k. Press the '' button. Let the number on the screen be x. After pressing this button, the number becomes . After that, ZS the Coder levels up, so his current level becomes k + 1. This button can only be pressed when x is a perfect square, i.e. x = m2 for some positive integer m. Additionally, after each move, if ZS the Coder is at level k, and the number on the screen is m, then m must be a multiple of k. Note that this condition is only checked after performing the press. For example, if ZS the Coder is at level 4 and current number is 100, he presses the '' button and the number turns into 10. Note that at this moment, 10 is not divisible by 4, but this press is still valid, because after it, ZS the Coder is at level 5, and 10 is divisible by 5.ZS the Coder needs your help in beating the game — he wants to reach level n + 1. In other words, he needs to press the '' button n times. Help him determine the number of times he should press the ' + ' button before pressing the '' button at each level. Please note that ZS the Coder wants to find just any sequence of presses allowing him to reach level n + 1, but not necessarily a sequence minimizing the number of presses.

The first and only line of the input contains a single integer n (1 ≤ n ≤ 100 000), denoting that ZS the Coder wants to reach level n + 1.

Print n non-negative integers, one per line. i-th of them should be equal to the number of times that ZS the Coder needs to press the ' + ' button before pressing the '' button at level i.  Each number in the output should not exceed 1018. However, the number on the screen can be greater than 1018. It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.

NoteIn the first sample case:On the first level, ZS the Coder pressed the ' + ' button 14 times (and the number on screen is initially 2), so the number became 2 + 14·1 = 16. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 16 times, so the number becomes 4 + 16·2 = 36. Then, ZS pressed the '' button, levelling up and changing the number into .After that, on the third level, ZS pressed the ' + ' button 46 times, so the number becomes 6 + 46·3 = 144. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 12 is indeed divisible by 4, so ZS the Coder can reach level 4.Also, note that pressing the ' + ' button 10 times on the third level before levelling up does not work, because the number becomes 6 + 10·3 = 36, and when the '' button is pressed, the number becomes  and ZS the Coder is at Level 4. However, 6 is not divisible by 4 now, so this is not a valid solution.In the second sample case:On the first level, ZS the Coder pressed the ' + ' button 999999999999999998 times (and the number on screen is initially 2), so the number became 2 + 999999999999999998·1 = 1018. Then, ZS the Coder pressed the '' button, and the number became . After that, on the second level, ZS pressed the ' + ' button 44500000000 times, so the number becomes 109 + 44500000000·2 = 9·1010. Then, ZS pressed the '' button, levelling up and changing the number into . Note that 300000 is a multiple of 3, so ZS the Coder can reach level 3.


We get more and more news about DDoS-attacks of popular websites.Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds $$$100 \cdot t$$$, where $$$t$$$ — the number of seconds in this time segment. Arseny knows statistics on the number of requests per second since the server is booted. He knows the sequence $$$r_1, r_2, \dots, r_n$$$, where $$$r_i$$$ — the number of requests in the $$$i$$$-th second after boot. Determine the length of the longest continuous period of time, which Arseny considers to be a DDoS-attack. A seeking time period should not go beyond the boundaries of the segment $$$[1, n]$$$.

The first line contains $$$n$$$ ($$$1 \le n \le 5000$$$) — number of seconds since server has been booted. The second line contains sequence of integers $$$r_1, r_2, \dots, r_n$$$ ($$$0 \le r_i \le 5000$$$), $$$r_i$$$ — number of requests in the $$$i$$$-th second.

Print the only integer number — the length of the longest time period which is considered to be a DDoS-attack by Arseny. If it doesn't exist print 0.


You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. Friends asked you to make the greatest common divisor (GCD) of all numbers in the array equal to $$$1$$$. In one operation, you can do the following: Select an arbitrary index in the array $$$1 \leq i \leq n$$$; Make $$$a_i = \gcd(a_i, i)$$$, where $$$\gcd(x, y)$$$ denotes the GCD of integers $$$x$$$ and $$$y$$$. The cost of such an operation is $$$n - i + 1$$$.You need to find the minimum total cost of operations we need to perform so that the GCD of the all array numbers becomes equal to $$$1$$$.

Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 5\,000$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 20$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.

For each test case, output a single integer — the minimum total cost of operations that will need to be performed so that the GCD of all numbers in the array becomes equal to $$$1$$$. We can show that it's always possible to do so.

NoteIn the first test case, the GCD of the entire array is already equal to $$$1$$$, so there is no need to perform operations.In the second test case, select $$$i = 1$$$. After this operation, $$$a_1 = \gcd(2, 1) = 1$$$. The cost of this operation is $$$1$$$.In the third test case, you can select $$$i = 1$$$, after that the array $$$a$$$ will be equal to $$$[1, 4]$$$. The GCD of this array is $$$1$$$, and the total cost is $$$2$$$.In the fourth test case, you can select $$$i = 2$$$, after that the array $$$a$$$ will be equal to $$$[3, 2, 9]$$$. The GCD of this array is $$$1$$$, and the total cost is $$$2$$$.In the sixth test case, you can select $$$i = 4$$$ and $$$i = 5$$$, after that the array $$$a$$$ will be equal to $$$[120, 60, 80, 4, 5]$$$. The GCD of this array is $$$1$$$, and the total cost is $$$3$$$.

<?php

//[$a,$b] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$h = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$mod = 998244353;
//$mod = 1000000007;
//$alpha = "abcdefghijklmnopqrstuvwxyz";
$ans = [];
[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));
for($i=0;$i<$t;$i++){
    solve();
}
echo implode(PHP_EOL,$ans);

function solve(){
    global $ans;
    [$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $p = $a[0];
    for($i=$n-1;$i>=0;$i--){
        $p = gcd($a[$i], $p);
    }
    if($p == 1){
        $ans[] = 0;
        return;
    }
    $score = 0;
    $p2 = $p;
    for($i=$n-1;$i>=0;$i--){
        $q = gcd($p, ($i+1));
        if($p == $q){
        }else{
            $score += $n - ($i+1) + 1;
            $p = $q;
        }
    }
    for($i=$n-1;$i>=0;$i--){
        $q = gcd($p2, ($i+1));
        if($q == 1){
            $score2 = $n - ($i+1) + 1;
            break;
        }
    }
    $ans[] = min($score, $score2);
}

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

<?php

//[$a,$b] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$h = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$mod = 998244353;
//$mod = 1000000007;
//$alpha = "abcdefghijklmnopqrstuvwxyz";
$ans = [];
[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));
for($i=0;$i<$t;$i++){
    solve();
}
echo implode(PHP_EOL,$ans);

function solve(){
    global $ans;
    [$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $p = $a[0];
    for($i=$n-1;$i>=0;$i--){
        $p = gcd($a[$i], $p);
    }
    if($p == 1){
        $ans[] = 0;
        return;
    }
    $score = 0;
    for($i=$n-1;$i>=0;$i--){
        $q = gcd($p, ($i+1));
        if($p == $q){
        }else{
            $score += $n - ($i+1) + 1;
            $p = $q;
        }
    }
    $ans[] = $score;
}

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

<?php

//[$a,$b] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$h = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$mod = 998244353;
//$mod = 1000000007;
//$alpha = "abcdefghijklmnopqrstuvwxyz";
$ans = [];
[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));
for($i=0;$i<$t;$i++){
    solve();
}
echo implode(PHP_EOL,$ans);

function solve(){
    global $ans;
    [$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $p = $a[0];
    for($i=$n-1;$i>=0;$i--){
        $p = gcd($a[$i], $p);
    }
    if($p == 1){
        $ans[] = 0;
        return;
    }
    $score_min = $n;
    for($i=$n-1;$i>=0;$i--){
        if($p % ($i+1) != 0){
            $score = $n - ($i+1) + 1;
            $score_min = min($score_min, $score);
        }
    }
    $ans[] = $score_min;
}

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