Little C loves number «3» very much. He loves all things about it.Now he has a positive integer $$$n$$$. He wants to split $$$n$$$ into $$$3$$$ positive integers $$$a,b,c$$$, such that $$$a+b+c=n$$$ and none of the $$$3$$$ integers is a multiple of $$$3$$$. Help him to find a solution.

A single line containing one integer $$$n$$$ ($$$3 \leq n \leq 10^9$$$) — the integer Little C has.

Print $$$3$$$ positive integers $$$a,b,c$$$ in a single line, such that $$$a+b+c=n$$$ and none of them is a multiple of $$$3$$$. It can be proved that there is at least one solution. If there are multiple solutions, print any of them.

<?php

fscanf(STDIN, "%s\n", $number);
bcscale(0);

$number = bcsub($number, "2");

if ("0" === bcmod($number, "3")) {
    $second = 2;
    $third = bcsub($number, "1");
} else {
    $second = 1;
    $third = $number;
}

echo sprintf('1 %s %s', $second, $third);


Vasya is an administrator of a public page of organization "Mouse and keyboard" and his everyday duty is to publish news from the world of competitive programming. For each news he also creates a list of hashtags to make searching for a particular topic more comfortable. For the purpose of this problem we define hashtag as a string consisting of lowercase English letters and exactly one symbol '#' located at the beginning of the string. The length of the hashtag is defined as the number of symbols in it without the symbol '#'.The head administrator of the page told Vasya that hashtags should go in lexicographical order (take a look at the notes section for the definition).Vasya is lazy so he doesn't want to actually change the order of hashtags in already published news. Instead, he decided to delete some suffixes (consecutive characters at the end of the string) of some of the hashtags. He is allowed to delete any number of characters, even the whole string except for the symbol '#'. Vasya wants to pick such a way to delete suffixes that the total number of deleted symbols is minimum possible. If there are several optimal solutions, he is fine with any of them.

The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of hashtags being edited now. Each of the next n lines contains exactly one hashtag of positive length. It is guaranteed that the total length of all hashtags (i.e. the total length of the string except for characters '#') won't exceed 500 000.

Print the resulting hashtags in any of the optimal solutions.

NoteWord a1, a2, ..., am of length m is lexicographically not greater than word b1, b2, ..., bk of length k, if one of two conditions hold:   at first position i, such that ai ≠ bi, the character ai goes earlier in the alphabet than character bi, i.e. a has smaller character than b in the first position where they differ;  if there is no such position i and m ≤ k, i.e. the first word is a prefix of the second or two words are equal. The sequence of words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically not greater than the next word.For the words consisting of lowercase English letters the lexicographical order coincides with the alphabet word order in the dictionary.According to the above definition, if a hashtag consisting of one character '#' it is lexicographically not greater than any other valid hashtag. That's why in the third sample we can't keep first two hashtags unchanged and shorten the other two.


Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.

The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests. Next q lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20. The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone.

In the first line output the integer n — the number of users that changed their handles at least once. In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order. Each user who changes the handle must occur exactly once in this description.

5
Misha ILoveCodeforces
Vasya Petrov
Petrov VasyaPetrov123
ILoveCodeforces MikeMirzayanov
Petya Ivanov

3
Petya Ivanov
Misha MikeMirzayanov
Vasya VasyaPetrov123

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

<?php
function getInputString(){
    return trim(fgets(STDIN));
}

function writeOut($out){
    $out = $out."\n";
    fwrite(STDOUT,$out);
}

$reqCount = getInputString();
$reqs = array();
$result = array();
for($i = 0; $i<$reqCount;$i++){
    $reqs[] =getInputString();
}
foreach($reqs as $req){
    $req = explode(' ',$req);
    $old = array_search($req[0],$result,true);
    if(false===$old){
        $result[$req[0]] = $req[1];
    }
    else{
        $result[$old] = $req[1];
    }
}
$counResult = count($result);
writeOut($counResult);
foreach($result as $old=>$new){
    $out = $old.' '.$new;
    writeOut($out);
}
?>

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

$n = trim(fgets($fileIN));

$id = 0;

$users = array();
$newuser = array();
$olduser = array();

for ($i = 0; $i < $n; ++$i) {
	$line = explode(' ', trim(fgets($fileIN)));
	if (!isset($users[$line[0]])) {
		$users[$line[0]] = $id;
		$olduser[$id] = $line[0];
		$id++;
	}
	$tempid = $users[$line[0]];
	unset($users[$line[0]]);
	$users[$line[1]] = $tempid;
	$newuser[$tempid] = $line[1];
}

fprintf($fileOUT, $id . "\n");
for ($i = 0; $i < $id; ++$i) {
	fprintf($fileOUT, $olduser[$i] . " " . $newuser[$i] . "\n");
}

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

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

<?php
$a = trim(fgets(STDIN));
$b = array();
$c = array();
for($x = 1; $x <= $a; $x++)
{
    list($d, $e) = explode(" ", trim(fgets(STDIN)));
    array_push($b, $d);
    array_push($c, $e);
}
for($x = 0; $x < $a; $x++)
{
    $f = array_search($c[$x], $b);
    if($f == TRUE)
    {
        $b[$f] = $b[$x];
        unset($b[$x]);
        unset($c[$x]);
    }
}
$g = range(0, count($b) - 1);
$h = array_combine($g, $b);
$i = array_combine($g, $c);
print count($b) . "\n";
for($x = 0; $x < count($g) - 1; $x++)
{
    print $h[$x] . " " . $i[$x] . "\n";
}
print $h[$x] . " " . $i[$x];
?>

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

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

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

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

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

<?php
function getInputString(){
    return trim(fgets(STDIN));
}

function writeOut($out){
    $out = $out."\n";
    fwrite(STDOUT,$out);
}

$reqCount = getInputString();
$reqs = array();
$result = array();
for($i = 0; $i<$reqCount;$i++){
    $reqs[] =getInputString();
}
foreach($reqs as $req){
    $req = explode(' ',$req);
    $req[0] = strval($req[0]);
    $req[1] = strval($req[1]);
    $old = array_search($req[0],$result);
    if(false===$old){
        $result[$req[0]] = $req[1];
    }
    else{
        $result[$old] = $req[1];
    }
}
$counResult = count($result);
writeOut($counResult);
foreach($result as $old=>$new){
    $out = $old.' '.$new;
    writeOut($out);
}
?>

<?php
function getInputString(){
    return trim(fgets(STDIN));
}

function writeOut($out){
    $out = $out."\n";
    fwrite(STDOUT,$out);
}

$reqCount = getInputString();
$reqs = array();
$result = array();
for($i = 0; $i<$reqCount;$i++){
    $reqs[] =getInputString();
}
foreach($reqs as $req){
    $req = explode(' ',$req);
    $req[0] = strval($req[0]);
    $req[1] = strval($req[1]);
    $old = array_search($req[0],$result);
    if(!$old){
        $result[$req[0]] = $req[1];
    }
    else{
        $result[$old] = $req[1];
    }
}
$counResult = count($result);
writeOut($counResult);
foreach($result as $old=>$new){
    $out = $old.' '.$new;
    writeOut($out);
}
?>

<?php
function getInputString(){
    return trim(fgets(STDIN));
}

function writeOut($out){
    $out = $out."\n";
    fwrite(STDOUT,$out);
}

$reqCount = getInputString();
$reqs = array();
$result = array();
for($i = 0; $i<$reqCount;$i++){
    $reqs[] =getInputString();
}
foreach($reqs as $req){
    $req = explode(' ',$req);
    $req[0] = strval($req[0]);
    $req[1] = strval($req[1]);
    $old = array_search($req[0],$result);
    if(false!==$old){
        $result[$req[0]] = $req[1];
    }
    else{
        $result[$old] = $req[1];
    }
}
$counResult = count($result);
writeOut($counResult);
foreach($result as $old=>$new){
    $out = $old.' '.$new;
    writeOut($out);
}
?>

<?php
function getInputString(){
    return trim(fgets(STDIN));
}

function writeOut($out){
    $out = $out."\n";
    fwrite(STDOUT,$out);
}

$reqCount = getInputString();
$reqs = array();
$result = array();
for($i = 0; $i<$reqCount;$i++){
    $reqs[] =getInputString();
}
foreach($reqs as $req){
    $req = explode(' ',$req);
    $old = array_search($req[0],$result);
    if(false===$old){
        $result[$req[0]] = $req[1];
    }
    else{
        $result[$old] = $req[1];
    }
}
$counResult = count($result);
writeOut($counResult);
foreach($result as $old=>$new){
    $out = $old.' '.$new;
    writeOut($out);
}
?>

<?php
function getInputString(){
    return trim(fgets(STDIN));
}

function writeOut($out){
    $out = $out."\n";
    fwrite(STDOUT,$out);
}

$reqCount = getInputString();
$reqs = array();
$result = array();
for($i = 0; $i<$reqCount;$i++){
    $reqs[] =getInputString();
}
foreach($reqs as $req){
    $req = explode(' ',$req);
    $old = array_search($req[0],$result);
    if(!$old){
        $result[$req[0]] = $req[1];
    }
    else{
        $result[$old] = $req[1];
    }
}
$counResult = count($result);
writeOut($counResult);
foreach($result as $old=>$new){
    $out = $old.' '.$new;
    writeOut($out);
}
?>

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

$n = trim(fgets($fileIN));

$id = 0;

$users = array();
$newuser = array();
$olduser = array();

for ($i = 0; $i < $n; ++$i) {
	$line = explode(' ', trim(fgets($fileIN)));
	if (!isset($users[$line[0]])) {
		$users[$line[0]] = $id;
		$olduser[$id] = $line[0];
		$id++;
	}
	$tempid = $users[$line[0]];
	unset($users[$line[0]]);
	$users[$line[1]] = $tempid;
	$newuser[$tempid] = $line[1];
}

fprintf($fileOUT, $id . '\n');
for ($i = 0; $i < $id; ++$i) {
	fprintf($fileOUT, $olduser[$i] . ' ' . $newuser[$i] . '\n');
}

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

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

$n = trim(fgets($fileIN));

$id = 0;

$users = array();
$newuser = array();
$olduser = array();

for ($i = 0; $i < $n; ++$i) {
	$line = explode(' ', trim(fgets($fileIN)));
	if (!isset($users[$line[0]])) {
		$users[$line[0]] = $id;
		$olduser[$id] = $line[0];
		$id++;
	}
	$tempid = $users[$line[0]];
	unset($users[$line[0]]);
	$users[$line[1]] = $tempid;
	$newuser[$tempid] = $line[1];
}

fprintf($fileOUT, $id . '\n');
for ($i = 0; $i < $id; ++$i) {
	fprintf($fileOUT, $olduser[$i] . ' ' . $newuser[$i] . '\n');
}

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


Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order.Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≤ j ≤ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer.When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating.Your task is to calculate the total time it takes for Ayush to process all the orders.You can assume that the market has endless stock.

The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k. Each of the next n lines contains m distinct integers aij (1 ≤ aij ≤ k) — the order of the i-th person.

Print the only integer t — the total time needed for Ayush to process all the orders.

NoteCustomer 1 wants the items 1 and 5.pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5].pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2].Time taken for the first customer is 3 + 5 = 8.Customer 2 wants the items 3 and 1.pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2].pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2].Time taken for the second customer is 3 + 3 = 6.Total time is 8 + 6 = 14.Formally pos(x) is the index of x in the current row.

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


Black is gifted with a Divine array $$$a$$$ consisting of $$$n$$$ ($$$1 \le n \le 2000$$$) integers. Each position in $$$a$$$ has an initial value. After shouting a curse over the array, it becomes angry and starts an unstoppable transformation.The transformation consists of infinite steps. Array $$$a$$$ changes at the $$$i$$$-th step in the following way: for every position $$$j$$$, $$$a_j$$$ becomes equal to the number of occurrences of $$$a_j$$$ in $$$a$$$ before starting this step.Here is an example to help you understand the process better:  Initial array:$$$2$$$ $$$1$$$ $$$1$$$ $$$4$$$ $$$3$$$ $$$1$$$ $$$2$$$After the $$$1$$$-st step:$$$2$$$ $$$3$$$ $$$3$$$ $$$1$$$ $$$1$$$ $$$3$$$ $$$2$$$After the $$$2$$$-nd step:$$$2$$$ $$$3$$$ $$$3$$$ $$$2$$$ $$$2$$$ $$$3$$$ $$$2$$$After the $$$3$$$-rd step:$$$4$$$ $$$3$$$ $$$3$$$ $$$4$$$ $$$4$$$ $$$3$$$ $$$4$$$...... In the initial array, we had two $$$2$$$-s, three $$$1$$$-s, only one $$$4$$$ and only one $$$3$$$, so after the first step, each element became equal to the number of its occurrences in the initial array: all twos changed to $$$2$$$, all ones changed to $$$3$$$, four changed to $$$1$$$ and three changed to $$$1$$$.The transformation steps continue forever.You have to process $$$q$$$ queries: in each query, Black is curious to know the value of $$$a_x$$$ after the $$$k$$$-th step of transformation.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the size of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the initial values of array $$$a$$$. The third line of each test case contains a single integer $$$q$$$ ($$$1 \le q \le 100\,000$$$) — the number of queries. Next $$$q$$$ lines contain the information about queries — one query per line. The $$$i$$$-th line contains two integers $$$x_i$$$ and $$$k_i$$$ ($$$1 \le x_i \le n$$$; $$$0 \le k_i \le 10^9$$$), meaning that Black is asking for the value of $$$a_{x_i}$$$ after the $$$k_i$$$-th step of transformation. $$$k_i = 0$$$ means that Black is interested in values of the initial array. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2000$$$ and the sum of $$$q$$$ over all test cases doesn't exceed $$$100\,000$$$.

For each test case, print $$$q$$$ answers. The $$$i$$$-th of them should be the value of $$$a_{x_i}$$$ after the $$$k_i$$$-th step of transformation. It can be shown that the answer to each query is unique.

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

function solve($a, $n) {
  $f = 0;
	$d = 1;

	while ($f !== 1) {
	  $a[$d] = $a[$d - 1];
	  $b = array_count_values($a[$d]);
	  for ($i = 0; $i < $n; $i++) {
	    if ($b[$a[$d][$i]] !== $a[$d][$i]) {
	      $a[$d][$i] = $b[$a[$d][$i]];
	    }
	  }

	  $c = 0;
	  foreach ($b as $key => $val) {
	    if ($key == $val) {
	      $c++;
	    }
	  }

	  if ($c === count($b)) {
	    return $a;
	  }
	  $d++;
	}
}

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

for ($m = 0; $m < $t; $m++) {
	$n = trim(fgets($file));
	$s = explode(" ", trim(fgets($file)));
	$a = [];
	$a[0] = $s;

	$ans = solve($a, $n);

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

	for ($i = 0; $i < $q; $i++) {
	  list($x, $k) = explode(" ", trim(fgets($file)));
	  if ($k == 0) {
	    echo $a[0][$x - 1].PHP_EOL;
	  } else {
	    if ($k >= count($ans)) {
	      echo $ans[count($ans) - 1][$x - 1].PHP_EOL;
	    } else {
	      echo $ans[$k][$x - 1].PHP_EOL;
	    }
	  }

	}

}

?>

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
   $n = IO::str();
   $a = IO::arr();
   $q = IO::str();
   $res = [$a];
   for ($i = 0; $i < 2005; $i++) {
       $tmp = array_count_values($res[$i]);
       $nt = [];
       foreach ($res[$i] as $nv) {
           $nt[] = $tmp[$nv];
       }
       $res[$i+1] = $nt;
   }
   while ($q > 0) {
       $q--;
       list($x, $k) = IO::arr();
       if (isset($res[$k])) {
           IO::line($res[$k][$x - 1]);
       } else {
           IO::line($res[2004][$x - 1]);
       }
   }
}

?>

<?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;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }

    public static function res($res) {
        foreach ($res as $r) {
            echo $r . "\n";
        }
    }

    public static function dd($val){
        echo $val; exit;
    }
}

$t = IO::str();

function iter($arr, $ar) {
    $tmp = array();
    foreach ($arr as $i => $a) {
        $tmp[$i] = $ar[$a];
    }
    return $tmp;
}

function add($arr) {
    $ar = array();
    foreach ($arr as $a) {
        if (!isset($ar[$a])) {
            $ar[$a] = 1;
        } else {
            $ar[$a] += 1;
        }
    }
    return $ar;
}

while ($t--) {
    $n = IO::str();
    $arr = IO::arr();
    $ar = add($arr);
//    $arr = iter($arr, $ar);
//    $ar = add($arr);
//    $arr = iter($arr, $ar);
//    $ar = add($arr);
//    $arr = iter($arr, $ar);
//
//    var_dump($arr);
//    var_dump($ar);

    $tmp = array();
    $q = array();

    while ($arr != $tmp) {
        if (count($q) > 1 && $q[count($q)-1] == $arr) {
            break;
        }

        $q[] = $arr;

        $arr = iter($arr, $ar);
        $ar = add($arr);
    }

    $qs = IO::str();
//    foreach ($q as $aq) {
//        foreach ($aq as $qz) {
//            echo $qz . ' ';
//        }
//        echo PHP_EOL;
//    }
//    print_r($q[0][1]);
    while ($qs--) {
        list($a, $b) = IO::arr();
        if ($b >= count($q)) {
            $b = count($q) - 1;
        }
        echo $q[$b][$a-1] . PHP_EOL;
    }
}

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

function solve($a, $n) {
  $f = 0;
	$d = 1;
	$c = 0;

	while ($f !== 1) {
	  $b = array_count_values($a[$d - 1]);
	  for ($i = 0; $i < $n; $i++) {
	    $a[$d][$i] = $b[$a[$d - 1][$i]];
	  }

	  $c = 0;
	  foreach ($b as $key => $val) {
	    if ($key == $val) {
	      $c++;
	    }
	  }

	  if ($c === count($b)) {
	    return $a;
	  }
	  $d++;
	}
}

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

for ($m = 0; $m < $t; $m++) {
	$n = trim(fgets($file));
	$a[0] = explode(" ", trim(fgets($file)));

	$ans = solve($a, $n);

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

	for ($i = 0; $i < $q; $i++) {
	  list($x, $k) = explode(" ", trim(fgets($file)));
	  echo $ans[min($k, $n)][$x - 1].PHP_EOL;
	}

}

?>

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

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

function solveEnd($a, $n, $x, $k) {
  $f = 0;
	$d = 1;
	$c = 0;

	while ($f !== 1) {
	  $b = array_count_values($a);
	  for ($i = 0; $i < $n; $i++) {
	    if ($b[$a[$i]] !== $a[$i]) {
	      $a[$i] = $b[$a[$i]];
	    }
	  }

	  $c = 0;
	  foreach ($b as $key => $val) {
	    if ($key == $val) {
	      $c++;
	    }
	  }

	  if ($c === count($b)) {
	    $ans[0] = $a;
	    $ans[1] = $d;
	    return $ans;
	  }
	  $d++;
	}
}

function solve($a, $n, $x, $k) {
  $f = 0;
	$d = 1;
	$c = 0;

	while ($f !== 1) {
	  $b = array_count_values($a);
	  for ($i = 0; $i < $n; $i++) {
	    if ($b[$a[$i]] !== $a[$i]) {
	      $a[$i] = $b[$a[$i]];
	    }
	  }

	  if ($d == $k) return $a;
	  $d++;

	  $c = 0;
	  foreach ($b as $key => $val) {
	    if ($key == $val) {
	      $c++;
	    }
	  }

	  if ($c === count($b)) return $a;
	}
	return $a;
}

for ($m = 0; $m < $t; $m++) {
	$n = trim(fgets($file));
	$a = explode(" ", trim(fgets($file)));
	$q = trim(fgets($file));
	$ans = solveEnd($a, $n, $x, $k);

	for ($i = 0; $i < $q; $i++) {
	  list($x, $k) = explode(" ", trim(fgets($file)));

	  if ($k == 0) {
	    echo $a[$x - 1].PHP_EOL;
	  } else {
	    if ($ans[1] < $k) {
	      echo $ans[0][$x - 1].PHP_EOL;
	    } else {
	      $ans = solve($a, $n, $x, $k);
	      echo $ans[$x - 1].PHP_EOL;
	    }
	  }
	}
}

?>

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

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

function solveEnd($a, $n, $x, $k) {
  $f = 0;
	$d = 1;
	$c = 0;

	while ($f !== 1) {
	  $b = array_count_values($a);
	  for ($i = 0; $i < $n; $i++) {
	    if ($b[$a[$i]] !== $a[$i]) {
	      $a[$i] = $b[$a[$i]];
	    }
	  }

	  $c = 0;
	  foreach ($b as $key => $val) {
	    if ($key == $val) {
	      $c++;
	    }
	  }

	  if ($c === count($b)) {
	    $ans[0] = $a;
	    $ans[1] = $d;
	    return $ans;
	  }
	  $d++;
	}
}

function solve($a, $n, $x, $k) {
  $f = 0;
	$d = 1;
	$c = 0;

	while ($f !== 1) {
	  $b = array_count_values($a);
	  for ($i = 0; $i < $n; $i++) {
	    if ($b[$a[$i]] !== $a[$i]) {
	      $a[$i] = $b[$a[$i]];
	    }
	  }

	  if ($d == $k) return $a;
	  $d++;

	  $c = 0;
	  foreach ($b as $key => $val) {
	    if ($key == $val) {
	      $c++;
	    }
	  }

	  if ($c === count($b)) return $a;
	}
	return $a;
}

for ($m = 0; $m < $t; $m++) {
	$n = trim(fgets($file));
	$a = explode(" ", trim(fgets($file)));
	$q = trim(fgets($file));
	$ans = solveEnd($a, $n, $x, $k);

	for ($i = 0; $i < $q; $i++) {
	  list($x, $k) = explode(" ", trim(fgets($file)));

	  if ($k == 0) {
	    echo $a[$x - 1].PHP_EOL;
	  } else {
	    if ($ans[1] <= $k) {
	      echo $ans[0][$x - 1].PHP_EOL;
	    } else {
	      $ans = solve($a, $n, $x, $k);
	      echo $ans[$x - 1].PHP_EOL;
	    }
	  }
	}
}

?>

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

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

function solve($a, $n, $x, $k) {
  $f = 0;
	$d = 1;
	$c = 0;

	while ($f !== 1) {
	  $b = array_count_values($a);
	  for ($i = 0; $i < $n; $i++) {
	    if ($b[$a[$i]] !== $a[$i]) {
	      $a[$i] = $b[$a[$i]];
	    } else {
	      $c++;
	    }
	  }
	  if ($d == $k) return $a[$x - 1];
	  $d++;
	  if ($c >= $n) return $a[$x - 1];
	}
}

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

	for ($i = 0; $i < $q; $i++) {
	  list($x, $k) = explode(" ", trim(fgets($file)));

	  if ($k == 0) {
	    echo $a[$x - 1].PHP_EOL;
	  } else {
	    $ans = solve($a, $n, $x, $k);
	    echo $ans.PHP_EOL;
	  }

	}
}

?>

<?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;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }

    public static function res($res) {
        foreach ($res as $r) {
            echo $r . "\n";
        }
    }

    public static function dd($val){
        echo $val; exit;
    }
}

$t = IO::str();

function iter($arr, $ar) {
    $tmp = array();
    foreach ($arr as $i => $a) {
        $tmp[$i] = $ar[$a];
    }
    return $tmp;
}

function add($arr) {
    $ar = array();
    foreach ($arr as $a) {
        if (!isset($ar[$a])) {
            $ar[$a] = 1;
        } else {
            $ar[$a] += 1;
        }
    }
    return $ar;
}

while ($t--) {
    $n = IO::str();
    $arr = IO::arr();
    $ar = add($arr);
//    $arr = iter($arr, $ar);
//    $ar = add($arr);
//    $arr = iter($arr, $ar);
//    $ar = add($arr);
//    $arr = iter($arr, $ar);
//
//    var_dump($arr);
//    var_dump($ar);

    $tmp = array();
    $q = array();

    while ($arr != $tmp) {
        if (count($q) > 1 && $q[count($q)-1] == $arr) {
            break;
        }

        $q[] = $arr;

        $arr = iter($arr, $ar);
        $ar = add($arr);
    }

    $qs = IO::str();
//    foreach ($q as $aq) {
//        foreach ($aq as $qz) {
//            echo $qz . ' ';
//        }
//        echo PHP_EOL;
//    }
    while ($qs--) {
        list($a, $b) = IO::arr();
        if ($b > count($q)) {
            $b = count($q) - 1;
        }
        echo $q[$b][$a-1] . PHP_EOL;
    }
}


In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.The trajectory of a camel's spit is an arc, i.e. if the camel in position x spits d meters right, he can hit only the camel in position x + d, if such a camel exists.

The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of di correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position.

If there are two camels, which spitted at each other, output YES. Otherwise, output NO.

<?php

  $f = fopen('php://stdin','r');
  $n = intval(fgets($f));
  for($i=1;$i<=$n;$i++){
    $row = fgets($f);
    if(preg_match('/([0-9\-]+)\s+([0-9\-]+)/',$row,$pregs)){
      $x[$pregs[1]] = $pregs[2];
    }
  }
  fclose($f);

  foreach($x as $key=>$val){
    if(isset($x[$key+$val]) && isset($x[$key+$val+$x[$key+$val]]) && $x[$key+$val] == -$val){
      echo "YES";
      die();
    }
  }
  echo "NO";

?>


Two T-shirt sizes are given: $$$a$$$ and $$$b$$$. The T-shirt size is either a string M or a string consisting of several (possibly zero) characters X and one of the characters S or L.For example, strings M, XXL, S, XXXXXXXS could be the size of some T-shirts. And the strings XM, LL, SX are not sizes.The letter M stands for medium, S for small, L for large. The letter X refers to the degree of size (from eXtra). For example, XXL is extra-extra-large (bigger than XL, and smaller than XXXL).You need to compare two given sizes of T-shirts $$$a$$$ and $$$b$$$.The T-shirts are compared as follows:   any small size (no matter how many letters X) is smaller than the medium size and any large size;  any large size (regardless of the number of letters X) is larger than the medium size and any small size;  the more letters X before S, the smaller the size;  the more letters X in front of L, the larger the size. For example:   XXXS < XS  XXXL > XL  XL > M  XXL = XXL  XXXXXS < M  XL > XXXS

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line, in which $$$a$$$ and $$$b$$$ T-shirt sizes are written. The lengths of the strings corresponding to the T-shirt sizes do not exceed $$$50$$$. It is guaranteed that all sizes are correct.

For each test case, print on a separate line the result of comparing $$$a$$$ and $$$b$$$ T-shirt sizes (lines "<", ">" or "=" without quotes).

6

XXXS XS

XXXL XL

XL M

XXL XXL

XXXXXS M

L M

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   list($a, $b) = IO::getArray();
   $l = $r = 0;
    $ans = '=';//< >
    if(strlen($a) ==1) {
       if($a == 'M') {
          $l = 5;
         } elseif($a == 'S') {
              $l = 0;
         } else {
              $l = 10;
         }

    } else {
        $l = (strlen($a));
        if($a[strlen($a)-1] == 'S') {
             $l *=-10;
        } else {
            $l *= 10;
        }
    }
    if(strlen($b) == 1) {
       if($b == 'M') {
          $r = 5;
         } elseif($b == 'S') {
              $r = 0;
         } else {
              $r = 10;
         }
    } else {
        $r = (strlen($b));
        if($b[strlen($b)-1] == 'S') {
             $r *=-10;
        } else {
             $r *= 10;
        }
    }
    if($l > $r) {
         $ans = '>';
    } elseif($l< $r) {
         $ans = '<';
    } else {
         $ans = '=';
    }
    IO::pr($ans);
}

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

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

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$s = explode(' ', trim(fgets(STDIN)));
//function decr($v){return --$v;}
//$alpha='abcdefghijklmnopqrstuvwxyz';
//$mod=1000000009;
//$mod=1000000007;
//$mod=998244353;
//$a=[];
//$b=[];
//for($i=0;$i<$n;$i++){
//    [$a[],$b[]] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//}
$ans = [];
for($i=0;$i<$n;$i++){
    [$a,$b] = explode(' ', trim(fgets(STDIN)));
    $lena = strlen($a);
    $lenb = strlen($b);
    if($a[$lena-1]=="S"){
        if($b[$lenb-1]=="S"){
            if($lena > $lenb) $ans[] = "<";
            else if($lena < $lenb) $ans[] = ">";
            else $ans[] = "=";
        }else{
            $ans[] = "<";
        }
    }else if($a[$lena-1]=="M"){
        if($b[$lenb-1]=="S"){
            $ans[] = ">";
        }else if($b[$lenb-1]=="M"){
            $ans[] = "=";
        }else{
            $ans[] = "<";
        }
    }else{
        if($b[$lenb-1]=="L"){
            if($lena > $lenb) $ans[] = ">";
            else if($lena < $lenb) $ans[] = "<";
            else $ans[] = "=";
        }else{
            $ans[] = ">";
        }
    }
}
echo implode(PHP_EOL,$ans);

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   list($a, $b) = IO::getArray();
   $l = $r = 0;
    $ans = '=';//< >
    if(strlen($a) ==1) {
       if($a == 'M') {
          $l = 5;
         } elseif($a == 'S') {
              $l = 0;
         } else {
              $l = 10;
         }

    } else {
        $l = (strlen($a)-1)*10;
        if($a[strlen($a)-1] == 'S') {
             $l *=-1;
        }
    }
    if(strlen($b) == 1) {
       if($b == 'M') {
          $r = 5;
         } elseif($b == 'S') {
              $r = 0;
         } else {
              $r = 10;
         }
    } else {
        $r = (strlen($b)-1)*10;
        if($b[strlen($b)-1] == 'S') {
             $r *=-1;
        }
    }
    if($l > $r) {
         $ans = '>';
    } elseif($l< $r) {
         $ans = '<';
    } else {
         $ans = '=';
    }
    IO::pr($ans);
}

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

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


You have an array $$$a_1, a_2, \dots, a_n$$$. All $$$a_i$$$ are positive integers.In one step you can choose three distinct indices $$$i$$$, $$$j$$$, and $$$k$$$ ($$$i \neq j$$$; $$$i \neq k$$$; $$$j \neq k$$$) and assign the sum of $$$a_j$$$ and $$$a_k$$$ to $$$a_i$$$, i. e. make $$$a_i = a_j + a_k$$$.Can you make all $$$a_i$$$ lower or equal to $$$d$$$ using the operation above any number of times (possibly, zero)?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$d$$$ ($$$3 \le n \le 100$$$; $$$1 \le d \le 100$$$) — the number of elements in the array $$$a$$$ and the value $$$d$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$) — the array $$$a$$$.

For each test case, print YES, if it's possible to make all elements $$$a_i$$$ less or equal than $$$d$$$ using the operation above. Otherwise, print NO. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).

NoteIn the first test case, we can prove that we can't make all $$$a_i \le 3$$$.In the second test case, all $$$a_i$$$ are already less or equal than $$$d = 4$$$.In the third test case, we can, for example, choose $$$i = 5$$$, $$$j = 1$$$, $$$k = 2$$$ and make $$$a_5 = a_1 + a_2 = 2 + 1 = 3$$$. Array $$$a$$$ will become $$$[2, 1, 5, 3, 3]$$$.After that we can make $$$a_3 = a_5 + a_2 = 3 + 1 = 4$$$. Array will become $$$[2, 1, 4, 3, 3]$$$ and all elements are less or equal than $$$d = 4$$$.

<?php

/**
 * Соревнование http://codeforces.com/contest/1473
 */

$file = fopen("php://stdin", "r");
// $file = fopen("./input.txt", "r");

$rowsNumber = fgets($file);

for($i=0; $i<$rowsNumber; $i++) {
    list($n, $d) = explode(" ", trim(fgets($file)));

    $array = explode(" ", trim(fgets($file)));

    sort($array);

    if ($array[$n-1] <= $d) {
        echo "YES".PHP_EOL;

        continue;
    }

    if ((trim($array[0]) + trim($array[1])) <= trim($d)) {
        echo "YES".PHP_EOL;

        continue;
    }

    echo "NO".PHP_EOL;
}

<?php

$t = trim(fgets(STDIN));

for ($i=0; $i<$t; $i++) {
    list($count, $r) = explode(' ', trim(fgets(STDIN)));
    $array = explode(' ', trim(fgets(STDIN)));
    sort($array);

    if ($array[$count -1] <= $r || $array[0] + $array[1] <= $r) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }

}

<?php

$t = trim(fgets(STDIN));

for ($i=0; $i<$t; $i++) {
    list($count, $d) = explode(' ', trim(fgets(STDIN)));
    $array = explode(' ', trim(fgets(STDIN)));
    sort($array);

    if ($array[$count -1] <= $d || $array[0] + $array[1] <= $d) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }

}

<?php

$t = trim(fgets(STDIN));

for ($i=0; $i<$t; $i++) {
    list($count, $d) = explode(' ', trim(fgets(STDIN)));
    $array = explode(' ', trim(fgets(STDIN)));
    $aMin = [];
    $aMax = [];
    foreach ($array as $s) {
        if ($s <= $d) {
            $aMin[] = $s;
        } else {
            $aMax[] = $s;
        }
    }

    if (count($aMax) <= 0) {
        echo 'YES' . PHP_EOL;
    } else {
        if (count($aMin) > 1) {
            sort($aMin);
            if ($aMin[0] + $aMin[1] <= $d){
                echo 'YES' . PHP_EOL;
            }  else {
                echo 'NO' . PHP_EOL;
            }
        } else {
            echo 'NO' . PHP_EOL;
        }
    }

}

<?php
/**
 * Author       : Mina Sameh Wadie

 * Date         : 2021-01-21

 * Requirements : PHP V7+

 * *Description*  : Code Forces Problem https://codeforces.com/problemset/problem/1473/A

 *
 * The problem is replacing elements, the idea is you have elements in an array, and an inputed 'd',

 * if all elements can be less than or equal 'd' using a[i] = a[j] + a[k] where

 * i,j,k are different indices, then output Yes

 *
 * @inputs       : First input t number of test cases where (1<=t<=2000), newline

 * 		  Second input n (3<=n<=100), third input is 'd' (1<=d<=100)

 *
 */
class prob
{

	/**
	 * Takes input form user.
	 * @return array of inputs *See #inputs
	 */
	public function take_input() {

		$n = fgets(STDIN);
		$d = substr($n, strpos($n, ' '), -1);
		$n = substr($n, 0,strpos($n, ' '));

		return [ "n" => $n, "d" => $d ];

	}

	public function less_equal($data, $val) : bool {
		if( $data >= $val ) { return true; }
		return false;
	}

	/**
	 * die and dump, used for debugging.
	 * @parm data that will be dumped.
	 * @return void
	 */
	public function dd($data) {
		die(var_dump($data));
	}

	/**
	 * gets Array that will be used
	 * @parm amount of elements
	 * @return arr of elements
	 */
	public function getArr( $n ) {
		return array_map('intval', explode(' ', fgets(STDIN) ) );

	}

	/**
	 * Main Logic of doing the operations.
	 * @parm the array, and d.
	 * @return String YES or NO
	 */
	public function ReplaceElements( $arr, $d ) : string {
		// get the needed value
		$NeededVal = (int) $d;
		// Sort the arr
		sort($arr);
		$Counter = 1;

		// First Check if there is something to be done, by comparing the largest element to d.
		if( $this->less_equal($NeededVal,$arr[count($arr)-1])) { return "YES\n"; }

		// If not then, set j and k to first elements, which are the lowest ones.
		$arr[count($arr)-1] = $arr[0] + $arr[1];
		//Reset the counter
		$Counter = 0;
		// Then check again, if yes then that means all can be smaller | equal to d.
		if( $this->less_equal($NeededVal,$arr[count($arr)-1])) { return "YES\n"; }
		return "NO\n";
	}

	/**
	 * Constructor, used as main.
	 */
	public function Run(){
		// get T
		$t  = (int)fgets(STDIN);
		do {
			// take the required input
			$inputs = $this->take_input();
			// get Arr
			echo $this->ReplaceElements(  $this->getArr( $inputs["n"] ) , $inputs["d"] );
			$t--;
		} while( $t > 0 );

	}
}

$obj = new prob();
$obj->Run();

<?php
     $ft =  trim(fgets(STDIN));
     for($irt = 0; $irt < $ft; $irt++){
         $a = explode(" ", trim(fgets(STDIN)));
         $b = explode(" ", trim(fgets(STDIN)));

         sort($b);
         $s = 0;
         $bool = false;
         for($u = 0; $u < $a[0]; $u++) {
             if($u < 2) {
                 $s += $b[$u];
             }
             if($b[$u] > $a[1]){
                 $bool = true;
             }
         }
         if($s <= $a[1] || !$bool){
             echo "YES\n";
         } else {
             echo "NO\n";
         }
     }

?>

<?php
    $t = trim(fgets(STDIN));
    for ($i = 0; $i < $t; $i++) {
        list($n, $d) = explode(" ", trim(fgets(STDIN)));
        $a = explode(" ", trim(fgets(STDIN)));
        if (max($a) <= $d) {
            echo 'YES'."\n";
        } else {
            $m = min($a);
            if ($m > $d) {
                echo 'NO' ."\n";
            } else {
                foreach ($a as $k => $v) {
                    if ($v == $m) {
                        unset($a[$k]);
                        break;
                    }
                }
                if (min($a) + $m <= $d) {
                    echo 'YES'."\n";
                } else {
                    echo 'NO' ."\n";
                }
            }
        }
    }

?>

<?php
$t = readline();
while($t!=0){
    $case = explode(' ',readline());

    $arr = explode(' ',readline());

    sort($arr);
    if ($arr[0]+$arr[1]<=$case[1]||$arr[$case[0]-1]<=$case[1]){
        echo "YES\n";
    }
    else {
        echo "NO\n";
    }
    $t--;
}
?>

<?php

$t = (int) trim(fgets(STDIN));
for ($i = 0; $i < $t; ++$i) {
    list($n[], $d[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a[$i] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($i = 0; $i < $t; ++$i) {
    $di = $d[$i];
    $ai = $a[$i];
    sort($ai);
    echo (($ai[0] + $ai[1] <= $di || max($ai) <= $di) ? 'YES' : 'NO'), PHP_EOL;
}

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

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

  $r = 0; $l = 0;
  $c = count($a);
  for ($j = 0; $j < $c; $j++) {
    if ($a[$j] > $d) {
      $a[$j] = $a[$c - 1] + $a[$c - 2];
      if ($a[$j] > $d) { $l = 1; echo 'NO'.PHP_EOL; break;}
    } else {
      $r++;
    }
  }
  if ($l != 1) { echo 'YES'.PHP_EOL; }
}

?>

<?php
function checkArr($arr, $d)
{
	foreach($arr as $key => $value)
	{
		if($value > $d)
			return false;
	}
	return true;
}

$t = (int)fgets(STDIN);
for($i=0;$i<$t;$i++)
{
	$str = fgets(STDIN);
	$arr = explode(" ", $str);
	$n = (int)$arr[0];
	$d = (int)$arr[1];
	$a_str = fgets(STDIN);
	$a = explode(" ", trim($a_str));
	if(checkArr($a, $d))
		print("YES\r\n");
	else
	{
		if(sizeof($a) == 1)
			print("NO\r\n");
		else
		{
			sort($a, SORT_NUMERIC);
			if($a[0] + $a[1] <= $d)
				print("YES\r\n");
			else
				print("NO\r\n");
		}
	}
}

$end = readline();
?>

<?php

/**
 * Соревнование http://codeforces.com/contest/1473
 */

$file = fopen("php://stdin", "r");
// $file = fopen("./input.txt", "r");

$rowsNumber = fgets($file);

for($i=0; $i<$rowsNumber; $i++) {
    list($n, $d) = explode(" ", fgets($file));

    $array = explode(" ", trim(fgets($file)));

    sort($array);

    if ($array[$n-1] <= $d) {
        echo "YES".PHP_EOL;

        continue;
    }

    if ((trim($array[0]) + trim($array[1])) <= trim($d)) {
        echo "YES".PHP_EOL;

        continue;
    }

    echo "NO".PHP_EOL;
}

<?php

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

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

for($i=0; $i<$rowsNumber; $i++) {
    list($n, $d) = explode(" ", trim(fgets($file)));

    $array = explode(" ", trim(fgets($file)));

    sort($array);

    if (($array[0] + $array[1]) <= $d) {
        echo "YES".PHP_EOL;

        continue;
    }

    echo "NO".PHP_EOL;
}

<?php

/**
 * Соревнование http://codeforces.com/contest/1473
 */

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

$rowsNumber = fgets($file);

function hasMoreThen($array, $n, $d) {
    for ($i=0; $i<$n; $i++) {
        if (trim($array[$i]) > trim($d)) {
            return true;
        }
    }

    return false;
}

for($i=0; $i<$rowsNumber; $i++) {
    list($n, $d) = explode(" ", fgets($file));

    $array = explode(" ", fgets($file));

    if (! hasMoreThen($array, $n, $d)) {
        echo "YES".PHP_EOL;

        continue;
    }

    sort($array);

    if ((trim($array[0]) + trim($array[1])) <= trim($d)) {
        echo "YES".PHP_EOL;

        continue;
    }

    echo "NO".PHP_EOL;
}

<?php

/**
 * Соревнование http://codeforces.com/contest/1473
 */

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

$rowsNumber = fgets($file);

function hasMoreThen($array, $n, $d) {
    for ($i=0; $i<$n; $i++) {
        if (trim($array[$i]) > trim($d)) {
            return true;
        }
    }

    return false;
}

for($i=0; $i<$rowsNumber; $i++) {
    list($n, $d) = explode(" ", fgets($file));

    $array = explode(" ", fgets($file));

    if (! hasMoreThen($array, $n, $d)) {
        echo "YES".PHP_EOL;

        continue;
    }

    sort($array);
        var_dump($array);
    if ((trim($array[0]) + trim($array[1])) <= trim($d)) {
        echo "YES".PHP_EOL;

        continue;
    }

    echo "NO".PHP_EOL;
}

<?php

/**
 * Соревнование http://codeforces.com/contest/1473
 */

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

$rowsNumber = fgets($file);

function hasMoreThen($array, $n, $d) {
    for ($i=0; $i<$n; $i++) {
        if ($array[$i] > $d) {
            return true;
        }
    }

    return false;
}

for($i=0; $i<$rowsNumber; $i++) {
    list($n, $d) = explode(" ", fgets($file));

    $array = explode(" ", fgets($file));

    if (! hasMoreThen($array, $n, $d)) {
        echo "YES".PHP_EOL;

        continue;
    }

    sort($array);

    if (($array[0] + $array[1]) <= $d) {
        echo "YES".PHP_EOL;

        continue;
    }

    echo "NO".PHP_EOL;
}

<?php

/**
 * Соревнование http://codeforces.com/contest/1473
 */

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

$rowsNumber = fgets($file);

function hasMoreThen($array, $n, $d) {
    for ($i=0; $i<$n; $i++) {
        if ($array[$i] > $d) {
            return true;
        }
    }

    return false;
}

for($i=0; $i<$rowsNumber; $i++) {
    list($n, $d) = explode(" ", fgets($file));

    $array = explode(" ", fgets($file));

    if (! hasMoreThen($array, $n, $d)) {
        echo "YES".PHP_EOL;

        continue;
    }

    sort($array);

    if (($array[0] + $array[1]) < $d) {
        echo "YES".PHP_EOL;

        continue;
    }

    echo "NO".PHP_EOL;
}

<?php

$t = trim(fgets(STDIN));

for ($i=0; $i<$t; $i++) {
    list($count, $d) = explode(' ', trim(fgets(STDIN)));
    $array = explode(' ', trim(fgets(STDIN)));
    $aMin = [];
    $aMax = [];
    foreach ($array as $s) {
        if ($s <= $d) {
            $aMin[$s] = $s;
        } else {
            $aMax[$s] = $s;
        }
    }

    if (count($aMax) <= 0) {
        echo 'YES' . PHP_EOL;
    } else {
        if (count($aMin) > 1) {
            sort($aMin);
            if ($aMin[0] + $aMin[1] <= $d){
                echo 'YES' . PHP_EOL;
            }  else {
                echo 'NO' . PHP_EOL;
            }
        } else {
            echo 'NO' . PHP_EOL;
        }
    }

}

<?php

$t = trim(fgets(STDIN));

for ($i=0; $i<$t; $i++) {
    list($count, $d) = explode(' ', trim(fgets(STDIN)));
    $array = explode(' ', trim(fgets(STDIN)));

    foreach ($array as $s) {
        if ($s <= $d) {
            $aMin[$s] = $s;
        } else {
            $aMax[$s] = $s;
        }
    }

    if (count($aMax) <= 0) {
        echo 'YES' . PHP_EOL;
    } else {
        if (count($aMin) > 1) {
            sort($aMin);
            if ($aMin[0] + $aMin[1] <= $d){
                echo 'YES' . PHP_EOL;
            }  else {
                echo 'NO' . PHP_EOL;
            }
        } else {
            echo 'NO' . PHP_EOL;
        }
    }

}

<?php
/**
 * Author       : Mina Sameh Wadie

 * Date         : 2021-01-21

 * Requirements : PHP V7+

 * *Description*  : Code Forces Problem https://codeforces.com/problemset/problem/1473/A

 *
 * The problem is replacing elements, the idea is you have elements in an array, and an inputed 'd',

 * if all elements can be less than or equal 'd' using a[i] = a[j] + a[k] where

 * i,j,k are different indices, then output Yes

 *
 * @inputs       : First input t number of test cases where (1<=t<=2000), newline

 * 		  Second input n (3<=n<=100), third input is 'd' (1<=d<=100)

 *
 */
class prob
{

	/**
	 * Takes input form user.
	 * @return array of inputs *See #inputs
	 */
	public function take_input() {

		$n = fgets(STDIN);
		$d = substr($n, strpos($n, ' '), -1);
		$n = substr($n, 0,strpos($n, ' '));

		return [ "n" => $n, "d" => $d ];

	}

	public function less_equal($data, $val) : bool {
		if( $data >= $val ) { return true; }
		return false;
	}

	/**
	 * die and dump, used for debugging.
	 * @parm data that will be dumped.
	 * @return void
	 */
	public function dd($data) {
		die(var_dump($data));
	}

	/**
	 * gets Array that will be used
	 * @parm amount of elements
	 * @return arr of elements
	 */
	public function getArr( $n ) {
		return array_map('intval', explode(' ', fgets(STDIN) ) );

	}

	/**
	 * Main Logic of doing the operations.
	 * @parm the array, and d.
	 * @return String YES or NO
	 */
	public function ReplaceElements( $arr, $d ) : string {
		// get the needed value
		$NeededVal = ( $d < sizeof($arr) ? $arr[(int)$d] : $d );
		$Counter = 1;

		// First Check if there is something to be done.
		foreach( $arr as $val ) {
			if( $this->less_equal($NeededVal,$val) || $this->less_equal($NeededVal,$val ))
		       	{ $Counter++; }
		}

		if( $Counter == sizeof($arr) ) { return "YES"; }
		// First, get I, J and K.
		$i = 0; $j = 1; $k = 2;
		// Reset the counter
		$Counter = 0;
		for( $i=0; $i<sizeof($arr); ( $i != $k && $i != $j ) ? $i++ : $i+=2  ) {
			for( $j=1; $j<sizeof($arr); ( $j != $i && $j != $k ) ? $j++ : $j+=2  ) {
					if( $this->less_equal($NeededVal, $arr[$i] ) ){
						continue;
					}
				for( $k=2; $k<sizeof($arr); ( $k != $i && $k != $j ) ? $k++ : $k+=2  ) {
					if( $this->less_equal($NeededVal, ($arr[$j] + $arr[$k] ) ) ) {
						$arr[$i] = $arr[$j] + $arr[$k];
						echo "| NeededVal:";
						echo $NeededVal;
						echo " ,Arr[i]:";
						echo $arr[$i];
						}
					}
			}
		}
		foreach( $arr as $val ) {
			if( $this->less_equal($NeededVal,$val) || $this->less_equal($NeededVal,$val ))
		       	{ $Counter++; }
		}

		if( $Counter == sizeof($arr) ) { return "YES\n"; }
		return "NO\n";
	}

	/**
	 * Constructor, used as main.
	 */
	public function Run(){
		// get T
		$t  = (int)fgets(STDIN);
		do {
			// take the required input
			$inputs = $this->take_input();
			// get Arr
			echo $this->ReplaceElements( $this->getArr( $inputs["n"] ), $inputs["d"] );
			$t--;
		} while( $t > 0 );

	}
}

$obj = new prob();
$obj->Run();

<?php
/**
 * Author       : Mina Sameh Wadie

 * Date         : 2021-01-21

 * Requirements : PHP V7+

 * *Description*  : Code Forces Problem https://codeforces.com/problemset/problem/1473/A

 *
 * The problem is replacing elements, the idea is you have elements in an array, and an inputed 'd',

 * if all elements can be less than or equal 'd' using a[i] = a[j] + a[k] where

 * i,j,k are different indices, then output Yes

 *
 * @inputs       : First input t number of test cases where (1<=t<=2000), newline

 * 		  Second input n (3<=n<=100), third input is 'd' (1<=d<=100)

 *
 */
class prob
{

	/**
	 * Takes input form user.
	 * @return array of inputs *See #inputs
	 */
	public function take_input() {

		$n = fgets(STDIN);
		$d = substr($n, strpos($n, ' '), -1);
		$n = substr($n, 0,strpos($n, ' '));

		return [ "n" => $n, "d" => $d ];

	}

	public function less_equal($data, $val) : bool {
		if( $data >= $val ) { return true; }
		return false;
	}

	/**
	 * die and dump, used for debugging.
	 * @parm data that will be dumped.
	 * @return void
	 */
	public function dd($data) {
		die(var_dump($data));
	}

	/**
	 * gets Array that will be used
	 * @parm amount of elements
	 * @return arr of elements
	 */
	public function getArr( $n ) {
		return array_map('intval', explode(' ', fgets(STDIN) ) );

	}

	/**
	 * Main Logic of doing the operations.
	 * @parm the array, and d.
	 * @return String YES or NO
	 */
	public function ReplaceElements( $arr, $d ) : string {
		// get the needed value
		$NeededVal = ( $d < sizeof($arr) ? $arr[(int)$d] : $d );
		$Counter = 1;

		// First Check if there is something to be done.
		foreach( $arr as $val ) {
			if( $this->less_equal($NeededVal,$val) || $this->less_equal($NeededVal,$val ))
		       	{ $Counter++; }
		}

		if( $Counter == sizeof($arr) ) { return "YES"; }
		// First, get I, J and K.
		$i = 0; $j = 1; $k = 2;
		// Reset the counter
		$Counter = 0;
		for( $i=0; $i<sizeof($arr); ( $i != $k && $i != $j ) ? $i++ : $i+=2  ) {
			for( $j=1; $j<sizeof($arr); ( $j != $i && $j != $k ) ? $j++ : $j+=2  ) {
					if( $this->less_equal($NeededVal, $arr[$i] ) ){
						continue;
					}
				for( $k=2; $k<sizeof($arr); ( $k != $i && $k != $j ) ? $k++ : $k+=2  ) {
					if( $this->less_equal($NeededVal, ($arr[$j] + $arr[$k] ) ) ) {
						$arr[$i] = $arr[$j] + $arr[$k];
						echo "| NeededVal:";
						echo $NeededVal;
						echo " ,Arr[i]:";
						echo $arr[$i];
						}
					}
			}
		}
		foreach( $arr as $val ) {
			if( $this->less_equal($NeededVal,$val) || $this->less_equal($NeededVal,$val ))
		       	{ $Counter++; }
		}

		if( $Counter == sizeof($arr) ) { return "YES"; }
		return "NO";
	}

	/**
	 * Constructor, used as main.
	 */
	public function Run(){
		// get T
		$t  = (int)fgets(STDIN);
		do {
			// take the required input
			$inputs = $this->take_input();
			// get Arr
			echo $this->ReplaceElements( $this->getArr( $inputs["n"] ), $inputs["d"] );
			$t--;
		} while( $t > 0 );

	}
}

$obj = new prob();
$obj->Run();

<?php
     $ft =  trim(fgets(STDIN));
     for($irt = 0; $irt < $ft; $irt++){
         $a = explode(" ", trim(fgets(STDIN)));
         $b = explode(" ", trim(fgets(STDIN)));

         sort($b);
         var_dump($b);
         $s = 0;
         $bool = false;
         for($u = 0; $u < $a[0]; $u++) {
             if($u < 2) {
                 $s += $b[$u];
             }
             if($b[$u] > $a[1]){
                 $bool = true;
             }
         }
         if($s <= $a[1] || !$bool){
             echo "YES\n";
         } else {
             echo "NO\n";
         }
     }

?>

<?php
     $ft =  trim(fgets(STDIN));
     for($irt = 0; $irt < $ft; $irt++){
         $a = explode(" ", trim(fgets(STDIN)));
         $b = explode(" ", trim(fgets(STDIN)));

         sort($b);
         $s = 0;
         $bool = false;
         for($u = 0; $u < $a[0]; $u++) {
             if($u < 2) {
                 $s += $b[$u];
             }
             if($u > $a[1]){
                 $bool = true;
             }
         }
         if($s <= $a[1] || !$bool){
             echo "YES\n";
         } else {
             echo "NO\n";
         }
     }

?>

<?php
    $t = trim(fgets(STDIN));
    for ($i = 0; $i < $t; $i++) {
        list($n, $d) = explode(" ", trim(fgets(STDIN)));
        $a = explode(" ", trim(fgets(STDIN)));
        if (max($a) <= $d) {
            echo 'YES'."\n";
        } else {
            $m = min($a);
            if ($m > $d) {
                echo 'NO' ."\n";
            } else {
                foreach ($a as $k => $v) {
                    if ($v == $m) {
                        unset($a[$k]);
                    }
                }
                if (min($a) + $m <= $d) {
                    echo 'YES'."\n";
                } else {
                    echo 'NO' ."\n";
                }
            }
        }
    }

?>


Vasya has got $$$n$$$ books, numbered from $$$1$$$ to $$$n$$$, arranged in a stack. The topmost book has number $$$a_1$$$, the next one — $$$a_2$$$, and so on. The book at the bottom of the stack has number $$$a_n$$$. All numbers are distinct.Vasya wants to move all the books to his backpack in $$$n$$$ steps. During $$$i$$$-th step he wants to move the book number $$$b_i$$$ into his backpack. If the book with number $$$b_i$$$ is in the stack, he takes this book and all the books above the book $$$b_i$$$, and puts them into the backpack; otherwise he does nothing and begins the next step. For example, if books are arranged in the order $$$[1, 2, 3]$$$ (book $$$1$$$ is the topmost), and Vasya moves the books in the order $$$[2, 1, 3]$$$, then during the first step he will move two books ($$$1$$$ and $$$2$$$), during the second step he will do nothing (since book $$$1$$$ is already in the backpack), and during the third step — one book (the book number $$$3$$$). Note that $$$b_1, b_2, \dots, b_n$$$ are distinct.Help Vasya! Tell him the number of books he will put into his backpack during each step.

The first line contains one integer $$$n~(1 \le n \le 2 \cdot 10^5)$$$ — the number of books in the stack. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n~(1 \le a_i \le n)$$$ denoting the stack of books. The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n~(1 \le b_i \le n)$$$ denoting the steps Vasya is going to perform. All numbers $$$a_1 \dots a_n$$$ are distinct, the same goes for $$$b_1 \dots b_n$$$.

Print $$$n$$$ integers. The $$$i$$$-th of them should be equal to the number of books Vasya moves to his backpack during the $$$i$$$-th step.

NoteThe first example is described in the statement.In the second example, during the first step Vasya will move the books $$$[3, 1, 4]$$$. After that only books $$$2$$$ and $$$5$$$ remain in the stack ($$$2$$$ is above $$$5$$$). During the second step Vasya will take the books $$$2$$$ and $$$5$$$. After that the stack becomes empty, so during next steps Vasya won't move any books.

<?php
$l = (int)fgets(STDIN);
$l1 = explode(' ', fgets(STDIN));
$l2 = explode(' ', fgets(STDIN));
$l2cp = array_flip($l2);
$LJ = 0;
$r = [];
for ($i = 0; $i < $l; ++$i) {
    if ($LJ == $l) {
        echo '0 ';
        continue;
    }
    if ($l2cp[$l2[$i]] === false) {
        echo '0 ';
        continue;
    }
    $J = $LJ;
    $SS = 0;
    while($J <= $l) {
        if (intval($l2[$i]) == intval($l1[$J])) {
            ++$J;
            $SS = $J - $LJ;
            $LJ = $J;
            break;
        }
        $l2cp[$l1[$J]] = false;
        ++$J;
    }
    echo $SS . ' ';
}

<?php
$l = (int)fgets(STDIN);
$r = [];
for($i = 0; $i < $l; $i++) {
    $r[] = 0;
}
$l1 = array_map('intval', explode(' ', fgets(STDIN)));
$l2 = explode(' ', fgets(STDIN));
for ($i = 0; $i < $l; $i++) {
    $ind = array_search((int)$l2[$i], $l1) - $i;
    if ($ind !== false && $ind > -1) {
        $r[$i] = $ind + 1;
    }
}
echo implode(' ', $r);


You are given a problemset consisting of $$$n$$$ problems. The difficulty of the $$$i$$$-th problem is $$$a_i$$$. It is guaranteed that all difficulties are distinct and are given in the increasing order.You have to assemble the contest which consists of some problems of the given problemset. In other words, the contest you have to assemble should be a subset of problems (not necessary consecutive) of the given problemset. There is only one condition that should be satisfied: for each problem but the hardest one (the problem with the maximum difficulty) there should be a problem with the difficulty greater than the difficulty of this problem but not greater than twice the difficulty of this problem. In other words, let $$$a_{i_1}, a_{i_2}, \dots, a_{i_p}$$$ be the difficulties of the selected problems in increasing order. Then for each $$$j$$$ from $$$1$$$ to $$$p-1$$$ $$$a_{i_{j + 1}} \le a_{i_j} \cdot 2$$$ should hold. It means that the contest consisting of only one problem is always valid.Among all contests satisfying the condition above you have to assemble one with the maximum number of problems. Your task is to find this number of problems.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of problems in the problemset. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — difficulties of the problems. It is guaranteed that difficulties of the problems are distinct and are given in the increasing order.

Print a single integer — maximum number of problems in the contest satisfying the condition in the problem statement.

NoteDescription of the first example: there are $$$10$$$ valid contests consisting of $$$1$$$ problem, $$$10$$$ valid contests consisting of $$$2$$$ problems ($$$[1, 2], [5, 6], [5, 7], [5, 10], [6, 7], [6, 10], [7, 10], [21, 23], [21, 24], [23, 24]$$$), $$$5$$$ valid contests consisting of $$$3$$$ problems ($$$[5, 6, 7], [5, 6, 10], [5, 7, 10], [6, 7, 10], [21, 23, 24]$$$) and a single valid contest consisting of $$$4$$$ problems ($$$[5, 6, 7, 10]$$$).In the second example all the valid contests consist of $$$1$$$ problem.In the third example are two contests consisting of $$$3$$$ problems: $$$[4, 7, 12]$$$ and $$$[100, 150, 199]$$$.


Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by n square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every x, y such that 1 ≤ x, y ≤ n and ax, y ≠ 1, there should exist two indices s and t so that ax, y = ax, s + at, y, where ai, j denotes the integer in i-th row and j-th column.Help Okabe determine whether a given lab is good!

The first line of input contains the integer n (1 ≤ n ≤ 50) — the size of the lab.  The next n lines contain n space-separated integers denoting a row of the grid. The j-th integer in the i-th row is ai, j (1 ≤ ai, j ≤ 105).

Print "Yes" if the given lab is good and "No" otherwise. You can output each letter in upper or lower case.

NoteIn the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "No".

<?php

    $stdin = fopen ('php://stdin','r');
    $n = fgets($stdin);
    $grid = array();
    for ($i = 0; $i < $n; $i++)
        array_push($grid, explode(" ", trim(fgets($stdin))));

    $answer = true;
    for ($i = 0; $i < $n && $answer; $i++)
        for ($j = 0; $j < $n && $answer; $j++)
            if ($grid[$i][$j] != 1) {
                $sumNth = false;
                for ($a=0; $a < $n; $a++)
                    for ($b=0; $b < $n && $a != $j; $b++)
                        if ($b != $i)
                            if ($grid[$i][$a] + $grid[$b][$j] == $grid[$i][$j]) {
                                $sumNth = true;
                                $a = $n;
                                break;
                            }
                $answer = $answer && $sumNth;
            }
    echo ($answer ? "Yes" : "No")."\n";
    fclose($stdin);
?>

<?php

    $stdin = fopen ('php://stdin','r');
    $n = fgets($stdin);
    $grid = array();
    for ($i = 0; $i < $n; $i++)
        array_push($grid, explode(" ", trim(fgets($stdin))));

    $answer = true;
    for ($i = 0; $i < $n; $i++)
        for ($j = 0; $j < $n; $j++)
            if ($grid[$i][$j] != 1) {
                $sumNth = false;
                for ($a=0; $a < $n; $a++)
                    for ($b=0; $b < $n && $a != $j; $b++)
                        if ($b != $i)
                            if ($grid[$i][$a] + $grid[$b][$j] == $grid[$i][$j]) {
                                $sumNth = true;
                                $a = $n;
                                break;
                            }
                $answer = $answer && $sumNth;
            }
    echo ($answer ? "Yes" : "No")."\n";
    fclose($stdin);
?>

<?php

    $stdin = fopen ('php://stdin','r');
    $n = fgets($stdin);
    $grid = [];
    for ($i = 0; $i < $n; $i++)
        array_push($grid, explode(" ", trim(fgets($stdin))));

    $answer = true;
    for ($i = 0; $i < $n; $i++)
        for ($j = 0; $j < $n; $j++)
            if ($grid[$i][$j] != 1) {
                $sumNth = false;
                for ($a = 0; $a < $n; $a++) {
                    if ($a != $j) {
                        for ($b = 0; $b < $n; $b++)
                            if ($b != $i)
                                if ($grid[$i][$a] + $grid[$b][$j] == $grid[$i][$j]) {
                                    $sumNth = true;
                                    $a = $n;
                                    break;
                                }
                    }
                }
                if (!$sumNth) {
                    $answer = false;
                    $i = $n;
                    break;
                }
            }
    echo ($answer ? "Yes" : "No")."\n";
    fclose($stdin);
?>

<?php
$a=intval(trim(fgets(STDIN)));
for($i=0;$i<$a;$i++){
    $b[$i]=explode(' ',trim(fgets(STDIN)));
}
$sign=true;
for($i=0;$i<$a;$i++){
    for($j=0;$j<$a;$j++){
        if($b[$i][$j]==1){
            continue;
        }
        else{
            $flag=false;
            for ($k=0;$k<$a;$k++){
                if ($k==$i){
                    continue;
                }
                else{
                    if(in_array($b[$i][$j]-$b[$k][$j],$b[$i])){
                        $flag=true;
                        break;
                    }
                }
            }
            if (!$flag){
                echo 'No';
                $sign=false;
                break 2;
            }
        }
    }
}
if ($sign){
    echo 'Yes';
}
?>


Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array a (in increasing order) by reversing exactly one segment of a? See definitions of segment and reversing in the notes.

The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a. The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109).

Print "yes" or "no" (without quotes), depending on the answer. If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.

NoteSample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.Sample 3. No segment can be reversed such that the array will be sorted.DefinitionsA segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].If you have an array a of size n and you reverse its segment [l, r], the array will become:a[1], a[2], ..., a[l - 2], a[l - 1], a[r], a[r - 1], ..., a[l + 1], a[l], a[r + 1], a[r + 2], ..., a[n - 1], a[n].

<?php
/**
 * Created by PhpStorm.
 * User: CPU11316-local
 * Date: 5/22/2019
 * Time: 5:21 PM
 */
//  Bear and Game
function check($n, $arr){
    /*
    $count = 0;
    for($i = 0;$i<$n - 1;$i++){
        if($arr[$i] >= $arr[$i+1]){
            $count++;
            if($i == $n-2){//end
                $temp = swap($arr,$i - $count + 1,$i + 1);
                $res = checkIncre($n,$temp);
                if($res){
                    echo "yes\n";
                    echo ($i - $count + 2);
                    echo " ";
                    echo ($i + 2);
                    return true;
                }
                $count = 0;
            }
        }
        else{
            $temp = swap($arr,$i - $count,$i);
            $res = checkIncre($n,$temp);
            if($res){
                echo "yes\n";
                echo ($i - $count + 1);
                echo " ";
                echo ($i + 1);
                return true;
            }
            if($count != 0 ){
                echo "no";
                return false;
            }
            $count = 0;
        }
    }
    echo "no";
    return false;*/
    $count = 0;
    $arrTemp = [];
    for($i = 0;$i<$n - 1;$i++){
        if($arr[$i] >= $arr[$i+1]) {
            if($count == 0){
                array_push($arrTemp,$i);
            }
            if($i == $n - 2){
                array_push($arrTemp,$i +1);
            }
            $count++;
        }
        else{
            if($count !== 0){
                array_push($arrTemp,$i);
            }
            $count = 0;
        }
    }
    if (count($arrTemp) != 2){
        if(count($arrTemp) == 0){
            echo "yes\n";
            echo (1);
            echo " ";
            echo (1);
        }
        else
        echo "no";
    }
    else{
         $st1 = $arrTemp[0];
         $st2 = $arrTemp[1];
         if($st1 == 0||$arr[$st1 - 1] <= $arr[$st2]){
            if ($st2+1 == $n ||$arr[$st2 +1] >= $arr[$st1]){
                echo "yes\n";
                echo ($st1 + 1);
                echo " ";
                echo ($st2 + 1);
            }
            else{
                echo "no";
            }
        }
        else{
            echo "no";
        }
    }
    return;
}
function swap($arr,$start,$end)
{
    $tempArr = $arr;
    $count = 0;
    for ($i = $start; $i <= $end; $i++) {
        $tempArr[$i] = $arr[$end - $count];
        $count++;
    }
    return $tempArr;
}
function checkIncre($n,$arr){
    for($i = 0;$i<$n -1;$i++){
        if($arr[$i] >= $arr[$i+1]) return false;
    }
    return true;
}

$in = 'php://stdin';

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

$n = fgets($input);

$t = [];

$t = array_merge($t, explode(" ", trim(fgets($input))));

check($n,$t);

<?php

function Sort_array($array_size,$raw_array){
   $raw_array     = explode(" ",$raw_array);
   $default       = $raw_array;
   $array         = $default;
   $pos           = array();
   $start         = 0;
   $end           = 0;
   $reverse       = 0;

   for($i=0;$i<$array_size-1;$i++){

       if(($array[$i] > $array[$i+1]) )
       {
           if($start==0){
                $start = $i+1;
                if($i>0)
                    $start_value = $array[$i-1];
                else
                    $start_value = $array[$i];
           }

           if($i==$array_size-2){
                $end       = $i+2;
                $end_value = $array[$i+1];
           }
           else {
                $end = $i+2;
                $end_value = $array[$i+2];
           }

       }

    }
    //echo $start. " ".$end."\n";
    //echo $start_value. " ".$end_value."\n";
    if($start==0 && $end==0){
        echo "yes\n"."1 1";

    }
    else{

        for($i=$end-1;$i>$start-1;$i--){

            if($default[$i]>$default[$i-1]){
                $reverse = 1;
            }
        }

        if(($end == $array_size) && ($start==1))
        {
            if($start_value > $end_value && $reverse==0)
                echo "yes\n".$start." ".$end;
            else
                echo "no";
        }
        elseif ($start==1 && $end<$array_size  ) {

            if($start_value < $end_value && $array[$start-1] <= $end_value && $reverse==0)
                echo "yes\n".$start." ".$end;
            else
                echo "no";
        }
        elseif ($start>1 && $end<$array_size) {
            if($start_value < $end_value && $array[$start-1] <= $end_value && $reverse==0)
                echo "yes\n".$start." ".$end;
            else
                echo "no";
        }
        elseif ($start>1 && $end==$array_size) {
            if($start_value < $end_value && $reverse==0)
                echo "yes\n".$start." ".$end;
            else
                echo "no";
        }

    }

}

$array_size = trim(fgets(STDIN));
$array      = trim(fgets(STDIN));
Sort_array($array_size,$array);

<?php
$_fp = fopen("php://stdin", "r");

$n = (int) trim(fgets($_fp));

$a = explode(' ', trim(fgets($_fp)));
$b = $a;
sort($a);
$swap_list = [];
$start = 0;
$first = false;
for ($i=0; $i < $n; $i++) {
    if ($a[$i] != $b[$i]) {
        $swap_list[] = $i;
    }
}
if (count($swap_list) == 0) {
    echo 'yes' . PHP_EOL;
    echo '1 1';
} else {
    $start = $swap_list[0];
    $end = end($swap_list);
    $sub_list = array_slice($b, $start, $end-$start+1);
    $sub_list_sort = array_slice($a, $start, $end-$start+1);
    $sub_list_reverse = array_reverse($sub_list);

    if ($sub_list_reverse == $sub_list_sort) {
        echo 'yes' . PHP_EOL;
        echo ($swap_list[0] + 1) . ' ' . (end($swap_list) + 1);
    } else {
        echo 'no';
    }
}

<?php
/**
 * Created by PhpStorm.
 * User: CPU11316-local
 * Date: 5/22/2019
 * Time: 5:21 PM
 */
//  Bear and Game
function check($n, $arr){
    /*
    $count = 0;
    for($i = 0;$i<$n - 1;$i++){
        if($arr[$i] >= $arr[$i+1]){
            $count++;
            if($i == $n-2){//end
                $temp = swap($arr,$i - $count + 1,$i + 1);
                $res = checkIncre($n,$temp);
                if($res){
                    echo "yes\n";
                    echo ($i - $count + 2);
                    echo " ";
                    echo ($i + 2);
                    return true;
                }
                $count = 0;
            }
        }
        else{
            $temp = swap($arr,$i - $count,$i);
            $res = checkIncre($n,$temp);
            if($res){
                echo "yes\n";
                echo ($i - $count + 1);
                echo " ";
                echo ($i + 1);
                return true;
            }
            if($count != 0 ){
                echo "no";
                return false;
            }
            $count = 0;
        }
    }
    echo "no";
    return false;*/
    $count = 0;
    $arrTemp = [];
    for($i = 0;$i<$n - 1;$i++){
        if($arr[$i] >= $arr[$i+1]) {
            if($count == 0){
                array_push($arrTemp,$i);
            }
            if($i == $n - 2){
                array_push($arrTemp,$i +1);
            }
            $count++;
        }
        else{
            if($count !== 0){
                array_push($arrTemp,$i);
            }
            $count = 0;
        }
    }
    if (count($arrTemp) != 2){
        echo "no";
    }
    else{
         $st1 = $arrTemp[0];
         $st2 = $arrTemp[1];
         if($st1 == 0||$arr[$st1 - 1] <= $arr[$st2]){
            if ($st2+1 == $n ||$arr[$st2 +1] >= $arr[$st1]){
                echo "yes\n";
                echo ($st1 + 1);
                echo " ";
                echo ($st2 + 1);
            }
            else{
                echo "no";
            }
        }
        else{
            echo "no";
        }
    }
    return;
}
function swap($arr,$start,$end)
{
    $tempArr = $arr;
    $count = 0;
    for ($i = $start; $i <= $end; $i++) {
        $tempArr[$i] = $arr[$end - $count];
        $count++;
    }
    return $tempArr;
}
function checkIncre($n,$arr){
    for($i = 0;$i<$n -1;$i++){
        if($arr[$i] >= $arr[$i+1]) return false;
    }
    return true;
}

$in = 'php://stdin';

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

$n = fgets($input);

$t = [];

$t = array_merge($t, explode(" ", trim(fgets($input))));

check($n,$t);

<?php
/**
 * Created by PhpStorm.
 * User: CPU11316-local
 * Date: 5/22/2019
 * Time: 5:21 PM
 */
//  Bear and Game
function check($n, $arr){
    $count = 0;
    for($i = 0;$i<$n - 1;$i++){
        if($arr[$i] >= $arr[$i+1]){
            $count++;
            if($i == $n-2){//end
                $temp = swap($arr,$i - $count + 1,$i + 1);
                $res = checkIncre($n,$temp);
                if($res){
                    echo "yes\n";
                    echo ($i - $count + 2);
                    echo " ";
                    echo ($i + 2);
                    return true;
                }
                $count = 0;
            }
        }
        else{
            $temp = swap($arr,$i - $count,$i);
            $res = checkIncre($n,$temp);
            if($res){
                echo "yes\n";
                echo ($i - $count + 1);
                echo " ";
                echo ($i + 1);
                return true;
            }
            if($count == 0 ){
                echo "no";
                return false;
            }
            $count = 0;
        }
    }
    echo "no";
    return false;
}
function swap($arr,$start,$end)
{
    $tempArr = $arr;
    $count = 0;
    for ($i = $start; $i <= $end; $i++) {
        $tempArr[$i] = $arr[$end - $count];
        $count++;
    }
    return $tempArr;
}
function checkIncre($n,$arr){
    for($i = 0;$i<$n -1;$i++){
        if($arr[$i] >= $arr[$i+1]) return false;
    }
    return true;
}

$in = 'php://stdin';

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

$n = fgets($input);

$t = [];

$t = array_merge($t, explode(" ", trim(fgets($input))));

check($n,$t);

<?php
/**
 * Created by PhpStorm.
 * User: CPU11316-local
 * Date: 5/22/2019
 * Time: 5:21 PM
 */
//  Bear and Game
function check($n, $arr){
    $count = 0;
    for($i = 0;$i<$n - 1;$i++){
        if($arr[$i] >= $arr[$i+1]){
            $count++;
            if($i == $n-2){//end
                $temp = swap($arr,$i - $count + 1,$i + 1);
                $res = checkIncre($n,$temp);
                if($res){
                    echo "yes\n";
                    echo ($i - $count + 2);
                    echo " ";
                    echo ($i + 2);
                    return true;
                }
                $count = 0;
            }
        }
        else{
            $temp = swap($arr,$i - $count,$i);
            $res = checkIncre($n,$temp);
            if($res){
                echo "yes\n";
                echo ($i - $count + 1);
                echo " ";
                echo ($i + 1);
                return true;
                return true;
            }
            $count = 0;
        }
    }
    echo "no";
    return false;
}
function swap($arr,$start,$end)
{
    $tempArr = $arr;
    for ($i = $start; $i <= $end; $i++) {
        $tempArr[$i] = $arr[$end - $i];
    }
    return $tempArr;
}
function checkIncre($n,$arr){
    for($i = 0;$i<$n -1;$i++){
        if($arr[$i] >= $arr[$i+1]) return false;
    }
    return true;
}
$in = 'php://stdin';

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

$n = fgets($input);

$t = [];

$t = array_merge($t, explode(" ", trim(fgets($input))));

check($n,$t);

<?php

function Sort_array($array_size,$raw_array){
   $raw_array     = explode(" ",$raw_array);
   $default       = $raw_array;
   $array       = $default;
    for($i=0;$i<$array_size;$i++){
        for($j=$i+1;$j<$array_size;$j++){
            if($array[$i]>$array[$j])
            {
                $temp        = $array[$i];
                $array[$i]   = $array[$j];
                $array[$j]   = $temp;

            }

        }
    }

    if($default==$array){
        echo "yes\n"."1 1";
        exit();
    }
    else
    {
        for($i=0;$i<$array_size;$i++){
            for($j=$i+1;$j<$array_size;$j++){
                $swap = 0;
                if($default[$i]>$default[$j]&& $swap<=1)
                {
                    $temp        = $default[$i];
                    $default[$i]   = $default[$j];
                    $default[$j]   = $temp;
                    $swap++;
                    if($default==$array){
                        echo "yes\n".($i+1)." ".($j+1);
                        exit();
                    }
                    else{
                        $default = $raw_array;
                    }
                }

            }
        }
        if($default!=$array){
            echo "no";
        }
    }

}

$array_size = trim(fgets(STDIN));
$array      = trim(fgets(STDIN));
Sort_array($array_size,$array);

<?php

function Sort_array($array_size,$raw_array){
   $raw_array     = explode(" ",$raw_array);
   $default       = $raw_array;
   $array         = $default;
   $pos           = array();
   $start         = 0;
   $end           = 0;
   $reverse       = 0;

   for($i=0;$i<$array_size-1;$i++){

       if(($array[$i] > $array[$i+1]) )
       {
           if($start==0){
                $start = $i+1;
                if($i>0)
                    $start_value = $array[$i-1];
                else
                    $start_value = $array[$i];
           }

           if($i==$array_size-2){
                $end       = $i+2;
                $end_value = $array[$i+1];
           }
           else {
                $end = $i+2;
                $end_value = $array[$i+2];
           }

       }

    }
    //echo $start. " ".$end."\n";
    //echo $start_value. " ".$end_value."\n";
    if($start==0 && $end==0){
        echo "yes\n"."1 1";

    }
    else{
        if(($end == $array_size) && ($start==1))
        {
            if($start_value > $end_value )
                echo "yes\n".$start." ".$end;
            else
                echo "no";
        }
        elseif ($start==1 && $end<$array_size  ) {

            if($start_value < $end_value && $array[$start-1] <= $end_value)
                echo "yes\n".$start." ".$end;
            else
                echo "no";
        }
        elseif ($start>1 && $end<$array_size) {
            if($start_value < $end_value && $array[$start-1] <= $end_value)
                echo "yes\n".$start." ".$end;
            else
                echo "no";
        }
        elseif ($start>1 && $end==$array_size) {
            if($start_value < $end_value)
                echo "yes\n".$start." ".$end;
            else
                echo "no";
        }

    }

}

$array_size = trim(fgets(STDIN));
$array      = trim(fgets(STDIN));
Sort_array($array_size,$array);

<?php

function Sort_array($array_size,$raw_array){
   $raw_array     = explode(" ",$raw_array);
   $default       = $raw_array;
   $array         = $default;
   $pos           = array();
   $start         = 0;
   $end           = 0;
   $reverse       = 0;

   for($i=0;$i<$array_size-1;$i++){

       if(($array[$i] > $array[$i+1]) )
       {
           if($start==0){
                $start = $i+1;
                if($i>0)
                    $start_value = $array[$i-1];
                else
                    $start_value = $array[$i];
           }

           if($i==$array_size-2){
                $end       = $i+2;
                $end_value = $array[$i+1];
           }
           else {
                $end = $i+2;
                $end_value = $array[$i+2];
           }

       }

    }

    if($start==0 && $end==0){
        echo "yes\n"."1 1";

    }
    else{
        if(($end == $array_size) && ($start==1))
        {
            if($start_value > $end_value)
                echo "yes\n".$start." ".$end;
            else
                echo "no";
        }
        elseif ($start==1 && $end<$array_size) {

            if($start_value < $end_value)
                echo "yes\n".$start." ".$end;
            else
                echo "no";
        }
        elseif ($start>1) {
            if($start_value < $end_value)
                echo "yes\n".$start." ".$end;
            else
                echo "no";
        }

    }

}

$array_size = trim(fgets(STDIN));
$array      = trim(fgets(STDIN));
Sort_array($array_size,$array);

<?php

function Sort_array($array_size,$raw_array){
   $raw_array     = explode(" ",$raw_array);
   $default       = $raw_array;
   $array         = $default;

   for($i=0;$i<$array_size;$i++){
        for($j=$i+1;$j<$array_size;$j++){
            if($array[$i]>$array[$j])
            {
                $temp        = $array[$i];
                $array[$i]   = $array[$j];
                $array[$j]   = $temp;

            }

        }
    }

    for($i=0;$i<$array_size;$i++){
        $reverse_array[$i] = $default[$array_size-1-$i];
    }

    if($default==$array){
        echo "yes\n"."1 1";
        exit();
    }
    else if($reverse_array==$array){
        echo "yes\n"."1 ".$array_size;
        exit();
    }
    else
    {
        for($i=0;$i<$array_size;$i++){
            for($j=$i+1;$j<$array_size;$j++){
                $swap = 0;
                if($default[$i]>$default[$j]&& $swap<=1)
                {
                    $temp        = $default[$i];
                    $default[$i]   = $default[$j];
                    $default[$j]   = $temp;
                    $swap++;
                    if($default==$array){
                        echo "yes\n".($i+1)." ".($j+1);
                        exit();
                    }
                    else{
                        $default = $raw_array;
                    }
                }

            }
        }
        if($default!=$array){
            echo "no";
        }
    }

}

$array_size = trim(fgets(STDIN));
$array      = trim(fgets(STDIN));
Sort_array($array_size,$array);

<?php
$_fp = fopen("php://stdin", "r");

$n = (int) trim(fgets($_fp));

$a = explode(' ', trim(fgets($_fp)));
$b = $a;
sort($a);
$swap_list = [];
$start = 0;
$first = false;
for ($i=0; $i < $n; $i++) {
    if ($a[$i] != $b[$i]) {
        $swap_list[] = $i;
    }
}
if (count($swap_list) == 0) {
    echo 'yes' . PHP_EOL;
    echo '1 1';
} else {
    $sub_list = array_slice($b, $swap_list[0], end($swap_list) + 1);
    $sub_list_sort = array_slice($a, $swap_list[0], end($swap_list) + 1);
    $sub_list_reverse = array_reverse($sub_list);

    if ($sub_list_reverse == $sub_list_sort) {
        echo 'yes' . PHP_EOL;
        echo ($swap_list[0] + 1) . ' ' . (end($swap_list) + 1);
    } else {
        echo 'no';
    }
}


Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.

The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.

In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.

NoteIn the first test you can make only one number that is a multiple of 90 — 0.In the second test you can make number 5555555550, it is a multiple of 90.

<?

error_reporting(false);

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

if (file_exists("in.txt")) {
    error_reporting(E_ALL);
    $handle = fopen('in.txt', 'r');
    set_time_limit(1);
};

$n = intval(fgets($handle));
$n5 = 0;
$n0 = 0;

$array = explode(" ", fgets($handle));

foreach($array as $c) {
    if ($c == 0) $n0++;
    else $n5++;
}

$k = intval(5*$n5/45);

if ($n0 == 0) die("-1");
if ($n0 > 0 && $k == 0) die("0");
echo str_repeat("5", $k*9).str_repeat("0", $n0);

?>