Nezzar's favorite digit among $$$1,\ldots,9$$$ is $$$d$$$. He calls a positive integer lucky if $$$d$$$ occurs at least once in its decimal representation. Given $$$q$$$ integers $$$a_1,a_2,\ldots,a_q$$$, for each $$$1 \le i \le q$$$ Nezzar would like to know if $$$a_i$$$ can be equal to a sum of several (one or more) lucky numbers.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 9$$$) — the number of test cases. The first line of each test case contains two integers $$$q$$$ and $$$d$$$ ($$$1 \le q \le 10^4$$$, $$$1 \le d \le 9$$$). The second line of each test case contains $$$q$$$ integers $$$a_1,a_2,\ldots,a_q$$$ ($$$1 \le a_i \le 10^9$$$).

For each integer in each test case, print "YES" in a single line if $$$a_i$$$ can be equal to a sum of lucky numbers. Otherwise, print "NO". You can print letters in any case (upper or lower).

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

NoteIn the first test case, $$$24 = 17 + 7$$$, $$$27$$$ itself is a lucky number, $$$25$$$ cannot be equal to a sum of lucky numbers.

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        if ($sV > 100) {
            echo "YES\n";
            continue;
        } else {
            while ($sV > $d || strpos($sV , $d . '') !== false) {
                if (strpos($sV, $d . '') !== false) {
                    echo "YES\n";
                    continue 2;
                }
                $sV -= $d;
            }
        }
        echo "NO\n";
    }
}

<?php
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($q, $d) = IO::arr();
    $a = IO::arr();
    $ends = [];
    for($i = 1; $i <= 10; $i++){
        $j = $d * $i;
        $j = str_split($j);
        $ends[end($j)] = $i;
    }
    foreach ($a as $b) {
        $bool = false;
        for ($h = 0; $h <= 100; $h++) {
            $res = bcsub($b, ($h * $d));
            if($res < 0) {
                break;
            }
            $res = substr($res, -2);
            if (strpos($res, $d) !== false) {
                $bool = true;
                break;
            }
        }
        if($bool) {
            IO::yes();
        } else {
            IO::no();
        }
    }
}

<?php
$iCount = read();

for($i=0; $i < $iCount; $i++) {
    $aTest = explode(' ', read());
    $aTest2 = explode(' ', read());

    $iLuck = $aTest[1];
    foreach ($aTest2 AS $sTest) {
        $iTest = (int)$sTest;
        if(strpos($sTest, $iLuck . '') !== false) {
            write('YES');
            continue;
        } else {
            while ($iTest > $iLuck || strpos($iTest . '', $iLuck . '') !== false) {
                $iTest -= $iLuck;
                if (strpos($iTest . '', $iLuck . '') !== false) {
                    write('YES');
                    continue 2;
                }
            }
        }

        write('NO');

    }
}

function write($a) {
    echo $a . "\n";
}

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

  <?php
  $t = trim(fgets(STDIN));
   for($w=0; $w<$t; $w++) {

     list($q, $d) = explode(' ', trim(fgets(STDIN)));
     $a = explode(' ', trim(fgets(STDIN)));

           for($i = 0; $i<$q; $i++) {
              $iN = $a[$i];
              if($iN >= $d) {
                  while($iN >= $d) {
                        if(goodNum($iN, $d)) {
                            echo "YES\n";
                            break;
                        } else {
                            $iN = $iN - $d;
                            if($iN < $d) {
                                echo "NO\n";
                            }
                        }
                    }
              } else {
                  echo "NO\n";
              }

          }

    }

   function goodNum($iNum, $d) {
        if($iNum < $d) {
            return false;
        }
        $sV = strval($iNum);
            for($i = 0; $i < strlen($sV); $i++) {
                if(intval($sV[$i]) == $d) {
                    return true;
                }
            }
            return false;
    }

<?php

$times = (int) trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($qi[], $di[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $q = &$qi[$idx];
    $d = &$di[$idx];
    $a = &$ai[$idx];
    for ($i = 0; $i < $q; ++$i) {
        $b = $a[$i];
        if ($b >= 10 * $d) {
            echo 'YES'.PHP_EOL;
            continue;
        }
        while ($b > 0) {
            if (0 == $b % $d) {
                echo 'YES'.PHP_EOL;
                continue 2;
            }
            $b -= 10;
        }
        echo 'NO'.PHP_EOL;
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        if ($sV > 100) {
            echo "YES\n";
            continue;
        } else {
            $iTemp = $sV;
            $iLength = strlen($iTemp);
            while ($iTemp > $d || $iTemp[($iLength - 1)] == $d) {
                //echo $iTemp . ' ' . "\n";
                if ($iTemp[($iLength - 1)] == $d) {
                    echo "YES\n";
                    continue 2;
                }
                $iTemp = strval($iTemp - $d);
                $iLength = strlen($iTemp);
            }
        }
        echo "NO\n";
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        if ($sV > 100) {
            echo "YES\n";
        } else {
            $bFlag = false;
            if ($sV[(strlen($sV) - 1)] == $d) {
                echo "YES\n";
            } else {
                while ($sV > $d) {
                    //echo $sV . "\n";
                    $sV = strval($sV - $d);
                    $iLength = strlen($sV);
                    if ($sV[($iLength - 1)] == $d) {
                        $bFlag = true;
                        break;
                    }
                }
                if ($bFlag) {
                    echo "YES\n";
                } else {
                    echo "NO\n";
                }
            }
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        if ($sV > 90) {
            echo "YES\n";
        } else {
            $bFlag = false;
            if ($sV[(strlen($sV) - 1)] == $d) {
                echo "YES\n";
            } else {
                while ($sV > $d) {
                    //echo $sV . "\n";
                    $sV = strval($sV - $d);
                    $iLength = strlen($sV);
                    if ($sV[($iLength - 1)] == $d) {
                        $bFlag = true;
                        break;
                    }
                }
                if ($bFlag) {
                    echo "YES\n";
                } else {
                    echo "NO\n";
                }
            }
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        $iLength = strlen($sV);
        if ($sV[$iLength - 1] == $d && $sV < 100) {
            echo "YES\n";
        } else {
            $iTemp = $sV;
            $bFlag = false;
            while ($iTemp > 9) {
                echo $iTemp . "\n";
                if (strlen($iTemp) > 2 && $iTemp > 170) {
                    $iTemp -= ($d * pow(10,(strlen($iTemp) - 2)));
                } else {
                    $iTemp = strval($iTemp - $d);
                    if ($iTemp < 110) {
                        $iLength = strlen($iTemp);
                        if ($iTemp[($iLength - 1)] == $d) {
                            $bFlag = true;
                            break;
                        }
                    }
                }
            }
            if ($bFlag) {
                echo "YES\n";
            } else {
                echo "NO\n";
            }
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        $iLength = strlen($sV);
        if ($sV[$iLength - 1] == '7' && $sV < 100) {
            echo "YES\n";
        } else {
            $iTemp = $sV;
            $bFlag = false;
            while ($iTemp > 9) {
                //echo $iTemp . "\n";
                if (strlen($iTemp) > 2 && $iTemp > 170) {
                    $iTemp -= (7 * pow(10,(strlen($iTemp) - 2)));
                } else {
                    $iTemp = strval($iTemp - 7);
                    if ($iTemp < 110) {
                        $iLength = strlen($iTemp);
                        if ($iTemp[($iLength - 1)] == 7) {
                            $bFlag = true;
                            break;
                        }
                    }
                }
            }
            if ($bFlag) {
                echo "YES\n";
            } else {
                echo "NO\n";
            }
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        $iLength = strlen($sV);
        if ($sV[$iLength - 1] == '7' && $sV < 100) {
            echo "YES\n";
        } else {
            $iTemp = $sV;
            $bFlag = false;
            while ($iTemp > 9) {
                //echo $iTemp . "\n";
                if (strlen($iTemp) > 2 && $iTemp > 170) {
                    $iTemp -= (7 * pow(10,(strlen($iTemp) - 2)));
                } else {
                    $iTemp = strval($iTemp - 7);
                    if ($iTemp < 100) {
                        $iLength = strlen($iTemp);
                        if ($iTemp[($iLength - 1)] == 7) {
                            $bFlag = true;
                            break;
                        }
                    }
                }
            }
            if ($bFlag) {
                echo "YES\n";
            } else {
                echo "NO\n";
            }
        }
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($q, $d) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    foreach ($aList as $sK => $sV) {
        $iLength = strlen($sV);
        if ($sV[$iLength - 1] == '7') {
            echo "YES\n";
        } else {
            $iTemp = $sV;
            $bFlag = false;
            while ($iTemp > 9) {
                $iTemp = strval($iTemp - 7);
                $iLength = strlen($iTemp);
                if ($iTemp[($iLength - 1)] == 7) {
                    $bFlag = true;
                    break;
                }
            }
            if ($bFlag) {
                echo "YES\n";
            } else {
                echo "NO\n";
            }
        }
    }
}

<?php
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($q, $d) = IO::arr();
    $a = IO::arr();
    $ends = [];
    for($i = 1; $i <= 10; $i++){
        $j = $d * $i;
        $j = str_split($j);
        $ends[end($j)] = $i;
    }
    foreach ($a as $b) {
        $bool = false;
        for ($h = 0; $h <= 20; $h++) {
            $res = bcsub($b, ($h * $d));
            if($res < 0) {
                break;
            }
            $res = substr($res, -2);
            if (strpos($res, $d) !== false) {
                $bool = true;
                break;
            }
        }
        if($bool) {
            IO::yes();
        } else {
            IO::no();
        }
    }
}

<?php
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($q, $d) = IO::arr();
    $a = IO::arr();
    $ends = [];
    for($i = 1; $i <= 10; $i++){
        $j = $d * $i;
        $j = str_split($j);
        $ends[end($j)] = $i;
    }
    foreach ($a as $b) {
        if (strlen($b) > 3) {
            $b = substr($b, -3);
        } else {
            $b = $b;
        }
        $c = str_split($b);
        $count = count($c);

        $last = end($c);
        if(isset($last, $ends)) {
            $r = $b - (($ends[$last] - 1) * $d);
            if(strpos($r, $d) !== false) {
                IO::yes();
            } else {
                IO::no();
            }
        } else {
            if($count == 3) {
                $prev = $c[1];
                if(isset($prev, $ends)) {
                    IO::yes();
                } else {
                    IO::no();
                }
            } else {
                IO::no();
            }
        }
    }
}

<?php
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($q, $d) = IO::arr();
    $a = IO::arr();
    $ends = [];
    for($i = 1; $i <= 10; $i++){
        $j = $d * $i;
        $j = str_split($j);
        $ends[end($j)] = $i;
    }
    foreach ($a as $b) {
        if (strlen($b) > 3) {
            $b = substr($b, -3);
        } else {
            $b = $b;
        }
        $c = str_split($b);
        $last = end($c);
        if(isset($last, $ends)) {
            $r = $b - (($ends[$last] - 1) * $d);
            if(strpos($r, $d) !== false) {
                IO::yes();
            } else {
                IO::no();
            }
        } else {
            IO::no();
        }
    }
}

<?php
    $iCount = read();

    for($i=0; $i < $iCount; $i++) {
        $aTest = explode(' ', read());
        $aTest2 = explode(' ', read());

        $iLuck = $aTest[1];
        foreach ($aTest2 AS $sTest) {
            $iTest = (int)$sTest;
            if(strpos($sTest, '7') !== false) {
                write('YES');
                continue;
            } else if($iTest < 13) {
                write('NO');
                continue;
            } else {
                while ($iTest > 7 || strpos($iTest . '', '7') !== false) {
                    $iTest -= 7;
                    if (strpos($iTest . '', '7') !== false) {
                        write('YES');
                        continue 2;
                    }
                }
            }

            write('NO');

        }
    }

    function write($a) {
        echo $a . "\n";
    }

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


The Little Elephant loves sortings.He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.

The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.

In a single line print a single integer — the answer to the problem. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample the array is already sorted in the non-decreasing order, so the answer is 0.In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].

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

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

$res = 0;
for($i=1;$i<$n;$i++) if($a[$i] < $a[$i - 1]) $res -= $a[$i] - $a[$i - 1];

print $res;
?>


You are given an integer a that consists of n digits. You are also given a sequence of digits s of length m. The digit in position j (1 ≤ j ≤ m) of sequence s means that you can choose an arbitrary position i (1 ≤ i ≤ n) in a and replace the digit in the chosen position i with sj. Each element in the sequence s can participate in no more than one replacing operation.Your task is to perform such sequence of replacements, that the given number a gets maximum value. You are allowed to use not all elements from s.

The first line contains positive integer a. Its length n is positive and doesn't exceed 105. The second line contains sequence of digits s. Its length m is positive and doesn't exceed 105. The digits in the sequence s are written consecutively without any separators. The given number a doesn't contain leading zeroes.

Print the maximum value that can be obtained from a after a series of replacements. You are allowed to use not all elements from s. The printed number shouldn't contain any leading zeroes.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = str_split($b);
rsort($c);
$d = 0;
for($x = 0; $x < strlen($a); $x++)
{
    if($c[$d] > $a[$x])
    {
        $a[$x] = $c[$d];
        $d++;
    }
}
print $a;
?>

<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$A = $Scanner->Scan();
	$B = $Scanner->Scan();

	$ADig = str_split($A);
	$BDig = str_split($B);
	rsort($BDig);
	$Alen = count($ADig);
	$Blen = count($BDig);
	$start = 0;
	for ($i = 0; $i < $Blen; $i++) {
		$REPLACE = false;
		for ($j = $start; $j < $Alen; $j++) {
			if ($BDig[$i] > $ADig[$j]) {
				$temp = $ADig[$j];
				$ADig[$j] = $BDig[$i];
				$BDig[$i] = $temp;
				$start = $j + 1;
				$REPLACE = true;
				break;
			}
		}
		if (!$REPLACE) break;
	}

	$a =implode($ADig);
	print($a);

	$Scanner->Close();
}

class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);
		$contents = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	public function Scan(){
		return $this->Scanners[$this->Id++];
	}

	public function Close(){
		fclose($this->Stream);
	}
}

?>


Recently Vova found $$$n$$$ candy wrappers. He remembers that he bought $$$x$$$ candies during the first day, $$$2x$$$ candies during the second day, $$$4x$$$ candies during the third day, $$$\dots$$$, $$$2^{k-1} x$$$ candies during the $$$k$$$-th day. But there is an issue: Vova remembers neither $$$x$$$ nor $$$k$$$ but he is sure that $$$x$$$ and $$$k$$$ are positive integers and $$$k > 1$$$.Vova will be satisfied if you tell him any positive integer $$$x$$$ so there is an integer $$$k>1$$$ that $$$x + 2x + 4x + \dots + 2^{k-1} x = n$$$. It is guaranteed that at least one solution exists. Note that $$$k > 1$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$3 \le n \le 10^9$$$) — the number of candy wrappers Vova found. It is guaranteed that there is some positive integer $$$x$$$ and integer $$$k>1$$$ that $$$x + 2x + 4x + \dots + 2^{k-1} x = n$$$.

Print one integer — any positive integer value of $$$x$$$ so there is an integer $$$k>1$$$ that $$$x + 2x + 4x + \dots + 2^{k-1} x = n$$$.

NoteIn the first test case of the example, one of the possible answers is $$$x=1, k=2$$$. Then $$$1 \cdot 1 + 2 \cdot 1$$$ equals $$$n=3$$$.In the second test case of the example, one of the possible answers is $$$x=2, k=2$$$. Then $$$1 \cdot 2 + 2 \cdot 2$$$ equals $$$n=6$$$.In the third test case of the example, one of the possible answers is $$$x=1, k=3$$$. Then $$$1 \cdot 1 + 2 \cdot 1 + 4 \cdot 1$$$ equals $$$n=7$$$.In the fourth test case of the example, one of the possible answers is $$$x=7, k=2$$$. Then $$$1 \cdot 7 + 2 \cdot 7$$$ equals $$$n=21$$$.In the fifth test case of the example, one of the possible answers is $$$x=4, k=3$$$. Then $$$1 \cdot 4 + 2 \cdot 4 + 4 \cdot 4$$$ equals $$$n=28$$$.

<?php
// $stdin = fopen('input.txt', 'r');

$solve = function($n){

	$k = 1;
	$r = 1;
	do{

		$r *= 2;
		$k += $r;

		if($n % $k == 0){
			return $n / $k;
		}

	} while(true);

};

$t = intval(fgets(STDIN));
for(; $t > 0; $t--){

	$n = intval(fgets(STDIN));

	echo $solve($n) . "\n";
}

<?php
error_reporting(0);

main();

function main() {
	list($cases) = explode(" ", trim(fgets(STDIN)));

	for ($i = 0; $i < $cases; $i++) {
		$n = trim(fgets(STDIN));
		print run($n) . "\n";

	}
}

function run($n) {
	$res = [];

	$num = 0;

	for ($i = 0; $i < 100000; $i++) {
			$num += pow(2, $i);

			$res[$i] = $num;

			if ($num > pow(10, 9)) {
				break;
			}
	}
	foreach ($res as $r) {
		if ($r != 1) {
			if ($n % $r == 0) {
				return $n/$r;
			}
		}
	}

	return -1;

}

?>

<?php

for($t = intval(trim(fgets(STDIN))); $t > 0; $t --){
    //print pow(2, intval(fgets(STDIN)) - 1)."\n";
    $n = intval(fgets(STDIN));
    $limit = $n;
    $flag = 0;
    for($i = 2; $i < $n; $i++){
        $sum = pow(2, $i) - 1;
        if($n % $sum == 0){
            print $n / $sum."\n";
            break;

        }

    }
}

<?php

$t = (int)fgets(STDIN);
for ($i = 0; $i < $t; $i++) {
    $n = (int)fgets(STDIN);
    $k = 2;
    do {
        $x = $n / (pow(2, $k) - 1);
        $k++;
    } while (!is_int($x));

    fputs(STDOUT, $x.PHP_EOL);
}

<?php
    //phpinfo();
    // 输入
    function slove($n)
    {
        for($i = 2; $i <= 30; $i ++)
        {
            if($n % ((1 << $i) - 1) == 0) return $n / ((1 << $i) - 1) ;
        }
        return $n ;
    }

    $a = trim(fgets(STDIN));
    while($a --)
    {
        $n = trim(fgets(STDIN));

        echo slove($n) . "\n" ;
    }
?>


DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x) = x mod p. Operation a mod b denotes taking a remainder after division a by b.However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the i-th insertion, you should output i. If no conflict happens, just output -1.

The first line contains two integers, p and n (2 ≤ p, n ≤ 300). Then n lines follow. The i-th of them contains an integer xi (0 ≤ xi ≤ 109).

Output a single integer — the answer to the problem.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = array();
for($x = 1; $x <= $b; $x++)
{
    $c = trim(fgets(STDIN));
    $d = $c % $a;
    array_push($e, $d);
    $f = count($e);
    $g = array_unique($e);
    if($f != count($g))
    {
        break;
    }
}
if($f != count($g))
{
    print $x;
}
else
{
    print "-1";
}
?>

<?php

$occ = [];
$res = -1;
$found = false;
fscanf(STDIN, "%d %d", $p, $n);
for ($i = 0; $i < $n; $i++) {
	$k = (int)fgets(STDIN);
	if (isset($occ[$k % $p]) && !$found) {
		$res = $i+1;
		$found = true;
	}
	else {
		$occ[$k % $p] = 1;
	}
}

echo $res."\n";

<?php
    $in = 'php://stdin';
    //$in = 'inputA.txt';

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

    list($p, $n) = explode(" ", trim(fgets($input)));
    $Flags = Array();

    for ($i=0;$i<$p;$i++)
        $Flags[$i] = 0;

    for ($i=1;$i<=$n;$i++) {
        $m = trim(fgets($input));

        if ($Flags[$m%$p]==1) die(''.$i);

        $Flags[$m%$p]=1;
    }

    echo '-1';

?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = array();
for($x = 1; $x <= $a; $x++)
{
    $c = trim(fgets(STDIN));
    $d = $c % $a;
    array_push($e, $d);
    $f = count($e);
    $g = array_unique($e);
    if($f != count($g))
    {
        break;
    }
}
if($f != count($g))
{
    print $x;
}
else
{
    print "-1";
}
?>


Two integer sequences existed initially — one of them was strictly increasing, and the other one — strictly decreasing.Strictly increasing sequence is a sequence of integers $$$[x_1 < x_2 < \dots < x_k]$$$. And strictly decreasing sequence is a sequence of integers $$$[y_1 > y_2 > \dots > y_l]$$$. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.They were merged into one sequence $$$a$$$. After that sequence $$$a$$$ got shuffled. For example, some of the possible resulting sequences $$$a$$$ for an increasing sequence $$$[1, 3, 4]$$$ and a decreasing sequence $$$[10, 4, 2]$$$ are sequences $$$[1, 2, 3, 4, 4, 10]$$$ or $$$[4, 2, 1, 10, 4, 3]$$$.This shuffled sequence $$$a$$$ is given in the input.Your task is to find any two suitable initial sequences. One of them should be strictly increasing and the other one — strictly decreasing. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.If there is a contradiction in the input and it is impossible to split the given sequence $$$a$$$ to increasing and decreasing sequences, print "NO".

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

If there is a contradiction in the input and it is impossible to split the given sequence $$$a$$$ to increasing and decreasing sequences, print "NO" in the first line. Otherwise print "YES" in the first line and any two suitable sequences. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing. In the second line print $$$n_i$$$ — the number of elements in the strictly increasing sequence. $$$n_i$$$ can be zero, in this case the increasing sequence is empty. In the third line print $$$n_i$$$ integers $$$inc_1, inc_2, \dots, inc_{n_i}$$$ in the increasing order of its values ($$$inc_1 < inc_2 < \dots < inc_{n_i}$$$) — the strictly increasing sequence itself. You can keep this line empty if $$$n_i = 0$$$ (or just print the empty line). In the fourth line print $$$n_d$$$ — the number of elements in the strictly decreasing sequence. $$$n_d$$$ can be zero, in this case the decreasing sequence is empty. In the fifth line print $$$n_d$$$ integers $$$dec_1, dec_2, \dots, dec_{n_d}$$$ in the decreasing order of its values ($$$dec_1 > dec_2 > \dots > dec_{n_d}$$$) — the strictly decreasing sequence itself. You can keep this line empty if $$$n_d = 0$$$ (or just print the empty line). $$$n_i + n_d$$$ should be equal to $$$n$$$ and the union of printed sequences should be a permutation of the given sequence (in case of "YES" answer).

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


Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input.

Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print  - 1 in the only line.

NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened.

<?php

function readArrayInt($std)
{
    $str = fgets($std);
    $str = explode(' ', $str);
    $a = [];
    $n = count($str);
    for ($i = 0; $i < $n; ++$i)
    {
        $a[] = $str[$i] + 0;
    }
    return $a;
}

function addEdge(&$G, $u, $v, $w)
{
    if (isset($G[$u][$v]))
    {
        $G[$u][$v] = min($G[$u][$v], $w);
    }
    else
    {
        $G[$u][$v] = $w;
    }
}

$stdin = fopen("php://stdin", 'r');
fscanf($stdin, "%d%d%d\n", $n, $m, $k);
$G = [];
for ($i = 0; $i < $m; ++$i)
{
    fscanf($stdin, "%d%d%d\n", $u, $v, $w);
    addEdge($G, $u, $v, $w);
    addEdge($G, $v, $u, $w);
}
$a = array();
if ($k > 0)
{
    $a = readArrayInt($stdin);
}
fclose($stdin);
$used = [];
for ($i = 0; $i < count($a); ++$i)
{
    $used[$a[$i]] = true;
}
$result = -1;
for ($i = 0; $i < count($a); ++$i)
{
    if (isset($G[$a[$i]]))
    {
        $adj = $G[$a[$i]];
        foreach ($adj as $key => $value)
        {
            if (!isset($used[$key]) && ($result == -1 || $result > $value))
            {
                $result = $value;
            }
        }
    }
}
echo $result;
?>


Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a group of b-s), but cccc is not since in each possible consequent partition letters in these two groups coincide.You're given a string s. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string.

The only line contains s (1 ≤ |s| ≤ 105) consisting of lowercase latin letters.

Print «Yes» if the string can be split according to the criteria above or «No» otherwise. Each letter can be printed in arbitrary case.

NoteIn sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable.There's no suitable partition in sample case three.


Vasya lives in a strange world. The year has n months and the i-th month has ai days. Vasya got a New Year present — the clock that shows not only the time, but also the date.The clock's face can display any number from 1 to d. It is guaranteed that ai ≤ d for all i from 1 to n. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number d + 1, so after day number d it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day d is also followed by day 1.Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the n-th month inclusive, considering that on the first day of the first month the clock display showed day 1.

The first line contains the single number d — the maximum number of the day that Vasya's clock can show (1 ≤ d ≤ 106). The second line contains a single integer n — the number of months in the year (1 ≤ n ≤ 2000). The third line contains n space-separated integers: ai (1 ≤ ai ≤ d) — the number of days in each month in the order in which they follow, starting from the first one.

Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.

NoteIn the first sample the situation is like this:   Day 1. Month 1. The clock shows 1. Vasya changes nothing.  Day 2. Month 1. The clock shows 2. Vasya changes nothing.  Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1.  Day 2. Month 2. The clock shows 2. Vasya changes nothing.  In total, Vasya manually changed the day number by 1 exactly 2 times.

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

<?php

fscanf(STDIN,"%d",$d);
fscanf(STDIN,"%d",$n);

$n--;
$sum=0;

$item=explode(" ", trim(fgets(STDIN)));

for($i=0;$i<$n;$i++){
        $tm=($d-$item[$i]);
        $sum+=$tm;
}
echo $sum;

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

$r = 0;
foreach($a as $v){
 $r += $d - $v;
}

$r -= $d - $a[$n - 1];

print $r;
?>

<?

fscanf(STDIN,"%d%d",$d,$n);
while($n--){
    fscanf(STDIN,"%d",$x);
    $sum+=$d-$x;
}
fprintf(STDOUT,"%d",$sum);


Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.

The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000). The following line contains a binary string of length n representing Kevin's results on the USAICO.

Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.

NoteIn the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.In the second sample, Kevin can flip the entire string and still have the same score.


Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если a является другом b, то b также является другом a. В этой же сети есть функция, которая демонстрирует множество людей, имеющих высокую вероятность быть знакомыми для пользователя. Эта функция работает следующим образом. Зафиксируем пользователя x. Пусть некоторый другой человек y, не являющийся другом x на текущий момент, является другом не менее, чем для k% друзей x. Тогда он является предполагаемым другом для x.У каждого человека в социальной сети есть свой уникальный идентификатор — это целое число от 1 до 109. Вам дан список пар пользователей, являющихся друзьями. Определите для каждого упомянутого пользователя множество его предполагаемых друзей.

В первой строке следуют два целых числа m и k (1 ≤ m ≤ 100, 0 ≤ k ≤ 100) — количество пар друзей и необходимый процент общих друзей для того, чтобы считаться предполагаемым другом. В последующих m строках записано по два числа ai, bi (1 ≤ ai, bi ≤ 109, ai ≠ bi), обозначающих идентификаторы пользователей, являющихся друзьями.  Гарантируется, что каждая пара людей фигурирует в списке не более одного раза.

Для всех упомянутых людей в порядке возрастания id выведите информацию о предполагаемых друзьях. Информация должна иметь вид "id:  k id1 id2 ... idk", где id — это id самого человека, k — количество его предполагаемых друзей, а id1, id2, ..., idk — идентификаторы его предполагаемых друзей в возрастающем порядке.

<?PHP
$fileIN = fopen("php://stdin", "r");
$fileOUT = fopen("php://stdout", "w");

$line = explode(" ", trim(fgets($fileIN)));
$n = $line[0];
$k = $line[1];

$friendmap = array();
$possibleFriendMap = array();

for ($i = 0; $i < $n; ++$i) {
    $line = explode(" ", trim(fgets($fileIN)));
    if (!isset($friendmap[$line[0]])) {
        $friendmap[$line[0]] = array();
        array_push($friendmap[$line[0]], $line[1]);
    } else {
        array_push($friendmap[$line[0]], $line[1]);
    }
    if (!isset($friendmap[$line[1]])) {
        $friendmap[$line[1]] = array();
        array_push($friendmap[$line[1]], $line[0]);
    } else {
        array_push($friendmap[$line[1]], $line[0]);
    }
}

function ver($a, $b) {
    global $friendmap;
    $common = 0;
    foreach ($friendmap[$a] as $k1 => $v1) {
        foreach ($friendmap[$b] as $k2 => $v2) {
            if ($v1 == $v2) {
                $common++;
            }
        }
    }
    return ($common);
}

function areFriends($a, $b) {
    global $friendmap;
    foreach ($friendmap[$a] as $key => $value) {
        if ($value == $b) {
            return true;
        }
    }
    return false;
}

// foreach ($friendmap as $key => $value) {
//  echo $key . " : " . count($friendmap[$key]) . " ";
//  foreach ($friendmap[$key] as $key2 => $value2) {
//      echo $value2 . " ";
//  }
//  echo "<br>";
// }

foreach ($friendmap as $key1 => $v1) {
    foreach ($friendmap as $key2 => $v2) {
        if ($key1 != $key2) {
            if (!isset($possibleFriendMap[$key1])) {
                $possibleFriendMap[$key1] = array();
            }
            if (!isset($possibleFriendMap[$key2])) {
                $possibleFriendMap[$key2] = array();
            }
            if (!areFriends($key1, $key2)) {
                if (ver($key1, $key2) * 100 >= sizeof($friendmap[$key1]) * $k) {
                    array_push($possibleFriendMap[$key1], $key2);
                }
            }
        }
    }
}

ksort($possibleFriendMap);
foreach ($possibleFriendMap as $key => $value) {
    sort($possibleFriendMap[$key]);
}

foreach ($possibleFriendMap as $key => $value) {
    fprintf($fileOUT, $key . ": " . count($possibleFriendMap[$key]) . " ");
    foreach ($possibleFriendMap[$key] as $key2 => $value2) {
        fprintf($fileOUT, $value2 . " ");
    }
    fprintf($fileOUT, "\n");
}

fclose($fileOUT);
fclose($fileIN);
?>

<?PHP
$fileIN = fopen("php://stdin", "r");
$fileOUT = fopen("php://stdout", "w");

$line = explode(" ", trim(fgets($fileIN)));
$n = $line[0];
$k = $line[1];

$friendmap = array();
$possibleFriendMap = array();

for ($i = 0; $i < $n; ++$i) {
    $line = explode(" ", trim(fgets($fileIN)));
    if (!isset($friendmap[$line[0]])) {
        $friendmap[$line[0]] = array();
        $possibleFriendMap[$line[0]] = array();
        array_push($friendmap[$line[0]], $line[1]);
    } else {
        array_push($friendmap[$line[0]], $line[1]);
    }
    if (!isset($friendmap[$line[1]])) {
        $friendmap[$line[1]] = array();
        $possibleFriendMap[$line[0]] = array();
        array_push($friendmap[$line[1]], $line[0]);
    } else {
        array_push($friendmap[$line[1]], $line[0]);
    }
}

function ver($a, $b) {
    global $friendmap;
    $common = 0;
    foreach ($friendmap[$a] as $k1 => $v1) {
        foreach ($friendmap[$b] as $k2 => $v2) {
            if ($v1 == $v2) {
                $common++;
            }
        }
    }
    return ($common);
}

function areFriends($a, $b) {
    global $friendmap;
    foreach ($friendmap[$a] as $key => $value) {
        if ($value == $b) {
            return true;
        }
    }
    return false;
}

// foreach ($friendmap as $key => $value) {
//  echo $key . " : " . count($friendmap[$key]) . " ";
//  foreach ($friendmap[$key] as $key2 => $value2) {
//      echo $value2 . " ";
//  }
//  echo "<br>";
// }

foreach ($friendmap as $key1 => $v1) {
    foreach ($friendmap as $key2 => $v2) {
        if ($key1 != $key2) {
            if (!areFriends($key1, $key2)) {
                if (ver($key1, $key2) * 100 >= sizeof($friendmap[$key1]) * $k) {
                    $possibleFriendMap[$key1] = array();
                    array_push($possibleFriendMap[$key1], $key2);
                }
            }
        }
    }
}

ksort($possibleFriendMap);
foreach ($possibleFriendMap as $key => $value) {
    sort($possibleFriendMap[$key]);
}

foreach ($possibleFriendMap as $key => $value) {
    fprintf($fileOUT, $key . ": " . count($possibleFriendMap[$key]) . " ");
    foreach ($possibleFriendMap[$key] as $key2 => $value2) {
        fprintf($fileOUT, $value2 . " ");
    }
    fprintf($fileOUT, "\n");
}

fclose($fileOUT);
fclose($fileIN);
?>

<?PHP
$fileIN = fopen("php://stdin", "r");
$fileOUT = fopen("php://stdout", "w");

$line = explode(" ", trim(fgets($fileIN)));
$n = $line[0];
$k = $line[1];

$friendmap = array();

for ($i = 0; $i < $n; ++$i) {
    $line = explode(" ", trim(fgets($fileIN)));
    if (!isset($friendmap[$line[0]])) {
        $friendmap[$line[0]] = array();
        array_push($friendmap[$line[0]], $line[1]);
    } else {
        array_push($friendmap[$line[0]], $line[1]);
    }
    if (!isset($friendmap[$line[1]])) {
        $friendmap[$line[1]] = array();
        array_push($friendmap[$line[1]], $line[0]);
    } else {
        array_push($friendmap[$line[1]], $line[0]);
    }
}

function ver($a, $b) {
    global $friendmap;
    $common = 0;
    foreach ($friendmap[$a] as $k1 => $v1) {
        foreach ($friendmap[$b] as $k2 => $v2) {
            if ($v1 == $v2) {
                $common++;
            }
        }
    }
    return ($common);
}

function areFriends($a, $b) {
    global $friendmap;
    foreach ($friendmap[$a] as $key => $value) {
        if ($value == $b) {
            return true;
        }
    }
    return false;
}

// foreach ($friendmap as $key => $value) {
//  echo $key . " : " . count($friendmap[$key]) . " ";
//  foreach ($friendmap[$key] as $key2 => $value2) {
//      echo $value2 . " ";
//  }
//  echo "<br>";
// }

$possibleFriendMap = array();

foreach ($friendmap as $key1 => $v1) {
    foreach ($friendmap as $key2 => $v2) {
        if ($key1 != $key2) {
            if (!areFriends($key1, $key2)) {
                if (ver($key1, $key2) * 100 >= sizeof($friendmap[$key1]) * $k) {
                    if (!isset($possibleFriendMap[$key1])) {
                        $possibleFriendMap[$key1] = array();
                        array_push($possibleFriendMap[$key1], $key2);
                    } else {
                        array_push($possibleFriendMap[$key1], $key2);
                    }
                }
            }
        }
    }
}

ksort($possibleFriendMap);
foreach ($possibleFriendMap as $key => $value) {
    sort($possibleFriendMap[$key]);
}

foreach ($possibleFriendMap as $key => $value) {
    fprintf($fileOUT, $key . ": " . count($possibleFriendMap[$key]) . " ");
    foreach ($possibleFriendMap[$key] as $key2 => $value2) {
        fprintf($fileOUT, $value2 . " ");
    }
    fprintf($fileOUT, "\n");
}

fclose($fileOUT);
fclose($fileIN);
?>

<?PHP
$fileIN = fopen("php://stdin", "r");
$fileOUT = fopen("php://stdout", "w");

$line = explode(" ", trim(fgets($fileIN)));
$n = $line[0];
$k = $line[1];

$friendmap = array();

for ($i = 0; $i < $n; ++$i) {
    $line = explode(" ", trim(fgets($fileIN)));
    if (!isset($friendmap[$line[0]])) {
        $friendmap[$line[0]] = array();
        array_push($friendmap[$line[0]], $line[1]);
    } else {
        array_push($friendmap[$line[0]], $line[1]);
    }
    if (!isset($friendmap[$line[1]])) {
        $friendmap[$line[1]] = array();
        array_push($friendmap[$line[1]], $line[0]);
    } else {
        array_push($friendmap[$line[1]], $line[0]);
    }
}

function ver($a, $b) {
    global $friendmap;
    $common = 0;
    foreach ($friendmap[$a] as $k1 => $v1) {
        foreach ($friendmap[$b] as $k2 => $v2) {
            if ($v1 == $v2) {
                $common++;
            }
        }
    }
    return ($common);
}

function areFriends($a, $b) {
    global $friendmap;
    foreach ($friendmap[$a] as $key => $value) {
        if ($value == $b) {
            return true;
        }
    }
    return false;
}

// foreach ($friendmap as $key => $value) {
//  echo $key . " : " . count($friendmap[$key]) . " ";
//  foreach ($friendmap[$key] as $key2 => $value2) {
//      echo $value2 . " ";
//  }
//  echo "<br>";
// }

$possibleFriendMap = array();

foreach ($friendmap as $key1 => $v1) {
    foreach ($friendmap as $key2 => $v2) {
        if ($key1 != $key2) {
            if (!areFriends($key1, $key2)) {
                if (ver($key1, $key2) * 100 >= sizeof($friendmap[$key1]) * $k) {
                    if (!isset($possibleFriendMap[$key1])) {
                        $possibleFriendMap[$key1] = array();
                        array_push($possibleFriendMap[$key1], $key2);
                    } else {
                        array_push($possibleFriendMap[$key1], $key2);
                    }
                }
            }
        }
    }
}

foreach ($possibleFriendMap as $key => $value) {
    fprintf($fileOUT, $key . ": " . count($possibleFriendMap[$key]) . " ");
    foreach ($possibleFriendMap[$key] as $key2 => $value2) {
        fprintf($fileOUT, $value2 . " ");
    }
    fprintf($fileOUT, "\n");
}

fclose($fileOUT);
fclose($fileIN);
?>

<?PHP
$fileIN = fopen("php://stdin", "r");
$fileOUT = fopen("php://stdout", "w");

$line = explode(" ", trim(fgets($fileIN)));
$n = $line[0];
$k = $line[1];

$friendmap = array();
$possibleFriendMap = array();

for ($i = 0; $i < $n; ++$i) {
    $line = explode(" ", trim(fgets($fileIN)));
    if (!isset($friendmap[$line[0]])) {
        $friendmap[$line[0]] = array();
        $possibleFriendMap[$line[0]] = array();
        array_push($friendmap[$line[0]], $line[1]);
    } else {
        array_push($friendmap[$line[0]], $line[1]);
    }
    if (!isset($friendmap[$line[1]])) {
        $friendmap[$line[1]] = array();
        $possibleFriendMap[$line[1]] = array();
        array_push($friendmap[$line[1]], $line[0]);
    } else {
        array_push($friendmap[$line[1]], $line[0]);
    }
}

function ver($a, $b) {
    global $friendmap;
    $common = 0;
    foreach ($friendmap[$a] as $k1 => $v1) {
        foreach ($friendmap[$b] as $k2 => $v2) {
            if ($v1 == $v2) {
                $common++;
            }
        }
    }
    return ($common);
}

function areFriends($a, $b) {
    global $friendmap;
    foreach ($friendmap[$a] as $key => $value) {
        if ($value == $b) {
            return true;
        }
    }
    return false;
}

// foreach ($friendmap as $key => $value) {
//  echo $key . " : " . count($friendmap[$key]) . " ";
//  foreach ($friendmap[$key] as $key2 => $value2) {
//      echo $value2 . " ";
//  }
//  echo "<br>";
// }

foreach ($friendmap as $key1 => $v1) {
    foreach ($friendmap as $key2 => $v2) {
        if ($key1 != $key2) {
            if (!areFriends($key1, $key2)) {
                if (ver($key1, $key2) * 100 >= sizeof($friendmap[$key1]) * $k) {
                    $possibleFriendMap[$key1] = array();
                    array_push($possibleFriendMap[$key1], $key2);
                }
            }
        }
    }
}

ksort($possibleFriendMap);
foreach ($possibleFriendMap as $key => $value) {
    sort($possibleFriendMap[$key]);
}

foreach ($possibleFriendMap as $key => $value) {
    fprintf($fileOUT, $key . ": " . count($possibleFriendMap[$key]) . " ");
    foreach ($possibleFriendMap[$key] as $key2 => $value2) {
        fprintf($fileOUT, $value2 . " ");
    }
    fprintf($fileOUT, "\n");
}

fclose($fileOUT);
fclose($fileIN);
?>

<?PHP
$fileIN = fopen("in.txt", "r");
$fileOUT = fopen("out.txt", "w");

$line = explode(" ", trim(fgets($fileIN)));
$n = $line[0];
$k = $line[1];

$friendmap = array();
$possibleFriendMap = array();

for ($i = 0; $i < $n; ++$i) {
    $line = explode(" ", trim(fgets($fileIN)));
    if (!isset($friendmap[$line[0]])) {
        $friendmap[$line[0]] = array();
        array_push($friendmap[$line[0]], $line[1]);
    } else {
        array_push($friendmap[$line[0]], $line[1]);
    }
    if (!isset($friendmap[$line[1]])) {
        $friendmap[$line[1]] = array();
        array_push($friendmap[$line[1]], $line[0]);
    } else {
        array_push($friendmap[$line[1]], $line[0]);
    }
}

function ver($a, $b) {
    global $friendmap;
    $common = 0;
    foreach ($friendmap[$a] as $k1 => $v1) {
        foreach ($friendmap[$b] as $k2 => $v2) {
            if ($v1 == $v2) {
                $common++;
            }
        }
    }
    return ($common);
}

function areFriends($a, $b) {
    global $friendmap;
    foreach ($friendmap[$a] as $key => $value) {
        if ($value == $b) {
            return true;
        }
    }
    return false;
}

// foreach ($friendmap as $key => $value) {
//  echo $key . " : " . count($friendmap[$key]) . " ";
//  foreach ($friendmap[$key] as $key2 => $value2) {
//      echo $value2 . " ";
//  }
//  echo "<br>";
// }

foreach ($friendmap as $key1 => $v1) {
    foreach ($friendmap as $key2 => $v2) {
        if ($key1 != $key2) {
            if (!isset($possibleFriendMap[$key1])) {
                $possibleFriendMap[$key1] = array();
            }
            if (!isset($possibleFriendMap[$key2])) {
                $possibleFriendMap[$key2] = array();
            }
            if (!areFriends($key1, $key2)) {
                if (ver($key1, $key2) * 100 >= sizeof($friendmap[$key1]) * $k) {
                    array_push($possibleFriendMap[$key1], $key2);
                }
            }
        }
    }
}

ksort($possibleFriendMap);
foreach ($possibleFriendMap as $key => $value) {
    sort($possibleFriendMap[$key]);
}

foreach ($possibleFriendMap as $key => $value) {
    fprintf($fileOUT, $key . ": " . count($possibleFriendMap[$key]) . " ");
    foreach ($possibleFriendMap[$key] as $key2 => $value2) {
        fprintf($fileOUT, $value2 . " ");
    }
    fprintf($fileOUT, "\n");
}

fclose($fileOUT);
fclose($fileIN);
?>

<?PHP
$fileIN = fopen("php://stdin", "r");
$fileOUT = fopen("php://stdout", "w");

$line = explode(" ", trim(fgets($fileIN)));
$n = $line[0];
$k = $line[1];

$friendmap = array();

for ($i = 0; $i < $n; ++$i) {
    $line = explode(" ", trim(fgets($fileIN)));
    if (!isset($friendmap[$line[0]])) {
        $friendmap[$line[0]] = array();
        array_push($friendmap[$line[0]], $line[1]);
    } else {
        array_push($friendmap[$line[0]], $line[1]);
    }
    if (!isset($friendmap[$line[1]])) {
        $friendmap[$line[1]] = array();
        array_push($friendmap[$line[1]], $line[0]);
    } else {
        array_push($friendmap[$line[1]], $line[0]);
    }
}

function ver($a, $b) {
    global $friendmap;
    $common = 0;
    foreach ($friendmap[$a] as $k1 => $v1) {
        foreach ($friendmap[$b] as $k2 => $v2) {
            if ($v1 == $v2) {
                $common++;
            }
        }
    }
    return ($common);
}

function areFriends($a, $b) {
    global $friendmap;
    foreach ($friendmap[$a] as $key => $value) {
        if ($value == $b) {
            return true;
        }
    }
    return false;
}

// foreach ($friendmap as $key => $value) {
//  echo $key . " : " . count($friendmap[$key]) . " ";
//  foreach ($friendmap[$key] as $key2 => $value2) {
//      echo $value2 . " ";
//  }
//  echo "<br>";
// }

$possibleFriendMap = array();

foreach ($friendmap as $key1 => $v1) {
    foreach ($friendmap as $key2 => $v2) {
        if ($key1 != $key2) {
            if (!areFriends($key1, $key2)) {
                if (ver($key1, $key2) * 100 >= sizeof($friendmap[$key1]) * $k) {
                    if (!isset($possibleFriendMap[$key1])) {
                        $possibleFriendMap[$key1] = array();
                        array_push($possibleFriendMap[$key1], $key2);
                    } else {
                        array_push($possibleFriendMap[$key1], $key2);
                    }
                }
            }
        }
    }
}

foreach ($possibleFriendMap as $key => $value) {
    fprintf($fileOUT, $key . " : " . count($possibleFriendMap[$key]) . " ");
    foreach ($possibleFriendMap[$key] as $key2 => $value2) {
        fprintf($fileOUT, $value2 . " ");
    }
    fprintf($fileOUT, "\n");
}

fclose($fileOUT);
fclose($fileIN);
?>

<?PHP
$fileIN = fopen("php://stdin", "r");
$fileOUT = fopen("php://stdout", "w");

$line = explode(" ", trim(fgets($fileIN)));
$n = $line[0];
$k = $line[1];

$friendmap = array();
$possibleFriendMap = array();

for ($i = 0; $i < $n; ++$i) {
    $line = explode(" ", trim(fgets($fileIN)));
    if (!isset($friendmap[$line[0]])) {
        $friendmap[$line[0]] = array();
        array_push($friendmap[$line[0]], $line[1]);
    } else {
        array_push($friendmap[$line[0]], $line[1]);
    }
    if (!isset($friendmap[$line[1]])) {
        $friendmap[$line[1]] = array();
        array_push($friendmap[$line[1]], $line[0]);
    } else {
        array_push($friendmap[$line[1]], $line[0]);
    }
}

function ver($a, $b) {
    global $friendmap;
    $common = 0;
    foreach ($friendmap[$a] as $k1 => $v1) {
        foreach ($friendmap[$b] as $k2 => $v2) {
            if ($v1 == $v2) {
                $common++;
            }
        }
    }
    return ($common);
}

function areFriends($a, $b) {
    global $friendmap;
    foreach ($friendmap[$a] as $key => $value) {
        if ($value == $b) {
            return true;
        }
    }
    return false;
}

// foreach ($friendmap as $key => $value) {
//  echo $key . " : " . count($friendmap[$key]) . " ";
//  foreach ($friendmap[$key] as $key2 => $value2) {
//      echo $value2 . " ";
//  }
//  echo "<br>";
// }

foreach ($friendmap as $key1 => $v1) {
    foreach ($friendmap as $key2 => $v2) {
        if ($key1 != $key2) {
            if (!isset($possibleFriendMap[$key1])) {
                $possibleFriendMap[$key1] = array();
            }
            if (!isset($possibleFriendMap[$key2])) {
                $possibleFriendMap[$key2] = array();
            }
            if (!areFriends($key1, $key2)) {
                if (ver($key1, $key2) * 100 >= sizeof($friendmap[$key1]) * $k) {
                    $possibleFriendMap[$key1] = array();
                    array_push($possibleFriendMap[$key1], $key2);
                }
            }
        }
    }
}

ksort($possibleFriendMap);
foreach ($possibleFriendMap as $key => $value) {
    sort($possibleFriendMap[$key]);
}

foreach ($possibleFriendMap as $key => $value) {
    fprintf($fileOUT, $key . ": " . count($possibleFriendMap[$key]) . " ");
    foreach ($possibleFriendMap[$key] as $key2 => $value2) {
        fprintf($fileOUT, $value2 . " ");
    }
    fprintf($fileOUT, "\n");
}

fclose($fileOUT);
fclose($fileIN);
?>


You have received data from a Bubble bot. You know your task is to make factory facilities, but before you even start, you need to know how big the factory is and how many rooms it has. When you look at the data you see that you have the dimensions of the construction, which is in rectangle shape: N x M. Then in the next N lines you have M numbers. These numbers represent factory tiles and they can go from 0 to 15. Each of these numbers should be looked in its binary form. Because from each number you know on which side the tile has walls. For example number 10 in it's binary form is 1010, which means that it has a wall from the North side, it doesn't have a wall from the East, it has a wall on the South side and it doesn't have a wall on the West side. So it goes North, East, South, West. It is guaranteed that the construction always has walls on it's edges. The input will be correct. Your task is to print the size of the rooms from biggest to smallest.

The first line has two numbers which are N and M, the size of the construction. Both are integers:  $$$n$$$ ($$$1 \leq n \leq 10^3$$$) $$$m$$$ ($$$1 \leq m \leq 10^3$$$) Next N x M numbers represent each tile of construction.

Once you finish processing the data your output consists of one line sorted from biggest to smallest room sizes.

<?php

function recMatrix($y,$x) {
	global $matrix,$number,$answer;
	$answer[$y][$x]=$number;
	if (!($matrix[$y][$x] & 8) && !isset($answer[$y-1][$x])) {
		recMatrix($y-1,$x);
	}
	if (!($matrix[$y][$x] & 4) && !isset($answer[$y][$x+1])) {
		recMatrix($y,$x+1);
	}
	if (!($matrix[$y][$x] & 2) && !isset($answer[$y+1][$x])) {
		recMatrix($y+1,$x);
	}
	if (!($matrix[$y][$x] & 1) && !isset($answer[$y][$x-1])) {
		recMatrix($y,$x-1);
	}
}

$filename=!empty($_GET['input'])?fopen("input.txt", 'r'):STDIN;
$sizes=explode(' ', trim(fgets($filename)));
$matrix=[];
$answer=[];
for ($i=0;$i<$sizes[0];$i++) {
	$matrix[]=explode(' ', trim(fgets($filename)));
	$answer[]=[];
}

$number=0;

for ($j=0;$j<count($matrix);$j++) {
	for ($i=0;$i<count($matrix[$j]);$i++) {
		if (!isset($answer[$j][$i])) {
			recMatrix($j,$i);
			$number++;
		}
	}
}
$count=[];
foreach ($answer as $field) {
	foreach ($field as $n) {
		if (empty($count[$n])) {
			$count[$n]=0;
		}
		$count[$n]++;
	}
}
rsort($count);
echo implode(' ', $count).' ';
?>

<?php

function recMatrix($y,$x) {
	global $matrix,$number,$answer;
	$answer[$y][$x]=$number;
	if (!($matrix[$y][$x] & 8) && !isset($answer[$y-1][$x])) {
		recMatrix($y-1,$x);
	}
	if (!($matrix[$y][$x] & 4) && !isset($answer[$y][$x+1])) {
		recMatrix($y,$x+1);
	}
	if (!($matrix[$y][$x] & 2) && !isset($answer[$y+1][$x])) {
		recMatrix($y+1,$x);
	}
	if (!($matrix[$y][$x] & 1) && !isset($answer[$y][$x-1])) {
		recMatrix($y,$x-1);
	}
}

$filename=!empty($_GET['input'])?fopen("input.txt", 'r'):STDIN;
$sizes=explode(' ', trim(fgets($filename)));
$matrix=[];
$answer=[];
for ($i=0;$i<$sizes[0];$i++) {
	$matrix[]=explode(' ', trim(fgets($filename)));
	$answer[]=[];
}

$number=0;

for ($j=0;$j<count($matrix);$j++) {
	for ($i=0;$i<count($matrix[$j]);$i++) {
		if (!isset($answer[$j][$i])) {
			recMatrix($j,$i);
			$number++;
		}
	}
}
$count=[];
foreach ($answer as $field) {
	foreach ($field as $n) {
		if (empty($count[$n])) {
			$count[$n]=0;
		}
		$count[$n]++;
	}
}
rsort($count);
echo implode(' ', $count);
?>

<?php

function recMatrix($y,$x) {
	global $matrix,$number,$answer;
	$answer[$y][$x]=$number;
	if (!($matrix[$y][$x] & 8) && !isset($answer[$y-1][$x])) {
		recMatrix($y-1,$x);
	}
	if (!($matrix[$y][$x] & 4) && !isset($answer[$y][$x+1])) {
		recMatrix($y,$x+1);
	}
	if (!($matrix[$y][$x] & 2) && !isset($answer[$y+1][$x])) {
		recMatrix($y+1,$x);
	}
	if (!($matrix[$y][$x] & 1) && !isset($answer[$y][$x-1])) {
		recMatrix($y,$x-1);
	}
}
$input=explode("\n", file_get_contents('input.txt'));
$sizes=explode(' ', $input[0]);
$matrix=[];
$answer=[];
for ($i=1;$i<count($input);$i++) {
	$matrix[]=explode(' ', $input[$i]);
	$answer[]=[];
}

$number=0;

for ($j=0;$j<count($matrix);$j++) {
	for ($i=0;$i<count($matrix[$j]);$i++) {
		if (!isset($answer[$j][$i])) {
			recMatrix($j,$i);
			$number++;
		}
	}
}
$count=[];
foreach ($answer as $field) {
	foreach ($field as $n) {
		if (empty($count[$n])) {
			$count[$n]=0;
		}
		$count[$n]++;
	}
}
rsort($count);
echo implode(' ', $count);
?>


You are playing a computer game. To pass the current level, you have to kill a big horde of monsters. In this horde, there are $$$n$$$ monsters standing in the row, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$a_i$$$ health and a special "Death's Blessing" spell of strength $$$b_i$$$ attached to it.You are going to kill all of them one by one. It takes exactly $$$h$$$ seconds to kill a monster with health $$$h$$$.When the $$$i$$$-th monster dies, it casts its spell that increases the health of its neighbors by $$$b_i$$$ (the neighbors of the $$$j$$$-th monster in the row are the monsters on places $$$j - 1$$$ and $$$j + 1$$$. The first and the last monsters have only one neighbor each).After each monster is killed, the row shrinks, so its former neighbors become adjacent to each other (so if one of them dies, the other one is affected by its spell). For example, imagine a situation with $$$4$$$ monsters with health $$$a = [2, 6, 7, 3]$$$ and spells $$$b = [3, 6, 0, 5]$$$. One of the ways to get rid of the monsters is shown below:  $$$2$$$$$$6$$$$$$7$$$$$$3$$$$$$\xrightarrow{6\ s}$$$$$$8$$$$$$13$$$$$$3$$$$$$\xrightarrow{13\ s}$$$$$$8$$$$$$3$$$$$$\xrightarrow{8\ s}$$$$$$6$$$$$$\xrightarrow{6\ s}$$$$$$\{\}$$$$$$3$$$$$$6$$$$$$0$$$$$$5$$$$$$3$$$$$$0$$$$$$5$$$$$$3$$$$$$5$$$$$$5$$$ The first row represents the health of each monster, the second one — the power of the spells. As a result, we can kill all monsters in $$$6 + 13 + 8 + 6$$$ $$$=$$$ $$$33$$$ seconds. Note that it's only an example and may not be the fastest way to get rid of the monsters.What is the minimum time required to kill all monsters in the row?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of monsters in the row. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the initial health of corresponding monsters. The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$0 \le b_i \le 10^9$$$), where $$$b_i$$$ is the strength of the spell for the $$$i$$$-th monster. It's guaranteed that the sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer — the minimum possible total time to kill all monsters.

NoteIn the first test case, there is only one monster that will be killed in $$$10$$$ seconds.In the second test case, it's optimal to kill the first monster, the last monster and then the middle one. It will take $$$100 + 100 + (1 + 1 + 1)$$$ $$$=$$$ $$$203$$$ seconds.In the third test case, it's optimal to kill the first monster, then the third one, then the fourth one and finally the second one. It will take $$$2 + 7 + (3 + 0) + (3 + 6 + 5)$$$ $$$=$$$ $$$26$$$ seconds.

<?php
      $inp = preg_split('#\s+#', trim(file_get_contents("php://stdin")));
      $p = 0;
      $tests = intval($inp[$p++]);
      for($test=0;$test<$tests;$test++)
      {
        $n = intval($inp[$p++]);
        $a = array();
        $b = array();
        for($i=0;$i<$n;$i++) $a[] = intval($inp[$p++]);
        for($i=0;$i<$n;$i++) $b[] = intval($inp[$p++]);
	sort($b);
	unset($b[count($b)-1]);
	echo (array_sum($a) + array_sum($b))."\n";

      }


Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there.If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift.Now Petya wants to know for each friend i the number of a friend who has given him a gift.

The first line contains one integer n (1 ≤ n ≤ 100) — the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi — the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.

Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i.

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

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

for ($i=1; $i <=$n ; $i++) {
	echo array_search($i, $p)+1 . " ";
}

?>

<?php
function input()
{
    while (($line = fgets(STDIN)) != PHP_EOL) {
        yield $line;
    }
}

$COUNT = 0;
foreach (input() as $line) {
    if ($COUNT == 0) {
        $n = intval($line);
        ++$COUNT;
        continue;
    }
    $p = explode(' ', $line);
    // print_r($p);
    $r = array(count($p));
    for($i=0; $i<$n; ++$i) {
        $r[intval($p[$i])-1] = $i+1;
    }

    for($i=0; $i<$n; ++$i) {
        echo $r[$i] . " ";
    }
    // echo $x;

    if (++$COUNT > 1) {
        break;
    }
}

<?php
$n = (int) readline();
$nums = array_map('intval', explode(' ', readline()));
$result = array();
foreach($nums as $key => $num){
    $result[$num] = $key+1;
}

for($i=1; $i<=$n;$i++){
    echo $result[$i] . " ";
}

<?php

fscanf(STDIN, '%d', $number);
$guests = explode(" ", trim(fgets(STDIN)));
$str = '';
for ($i = 1; $i <= $number; $i++) {
    $str .= (array_search($i, $guests) + 1) . " ";
}

print(trim($str, ' '));

<?php
fscanf(STDIN,"%d",$n);
$line=trim(fgets(STDIN));
$singleValue=explode(' ',$line);

$saveToAnother=$singleValue;

for($i=0;$i<$n;$i++)
{
	for($j=0;$j<$n-1;$j++)
	{
		if($saveToAnother[$i]<$saveToAnother[$j])
		{
			$saveToAnother[$i]=$saveToAnother[$i]+$saveToAnother[$j];
			$saveToAnother[$j]=$saveToAnother[$i]-$saveToAnother[$j];
			$saveToAnother[$i]=$saveToAnother[$i]-$saveToAnother[$j];
		}
	}
}
for($i=0;$i<$n;$i++)
$store[$i]=array_keys($singleValue,$saveToAnother[$i]);

for($i=0;$i<$n-1;$i++){
$str[$i]=$store[$i][0]+1;
echo "$str[$i] ";
}
echo $store[$n-1][0]+1;

<?php
class Stream {

    const STDIN = 'php://stdin';
    const STDOUT = 'php://stdout';

    const READ = 'r';
    const WRITE = 'w';

    const SPACE = " ";
    const ENDL = "\n";

    protected $stream;

    public function __construct($file, $mode) {
        $this->stream = fopen($file, $mode);
    }

    public function __destruct() {
        fclose($this->stream);
    }

}

class InputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDIN) {
        parent::__construct($file, self::READ);
    }

    private function update() {
        $content = stream_get_contents($this->stream);
        $buffer = explode(self::ENDL, $content);
        foreach ($buffer as $k => $v) {
            $buffer[$k] = strtr($v, array("\n", "\r"), "");
            $buffer[$k] = explode(self::SPACE, $buffer[$k]);
        }
        $this->buffer = array_merge($this->buffer, $buffer);
    }

    public function read() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = array_shift($this->buffer[0]);
            if (count($this->buffer[0]) <= 0) {
                array_shift($this->buffer);
            }
        }
        return $buf;
    }

    public function readLine() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = implode(self::SPACE, $this->buffer[0]);
            array_shift($this->buffer);
        }
        return $buf;
    }

}

class OutputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDOUT) {
        parent::__construct($file, self::WRITE);
    }

    public function flush() {
        fwrite($this->stream, implode($this->buffer));
        $this->buffer = array();
    }

    public function write($var) {
        array_push($this->buffer, $var);
    }

    public function __destruct() {
        $this->flush();
        parent::__destruct();
    }

}

global $stdin, $stdout;

$stdin = new InputStream();
$stdout = new OutputStream();

/* Program Code */
$n = 0; $a = array(); $p = array();

$n = $stdin->read();
for ($i = 1; $i <= $n; $i++) {
    $p[$i] = (int) $stdin->read();
    $a[$p[$i]] = $i;
}

for ($i = 1; $i <= $n; $i++) {
    $stdout->write($a[$i] . " ");
}
?>

<?php
$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');

$n = trim(fgets($f));
$s = trim(fgets($f));

$a = explode(" ",$s);

$b = array();
foreach($a as $k=>$x){
    $b[$x] = $k+1;
}
ksort($b);

echo(implode(" ",$b));

<?php

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

fscanf( $stdin , "%d" , $t ) ;

fscanf( $stdin , "%[^\n]" , $test ) ;

$numbers = array_map( 'intval' , preg_split('/ /' , $test , -1 , PREG_SPLIT_NO_EMPTY ) );

$arr = [] ;

for( $i=0 ; $i<$t ; $i++)
{
     $x = $numbers[$i] ;
     $arr[ $numbers[$x-1] ] = $x ;
}
for( $i=1 ; $i<=$t ; $i++)
{
     echo $arr[$i] . " " ;
}

fwrite($stdout);

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

?>

<?php
$n = trim(fgets(STDIN));
$a = explode(' ',trim(fgets(STDIN)));
for($i=1;$i<=$n;$i++) print (array_search($i,$a)+1).' ';
?>

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

for ($i=1;$i<=$n;$i++){
	echo array_search($i, $a)+1 . " ";
}
?>

<?php
$fr = trim(fgets(STDIN));
$nfr = explode(' ', trim(fgets(STDIN)));
$array = array();
foreach ($nfr as $k => $v)
{
    $array[$k + 1] = $v;
}
foreach ($array as $k => $v)
{
    $mas[] = array_search($k, $array);
}

echo implode(' ', $mas);

?>

<?php
$input = explode("\n", trim(file_get_contents("php://stdin")));
unset($input[0]);
$prs = explode(' ',$input[1]);
$ipr = array();
foreach($prs as $pr => $fr){
    $ipr[--$fr] = ++$pr;
}
ksort($ipr);
echo implode(' ', $ipr);

<?php
// 136A Подарки

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

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

$out = '';

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

$arr = array_flip ( $arr );

ksort($arr);

foreach ($arr as $key => $value) {
    $x = $value + 1;
    $out .= "$x ";
}

echo $out;

?>

<?php
    $a = trim(fgets(STDIN));
    $b = explode(' ',trim(fgets(STDIN)));
   // $ball=explode(' ',trim(fgets(STDIN)));
  asort($b); $count=$b[0];  $k=1;
  foreach ($b as $key=>$value)
  {

      print(($key+1)." ");
  }

?>

<?php
fscanf(STDIN, '%d', $n);
$in = explode(' ', fgets(STDIN));

$arr = array();
for ($i = 0; $i < $n; $i++) {
    $arr[$in[$i]] = $i + 1;
}

ksort($arr);
foreach($arr as $elem) {
    echo $elem.' ';
}

<?php

/**
 * @author: Sunwarul Islam, Bangladesh
 * Php 7.2
 */

$n = (int) fgets(STDIN);
$myarr = array_map('intval', preg_split('/ /', fgets(STDIN)));
$new_arr = [];

for ($i = 0; $i < count($myarr); $i++) {
    $new_arr[$myarr[$i] - 1] = $i + 1;
}

for ($i = 0; $i < count($new_arr); $i++) {
    echo $new_arr[$i] . " ";
}
echo "\n";

<?
$n=fgets(STDIN);
$m=explode(" ",fgets(STDIN));
foreach($m as $k => $v)$x[$v]=$k+1;
ksort($x);
foreach($x as $xv)echo $xv." ";

?>

<?
$fp=fopen('php://stdin', 'r');
$lines=stream_get_contents($fp);
$lines=trim($lines);
$lines=explode("\n", $lines);

$arr=array();
$ps=explode(" ", trim($lines[1]));
foreach ($ps as $from=>$to)
    $arr[$from+1]=$to;

foreach($arr as $from=>$to)
    $res[]=array_search($from, $arr);
echo implode(" ", $res);

?>

<?php

while (fscanf(STDIN, "%d", $people_num)){
    $gifts = stream_get_line(STDIN, 65535, "\n");
    $person_gift = array();
    $person_gift = explode(' ', $gifts);

    $person_gift = array_flip($person_gift);
    ksort($person_gift);

    $i = 1;
    foreach ($person_gift as $key => $value){
        echo $value + 1;
        if ($i == $people_num){
            echo "\n";
        } else {
            echo ' ';
        }
        ++$i;
    }
}

<?php
error_reporting("off");
//136A: Presents
$n = trim(fgets(STDIN)); //$n = 4;
$parray = explode(" ", trim(fgets(STDIN))); //$parray = explode(" ", "4 2 1 5 3");
$startatone = array();
foreach ($parray as $key => $value) {
    $startatone[$key+1] = $value;
}
$gaveto = array();
foreach ($startatone as $key => $value) {
    $gaveto[$value] = $key;
}
ksort($gaveto);
$implode = implode(" ", $gaveto);
echo $implode;
?>

<?php
$n = fgets(STDIN);
$no=array();
$friend = explode(" ",fgets(STDIN));
for ($i=0;$i<$n;$i++)
{
    $no[$friend[$i]-1] = $i;
}
var_dump($no);
for ($i=0;$i<$n;$i++)
{
    echo $no[$i]+1;
}

<?php
$n = fgets(STDIN);
$friend = explode(" ",fgets(STDIN));
for ($i=0;$i<$n;$i++)
{
    echo $friend[$friend[$i]%4]." ";
}

<?php
$n = fgets(STDIN);
$friend = explode(" ",fgets(STDIN));
for ($i=0;$i<$n;$i++)
{
    echo $friend[$friend[$i]%$n]." ";
}

<?php
class Stream {

    const STDIN = 'php://stdin';
    const STDOUT = 'php://stdout';

    const READ = 'r';
    const WRITE = 'w';

    const SPACE = " ";
    const ENDL = "\n";

    protected $stream;

    public function __construct($file, $mode) {
        $this->stream = fopen($file, $mode);
    }

    public function __destruct() {
        fclose($this->stream);
    }

}

class InputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDIN) {
        parent::__construct($file, self::READ);
    }

    private function update() {
        $content = stream_get_contents($this->stream);
        $buffer = explode(self::ENDL, $content);
        foreach ($buffer as $k => $v) {
            $buffer[$k] = explode(self::SPACE, $v);
        }
        $this->buffer = array_merge($this->buffer, $buffer);
    }

    public function read() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = array_shift($this->buffer[0]);
            if (count($this->buffer[0]) <= 0) {
                array_shift($this->buffer);
            }
        }
        return $buf;
    }

    public function readLine() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = implode(self::SPACE, $this->buffer[0]);
            array_shift($this->buffer);
        }
        return $buf;
    }

}

class OutputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDOUT) {
        parent::__construct($file, self::WRITE);
    }

    public function flush() {
        fwrite($this->stream, implode($this->buffer));
        $this->buffer = array();
    }

    public function write($var) {
        array_push($this->buffer, $var);
    }

    public function __destruct() {
        $this->flush();
        parent::__destruct();
    }

}

global $stdin, $stdout;

$stdin = new InputStream();
$stdout = new OutputStream();

/* Program Code */
$n = 0; $a = array(); $p = array();

$n = $stdin->read();
for ($i = 1; $i <= $n; $i++) {
    $p[$i] = $stdin->read();
    $a[$p[$i]] = $i;
}

for ($i = 1; $i <= $n; $i++) {
    $stdout->write($a[$i] . " ");
}
?>

<?php
class Stream {

    const STDIN = 'php://stdin';
    const STDOUT = 'php://stdout';

    const READ = 'r';
    const WRITE = 'w';

    const SPACE = " ";
    const ENDL = "\n";

    protected $stream;

    public function __construct($file, $mode) {
        $this->stream = fopen($file, $mode);
    }

    public function __destruct() {
        fclose($this->stream);
    }

}

class InputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDIN) {
        parent::__construct($file, self::READ);
    }

    private function update() {
        $content = stream_get_contents($this->stream);
        $content = strtr($content, "\r", "");
        $buffer = explode(self::ENDL, $content);
        foreach ($buffer as $k => $v) {
            $buffer[$k] = explode(self::SPACE, $v);
        }
        $this->buffer = array_merge($this->buffer, $buffer);
    }

    public function read() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = array_shift($this->buffer[0]);
            if (count($this->buffer[0]) <= 0) {
                array_shift($this->buffer);
            }
        }
        return $buf;
    }

    public function readLine() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = implode(self::SPACE, $this->buffer[0]);
            array_shift($this->buffer);
        }
        return $buf;
    }

}

class OutputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDOUT) {
        parent::__construct($file, self::WRITE);
    }

    public function flush() {
        fwrite($this->stream, implode($this->buffer));
        $this->buffer = array();
    }

    public function write($var) {
        array_push($this->buffer, $var);
    }

    public function __destruct() {
        $this->flush();
        parent::__destruct();
    }

}

global $stdin, $stdout;

$stdin = new InputStream();
$stdout = new OutputStream();

/* Program Code */
$n = 0; $a = array(); $p = array();

$n = $stdin->read();
for ($i = 1; $i <= $n; $i++) {
    $p[$i] = $stdin->read();
    $a[$p[$i]] = $i;
}

for ($i = 1; $i <= $n; $i++) {
    $stdout->write($a[$i] . " ");
}
?>

<?php
$n = trim(fgets(STDIN));
$a = explode(' ',trim(fgets(STDIN)));
for($i=2;$i<=$n;$i++) print (array_search($i,$a)+1).' ';
?>

<?php
class Stream {

	const STDIN = 'php://stdin';
	const STDOUT = 'php://stdout';

	const READ = 'r';
	const WRITE = 'w';

	const SPACE = " ";
	const ENDL = "\n";

	protected $stream;

	public function __construct($file, $mode) {
		$this->stream = fopen($file, $mode);
	}

	public function __destruct() {
		fclose($this->stream);
	}

}

class InputStream extends Stream {

	private $buffer = array();

	public function __construct($file = self::STDIN) {
		parent::__construct($file, self::READ);
	}

	private function update() {
		$content = stream_get_contents($this->stream);
		$buffer = explode(self::ENDL, $content);
		foreach ($buffer as $k => $v) {
			$buffer[$k] = strtr($v, array("\n", "\r"), "");
			$buffer[$k] = explode(self::SPACE, $buffer[$k]);
		}
		$this->buffer = array_merge($this->buffer, $buffer);
	}

	public function read() {
		$this->update();
		if (count($this->buffer) <= 0) {
			$buf = NULL;
		} else {
			$buf = array_shift($this->buffer[0]);
			if (count($this->buffer[0]) <= 0) {
				array_shift($this->buffer);
			}
		}
		return $buf;
	}

	public function readLine() {
		$this->update();
		if (count($this->buffer) <= 0) {
			$buf = NULL;
		} else {
			$buf = implode(self::SPACE, $this->buffer[0]);
			array_shift($this->buffer);
		}
		return $buf;
	}

}

class OutputStream extends Stream {

	private $buffer = array();

	public function __construct($file = self::STDOUT) {
		parent::__construct($file, self::WRITE);
	}

	public function flush() {
		fwrite($this->stream, implode($this->buffer));
		$this->buffer = array();
	}

	public function write($var) {
		array_push($this->buffer, $var);
	}

	public function __destruct() {
		$this->flush();
		parent::__destruct();
	}

}

global $stdin, $stdout;

$stdin = new InputStream();
$stdout = new OutputStream();

/* Program Code */
$n = 0; $a = array(); $p = array();

$n = $stdin->read();
for ($i = 1; $i <= $n; $i++) {
	$p[$i] = $stdin->read();
	$a[$p[$i]] = $i;
}

for ($i = 1; $i <= $n; $i++) {
	$stdout->write($a[$i] . " ");
}
?>

<?php
class Stream {

    const STDIN = 'php://stdin';
    const STDOUT = 'php://stdout';

    const READ = 'r';
    const WRITE = 'w';

    const SPACE = " ";
    const ENDL = "\n";

    protected $stream;

    public function __construct($file, $mode) {
        $this->stream = fopen($file, $mode);
    }

    public function __destruct() {
        fclose($this->stream);
    }

}

class InputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDIN) {
        parent::__construct($file, self::READ);
    }

    private function update() {
        $content = stream_get_contents($this->stream);
        $buffer = explode(self::ENDL, $content);
        var_dump($buffer);
        foreach ($buffer as $k => $v) {
            $buffer[$k] = strtr($v, array("\n", "\r"), "");
            $buffer[$k] = explode(self::SPACE, $buffer[$k]);
        }
        $this->buffer = array_merge($this->buffer, $buffer);
    }

    public function read() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = array_shift($this->buffer[0]);
            if (count($this->buffer[0]) <= 0) {
                array_shift($this->buffer);
            }
        }
        return $buf;
    }

    public function readLine() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = implode(self::SPACE, $this->buffer[0]);
            array_shift($this->buffer);
        }
        return $buf;
    }

}

class OutputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDOUT) {
        parent::__construct($file, self::WRITE);
    }

    public function flush() {
        fwrite($this->stream, implode($this->buffer));
        $this->buffer = array();
    }

    public function write($var) {
        array_push($this->buffer, $var);
    }

    public function __destruct() {
        $this->flush();
        parent::__destruct();
    }

}

global $stdin, $stdout;

$stdin = new InputStream();
$stdout = new OutputStream();

/* Program Code */
$n = 0; $a = array(); $p = array();

$n = $stdin->read();
for ($i = 1; $i <= $n; $i++) {
    $p[$i] = $stdin->read();
    $stdout->write($p[$i] . " ");
    $a[$p[$i]] = $i;
}

for ($i = 1; $i <= $n; $i++) {
    $stdout->write($a[$i] . " ");
}
?>

<?php
class Stream {

	const STDIN = 'php://stdin';
	const STDOUT = 'php://stdout';

	const READ = 'r';
	const WRITE = 'w';

	const SPACE = " ";
	const ENDL = "\n";

	protected $stream;

	public function __construct($file, $mode) {
		$this->stream = fopen($file, $mode);
	}

	public function __destruct() {
		fclose($this->stream);
	}

}

class InputStream extends Stream {

	private $buffer = array();

	public function __construct($file = self::STDIN) {
		parent::__construct($file, self::READ);
	}

	private function update() {
		$content = stream_get_contents($this->stream);
		$buffer = explode(self::ENDL, $content);
		var_dump($buffer);
		foreach ($buffer as $k => $v) {
			$buffer[$k] = strtr($v, array("\n", "\r"), "");
			$buffer[$k] = explode(self::SPACE, $buffer[$k]);
		}
		$this->buffer = array_merge($this->buffer, $buffer);
	}

	public function read() {
		$this->update();
		if (count($this->buffer) <= 0) {
			$buf = NULL;
		} else {
			$buf = array_shift($this->buffer[0]);
			if (count($this->buffer[0]) <= 0) {
				array_shift($this->buffer);
			}
		}
		return $buf;
	}

	public function readLine() {
		$this->update();
		if (count($this->buffer) <= 0) {
			$buf = NULL;
		} else {
			$buf = implode(self::SPACE, $this->buffer[0]);
			array_shift($this->buffer);
		}
		return $buf;
	}

}

class OutputStream extends Stream {

	private $buffer = array();

	public function __construct($file = self::STDOUT) {
		parent::__construct($file, self::WRITE);
	}

	public function flush() {
		fwrite($this->stream, implode($this->buffer));
		$this->buffer = array();
	}

	public function write($var) {
		array_push($this->buffer, $var);
	}

	public function __destruct() {
		$this->flush();
		parent::__destruct();
	}

}

global $stdin, $stdout;

$stdin = new InputStream();
$stdout = new OutputStream();

/* Program Code */
$n = 0; $a = array(); $p = array();

$n = $stdin->read();
for ($i = 1; $i <= $n; $i++) {
	$p[$i] = $stdin->read();
	$a[$p[$i]] = $i;
}

for ($i = 1; $i <= $n; $i++) {
	$stdout->write($a[$i] . " ");
}
?>

<?php
class Stream {

    const STDIN = 'php://stdin';
    const STDOUT = 'php://stdout';

    const READ = 'r';
    const WRITE = 'w';

    const SPACE = " ";
    const ENDL = "\n";

    protected $stream;

    public function __construct($file, $mode) {
        $this->stream = fopen($file, $mode);
    }

    public function __destruct() {
        fclose($this->stream);
    }

}

class InputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDIN) {
        parent::__construct($file, self::READ);
    }

    private function update() {
        $content = stream_get_contents($this->stream);
        $buffer = explode(self::ENDL, $content);
        var_dump($buffer);
        foreach ($buffer as $k => $v) {
            $buffer[$k] = strtr($v, array("\n", "\r"), "");
            $buffer[$k] = explode(self::SPACE, $buffer[$k]);
        }
        $this->buffer = array_merge($this->buffer, $buffer);
    }

    public function read() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = array_shift($this->buffer[0]);
            if (count($this->buffer[0]) <= 0) {
                array_shift($this->buffer);
            }
        }
        return $buf;
    }

    public function readLine() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = implode(self::SPACE, $this->buffer[0]);
            array_shift($this->buffer);
        }
        return $buf;
    }

}

class OutputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDOUT) {
        parent::__construct($file, self::WRITE);
    }

    public function flush() {
        var_dump($this->buffer);
        fwrite($this->stream, implode($this->buffer));
        $this->buffer = array();
    }

    public function write($var) {
        array_push($this->buffer, $var);
    }

    public function __destruct() {
        $this->flush();
        parent::__destruct();
    }

}

global $stdin, $stdout;

$stdin = new InputStream();
$stdout = new OutputStream();

/* Program Code */
$n = 0; $a = array(); $p = array();

$n = $stdin->read();
for ($i = 1; $i <= $n; $i++) {
    $p[$i] = (int) $stdin->read();
    $stdout->write($p[$i] . " ");
    $a[$p[$i]] = $i;
}

for ($i = 1; $i <= $n; $i++) {
    $stdout->write($a[$i] . " ");
}
?>

<?php
class Stream {

    const STDIN = 'php://stdin';
    const STDOUT = 'php://stdout';

    const READ = 'r';
    const WRITE = 'w';

    const SPACE = " ";
    const ENDL = "\n";

    protected $stream;

    public function __construct($file, $mode) {
        $this->stream = fopen($file, $mode);
    }

    public function __destruct() {
        fclose($this->stream);
    }

}

class InputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDIN) {
        parent::__construct($file, self::READ);
    }

    private function update() {
        $content = stream_get_contents($this->stream);
        $buffer = explode(self::ENDL, $content);
        var_dump($buffer);
        foreach ($buffer as $k => $v) {
            $buffer[$k] = strtr($v, array("\n", "\r"), "");
            $buffer[$k] = explode(self::SPACE, $buffer[$k]);
        }
        $this->buffer = array_merge($this->buffer, $buffer);
    }

    public function read() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = array_shift($this->buffer[0]);
            if (count($this->buffer[0]) <= 0) {
                array_shift($this->buffer);
            }
        }
        return $buf;
    }

    public function readLine() {
        $this->update();
        if (count($this->buffer) <= 0) {
            $buf = NULL;
        } else {
            $buf = implode(self::SPACE, $this->buffer[0]);
            array_shift($this->buffer);
        }
        return $buf;
    }

}

class OutputStream extends Stream {

    private $buffer = array();

    public function __construct($file = self::STDOUT) {
        parent::__construct($file, self::WRITE);
    }

    public function flush() {
        var_dump($this->buffer);
        fwrite($this->stream, implode($this->buffer));
        $this->buffer = array();
    }

    public function write($var) {
        array_push($this->buffer, $var);
    }

    public function __destruct() {
        $this->flush();
        parent::__destruct();
    }

}

global $stdin, $stdout;

$stdin = new InputStream();
$stdout = new OutputStream();

/* Program Code */
$n = 0; $a = array(); $p = array();

$n = $stdin->read();
for ($i = 1; $i <= $n; $i++) {
    $p[$i] = $stdin->read();
    $stdout->write($p[$i] . " ");
    $a[$p[$i]] = $i;
}

for ($i = 1; $i <= $n; $i++) {
    $stdout->write($a[$i] . " ");
}
?>

<?php
////////////////TEST
while (fscanf(STDIN, "%d", $people_num)){
    $gifts = stream_get_line(STDIN, 65535, "\n");
    $person_gift = array();
    $person_gift = explode(' ', $gifts);

    $person_gift = array_flip($person_gift);
    echo $person_gift[0] . ' ' . $person_gift[1] . ' ' . $person_gift[2] . ' ' . $person_gift[3];
//    for ($i = 1; $i <= $people_num; $i++){
//        echo (int)($person_gift[$i] + 1) . ' ';
//        if ($i == $people_num){
//            echo "\n";
//        }
//    }
}

<?php
////////////////TEST
while (fscanf(STDIN, "%d", $people_num)){
    $gifts = stream_get_line(STDIN, 65535, "\n");
    $person_gift = array();
    $person_gift = explode(' ', $gifts);

    $person_gift = array_flip($person_gift);
    echo $person_gift[1] . ' ' . $person_gift[2] . ' ' . $person_gift[3] . ' ' . $person_gift[4];
//    for ($i = 1; $i <= $people_num; $i++){
//        echo (int)($person_gift[$i] + 1) . ' ';
//        if ($i == $people_num){
//            echo "\n";
//        }
//    }
}

<?php

while (fscanf(STDIN, "%d", $people_num)){
    $gifts = stream_get_line(STDIN, 65535, "\n");
    $person_gift = array();
    $person_gift = explode(' ', $gifts);

    $person_gift = array_flip($person_gift);
    for ($i = 1; $i <= $people_num; $i++){
        echo (int)($person_gift[$i] + 1) . ' ';
        if ($i == $people_num){
            echo "\n";
        }
    }
}

<?php

while (fscanf(STDIN, "%d", $people_num)){
    $gifts = stream_get_line(STDIN, 65535, "\n");
    $person_gift = array();
    $person_gift = explode(' ', $gifts);

    $person_gift = array_flip($person_gift);
    for ($i = 1; $i <= $people_num; $i++){
        echo $person_gift[$i] + 1 . ' ';
        if ($i == $people_num){
            echo "\n";
        }
    }
}

<?php
////////////////TEST
while (fscanf(STDIN, "%d", $people_num)){
    $gifts = stream_get_line(STDIN, 65535, "\n");
    $person_gift = array();
    $person_gift = explode(' ', $gifts);

    $person_gift = array_flip($person_gift);
    foreach ($person_gift as $key => $value){
        echo $key . '-' . $value . ';';
    }
//    for ($i = 1; $i <= $people_num; $i++){
//        echo (int)($person_gift[$i] + 1) . ' ';
//        if ($i == $people_num){
//            echo "\n";
//        }
//    }
}

<?php
//136A: Presents
$n = trim(fgets(STDIN));
$parray = explode(" ", trim(fgets(STDIN)));
$startatone = array();
foreach ($parray as $key => $value) {
    $startatone[$key+1] = $value;
}
$gaveto = array();
foreach ($startatone as $key => $value) {
    $gaveto[$value] = $key;
}
$implode = implode(" ", $gaveto);
echo $implode;
?>

<?php
error_reporting("off");
//136A: Presents
$n = trim(fgets(STDIN)); //$n = 4;
$parray = explode(" ", trim(fgets(STDIN))); //$parray = explode(" ", "2 3 4 1");
$startatone = array();
foreach ($parray as $key => $value) {
    $startatone[$key+1] = $value;
}
$gaveto = array();
foreach ($startatone as $key => $value) {
    $gaveto[$value] = $key;
}
ksort($gaveto);
print_r($gaveto);
$implode = implode(" ", $gaveto);
echo $implode;
?>

<?php
//136A: Presents
$n = trim(fgets(STDIN));
$parray = explode(" ", trim(fgets(STDIN)));
$gaveto = array();
foreach ($parray as $value) {
    $gaveto[$value] = $value;
}
$implode = implode(" ", $gaveto);
echo $implode;
?>

<?php
//136A: Presents
$n = trim(fgets(STDIN));
$parray = explode(" ", trim(fgets(STDIN)));
$gaveto = array();
foreach ($parray as $key => $value) {
    $gaveto[$value] = $key;
}
$implode = implode(" ", $gaveto);
echo $implode;
?>