The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).

The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki integers — aij (1 ≤ aij ≤ m) — the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces.

Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).

NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.


You are given four integer values $$$a$$$, $$$b$$$, $$$c$$$ and $$$m$$$.Check if there exists a string that contains:   $$$a$$$ letters 'A';  $$$b$$$ letters 'B';  $$$c$$$ letters 'C';  no other letters;  exactly $$$m$$$ pairs of adjacent equal letters (exactly $$$m$$$ such positions $$$i$$$ that the $$$i$$$-th letter is equal to the $$$(i+1)$$$-th one).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Each of the next $$$t$$$ lines contains the description of the testcase — four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$m$$$ ($$$1 \le a, b, c \le 10^8$$$; $$$0 \le m \le 10^8$$$).

For each testcase print "YES" if there exists a string that satisfies all the requirements. Print "NO" if there are no such strings. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

NoteIn the first testcase strings "ABCAB" or "BCABA" satisfy the requirements. There exist other possible strings.In the second testcase there's no way to put adjacent equal letters if there's no letter that appears at least twice.In the third testcase string "CABBCC" satisfies the requirements. There exist other possible strings.

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($a, $b, $c, $m) = IO::arr();
    $maxt = max([$a, $b, $c]);
    $sum = $a + $b + $c - $maxt;
    $min = $maxt - $sum;
    if ($min <= 0) {
        $min = 0;
    } else {
        $min -= 1;
    }
    $ma = max([$a - 1, 0]);
    $mb = max([$b - 1, 0]);
    $mc = max([$c - 1, 0]);
    $max = $ma + $mb + $mc;
    if ($m >= $min && $m <= $max) {
        IO::yes();
    } else {
        IO::no();
    }
}

?>

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($a, $b, $c, $m) = IO::arr();
    $maxt = max([$a, $b, $c]);
    $sum = $a + $b + $c - $maxt;
    $min = $maxt - $sum;
    if ($min <= 0) {
        $min = 0;
    } else {
        $min -= 1;
    }
    $ma = max([$a - 1, 0]);
    $mb = max([$b - 1, 0]);
    $mc = max([$c - 1, 0]);
    $max = $ma + $mb + $mc;
    echo $max . $min;
    if ($m >= $min && $m <= $max) {
        IO::yes();
    } else {
        IO::no();
    }
}

?>

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($a, $b, $c, $m) = IO::arr();
    $maxt = max([$a, $b, $c]);
    $sum = $a + $b + $c - $maxt;
    $min = $maxt - $sum;
    $min = max([$min - 1, 0]);
    $ma = max([$a - 1, 0]);
    $mb = max([$b - 1, 0]);
    $mc = max([$c - 1, 0]);
    $max = $ma + $mb + $mc;
    echo $max . $min;
    if ($m >= $min && $m <= $max) {
        IO::yes();
    } else {
        IO::no();
    }
}

?>

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($a, $b, $c, $m) = IO::arr();
    $maxt = max([$a, $b, $c]);
    $sum = $a + $b + $c - $maxt;
    $min = abs($sum - $maxt);

    $min = max([$min - 1, 0]);
    $ma = max([$a - 1, 0]);
    $mb = max([$b - 1, 0]);
    $mc = max([$c - 1, 0]);
    $max = $ma + $mb + $mc;
    if ($m >= $min && $m <= $max) {
        IO::yes();
    } else {
        IO::no();
    }
}

?>

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($a, $b, $c, $m) = IO::arr();
    $maxt = max([$a, $b, $c]);
    $sum = $a + $b + $c - $maxt;
    $min = abs($sum - $maxt);

    $min = max([$min - 1, 0]);
    $ma = max([$a - 1, 0]);
    $mb = max([$b - 1, 0]);
    $mc = max([$c - 1, 0]);
    $max = $ma + $mb + $mc;
    if ($m - $min >= 0 && $max - $m >= 0) {
        IO::yes();
    } else {
        IO::no();
    }
}

?>

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($a, $b, $c, $m) = IO::arr();
    $maxt = max([$a, $b, $c]);
    $sum = $a + $b + $c - $maxt;
    $min = abs($sum - $maxt);

    $min = max([$min - 1, 0]);
    $min = max([$min, 0]);
    $ma = max([$a - 1, 0]);
    $mb = max([$b - 1, 0]);
    $mc = max([$c - 1, 0]);
    $max = $ma + $mb + $mc;
  //  IO::line($min . ' - ' . $max);
    if ($m - $min >= 0 && $max - $m >= 0) {
        IO::yes();
    } else {
        IO::no();
    }
}

?>

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($a, $b, $c, $m) = IO::arr();
    $maxt = max([$a, $b, $c]);
    $sum = $a + $b + $c - $maxt;
    $min = abs($sum - $maxt);
    if ($min % 2 != 0) {
        $min -= 1;
    }
    $min = $min / 2;
    $min = max([$min, 0]);
    $ma = max([$a - 1, 0]);
    $mb = max([$b - 1, 0]);
    $mc = max([$c - 1, 0]);
    $max = $ma + $mb + $mc;
  //  IO::line($min . ' - ' . $max);
    if ($m - $min >= 0 && $max - $m >= 0) {
        IO::yes();
    } else {
        IO::no();
    }
}

?>

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($a, $b, $c, $m) = IO::arr();
    $maxt = max([$a, $b, $c]);
    $sum = $a + $b + $c - $maxt;
    $min = abs($sum - $maxt);
    if ($min % 2 != 0) {
        $min -= 1;
    }
    $min = $min / 2;
    $min = max([$min, 0]);
    $ma = floor($a / 2);
    $mb = floor($b / 2);
    $mc = floor($c / 2);
    $max = $ma + $mb + $mc;
    if ($m - $min >= 0 && $max - $m >= 0) {
        IO::yes();
    } else {
        IO::no();
    }
}

?>

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($a, $b, $c, $m) = IO::arr();
    $maxt = max([$a, $b, $c]);
    $sum = $a + $b + $c;
    $min = $maxt - ($sum - $maxt);
    if ($min % 2 != 0) {
        $min -= 1;
    }
    $min = $min / 2;
    $min = max([$min, 0]);
    $ma = floor($a / 2);
    $mb = floor($b / 2);
    $mc = floor($c / 2);
    $max = $ma + $mb + $mc;
    if ($m >= $min && $m <= $max) {
        IO::yes();
    } else {
        IO::no();
    }
}

?>

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($a, $b, $c, $m) = IO::arr();
    $maxt = max([$a, $b, $c]);
    $sum = $a + $b + $c;
    $min = $maxt - ($sum - $maxt);
    if ($min % 2 != 0) {
        $min -= 1;
    }
    $min = max([$min, 0]);
    $ma = floor($a / 2);
    $mb = floor($b / 2);
    $mc = floor($c / 2);
    $max = $ma + $mb + $mc;
    if ($m >= $min && $m <= $max) {
        IO::yes();
    } else {
        IO::no();
    }
}

?>


Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive.

Print the maximum number of people that may come to Famil Door's party.

NoteIn the first sample, friends 3 and 4 can come on any day in range [117, 128].In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.


There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:   alloc n — to allocate n bytes of the memory and return the allocated block's identifier x;  erase x — to erase the block with the identifier x;  defragment — to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order; The memory model in this case is very simple. It is a sequence of m bytes, numbered for convenience from the first to the m-th.The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of n successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL.The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT.The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order.In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration.You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands.

The first line of the input data contains two positive integers t and m (1 ≤ t ≤ 100;1 ≤ m ≤ 100), where t — the amount of operations given to the memory manager for processing, and m — the available memory size in bytes. Then there follow t lines where the operations themselves are given. The first operation is alloc n (1 ≤ n ≤ 100), where n is an integer. The second one is erase x, where x is an arbitrary 32-bit integer numerical token. The third operation is defragment.

Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks.

6 10
alloc 5
alloc 3
erase 1
alloc 6
defragment
alloc 6


You are given a multiset (i. e. a set that can contain multiple equal integers) containing $$$2n$$$ integers. Determine if you can split it into exactly $$$n$$$ pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by $$$2$$$, the remainder is $$$1$$$).

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1\leq n\leq 100$$$). The second line of each test case contains $$$2n$$$ integers $$$a_1,a_2,\dots, a_{2n}$$$ ($$$0\leq a_i\leq 100$$$) — the numbers in the set.

For each test case, print "Yes" if it can be split into exactly $$$n$$$ pairs so that the sum of the two elements in each pair is odd, and "No" otherwise. You can print each letter in any case.

NoteIn the first test case, a possible way of splitting the set is $$$(2,3)$$$, $$$(4,5)$$$.In the second, third and fifth test case, we can prove that there isn't any possible way.In the fourth test case, a possible way of splitting the set is $$$(2,3)$$$.

<?php
function oddSet($n2){
    $countOdd = 0;
    $countEven = 0;
    for($i=0;$i<count($n2);$i++){
        if($n2[$i] % 2 === 0){
            $countEven += 1;
            continue;
        }
        $countOdd += 1;
    }
    if($countOdd === $countEven){
        return "Yes\n";
    }
    return "No\n";
}

$t = readline();
$i = 0;
while($i<$t){
    $n = readline();
    $n2 = readline();
    $n2 = explode(" ",$n2);
    print_r(oddSet($n2));
    $i++;
}

<?php

$t = readline();

while($t){
    $n = readline();

    $a = readline();
    $arr = explode(" ",$a);
    $x = TRUE;
    $odd = 0;
    $even = 0;
    for($i = 0; $i< $n*2; $i++){
        if($arr[$i]%2 == 0)
            $even++;
        else $odd++;
    }
    if($odd == $even)
        echo "Yes";
    else echo "No";
    echo PHP_EOL;

    $t--;
}

?>

<?php
function oddSet($n2){
    $countOdd = 0;
    $countEven = 0;
    for($i=0;$i<count($n2);$i++){
        if($n2[$i] % 2 === 0){
            $countEven += 1;
            continue;
        }
        $countOdd += 1;
    }
    if($countOdd === $countEven){
        return "Yes";
    }
    return "No";
}

$t = readline();
$i = 0;
while($i<$t){
    $n = readline();
    $n2 = readline();
    $n2 = explode(" ",$n2);
    print_r(oddSet($n2));
    $i++;
}

<?php

$t = readline();

while($t){
    $n = readline();

    $a = readline();
    $arr = explode(" ",$a);
    $x = TRUE;
    for($i = 0; $i< $n*2; $i+=2){
        if(( $arr[$i] + $arr[$i+1] )%2 == 0){
            $x = FALSE;;
        }
    }
    if($x)
        echo "Yes";
    else echo "No";

    $t--;
}

?>


You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.

First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.

If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.


Genos needs your help. He was asked to solve the following programming problem by Saitama:The length of some string s is denoted |s|. The Hamming distance between two strings s and t of equal length is defined as , where si is the i-th character of s and ti is the i-th character of t. For example, the Hamming distance between string "0011" and string "0110" is |0 - 0| + |0 - 1| + |1 - 1| + |1 - 0| = 0 + 1 + 0 + 1 = 2.Given two binary strings a and b, find the sum of the Hamming distances between a and all contiguous substrings of b of length |a|.

The first line of the input contains binary string a (1 ≤ |a| ≤ 200 000). The second line of the input contains binary string b (|a| ≤ |b| ≤ 200 000). Both strings are guaranteed to consist of characters '0' and '1' only.

Print a single integer — the sum of Hamming distances between a and all contiguous substrings of b of length |a|.

NoteFor the first sample case, there are four contiguous substrings of b of length |a|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts twice, as there are two occurrences of string "11". The sum of these edit distances is 1 + 0 + 1 + 1 = 3.The second sample case is described in the statement.


Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret!A password is an array $$$a$$$ of $$$n$$$ positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and replace them with their sum. Formally, choose an index $$$i$$$ such that $$$1 \leq i < n$$$ and $$$a_{i} \neq a_{i+1}$$$, delete both $$$a_i$$$ and $$$a_{i+1}$$$ from the array and put $$$a_{i}+a_{i+1}$$$ in their place. For example, for array $$$[7, 4, 3, 7]$$$ you can choose $$$i = 2$$$ and the array will become $$$[7, 4+3, 7] = [7, 7, 7]$$$. Note that in this array you can't apply this operation anymore.Notice that one operation will decrease the size of the password by $$$1$$$. What is the shortest possible length of the password after some number (possibly $$$0$$$) of operations?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the password. The second line of each test case contains $$$n$$$ integers $$$a_{1},a_{2},\dots,a_{n}$$$ ($$$1 \leq a_{i} \leq 10^9$$$) — the initial contents of your password. The sum of $$$n$$$ over all test cases will not exceed $$$2 \cdot 10^5$$$.

For each password, print one integer: the shortest possible length of the password after some number of operations.

NoteIn the first test case, you can do the following to achieve a length of $$$1$$$:Pick $$$i=2$$$ to get $$$[2, 4, 1]$$$Pick $$$i=1$$$ to get $$$[6, 1]$$$Pick $$$i=1$$$ to get $$$[7]$$$In the second test case, you can't perform any operations because there is no valid $$$i$$$ that satisfies the requirements mentioned above.

<?php
	$a = trim( fgets(STDIN)) ; //kol-vo naborov
	for ($x=0; $x <$a ; $x++) {
		$n = trim (fgets(STDIN)) ;   //$n - kolvo cisel
		$arr = explode(" ", trim(fgets(STDIN)));
		$result = 1;
		for ($y=0; $y < $n -1; $y++) {
			if ($arr[$y] == $arr[$y+1]) {
				$result ++;
			}
		}
		if ($n == $result) {
			print  $n."\n";
		}
		else
		{
			print "1\n";
		}
	}

	/*
$a = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     $d = 1;
     for($y = 0; $y < $b - 1; $y++)
     {
          if($c[$y] == $c[$y + 1])
          {
               $d++;
          }
     }
     if($b == $d)
     {
          echo $b . "\n";
     }
     else
     {
          echo "1\n";
     }
}

*/

?>

<?php
	$a = trim( fgets(STDIN)) ; //kol-vo naborov
	for ($y=0; $y <$a ; $y++) {
		$n = trim (fgets(STDIN)) ;   //$n - kolvo cisel
		$arr = explode(" ", trim(fgets(STDIN)));
		$result = 1;
		for ($y=0; $y < $n -1; $y++) {
			if ($arr[$y] == $arr[$y+1]) {
				$result ++;
			}
		}
		if ($n == $result) {
			print  $n."\n";
		}
		else
		{
			print "1\n";
		}
	}
?>

<?php
	$a = trim( fgets(STDIN)) ; //kol-vo naborov
	for ($y=0; $y <$a ; $y++) {
		$n = trim (fgets(STDIN)) ;   //$n - kolvo cisel
		$arr = explode(" ", (trim(fgets(STDIN))) );
		$result = 1;
		for ($y=0; $y < $n -1; $y++) {
			if ($arr[$y] == $arr[$y+1]) {
				$result ++;
			}
		}
		if ($n == $result) {
			print  $result."\n";
		}
		else
		{
			print "1\n";
		}
	}
?>

<?php
	$a = trim( fgets(STDIN)) ; //kol-vo naborov
	for ($y=0; $y <$a ; $y++) {
		$n = trim (fgets(STDIN)) ;   //$n - kolvo cisel
		$arr = explode(" ", trim(fgets(STDIN)) );
		$result = 1;
		for ($y=0; $y < $n -1; $y++) {
			if ($arr[$y] == $arr[$y+1]) {
				$result ++;
			}
		}
		if ($n == $result) {
			print  $result."\n";
		}
		else
		{
			print "1\n";
		}
	}
?>

<?php
	$a = trim( fgets(STDIN)) ; //kol-vo naborov
	for ($y=0; $y <$a ; $y++) {
		$n = trim (fgets(STDIN)) ;   //$n - kolvo cisel
		$arr = explode(" ", trim(fgets(STDIN)));
		$result = 1;
		for ($y=0; $y < $n -1; $y++) {
			if ($arr[$y] == $arr[$y+1]) {
				$result ++;
			}
		}
		if ($n == $result) {
			print  $result."\n";
		}
		else
		{
			print "1\n";
		}
	}
?>


This is an easier version of the problem. In this version $$$n \le 1000$$$The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company has already bought $$$n$$$ plots along the highway and is preparing to build $$$n$$$ skyscrapers, one skyscraper per plot.Architects must consider several requirements when planning a skyscraper. Firstly, since the land on each plot has different properties, each skyscraper has a limit on the largest number of floors it can have. Secondly, according to the design code of the city, it is unacceptable for a skyscraper to simultaneously have higher skyscrapers both to the left and to the right of it.Formally, let's number the plots from $$$1$$$ to $$$n$$$. Then if the skyscraper on the $$$i$$$-th plot has $$$a_i$$$ floors, it must hold that $$$a_i$$$ is at most $$$m_i$$$ ($$$1 \le a_i \le m_i$$$). Also there mustn't be integers $$$j$$$ and $$$k$$$ such that $$$j < i < k$$$ and $$$a_j > a_i < a_k$$$. Plots $$$j$$$ and $$$k$$$ are not required to be adjacent to $$$i$$$.The company wants the total number of floors in the built skyscrapers to be as large as possible. Help it to choose the number of floors for each skyscraper in an optimal way, i.e. in such a way that all requirements are fulfilled, and among all such construction plans choose any plan with the maximum possible total number of floors.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of plots. The second line contains the integers $$$m_1, m_2, \ldots, m_n$$$ ($$$1 \leq m_i \leq 10^9$$$) — the limit on the number of floors for every possible number of floors for a skyscraper on each plot.

Print $$$n$$$ integers $$$a_i$$$ — the number of floors in the plan for each skyscraper, such that all requirements are met, and the total number of floors in all skyscrapers is the maximum possible. If there are multiple answers possible, print any of them.

NoteIn the first example, you can build all skyscrapers with the highest possible height.In the second test example, you cannot give the maximum height to all skyscrapers as this violates the design code restriction. The answer $$$[10, 6, 6]$$$ is optimal. Note that the answer of $$$[6, 6, 8]$$$ also satisfies all restrictions, but is not optimal.


Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.

The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.

In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_unique($b);
$d = array();
for($x = 0; $x < count($b); $x++)
{
    $e = 0;
    for($y = 0; $y < count($b); $y++)
    {
        if($b[$x] == $b[$y])
        {
            $e++;
        }
    }
    array_push($d, $e);
}
rsort($d);
print $d[0] . " " . count($c);
?>

<?php
fscanf(STDIN, "%d", $t);
 $a = trim(fgets(STDIN));
$t=explode(' ', $a);
foreach ($t as $d){@$k[$d]++;}
rsort($k);
printf("%d %d\n", $k[0], count($k));
?>

<?php

        fscanf(STDIN,"%d\n",$n);
        $arr2 = explode(' ', trim(fgets(STDIN)));
		foreach($arr2 as $value) {
                $arr[$value]++;
        }
        $c = count($arr);
        arsort($arr);
        $h = current($arr);
        print($h.' '.$c."\n");

?>

<?php
$n = trim(fgets(STDIN));
$in = explode(' ',trim(fgets(STDIN)));
$r = array_count_values($in);
rsort($r);
echo($r[0].' '.count($r));

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

$tree = explode(' ',trim(fgets(STDIN)));
sort($tree);

$count = array_values( array_unique($tree) );
$max = 0;

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

   if( array_value_count($count[$i],$tree) > $max ){
        $max = array_value_count($count[$i], $tree);
   }
}

/*
 * Ищет сколько раз было найдено значение в массиве
 */
function array_value_count( $match, $array ){
    $count = 0;

    foreach( $array as $key => $value ){
        if( $value == $match ){
            $count++;
        }
    }
    return $count;
}

echo $max.' '.count( $count );

<?php

$fl = STDIN;//fopen("input.txt","r");
$n=trim(fgets($fl));
$a=explode(' ',trim(fgets($fl)));
$mx=0;
foreach($a as $k=>$v)
{
    $b[$v]++;
    $mx=max($mx,$b[$v]);
}
printf("%d %d\n",$mx,count($b));
//for(fscanf($fl,"%d",$n),$a=array(),$i=0;$i<$n;++$i,fscanf($fl,"%d",$a[$i]));
//var_dump($a);
//echo $a;
?>

<?php
    $stdin = fopen('php://stdin', 'r');
    $stdout = fopen('php://stdout', 'w');

    $n = fgets($stdin);
    $lenghts = explode(" ", fgets($stdin));
    $lenghts[$n-1] = intval($lenghts[$n-1]);

    $tmp = array_count_values($lenghts);
    fputs($stdout, max($tmp) . " " . count($tmp));
?>

<?php
$f = file_get_contents('php://stdin');
$str = explode("\n", $f);
$e = explode(" ", trim($str[1]));
$max = 0;
$c = array();
$sum = 0;
foreach ($e as $k=>$v) {
    if (!isset($c[$v])) {$c[$v] = 1;$sum++;}
    else {$c[$v]++;}
    if ($max < $c[$v]) {$max = $c[$v];}
}

echo $max." ".$sum;

<?php

$n = trim(fgets(STDIN));

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

$number = array_count_values($l);

$total = count($number);

//echo $total;

//print_r ($number);

rsort($number);

echo ($number[0].' '.$total);
?>

<?php
    define('DEBUG', 0);

    if(DEBUG) $GLOBALS['file'] = fopen('input.txt', 'r');
    function debug($var){echo '<pre>';print_r($var);echo '</pre>';}
    function read_line()
    {
        if(DEBUG) { $file = $GLOBALS['file'];$line = trim(fgets($file));}
        else $line = trim(fgets(STDIN));
        return $line;
    }
    function get_array($line){return explode(' ', $line);}
    function read_array(){return get_array(read_line());}
    //echo "$s\n";
    /*****************************************************************/

    read_line();
    $arr = read_array();

    $b = array();

    foreach($arr as $item)
    {
        if(isset($b[$item])) $b[$item]++;
        else $b[$item]=1;
    }

    $count = count($b);
    $max = max($b);

    echo "{$max} {$count}";
?>

<?php
$n = trim(fgets(STDIN));
$mas = explode(' ', trim(fgets(STDIN)));

echo max(array_count_values($mas)) . " " . count(array_count_values($mas));

?>

<?php
// 37A  Башни
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$n = (int) $input_line;

$input_line = fgets($in);
$arr = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

sort($arr);

$max = $imax = $col = 1;

for ($i=1; $i < $n; $i++) {
    if ($arr[$i] !== $arr[$i-1]) {
       $col ++;
       $imax = 1;
    } else {
        $imax ++;
        if ($imax > $max) $max = $imax;
    }
}

echo "$max $col";

?>

<?php

fscanf(STDIN, "%d\n", $quantity);
$line = trim(fgets(STDIN));

$lengths = explode(' ', $line);
$quant = array_count_values($lengths);
$max = 0;
$num = 0;
$max = max($quant);

$towerQuantity = count($quant);
echo $max . ' '. $towerQuantity;

?>

<?php
fscanf(STDIN, "%d",$n);
$items = explode(" ",trim(fgets(STDIN)));
foreach ($items as $k)
	$gr[$k]++;
echo max($gr)." ".count($gr);
?>

<?php
$n=trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
foreach($arr as $v)
    $newarr[$v]++;
$max=max($newarr);
$count=sizeof($newarr);
printf('%.0f',$max);
echo " ";
printf('%.0f',$count);
?>

<?
$n=trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
foreach($arr as $v)
    $newarr[$v]++;
$max=max($newarr);
$count=sizeof($newarr);
printf('%.0f',$max);
echo " ";
printf('%.0f',$count);
?>

<?php

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

$b = array();
foreach($l as $v) $b[$v]++;

print max($b).' '.count($b);

?>

<?php
error_reporting("off");
//37A: Towers
$n = trim(fgets(STDIN)); //$n = 3;
$l = explode(" ", trim(fgets(STDIN))); //$l = explode(" ", "1 2 3");
$unique = array_unique($l);
$difvalues = count($unique);
$values = array_count_values($l);
rsort($values);
$mode = $values[0];
$line = $mode." ".$difvalues;
echo $line;
?>

<?php

	fscanf(STDIN,"%d\n",$n);
	for ($i = 0;$i<$n;$i++) {
		fscanf(STDIN,"%d ",$m);
		$arr[$m]++;
	}
	foreach($arr2 as $value) {
		$arr[$value] = $arr[$value]+1;
	}
	$c = count($arr);
	asort($arr);
	$h = current($arr);
	print($h.' '.$c."\n");

?>

<?php

	fscanf(STDIN,"%d\n",$n);
	fscanf(STDIN,"%s\n",$string);
	$arr2 = split(' ', $string);
	foreach($arr2 as $value) {
		$arr[$value]++;
	}
	$c = count($arr);
	arsort($arr);
	$h = current($arr);
	print($h.' '.$c."\n");

?>

<?php

        fscanf(STDIN,"%d\n",$n);
        for ($i = 0;$i<$n;$i++) {
                fscanf(STDIN,"%d ",$m);
                $arr[$m]++;
        }
        $c = count($arr);
        arsort($arr);
        $h = current($arr);
        print($h.' '.$c);

?>

<?php

	fscanf(STDIN,"%d\n",$n);
	for ($i = 0;$i<$n;$i++) {
		fscanf(STDIN,"%d ",$m);
		$arr[$m]++;
	}
	$c = count($arr);
	asort($arr);
	$h = current($arr);
	print($h.' '.$c."\n");

?>

<?php

$fl = STDIN;//fopen("input.txt","r");
$n=fgets($fl);
$a=explode(' ',fgets($fl));
$mx=0;
foreach($a as $k=>$v)
{
    $b[$v]++;
    $mx=max($mx,$b[$v]);
}
printf("%d %d\n",$mx,count($b));
//for(fscanf($fl,"%d",$n),$a=array(),$i=0;$i<$n;++$i,fscanf($fl,"%d",$a[$i]));
//var_dump($a);
//echo $a;
?>

<?php
    $stdin = fopen('php://stdin', 'r');
    $stdout = fopen('php://stdout', 'w');

    $n = fgets($stdin);
    $lenghts = explode(" ", fgets($stdin));

    $tmp = array_count_values($lenghts);
    fputs($stdout, max($tmp) . " " . count($tmp));
?>

<?php
$f = file_get_contents('php://stdin');
$str = explode("\n", $f);
$e = explode(" ", $str[1]);
$max = 0;
$c = array();
$sum = 0;
foreach ($e as $k=>$v) {
    if (!isset($c[$v])) {$c[$v] = 1;$sum++;}
    else {$c[$v]++;}
    if ($max < $c[$v]) {$max = $c[$v];}
}

echo $max." ".$sum;

<?php
$f = file_get_contents('php://stdin');
$str = explode("\n", $f);
$e = explode(" ", $str[1]);
$max = 0;
$c = array();
$sum = 0;
foreach ($e as $v) {
    if (!isset($c[$v])) {$c[$v] = 1;$sum++;}
    else {$c[$v]++;}
    if ($max < $c[$v]) {$max = $c[$v];}
}

echo $max." ".$sum;

<?php
$f = file_get_contents('php://stdin');
$str = explode("\n", $f);

$errors = 0;
if ($str[0] == 4 && $str[1] != "6 5 6 7") $errors = 1;

unset($str[0]);
$str2 = implode("", $str);

$e = explode(" ", $str2);
$max = 0;
$c = array();
$sum = 0;

foreach ($e as $k=>$v) {
    if (!isset($c[$v])) {$c[$v] = 1;$sum++;}
    else {$c[$v]++;}
    if ($max < $c[$v]) {$max = $c[$v];}
}

echo $max." ".$sum;
if ($errors == 1) {
echo '".$str2."';
print_r($str);
print_r($c);
}

<?php
$f = file_get_contents('php://stdin');
$str = explode("\n", $f);

unset($str[0]);
$str2 = implode("", $str);

$e = explode(" ", $str2);
$max = 0;
$c = array();
$sum = 0;

foreach ($e as $k=>$v) {
    if (!isset($c[$v])) {$c[$v] = 1;$sum++;}
    else {$c[$v]++;}
    if ($max < $c[$v]) {$max = $c[$v];}
}

echo $max." ".$sum;

<?php
$f = file_get_contents('php://stdin');
$str = explode("\n", $f);
$e = explode(" ", $str[1]);
$max = 0;
$c = array();
$sum = 0;
foreach ($e as $v) {
    if (!isset($c[$v])) {$c[$v] = 1;$sum++;}
    else {$c[$v]++;}
    if ($max < $c[$v]) {$max = $c[$v];}
}
$r = $max." ".$sum;
printf('%s', $r);

<?php
	fscanf(STDIN, "%d",$n);
        $items = explode(" ",fgets(STDIN));
	foreach ($items as $k)
	  $gr[$k]++;
  	echo max($gr)." ".count($gr);
?>

<?php
	fscanf(STDIN, "%d",$n);
	fscanf(STDIN, "%s",$s);
	$items = explode(" ", $s);
	foreach ($items as $k)
	  $gr[$k]++;
        echo max($gr)." ".count($gr);
?>

<?php
	fscanf(STDIN, "%d",$n);
	fscanf(STDIN, "%s",$s);
	$items = explode(" ", $s);
	foreach ($items as $k){
	  $gr[$k]++;
	}
	echo $s." ".max($gr)." ".count($gr);
?>

<?php
	fscanf(STDIN, "%d",$n);
	fscanf(STDIN, "%s",$s);
	$items = explode(" ", $s);
	foreach ($items as $k){
	  $gr[$k]++;
	}
	echo max($gr)." ".count($gr);
?>

<?php
error_reporting("off");
//37A: Towers
$n = trim(fgets(STDIN));
$l = explode(" ", trim(fgets(STDIN)));
$unique = array_unique($l);
$difvalues = count($unique);
$values = array_count_values($l);
rsort($values);
$mode = $values[0];
$line = $unique." ".$mode;
echo $line;
?>

<?php
error_reporting("off");
//37A: Towers
$n = trim(fgets(STDIN));
$l = explode(" ", trim(fgets(STDIN)));
$unique = array_unique($l);
$difvalues = count($unique);
$values = array_count_values($l);
rsort($values);
$mode = $values[0];
$line = $unique." ".$mode;
?>


Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid also threw part of the pieces away. Having seen this, Vasya got terrified but still tried to restore the collection. He chose several piece pairs and glued each pair together so that each pair formed a lucky ticket. The rest of the pieces Vasya threw away reluctantly. Thus, after the gluing of the 2t pieces he ended up with t tickets, each of which was lucky.When Leonid tore the tickets in two pieces, one piece contained the first several letters of his number and the second piece contained the rest.Vasya can glue every pair of pieces in any way he likes, but it is important that he gets a lucky ticket in the end. For example, pieces 123 and 99 can be glued in two ways: 12399 and 99123.What maximum number of tickets could Vasya get after that?

The first line contains integer n (1 ≤ n ≤ 104) — the number of pieces. The second line contains n space-separated numbers ai (1 ≤ ai ≤ 108) — the numbers on the pieces. Vasya can only glue the pieces in pairs. Even if the number of a piece is already lucky, Vasya should glue the piece with some other one for it to count as lucky. Vasya does not have to use all the pieces. The numbers on the pieces an on the resulting tickets may coincide.

Print the single number — the maximum number of lucky tickets that will be able to be restored. Don't forget that every lucky ticket is made of exactly two pieces glued together.


A binary string is a string where each character is either 0 or 1. Two binary strings $$$a$$$ and $$$b$$$ of equal length are similar, if they have the same character in some position (there exists an integer $$$i$$$ such that $$$a_i = b_i$$$). For example:  10010 and 01111 are similar (they have the same character in position $$$4$$$);  10010 and 11111 are similar;  111 and 111 are similar;  0110 and 1001 are not similar. You are given an integer $$$n$$$ and a binary string $$$s$$$ consisting of $$$2n-1$$$ characters. Let's denote $$$s[l..r]$$$ as the contiguous substring of $$$s$$$ starting with $$$l$$$-th character and ending with $$$r$$$-th character (in other words, $$$s[l..r] = s_l s_{l + 1} s_{l + 2} \dots s_r$$$).You have to construct a binary string $$$w$$$ of length $$$n$$$ which is similar to all of the following strings: $$$s[1..n]$$$, $$$s[2..n+1]$$$, $$$s[3..n+2]$$$, ..., $$$s[n..2n-1]$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$). The second line of each test case contains the binary string $$$s$$$ of length $$$2n - 1$$$. Each character $$$s_i$$$ is either 0 or 1.

For each test case, print the corresponding binary string $$$w$$$ of length $$$n$$$. If there are multiple such strings — print any of them. It can be shown that at least one string $$$w$$$ meeting the constraints always exists.

NoteThe explanation of the sample case (equal characters in equal positions are bold):The first test case:   $$$\mathbf{1}$$$ is similar to $$$s[1..1] = \mathbf{1}$$$. The second test case:   $$$\mathbf{000}$$$ is similar to $$$s[1..3] = \mathbf{000}$$$;  $$$\mathbf{000}$$$ is similar to $$$s[2..4] = \mathbf{000}$$$;  $$$\mathbf{000}$$$ is similar to $$$s[3..5] = \mathbf{000}$$$. The third test case:   $$$\mathbf{1}0\mathbf{10}$$$ is similar to $$$s[1..4] = \mathbf{1}1\mathbf{10}$$$;  $$$\mathbf{1}01\mathbf{0}$$$ is similar to $$$s[2..5] = \mathbf{1}10\mathbf{0}$$$;  $$$\mathbf{10}1\mathbf{0}$$$ is similar to $$$s[3..6] = \mathbf{10}0\mathbf{0}$$$;  $$$1\mathbf{0}1\mathbf{0}$$$ is similar to $$$s[4..7] = 0\mathbf{0}0\mathbf{0}$$$. The fourth test case:   $$$0\mathbf{0}$$$ is similar to $$$s[1..2] = 1\mathbf{0}$$$;  $$$\mathbf{0}0$$$ is similar to $$$s[2..3] = \mathbf{0}1$$$.

<?php
fscanf(STDIN,"%d",$t);
while ($t--)
{
    fscanf(STDIN,"%d",$n);
    fscanf(STDIN,"%s",$str);
    if($n==1)
    	echo "$str\n";
    else
    {
    $str1=array();
    for ($i=0; $i <$n ; $i++)
     {
    	 $str1[$i]=substr($str,$i,$n);

     }
     $flag=0;
     for ($i=0; $i <$n ; $i++)
      { $count=0;
     	for ($j=0; $j <$n-1 ; $j++)
     	 {
     		if($str1[0][$i]==$str1[$j+1][$i])
     			$count++;
     		if($count==$n-1)
     		{
     			$flag=1;
     			echo str_repeat($str1[0][$i],$n)."\n";

     			break;
     		}
     	 }
     	 if($flag==1)
     	 	break;
     	 //echo "count=$count\n";
      }
      if($flag==0)
      	echo str_repeat('0',$n)."\n";

    }

}


While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface.  Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$?

The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$).

Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = (pow($b, 2) - pow($a, 2)) / (2 * $a);
print number_format($c, 6, ".", "");
?>

<?php
$line = "";
if (PHP_OS == 'WINNT') {
  $line = stream_get_line(STDIN, 1024, PHP_EOL);
} else {
  $line = readline('$ ');
}

$params = explode(" ", $line);
$H = $params[0];
$L = $params[1];

$A = (($L*$L) - ($H*$H)) / (2*$H);

echo $A;

<?php
$line = "";
if (PHP_OS == 'WINNT') {
  echo '$ ';
  $line = stream_get_line(STDIN, 1024, PHP_EOL);
} else {
  $line = readline('$ ');
}

$params = explode(" ", $line);
$H = $params[0];
$L = $params[1];

$A = (($L*$L) - ($H*$H)) / (2*$H);

echo $A;

// $output = $line;

// echo($output);


Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that also lies in the range from 1 to 109, inclusive. It is not allowed to replace a number with itself or to change no number at all. After the replacement Petya sorted the array by the numbers' non-decreasing. Now he wants to know for each position: what minimum number could occupy it after the replacement and the sorting.

The first line contains a single integer n (1 ≤ n ≤ 105), which represents how many numbers the array has. The next line contains n space-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive.

Print n space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = max($b);
if($c == 1)
{
     $b[0] = 2;
     sort($b);
}
else
{
     sort($b);
     array_unshift($b, 1);
     unset($b[$a]);
}
print implode(" ", $b);
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_unique($b);
if((count($c) == 1) && ($c[0] == 1))
{
    unset($b[$a - 1]);
    array_push($b, 2);
    sort($b);
    print implode(" ", $b);
}
else
{
    array_unshift($b, 1);
    unset($b[$a]);
    sort($b);
    print implode(" ", $b);
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
array_unshift($b, " ");
unset($b[0]);
$c = min($b);
$d = max($b);
$e = array_search($c, $b);
$d = array_search($d, $b);
if(($b[$e] == 1) && ($b[$d] == 1))
{
    unset($b[$d]);
    array_push($b, 2);
    print implode(" ", $b);
}
else
{
    unset($b[$d]);
    array_unshift($b, 1);
    print implode(" ", $b);
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_unique($b);
if((count($c) == 1) && ($c[0] == 1))
{
    unset($b[$a - 1]);
    array_push($b, 2);
    print implode(" ", $b);
}
else
{
    array_unshift($b, 1);
    unset($b[$a]);
    print implode(" ", $b);
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
array_unshift($b, 1);
unset($b[$a]);
print implode(" ", $b);
?>


You are given an equation:  Ax2 + Bx + C = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order.

The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0.

In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.

<?php
$input=trim(fgets(STDIN));
list($a, $b, $c)= explode(" ", $input)  ;
$arg=$b*$b -4*($a*$c);
$bne=-$b;
$a2=2*$a;
$topplus=$bne + sqrt($arg);
$topmins=$bne - sqrt($arg);
$x1=@($topplus / $a2);
$x2=@($topmins / $a2);
if ($a != 0) {
    if ($arg == 0){
       echo "1";
       $turbo = PHP_EOL.number_format($x1, 10, '.', '');;
      }elseif ($arg > 0) {
       echo "2";
        if ($x2 > $x1) {
        $turbo= PHP_EOL.number_format($x1, 10, '.', '').PHP_EOL.number_format($x2, 10, '.', '');
        }else $turbo= PHP_EOL.number_format($x2, 10, '.', '').PHP_EOL.number_format($x1, 10, '.', '');
    }elseif ($arg < 0) {
       echo "0";
 }
}elseif ($a== 0 and $b == 0 and $c == 0) {
    $turbo= -1;
}elseif ($a==0 and $b ==0) {
 echo 0;
}elseif ($c != 0 or $b != 0)  {
echo 1;
$turbo= PHP_EOL.number_format(-$c/$b, 10, '.', '');
    }else echo 0;

echo $turbo;
?>

<?php
$input=trim(fgets(STDIN));
list($a, $b, $c)= explode(" ", $input)  ;
$arg=$b*$b -4*($a*$c);
$bne=-$b;
$a2=2*$a;
$topplus=$bne + sqrt($arg);
$topmins=$bne - sqrt($arg);
$x1=@($topplus / $a2);
$x2=@($topmins / $a2);
if ($a != 0) {
    if ($arg == 0){
       echo "1";
       $turbo = PHP_EOL.number_format($x1, 10, '.', '');;
      }elseif ($arg > 0) {
       echo "2";
        if ($x2 > $x1) {
        $turbo= PHP_EOL.number_format($x1, 10, '.', '').PHP_EOL.number_format($x2, 10, '.', '');
        }else $turbo= PHP_EOL.number_format($x2, 10, '.', '').PHP_EOL.number_format($x1, 10, '.', '');
    }elseif ($arg < 0) {
       echo "0";
 }
}elseif ($a== 0 and $b == 0 and $c == 0) {
    $turbo= -1;
}elseif ($c != 0 or $b != 0)  {
echo 1;
$turbo= PHP_EOL.number_format(-$c/$b, 10, '.', '');
    }else echo 0;

echo $turbo;
?>

<?php
$input=trim(fgets(STDIN));
list($a, $b, $c)= explode(" ", $input)  ;
$arg=$b*$b -4*($a*$c);
$bne=-$b;
$a2=2*$a;
$topplus=$bne + sqrt($arg);
$topmins=$bne - sqrt($arg);
$x1=@($topplus / $a2);
$x2=@($topmins / $a2);
if ($a != 0) {
    if ($arg == 0){
       echo "1";
       $turbo = PHP_EOL.number_format($x1, 10, '.', '');;
      }elseif ($arg > 0) {
       echo "2";
        if ($x2 > $x1) {
        $turbo= PHP_EOL.number_format($x1, 10, '.', '').PHP_EOL.number_format($x2, 10, '.', '');
        }else $turbo= PHP_EOL.number_format($x2, 10, '.', '').PHP_EOL.number_format($x1, 10, '.', '');
    }elseif ($arg < 0) {
       echo "0";
 }
}elseif ($a== 0 and $b == 0 and $c == 0) {
    $turbo= -1;
}elseif ($c != 0 and $b != 0)  {
echo 1;
$turbo= PHP_EOL.number_format(-$c/$b, 10, '.', '');
    }else echo 0;

echo $turbo;
?>


You are given an array $$$a$$$ that contains $$$n$$$ integers. You can choose any proper subsegment $$$a_l, a_{l + 1}, \ldots, a_r$$$ of this array, meaning you can choose any two integers $$$1 \le l \le r \le n$$$, where $$$r - l + 1 < n$$$. We define the beauty of a given subsegment as the value of the following expression:$$$$$$\max(a_{1}, a_{2}, \ldots, a_{l-1}, a_{r+1}, a_{r+2}, \ldots, a_{n}) - \min(a_{1}, a_{2}, \ldots, a_{l-1}, a_{r+1}, a_{r+2}, \ldots, a_{n}) + \max(a_{l}, \ldots, a_{r}) - \min(a_{l}, \ldots, a_{r}).$$$$$$Please find the maximum beauty among all proper subsegments.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Then follow the descriptions of each test case. The first line of each test case contains a single integer $$$n$$$ $$$(4 \leq n \leq 10^5)$$$ — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_{i} \leq 10^9$$$) — the elements of the given array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each testcase print a single integer — the maximum beauty of a proper subsegment.

NoteIn the first test case, the optimal segment is $$$l = 7$$$, $$$r = 8$$$. The beauty of this segment equals to $$$(6 - 1) + (5 - 1) = 9$$$.In the second test case, the optimal segment is $$$l = 2$$$, $$$r = 4$$$. The beauty of this segment equals $$$(100 - 2) + (200 - 1) = 297$$$.

<?php
/**
 * https://codeforces.com/contest/1720/problem/B
 * input:
 * 4
 * 8
 * 1 2 2 3 1 5 6 1
 * 5
 * 1 2 3 100 200
 * 4
 * 3 3 3 3
 * 6
 * 7 8 3 1 1 8
 */

// it is working fine on lap but not on codeforces
function inputArray($sys)
{
    fscanf($sys, "%[^\n]", $tempA);
    $arr = array_map('intval', preg_split('/ /', $tempA, -1, PREG_SPLIT_NO_EMPTY));
    return $arr;
}
$cin = fopen("php://stdin", "r");
$cout = fopen("php://stdout", "w");

$t;
fscanf($cin, "%d\n", $t);
$result = array();
for ($T = 0; $T < $t; $T++) {
    $n = 0;
    $max1 = 0;
    $max2 = 0;
    $min1 = 1000000001;
    $min2 = 1000000001;
    fscanf($cin, "%d\n", $n);
    $arr = inputArray($cin);
    $rev = array_reverse($arr);
    for ($i = 0; $i < $n; $i++) {
        $num = array_pop($rev);
        if ($num >= $max1) {
            $max2 = $max1;
            $max1 = $num;
        }
        else if ($num >= $max2) {
            $max2 = $num;
        }
        if ($num <= $min1) {
            $min2 = $min1;
            $min1 = $num;
        }
        else if ($num <= $min2) {
            $min2 = $num;
        }

    }
    $value = $max1 - $min1 + $max2 - $min2;
    array_push($result, $value);
}
foreach ($result as $item) {
    echo $item . "\n";
}
?>

<?php

$inp = fopen('php://stdin', 'rb');

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

while ($t--) {
    fscanf($inp, '%d', $n);

    $arr = fscanf($inp, str_repeat('%d ', $n));

    sort($arr);

    $minValues = array_slice($arr, 0, 2);
    $maxValues = array_slice($arr, -2);

    echo (array_sum($maxValues) - array_sum($minValues)).PHP_EOL;
}

fclose($inp);

<?php
/**
 * https://codeforces.com/contest/1720/problem/B
 * input:
 * 4
 * 8
 * 1 2 2 3 1 5 6 1
 * 5
 * 1 2 3 100 200
 * 4
 * 3 3 3 3
 * 6
 * 7 8 3 1 1 8
 */

function inputArray($sys)
{
    fscanf($sys, "%[^\n]", $tempA);
    $arr = array_map('intval', preg_split('/ /', $tempA, -1, PREG_SPLIT_NO_EMPTY));
    return $arr;
}
$cin = fopen("php://stdin", "r");
$cout = fopen("php://stdout", "w");

$t;
fscanf($cin, "%d\n", $t);
$result = array();
for ($T = 0; $T < $t; $T++) {
    $n;
    $num;
    $max1 = 0;
    $max2 = 0;
    $min1 = 1000000001;
    $min2 = 1000000001;
    fscanf($cin, "%d\n", $n);
    $arr = inputArray(fopen('php://stdin', 'r'));
    $rev = array_reverse($arr);
    for ($i = 0; $i < $n; $i++) {
        $num = array_pop($rev);
        if ($num >= $max1) {
            $max2 = $max1;
            $max1 = $num;
        }
        else if ($num >= $max2) {
            $max2 = $num;
        }
        if ($num <= $min1) {
            $min2 = $min1;
            $min1 = $num;
        }
        else if ($num <= $min2) {
            $min2 = $num;
        }

    }
    // fix for the second input
    $value = $max1 - $min1 + $max2 - $min2;
    array_push($result, $value);
}
foreach ($result as $item) {
    echo $item . "\n";
}
?>

<?php
$cin = fopen("php://stdin", "r");
$cout = fopen("php://stdout", "w");

$t;
fscanf($cin, "%d\n", $t);
$result = array();
for ($T = 0; $T < $t; $T++) {
    $n;
    $num;
    $max1 = 0;
    $max2 = 0;
    $min1 = 1000000001;
    $min2 = 1000000001;
    fscanf($cin, "%d\n", $n);
    for ($i = 0; $i < $n; $i++) {
        fscanf($cin, "%d\n", $num);
        if ($num >= $max1) {
            $max2 = $max1;
            $max1 = $num;
        }
        else if ($num >= $max2) {
            $max2 = $num;
        }
        if ($num <= $min1) {
            $min2 = $min1;
            $min1 = $num;
        }
        else if ($num <= $min2) {
            $min2 = $num;
        }

    }
    // fix for the second input
    $value = $max1 - $min1 + $max2 - $min2;
    array_push($result, $value);
}
foreach ($result as $item) {
    echo $item . "\n";
}
?>

<?php
$cin = fopen("php://stdin", "r");
$cout = fopen("php://stdout", "w");

$t;
fscanf($cin, "%d\n", $t);
$result = array();
for ($T = 0; $T < $t; $T++) {
    $n;
    $num;
    $max1 = 0;
    $max2 = 0;
    $min1 = 1000000001;
    $min2 = 1000000001;
    fscanf($cin, "%d\n", $n);
    for ($i = 0; $i < $n; $i++) {
        fscanf($cin, "%d\n", $num);
        if ($num >= $max1) {
            $max2 = $max1;
            $max1 = $num;
        }
        else if ($num >= $max2) {
            $max2 = $num;
        }
        if ($num <= $min1) {
            $min2 = $min1;
            $min1 = $num;
        }
        else if ($num <= $min2) {
            $min2 = $num;
        }

    }
    // fix for the second input
    $value = $max1 - $min1 + $max2 - $min2;
    array_push($result, $value);
}
print_r($result);
?>

<?php
$cin = fopen("php://stdin", "r");
$cout = fopen("php://stdout", "w");

$t;
fscanf($cin, "%d\n", $t);
for ($T = 0; $T < $t; $T++) {
    $n;
    $num;
    $max1 = 0;
    $max2 = 0;
    $min1 = 1000000001;
    $min2 = 1000000001;
    fscanf($cin, "%d\n", $n);
    for ($i = 0; $i < $n; $i++) {
        fscanf($cin, "%d\n", $num);
        if ($num >= $max1) {
            $max2 = $max1;
            $max1 = $num;
        }
        else if ($num >= $max2) {
            $max2 = $num;
        }
        if ($num <= $min1) {
            $min2 = $min1;
            $min1 = $num;
        }
        else if ($num <= $min2) {
            $min2 = $num;
        }

    }
    // fix for the second input
    $result = $max1 - $min1 + $max2 - $min2;
    fprintf($cout, $result);
}?>


Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with. Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length.Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100).

Print the single number — the maximum number of frames Nicholas can make for his future canvases.

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

<?php
$n=trim(fgets(STDIN));
$p=explode(" ", trim(fgets(STDIN)));

for($i=0;$i<$n;$i++){
    $l=trim($p[$i]);
    @$mas[$l]++;
}
$sum=0;
foreach($mas as $t){
    $sum=$sum+floor($t/2);

}
$sum=floor($sum/2);
if($sum<0){$sum=0;}
printf("%s", $sum);
?>

<?php
$input[0]=intval(trim(fgets(STDIN)));
$input[1]=explode(' ',trim(fgets(STDIN)));
sort($input[1]);
$pair=0;
for($i=0;$i<$input[0];$i++) {
    if(isset($input[1][$i+1]) && intval($input[1][$i]) === intval($input[1][$i+1])) {
        $pair++;
        $i++;
    }
}
$result = floor($pair/2);
echo( $result );

<?php
$n = trim(fgets(STDIN));
$pal = explode(' ', trim(fgets(STDIN)));

$mas = array_count_values($pal);

foreach ($mas as $k => $v)
{
    if ($v % 2 == 0)
        $s += $v / 2;
    else
        $s += floor($v / 2);
}
echo floor($s / 2);
?>

<?php

$n = intval(fgets(STDIN, 10241024));
$t = 0;
$s = trim(fgets(STDIN, 10241024));
$a = array_map('intval', explode(' ', $s));
sort($a);
$v0 = false;
foreach($a as $v) {
	if ($v0 !== $v) {
		$v0 = $v;
	} else {
		$t++;
		$v0 = false;
	}
}

echo(floor($t/2));
?>

<?php
$n=trim(fgets(STDIN));
$p=explode(" ", trim(fgets(STDIN)));

for($i=0;$i<$n;$i++){
    $l=trim($p[$i]);
    @$mas[$l]++;
}
$sum=0;
foreach($mas as $t){
    $sum=$sum+floor($t/2);
}

if(($sum/2)==ceil($sum/2)){
$sum=$sum/2;
}else{

$sum=($sum-2)/2;

}
if($sum<0){$sum=0;}
printf("%s", $sum);
?>

<?php

$n = fgets(STDIN, 1024);
$t = 0;
$s = fgets(STDIN, 1024);
$a = explode(' ', $s);
sort($a);
$v0 = false;
foreach($a as $v) {
	if ($v0 !== $v) {
		$v0 = $v;
	} else {
		$t++;
		$v0 = false;
	}
}

echo(floor($t/2));
?>


You are given $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$. With a cost of one coin you can perform the following operation:Choose one of these numbers and add or subtract $$$1$$$ from it.In particular, we can apply this operation to the same number several times.We want to make the product of all these numbers equal to $$$1$$$, in other words, we want $$$a_1 \cdot a_2$$$ $$$\dots$$$ $$$\cdot a_n = 1$$$. For example, for $$$n = 3$$$ and numbers $$$[1, -3, 0]$$$ we can make product equal to $$$1$$$ in $$$3$$$ coins: add $$$1$$$ to second element, add $$$1$$$ to second element again, subtract $$$1$$$ from third element, so that array becomes $$$[1, -1, -1]$$$. And $$$1\cdot (-1) \cdot (-1) = 1$$$.What is the minimum cost we will have to pay to do that?

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

Output a single number — the minimal number of coins you need to pay to make the product equal to $$$1$$$.

NoteIn the first example, you can change $$$1$$$ to $$$-1$$$ or $$$-1$$$ to $$$1$$$ in $$$2$$$ coins.In the second example, you have to apply at least $$$4$$$ operations for the product not to be $$$0$$$.In the third example, you can change $$$-5$$$ to $$$-1$$$ in $$$4$$$ coins, $$$-3$$$ to $$$-1$$$ in $$$2$$$ coins, $$$5$$$ to $$$1$$$ in $$$4$$$ coins, $$$3$$$ to $$$1$$$ in $$$2$$$ coins, $$$0$$$ to $$$1$$$ in $$$1$$$ coin.

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$x= trim(fgets($handle));
$a = trim(fgets($handle));
$p = explode(' ', $a);
$cnt=0;
$less=1;
$ok=0;
for($i=0;$i<$x;$i++)
{
    if($p[$i]>0)
    {
        $cnt+=$p[$i]-1;

    }else if($p[$i]<0)
    {
        $cnt+=-1-$p[$i];
        $less*=-1;

    }else
    {
        $cnt++;
        $ok=1;
    }
}
if($ok || $less==1)
{
    echo $cnt;
}else
{
    echo $cnt+2;
}
?>

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$x= trim(fgets($handle));
$a = trim(fgets($handle));
$p = explode(' ', $a);
$cnt=0;
$less=0;
$ok=0;
for($i=0;$i<$x;$i++)
{
    if($p[$i]>0)
    {
        $cnt+=$p[$i]-1;

    }else if($p[$i]<0)
    {
        $cnt+=-1-$p[$i];
        $less*=-1;

    }else
    {
        $cnt++;
        $ok=1;
    }
}
if($ok || $less==1)
{
    echo $cnt;
}else
{
    echo $cnt+2;
}
?>


After a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are $$$n$$$ crossroads in the line in the town, and there is either the bus or the tram station at each crossroad.The crossroads are represented as a string $$$s$$$ of length $$$n$$$, where $$$s_i = \texttt{A}$$$, if there is a bus station at $$$i$$$-th crossroad, and $$$s_i = \texttt{B}$$$, if there is a tram station at $$$i$$$-th crossroad. Currently Petya is at the first crossroad (which corresponds to $$$s_1$$$) and his goal is to get to the last crossroad (which corresponds to $$$s_n$$$).If for two crossroads $$$i$$$ and $$$j$$$ for all crossroads $$$i, i+1, \ldots, j-1$$$ there is a bus station, one can pay $$$a$$$ roubles for the bus ticket, and go from $$$i$$$-th crossroad to the $$$j$$$-th crossroad by the bus (it is not necessary to have a bus station at the $$$j$$$-th crossroad). Formally, paying $$$a$$$ roubles Petya can go from $$$i$$$ to $$$j$$$ if $$$s_t = \texttt{A}$$$ for all $$$i \le t < j$$$. If for two crossroads $$$i$$$ and $$$j$$$ for all crossroads $$$i, i+1, \ldots, j-1$$$ there is a tram station, one can pay $$$b$$$ roubles for the tram ticket, and go from $$$i$$$-th crossroad to the $$$j$$$-th crossroad by the tram (it is not necessary to have a tram station at the $$$j$$$-th crossroad). Formally, paying $$$b$$$ roubles Petya can go from $$$i$$$ to $$$j$$$ if $$$s_t = \texttt{B}$$$ for all $$$i \le t < j$$$.For example, if $$$s$$$="AABBBAB", $$$a=4$$$ and $$$b=3$$$ then Petya needs:  buy one bus ticket to get from $$$1$$$ to $$$3$$$,  buy one tram ticket to get from $$$3$$$ to $$$6$$$,  buy one bus ticket to get from $$$6$$$ to $$$7$$$. Thus, in total he needs to spend $$$4+3+4=11$$$ roubles. Please note that the type of the stop at the last crossroad (i.e. the character $$$s_n$$$) does not affect the final expense.Now Petya is at the first crossroad, and he wants to get to the $$$n$$$-th crossroad. After the party he has left with $$$p$$$ roubles. He's decided to go to some station on foot, and then go to home using only public transport.Help him to choose the closest crossroad $$$i$$$ to go on foot the first, so he has enough money to get from the $$$i$$$-th crossroad to the $$$n$$$-th, using only tram and bus tickets.

Each test contains one or more test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The first line of each test case consists of three integers $$$a, b, p$$$ ($$$1 \le a, b, p \le 10^5$$$) — the cost of bus ticket, the cost of tram ticket and the amount of money Petya has. The second line of each test case consists of one string $$$s$$$, where $$$s_i = \texttt{A}$$$, if there is a bus station at $$$i$$$-th crossroad, and $$$s_i = \texttt{B}$$$, if there is a tram station at $$$i$$$-th crossroad ($$$2 \le |s| \le 10^5$$$). It is guaranteed, that the sum of the length of strings $$$s$$$ by all test cases in one test doesn't exceed $$$10^5$$$.

For each test case print one number — the minimal index $$$i$$$ of a crossroad Petya should go on foot. The rest of the path (i.e. from $$$i$$$ to $$$n$$$ he should use public transport).

5
2 2 1
BB
1 1 1
AB
3 2 8
AABBBBAABB
5 3 4
BBBBB
2 1 1
ABABAB


Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome.Gildong loves this concept so much, so he wants to play with it. He has $$$n$$$ distinct strings of equal length $$$m$$$. He wants to discard some of the strings (possibly none or all) and reorder the remaining strings so that the concatenation becomes a palindrome. He also wants the palindrome to be as long as possible. Please help him find one.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100$$$, $$$1 \le m \le 50$$$) — the number of strings and the length of each string. Next $$$n$$$ lines contain a string of length $$$m$$$ each, consisting of lowercase Latin letters only. All strings are distinct.

In the first line, print the length of the longest palindrome string you made. In the second line, print that palindrome. If there are multiple answers, print any one of them. If the palindrome is empty, print an empty line or don't print this line at all.

9 4
abab
baba
abcd
bcde
cdef
defg
wxyz
zyxw
ijji

NoteIn the first example, "battab" is also a valid answer.In the second example, there can be 4 different valid answers including the sample output. We are not going to provide any hints for what the others are.In the third example, the empty string is the only valid palindrome string.

<?php
    // $t = trim(fgets(STDIN));

    // for($i=0; $i<$t; $i++) {
    //     list($x, $y, $a, $b) =  explode(' ', trim(fgets(STDIN)));

    //     if(($y-$x) % ($a+$b) == 0) {
    //       echo ($y-$x) / ($a+$b)."\n";
    //     } else {
    //         echo "-1\n";
    //     }

    // }

   list($n, $m) = explode(' ', trim(fgets(STDIN)));
   $array = [];
   $tmp = [];

   for($i =0; $i < $n; $i++) {
       $s = trim(fgets(STDIN));
       $palindrom = 1;
       $t = ceil($m/2);
       for($j=0; $j<$t; $j++) {
           if($m - 1 - $j > $j && $s[$j] != $s[$m-1 - $j]) {
              $palindrom  = 0;
           }

       }
       $ar['text'] = $s;
       $ar['palindrom'] = $palindrom;
       $array[$s] = $ar;
       $tmp[] = $ar;
   }

    for($i =0; $i < $n; $i++) {
       $text = $tmp[$i]['text'];
       if(isset($array[$text])) {
           for($q = 1; $q < $n; $q++) {
               if($q != $i){
                   $text2 = $tmp[$q]['text'];
                   $p = 1;
                    for($j=0; $j<$m; $j++) {
                       if($text[$j] != $text2[$m-1 - $j]) {
                          $p  = 0;
                          break;
                       }
                   }
                   if($p == 1 ) {
                      $array[$text]['p_text'] = $text2;
                      unset($array[$text2]);
                      break;
                   }
               }

           }
       }

   }

   $countP = 0;
   $string = '';
   foreach ($array as $key => $a) {

       if(!isset($a['p_text']) && $a['palindrom'] == 1 && $countP == 0) {
           $countP ++;
           $string .= $array[$key]['text'];
       }
   }

   foreach ($array as  $a) {
       if(isset($a['p_text'])) {
           $string =$a['text']. $string . $a['p_text'];
       }
   }

  if(strlen($string)) {
      echo strlen($string) ."\n". $string. "\n";
  } else {
      echo "0\n";
  }


One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not exactly paper the walls with the oversupply). After considerable brain racking and some pre-estimating, the sponsor representatives ordered a certain number of T-shirts of sizes S, M, L, XL and XXL. The T-shirts turned out to bring good luck, that's why on the contest day there built up a line of K participants willing to get one. Every contestant is characterized by his/her desired T-shirt size (so it happens that for all the participants it is also one of the sizes S, M, L, XL and XXL). The participants come up to get a T-shirt one by one and try to choose the most suitable one, choosing it like this. If there is still a T-shirt of the optimal size left, that he/she takes it without further ado. Otherwise the contestant would prefer to choose a T-shirt with the size as close to the optimal one as possible (the distance between neighboring sizes is considered equal to one). If the variant of choice is not unique, the contestant will take a T-shirt of a bigger size (in case he/she grows more). For example, for a person whose optimal size is L the preference list looks like this: L, XL, M, XXL, S. Using the data on how many T-shirts of every size had been ordered by the organizers, on the size of contestants in the line determine who got a T-shirt of what size.

The first line contains five non-negative integers NS, NM, NL, NXL, NXXL not exceeding 1000 which represent the number of T-shirts of the corresponding sizes. The second line contains an integer K (1 ≤ K ≤ 1000) which represents the number of participants. The next K lines contain the optimal T-shirt sizes for the contestants. The sizes are given in the order in which the participants stand in the line. It is guaranteed that NS + NM + NL + NXL + NXXL ≥ K.

For each contestant, print a line containing the size of the T-shirt he/she got.


You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either grass or weeds. For example, a 4 × 5 garden may look as follows (empty cells denote grass):  You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction — either left or right. And initially, you face right.In one move you can do either one of these:1) Move one cell in the direction that you are facing.  if you are facing right: move from cell (r, c) to cell (r, c + 1)     if you are facing left: move from cell (r, c) to cell (r, c - 1)    2) Move one cell down (that is, from cell (r, c) to cell (r + 1, c)), and change your direction to the opposite one.  if you were facing right previously, you will face left     if you were facing left previously, you will face right    You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.What is the minimum number of moves required to mow all the weeds?

The first line contains two integers n and m (1 ≤ n, m ≤ 150) — the number of rows and columns respectively. Then follow n lines containing m characters each — the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.  It is guaranteed that the top-left corner of the grid will contain grass.

Print a single number — the minimum number of moves required to mow all the weeds.

NoteFor the first example, this is the picture of the initial state of the grid:  A possible solution is by mowing the weeds as illustrated below:


The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all i from 1 to n, inclusive). You need to help him cope with this task.Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added).

The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of houses in the capital of Berland. The second line contains n space-separated positive integers hi (1 ≤ hi ≤ 109), where hi equals the number of floors in the i-th house.

Print n integers a1, a2, ..., an, where number ai is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then ai should be equal to zero. All houses are numbered from left to right, starting from one.

<?php
function getInputString(){
    return trim(fgets(STDIN));
}
$housCount = getInputString();
$floors = getInputString();
$floors = explode(' ',$floors);
$out = array();
$max = 0;
for($i = $housCount; $i>0; $i--){
    $out[$i] = max(0, $max + 1 - $floors[$i-1]);
    $max = max($max,$floors[$i-1]);
}
$out = array_reverse($out);
$out = implode(' ',$out);
fwrite(STDOUT,$out);

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$n = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
array_unshift($aArray, "T");
unset($aArray[0]);
$rArray[$n] = 0;
$max = $aArray[$n];
for ($i = $n-1; $i >0; $i--) {
    if ($aArray[$i]>$max) {
        $rArray[$i] = 0;
        $max = $aArray[$i];
    } else {
        $rArray[$i] = $max - $aArray[$i] + 1;
    }
}
for ($i = 1; $i <= $n; $i++) {
    echo $rArray[$i] . " ";
}

<?
$file = STDIN;
$n = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
array_unshift($aArray, "T");
unset($aArray[0]);
$rArray[$n] = 0;
$max = $aArray[$n];
for ($i = $n-1; $i >0; $i--) {
    if ($aArray[$i]>$max) {
        $rArray[$i] = 0;
        $max = $aArray[$i];
    } else {
        $rArray[$i] = $max - $aArray[$i] + 1;
    }
}
for ($i = 1; $i <= $n; $i++) {
    echo $rArray[$i] . " ";
}

<?php
function getInputString(){
    return trim(fgets(STDIN));
}
$housCount = getInputString();
$floors = getInputString();
$floors = explode(' ',$floors);
$out = array();
$max = 0;
for($i = $housCount; $i>0; $i--){
    $max = max($max,$floors[$i-1]);
    $out[$i-1] = $max - $floors[$i-1];
    if($out[$i-1]>0){
        $out[$i-1] = strval($out[$i-1]+1);
    }

}
$out = array_reverse($out);
$out = implode(' ',$out);
fwrite(STDOUT,$out);

<?php
function getInputString(){
    return trim(fgets(STDIN));
}
$housCount = getInputString();
$floors = getInputString();
$floors = explode(' ',$floors);
$out = array();
$max = 0;
for($i = $housCount; $i>0; $i--){
    $out[$i] = max(0, $max + 1 - $floors[$i-1]);
}
$out = array_reverse($out);
$out = implode(' ',$out);
fwrite(STDOUT,$out);

<?php
function getInputString(){
    return trim(fgets(STDIN));
}
$housCount = getInputString();
$floors = getInputString();
$floors = explode(' ',$floors);
$out = array();
$max = 0;
for($i = $housCount; $i>0; $i--){
    $max = max($max,$floors[$i-1]);
    $out[$i-1] = $max - $floors[$i-1];
    if($out[$i-1]>0){
        $out[$i-1]++;
    }

}
$out = array_reverse($out);
$out = implode(' ',$out);
fwrite(STDOUT,$out);

<?php
function getInputString(){
    return trim(fgets(STDIN));
}
$housCount = getInputString();
$floors = getInputString();
$floors = explode(' ',$floors);
$out = array();
$max = 0;
for($i = $housCount; $i>0; $i--){
    $max = max($max,$floors[$i-1]);
    $out[$i-1] = $max - $floors[$i-1];
    if($out[$i-1]>0){
        $out[$i-1]++;
    }

}
$out = implode(' ',$out);
fwrite(STDOUT,$out);