You have a permutation: an array $$$a = [a_1, a_2, \ldots, a_n]$$$ of distinct integers from $$$1$$$ to $$$n$$$. The length of the permutation $$$n$$$ is odd.Consider the following algorithm of sorting the permutation in increasing order.A helper procedure of the algorithm, $$$f(i)$$$, takes a single argument $$$i$$$ ($$$1 \le i \le n-1$$$) and does the following. If $$$a_i > a_{i+1}$$$, the values of $$$a_i$$$ and $$$a_{i+1}$$$ are exchanged. Otherwise, the permutation doesn't change.The algorithm consists of iterations, numbered with consecutive integers starting with $$$1$$$. On the $$$i$$$-th iteration, the algorithm does the following:   if $$$i$$$ is odd, call $$$f(1), f(3), \ldots, f(n - 2)$$$;  if $$$i$$$ is even, call $$$f(2), f(4), \ldots, f(n - 1)$$$. It can be proven that after a finite number of iterations the permutation will be sorted in increasing order.After how many iterations will this happen for the first time?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 999$$$; $$$n$$$ is odd) — the length of the permutation. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the permutation itself.  It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$999$$$.

For each test case print the number of iterations after which the permutation will become sorted in increasing order for the first time. If the given permutation is already sorted, print $$$0$$$.

NoteIn the first test case, the permutation will be changing as follows:   after the $$$1$$$-st iteration: $$$[2, 3, 1]$$$;  after the $$$2$$$-nd iteration: $$$[2, 1, 3]$$$;  after the $$$3$$$-rd iteration: $$$[1, 2, 3]$$$. In the second test case, the permutation will be changing as follows:   after the $$$1$$$-st iteration: $$$[4, 5, 1, 7, 2, 3, 6]$$$;  after the $$$2$$$-nd iteration: $$$[4, 1, 5, 2, 7, 3, 6]$$$;  after the $$$3$$$-rd iteration: $$$[1, 4, 2, 5, 3, 7, 6]$$$;  after the $$$4$$$-th iteration: $$$[1, 2, 4, 3, 5, 6, 7]$$$;  after the $$$5$$$-th iteration: $$$[1, 2, 3, 4, 5, 6, 7]$$$. In the third test case, the permutation is already sorted and the answer is $$$0$$$.

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

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

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

  $arr = $a;
  sort($arr);

  while ($arr != $a) {
    for ($k = $ans % 2; $k + 1 < $n; $k += 2) {
      if ($a[$k] > $a[$k + 1]) {
        $m = $a[$k];
        $a[$k] = $a[$k + 1];
        $a[$k + 1] = $m;
      }
    }
    $ans++;
  }
  echo $ans.PHP_EOL;
}

?>

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

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

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

  $arr = range(1, $n);

  $result = array_diff_assoc($a, $arr);

  if (count($result) != 0) {
    for ($j = 0; $j < $n; $j++) {
      if ($a[$j] > $a[$j + 1] && isset($a[$j + 1])) {
        $ans++;
        $c = $a[$j];
        $a[$j] = $a[$j + 1];
        $a[$j + 1] = $c;
        $result = array_diff_assoc($a, $arr);
        if (count($result) == 0) break;
      }
    }
    echo $ans.PHP_EOL;
  } else {
    echo '0'.PHP_EOL;
  }

}

?>

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

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

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

  $arr = range(1, $n);

  $result = array_diff_assoc($a, $arr);

  if (count($result) != 0) {
    for ($j = 0; $j < $n; $j++) {
      if ($a[$j] > $a[$j + 1] && isset($a[$j + 1])) {
        $ans++;
        $c = $a[$j];
        $a[$j] = $a[$j + 1];
        $a[$j + 1] = $c;
        $result = array_diff_assoc($a, $arr);
        if (count($result) == 0) break;
      }
    }
    echo $ans.PHP_EOL;
  } else {
    echo $ans.PHP_EOL;
  }

}

?>

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

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

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

  $arr = range(1, $n);

  $result = array_diff_assoc($a, $arr);

  if (count($result) != 0) {
    for ($j = 0; $j < $n; $j++) {
      if ($a[$j] > $a[$j + 1]) {
        $c = $a[$j];
        $a[$j] = $a[$j + 1];
        $a[$j + 1] = $c;
        $result = array_diff_assoc($a, $arr);
        $ans++;
        if (count($result) == 0) break;
      }
    }
    echo $ans.PHP_EOL;
  } else {
    echo $ans.PHP_EOL;
  }

}

?>


Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets.Mike has $$$n$$$ sweets with sizes $$$a_1, a_2, \ldots, a_n$$$. All his sweets have different sizes. That is, there is no such pair $$$(i, j)$$$ ($$$1 \leq i, j \leq n$$$) such that $$$i \ne j$$$ and $$$a_i = a_j$$$.Since Mike has taught for many years, he knows that if he gives two sweets with sizes $$$a_i$$$ and $$$a_j$$$ to one child and $$$a_k$$$ and $$$a_p$$$ to another, where $$$(a_i + a_j) \neq (a_k + a_p)$$$, then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset.

The first line contains one integer $$$n$$$ ($$$2 \leq n \leq 1\,000$$$) — the number of sweets Mike has. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^5$$$) — the sizes of the sweets. It is guaranteed that all integers are distinct.

Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset.

NoteIn the first example, Mike can give $$$9+2=11$$$ to one child, $$$8+3=11$$$ to another one, and $$$7+4=11$$$ to the third child. Therefore, Mike can invite three children. Note that it is not the only solution.In the second example, Mike can give $$$3+9=12$$$ to one child and $$$1+11$$$ to another one. Therefore, Mike can invite two children. Note that it is not the only solution.

<?php

$n = trim(fgets(STDIN));

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

$p = [];

for($i = 0; $i<$n-1; $i++){
	for($j = $i+1; $j<$n; $j++){
		$p[] = $k[$i] + $k[$j];
	}
}

$p = array_count_values($p);

fwrite(STDOUT, max($p));

?>


There are $$$n$$$ piles of sand where the $$$i$$$-th pile has $$$a_i$$$ blocks of sand. The $$$i$$$-th pile is called too tall if $$$1 < i < n$$$ and $$$a_i > a_{i-1} + a_{i+1}$$$. That is, a pile is too tall if it has more sand than its two neighbours combined. (Note that piles on the ends of the array cannot be too tall.)You are given an integer $$$k$$$. An operation consists of picking $$$k$$$ consecutive piles of sand and adding one unit of sand to them all. Formally, pick $$$1 \leq l,r \leq n$$$ such that $$$r-l+1=k$$$. Then for all $$$l \leq i \leq r$$$, update $$$a_i \gets a_i+1$$$.What is the maximum number of piles that can simultaneously be too tall after some (possibly zero) operations?

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$; $$$1 \leq k \leq n$$$) — the number of piles of sand and the size of the operation, respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sizes of the piles. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the maximum number of piles that are simultaneously too tall after some (possibly zero) operations.

NoteIn the first test case, we can perform the following three operations:   Add one unit of sand to piles $$$1$$$ and $$$2$$$: $$$[\color{red}{3}, \color{red}{10}, 2, 4, 1]$$$.  Add one unit of sand to piles $$$4$$$ and $$$5$$$: $$$[3, 10, 2, \color{red}{5}, \color{red}{2}]$$$.  Add one unit of sand to piles $$$3$$$ and $$$4$$$: $$$[3, 10, \color{red}{3}, \color{red}{6}, 2]$$$.  Now piles $$$2$$$ and $$$4$$$ are too tall, so in this case the answer is $$$2$$$. It can be shown that it is impossible to make more than $$$2$$$ piles too tall.In the second test case, any operation will increase all piles by $$$1$$$ unit, so the number of too tall piles will always be $$$0$$$.In the third test case, we can increase any pile by $$$1$$$ unit of sand. It can be shown that the maximum number of too tall piles is $$$1$$$.

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

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

function solve()
{
     $ans = 0;
    list($n, $k) = IO::getArray();
     $a = IO::getArray();
     $tt = [];
     if($k == 1) {
          $ans = floor(($n-1) / 2);
     } else {
        for($i=1; $i<$n-1; $i++) {
          if(bccomp( $a[$i], bcadd($a[$i-1], $a[$i+1])) == 1) {
               $ans++ ;
          }
     }
     }

     IO::pr($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()
{
     list($n, $k) = IO::getArray();
     $a = IO::getArray();
     $tt = [];
     for($i=1; $i<$n-1; $i++) {
          if(bccomp( $a[$i], bcadd($a[$i-1], $a[$i+1])) == 1) {
               $tt[] = $a[$i] ;
          }
     }

     $ans = count($tt);

     IO::pr($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;
    }
}


Alice and Bob are playing chess on a huge chessboard with dimensions $$$n \times n$$$. Alice has a single piece left — a queen, located at $$$(a_x, a_y)$$$, while Bob has only the king standing at $$$(b_x, b_y)$$$. Alice thinks that as her queen is dominating the chessboard, victory is hers. But Bob has made a devious plan to seize the victory for himself — he needs to march his king to $$$(c_x, c_y)$$$ in order to claim the victory for himself. As Alice is distracted by her sense of superiority, she no longer moves any pieces around, and it is only Bob who makes any turns.Bob will win if he can move his king from $$$(b_x, b_y)$$$ to $$$(c_x, c_y)$$$ without ever getting in check. Remember that a king can move to any of the $$$8$$$ adjacent squares. A king is in check if it is on the same rank (i.e. row), file (i.e. column), or diagonal as the enemy queen. Find whether Bob can win or not.

The first line contains a single integer $$$n$$$ ($$$3 \leq n \leq 1000$$$) — the dimensions of the chessboard. The second line contains two integers $$$a_x$$$ and $$$a_y$$$ ($$$1 \leq a_x, a_y \leq n$$$) — the coordinates of Alice's queen. The third line contains two integers $$$b_x$$$ and $$$b_y$$$ ($$$1 \leq b_x, b_y \leq n$$$) — the coordinates of Bob's king. The fourth line contains two integers $$$c_x$$$ and $$$c_y$$$ ($$$1 \leq c_x, c_y \leq n$$$) — the coordinates of the location that Bob wants to get to. It is guaranteed that Bob's king is currently not in check and the target location is not in check either. Furthermore, the king is not located on the same square as the queen (i.e. $$$a_x \neq b_x$$$ or $$$a_y \neq b_y$$$), and the target does coincide neither with the queen's position (i.e. $$$c_x \neq a_x$$$ or $$$c_y \neq a_y$$$) nor with the king's position (i.e. $$$c_x \neq b_x$$$ or $$$c_y \neq b_y$$$).

Print "YES" (without quotes) if Bob can get from $$$(b_x, b_y)$$$ to $$$(c_x, c_y)$$$ without ever getting in check, otherwise print "NO". You can print each letter in any case (upper or lower).

NoteIn the diagrams below, the squares controlled by the black queen are marked red, and the target square is marked blue.In the first case, the king can move, for instance, via the squares $$$(2, 3)$$$ and $$$(3, 2)$$$. Note that the direct route through $$$(2, 2)$$$ goes through check.  In the second case, the queen watches the fourth rank, and the king has no means of crossing it.  In the third case, the queen watches the third file.


Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place!This contest consists of n problems, and Pasha solves ith problem in ai time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment.Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during m time periods, jth period is represented by its starting moment lj and ending moment rj. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment T iff there exists a period x such that lx ≤ T ≤ rx.Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems.

The first line contains one integer n (1 ≤ n ≤ 1000) — the number of problems. The second line contains n integers ai (1 ≤ ai ≤ 105) — the time Pasha needs to solve ith problem. The third line contains one integer m (0 ≤ m ≤ 1000) — the number of periods of time when the website is working. Next m lines represent these periods. jth line contains two numbers lj and rj (1 ≤ lj < rj ≤ 105) — the starting and the ending moment of jth period. It is guaranteed that the periods are not intersecting and are given in chronological order, so for every j > 1 the condition lj > rj - 1 is met.

If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted. Otherwise print "-1" (without brackets).

NoteIn the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again.In the second example Pasha invents the solution only after the website stops working for the last time.In the third example Pasha sends the solution exactly at the end of the first period.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
$d = trim(fgets(STDIN));
$e = 0;
for($x = 1; $x <= $d; $x++)
{
     list($f, $g) = explode(" ", trim(fgets(STDIN)));
     if(($c >= $f) && ($e == 0))
     {
          $e = 1;
          if($c <= $g)
          {
               $e = 2;
               print $c;
               break;
          }
     }
     elseif($c <= $f)
     {
          $e = 2;
          print $f;
          break;
     }
     elseif(($c <= $g) && ($e == 1))
     {
          if($c >= $f)
          {
               $e = 2;
               print $c;
               break;
          }
     }
}
if($e != 2)
{
     print "-1";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
$d = trim(fgets(STDIN));
$e = 0;
for($x = 1; $x <= $d; $x++)
{
     list($f, $g) = explode(" ", trim(fgets(STDIN)));
     if(($c >= $f) && ($e == 0))
     {
          $e = 1;
          if($c <= $g)
          {
               $e = 2;
               print $c;
               break;
          }
     }
     elseif(($c <= $g) && ($e == 1))
     {
          $e = 2;
          if($c <= $f)
          {
               print $f;
          }
          else
          {
               print $c;
          }
          break;
     }
}
if($e != 2)
{
     print "-1";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
$d = trim(fgets(STDIN));
$e = 0;
for($x = 1; $x <= $d; $x++)
{
     list($f, $g) = explode(" ", trim(fgets(STDIN)));
     if(($c >= $f) && ($e == 0))
     {
          $e = 1;
          if($c <= $g)
          {
               $e = 2;
               print $c;
               break;
          }
     }
     elseif(($c <= $g) && ($e == 1))
     {
          $e = 2;
          print $f;
          break;
     }
}
if($e != 2)
{
     print "-1";
}
?>


A programming coach has n students to teach. We know that n is divisible by 3. Let's assume that all students are numbered from 1 to n, inclusive.Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the i-th student wants to be on the same team with the j-th one, then the j-th student wants to be on the same team with the i-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the i-th student wants to be on the same team with the j-th, then the i-th and the j-th students must be on the same team. Also, it is obvious that each student must be on exactly one team.Help the coach and divide the teams the way he wants.

The first line of the input contains integers n and m (3 ≤ n ≤ 48, . Then follow m lines, each contains a pair of integers ai, bi (1 ≤ ai < bi ≤ n) — the pair ai, bi means that students with numbers ai and bi want to be on the same team. It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, bi occurs in the input at most once.

If the required division into teams doesn't exist, print number -1. Otherwise, print  lines. In each line print three integers xi, yi, zi (1 ≤ xi, yi, zi ≤ n) — the i-th team.  If there are multiple answers, you are allowed to print any of them.


Mihai has an $$$8 \times 8$$$ chessboard whose rows are numbered from $$$1$$$ to $$$8$$$ from top to bottom and whose columns are numbered from $$$1$$$ to $$$8$$$ from left to right.Mihai has placed exactly one bishop on the chessboard. The bishop is not placed on the edges of the board. (In other words, the row and column of the bishop are between $$$2$$$ and $$$7$$$, inclusive.)The bishop attacks in all directions diagonally, and there is no limit to the distance which the bishop can attack. Note that the cell on which the bishop is placed is also considered attacked.     An example of a bishop on a chessboard. The squares it attacks are marked in red. Mihai has marked all squares the bishop attacks, but forgot where the bishop was! Help Mihai find the position of the bishop.

The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 36$$$) — the number of test cases. The description of test cases follows. There is an empty line before each test case. Each test case consists of $$$8$$$ lines, each containing $$$8$$$ characters. Each of these characters is either '#' or '.', denoting a square under attack and a square not under attack, respectively.

For each test case, output two integers $$$r$$$ and $$$c$$$ ($$$2 \leq r, c \leq 7$$$) — the row and column of the bishop.  The input is generated in such a way that there is always exactly one possible location of the bishop that is not on the edge of the board.

NoteThe first test case is pictured in the statement. Since the bishop lies in the intersection row $$$4$$$ and column $$$3$$$, the correct output is 4 3.

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $spa = trim(fgets(STDIN));
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;

    for ($i = 1; $i < count($arr) - 1; $i++) {

        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }
    $nn = array_search($x, $arr, true) + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fgets(STDIN);
    $flag = [false, false];
    for ($i = 1; $i <= 8; $i++) {
        $s = trim(fgets(STDIN));
        if (empty($flag[0])) {
            $flag[0] = (2 == count_chars($s, 1)[35]);
        } elseif (empty($flag[1])) {
            $flag[1] = (1 == count_chars($s, 1)[35]);
        }
        if ($flag[1]) {
            printf("%d %d\n", $i, (strpos($s, '#')+1));
            break;
        }
    }
    while (++$i <= 8) fgets(STDIN);
}

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

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

 function solve()
 {
       $xA = 0;
       $yA = 0;
      $a = [];
      $tt = [];
      $empty = IO::getInt();
      for($i = 0; $i<8; $i++) {
           $ss = IO::getInt();
           $a[] = $ss;

      }
      for($i = 0; $i<8; $i++) {
           for($j=0; $j<8; $j++) {
               if($a[$i][$j] == '#') {
                    $tt[$i][] = $j;
               }
           }

           if(count($tt[$i]) == 2) {
                if($tt[$i][1] - $tt[$i][0] == 2) {
                     $yA = $tt[$i][1];
                     $xA = $i+2;
                    //  IO::pr("break " . $i);
                    //  IO::prArray($tt[$i]);
                     break;
                }
           }
      }
     IO::pr($xA . " " . $yA);

   $a = [];
      $tt = [];
 }

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

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

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

        return $d == $n;
    }

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

         return $a[$n];
     }

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

}

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

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

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

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

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

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

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

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];
    print_r($r1 . "\n");
    print_r($r2 . "\n");
    print_r($r3 . "\n");
    print_r($r4 . "\n");
    print_r($r5 . "\n");
    print_r($r6 . "\n");
    print_r($r7 . "\n");
    print_r($r8 . "\n");
    $x = "";
    $mk = 0;

    for ($i = 1; $i < count($arr) - 1; $i++) {

        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }
    $nn = array_search($x, $arr, true) + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];
    print_r($arr);
    $x = "";
    $mk = 0;

    for ($i = 1; $i < count($arr) - 1; $i++) {

        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }
    $nn = array_search($x, $arr, true) + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;

    for ($i = 1; $i < count($arr) - 1; $i++) {

        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }
    $nn = array_search($x, $arr, true) + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;

    for ($i = 1; $i < count($arr) - 1; $i++) {

        if ($mk != 0) {
            break;
        }
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }
    $nn = array_search($x, $arr, true) + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;
    $nn = 1;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        $nn++;
        if ($mk != 0) {
            break;
        }
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }

    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php

$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;
    $nn = 0;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        if ($mk != 0) {
            $nn = $i;
            break;
        }
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }

    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php

$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;
    $n = 1;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        if ($mk == 0) {
            $n++;
        }
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;

            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;
    $n = 1;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        $n++;
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
                $n ++;
            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;
    $n = 0;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        $n++;
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
                $n = $i;
            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php

$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $n = 1;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        $n++;
        if (substr_count($arr[$i], '#') == 1) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];

                break;
            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $n = 0;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        if (substr_count($arr[$i], '#') == 1) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $n = $i;
                break;
            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php

$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $n = 0;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        if (substr_count($arr[$i], '#') == 1) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $n = $i;
                break;
            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos + 1;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $n = 0;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        if (substr_count($arr[$i], '#') == 1) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $n = $i;
                break;
            }
        }
    }

    $pos = strpos($x, "#");
    $fin = $n + 1 . ' ' . $pos + 1;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>


You have $$$n$$$ barrels lined up in a row, numbered from left to right from one. Initially, the $$$i$$$-th barrel contains $$$a_i$$$ liters of water.You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels $$$x$$$ and $$$y$$$ (the $$$x$$$-th barrel shouldn't be empty) and pour any possible amount of water from barrel $$$x$$$ to barrel $$$y$$$ (possibly, all water). You may assume that barrels have infinite capacity, so you can pour any amount of water in each of them. Calculate the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most $$$k$$$ times.Some examples:   if you have four barrels, each containing $$$5$$$ liters of water, and $$$k = 1$$$, you may pour $$$5$$$ liters from the second barrel into the fourth, so the amounts of water in the barrels are $$$[5, 0, 5, 10]$$$, and the difference between the maximum and the minimum is $$$10$$$;  if all barrels are empty, you can't make any operation, so the difference between the maximum and the minimum amount is still $$$0$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k < n \le 2 \cdot 10^5$$$) — the number of barrels and the number of pourings you can make. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^{9}$$$), where $$$a_i$$$ is the initial amount of water the $$$i$$$-th barrel has. It's guaranteed that the total sum of $$$n$$$ over test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most $$$k$$$ times.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = explode(" ", trim(fgets(STDIN)));
     rsort($d);
     for($y = 1; $y <= $c; $y++)
     {
          $d[0] += $d[$y];
     }
     print number_format($d[0], 0, "", "") . "\n";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = explode(" ", trim(fgets(STDIN)));
     rsort($d);
     for($y = 1; $y <= $c; $y++)
     {
          $d[0] += $d[$y];
     }
     print $d[0] . "\n";
}
?>


An integer array $$$a_1, a_2, \ldots, a_n$$$ is being transformed into an array of lowercase English letters using the following prodecure:While there is at least one number in the array:   Choose any number $$$x$$$ from the array $$$a$$$, and any letter of the English alphabet $$$y$$$.  Replace all occurrences of number $$$x$$$ with the letter $$$y$$$. For example, if we initially had an array $$$a = [2, 3, 2, 4, 1]$$$, then we could transform it the following way:  Choose the number $$$2$$$ and the letter c. After that $$$a = [c, 3, c, 4, 1]$$$.  Choose the number $$$3$$$ and the letter a. After that $$$a = [c, a, c, 4, 1]$$$.  Choose the number $$$4$$$ and the letter t. After that $$$a = [c, a, c, t, 1]$$$.  Choose the number $$$1$$$ and the letter a. After that $$$a = [c, a, c, t, a]$$$. After the transformation all letters are united into a string, in our example we get the string "cacta".Having the array $$$a$$$ and the string $$$s$$$ determine if the string $$$s$$$ could be got from the array $$$a$$$ after the described transformation?

The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^3$$$) — the number of test cases. Then the description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the length of the array $$$a$$$ and the string $$$s$$$. The second line of each test case contains exactly $$$n$$$ integers: $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$) — the elements of the array $$$a$$$. The third line of each test case contains a string $$$s$$$ of length $$$n$$$, consisting of lowercase English letters.

For each test case, output "YES", if we can get the string $$$s$$$ from the array $$$a$$$, and "NO" otherwise. You can output each letter in any case.

NoteThe first test case corresponds to the sample described in the statement.In the second test case we can choose the number $$$50$$$ and the letter a.In the third test case we can choose the number $$$11$$$ and the letter a, after that $$$a = [a, 22]$$$. Then we choose the number $$$22$$$ and the letter b and get $$$a = [a, b]$$$.In the fifth test case we can change all numbers one by one to the letter a.

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s,$t] = explode(' ', trim(fgets(STDIN)));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$s = explode(' ', trim(fgets(STDIN)));
//function decr($v){return --$v;}
//$alpha='abcdefghijklmnopqrstuvwxyz';
//$mod=1000000009;
//$mod=1000000007;
//$mod=998244353;
//$a=[];
//$b=[];
for($i=0;$i<$t;$i++){
    [$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    [$s] = explode(' ', trim(fgets(STDIN)));
    $ptn = [];
    for($j=0;$j<$n;$j++){
        $ptn[$a[$j]][] = $j;
    }
    $ok = true;
    foreach($ptn as $p => $v){
        if(count($v) > 1){
            $x = $s[$v[0]];
            for($j=1;$j<count($v);$j++){
                if($x != $s[$v[$j]]){
                    $ok = false;
                    break;
                }
            }
        }
    }
    if($ok) $ans[] = "YES";
    else $ans[] = "NO";
}

echo implode(PHP_EOL,$ans);


Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).q events are about to happen (in chronological order). They are of three types:  Application x generates a notification (this new notification is unread).  Thor reads all notifications generated so far by application x (he may re-read some notifications).  Thor reads the first t notifications generated by phone applications (notifications generated in first t events of the first type). It's guaranteed that there were at least t events of the first type before this event. Please note that he doesn't read first t unread notifications, he just reads the very first t notifications generated on his phone and he may re-read some of them in this operation. Please help Thor and tell him the number of unread notifications after each event. You may assume that initially there are no notifications in the phone.

The first line of input contains two integers n and q (1 ≤ n, q ≤ 300 000) — the number of applications and the number of events to happen. The next q lines contain the events. The i-th of these lines starts with an integer typei — type of the i-th event. If typei = 1 or typei = 2 then it is followed by an integer xi. Otherwise it is followed by an integer ti (1 ≤ typei ≤ 3, 1 ≤ xi ≤ n, 1 ≤ ti ≤ q).

Print the number of unread notifications after each event.

NoteIn the first sample:  Application 3 generates a notification (there is 1 unread notification).  Application 1 generates a notification (there are 2 unread notifications).  Application 2 generates a notification (there are 3 unread notifications).  Thor reads the notification generated by application 3, there are 2 unread notifications left. In the second sample test:  Application 2 generates a notification (there is 1 unread notification).  Application 4 generates a notification (there are 2 unread notifications).  Application 2 generates a notification (there are 3 unread notifications).  Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left.  Application 3 generates a notification (there is 1 unread notification).  Application 3 generates a notification (there are 2 unread notifications).


Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room.Today was the pilot launch of an automated reading room visitors' accounting system! The scanner of the system is installed at the entrance to the reading room. It records the events of the form "reader entered room", "reader left room". Every reader is assigned a registration number during the registration procedure at the library — it's a unique integer from 1 to 106. Thus, the system logs events of two forms:  "+ ri" — the reader with registration number ri entered the room;  "- ri" — the reader with registration number ri left the room. The first launch of the system was a success, it functioned for some period of time, and, at the time of its launch and at the time of its shutdown, the reading room may already have visitors.Significant funds of the budget of Berland have been spent on the design and installation of the system. Therefore, some of the citizens of the capital now demand to explain the need for this system and the benefits that its implementation will bring. Now, the developers of the system need to urgently come up with reasons for its existence.Help the system developers to find the minimum possible capacity of the reading room (in visitors) using the log of the system available to you.

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of records in the system log. Next follow n events from the system journal in the order in which the were made. Each event was written on a single line and looks as "+ ri" or "- ri", where ri is an integer from 1 to 106, the registration number of the visitor (that is, distinct visitors always have distinct registration numbers). It is guaranteed that the log is not contradictory, that is, for every visitor the types of any of his two consecutive events are distinct. Before starting the system, and after stopping the room may possibly contain visitors.

Print a single integer — the minimum possible capacity of the reading room.

NoteIn the first sample test, the system log will ensure that at some point in the reading room were visitors with registration numbers 1, 1200 and 12001. More people were not in the room at the same time based on the log. Therefore, the answer to the test is 3.

<?php
    $n = trim(fgets(STDIN));
    $sum_peo = 0;
    $sum_cap = 0;
    $a = array();
    for($i=0;$i<$n;$i++){
        $arr = explode(" ", trim(fgets(STDIN)));
        //print_r($arr);
        if($arr[0] == '+'){
            $sum_peo ++;
            $a[] = $arr[1];
            if($sum_cap < $sum_peo){
                $sum_cap = $sum_peo;
            }
        }else{
            if(in_array($arr[1], $a)){
                $sum_peo --;
            }else{
                $sum_cap ++;
            }
        }
    }
    echo $sum_cap."\n";


An array is sorted if it has no inversionsA Young BoyYou are given an array of $$$n$$$ positive integers $$$a_1,a_2,\ldots,a_n$$$. In one operation you do the following:   Choose any integer $$$x$$$.  For all $$$i$$$ such that $$$a_i = x$$$, do $$$a_i := 0$$$ (assign $$$0$$$ to $$$a_i$$$). Find the minimum number of operations required to sort the array in non-decreasing order.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). 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 second line of each test case contains $$$n$$$ positive integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le n$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print one integer — the minimum number of operations required to sort the array in non-decreasing order.

NoteIn the first test case, you can choose $$$x = 3$$$ for the operation, the resulting array is $$$[0, 0, 2]$$$.In the second test case, you can choose $$$x = 1$$$ for the first operation and $$$x = 3$$$ for the second operation, the resulting array is $$$[0, 0, 0, 0]$$$.

<?php
function read() {
  return trim(fgets($GLOBALS['file'])) ;
}
function readInt() {
  return (int) read() ;
}
function readStrs() {
  return explode(" ",read()) ;
}
function readIntArray() {
  return array_map('intval', readStrs());
}
function readAsArray() {
  return str_split(read()) ;
}
function puts($arg) {
  if($arg === true) print_r("true");
  elseif($arg === false) print_r("false");
  else {
    print_r($arg) ;
  }
  print_r("\n") ;
}
$file = (file_exists("input.txt")) ? fopen("input.txt","r") : STDIN ;

//-----------------------------------//

$t = readInt();
while($t--) {
    $n = readInt();
    $arr = readIntArray();
    $cul = -1 ;
    $mi = [] ;
    $ma = [];
    for($i=0;$i<$n;$i++) {
        if(!isset($mi[$arr[$i]])) {
            $mi[$arr[$i]] = $i ;
        }
    }
    for($i=0;$i<$n;$i++) {
        $ma[$arr[$i]] = $i ;
    }
    for($i=$n-2;$i>-1;$i--) {
        if($arr[$i] > $arr[$i+1]) {
            $cul = $i;
            break;
        }
    }
//    puts($mi);
    if($cul != -1) {
//        puts($cul);
        $here = $cul;
        $ele = $arr[$cul] ;
        for($i=$n-1;$i>$cul;$i--) {
            if($mi[$arr[$i]] <= $ma[$ele]) {
                $here = $i ;
                break ;
            }
        }
//        puts($here);
        $mew = [] ;
        for($i=0;$i<=$here;$i++) {
            $mew[] = $arr[$i] ;
        }
//        puts($mew);
        puts(count(array_unique($mew)));
    }
    else {
        puts(0);
    }
}

<?php
function read() {
  return trim(fgets($GLOBALS['file'])) ;
}
function readInt() {
  return (int) read() ;
}
function readStrs() {
  return explode(" ",read()) ;
}
function readIntArray() {
  return array_map('intval', readStrs());
}
function readAsArray() {
  return str_split(read()) ;
}
function puts($arg) {
  if($arg === true) print_r("true");
  elseif($arg === false) print_r("false");
  else {
    print_r($arg) ;
  }
  print_r("\n") ;
}
$file = (file_exists("input.txt")) ? fopen("input.txt","r") : STDIN ;

//-----------------------------------//

$t = readInt();
while($t--) {
    $n = readInt();
    $arr = readIntArray();
    $cul = -1 ;
    $mi = [] ;
    for($i=0;$i<$n;$i++) {
        if(!isset($mi[$arr[$i]])) {
            $mi[$arr[$i]] = $i ;
        }
    }
    for($i=$n-2;$i>-1;$i--) {
        if($arr[$i] > $arr[$i+1]) {
            $cul = $i;
            break;
        }
    }
//    puts($mi);
    if($cul != -1) {
//        puts($cul);
        $here = $cul;
        $ele = $arr[$cul] ;
        for($i=$n-1;$i>$cul;$i--) {
            if($mi[$arr[$i]] <= $mi[$ele]) {
                $here = $i ;
                break ;
            }
        }
//        puts($here);
        $mew = [] ;
        for($i=0;$i<=$here;$i++) {
            $mew[] = $arr[$i] ;
        }
//        puts($mew);
        puts(count(array_unique($mew)));
    }
    else {
        puts(0);
    }
}

<?php
function read() {
  return trim(fgets($GLOBALS['file'])) ;
}
function readInt() {
  return (int) read() ;
}
function readStrs() {
  return explode(" ",read()) ;
}
function readIntArray() {
  return array_map('intval', readStrs());
}
function readAsArray() {
  return str_split(read()) ;
}
function puts($arg) {
  if($arg === true) print_r("true");
  elseif($arg === false) print_r("false");
  else {
    print_r($arg) ;
  }
  print_r("\n") ;
}
$file = (file_exists("input.txt")) ? fopen("input.txt","r") : STDIN ;

//-----------------------------------//

$t = readInt() ;
while($t--) {
    $n = readInt() ;
    $arr = readIntArray();
    $dic = [];
    foreach ($arr as $e) {
       $dic[$e] = false;
    }
    $ans = 0 ;
    for($i=$n-2;$i>-1;$i--) {
        $curi = $arr[$i+1] ;
        $cur = $arr[$i];
        if(!$dic[$curi]) {
            if($cur > $curi) {
                $ans += 1 ;
                $dic[$cur] = true ;
            }
        }
        else {
            if(!$dic[$cur]) {
                $ans += 1;
                $dic[$cur] = true;
            }
        }
    }
    for($i=0;$i<$n-1;$i++) {
        $curi = $arr[$i+1] ;
        $cur = $arr[$i];
        if(!$dic[$cur] && $dic[$curi]) {
            $ans += 1 ;
            $dic[$curi] = true ;
        }
    }
    puts($ans);
}


Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one Morty. They're gathering in m groups. Each person can be in many groups and a group can contain an arbitrary number of members.Ricks and Mortys have registered online in these groups. So, a person can have joined a group more than once (developer of this website hadn't considered this possibility).  Summer from universe #1 knows that in each parallel universe (including hers) exactly one of Rick and Morty from that universe is a traitor and is loyal, but no one knows which one. She knows that we are doomed if there's a group such that every member in that group is a traitor (they will plan and destroy the world). Summer knows that if there's a possibility that world ends (there's a group where all members are traitors) she should immediately cancel this event. So she wants to know if she should cancel the event. You have to tell her yes if and only if there's at least one scenario (among all 2n possible scenarios, 2 possible scenarios for who a traitor in each universe) such that in that scenario the world will end.

The first line of input contains two integers n and m (1 ≤ n, m ≤ 104) — number of universes and number of groups respectively. The next m lines contain the information about the groups. i-th of them first contains an integer k (number of times someone joined i-th group, k > 0) followed by k integers vi, 1, vi, 2, ..., vi, k. If vi, j is negative, it means that Rick from universe number  - vi, j has joined this group and otherwise it means that Morty from universe number vi, j has joined it. Sum of k for all groups does not exceed 104.

In a single line print the answer to Summer's question. Print "YES" if she should cancel the event and "NO" otherwise.

NoteIn the first sample testcase, 1st group only contains the Rick from universe number 3, so in case he's a traitor, then all members of this group are traitors and so Summer should cancel the event.

<?php
list($n, $m) = explode(' ', trim(fgets(STDIN)));
for($i = 0; $i < $m; $i++) {
    $b = false;
    $x = array();
    $a = explode(' ', trim(fgets(STDIN)));
    for($j = 1; $j < count($a); $j++) {
        $x[$a[$j]] = 1;
        if(isset($x[$a[$j]]) && isset($x[-$a[$j]])) {
            $b = true;
        }
    }
    if(!$b) {
        echo "YES";
        exit;
    }
}
echo "NO";

<?php
list($n, $m) = explode(' ', trim(fgets(STDIN)));
$b = false;
for($i = 0; $i < $m; $i++) {
    $x = array();
    $a = explode(' ', trim(fgets(STDIN)));
    for($j = 0; $j < count($a); $j++) {
        $x[$a[$j]] = 1;
    }
    for($j = 1; $j <= $n; $j++) {
        if(isset($x[$j]) && isset($x[-$j])) {
            $b = true;
        }
    }
    if(!$b) {
        echo "YES";
        exit;
    }
}
echo "NO";

<?php
list($n, $m) = explode(' ', trim(fgets(STDIN)));
for($i = 0; $i < $m; $i++) {
    $b = false;
    $x = array();
    $a = explode(' ', trim(fgets(STDIN)));
    for($j = 0; $j < count($a); $j++) {
        $x[$a[$j]] = 1;
        if(isset($x[$a[$j]]) && isset($x[-$a[$j]])) {
            $b = true;
        }
    }
    if(!$b) {
        echo "YES";
        exit;
    }
}
echo "NO";


Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2wi pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.  Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2a1, ..., 2ak if and only if there exists a non-negative integer x such that 2a1 + 2a2 + ... + 2ak = 2x, i. e. the sum of those numbers is a power of two.Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.

The first line of input contains integer n (1 ≤ n ≤ 106), the number of weights. The second line contains n integers w1, ..., wn separated by spaces (0 ≤ wi ≤ 106 for each 1 ≤ i ≤ n), the powers of two forming the weights values.

Print the minimum number of steps in a single line.

NoteIn the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two.

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$n = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
$aArray = array_count_values($aArray);
$result = 0;
for ($i = 0; $i <= 1000200; $i++) {
    if (!isset($aArray[$i])) {
        continue;
    }
    if (isset($aArray[$i+1])) {
        $aArray[$i + 1] += ($aArray[$i] - $aArray[$i] % 2) / 2;
    }else{
        $aArray[$i + 1] = ($aArray[$i] - $aArray[$i] % 2) / 2;
    }
    $result += $aArray[$i] % 2;
}

echo $result;


You are given two binary strings $$$a$$$ and $$$b$$$ of the same length. You can perform the following two operations on the string $$$a$$$:  Swap any two bits at indices $$$i$$$ and $$$j$$$ respectively ($$$1 \le i, j \le n$$$), the cost of this operation is $$$|i - j|$$$, that is, the absolute difference between $$$i$$$ and $$$j$$$.  Select any arbitrary index $$$i$$$ ($$$1 \le i \le n$$$) and flip (change $$$0$$$ to $$$1$$$ or $$$1$$$ to $$$0$$$) the bit at this index. The cost of this operation is $$$1$$$. Find the minimum cost to make the string $$$a$$$ equal to $$$b$$$. It is not allowed to modify string $$$b$$$.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the length of the strings $$$a$$$ and $$$b$$$. The second and third lines contain strings $$$a$$$ and $$$b$$$ respectively. Both strings $$$a$$$ and $$$b$$$ have length $$$n$$$ and contain only '0' and '1'.

Output the minimum cost to make the string $$$a$$$ equal to $$$b$$$.

NoteIn the first example, one of the optimal solutions is to flip index $$$1$$$ and index $$$3$$$, the string $$$a$$$ changes in the following way: "100" $$$\to$$$ "000" $$$\to$$$ "001". The cost is $$$1 + 1 = 2$$$.The other optimal solution is to swap bits and indices $$$1$$$ and $$$3$$$, the string $$$a$$$ changes then "100" $$$\to$$$ "001", the cost is also $$$|1 - 3| = 2$$$.In the second example, the optimal solution is to swap bits at indices $$$2$$$ and $$$3$$$, the string $$$a$$$ changes as "0101" $$$\to$$$ "0011". The cost is $$$|2 - 3| = 1$$$.


You want to perform the combo on your opponent in one popular fighting game. The combo is the string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in $$$s$$$. I.e. if $$$s=$$$"abca" then you have to press 'a', then 'b', 'c' and 'a' again.You know that you will spend $$$m$$$ wrong tries to perform the combo and during the $$$i$$$-th try you will make a mistake right after $$$p_i$$$-th button ($$$1 \le p_i < n$$$) (i.e. you will press first $$$p_i$$$ buttons right and start performing the combo from the beginning). It is guaranteed that during the $$$m+1$$$-th try you press all buttons right and finally perform the combo.I.e. if $$$s=$$$"abca", $$$m=2$$$ and $$$p = [1, 3]$$$ then the sequence of pressed buttons will be 'a' (here you're making a mistake and start performing the combo from the beginning), 'a', 'b', 'c', (here you're making a mistake and start performing the combo from the beginning), 'a' (note that at this point you will not perform the combo because of the mistake), 'b', 'c', 'a'.Your task is to calculate for each button (letter) the number of times you'll press it.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 2 \cdot 10^5$$$) — the length of $$$s$$$ and the number of tries correspondingly. The second line of each test case contains the string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. The third line of each test case contains $$$m$$$ integers $$$p_1, p_2, \dots, p_m$$$ ($$$1 \le p_i < n$$$) — the number of characters pressed right during the $$$i$$$-th try. It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ both does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$, $$$\sum m \le 2 \cdot 10^5$$$). It is guaranteed that the answer for each letter does not exceed $$$2 \cdot 10^9$$$.

For each test case, print the answer — $$$26$$$ integers: the number of times you press the button 'a', the number of times you press the button 'b', $$$\dots$$$, the number of times you press the button 'z'.

3
4 2
abca
1 3
10 5
codeforces
2 8 3 2 9
26 10
qwertyuioplkjhgfdsazxcvbnm
20 10 1 2 3 5 10 5 9 4

NoteThe first test case is described in the problem statement. Wrong tries are "a", "abc" and the final try is "abca". The number of times you press 'a' is $$$4$$$, 'b' is $$$2$$$ and 'c' is $$$2$$$.In the second test case, there are five wrong tries: "co", "codeforc", "cod", "co", "codeforce" and the final try is "codeforces". The number of times you press 'c' is $$$9$$$, 'd' is $$$4$$$, 'e' is $$$5$$$, 'f' is $$$3$$$, 'o' is $$$9$$$, 'r' is $$$3$$$ and 's' is $$$1$$$.

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
$chars=[];

for ($k = 0; $k < $t; $k++) {
    for ($i='a';$i<'z';$i++)
    {
        $chars[$i]=0;
    }
    $chars['z']=0;
    $h=trim(fgets($handle));
    $h=explode(' ',$h);
    $n=$h[0];$m=$h[1];
    $str=trim(fgets($handle));
    $arr=trim(fgets($handle));
    $arr=explode(' ',$arr);

    for ($i=0;$i<$n;$i++)
    {
        $chars[$str[$i]]+=1;
    }
    $new=[];$count=0;
    for($i=0;$i<$m;$i++)
    {
        if(isset($new[$arr[$i]]))
        $new[$arr[$i]]+=1;
        else
            $new[$arr[$i]]=1;

        $count++;
    }
    for ($i=0;$i<$n;$i++)
    {
        $chars[$str[$i]]+=$count;
        if(isset($new[$i+1]))
        {
            $count-=$new[$i+1];
            $new[$i+1]=0;
        }
    }
    foreach ($chars as $b=>$v)
    {
        echo $v." ";
    }
    echo "\n";
}