You have given an array $$$a$$$ of length $$$n$$$ and an integer $$$x$$$ to a brand new robot. What the robot does is the following: it iterates over the elements of the array, let the current element be $$$q$$$. If $$$q$$$ is divisible by $$$x$$$, the robot adds $$$x$$$ copies of the integer $$$\frac{q}{x}$$$ to the end of the array, and moves on to the next element. Note that the newly added elements could be processed by the robot later. Otherwise, if $$$q$$$ is not divisible by $$$x$$$, the robot shuts down.Please determine the sum of all values of the array at the end of the process.

The first input line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \leq n \leq 10^5$$$, $$$2 \leq x \leq 10^9$$$) — the length of the array and the value which is used by the robot. The next line contains integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the initial values in the array. It is guaranteed that the sum of values $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case output one integer — the sum of all elements at the end of the process.

NoteIn the first test case the array initially consists of a single element $$$[12]$$$, and $$$x=2$$$. After the robot processes the first element, the array becomes $$$[12, 6, 6]$$$. Then the robot processes the second element, and the array becomes $$$[12, 6, 6, 3, 3]$$$. After the robot processes the next element, the array becomes $$$[12, 6, 6, 3, 3, 3, 3]$$$, and then the robot shuts down, since it encounters an element that is not divisible by $$$x = 2$$$. The sum of the elements in the resulting array is equal to $$$36$$$.In the second test case the array initially contains integers $$$[4, 6, 8, 2]$$$, and $$$x=2$$$. The resulting array in this case looks like $$$ [4, 6, 8, 2, 2, 2, 3, 3, 4, 4, 1, 1, 1, 1, 1, 1]$$$.

<?php
function solve() {
    list($n, $x) = explode(' ', Read::string());
    $a = Read::array_int();
    $b = [];
    for ($i = 0; $i < $n; $i++) {
        $k = $a[$i];
        $b[$i] = 1;
        while ($k % $x  == 0) {
            $k = $k / $x;
            $b[$i] +=1;
        }
    }
    $min = min($b);
    $iSum = 0;
    $iCounter = 1;
    for ($i = 0; $i < $n; $i++) {
        if ($min == $b[$i]) {
            $iCounter = 0;
        }
        $iSum = Bigint::add($iSum, $a[$i] * ($min + $iCounter));
    }

    return $iSum;
}

#$t = 1;
$t = Read::int();
while ($t--) {
    echo solve();
    echo "\n";
}

class Read
{
    public static function string()
    {
        return trim(fgets(STDIN));
    }

    public static function int()
    {
        return intval(fgets(STDIN));
    }

    public static function array_int($sep = ' ')
    {
        $s = trim(fgets(STDIN));
        return preg_split("/[\s,]+/", $s);
    }

}

class Bigint
{
    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 / $bigint2
     */
    public static function div($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcmod($bigint1, $bigint2) == 0 ? bcdiv($bigint1, $bigint2) : bcadd(bcdiv($bigint1, $bigint2), 1);
            case 'floor':
                return bcdiv($bigint1, $bigint2);
            case 'round':
                $sResult = bcdiv($bigint1, $bigint2);
                return bcsub(bcdiv($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcdiv($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 + $bigint2
     */
    public static function add($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcadd($bigint1, $bigint2);
            case 'round':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcadd($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 - $bigint2
     */
    public static function sub($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcsub($bigint1, $bigint2);
            case 'round':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsub($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 * $bigint2
     */
    public static function mul($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcmul($bigint1, $bigint2);
            case 'round':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcmul ($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @return string $bigint1 % $bigint2
     */
    public static function mod($bigint1, $bigint2) {
        return bcmod($bigint1, $bigint2);
    }

    /**
     * @param string $bigint
     * @param string $scale (ceil or floor or round)
     * @return string sqrt($bigint)
     */
    public static function sqrt($bigint, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcadd(bcsqrt ($bigint), 1);
            case 'floor':
                return bcsqrt($bigint);
            case 'round':
                $sResult = bcsqrt($bigint);
                return bcsub(bcsqrt($bigint, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsqrt($bigint);
        }
    }

    /**
     * @param string $bigint
     * @param string $exponent
     * @param string $scale (ceil or floor or round)
     * @return string pow($bigint, $exponent)
     */
    public static function pow($bigint, $exponent, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcpow($bigint, $exponent);
            case 'round':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcpow ($bigint, $exponent);
        }
    }
}

class Algorithms
{

    /** Факторизация - Разложение числа на простые множители
     * @param int $n
     * @return array
     */
    public static function factorization($n)
    {
        $a = [];
        for ($i = 2; $i * $i <= $n; ++$i) {
            $cnt = 0;
            while (bcmod($n, $i) == 0) {
                ++$cnt;
                $n = bcdiv($n, $i);
            }
            if ($cnt > 0) {
                $a[$i] = $cnt;
            }
        }
        if ($n > 1) {
            $a[$n] = 1;
        }

        return $a;
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наибольший общий делитель (НОД)
     */
    public static function gcd($a, $b)
    {
        if ($b == 0) {
            return $a;
        } else {
            $a = $a % $b;
            return self::gcd($b, $a);
        }
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наименьшее общее кратное (НОК)
     */
    public static function lcm($a, $b)
    {
        return abs($a * $b) / self::gcd($a, $b);
    }

    /**Последовательность Фибоначчи =  0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987
     * return Фибоначчи{n}
     * @param int $n
     * @return int
     */
    public static function fibonacci($n)
    {
        $a = [0, 1];

        for ($i = 2; $i <= $n; $i++) {
            $a[$i] = $a[$i-1] + $a[$i-2];
        }

        return $a[$n];
    }

}

?>

<?php

$times = (int) trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($ni[], $xi[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $x = &$xi[$idx];
    $a = &$ai[$idx];
    $b = [];
    for ($i = 0; $i < $n; ++$i) {
        $cnt = 0;
        $tmp = $a[$i];
        while (0 == $tmp % $x) {
            $tmp /= $x;
            ++$cnt;
        }
        $b[] = $cnt;
    }
    $m = min($b);
    $sm = array_sum($a) * ($m + 1);
    for ($i = 0; $i < $n; ++$i) {
        if ($b[$i] > $m) {
            $sm += $a[$i];
        } else {
            break;
        }
    }
    echo nf($sm).PHP_EOL;
}
function nf($n)
{
    return number_format($n, 0, '', '');
}

<?php
function solve() {
    list($n, $x) = explode(' ', Read::string());
    $a = Read::array_int();
    $b = $a;
    $iSum = 0;
    $min = -1;
    for ($i = 0; $i < $n; $i++) {
        $iCounter2 = 1;
        while (Bigint::mod($a[$i], $x)  == 0 && ($min == -1 || $min > $iCounter2)) {
            $a[$i] = Bigint::div($a[$i], $x);
            $iCounter2 +=1;
        }
        $min = $min == -1 ? $iCounter2 : min($min, $iCounter2);
        $iSum = Bigint::add($iSum, Bigint::mul($b[$i], $min));
    }

    return $iSum;
}

#$t = 1;
$t = Read::int();
while ($t--) {
    echo solve();
    echo "\n";
}

class Read
{
    public static function string()
    {
        return trim(fgets(STDIN));
    }

    public static function int()
    {
        return intval(fgets(STDIN));
    }

    public static function array_int($sep = ' ')
    {
        $s = trim(fgets(STDIN));
        return preg_split("/[\s,]+/", $s);
    }

}

class Bigint
{
    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 / $bigint2
     */
    public static function div($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcmod($bigint1, $bigint2) == 0 ? bcdiv($bigint1, $bigint2) : bcadd(bcdiv($bigint1, $bigint2), 1);
            case 'floor':
                return bcdiv($bigint1, $bigint2);
            case 'round':
                $sResult = bcdiv($bigint1, $bigint2);
                return bcsub(bcdiv($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcdiv($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 + $bigint2
     */
    public static function add($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcadd($bigint1, $bigint2);
            case 'round':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcadd($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 - $bigint2
     */
    public static function sub($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcsub($bigint1, $bigint2);
            case 'round':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsub($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 * $bigint2
     */
    public static function mul($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcmul($bigint1, $bigint2);
            case 'round':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcmul ($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @return string $bigint1 % $bigint2
     */
    public static function mod($bigint1, $bigint2) {
        return bcmod($bigint1, $bigint2);
    }

    /**
     * @param string $bigint
     * @param string $scale (ceil or floor or round)
     * @return string sqrt($bigint)
     */
    public static function sqrt($bigint, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcadd(bcsqrt ($bigint), 1);
            case 'floor':
                return bcsqrt($bigint);
            case 'round':
                $sResult = bcsqrt($bigint);
                return bcsub(bcsqrt($bigint, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsqrt($bigint);
        }
    }

    /**
     * @param string $bigint
     * @param string $exponent
     * @param string $scale (ceil or floor or round)
     * @return string pow($bigint, $exponent)
     */
    public static function pow($bigint, $exponent, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcpow($bigint, $exponent);
            case 'round':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcpow ($bigint, $exponent);
        }
    }
}

class Algorithms
{

    /** Факторизация - Разложение числа на простые множители
     * @param int $n
     * @return array
     */
    public static function factorization($n)
    {
        $a = [];
        for ($i = 2; $i * $i <= $n; ++$i) {
            $cnt = 0;
            while (bcmod($n, $i) == 0) {
                ++$cnt;
                $n = bcdiv($n, $i);
            }
            if ($cnt > 0) {
                $a[$i] = $cnt;
            }
        }
        if ($n > 1) {
            $a[$n] = 1;
        }

        return $a;
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наибольший общий делитель (НОД)
     */
    public static function gcd($a, $b)
    {
        if ($b == 0) {
            return $a;
        } else {
            $a = $a % $b;
            return self::gcd($b, $a);
        }
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наименьшее общее кратное (НОК)
     */
    public static function lcm($a, $b)
    {
        return abs($a * $b) / self::gcd($a, $b);
    }

    /**Последовательность Фибоначчи =  0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987
     * return Фибоначчи{n}
     * @param int $n
     * @return int
     */
    public static function fibonacci($n)
    {
        $a = [0, 1];

        for ($i = 2; $i <= $n; $i++) {
            $a[$i] = $a[$i-1] + $a[$i-2];
        }

        return $a[$n];
    }

}

?>

<?php
function solve() {
    list($n, $x) = explode(' ', Read::string());
    $a = Read::array_int();
    $b = $a;
    $iSum = array_sum($a);
    $status = true;
    while($status) {
         for ($j = 0; $j < $n; $j++) {
            if ($a[$j] % $x  == 0) {
                $iSum += $b[$j];
                $a[$j] = $a[$j] / $x;
            } else {
                $status = false;
                break;
            }
        }
    }

    return $iSum;
}

#$t = 1;
$t = Read::int();
while ($t--) {
    echo solve();
    echo "\n";
}

class Read
{
    public static function string()
    {
        return trim(fgets(STDIN));
    }

    public static function int()
    {
        return intval(fgets(STDIN));
    }

    public static function array_int($sep = ' ')
    {
        $s = trim(fgets(STDIN));
        return preg_split("/[\s,]+/", $s);
    }

}

class Bigint
{
    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 / $bigint2
     */
    public static function div($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcmod($bigint1, $bigint2) == 0 ? bcdiv($bigint1, $bigint2) : bcadd(bcdiv($bigint1, $bigint2), 1);
            case 'floor':
                return bcdiv($bigint1, $bigint2);
            case 'round':
                $sResult = bcdiv($bigint1, $bigint2);
                return bcsub(bcdiv($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcdiv($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 + $bigint2
     */
    public static function add($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcadd($bigint1, $bigint2);
            case 'round':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcadd($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 - $bigint2
     */
    public static function bigintSub($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcsub($bigint1, $bigint2);
            case 'round':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsub($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 * $bigint2
     */
    public static function mul($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcmul($bigint1, $bigint2);
            case 'round':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcmul ($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @return string $bigint1 % $bigint2
     */
    public static function mod($bigint1, $bigint2) {
        return bcmod($bigint1, $bigint2);
    }

    /**
     * @param string $bigint
     * @param string $scale (ceil or floor or round)
     * @return string sqrt($bigint)
     */
    public static function sqrt($bigint, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcadd(bcsqrt ($bigint), 1);
            case 'floor':
                return bcsqrt($bigint);
            case 'round':
                $sResult = bcsqrt($bigint);
                return bcsub(bcsqrt($bigint, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsqrt($bigint);
        }
    }

    /**
     * @param string $bigint
     * @param string $exponent
     * @param string $scale (ceil or floor or round)
     * @return string pow($bigint, $exponent)
     */
    public static function pow($bigint, $exponent, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcpow($bigint, $exponent);
            case 'round':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcpow ($bigint, $exponent);
        }
    }
}

class Algorithms
{

    /** Факторизация - Разложение числа на простые множители
     * @param int $n
     * @return array
     */
    public static function factorization($n)
    {
        $a = [];
        for ($i = 2; $i * $i <= $n; ++$i) {
            $cnt = 0;
            while (bcmod($n, $i) == 0) {
                ++$cnt;
                $n = bcdiv($n, $i);
            }
            if ($cnt > 0) {
                $a[$i] = $cnt;
            }
        }
        if ($n > 1) {
            $a[$n] = 1;
        }

        return $a;
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наибольший общий делитель (НОД)
     */
    public static function gcd($a, $b)
    {
        if ($b == 0) {
            return $a;
        } else {
            $a = $a % $b;
            return self::gcd($b, $a);
        }
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наименьшее общее кратное (НОК)
     */
    public static function lcm($a, $b)
    {
        return abs($a * $b) / self::gcd($a, $b);
    }

    /**Последовательность Фибоначчи =  0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987
     * return Фибоначчи{n}
     * @param int $n
     * @return int
     */
    public static function fibonacci($n)
    {
        $a = [0, 1];

        for ($i = 2; $i <= $n; $i++) {
            $a[$i] = $a[$i-1] + $a[$i-2];
        }

        return $a[$n];
    }

}

?>

<?php
function solve() {
    list($n, $x) = explode(' ', Read::string());
    $a = Read::array_int();
    $iCounter = 0;
    $k = $a[0];
    while ($k % $x == 0) {
        $iCounter += 1;
        $k = $k / $x;
    }
    for ($i = 1; $i < $n; $i++) {
        $iCounter2 = 1;
        $k = $a[$i];
        while ($k % $x == 0) {
            $iCounter2 += 1;
            $k = $k / $x;
        }

        $iCounter = min($iCounter, $iCounter2);
    }
    $iSum = $a[0];
    for ($i = 0; $i < $n; $i++) {
        $iSum += $a[$i] * $iCounter;
    }

    return $iSum;
}

#$t = 1;
$t = Read::int();
while ($t--) {
    echo solve();
    echo "\n";
}

class Read
{
    public static function string()
    {
        return trim(fgets(STDIN));
    }

    public static function int()
    {
        return intval(fgets(STDIN));
    }

    public static function array_int($sep = ' ')
    {
        $s = trim(fgets(STDIN));
        return preg_split("/[\s,]+/", $s);
    }

}

class Bigint
{
    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 / $bigint2
     */
    public static function div($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcmod($bigint1, $bigint2) == 0 ? bcdiv($bigint1, $bigint2) : bcadd(bcdiv($bigint1, $bigint2), 1);
            case 'floor':
                return bcdiv($bigint1, $bigint2);
            case 'round':
                $sResult = bcdiv($bigint1, $bigint2);
                return bcsub(bcdiv($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcdiv($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 + $bigint2
     */
    public static function add($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcadd($bigint1, $bigint2);
            case 'round':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcadd($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 - $bigint2
     */
    public static function bigintSub($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcsub($bigint1, $bigint2);
            case 'round':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsub($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 * $bigint2
     */
    public static function mul($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcmul($bigint1, $bigint2);
            case 'round':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcmul ($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @return string $bigint1 % $bigint2
     */
    public static function mod($bigint1, $bigint2) {
        return bcmod($bigint1, $bigint2);
    }

    /**
     * @param string $bigint
     * @param string $scale (ceil or floor or round)
     * @return string sqrt($bigint)
     */
    public static function sqrt($bigint, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcadd(bcsqrt ($bigint), 1);
            case 'floor':
                return bcsqrt($bigint);
            case 'round':
                $sResult = bcsqrt($bigint);
                return bcsub(bcsqrt($bigint, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsqrt($bigint);
        }
    }

    /**
     * @param string $bigint
     * @param string $exponent
     * @param string $scale (ceil or floor or round)
     * @return string pow($bigint, $exponent)
     */
    public static function pow($bigint, $exponent, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcpow($bigint, $exponent);
            case 'round':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcpow ($bigint, $exponent);
        }
    }
}

class Algorithms
{

    /** Факторизация - Разложение числа на простые множители
     * @param int $n
     * @return array
     */
    public static function factorization($n)
    {
        $a = [];
        for ($i = 2; $i * $i <= $n; ++$i) {
            $cnt = 0;
            while (bcmod($n, $i) == 0) {
                ++$cnt;
                $n = bcdiv($n, $i);
            }
            if ($cnt > 0) {
                $a[$i] = $cnt;
            }
        }
        if ($n > 1) {
            $a[$n] = 1;
        }

        return $a;
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наибольший общий делитель (НОД)
     */
    public static function gcd($a, $b)
    {
        if ($b == 0) {
            return $a;
        } else {
            $a = $a % $b;
            return self::gcd($b, $a);
        }
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наименьшее общее кратное (НОК)
     */
    public static function lcm($a, $b)
    {
        return abs($a * $b) / self::gcd($a, $b);
    }

    /**Последовательность Фибоначчи =  0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987
     * return Фибоначчи{n}
     * @param int $n
     * @return int
     */
    public static function fibonacci($n)
    {
        $a = [0, 1];

        for ($i = 2; $i <= $n; $i++) {
            $a[$i] = $a[$i-1] + $a[$i-2];
        }

        return $a[$n];
    }

}

?>

<?php
function solve() {
    list($n, $x) = explode(' ', Read::string());
    $a = Read::array_int();
    $iCounter = 0;
    $k = $a[0];
    while ($k % $x == 0) {
        $iCounter += 1;
        $k = $k / $x;
    }
    for ($i = 1; $i < $n; $i++) {
        $iCounter2 = 1;
        $k = $a[$i];
        while ($k % $x == 0) {
            $iCounter2 += 1;
            $k = $k / $x;
        }

        $iCounter = min($iCounter, $iCounter2);
    }
    $iSum = $a[0];
    for ($i = 0; $i < $n; $i++) {
        $iSum += $a[$i] * $iCounter;
    }

    echo $iCounter."\n";

    return $iSum;
}

#$t = 1;
$t = Read::int();
while ($t--) {
    echo solve();
    echo "\n";
}

class Read
{
    public static function string()
    {
        return trim(fgets(STDIN));
    }

    public static function int()
    {
        return intval(fgets(STDIN));
    }

    public static function array_int($sep = ' ')
    {
        $s = trim(fgets(STDIN));
        return preg_split("/[\s,]+/", $s);
    }

}

class Bigint
{
    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 / $bigint2
     */
    public static function div($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcmod($bigint1, $bigint2) == 0 ? bcdiv($bigint1, $bigint2) : bcadd(bcdiv($bigint1, $bigint2), 1);
            case 'floor':
                return bcdiv($bigint1, $bigint2);
            case 'round':
                $sResult = bcdiv($bigint1, $bigint2);
                return bcsub(bcdiv($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcdiv($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 + $bigint2
     */
    public static function add($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcadd($bigint1, $bigint2);
            case 'round':
                $sResult = bcadd($bigint1, $bigint2);
                return bcsub(bcadd($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcadd($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 - $bigint2
     */
    public static function bigintSub($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcsub($bigint1, $bigint2);
            case 'round':
                $sResult = bcsub($bigint1, $bigint2);
                return bcsub(bcsub($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsub($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @param string $scale (ceil or floor or round)
     * @return string $bigint1 * $bigint2
     */
    public static function mul($bigint1, $bigint2, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcmul($bigint1, $bigint2);
            case 'round':
                $sResult = bcmul($bigint1, $bigint2);
                return bcsub(bcmul($bigint1, $bigint2, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcmul ($bigint1, $bigint2);
        }
    }

    /**
     * @param string $bigint1
     * @param string $bigint2
     * @return string $bigint1 % $bigint2
     */
    public static function mod($bigint1, $bigint2) {
        return bcmod($bigint1, $bigint2);
    }

    /**
     * @param string $bigint
     * @param string $scale (ceil or floor or round)
     * @return string sqrt($bigint)
     */
    public static function sqrt($bigint, $scale = '') {
        switch ($scale) {
            case 'ceil':
                return bcadd(bcsqrt ($bigint), 1);
            case 'floor':
                return bcsqrt($bigint);
            case 'round':
                $sResult = bcsqrt($bigint);
                return bcsub(bcsqrt($bigint, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcsqrt($bigint);
        }
    }

    /**
     * @param string $bigint
     * @param string $exponent
     * @param string $scale (ceil or floor or round)
     * @return string pow($bigint, $exponent)
     */
    public static function pow($bigint, $exponent, $scale = '') {
        switch ($scale) {
            case 'ceil':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) == 0 ? $sResult : bcadd($sResult, 1);
            case 'floor':
                return bcpow($bigint, $exponent);
            case 'round':
                $sResult = bcpow($bigint, $exponent);
                return bcsub(bcpow($bigint, $exponent, 2),  $sResult, 2) >= 0.5 ? bcadd($sResult, 1) : $sResult;
            default:
                return bcpow ($bigint, $exponent);
        }
    }
}

class Algorithms
{

    /** Факторизация - Разложение числа на простые множители
     * @param int $n
     * @return array
     */
    public static function factorization($n)
    {
        $a = [];
        for ($i = 2; $i * $i <= $n; ++$i) {
            $cnt = 0;
            while (bcmod($n, $i) == 0) {
                ++$cnt;
                $n = bcdiv($n, $i);
            }
            if ($cnt > 0) {
                $a[$i] = $cnt;
            }
        }
        if ($n > 1) {
            $a[$n] = 1;
        }

        return $a;
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наибольший общий делитель (НОД)
     */
    public static function gcd($a, $b)
    {
        if ($b == 0) {
            return $a;
        } else {
            $a = $a % $b;
            return self::gcd($b, $a);
        }
    }

    /**
     * @param int $a
     * @param int $b
     * @return int Наименьшее общее кратное (НОК)
     */
    public static function lcm($a, $b)
    {
        return abs($a * $b) / self::gcd($a, $b);
    }

    /**Последовательность Фибоначчи =  0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987
     * return Фибоначчи{n}
     * @param int $n
     * @return int
     */
    public static function fibonacci($n)
    {
        $a = [0, 1];

        for ($i = 2; $i <= $n; $i++) {
            $a[$i] = $a[$i-1] + $a[$i-2];
        }

        return $a[$n];
    }

}

?>

<?php
function solve() {
    $s1 = trim(fgets(STDIN));
    list($n, $x) = explode(' ', $s1);
    $s = trim(fgets(STDIN));
    $a = preg_split("/[\s,]+/", $s);
    $iCounter = 0;
    $k = $a[0];
    while ($k % $x == 0) {
        $iCounter += 1;
        $k = $k / $x;
    }

    $iSum = 0;
    for ($i = 0; $i < $n; $i++) {
        $iSum += $a[$i] * min($iCounter + 1, floor($a[$i] / $x));
    }

    echo $iSum;
}

$t = trim(fgets(STDIN));
while ($t--) {
    solve();
    echo "\n";
}
?>

<?php

$times = (int) trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($ni[], $xi[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $x = &$xi[$idx];
    $a = &$ai[$idx];
    $b = [];
    for ($i = 0; $i < $n; ++$i) {
        $cnt = 0;
        $tmp = $a[$i];
        while (0 == $tmp % $x) {
            $tmp /= $x;
            ++$cnt;
        }
        $b[] = $cnt;
    }
    $m = min($b);
    $sm = array_sum($a) * ($m + 1);
    for ($i = 0; $i < $n; ++$i) {
        if ($b[$i] > $m) {
            $sm += $a[$i];
        } else {
            break;
        }
    }
    echo $sm.PHP_EOL;
}

<?php

$times = (int) trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($ni[], $xi[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $x = &$xi[$idx];
    $a = &$ai[$idx];
    $mn = PHP_INT_MAX;
    for ($i = 0; $i < $n; ++$i) {
        $cnt = 0;
        $tmp = $a[$i];
        while (0 == $tmp % $x) {
            $tmp /= $x;
            ++$cnt;
            if ($cnt == $mn) {
                break;
            }
        }
        $mn > $cnt && $mn = $cnt;
        $a[$i] *= $mn + 1;
    }
    echo array_sum($a).PHP_EOL;
}


Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!Your task is to write a program which calculates two things:  The maximum beauty difference of flowers that Pashmak can give to Parmida.  The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.

The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109).

The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.

NoteIn the third sample the maximum beauty difference is 2 and there are 4 ways to do this:  choosing the first and the second flowers;  choosing the first and the fifth flowers;  choosing the fourth and the second flowers;  choosing the fourth and the fifth flowers.

<?php

function FindFlowers($flowers,$beauty){

    $beauty = explode(" ", $beauty);
    $count =0;
    $max_beauty = max($beauty);
    $min_beauty = min($beauty);
    $diff_max_beauty = $max_beauty-$min_beauty;

    $maxposition  = count(array_keys($beauty, max($beauty)));
    $min_position = count(array_keys($beauty, min($beauty)));

    if($diff_max_beauty==0){
        $count = $maxposition*($maxposition-1)/2;
    }
 else {
        $count = $maxposition*$min_position;
    }
    echo $diff_max_beauty." ". $count;

}

$flowers = trim(fgets(STDIN));
$beauty  = trim(fgets(STDIN));

FindFlowers($flowers,$beauty);

<?php
// 459B     Пашмак и цветы
$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 = $arr[$n-1] - $arr[0];

$colfirst = $colend = 1;
for ($i=1; $i < $n; $i++) {
    if ($arr[$i] === $arr[0]) {
        $colfirst ++;
    } else {
        break;
    }
}

for ($i=$n-2; $i >= 0; $i--) {
    if ($arr[$i] === $arr[$n-1]) {
        $colend ++;
    } else {
        break;
    }
}

if ($i < 0) {
    $sum = 0;
    for ($j=1; $j < $n; $j++) {
        $sum += $j;
    }
    $col = $n * ($n - 1) - $sum;
} else {
    $col = $colfirst * $colend;
}

echo "$max $col";

?>

<?
$n = trim(fgets(STDIN));
$m = explode(" ",trim(fgets(STDIN)));
$mx = max($m);
$mn = min($m);
foreach($m as $v){
    if($v == $mx)$cmx++;
    if($v == $mn)$cmn++;
}
if($mx != $mn)echo ($mx-$mn)." ".($cmx*$cmn);
else echo ($mx-$mn)." ".(($n*($n-1))/2);
?>

<?php
	$n = trim(fgets(STDIN));
	$b = explode(' ', trim(fgets(STDIN)));
	$mx = max($b);
	$mn = min($b);
	$cmx = $cmn = 0;
	foreach($b as $v)
	{
		$cmx += ($v == $mx);
		$cmn += ($v == $mn);
	}
	echo $mx-$mn.' '.($mx == $mn ? floor($n*($n-1)/2) : $cmx*$cmn);
?>

<?php

function FindFlowers($flowers,$beauty){

    $beauty = explode(" ", $beauty);
    $count =0;
    $max_beauty = max($beauty);
    $min_beauty = min($beauty);
    $diff_max_beauty = $max_beauty-$min_beauty;

    $maxposition  = count(array_keys($beauty, max($beauty)));
    $min_position = count(array_keys($beauty, min($beauty)));

    if($diff_max_beauty==0){
        $count = factorial($maxposition)/(factorial(2)*factorial($maxposition-2));
    }
 else {
        $count = $maxposition*$min_position;
    }
    echo $diff_max_beauty." ". $count;

}

function factorial($number) {

    if ($number < 2) {
        return 1;
    } else {
        return ($number * factorial($number-1));
    }
}

$flowers = trim(fgets(STDIN));
$beauty  = trim(fgets(STDIN));

FindFlowers($flowers,$beauty);

<?php

function FindFlowers($flowers,$beauty){

    $beauty = explode(" ", $beauty);
    $count =0;
    $max_beauty = max($beauty);
    $min_beauty = min($beauty);
    $diff_max_beauty = $max_beauty-$min_beauty;

    $maxposition  = array_keys($beauty, max($beauty));
    $min_position = array_keys($beauty, min($beauty));

    $count = count($min_position)*  count($maxposition);
    if($count==0)
        $count=1;
    echo $diff_max_beauty." ". $count;

}

$flowers = trim(fgets(STDIN));
$beauty  = trim(fgets(STDIN));

FindFlowers($flowers,$beauty);

<?php
// 459B     Пашмак и цветы
$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 = $arr[$n-1] - $arr[0];

$colfirst = $colend = 1;
for ($i=1; $i < $n; $i++) {
    if ($arr[$i] === $arr[0]) {
        $colfirst ++;
    } else {
        break;
    }
}

for ($i=$n-2; $i > 0; $i--) {
    if ($arr[$i] === $arr[$n-1]) {
        $colend ++;
    } else {
        break;
    }
}

$col = $colfirst * $colend;

echo "$max $col";

?>

<?
$n = trim(fgets(STDIN));
$m = explode(" ",trim(fgets(STDIN)));
$mx = max($m);
$mn = min($m);
foreach($m as $v){
    if($v == $mx)$cmx++;
    if($v == $mn)$cmn++;
}
echo ($mx-$mn)." ".($cmx*$cmn);
?>

<?
$n = trim(fgets(STDIN));
$m = explode(" ",trim(fgets(STDIN)));
$mx = max($m);
$mn = min($m);
foreach($m as $v){
    if($v == $mx)$cmx++;
    if($v == $mn)$cmn++;
}
if($mx != $mn)echo ($mx-$mn)." ".($cmx*$cmn);
else echo ($mx-$mn)." ".($n*($n-1));
?>


Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.

The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.

If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer k (k ≥ 0) — the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct. If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair. Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.


A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).  Alice and Bob play dice. Alice has built a tower from n dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not.

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of dice in the tower. The second line contains an integer x (1 ≤ x ≤ 6) — the number Bob sees at the top of the tower. Next n lines contain two space-separated integers each: the i-th line contains numbers ai, bi (1 ≤ ai, bi ≤ 6; ai ≠ bi) — the numbers Bob sees on the two sidelong faces of the i-th dice in the tower. Consider the dice in the tower indexed from top to bottom from 1 to n. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input.

Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$e = 0;
list($c, $d) = explode(" ", trim(fgets(STDIN)));
for($x = 1; $x < $a; $x++)
{
    list($c, $d) = explode(" ", trim(fgets(STDIN)));
    if(($b == $c) || ($b == $d) || ((7 - $b) == $c) || ((7 - $b) == $d))
    {
        $e++;
        break;
    }
}
if($e == 0)
{
    print "YES";
}
else
{
    print "NO";
}
?>

<?php
// Retrieve input
$stdin = fopen('php://stdin', 'r');
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Problem 225A
// Codeforces Contest 139 Div 2 Problem A
$raw = g();
$n = $raw[0];
$raw = g();
$x = $raw[0];
$done = false;
for ($i = 0; $i < $n; $i++) {
	$raw = g();
	$a = $raw[0];
	$b = $raw[1];
	if (($a == $x) || ($b == $x) || ($a == (7 - $x)) || ($b == (7 - $x))) {
		$done = true;
	}
}
if (!$done) {echo "YES";} else {echo "NO";}

// End of submission file
// Submission by chaotic_iak
?>

<?php
 $i= trim(fgets(STDIN));
 $point=7-trim(fgets(STDIN));
 for ($p=1;$p<=$i;$p++)
     { list($a,$b)=explode(" ",trim(fgets(STDIN)));
      if (($point==$a)or($point==$b)or($point==(7-$a)) or ($point==(7-$b))) {$res=0; break;}
       else {$res++;}; };
 if ($res==$i) {print ("YES");} else {print ("NO");};
?>

<?php
 $i= trim(fgets(STDIN));
 $point=7-trim(fgets(STDIN));
 for ($p=1;$p<=$i;$p++)
     { list($a,$b)=explode(" ",trim(fgets(STDIN)));
      if (($point==$a)or($point==$b)or($point==(7-$a)) or ($point==(7-$b))) {$res=0;}
       else {$res++;}; };
 if ($res==$i) {print ("YES");} else {print ("NO");};
?>

<?PHP
$n = fgets(STDIN);
$u = fgets(STDIN);
list($l, $r) = explode(" ", fgets(STDIN));
$res = "YES";

for ($i = 1; $i < $n; $i++) {
    $d = 7 - $u;
    list($l, $r) = explode(" ", fgets(STDIN));
    $di = array(intval($l), intval($r), 7 - $l, 7 - $r);
    //print_r ($di);
    if (in_array($d, $di))
        $res = "NO";
}
echo "$res\n";
?>

<?php
// Retrieve input
$stdin = fopen('php://stdin', 'r');
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Problem 225A
// Codeforces Contest 139 Div 2 Problem A
$raw = g();
$n = $raw[0];
$raw = g();
$x = $raw[0];
$done = false;
for ($i = 0; $i < $n; $i++) {
	$raw = g();
	$a = $raw[0];
	$b = $raw[1];
	if (($a == $x) || ($b == $x) || ($a == (7 - $x)) || ($b == (7 - $x))) {
		echo "NO";
		$done = true;
	}
}
if (!$done) {echo "YES";}

// End of submission file
// Submission by chaotic_iak
?>

<?PHP
$n = fgets(STDIN);
$u = fgets(STDIN);
list($l, $r) = explode(" ", fgets(STDIN));
$res = "SI";

for ($i = 1; $i < $n; $i++) {
    $d = 7 - $u;
    list($l, $r) = explode(" ", fgets(STDIN));
    $di = array(intval($l), intval($r), 7 - $l, 7 - $r);
    //print_r ($di);
    if (in_array($d, $di))
        $res = "NO";
}
echo "$res\n";
?>


Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?

The first line contains four space-separated integers a1, a2, a3, a4 (0 ≤ a1, a2, a3, a4 ≤ 104). The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.

Print a single integer — the total number of calories that Jury wastes.

<?php
list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
$e = str_split(trim(fgets(STDIN)));
$f = 0;
for($x = 0; $x < count($e); $x++)
{
    switch($e[$x])
    {
        case 1:
        $f += $a;
        break;
        case 2:
        $f += $b;
        break;
        case 3:
        $f += $c;
        break;
        case 4:
        $f += $d;
        break;
    }
}
print $f;
?>

<?php

//=====================================
// link: https://codeforces.com/contest/431/problem/A
//=====================================

// get inputs
$calories = explode(' ', trim(fgets(STDIN)));
$strips   = trim(fgets(STDIN));

// solution
$burning_calories = 0;

for ($i = 0; $i < strlen($strips); $i++) {
    $burning_calories += $calories[$strips[$i] - 1];
}

echo "$burning_calories\n";

<?php

$stdout = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%[^\n]", $str);
$arr = array_map( 'intval' , preg_split('/ /' , $str , -1 , PREG_SPLIT_NO_EMPTY ) );

fscanf($stdin, "%s", $s );

$result = 0 ;

for( $i=0 ; $i< strlen($s) ; $i++)
{
     $result += $arr[ $s[$i] - 1 ] ;
}
echo $result ;

fwrite($stdout);

fclose($stdin);
fclose($stdout);

?>

<?php
$c = explode(" ", trim(fgets(STDIN)));
$s = str_split(trim(fgets(STDIN)));
$sum = 0;
foreach($s as $value){
    $sum += $c[$value-1];
}
echo $sum;
?>

<?php
// 431A     Черный квадрат
$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);

$input_line = fgets($in);
$str = substr($input_line, 0, strlen($input_line)-2);
$len = strlen($str);

$col = 0;
for ($i=0; $i < $len ; $i++) {
    $k = (int) $str[$i] -1;
    $col += $arr[$k];
}

echo $col;

?>

<?php

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

	$a = explode(" ", fgets($temp));

	for ($i=0; $i < count($a) ; $i++) {
		$a[$i] = intval($a[$i]);
	}

	$s = fgets($temp);

	$sum = 0;
	for($i=0; $i < strlen($s)-2 ; $i++) {
		$sum += $a[intval($s[$i])-1];
	}

	echo $sum;

?>

<?php
error_reporting("off");
//431A: Black Square
$cal = explode(" ", trim(fgets(STDIN))); //$cal = explode(" ", "1 2 3 4");
$string = str_split(trim(fgets(STDIN))); //$string = str_split("123214");
$count = array_count_values($string);
$calcount = 0;
foreach ($count as $key => $value) {
    $calcount += $cal[$key - 1] * $value;
}
echo $calcount;
?>

<?php
$c = explode(" ", trim(fgets(STDIN)));
$s = explode("", trim(fgets(STDIN)));
$sum = 0;
foreach($s as $value){
    $sum += $c[$value-1];
}
echo $sum;
?>

<?php
    $in = 'php://stdin';

    $input = fopen($in, "r");

    $c = explode(" ", trim(fgets($input)));
    $s = trim(fgets($input));

    function MultArray ($a, $b) { return $a*$b; }

    $o = array_count_values(str_split($s));
    ksort($o);

    echo array_sum(array_map("MultArray", $c, $o));
?>


Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:  either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before);  or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible.

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room.

In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m.

NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = array();
array_unshift($c, " ");
unset($c[0]);
$d = array();
array_unshift($d, " ");
unset($d[0]);
$g = array();
for($x = 1; $x <= $a; $x++)
{
    for($y = 1; $y <= $b; $y++)
    {
        $e = array_search($x, $c);
        $f = array_search($y, $d);
        array_push($c, $x);
        array_push($d, $y);
        if(($e > 0) && ($f > 0))
        {
            continue;
        }
        else
        {
            array_push($g, $x . " " . $y);
        }
    }
}
print count($g) . "\n";
for($z = 0; $z < count($g) - 1; $z++)
{
    print $g[$z] . "\n";
}
print $g[$z];
?>

<?php
/** chaotic_iak's solution in PHP 5.4 to the problem 322A (Round 190 Div 2 Problem A) in Codeforces **/

/** Module for retrieving input **/

// If this is a local test (a variable declared in a specialized page to open this script), open from localtest.txt instead of php://stdin (because I'm too lazy to supply the arguments by stdin)
if (isset($localtest)) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}

// A function to retrieve the next line. Takes one optional argument $single, which should be true if the next line (based on problem's specification) has only one number/string/whatever, so I don't have to do silly things like $raw = g(); $num = $raw[0];
function g($single = false) {

	// Take the global $stdin variable aka the file handler so we can access it from this function
	global $stdin;

	// Take the input from the handler, trim it, and explode it based on space (" 1 2 3 " becomes array("1", "2", "3")); trim is usually to remove trailing \r
	$input = explode(" ", trim(fgets($stdin)));

	// If the line is not a single number, return the whole array, otherwise simply return the single string that we exploded for nothing
	if (!$single) {return $input;} else {return $input[0];}
}

/** Imported functions from chaotic_iak's library **/
// none

/** chaotic_iak's solution **/
// This is a competitive programming solution. The code is not remarked (because I want speed).

$raw = g();
$n = $raw[0];
$m = $raw[1];

echo $n + $m - 1 . "\n";
for ($i = 1; $i <= $n; $i++) {
	echo $i . " 1\n";
}
for ($i = 2; $i <= $m; $i++) {
	echo "1 " . $i . "\n";
}

<?php

list($n, $m) = explode(' ', getline());

$n = intval($n);
$m = intval($m);

$bisdance = array();
$gisdance = array();

init_array($bisdance, $n);
init_array($gisdance, $m);

$answer = 0;
$output = PHP_EOL;

for ($i = 1; $i <= $n; $i ++) {
  for ($j = 1; $j <= $m; $j ++) {
    if (!$bisdance[$i] || !$gisdance[$j]) {
      $bisdance[$i] = true;
      $gisdance[$j] = true;
      $answer ++;
      $output .= $i . ' ' . $j . PHP_EOL;
    }
  }
}

print $answer;
print $output;

function init_array(&$array, $n) {
  for ($i = 1; $i <= $n; $i ++) {
    $array[$i] = false;
  }
}

function getline() {
  return trim(fgets(STDIN));
}


A row of $$$n$$$ cells is given, all initially white. Using a stamp, you can stamp any two neighboring cells such that one becomes red and the other becomes blue. A stamp can be rotated, i.e. it can be used in both ways: as $$$\color{blue}{\texttt{B}}\color{red}{\texttt{R}}$$$ and as $$$\color{red}{\texttt{R}}\color{blue}{\texttt{B}}$$$.During use, the stamp must completely fit on the given $$$n$$$ cells (it cannot be partially outside the cells). The stamp can be applied multiple times to the same cell. Each usage of the stamp recolors both cells that are under the stamp.For example, one possible sequence of stamps to make the picture $$$\color{blue}{\texttt{B}}\color{red}{\texttt{R}}\color{blue}{\texttt{B}}\color{blue}{\texttt{B}}\texttt{W}$$$ could be $$$\texttt{WWWWW} \to \texttt{WW}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\texttt{W} \to \color{brown}{\underline{\color{blue}{\texttt{B}}\color{red}{\texttt{R}}}}\color{red}{\texttt{R}}\color{blue}{\texttt{B}}\texttt{W} \to \color{blue}{\texttt{B}}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\color{blue}{\texttt{B}}\texttt{W}$$$. Here $$$\texttt{W}$$$, $$$\color{red}{\texttt{R}}$$$, and $$$\color{blue}{\texttt{B}}$$$ represent a white, red, or blue cell, respectively, and the cells that the stamp is used on are marked with an underline.Given a final picture, is it possible to make it using the stamp zero or more times?

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the picture. The second line of each test case contains a string $$$s$$$ — the picture you need to make. It is guaranteed that the length of $$$s$$$ is $$$n$$$ and that $$$s$$$ only consists of the characters $$$\texttt{W}$$$, $$$\texttt{R}$$$, and $$$\texttt{B}$$$, representing a white, red, or blue cell, respectively. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if it possible to make the picture using the stamp zero or more times, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

12
5
BRBBW
1
B
2
WB
2
RW
3
BRB
3
RBB
7
WWWWWWW
9
RBWBWRRBW
10
BRBRBRBRRB
12
BBBRWWRRRWBR
10
BRBRBRBRBW
5
RBWBW

YES
NO
NO
NO
YES
YES
YES
NO
YES
NO
YES
NO

NoteThe first test case is explained in the statement.For the second, third, and fourth test cases, it is not possible to stamp a single cell, so the answer is "NO".For the fifth test case, you can use the stamp as follows: $$$\texttt{WWW} \to \texttt{W}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}} \to \color{brown}{\underline{\color{blue}{\texttt{B}}\color{red}{\texttt{R}}}}\color{blue}{\texttt{B}}$$$.For the sixth test case, you can use the stamp as follows: $$$\texttt{WWW} \to \texttt{W}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}} \to \color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\color{blue}{\texttt{B}}$$$.For the seventh test case, you don't need to use the stamp at all.

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($i = 0; $i < $t; $i++) {
    $l = trim(fgets($handle));
    $s = trim(fgets($handle));
    $arr= explode( 'W', $s);

    $hasOdd= false;

    for($j = 0;$j<count($arr);$j++){
        if(strlen($arr[$j]) > 0 && ( strpos( $arr[$j], 'R') === false || strpos( $arr[$j], 'B') === false)){
            $hasOdd =true;
        }
    }
    echo ($hasOdd? 'No':'Yes')."\n";
}

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

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

  for($q=0; $q <$t; $q++) {
      $ans = true;
      $n = getT();
      $s = getT();
  $temp = [
      'B' => 0,
      'R' => 0
      ];
      foreach(str_split($s) as $ch) {
          if($ch == 'W') {
              if(($temp['B'] == 0 && $temp['R'] != 0) || ($temp['B'] != 0 && $temp['R'] == 0)) {
                //  $bA = false;
                 break;
              }
               $temp = [
                  'B' => 0,
                  'R' => 0
                 ];
          } else {
              $temp[$ch] += 1;
          }
      }
    if(($temp['B'] == 0 && $temp['R'] != 0) || ($temp['B'] != 0 && $temp['R'] == 0)) {
                 pr($no);
              } else {
                  pr($yes);
              }

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

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

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

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

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

        return $a[$n];
    }

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($i = 0; $i < $t; $i++) {
    $l = trim(fgets($handle));
    $s = trim(fgets($handle));
    if ($l == 1) {
        echo 'No' . "\n";
    }elseif( $l == 2) {
        echo (strpos($s,"W") > -1 ? 'No': 'Yes'). "\n";
    }
        else {
        $hasOdd = false;
        $x='';
        $res = [];
        for ($k = 0; $k < $l; $k++) {
            if($s[$k] != 'W') {
                $x .= $s[$k];
            }else {
                $res[]= $x;
                $x = '';
            }
        }
        for($k = 0; $k < count($res); $k++)
        {
            if(strlen($res[$k])%2!=0 && strlen($res[$k]) < $l-1){
                $hasOdd = true;
            }
        }

        echo ($hasOdd ? "No": "Yes"). "\n";
    }
}


After lessons Nastya decided to read a book. The book contains $$$n$$$ chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number $$$k$$$ as the first page which was not read (i.e. she read all pages from the $$$1$$$-st to the $$$(k-1)$$$-th).The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle).

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of chapters in the book. There are $$$n$$$ lines then. The $$$i$$$-th of these lines contains two integers $$$l_i$$$, $$$r_i$$$ separated by space ($$$l_1 = 1$$$, $$$l_i \leq r_i$$$) — numbers of the first and the last pages of the $$$i$$$-th chapter. It's guaranteed that $$$l_{i+1} = r_i + 1$$$ for all $$$1 \leq i \leq n-1$$$, and also that every chapter contains at most $$$100$$$ pages. The $$$(n+2)$$$-th line contains a single integer $$$k$$$ ($$$1 \leq k \leq r_n$$$) — the index of the marked page.

Print a single integer — the number of chapters which has not been completely read so far.

NoteIn the first example the book contains $$$11$$$ pages and $$$3$$$ chapters — $$$[1;3]$$$, $$$[4;7]$$$ and $$$[8;11]$$$. Nastya marked the $$$2$$$-nd page, so she finished in the middle of the $$$1$$$-st chapter. So, all chapters has not been read so far, so the answer is $$$3$$$.The book in the second example contains $$$12$$$ pages and $$$3$$$ chapters too, but Nastya finished reading in the middle of the $$$2$$$-nd chapter, so that the answer is $$$2$$$.

<?php
$paragraphs = intval(trim(fgets(STDIN)));
$unreaded = $paragraphs;

while (STDIN && $paragraphs != 0) {
    $paragraph[] = explode(' ', trim(fgets(STDIN)));
    $paragraphs--;
}

$readed = intval(trim(fgets(STDIN)));

$i = 0;
foreach ($paragraph as $val) {
    if (filter_var(
        $readed,
        FILTER_VALIDATE_INT,
        array(
      'options' => array(
          'min_range' => $val[0],
          'max_range' => $val[1]
      )
    )
    )) {
        echo $unreaded - $i . PHP_EOL;
    } else {
        $i++;
    }
}

<?php
$a = trim(fgets(STDIN));
$b = array();
$c = 1;
for($x = 0; $x < $a; $x++)
{
     list($d, $e) = explode(" ", trim(fgets(STDIN)));
     for($y = $d; $y <= $e; $y++)
     {
          $b[$y] = $c;
     }
     $c++;
}
$f = trim(fgets(STDIN));
print $a - $b[$f] + 1;
?>

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $chaptersDescription[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
        // echo $inputArray[$i][0] . " : " . $inputArray[$i][1] . "\n";
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 2]);
    // echo $arr[count($arr) - 2] . "\n";
    // echo $unreadPageIndex . "\n";
    // exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

$n = trim(fgets(STDIN));

$r = [];

for($i = 0; $i<$n; $i++){
	$data = explode(' ', trim(fgets(STDIN)));
	$r[] = $data[1];
}

$k = trim(fgets(STDIN));
$c = 0;
for($i = 0; $i<$n; $i++){
	if($k > $r[$i]){
		$c++;
	}
}

fwrite(STDOUT, $n-$c);

?>

<?php
$n = fgets(STDIN);
$array;
for($i = 0; $i < $n; $i++){
    list($array[$i][0], $array[$i][1]) = explode(' ', fgets(STDIN));
}
$k = (int) fgets(STDIN);
for($i = 0; $i < $n; $i++){
    if($array[$i][0] <= $k && $array[$i][1] >= $k){
        $n = $n - $i;
        echo $n;
        return 0;
    }
}
?>

<?php
$n = fgets(STDIN);
$array;
$count = 0;
for($i = 0; $i < $n; $i++){
    list($array[$i][0], $array[$i][1]) = explode(' ', fgets(STDIN));
}
$k = fgets(STDIN);
for($i = 0; $i < $n; $i++){
    if($array[$i][0] <= $k && $array[$i][1] >= $k){
        echo $n - $i;
        return 0;
    }
}
?>

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim(end($arr));
    echo $unreadPageIndex;
    exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 1]);
    echo $unreadPageIndex;
    exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
        echo $inputArray[$i][0] . " : " . $inputArray[$i][1] . "\n";
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 2]);
    // echo $arr[count($arr) - 2] . "\n";
    // echo $unreadPageIndex . "\n";
    // exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    echo "Epta : '" . stream_get_contents($stdin) . "'";
    exit();

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

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    $nrChapters = stream_get_contents($dir);
    // $nrChapters = (int)$nrChapters;

    fwrite($stdout, "Epta : '" . $nrChapters . "'");
    exit();

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

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 1]);
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 2]);
    // echo $arr[count($arr) - 2] . "\n";
    // echo $unreadPageIndex . "\n";
    // exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    readline($nrChapters);
    readline($sec);
    // $nrChapters = (int)$nrChapters;

    fwrite($stdout, "Epta : '" . $nrChapters . "' | '$sec'");
    exit();

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

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 1]);
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim(end($arr));
    echo end($arr) . "\n";
    echo $unreadPageIndex . "\n";
    exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    fread($stdin, $nrChapters);
    fread($stdin, $sec);
    // $nrChapters = (int)$nrChapters;

    fwrite($stdout, "Epta : '" . $nrChapters . "' | '$sec'");
    exit();

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

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 1]);
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    fread($stdin, $nrChapters);
    $nrChapters = (int)$nrChapters;

    fwrite($stdout, "Epta : '" . $nrChapters . "'");
    exit();

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

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 2]);
    echo $arr[count($arr) - 2] . "\n";
    echo $unreadPageIndex . "\n";
    exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }


Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.

First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≤ k ≤ 26).

Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.

NoteIn the first test case string contains 6 different letters, so we don't need to change anything.In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}.In the third test case, it is impossible to make 7 different letters because the length of the string is 6.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if(strlen($a) < $b)
{
     print "impossible";
}
else
{
     $c = array_unique(str_split($a));
     sort($c);
     if(count($c) >= $b)
     {
          print "0";
     }
     else
     {
          print $b - count($c);
     }
}
?>

<?php

$l = trim(fgets(STDIN));
$r = trim(fgets(STDIN));

// base case sanity check
if($r > strlen($l))
{
    echo "impossible";
    exit;
}

$cc = array();
foreach(str_split($l) as $c) {
    if (!isset($cc[$c]))
        $cc[$c] = true;
}

$rr = max(0, $r - sizeof($cc));
echo ($rr);

<?php
$p = fopen('php://stdin', 'r');
$s = trim(fgets($p));
$k = intval(fgets($p));
fclose($p);
if (strlen($s) < $k) {
    echo 'impossible', PHP_EOL; die;
}
$chars = str_split($s);
$distinctLength = count(array_unique($chars));
$missing = $k - $distinctLength;
if ($missing < 0) {
    echo 0, PHP_EOL;
} else {
    echo $missing, PHP_EOL;
}

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if(strlen($a) < $b)
{
     print "impossible";
}
else
{
     $c = array_unique(str_split($a));
     sort($c);
     $d = $b - count($c);
     print $d;
}
?>

<?php

$r = trim(fgets(STDIN));
$l = explode("", trim(fgets(STDIN)));

// base case sanity check
if($r > $l)
{
    echo "impossible";
    exit;
}

$cc = array();
foreach($l as $c) {
    if (!isset($cc[$c]))
        $cc[$c] = true;
}

echo ($r - sizeof($cc));

<?php

$l = trim(fgets(STDIN));
$r = trim(fgets(STDIN));

// base case sanity check
if($r > strlen($l))
{
    echo "impossible";
    exit;
}

$cc = array();
foreach(str_split($l) as $c) {
    if (!isset($cc[$c]))
        $cc[$c] = true;
}

echo ($r - sizeof($cc));