Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally?

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student.

Print exactly one integer — the maximum number of students that can get a favorite drink.

NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth).

<?php
list($n,$k) = explode(' ', trim(fgets(STDIN)));
$aArrays = [];
for ($i = 0; $i < $n; $i++){
    $aArrays[$i] = trim(fgets(STDIN));
}
$aArrays = array_count_values($aArrays);
$iS = 0;
foreach ($aArrays as $sK => $sV){
    $iS += floor($sV % 2);
}
echo $n - floor($iS/2);

<?php
list($n,$k) = explode(' ', trim(fgets(STDIN)));
$aArrays = [];
$aTest = [];
for ($i = 0; $i < $n; $i++){
    $aArrays[$i] = trim(fgets(STDIN));
}
$aArrays = array_count_values($aArrays);
arsort($aArrays);
$iCount = $n;
foreach ($aArrays as $sK => $sV){
    if($sV % 2 == 0){
        $n = $n - $sV;
    } else {
        if($n > $sV){
            $n = $n - ($sV + 1);
        } else {
            $n = $sV -  $n;
        }
    }
}

echo $iCount - $n;

<?php
list($n,$k) = explode(' ', trim(fgets(STDIN)));
$aArrays = [];
for ($i = 0; $i < $n; $i++){
    $aArrays[$i] = trim(fgets(STDIN));
}
$aArrays = array_count_values($aArrays);
$iS = 0;
foreach ($aArrays as $sK => $sV){
    $iS += floor($sV % 2);
}
echo $n - $iS/2;


A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Restore the non-empty good string with minimum length. If several such strings exist, restore lexicographically minimum string. If there are no good strings, print "NO" (without quotes).A substring of a string is a contiguous subsequence of letters in the string. For example, "ab", "c", "abc" are substrings of string "abc", while "ac" is not a substring of that string.The number of occurrences of a substring in a string is the number of starting positions in the string where the substring occurs. These occurrences could overlap.String a is lexicographically smaller than string b, if a is a prefix of b, or a has a smaller letter at the first position where a and b differ.

The first line contains integer n (1 ≤ n ≤ 105) — the number of strings in the set. Each of the next n lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct. The total length of the strings doesn't exceed 105.

Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings.

NoteOne can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum.


You are given a table $$$a$$$ of size $$$n \times m$$$. We will consider the table rows numbered from top to bottom from $$$1$$$ to $$$n$$$, and the columns numbered from left to right from $$$1$$$ to $$$m$$$. We will denote a cell that is in the $$$i$$$-th row and in the $$$j$$$-th column as $$$(i, j)$$$. In the cell $$$(i, j)$$$ there is written a number $$$(i - 1) \cdot m + j$$$, that is $$$a_{ij} = (i - 1) \cdot m + j$$$.A turtle initially stands in the cell $$$(1, 1)$$$ and it wants to come to the cell $$$(n, m)$$$. From the cell $$$(i, j)$$$ it can in one step go to one of the cells $$$(i + 1, j)$$$ or $$$(i, j + 1)$$$, if it exists. A path is a sequence of cells in which for every two adjacent in the sequence cells the following satisfies: the turtle can reach from the first cell to the second cell in one step. A cost of a path is the sum of numbers that are written in the cells of the path.  For example, with $$$n = 2$$$ and $$$m = 3$$$ the table will look as shown above. The turtle can take the following path: $$$(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3)$$$. The cost of such way is equal to $$$a_{11} + a_{12} + a_{13} + a_{23} = 12$$$. On the other hand, the paths $$$(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 1)$$$ and $$$(1, 1) \rightarrow (1, 3)$$$ are incorrect, because in the first path the turtle can't make a step $$$(2, 2) \rightarrow (2, 1)$$$, and in the second path it can't make a step $$$(1, 1) \rightarrow (1, 3)$$$.You are asked to tell the turtle a minimal possible cost of a path from the cell $$$(1, 1)$$$ to the cell $$$(n, m)$$$. Please note that the cells $$$(1, 1)$$$ and $$$(n, m)$$$ are a part of the way.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The description of test cases follows. A single line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^4$$$) — the number of rows and columns of the table $$$a$$$ respectively.

For each test case output a single integer — a minimal possible cost of a path from the cell $$$(1, 1)$$$ to the cell $$$(n, m)$$$.

NoteIn the first test case the only possible path consists of a single cell $$$(1, 1)$$$.The path with the minimal cost in the second test case is shown in the statement.In the fourth and the fifth test cases there is only one path from $$$(1, 1)$$$ to $$$(n, m)$$$. Both paths visit every cell in the table.

<?php

$t = trim(fgets(STDIN));

for ($t1=1; $t1<=$t; $t1++) {
    list($n, $m) = explode(' ', trim(fgets(STDIN)));

    $iSumJ = 0;
    for ($j=1; $j <= $m; $j++) {
        $iSumJ += $j;
    }

    $iSumI = 0;
    for ($i=1; $i<= $n; $i++) {
        $iSumI += $i * $m;
    }
    echo $iSumI + $iSumJ - $m . PHP_EOL;

}

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

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

function solve()
{
     list($n,$m) = IO::getArray();
     $max = 0;

     $ans = 0;
     for($i=1; $i<=$m; $i++) {
          $ans += $i;
     }
     $ti = 0;
     for($i=2; $i<=$n; $i++) {
         $ti += $i;
     }
     $ans = bcadd(bcmul($m, $ti), $ans);

       IO::pr($ans);

}

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

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


Polycarp is sad — New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!For example, if you provide $$$3$$$ red, $$$3$$$ green and $$$3$$$ blue lamps, the resulting garland can look like this: "RGBRBGBGR" ("RGB" being the red, green and blue color, respectively). Note that it's ok to have lamps of the same color on the ends of the garland.However, if you provide, say, $$$1$$$ red, $$$10$$$ green and $$$2$$$ blue lamps then the store workers won't be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of sets of lamps Polycarp has bought. Each of the next $$$t$$$ lines contains three integers $$$r$$$, $$$g$$$ and $$$b$$$ ($$$1 \le r, g, b \le 10^9$$$) — the number of red, green and blue lamps in the set, respectively.

Print $$$t$$$ lines — for each set of lamps print "Yes" if the store workers can build a garland from them and "No" otherwise.

NoteThe first two sets are desribed in the statement.The third set produces garland "RBRG", for example.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = explode(" ", trim(fgets(STDIN)));
     rsort($b);
     if($b[0] - ($b[1] + $b[2]) <= 1)
     {
          print "Yes\n";
     }
     else
     {
          print "No\n";
     }
}
?>

<?php
class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

$sc = new Scanner();
$rows_count = $sc->nextInt();

for($i = 0; $i < $rows_count; $i++)
{
    $R = $sc->nextInt();
    $G = $sc->nextInt();
    $B = $sc->nextInt();
    $RGB = $R + $G + $B;
    if($RGB % 2 == 1)
    {
        if($RGB / 2 + 1 < $R ||$RGB / 2 + 1 < $G || $RGB / 2 + 1 < $B)
        {
            out::println('No');
        }
        else
        {
            out::println('Yes');
        }
    }
    else
    {
        if($RGB / 2 < $R ||$RGB / 2 < $G || $RGB / 2 < $B)
        {
            out::println('No');
        }
        else
        {
            out::println('Yes');
        }
    }
}

<?php
/**
 * Created by PhpStorm.
 * User: wanghaixia01
 * Date: 2020/1/6
 * Time: 14:22
 */

class NewYearGarland
{
    public function main(){
        $num = trim(fgets(STDIN));//接收用户输入
        for ($i = 0; $i < $num; $i++){
            $arr = explode(" ", trim(fgets(STDIN)));//接收用户输入
            $steps = $this->judgeOk($arr);
            fwrite(STDOUT, $steps."\n");
        }
    }
    //规则：保证相邻彩灯颜色不同，并使用完所有彩灯，然后构成花环返回true，否则返回false
    //排列组合问题：取两个小的颜色彩灯数，计算两者产生的间隙数，若间隙数大于等于第三个颜色彩灯数， 则返回true，否则返回false
    public function judgeOk($arr){
        rsort($arr);
        $maxGaps = $arr[1] + $arr[2] + 1;
        $minGaps = $arr[1] - $arr[2] - 1;
        if($maxGaps >= $arr[0] && $minGaps <= $arr[0]){
           return "Yes";
        }
        return "No";
    }
}

$nyg = new NewYearGarland();
$b = $nyg->main();

<?php

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

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

//$input = TXTIN;
$input = STDIN;

//$output = TXTOUT;
$output = STDOUT;

function foo($r, $g, $b)
{
    $rt = $r - ($g + $b);
    $gt = $g - ($r + $b);
    $bt = $b - ($r + $g);

    return ($rt >= 2) || ($gt >= 2) || ($bt >= 2);
}

$r = 0;

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

for ($i = 0; $i < $t; ++$i) {
    list($r, $g, $b) = fscanf($input, "%d %d %d\n");

    $r = (!foo($r, $g, $b) ? 'Yes' : 'No') . PHP_EOL;

    fwrite($output, $r);
}

<?php
    $t = trim(fgets(STDIN));
    for ($test = 0; $test < $t; $test++) {
        $res = '';
        $str = trim(fgets(STDIN));
        $aR = explode(" ", $str);
        $r = $aR[0];
        $q = $aR[1];
        $b = $aR[2];

        $max = max($aR);

        if ((array_sum($aR) - $max) + 1 >= $max) {
            echo "Yes\n";
        } else {
            echo "No\n";
        }

    }
?>

<?php
$o = trim(fgets(STDIN));
for($j = 0; $j < $o; $j++){
    $u = explode(" ",trim(fgets(STDIN)));
    sort($u);
    $b = true;
    if(($u[2] - $u[1] - $u[0]) > 1){
        $b = false;
    }
   if($b){
       echo "YES\n";
   } else {
       echo "NO\n";
   }

}

<?php
    //获取第一个标准输入，case的数量
    $nums = trim(fgets(STDIN));
    for($n = 0; $n < $nums; $n++){
        //获取接下来每一组的case
        $arr = explode(' ',trim(fgets(STDIN)));
        rsort($arr);
        echo ($arr[0] - $arr[1] <= $arr[2] + 1) ? "Yes\n" : "No\n";
    }
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = explode(" ", trim(fgets(STDIN)));
     if(max($b) - min($b) <= 2)
     {
          print "Yes\n";
     }
     else
     {
          print "No\n";
     }
}
?>

<?php
class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

$sc = new Scanner();
$rows_count = $sc->nextInt();

for($i = 0; $i < $rows_count; $i++)
{
    $R = $sc->nextInt();
    $G = $sc->nextInt();
    $B = $sc->nextInt();
    out::println($R);
    out::println($G);
    out::println($B);
    $RGB = $R + $G + $B;
    if($RGB % 2 == 1)
    {
        if($RGB / 2 < $R ||$RGB / 2 < $G || $RGB / 2 < $B)
        {
            out::println('No');
        }
        else
        {
            out::println('Yes');
        }
    }
    else
    {
        if($RGB / 2 < $R ||$RGB / 2 < $G || $RGB / 2 < $B)
        {
            out::println('No');
        }
        else
        {
            out::println('Yes');
        }
    }
}

<?php
class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

$sc = new Scanner();
$rows_count = $sc->nextInt();

for($i = 0; $i < $rows_count; $i++)
{
    $R = $sc->nextInt();
    $G = $sc->nextInt();
    $B = $sc->nextInt();
    out::println($R);
    out::println($G);
    out::println($B);
    $RGB = $R + $G + $B;
    if($RGB % 2 == 1)
    {
        if($RGB / 2 + 1 < $R ||$RGB / 2 + 1 < $G || $RGB / 2 + 1 < $B)
        {
            out::println('No');
        }
        else
        {
            out::println('Yes');
        }
    }
    else
    {
        if($RGB / 2 < $R ||$RGB / 2 < $G || $RGB / 2 < $B)
        {
            out::println('No');
        }
        else
        {
            out::println('Yes');
        }
    }
}

<?php
/**
 * Created by PhpStorm.
 * User: wanghaixia01
 * Date: 2020/1/6
 * Time: 14:22
 */

class NewYearGarland
{
    public function main(){
        $num = trim(fgets(STDIN));//接收用户输入
        for ($i = 0; $i < $num; $i++){
            $arr = explode(" ", trim(fgets(STDIN)));//接收用户输入
            $steps = $this->judgeOk($arr);
            fwrite(STDOUT, $steps."\n");
        }
    }
    //规则：保证相邻彩灯颜色不同，并使用完所有彩灯，然后构成花环返回true，否则返回false
    //排列组合问题：取两个小的颜色彩灯数，计算两者产生的间隙数，若间隙数大于等于第三个颜色彩灯数， 则返回true，否则返回false
    public function judgeOk($arr){
        rsort($arr);
        var_dump($arr);
        $maxGaps = $arr[1] + $arr[2] + 1;
        $minGaps = $arr[1] - $arr[2] - 1;
        if($maxGaps >= $arr[0] && $minGaps <= $arr[0]){
           return "Yes";
        }
        return "No";
    }
}

$nyg = new NewYearGarland();
$b = $nyg->main();

<?php

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

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

//$input = TXTIN;
$input = STDIN;

//$output = TXTOUT;
$output = STDOUT;

function foo($r, $g, $b)
{
    $rg = $r - $g;
    $rb = $r - $b;
    $bg = $g - $b;

    return
        ($rg === 0 || $rg === 1) ||
        ($rb === 0 || $rb === 1) ||
        ($bg === 0 || $bg === 1);
}

$r = 0;

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

for ($i = 0; $i < $t; ++$i) {
    list($r, $g, $b) = fscanf($input, "%d %d %d\n");

    $r = (foo($r, $g, $b) ? 'Yes' : 'No') . PHP_EOL;

    fwrite($output, $r);
}

<?php
$o = trim(fgets(STDIN));
for($j = 0; $j < $o; $j++){
    $u = explode(" ",trim(fgets(STDIN)));
    sort($u);
    $b = true;
    if(($u[2] - $u[1]) > 2){
        $b = false;
    }
    if(($u[1] - $u[0]) > 2){
        $b = false;
    }
   if($b){
       echo "YES\n";
   } else {
       echo "NO\n";
   }

}


Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.Let's assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 + 0 + 9 + 8 = 21. Then the digital root of number n equals to:   dr(n) = S(n), if S(n) < 10;  dr(n) = dr( S(n) ), if S(n) ≥ 10. For example, dr(4098)  =  dr(21)  =  3.Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that dr(n)  =  S( S( S( S(n) ) ) ) (n ≤ 101000).Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers k and d, find the number consisting of exactly k digits (the leading zeroes are not allowed), with digital root equal to d, or else state that such number does not exist.

The first line contains two integers k and d (1 ≤ k ≤ 1000; 0 ≤ d ≤ 9).

In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist. The chosen number must consist of exactly k digits. We assume that number 0 doesn't contain any leading zeroes.

NoteFor the first test sample dr(5881)  =  dr(22)  =  4.For the second test sample dr(36172)  =  dr(19)  =  dr(10)  =  1.

<?php
$n = trim(fgets(STDIN));
$data = explode(' ', $n);
$k = (int) $data[0];
$d = (int) $data[1];
if ($k == 1 && $d == 0) {
    echo '0';
} else if ($k > 1 && $d == 0) {
    echo 'No solution';
} else {
    echo $d;
    for ($i = 0; $i < $k-1; $i++) {
        echo 0;
    }
}

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

$temp = explode(" ", $str);

$k = $temp[0];
$d = $temp[1];

$n = 1;
if ($d ==0 && $k>1) {
    print "No solution";
} else {
if ($k>3) {

    if ($k%2 == 0) {
        for ($i = 0; $i <= $k-2; $i++) {
            $n = 9-$n;
            print $n;
        }
        if ($d == 9) {
            print "1";
        } else {
            print 1+$d;
        }
    } else {
        for ($i = 0; $i <= $k-2; $i++) {
            $n = 9-$n;
            print $n;
        }
        print $d;
    }

} else {
    switch ($k) {
        case 1:
            print $d;
            break;
        case 2:
            if ($d ==9) {
                print "81";
            } else {
                print "8".$d+1;
            }
            break;
        case 3:
            print "81".$d;
    }
}
}

<?php
$n = trim(fgets(STDIN));
$data = explode(' ', $n);
$k = (int) $data[0];
$d = (int) $data[1];
if ($k == 1 && $d == 0) {
    echo '0';
} if ($k > 1 && $d == 0) {
    echo 'No solution';
} else {
    echo $d . str_repeat(0, $k - 1);
}

<?php
$n = trim(fgets(STDIN));
$data = explode(' ', $n);
$k = (int) $data[0];
$d = (int) $data[1];
if ($k == 1 && $d == 0) {
    echo '0';
} if ($k > 1 && $d == 0) {
    echo 'No solution';
} else {
    echo $k . str_repeat(0, $d - 1);
}


You are given a positive integer $$$n$$$. Your task is to find any three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$0 \le a, b, c \le 10^9$$$) for which $$$(a\oplus b)+(b\oplus c)+(a\oplus c)=n$$$, or determine that there are no such integers.Here $$$a \oplus b$$$ denotes the bitwise XOR of $$$a$$$ and $$$b$$$. For example, $$$2 \oplus 4 = 6$$$ and $$$3 \oplus 1=2$$$.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following lines contain the descriptions of the test cases. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$).

For each test case, print any three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$0 \le a, b, c \le 10^9$$$) for which $$$(a\oplus b)+(b\oplus c)+(a\oplus c)=n$$$. If no such integers exist, print $$$-1$$$.

NoteIn the first test case, $$$a=3$$$, $$$b=3$$$, $$$c=1$$$, so $$$(3 \oplus 3)+(3 \oplus 1) + (3 \oplus 1)=0+2+2=4$$$.In the second test case, there are no solutions.In the third test case, $$$(2 \oplus 4)+(4 \oplus 6) + (2 \oplus 6)=6+2+4=12$$$.


Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!

The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.

If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.

NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.

<?php
$a = trim(fgets(STDIN));
$b = 0;
$c = 0;
for($x = 1; $x <= $a; $x++)
{
     list($d, $e) = explode(" ", trim(fgets(STDIN)));
     if($d > $e)
     {
          $b++;
     }
     elseif($d < $e)
     {
          $c++;
     }
}
if($b < $c)
{
     print "Chris";
}
elseif($b == $c)
{
     print "Friendship is magic!^^";
}
elseif($b > $c)
{
     print "Mishka";
}
?>

<?php
$n = trim(fgets(STDIN));
$m = 0;
$c = 0;
for ($i = 1; $i <= $n; $i++) {
    $r = explode(" ", trim(fgets(STDIN)));
    if ($r[0] > $r[1]) {
        $m++;
    } elseif ($r[1] > $r[0]) {
        $c++;
    }
}
if ($m > $c) {
    print "Mishka";
} elseif ($c > $m) {
    print "Chris";
} else {
    print "Friendship is magic!^^";
}
?>

<?php
$i = intval(fgets(STDIN));
$o = 0;
while($i-- && ($n = explode(' ', trim(fgets(STDIN))))) $o += $n[0]<$n[1]|-($n[0]>$n[1]);
echo $o == 0 ? 'Friendship is magic!^^' : ($o < 0 ? 'Mishka' : 'Chris');

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

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	$n = readNum($f);
	$counter = array(
		'm' => 0, 'c' => 0,
	);
	for ($i = 0; $i < $n; $i++) {
		list($m, $c) = readStringExplodeNum($f, ' ', true);
		if ($m > $c) {
			$counter['m'] ++;
		} elseif ($m < $c) {
			$counter['c'] ++;
		}
	}
	if ($counter['m'] > $counter['c']) {
		echo 'Mishka';
	} elseif ($counter['m'] < $counter['c']) {
		echo 'Chris';
	} else {
		echo 'Friendship is magic!^^';
	}
	/* / end body */
}

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

<?php
fscanf(STDIN,"%d",$n);
$mas=0;
$cha=0;
for($i=0;$i<$n;$i++){
	fscanf(STDIN,"%d %d",$m[$i],$c[$i]);
	if($m[$i]>$c[$i])
	{
		$mas++;
	}
	elseif ($m[$i]<$c[$i]) {
		$cha++;
		# code...
	}
	else{
		$mas++;
	   $cha++;
	}

}
	if($mas>$cha)
		echo "Mishka";
	elseif ($mas<$cha) {
		echo "Chris";
	}
	else
		echo "Friendship is magic!^^";

<?php
fscanf(STDIN, "%d", $n);
$a = 0;
$b = 0;
for($i=0;$i<$n;$i++){
    fscanf(STDIN, "%d %d", $x, $y);
    if ($x > $y)
        $a++;
    else if ($x < $y)
        $b++;
}
if ($a > $b)
    echo "Mishka";
else if ($a < $b)
    echo "Chris";
else
    echo "Friendship is magic!^^";
?>

<?php

$count = (int) fgets(STDIN);

$mishkaPoint = 0;
$chrisPoint  = 0;

for ($i = 0; $i < $count; $i++) {
    $rawQInfo = rtrim(fgets(STDIN));
    $rawInfo = explode(' ', $rawQInfo);

    $first = (int) $rawInfo[0];
    $second = (int) $rawInfo[1];

    if ($first > $second) {
        $mishkaPoint++;
    } elseif ($first < $second) {
        $chrisPoint++;
    }
}

if ($mishkaPoint > $chrisPoint) {
    echo 'Mishka';
} elseif ($mishkaPoint < $chrisPoint) {
    echo 'Chris';
} else {
    echo 'Friendship is magic!^^';
}

echo PHP_EOL;

<?php
	fscanf(STDIN, "%d", $n);
	$m = $c = 0;
	for($i = 0; $i < $n; $i++)
	{
		fscanf(STDIN, "%d%d", $a, $b);
		$m += $a > $b;
		$c += $b > $a;
	}
	if($m > $c) echo "Mishka";
	else if($m < $c) echo "Chris";
	else echo "Friendship is magic!^^";
?>

//703a
<?php
$n = readline();
$a = 0;
$b = 0;
for ($i = 0; $i < $n; $i++) {
	$p = explode(' ', readline());
	if ($p[0] > $p[1]) {
		$a++;
	}
	elseif ($p[0] < $p[1]) {
		$b++;
	}
}
if ($a > $b) {
	echo 'Mishka';
}
elseif ($a < $b) {
	echo 'Chris';
}
else echo 'Friendship is magic!^^';

<?php
$n = trim(fgets(STDIN));
$m = 0;
$c = 0;
for ($i = 1; $i <= $n; $i++) {
    $r = explode(" ", trim(fgets(STDIN)));
    $m += $r[0];
    $c += $r[1];
}
if ($m > $c) {
    print "Mishka";
} elseif ($c > $m) {
    print "Chris";
} else {
    print "Friendship is magic!^^";
}
?>

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

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	$n = readNum($f);
	$counter = array(
		'm' => 0, 'c' => 0,
	);
	for ($i = 0; $i < $n; $i++) {
		list($m, $c) = readStringExplodeNum($f, ' ', true);
		if ($m > $c) {
			$counter['m'] ++;
		} else {
			$counter['c'] ++;
		}
	}
	if ($counter['m'] > $counter['c']) {
		echo 'Mishka';
	} elseif ($counter['m'] < $counter['c']) {
		echo 'Chris';
	} else {
		echo 'Friendship is magic!^^';
	}
	/* / end body */
}

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

<?php
fscanf(STDIN, "%d", $n);
$a = 0;
$b = 0;
for($i=0;$i<$n;$i++){
    fscanf(STDIN, "%d", $x);
    fscanf(STDIN, "%d", $y);
    if ($x > $y)
        $a++;
    else if ($x < $y)
        $b++;
}
if ($a > $b)
    echo "Mishka";
else if ($a < $b)
    echo "Chris";
else
    echo "Friendship is magic!^^";
?>

<?php
fscanf(STDIN, "%d", $n);
$a = 0;
$b = 0;
for($i=0;$i<$n;$i++){
    $x = trim(fgets(STDIN));
    $y = trim(fgets(STDIN));
    if ($x > $y)
        $a++;
    else if ($x < $y)
        $b++;
}
if ($a > $b)
    echo "Mishka";
else if ($a < $b)
    echo "Chris";
else
    echo "Friendship is magic!^^";
?>


Heidi and Doctor Who hopped out of the TARDIS and found themselves at EPFL in 2018. They were surrounded by stormtroopers and Darth Vader was approaching. Miraculously, they managed to escape to a nearby rebel base but the Doctor was very confused. Heidi reminded him that last year's HC2 theme was Star Wars. Now he understood, and he's ready to face the evils of the Empire!The rebels have $$$s$$$ spaceships, each with a certain attacking power $$$a$$$.They want to send their spaceships to destroy the empire bases and steal enough gold and supplies in order to keep the rebellion alive.The empire has $$$b$$$ bases, each with a certain defensive power $$$d$$$, and a certain amount of gold $$$g$$$.A spaceship can attack all the bases which have a defensive power less than or equal to its attacking power.If a spaceship attacks a base, it steals all the gold in that base.The rebels are still undecided which spaceship to send out first, so they asked for the Doctor's help. They would like to know, for each spaceship, the maximum amount of gold it can steal.

The first line contains integers $$$s$$$ and $$$b$$$ ($$$1 \leq s, b \leq 10^5$$$), the number of spaceships and the number of bases, respectively. The second line contains $$$s$$$ integers $$$a$$$ ($$$0 \leq a \leq 10^9$$$), the attacking power of each spaceship. The next $$$b$$$ lines contain integers $$$d, g$$$ ($$$0 \leq d \leq 10^9$$$, $$$0 \leq g \leq 10^4$$$), the defensive power and the gold of each base, respectively.

Print $$$s$$$ integers, the maximum amount of gold each spaceship can steal, in the same order as the spaceships are given in the input.

NoteThe first spaceship can only attack the first base.The second spaceship can attack the first and third bases.The third spaceship can attack the first, second and third bases.


You are given some Tetris field consisting of $$$n$$$ columns. The initial height of the $$$i$$$-th column of the field is $$$a_i$$$ blocks. On top of these columns you can place only figures of size $$$2 \times 1$$$ (i.e. the height of this figure is $$$2$$$ blocks and the width of this figure is $$$1$$$ block). Note that you cannot rotate these figures.Your task is to say if you can clear the whole field by placing such figures.More formally, the problem can be described like this:The following process occurs while at least one $$$a_i$$$ is greater than $$$0$$$:  You place one figure $$$2 \times 1$$$ (choose some $$$i$$$ from $$$1$$$ to $$$n$$$ and replace $$$a_i$$$ with $$$a_i + 2$$$);  then, while all $$$a_i$$$ are greater than zero, replace each $$$a_i$$$ with $$$a_i - 1$$$. And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$2t$$$ lines describe test cases. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of columns in the Tetris field. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the initial height of the $$$i$$$-th column of the Tetris field.

For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise.

NoteThe first test case of the example field is shown below:Gray lines are bounds of the Tetris field. Note that the field has no upper bound.One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes $$$[2, 0, 2]$$$. Then place the figure in the second column and after the second step of the process, the field becomes $$$[0, 0, 0]$$$.And the second test case of the example field is shown below:It can be shown that you cannot do anything to end the process.In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes $$$[0, 2]$$$. Then place the figure in the first column and after the second step of the process, the field becomes $$$[0, 0]$$$.In the fourth test case of the example, place the figure in the first column, then the field becomes $$$[102]$$$ after the first step of the process, and then the field becomes $$$[0]$$$ after the second step of the process.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = explode(" ", trim(fgets(STDIN)));
    $c = array_unique($c);
    sort($c);
    if(count($c) == 1)
    {
         print "YES\n";
    }
    else
    {
         $d = array();
         for($y = 0; $y < count($c) - 1; $y++)
         {
              $d[$y] = $c[$y + 1] - $c[$y];
         }
         $d = array_unique($d);
         sort($d);
         $e = 0;
         for($y = 0; $y < count($d); $y++)
         {
              if($d[$y] % 2 == 1)
              {
                   $e = 1;
                   break;
              }
         }
         if($e == 0)
         {
              print "YES\n";
         }
         else
         {
              print "NO\n";
         }
    }
}
?>

<?php
    $j = trim(fgets(STDIN));
    for($i = 0; $i < $j; $i++){
        $n = trim(fgets(STDIN));
        $a = explode(' ', trim(fgets(STDIN)));
        sort($a);
        $bo = true;
        if($n < 2){
            echo "YES\n";
            continue;
        }
        for($x = 0; $x < $n - 1; $x++){
            if(($a[$x+1] - $a[$x]) % 2 != 0){
                $bo = false;
                break;
            }
        }
        if($bo){
            echo "YES\n";
        } else {
            echo "NO\n";
        }

    }

<?php

	function check($a) {
		$pos = false;
		for ($i = 0; $i < count($a); $i++)
			if ($a[$i] == 0)
				$pos = true;
		return $pos;
	}

	$t = trim(fgets(STDIN));

	$fans = '';

	for ($o = 0; $o < $t; $o++) {
		$n = trim(fgets(STDIN));
		$a = explode(" ", trim(fgets(STDIN)));

		while (!check($a)) {
			for ($i = 0; $i < $n; $i++)
				$a[$i]--;
		}

		$ans = 'YES';
		for ($i = 0; $i < $n; $i++)
			if ($a[$i] % 2 != 0)
				$ans = "NO";

		$fans .= $ans."\n";

	}
	print $fans;
?>

<?php
$in = fopen("php://stdin", "r"); //or simply $in = STDIN;
$t = trim(fgets($in));

for($i = 0;$i <$t; $i++)
{
    $min = PHP_INT_MAX;
    $n = trim(fgets($in));
    $foo = explode(" ", trim(fgets($in)));
    for($j=0; $j < $n; $j++)
        $min = min($foo[$j],$min);

    for($j=0; $j < $n ; $j++)
    {
        $foo[$j] = $foo[$j] - $min;
        if( ($foo[$j]&1) != 0)
        {
          print "NO\n";
          continue 2;
        }

    }
    print "YES\n";
}
?>

<?php
$t = trim(fgets(STDIN));
for($i = 0;$i <$t; $i++)
{
    $flag = true;
    $min = PHP_INT_MAX;
    $n = trim(fgets(STDIN));
    $foo = explode(" ", trim(fgets(STDIN)));
    for($j=0; $j < $n; $j++)
        $min = min($foo[$j],$min);

    for($j=0; $j < $n && $flag; $j++)
    {
        $foo[$j] = $foo[$j] - $min;
        if( ($foo[$j]&1) != 0)
        {
          printf("NO\n");
          $flag = false;
        }

    }
    if($flag)
        printf("YES\n");

}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     $c = array_unique($c);
     sort($c);
     if(count($c) == 1)
     {
          print "YES\n";
     }
     else
     {
          $d = array();
          for($y = 0; $y < count($c) - 1; $y++)
          {
               $d[$y] = $c[$y + 1] - $c[$y];
          }
          $d = array_unique($d);
          sort($d);
          if((count($d) == 1) && ($d[0] == 2))
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
}
?>


Vus the Cossack has $$$n$$$ real numbers $$$a_i$$$. It is known that the sum of all numbers is equal to $$$0$$$. He wants to choose a sequence $$$b$$$ the size of which is $$$n$$$ such that the sum of all numbers is $$$0$$$ and each $$$b_i$$$ is either $$$\lfloor a_i \rfloor$$$ or $$$\lceil a_i \rceil$$$. In other words, $$$b_i$$$ equals $$$a_i$$$ rounded up or down. It is not necessary to round to the nearest integer.For example, if $$$a = [4.58413, 1.22491, -2.10517, -3.70387]$$$, then $$$b$$$ can be equal, for example, to $$$[4, 2, -2, -4]$$$. Note that if $$$a_i$$$ is an integer, then there is no difference between $$$\lfloor a_i \rfloor$$$ and $$$\lceil a_i \rceil$$$, $$$b_i$$$ will always be equal to $$$a_i$$$.Help Vus the Cossack find such sequence!

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of numbers. Each of the next $$$n$$$ lines contains one real number $$$a_i$$$ ($$$|a_i| < 10^5$$$). It is guaranteed that each $$$a_i$$$ has exactly $$$5$$$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $$$0$$$.

In each of the next $$$n$$$ lines, print one integer $$$b_i$$$. For each $$$i$$$, $$$|a_i-b_i|<1$$$ must be met. If there are multiple answers, print any.

NoteThe first example is explained in the legend.In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.

<?php
#1186d
$_n = $n = trim(fgets(STDIN));
$arr = [];
$ceil = [];

while ($_n--) {
    [$value] = fscanf(STDIN, '%f');
    $intValue = (int)ceil($value);
    $arr[] = $intValue;
    $ceil[] = $value === (float)$intValue;
}
$sum = array_sum($arr);
for ($i = 0; $i < $n && $sum > 0; $i++) {
    if ($ceil[$i] === false) {
        $arr[$i]--;
        $sum--;
    }
}
echo implode(PHP_EOL, $arr);

<?php
$a = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
    $b = trim(fgets(STDIN));
    if(round($b) == "-0")
    {
         print "0\n";
    }
    else
    {
         print round($b) . "\n";
    }
}
?>

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

<?php
#1186d
$_n = $n = trim(fgets(STDIN));
$arr = [];

while ($_n--) {
    [$value] = fscanf(STDIN, '%f');
    $arr[] = (int)ceil($value);
}
$sum = array_sum($arr);
for ($i = 0; $i < $n && $sum > 0; $i++, $sum--) {
    $arr[$i]--;
}
echo implode(PHP_EOL, $arr);

<?php
#1186d
$_n = $n = trim(fgets(STDIN));
$arr = [];

while ($_n--) {
    [$value] = fscanf(STDIN, '%f');
    if ($value > 0) {
        $arr[] = (int)ceil($value);
    } else {
        $arr[] = (int)floor($value);

    }
}
$sum = array_sum($arr);
for ($i = 0; $i < $n && $sum > 0; $i++, $sum--) {
    if ($arr[$i] > 0) {
        $arr[$i]--;
    } else {
        $arr[$i]++;
    }
}
echo implode(PHP_EOL, $arr);


The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold:  the first letter of $$$a$$$ is less than the first letter of $$$b$$$;  the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that:  Word $$$1$$$: ab  Word $$$2$$$: ac  ...  Word $$$25$$$: az  Word $$$26$$$: ba  Word $$$27$$$: bc  ...  Word $$$649$$$: zx  Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).

For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.

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

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

  for($q=0; $q <$t; $q++) {
      $ans = 0;
      $s = getT();
      $t0 = (ord($s[0]) - ord('a')) * 26;
      $t1 = 0;
      if($s[0] != 'a') {
          if(ord($s[1]) > ord($s[0])) {
             $t1 =  ord($s[1]) - ord($s[0]) ;
          } else {
              $t1 =  ord($s[1]) - ord($s[0]) + 1;
          }
      } else {
        $t1 = ord($s[1]) - ord($s[0]);
      }

      $ans = $t0 + $t1 ;

        echo $ans, $inter;

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

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

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

        return $d == $n;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

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

<?php
$dict = [];
$counter = 1;
for($x = ord('a') ; $x <= ord('z') ; $x++)
    for($y = ord('a') ; $y <= ord('z') ; $y++)
        if($x != $y)
            $dict[chr($x) . chr($y)] = $counter++;

$n = readline();
while($n--)
{
    $text = readline();
    echo $dict[$text] . "\n";
}
?>

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

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

  for($q=0; $q <$t; $q++) {
      $ans = 0;
      $s = getT();
      $t0 = (ord($s[0]) - ord('a')) * 26;
      $t1 =  $s[0] != 'a' ? ord($s[1]) - ord($s[0]) + 1 : ord($s[1]) - ord($s[0]);
      $ans = $t0 + $t1 ;

        echo $ans, $inter;

//   echo $ans, $inter;

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

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

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

        return $d == $n;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

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


Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x1, x2, ..., xn. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order.Vasya wants to pick such checkpoints and the order of visiting them that the total distance travelled is minimized. He asks you to calculate this minimum possible value.

The first line of the input contains two integers n and a (1 ≤ n ≤ 100 000,  - 1 000 000 ≤ a ≤ 1 000 000) — the number of checkpoints and Vasya's starting position respectively. The second line contains n integers x1, x2, ..., xn ( - 1 000 000 ≤ xi ≤ 1 000 000) — coordinates of the checkpoints.

Print one integer — the minimum distance Vasya has to travel in order to visit at least n - 1 checkpoint.

NoteIn the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is 12 - 10 = 2) and then proceed to the second one (distance is 12 - 7 = 5). The total distance is equal to 2 + 5 = 7.In the second sample it's enough to visit only one checkpoint so Vasya should just walk to the point  - 10.

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

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	list($n, $a) = readStringExplodeNum($f, ' ', true);
	$points = readStringExplodeNum($f, ' ', true);
	sort($points);

	if ($n < 2) {
		echo 0;
		return;
	}
	$points1 = $points2 = $points3 = $points4 = $points;

	array_pop($points1);
	array_unshift($points1, $a);

	array_shift($points2);
	array_unshift($points2, $a);

	array_shift($points3);
	array_push($points3, $a);

	array_pop($points4);
	array_push($points4, $a);

	$paths = array();
	$len = count($points);
	for ($i = 1; $i < $len; $i++) {
		$paths[0]+=abs($points1[$i] - $points1[$i - 1]);
		$paths[1]+=abs($points2[$i] - $points2[$i - 1]);
		$paths[2]+=abs($points3[$i] - $points3[$i - 1]);
		$paths[3]+=abs($points4[$i] - $points4[$i - 1]);
	}
	echo min($paths);
	/* / end body */
}

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

<?php

class Solution
{
    protected function solve($l, $r)
    {
        while (count($l) < 2) $l[] = 0;
        while (count($r) < 2) $r[] = 0;

        list($maxL, $minL) = $l;
        list($maxR, $minR) = $r;

        if (!$maxL) {
            return $minR;
        }

        if (!$maxR) {
            return $minL;
        }

        return min($maxR * 2 + $minL, $minR * 2 + $maxL, $maxR + $minL * 2, $minR + $maxL * 2);
    }

    public function run()
    {
        fscanf(STDIN, '%d %d', $n, $a);
        $p = explode(' ', trim(fgets(STDIN)));

        $l = $r = [];
        foreach ($p as $value) {
            $value -= $a;
            if ($value < 0) {
                $l[] = -$value;
                continue;
            }

            $r[] = $value;
        }

        sort($l);
        sort($r);

        $result = $this->solve(array_reverse($l), array_reverse($r));
        echo $result . PHP_EOL;
    }
}

$sol = new Solution();
$sol->run();

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

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	list($n, $a) = readStringExplodeNum($f, ' ', true);
	$points = readStringExplodeNum($f, ' ', true);
	sort($points);
	$toFirst = abs($points[0] - $a);
	$toEnd = abs($points[count($points) - 1] - $a);
	$path = 0;
	if ($toFirst <= $toEnd) {
		array_pop($points);
		$path = $toFirst;
	} else {
		array_shift($points);
		$path = $toEnd;
	}

	$len = count($points);
	for ($i = 1; $i < $len; $i++) {
		$path += $points[$i] - $points[$i - 1];
	}
	echo $path;
	/* / end body */
}

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

<?php

class Solution
{
    protected function calc($l, $r)
    {
        if (!$l) {
            return $r[count($r)-1];
        }

        if (!$r) {
            return $l[count($l)-1];
        }

        return min($r[count($r) - 1] * 2 + $l[count($l) - 1], $l[count($l) - 1] * 2 + $r[count($r) - 1]);
    }

    protected function solve($arr, $n, $a)
    {
        $l = $r = [];

        foreach ($arr as &$val) {
            $val -= $a;
            if ($val < 0) $l[] = -$val; else $r[] = $val;
        }

        sort($l); sort($r);

        if (!$l) {
            if (count($r) == 1) {
                return $r[count($r) - 1];
            }

            return $r[count($r) - 2];
        }

        if (!$r) {
            if (count($l) == 1) {
                return $l[count($l) - 1];
            }

            return $l[count($l) - 2];
        }

        return min($this->calc(array_slice($l, 0, -1), $r), $this->calc(array_slice($r, 0, -1), $l));
    }

    public function run()
    {
        fscanf(STDIN, '%d %d', $n, $a);
        $arr = explode(' ', trim(fgets(STDIN)));

        echo $this->solve($arr, $n, $a) . PHP_EOL;
    }
}

$sol = new Solution();
$sol->run();


You are given an array $$$a$$$ of $$$2n$$$ distinct integers. You want to arrange the elements of the array in a circle such that no element is equal to the the arithmetic mean of its $$$2$$$ neighbours.More formally, find an array $$$b$$$, such that: $$$b$$$ is a permutation of $$$a$$$.For every $$$i$$$ from $$$1$$$ to $$$2n$$$, $$$b_i \neq \frac{b_{i-1}+b_{i+1}}{2}$$$, where $$$b_0 = b_{2n}$$$ and $$$b_{2n+1} = b_1$$$. It can be proved that under the constraints of this problem, such array $$$b$$$ always exists.

The first line of input contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of testcases. The description of testcases follows. The first line of each testcase contains a single integer $$$n$$$ $$$(1 \leq n \leq 25)$$$. The second line of each testcase contains $$$2n$$$ integers $$$a_1, a_2, \ldots, a_{2n}$$$ $$$(1 \leq a_i \leq 10^9)$$$ — elements of the array. Note that there is no limit to the sum of $$$n$$$ over all testcases.

For each testcase, you should output $$$2n$$$ integers, $$$b_1, b_2, \ldots b_{2n}$$$, for which the conditions from the statement are satisfied.

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

  $m = 0;
  $k = 0;

  $b = $a;
  sort($b);
  rsort($a);

  for ($j = 1; $j <= $n * 2; $j++) {
    if ($j % 2 != 0) { echo $b[$m++].' '; }
    else { echo $a[$k++].' '; }
  }

  echo PHP_EOL;
}

?>


You have three piles of candies: red, green and blue candies:  the first pile contains only red candies and there are $$$r$$$ candies in it,  the second pile contains only green candies and there are $$$g$$$ candies in it,  the third pile contains only blue candies and there are $$$b$$$ candies in it. Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.

The first line contains integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given as a separate line of the input. It contains three integers $$$r$$$, $$$g$$$ and $$$b$$$ ($$$1 \le r, g, b \le 10^8$$$) — the number of red, green and blue candies, respectively.

Print $$$t$$$ integers: the $$$i$$$-th printed integer is the answer on the $$$i$$$-th test case in the input.

NoteIn the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.

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

for ($m=0; $m < $n; $m++) {
    $str = trim(fgets(STDIN));
    $aR = explode(" ", $str);
    $r = $aR[0];
    $q = $aR[1];
    $b = $aR[2];
    $max = max($aR);
    $min = min($aR);
    $sum = array_sum($aR);
    if (($sum - $max) <= $max) {
        echo ($sum - $max)."\n";
    } else {
        echo (intval($sum/2))."\n";
    }
}
?>


It is given a positive integer $$$n$$$. In $$$1$$$ move, one can select any single digit and remove it (i.e. one selects some position in the number and removes the digit located at this position). The operation cannot be performed if only one digit remains. If the resulting number contains leading zeroes, they are automatically removed.E.g. if one removes from the number $$$32925$$$ the $$$3$$$-rd digit, the resulting number will be $$$3225$$$. If one removes from the number $$$20099050$$$ the first digit, the resulting number will be $$$99050$$$ (the $$$2$$$ zeroes going next to the first digit are automatically removed).What is the minimum number of steps to get a number such that it is divisible by $$$25$$$ and positive? It is guaranteed that, for each $$$n$$$ occurring in the input, the answer exists. It is guaranteed that the number $$$n$$$ has no leading zeros.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing one integer $$$n$$$ ($$$25 \le n \le 10^{18}$$$). It is guaranteed that, for each $$$n$$$ occurring in the input, the answer exists. It is guaranteed that the number $$$n$$$ has no leading zeros.

For each test case output on a separate line an integer $$$k$$$ ($$$k \ge 0$$$) — the minimum number of steps to get a number such that it is divisible by $$$25$$$ and positive.

NoteIn the first test case, it is already given a number divisible by $$$25$$$.In the second test case, we can remove the digits $$$1$$$, $$$3$$$, and $$$4$$$ to get the number $$$75$$$.In the third test case, it's enough to remove the last digit to get the number $$$325$$$.In the fourth test case, we can remove the three last digits to get the number $$$50$$$.In the fifth test case, it's enough to remove the digits $$$4$$$ and $$$7$$$.


You are given a binary string $$$s$$$ of length $$$n$$$.Let's define $$$d_i$$$ as the number whose decimal representation is $$$s_i s_{i+1}$$$ (possibly, with a leading zero). We define $$$f(s)$$$ to be the sum of all the valid $$$d_i$$$. In other words, $$$f(s) = \sum\limits_{i=1}^{n-1} d_i$$$.For example, for the string $$$s = 1011$$$:   $$$d_1 = 10$$$ (ten);  $$$d_2 = 01$$$ (one)  $$$d_3 = 11$$$ (eleven);  $$$f(s) = 10 + 01 + 11 = 22$$$. In one operation you can swap any two adjacent elements of the string. Find the minimum value of $$$f(s)$$$ that can be achieved if at most $$$k$$$ operations are allowed.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). Description of the test cases follows. First line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^5$$$, $$$0 \le k \le 10^9$$$) — the length of the string and the maximum number of operations allowed. The second line of each test case contains the binary string $$$s$$$ of length $$$n$$$, consisting of only zeros and ones. It is also given that sum of $$$n$$$ over all the test cases doesn't exceed $$$10^5$$$.

For each test case, print the minimum value of $$$f(s)$$$ you can obtain with at most $$$k$$$ operations.

Note  For the first example, you can't do any operation so the optimal string is $$$s$$$ itself. $$$f(s) = f(1010) = 10 + 01 + 10 = 21$$$.  For the second example, one of the optimal strings you can obtain is "0011000". The string has an $$$f$$$ value of $$$22$$$.  For the third example, one of the optimal strings you can obtain is "00011". The string has an $$$f$$$ value of $$$12$$$.

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

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

 function solve()
 {

     list($n, $k) = IO::getArray();
     $s = IO::getInt();
     $ans = 0;
     $count= 0;
     for($i=0; $i<$n; $i++) {
        if($s[$i] == '1') {
             $count++;
        }
     }
     if($count > 0) {
          $ans = 11 * $count;
          $l=0;
          $r = $n-1;
          while ($s[$l] == '0') {
               $l += 1;
          }
          while ($s[$r] == '0') {
               $r -= 1;
          }
          $r = $n-1-$r;
          if($count == 1) {
               if($r<=$k) {
                    $ans -= 10;
               } else {
                    if($l <= $k) {
                         $ans -= 1;
                    }
               }
          } else {
               if ($l + $r <= $k) {
                  $ans -= 11;
                } else {
                  if ($r <= $k) {
                    $ans -= 10;
                  } else {
                    if ($l <= $k) {
                      $ans -= 1;
                    }
                  }
                }
          }

     }
     //  var_dump($a);

       IO::pr($ans);
 }

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

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

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

        return $d == $n;
    }

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

         return $a[$n];
     }

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

}

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

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

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

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

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

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

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

        return $aResult;

    }
}

class SolveArchive
{

}


Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$).

The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$.

Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists.

<?php
$input = fopen("php://stdin", 'r');
fscanf($input, "%d %d %d %d", $first, $second, $third, $fourth);
$set = [$first, $second, $third, $fourth];

sort($set);

$min = $set[count($set) - 1] - $set[count($set) - 2];
$middle = $set[0] - $min;
$max = $set[count($set) - 1] - $middle - $min;

echo "$min $middle $max";

<?php
# 1154A
$input = fopen('php://stdin', 'rb');
$values = array_map(
    function ($item){
        return (int)$item;
    },
    explode(' ', fgets($input))
);
$abc = max($values);
foreach ($values as $i => $item) {
    if ($item === $abc) {
        unset($values[$i]);
    } else {
        $values[$i] = $abc - $item;
    }
}
echo implode(' ', $values);

<?php
$array = explode(' ', trim(fgets(STDIN)));
$max = 0;
$maxKey = 0;
foreach ($array as $key => $value) {
    $array[$key] = (int) $value;
    if ($value > $max) {
        $maxKey = $key;
        $max = $value;
    }
}

$result = [];
foreach ($array as $key => $value) {
    if ($key != $maxKey) {
         $result[] = $max - $value;
    }
}
echo implode(' ', $result);

<?php

function search($sum, $ab, $ac, $bc) {
  // code goes here
  $c = (int)$sum - (int)$ab;
  $a = (int)$ac - $c;
  $b = (int)$bc - $c;
  return $b.' '.$c.' '.$a;
}

// keep this function call here
$file = fopen('php://stdin', 'r');
// $file = fopen('input.txt', 'r');
$str = fgets($file);
// $arr = explode(' ', $str);
$arr = array_map('intval', explode(' ', $str));
rsort($arr);
// print_r($arr);
echo search($arr[0], $arr[1], $arr[2], $arr[3]);
?>

<?php

$serial_info = readline();

$array = explode(' ', $serial_info);

sort($array);

$max = array_pop($array);

$a = $max - $array[0];
$b = $max - $array[1];
$c = $max - $array[2];

print_r($a.' '.$b.' '.$c);

return 0;

?>

<?php

while(!feof(STDIN)){
    $arr[]=fgets(STDIN);
}
$value=explode(" ", $arr[0]);

$sum=array_sum($value)/3;
for($i=0; $i<4; $i++){
    if($value[$i]!=$sum) echo $sum-$value[$i];
    if($value[$i]!=$sum && $i<>3) echo " ";
}

?>

<?php
$a = explode(' ', readline());
sort($a);
[$a, $b, $c, $sum] = $a;
echo $sum - $c, ' ', $sum - $b, ' ', $sum - $a;

<?php

$numbers = fgets(STDIN);
$numbers = explode(' ', $numbers);
$numbers = array_map('trim', $numbers);

bcscale(0);

usort($numbers, function ($a, $b) {
    return bccomp($a, $b);
});

$c = bcsub($numbers[3], $numbers[2]);
$a = bcsub($numbers[1], $c);
$b = bcsub($numbers[0], $c);

echo sprintf("%s %s %s", $a, $b, $c);

<?php //https://codeforces.com/problemset/problem/1154/A

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

	sort($s);

	$a = max($s) - $s[0];
	$b = max($s) - $s[1];
	$c = max($s) - $s[2];

	echo $a." ".$b." ".$c;
?>

<?php
    $a = explode(" ", (trim(fgets(STDIN))));
    rsort($a);
    $r = [];
    foreach ($a AS $k => $v) {
        if ($k == 0) {
            $max = $v;
        } else {
            $r[] = $max - $v;
        }
    }
    echo implode(" ", $r);
?>

<?php
$set = explode(' ', file_get_contents('php://stdin'));
sort($set);

$min = $set[count($set) - 1] - $set[count($set) - 2];
$middle = $set[0] - $min;
$max = $set[count($set) - 1] - $middle - $min;

echo "$min $middle $max";

<?php

function search($sum, $ab, $ac, $bc) {
  // code goes here
  $c = (int)$sum - (int)$ab;
  $a = (int)$ac - $c;
  $b = (int)$bc - $c;
  return $b.' '.$c.' '.$a;
}

// keep this function call here
$file = fopen('php://stdin', 'r');
// $file = fopen('input.txt', 'r');
$str = fgets($file);
$arr = explode(' ', $str);
// sort($arr);
natsort($arr);
echo search($arr[3], $arr[0], $arr[1], $arr[2]);
?>

<?php

function search($sum, $ab, $ac, $bc) {
  // code goes here
  $c = (int)$sum - (int)$ab;
  $a = (int)$ac - $c;
  $b = (int)$bc - $c;
  return $b.' '.$c.' '.$a;
}

// keep this function call here
$file = fopen('php://stdin', 'r');
// $file = fopen('input.txt', 'r');
$str = fgets($file);
// $arr = explode(' ', $str);
$arr = array_map('intval', explode(' ', $str));
rsort($arr);
print_r($arr);
echo search($arr[0], $arr[1], $arr[2], $arr[3]);
?>

<?php

function search($sum, $ab, $ac, $bc) {
  // code goes here
  $c = (int)$sum - (int)$ab;
  $a = (int)$ac - $c;
  $b = (int)$bc - $c;
  return $b.' '.$c.' '.$a;
}

// keep this function call here
$file = fopen('php://stdin', 'r');
// $file = fopen('input.txt', 'r');
$str = fgets($file);
// $arr = explode(' ', $str);
$arr = array_map('intval', explode(' ', $str));
rsort($arr);
echo search($arr[3], $arr[0], $arr[1], $arr[2]);
?>

<?php

function search($sum, $ab, $ac, $bc) {
  // code goes here
  $c = (int)$sum - (int)$ab;
  $a = (int)$ac - $c;
  $b = (int)$bc - $c;
  return $b.' '.$c.' '.$a;
}

// keep this function call here
$file = fopen('php://stdin', 'r');
// $file = fopen('input.txt', 'r');
$str = fgets($file);
$arr = explode(' ', $str);
rsort($arr);
echo search($arr[0], $arr[1], $arr[2], $arr[3]);
?>

<?php

$numbers = fgets(STDIN);
$numbers = explode(' ', $numbers);

bcscale(0);

usort($numbers, function ($a, $b) {
    return bccomp($a, $b);
});

$c = bcsub($numbers[3], $numbers[2]);
$a = bcsub($numbers[0], $c);
$b = bcsub($numbers[1], $c);

echo sprintf('%s %s %s', $a, $b, $c);

<?php

$numbers = fgets(STDIN);
$numbers = explode(' ', $numbers);

bcscale(0);

usort($numbers, function ($a, $b) {
    return bccomp($a, $b);
});

$numbers = array_map('trim', $numbers);

$c = bcsub($numbers[0], $numbers[1]);
$a = bcsub($numbers[2], $c);
$b = bcsub($numbers[3], $c);

echo sprintf("%s %s %s", $a, $b, $c);


In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.

The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles. The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).

Print a single number — the sought number of days.

NoteIn the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.


New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi.As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a certain book x, he follows the steps described below.  He lifts all the books above book x.  He pushes book x out of the stack.  He puts down the lifted books without changing their order.  After reading book x, he puts book x on the top of the stack.  He decided to read books for m days. In the j-th (1 ≤ j ≤ m) day, he will read the book that is numbered with integer bj (1 ≤ bj ≤ n). To read the book, he has to use the process described in the paragraph above. It is possible that he decides to re-read the same book several times.After making this plan, he realized that the total weight of books he should lift during m days would be too heavy. So, he decided to change the order of the stacked books before the New Year comes, and minimize the total weight. You may assume that books can be stacked in any possible order. Note that book that he is going to read on certain step isn't considered as lifted on that step. Can you help him?

The first line contains two space-separated integers n (2 ≤ n ≤ 500) and m (1 ≤ m ≤ 1000) — the number of books, and the number of days for which Jaehyun would read books. The second line contains n space-separated integers w1, w2, ..., wn (1 ≤ wi ≤ 100) — the weight of each book. The third line contains m space separated integers b1, b2, ..., bm (1 ≤ bj ≤ n) — the order of books that he would read. Note that he can read the same book more than once.

Print the minimum total weight of books he should lift, which can be achieved by rearranging the order of stacked books.

NoteHere's a picture depicting the example. Each vertical column presents the stacked books.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
$e = $d;
$f = array_unique($e);
$g = array();
for($x = 0; $x < $b; $x++)
{
    if($f[$x] == TRUE)
    {
        array_push($g, $f[$x]);
    }
}
$h = 0;
for($x = 0; $x < $b; $x++)
{
    for($y = 0; $y < count($g); $y++)
    {
        if($d[$x] == $g[$y])
        {
            array_unshift($g, $g[$y]);
            array_splice($g, $y + 1, 1);
            break;
        }
        else
        {
            $h += $c[$g[$y] - 1];
        }
    }
}
print $h;
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
$e = $d;
$f = array_unique($e);
$g = array();
for($x = 0; $x < $b; $x++) {
    if ($f[$x]) {
        array_push($g, $f[$x]);
    }
}

$h = 0;
for($x = 0; $x < $b; $x++) {
    for($y = 0; $y < count($g); $y++) {
        if($d[$x] == $g[$y]) {
            array_unshift($g, $g[$y]);
            array_splice($g, $y + 1, 1);
            break;
        } else {
            $h += $c[$g[$y] - 1];
        }
    }
}
echo $h;
?>


You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.Let instability of the array be the following value: $$$\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$$$.You have to remove exactly one element from this array to minimize instability of the resulting $$$(n-1)$$$-elements array. Your task is to calculate the minimum possible instability.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — elements of the array $$$a$$$.

Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array $$$a$$$.

NoteIn the first example you can remove $$$7$$$ then instability of the remaining array will be $$$3 - 1 = 2$$$.In the second example you can remove either $$$1$$$ or $$$100000$$$ then instability of the remaining array will be $$$100000 - 100000 = 0$$$ and $$$1 - 1 = 0$$$ correspondingly.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = $b;
array_splice($b, -1);
$d = $b[count($b) - 1] - $b[0];
array_splice($c, 0, 1);
$e = $c[count($c) - 1] - $c[0];
print min($d, $e);
?>

<?php
$number = trim(fgets(STDIN));
$input =explode(' ', trim(fgets(STDIN)));
sort($input);
if (count($input) <= 2) {
    echo 0;
    exit();
}
$res = [];
$max = array_pop($input);
$min = array_shift($input);
$res[] = $max - $min;
$res[] = max($input) - $min;
$res[] = $max - min($input);
$output = min($res);
echo $output;

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$a = $ir->readArrayOfInt($n);

sort($a);

echo ($a[$n-1]- $a[0] - max([$a[$n-1] - $a[$n-2], $a[1] - $a[0]]));

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = $b;
array_splice($b, -1);
$d = $b[count($b) - 1] - $b[0];
array_splice($c, 0, 1);
$e = $b[count($b) - 1] - $b[0];
print min($d, $e);
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
unset($b[count($b) - 1]);
print $b[count($b) - 1] - $b[0];
?>

<?php
$number = trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
$res = [];
while (true) {
    $max = max($input);
    $min = min($input);
    $res[] = $max - $min;
    $max_del = array_diff($input, [$max]);
    $max_l1 = max($max_del);
    $res[] = $max_l1 - $min;
    $min_del = array_diff($input, [$min]);
    $res[] = $max - min($min_del);
    $output = min($res);
    break;
}

echo $output;


You are given an array $$$a_{1}, a_{2}, \ldots, a_{n}$$$. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct.In other words, at most one time you can choose two integers $$$l$$$ and $$$r$$$ ($$$1 \leq l \leq r \leq n$$$) and delete integers $$$a_l, a_{l+1}, \ldots, a_r$$$ from the array. Remaining elements should be pairwise distinct. Find the minimum size of the subsegment you need to remove to make all remaining elements distinct.

The first line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the number of elements in the given array. The next line contains $$$n$$$ spaced integers $$$a_{1}, a_{2}, \ldots, a_{n}$$$ ($$$1 \le a_{i} \le 10^{9}$$$) — the elements of the array.

Print a single integer — the minimum size of the subsegment you need to remove to make all elements of the array pairwise distinct. If no subsegment needs to be removed, print $$$0$$$.

NoteIn the first example all the elements are already distinct, therefore no subsegment needs to be removed.In the second example you can remove the subsegment from index $$$2$$$ to $$$3$$$.In the third example you can remove the subsegments from index $$$1$$$ to $$$2$$$, or from index $$$2$$$ to $$$3$$$, or from index $$$3$$$ to $$$4$$$.


There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.

The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.

Print the maximum number of teams of three people the coach can form.

NoteIn the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.In the second example he can't make a single team.In the third example the coach can form three teams. For example, he can do this in the following way:  The first group (of two people) and the seventh group (of one person),  The second group (of two people) and the sixth group (of one person),  The third group (of two people) and the fourth group (of one person).

<?php

$n = trim(fgets(STDIN));

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

$result = 0;
$two_num = 0;
$one_num = 0;
foreach ($a_list as $a)
{
	switch ((int)$a)
	{
		case 1:
			$one_num++;
			break;
		case 2:
			$two_num++;
			break;
		default:
			break;
	}
}

if ($two_num > 0)
{
	$result = min($one_num, $two_num);
	$one_num -= $result;
}

$result += floor($one_num / 3);

echo $result;


In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper.

Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.

NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field.

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

    $intSL = strpos($S, ">");
    $intSR = strpos($S, "<");
    $intEL = strrpos($S, "<");
    $intER = strrpos($S, ">");

    // var_dump($intSL);
    // var_dump($intSR);
    // var_dump($intEL);
    // var_dump($intER);

    $ans = 0;
    if ($intSL === false || $intSR === false || $intEL === false || $intER === false) {
        $ans = $N;
    } else {
        if ($intSR < $intSL) {
            $ans += $intSL;
        }

        if ($intER > $intEL) {
            $ans += $N - $intEL - 1;
        }
    }

    echo $ans;

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

	$l = substr_count($S, '<');
	$r = substr_count($S, '>');

	echo abs($l - $r);

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

    $intSL = strpos($S, ">");
    $intSR = strpos($S, "<");
    $intEL = strrpos($S, "<");
    $intER = strrpos($S, ">");

    // var_dump($intSL);
    // var_dump($intSR);
    // var_dump($intEL);
    // var_dump($intER);

    $ans = 0;
    if ($intSL === false || $intSR === false || $intEL === false || $intER === false) {
        $ans = $N;
    } else {
        if ($intSR < $intSL) {
            $ans += $intSL;
        }

        if ($intER > $intEL) {
            $ans += $intER;
        }
    }

    echo $ans;


In BerSoft $$$n$$$ programmers work, the programmer $$$i$$$ is characterized by a skill $$$r_i$$$.A programmer $$$a$$$ can be a mentor of a programmer $$$b$$$ if and only if the skill of the programmer $$$a$$$ is strictly greater than the skill of the programmer $$$b$$$ $$$(r_a > r_b)$$$ and programmers $$$a$$$ and $$$b$$$ are not in a quarrel.You are given the skills of each programmers and a list of $$$k$$$ pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer $$$i$$$, find the number of programmers, for which the programmer $$$i$$$ can be a mentor.

The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$$$ — total number of programmers and number of pairs of programmers which are in a quarrel. The second line contains a sequence of integers $$$r_1, r_2, \dots, r_n$$$ $$$(1 \le r_i \le 10^{9})$$$, where $$$r_i$$$ equals to the skill of the $$$i$$$-th programmer. Each of the following $$$k$$$ lines contains two distinct integers $$$x$$$, $$$y$$$ $$$(1 \le x, y \le n$$$, $$$x \ne y)$$$ — pair of programmers in a quarrel. The pairs are unordered, it means that if $$$x$$$ is in a quarrel with $$$y$$$ then $$$y$$$ is in a quarrel with $$$x$$$. Guaranteed, that for each pair $$$(x, y)$$$ there are no other pairs $$$(x, y)$$$ and $$$(y, x)$$$ in the input.

Print $$$n$$$ integers, the $$$i$$$-th number should be equal to the number of programmers, for which the $$$i$$$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.

NoteIn the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can be a mentor of the second programmer. The fourth programmer can be a mentor of the first and of the second programmers. He can not be a mentor of the third programmer, because they are in a quarrel.

<?php

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

fscanf($handle, "%i %i", $n, $p);

$skill = array_map('intval', explode(' ', trim(fgets($handle))));

$arg = [];
for($i = 0; $i < $p; $i++)
{
	fscanf($handle, "%i %i", $k, $v);

	$k--;
	$v--;

	if(!isset($arg[$k]))
	{
		$arg[$k] = [];
	}

	$arg[$k][] = $v;

	if(!isset($arg[$v]))
	{
		$arg[$v] = [];
	}

	$arg[$v][] = $k;
}

asort($skill);

$prog = array_keys($skill);
$backProg = array_flip($prog);
$skill = array_values($skill);

$pos = array_fill(0, $n, 0);

for($i = 0; $i < $n; $i++)
{
	//$count = $i;

	$l = 0;
	$r = $i;

		while($r - $l > 1)
		{
			$m = $l + floor(($r - $l) / 2);
			if($skill[$m] < $skill[$i])
			{
				$l = $m;

			}
			else
			{
				$r = $m;
			}
		}

		$r = $skill[$l] < $skill[$i] ? $r : $l;

	$count = $r;

	$progId = $prog[$i];

	if(isset($arg[$progId]))
	{
		for($j = 0; $j < count($arg[$progId]); $j++)
		{
			if($skill[$backProg[$arg[$progId][$j]]] < $skill[$i])
			{
				$count--;
			}
		}
	}

	$pos[$progId] = $count;
}

echo implode(' ', $pos);

<?php

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

fscanf($handle, "%i %i", $n, $p);

$skill = array_map('intval', explode(' ', trim(fgets($handle))));

$arg = [];
for($i = 0; $i < $p; $i++)
{
	fscanf($handle, "%i %i", $k, $v);

	$k--;
	$v--;

	if(!isset($arg[$k]))
	{
		$arg[$k] = [];
	}

	$arg[$k][] = $v;

	if(!isset($arg[$v]))
	{
		$arg[$v] = [];
	}

	$arg[$v][] = $k;
}

asort($skill);

$prog = array_keys($skill);
$backProg = array_flip($prog);
$skill = array_values($skill);

$pos = array_fill(0, $n, 0);

for($i = 0; $i < $n; $i++)
{
	//$count = $i;

	$l = 0;
	$r = $i;
	if($r - $l > 1)
	{
		while($r - $l > 1)
		{
			$m = $l + floor(($r - $l) / 2);
			if($skill[$m] < $skill[$i])
			{
				$l = $m;

			}
			else
			{
				$r = $m;
			}
		}
	}
	else
	{
		$r = $skill[$l] < $skill[$i] ? $r : $l;
	}

	$count = $r;

	$progId = $prog[$i];

	if(isset($arg[$progId]))
	{
		for($j = 0; $j < count($arg[$progId]); $j++)
		{
			if($skill[$backProg[$arg[$progId][$j]]] < $skill[$i])
			{
				$count--;
			}
		}
	}

	$pos[$progId] = $count;
}

echo implode(' ', $pos);