Imagine that your city is an infinite 2D plane with Cartesian coordinate system. The only crime-affected road of your city is the x-axis. Currently, there are n criminals along the road. No police station has been built on this road yet, so the mayor wants to build one.As you are going to be in charge of this new police station, the mayor has asked you to choose a suitable position (some integer point) for building it. You should choose the best position for the police station, so that you could minimize the total time of your criminal catching mission. Your mission of catching the criminals will operate only from this station. The new station will have only one patrol car. You will go to the criminals by this car, carry them on the car, bring them back to the police station and put them in prison. The patrol car can carry at most m criminals at a time. Note that, the criminals don't know about your mission. So, they will stay where they are instead of running away.Your task is to find the position for the police station, so that total distance you need to cover to catch all the criminals will be minimum possible. Note that, you also can built the police station on the positions where one or more criminals already exist. In such a case all these criminals are arrested instantly.

The first line of the input will have two integers n (1 ≤ n ≤ 106) and m (1 ≤ m ≤ 106) separated by spaces. The next line will contain n integers separated by spaces. The ith integer is the position of the ith criminal on the x-axis. Absolute value of positions will not exceed 109. If a criminal has position x, he/she is located in the point (x, 0) of the plane.  The positions of the criminals will be given in non-decreasing order. Note, that there can be more than one criminal standing at some point of the plane. Note: since the size of the input/output could be very large, don't use slow input/output techniques in your language. For example, do not use input/output streams (cin, cout) in C++.

Print a single integer, that means the minimum possible distance you need to cover to catch all the criminals.

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

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

    list($n, $m) = explode(" ", trim(fgets($input)));

    $a = explode(" ", trim(fgets($input)));

    $i = 0;
    $j = $n-1;
    $l = 0;

    while ($i < $j) {

        $l = $l + $a[$j] - $a[$i];

        $i += $m;
        $j -= $m;
    }

    echo number_format(2 * $l, 0, "", "");
?>

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

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

	list($n, $m) = explode(" ", trim(fgets($input)));

	$a = explode(" ", trim(fgets($input)));

	$i = 0;
	$j = $n-1;

	while ($i < $j) {

		$l += $a[$j]-$a[$i];

		$i += $m;
		$j -= $m;
	}

	echo number_format($l*2, 0, "", "");
?>

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

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

	list($n, $m) = explode(" ", trim(fgets($input)));

	$a = explode(" ", trim(fgets($input)));

	$i = 0;
	$j = $n-1;

	while ($i < $j) {

		$l += $a[$j]-$a[$i];

		$i += $m;
		$j -= $m;
	}

	echo intval($l*2);
?>

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

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

	list($n, $m) = explode(" ", trim(fgets($input)));

	$a = explode(" ", trim(fgets($input)));

	$p = floor($n/2);
	$v = $a[$p];
	$i = 0;
	$j = $n-1;

	while ($i < $j) {

		$l = (int) ($l+ $a[$j]-$a[$i]);

		$i += $m;
		$j -= $m;
	}

	echo bcmul($l, "2");
?>

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

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

	list($n, $m) = explode(" ", trim(fgets($input)));

	$a = explode(" ", trim(fgets($input)));

	$i = 0;
	$j = $n-1;

	while ($i < $j) {

		$l += $a[$j]-$a[$i];

		$i += $m;
		$j -= $m;
	}

	echo $l*2;
?>

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

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

	list($n, $m) = explode(" ", trim(fgets($input)));

	$a = explode(" ", trim(fgets($input)));

	$i = 0;
	$j = $n-1;

	while ($i < $j) {

		$l += $a[$j]-$a[$i];

		$i += $m;
		$j -= $m;
	}

	echo (int) $l*2;
?>

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

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

	list($n, $m) = explode(" ", trim(fgets($input)));

	$a = explode(" ", trim(fgets($input)));

	$i = 0;
	$j = $n-1;

	while ($i < $j) {

		$l = $l+($a[$j]-$a[$i]);

		$i += $m;
		$j -= $m;
	}

	echo bcmul($l, "2");
?>

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

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

    list($n, $m) = explode(" ", trim(fgets($input)));

    $a = explode(" ", trim(fgets($input)));

    $i = 0;
    $j = $n-1;

    $l=0;
    while ($i < $j) {
        $l = $l+($a[$j]-$a[$i]);

        $i += $m;
        $j -= $m;
    }

    echo $l;
?>

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

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

    list($n, $m) = explode(" ", trim(fgets($input)));

    $a = explode(" ", trim(fgets($input)));

    $i = 0;
    $j = $n-1;
    $l = 0;

    while ($i < $j) {

        $l = $l + $a[$j] - $a[$i];

        $i += $m;
        $j -= $m;
    }

    echo sprintf('%d', $l);
?>

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

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

    list($n, $m) = explode(" ", trim(fgets($input)));

    $a = explode(" ", trim(fgets($input)));

    $i = 0;
    $j = $n-1;
    $l = 0;

    while ($i < $j) {

        $l = $l + $a[$j] - $a[$i];

        $i += $m;
        $j -= $m;
    }

    echo sprintf('%lld', 2 * $l);
?>

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

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

    list($n, $m) = explode(" ", trim(fgets($input)));

    $a = explode(" ", trim(fgets($input)));

    $i = 0;
    $j = $n-1;

    while ($i < $j) {

        $l = $l + $a[$j]-$a[$i];

        $i += $m;
        $j -= $m;
    }

    echo 2 * $l;
?>

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

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

    list($n, $m) = explode(" ", trim(fgets($input)));

    $a = explode(" ", trim(fgets($input)));

    $i = 0;
    $j = $n-1;

    while ($i < $j) {

        $l = $l + $a[$j]-$a[$i];

        $i += $m;
        $j -= $m;
    }

    echo $l;
?>

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

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

    list($n, $m) = explode(" ", trim(fgets($input)));

    $a = explode(" ", trim(fgets($input)));

    $i = 0;
    $j = $n-1;
    $l = 0;

    while ($i < $j) {

        $l = $l + $a[$j] - $a[$i];

        $i += $m;
        $j -= $m;
    }

    echo number_format(2 * $l);
?>

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

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

    list($n, $m) = explode(" ", trim(fgets($input)));

    $a = explode(" ", trim(fgets($input)));

    $i = 0;
    $j = $n-1;
    $l = 0;

    while ($i < $j) {

        $l = $l + $a[$j] - $a[$i];

        $i += $m;
        $j -= $m;
    }

    echo sprintf('%d', 2 * $l);
?>


During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x — the number of different solutions that are sent before the first solution identical to A, and k — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.

The first line of the input contains an integer n (1 ≤ n ≤ 105) — the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 ≤ x ≤ 105; 1 ≤ k ≤ 105) — the number of previous unique solutions and the identifier of the participant.

A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.

<?php
fscanf(STDIN, "%f", $n);
$arr=array();
$exist=array();
for ($i=0; $i<$n; $i++){
    fscanf(STDIN, "%f %f", $x, $k);
    $arr[$k][]=$x;
}
$r='YES';
foreach($arr as $user => $sends){
    $exist[$user][]=$sends[0];
    if ($sends[0]>0){
            $r='NO';
            echo $r;
            return;
        };
    $max=max($exist[$user]);
    for($i=1; $i<count($sends); $i++){
        $a=$sends[$i];
        if ($a<=$max) continue;
        if ( $max-$a !=-1 ){
            $r='NO';
            echo $r;
            return;
        }
        $exist[$user][]=$a;
        $max=max($max,$a);
    }
}
echo $r;

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

<?php

$n = trim(fgets(STDIN));

$a = array();
$aa = array();

for($i = 0; $i < $n; $i++)
{
	list($u, $p) = explode(" ", trim(fgets(STDIN)));

	if(! @isset($aa[$u]))
	{
		$aa[$u] = true;
		$a[] = $u;
	}
}

for($i = 1; $i < sizeof($a); $i++)
{
	if($a[$i - 1] > $a[$i])
	{
		echo "NO" . PHP_EOL;
		exit;
	}

	$a[$i] = max($a[$i], $a[$i - 1]);
}

echo "YES" . PHP_EOL;

<?php
fscanf(STDIN, "%f", $n);
$arr=array();
$exist=array();
for ($i=0; $i<$n; $i++){
    fscanf(STDIN, "%f %f", $x, $k);
    $arr[$k][]=$x;
}
$r='YES';
foreach($arr as $user => $sends){
    $exist[$user]=array();
    for($i=0; $i<count($sends); $i++){
        $a=$sends[$i];
        if (in_array($a,$exist[$user])) continue;
        if (max($exist[$user])>$a){
            $r='NO';
            echo $r;
            return;
        }
        $exist[$user][]=$a;
    }
}
echo $r;

<?php
fscanf(STDIN, "%f", $n);
$arr=array();
$exist=array();
for ($i=0; $i<$n; $i++){
    fscanf(STDIN, "%f %f", $x, $k);
    $arr[$k][]=$x;
}
$r='YES';
foreach($arr as $user => $sends){
    $exist[$user][]=$sends[0];
    for($i=1; $i<count($sends); $i++){
        $a=$sends[$i];
        if (in_array($a,$exist[$user])) continue;
        if ( max($exist[$user])-$a !=-1 ){
            $r='NO';
            echo $r;
            return;
        }
        $exist[$user][]=$a;
    }
}
echo $r;

<?php
fscanf(STDIN, "%f", $n);
$arr=array();
$exist=array();
for ($i=0; $i<$n; $i++){
    fscanf(STDIN, "%f %f", $x, $k);
    $arr[$k][]=$x;
}
$r='YES';
foreach($arr as $user => $sends){
    $exist[$user]=array();
    for($i=0; $i<count($sends); $i++){
        $a=$sends[$i];
        if (in_array($a,$exist[$user])) continue;
        if ( max($exist[$user])-$a>=1){
            $r='NO';
            echo $r;
            return;
        }
        $exist[$user][]=$a;
    }
}
echo $r;


For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 < 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.

The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$.  Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).

NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.

        <?php

        $server = "php://stdin";
        $local = "input.txt";
        $handle = fopen($server, "r");
        $t = trim(fgets($handle));

        for ($i=0;$i<$t;$i++)
        {
            $x = trim(fgets($handle));
            $a = trim(fgets($handle));
            $p = explode(' ', $a);
            $max=-1;$min=1000000009;
            $ok=false;
            for($j=0;$j<$x-1;$j++)
            {
               if(abs($p[$j]-$p[$j+1])>=2)
               {
                   $ok=true;
                   echo "YES"."\n";
                   echo ($j+1)." ".($j+2)."\n";
                   break;
               }
            }
            if(!$ok)
            {
                echo "NO"."\n";
            }

        }

        ?>

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

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

$iterate = function($a, $n){
	$a[0] = intval($a[0]);
	for ($i = 1; $i < $n; $i++) {
		$a[$i] = intval($a[$i]);
		if(abs($a[$i] - $a[$i-1]) > 1){
			echo "YES\n";
			echo ($i) . ' ' . ($i + 1) . "\n";
			return;
		}
	}
	echo "NO\n";
};

for (; $t != 0; $t--) {
	$n = intval(trim(fgets(STDIN)));
	$a = explode(' ', trim(fgets(STDIN)));

	$iterate($a, $n);
}

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));

for ($i=0;$i<$t;$i++)
{
    $x = trim(fgets($handle));
    $a = trim(fgets($handle));
    $p = explode(' ', $a);
    sort($p);
    $sum=0;$l=0;$r=$x-1;$count=$x;$check=false;$ok=false;
    while($l<$r)
    {
        if($p[$r]-$p[$l]>=$count)
        {
            $ok=true;
            echo "YES"."\n";
            echo ($l+1)." ".($r+1)."\n";
            break;
        }else if($check==false)
        {
            $l++;
            $count--;
            $check=true;
        }else if($check==true)
        {
            $r--;
            $count--;
            $check=false;
        }
    }
    $sum=0;$l=0;$r=$x-1;$count=$x;$check=true;$ok=false;
    while($l<$r)
    {
        if($p[$r]-$p[$l]>=$count)
        {
            $ok=true;
            echo "YES"."\n";
            echo ($l+1)." ".($r+1)."\n";
            break;
        }else if($check==false)
        {
            $l++;
            $count--;
            $check=true;
        }else if($check==true)
        {
            $r--;
            $count--;
            $check=false;
        }
    }
    if(!$ok)
    echo "NO"."\n";

}

?>

<?php
function getb($a,$l,$r)
{
    $min=1000000009;
    $max=0;
    for($i=$l;$i<=$r;$i++)
    {
        if($min>$a[$i])
        {
            $min=$a[$i];
        }
        if($max<$a[$i])
        {
            $max=$a[$i];
        }
    }
    return $max-$min;
}
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));

for ($i=0;$i<$t;$i++)
{
    $x = trim(fgets($handle));
    $a = trim(fgets($handle));
    $p = explode(' ', $a);
    $sum=0;$l=0;$r=0;$count=1;$check=false;$ok=false;
    $min=$p[0];
    $max=$p[0];
    while($l<$x-1)
    {
        if(getb($p,$l,$r)>=$count)
        {
            $ok=true;
            echo "YES"."\n";
            echo ($l+1)." ".($r+1)."\n";
            break;
        }else {
           $r++;
            if($r==$x-1)
            {
                $l++;
                $r=$l;
                $count=1;
            }
           $count++;
        }
    }

    if(!$ok)
    echo "NO"."\n";

}

?>

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));

for ($i=0;$i<$t;$i++)
{
    $x = trim(fgets($handle));
    $a = trim(fgets($handle));
    $p = explode(' ', $a);
    sort($p);
    $sum=0;$l=0;$r=$x-1;$count=$x;$check=false;$ok=false;
    while($l<$r)
    {
        if($p[$r]-$p[$l]>=$count)
        {
            $ok=true;
            echo "YES"."\n";
            echo ($l+1)." ".($r+1)."\n";
            break;
        }else {
            if($p[$r]-$p[$l+1]>$p[$r-1]-$p[$l])
            {
                $l++;
                $count--;
            }else
            {
                $r--;
                $count--;
            }
        }
    }

    if(!$ok)
    echo "NO"."\n";

}

?>

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));

for ($i=0;$i<$t;$i++)
{
    $x = trim(fgets($handle));
    $a = trim(fgets($handle));
    $p = explode(' ', $a);
    sort($p);
    $sum=0;$l=0;$r=$x-1;$count=$x;$check=false;$ok=false;
    while($l<$r)
    {
        if($p[$r]-$p[$l]>=$count)
        {
            $ok=true;
            echo "YES"."\n";
            echo ($l+1)." ".($r+1)."\n";
            break;
        }else if($check==false)
        {
            $l++;
            $count--;
            $check=true;
        }else if($check==true)
        {
            $r--;
            $count--;
            $check=false;
        }

    }
    if(!$ok)
    echo "NO"."\n";

}

?>

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

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

for (; $t != 0; $t--) {
	$n = intval(trim(fgets(STDIN)));
	$a = explode(' ', trim(fgets(STDIN)));
	for ($i = 0; $i < $n; $i++) {
		$a[$i] = intval($a[$i]);
	}

	$iterate = function () use ($n, $a) {
		$max =  max($a);
		$min =  min($a);
		$delta = $max - $min;

		for ($i = 0; $i < $n - 1; $i++) {
			if($max == $a[$i] || $min == $a[$i]){
				$max = $a[$i];
				$min = $a[$i];
				for ($j = $i + 1; $j < $n; $j++) {
					if ($max < $a[$j]) {
						$max = $a[$j];
						if ($max - $min > $j - $i) {
							return [$i, $j];
						}
					} else if ($min > $a[$j]) {
						$min = $a[$j];
						if ($max - $min > $j - $i) {
							return [$i, $j];
						}
					}
					if($delta < $j - $i){
						break;
					}
				}
			}

			$delta = $max - $min;
		}
		return false;
	};

	$res = $iterate();

	if ($res === false) {
		echo "NO\n";
	} else {
		echo "YES\n";
		echo ($res[0] + 1) . ' ' . ($res[1] + 1) . "\n";
	}

}

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

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

for (; $t!=0 ; $t--){
	$n = intval(trim(fgets(STDIN)));
	$a = explode(' ', trim(fgets(STDIN)));
	for ($i = 0; $i < $n; $i++){$a[$i] = intval($a[$i]);}

	$iterate = function() use($n, $a){
		for ($i = 0; $i < $n-1; $i++){
			$max = $a[$i];$min = $a[$i];
			for($j = $n-1; $j > $i; $j-- ){
				if($max < $a[$j]){
					$max = $a[$j];
					if($max - $min >= ($j - $i) + 1){
						return [$i, $j];
					}
				} else if($min > $a[$j]){
					$min = $a[$j];
					if($max - $min >= ($j - $i) + 1){
						return [$i, $j];
					}
				}
			}
		}
		return false;
	};

	$res = $iterate();

	if($res===false){
		echo "NO\n";
	} else {
		echo "YES\n";
		echo (min($res)+1).' '.(max($res)+1)."\n";
	}
}

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

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

for (; $t != 0; $t--) {
	$n = intval(trim(fgets(STDIN)));
	$a = explode(' ', trim(fgets(STDIN)));
	for ($i = 0; $i < $n; $i++) {
		$a[$i] = intval($a[$i]);
	}

	$iterate = function () use ($n, $a) {
		$max =  max($a);
		$min =  min($a);
		$delta = $max - $min;

		for ($i = 0; $i < $n - 1; $i++) {
			if($max == $a[$i] || $min == $a[$i]){
				$max = $a[$i];
				$min = $a[$i];
				for ($j = $i + 1; $j < $n; $j++) {
					if ($max < $a[$j]) {
						$max = $a[$j];
						if ($max - $min > $j - $i) {
							return [$i, $j];
						}
					} else if ($min > $a[$j]) {
						$min = $a[$j];
						if ($max - $min > $j - $i) {
							return [$i, $j];
						}
					}
					if($delta <= $j - $i){
						break;
					}
				}
			}

			$delta = $max - $min;
		}
		return false;
	};

	$res = $iterate();

	if ($res === false) {
		echo "NO\n";
	} else {
		echo "YES\n";
		echo ($res[0] + 1) . ' ' . ($res[1] + 1) . "\n";
	}

}

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));

for ($i=0;$i<$t;$i++)
{
    $x = trim(fgets($handle));
    $a = trim(fgets($handle));
    $p = explode(' ', $a);
    $r=$x-1;$ok=false;
    for($j=0;$j<$x;$j++)
    {
        for($k=$j+1;$k<$x;$k++)
        {
         if(abs($p[$j]-$p[$k])>$k)
         {
             $ok=true;
             echo "YES"."\n";
             echo min($k+1,$j+1)." ".max($j+1,$k+1)."\n";
            break;
         }

        }
        if($ok==true)break;
    }

    if(!$ok)
    echo "NO"."\n";

}

?>

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));

for ($i=0;$i<$t;$i++)
{
    $x = trim(fgets($handle));
    $a = trim(fgets($handle));
    $p = explode(' ', $a);
    $sum=0;$l=0;$r=$x-1;$count=$x;$check=false;$ok=false;
    while($l<$r)
    {
        if($p[$r]-$p[$l]>=$count)
        {
            $ok=true;
            echo "YES"."\n";
            echo ($l+1)." ".($r+1)."\n";
            break;
        }else {
            if($p[$r]-$p[$l+1]>$p[$r-1]-$p[$l])
            {
                $l++;
                $count--;
            }else
            {
                $r--;
                $count--;
            }
        }
    }

    if(!$ok)
    echo "NO"."\n";

}

?>

<?php
function subArray($arr, $n)
{

    // Pick starting point
    for ($i = 0; $i < $n; $i++)
    {

        // Pick ending point
        for ($j = $i; $j < $n; $j++)
        {
            $temp=[];
            // Print subarray between
            // current starting
            // and ending points
            for ($k = $i; $k <= $j; $k++)
                $temp[]=$arr[$k];

           if(max($temp)-min($temp)>=sizeof($temp))
           {
               echo "YES"."\n";
               echo $i." ".$j."\n";
               return true;
           }
        }
    }
    return false;
}
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));

for ($i=0;$i<$t;$i++)
{
    $x = trim(fgets($handle));
    $a = trim(fgets($handle));
    $p = explode(' ', $a);

    if(!subArray($p,$x))
    echo "NO"."\n";

}

?>

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));

for ($i=0;$i<$t;$i++)
{
    $x = trim(fgets($handle));
    $a = trim(fgets($handle));
    $p = explode(' ', $a);
    $sum=0;$l=0;$r=0;$count=1;$check=false;$ok=false;
    while($l<$x-1)
    {
        if($p[$r]-$p[$l]>=$count)
        {
            $ok=true;
            echo "YES"."\n";
            echo ($l+1)." ".($r+1)."\n";
            break;
        }else {
            if($r==$x-1)
            {
                $l++;
                $r=$l;
                $count=1;
            }
           $r++;
           $count++;
        }
    }

    if(!$ok)
    echo "NO"."\n";

}

?>

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));

for ($i=0;$i<$t;$i++)
{
    $x = trim(fgets($handle));
    $a = trim(fgets($handle));
    $p = explode(' ', $a);
    $r=$x-1;$ok=false;
    for($j=0;$j<$x;$j++)
    {
        for($k=$j+1;$k<$x;$k++)
        {
         if(abs($p[$j]-$p[$k])>=($k+1))
         {
             $ok=true;
             echo "YES"."\n";
             echo min($k+1,$j+1)." ".max($j+1,$k+1)."\n";
            break;
         }

        }
        if($ok==true)break;
    }

    if(!$ok)
    echo "NO"."\n";

}

?>


Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed. Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.

The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.  The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.

If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.


You are given $$$n$$$ sticks with positive integral length $$$a_1, a_2, \ldots, a_n$$$.You can perform the following operation any number of times (possibly zero):   choose one stick, then either increase or decrease its length by $$$1$$$. After each operation, all sticks should have positive lengths. What is the minimum number of operations that you have to perform such that it is possible to select three of the $$$n$$$ sticks and use them without breaking to form an equilateral triangle?An equilateral triangle is a triangle where all of its three sides have the same length.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 300$$$) — the number of sticks. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the lengths of the sticks. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$300$$$.

For each test case, print one integer on a single line — the minimum number of operations to be made.

NoteIn the first test case, you can increase the length of the first stick by $$$1$$$, then decrease the length of the third stick by $$$1$$$. In total, you perform $$$2$$$ operations, such that the three sticks form an equilateral triangle of side length $$$2$$$.In the fourth test case, you can decrease the length of the seventh stick by $$$1$$$. An equilateral triangle of side length $$$1$$$ can be selected and formed by the second, fourth, and seventh sticks.

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

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

    sort($a);

    $ans = INF;
    for ($i = 1; $i < count($a) - 1; $i += 1) {
        $ans = min($ans, $a[$i + 1] - $a[$i - 1]);
    }
    echo $ans . PHP_EOL;
}

<?php
   $cases = fgets(STDIN);
   while ($cases--) {
       $n = fgets(STDIN);
       $numbers = explode(' ', fgets(STDIN));

       sort($numbers);
       $out = PHP_INT_MAX;
       for ($i = 0; $i < $n - 2; $i++) {
           $out = min($out, ($numbers[$i + 2] - $numbers[$i]) + ($numbers[$i + 2] - $numbers[$i + 1]));
           $out = min($out, ($numbers[$i + 1] - $numbers[$i]) + ($numbers[$i + 2] - $numbers[$i + 1]));
           $out = min($out, ($numbers[$i + 2] - $numbers[$i]) + ($numbers[$i + 1] - $numbers[$i]));
       }
       echo $out;
       echo "\n";
   }
   // I'm just falah

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

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

   $n = IO::get();
   $a = IO::getArray();
   sort($a);
   $ans = 2147483646;
   $tt = 0;
   for($i=0; $i < $n-2; $i++) {
        $temp = min(($a[$i+2]-$a[$i+1]) + ($a[$i+1] - $a[$i]), ($a[$i+2]-$a[$i]) + ($a[$i+1] - $a[$i]));
        $ans = min($temp, $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
$t = trim(fgets(STDIN));

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

    sort($a);

    print_r($a);
    $ans = INF;
    for ($i = 1; $i < count($a) - 1; $i += 1) {
        $ans = min($ans, $a[$i + 1] - $a[$i - 1]);
    }
    echo $ans . PHP_EOL;
}


There was a big bank robbery in Tablecity. In order to catch the thief, the President called none other than Albert – Tablecity’s Chief of Police. Albert does not know where the thief is located, but he does know how he moves.Tablecity can be represented as 1000 × 2 grid, where every cell represents one district. Each district has its own unique name “(X, Y)”, where X and Y are the coordinates of the district in the grid. The thief’s movement is as Every hour the thief will leave the district (X, Y) he is currently hiding in, and move to one of the districts: (X - 1, Y), (X + 1, Y), (X - 1, Y - 1), (X - 1, Y + 1), (X + 1, Y - 1), (X + 1, Y + 1) as long as it exists in Tablecity. Below is an example of thief’s possible movements if he is located in district (7,1):Albert has enough people so that every hour he can pick any two districts in Tablecity and fully investigate them, making sure that if the thief is located in one of them, he will get caught. Albert promised the President that the thief will be caught in no more than 2015 hours and needs your help in order to achieve that.

The first line of output contains integer N – duration of police search in hours. Each of the following N lines contains exactly 4 integers Xi1, Yi1, Xi2, Yi2 separated by spaces, that represent 2 districts (Xi1, Yi1), (Xi2, Yi2) which got investigated during i-th hour. Output is given in chronological order (i-th line contains districts investigated during i-th hour) and should guarantee that the thief is caught in no more than 2015 hours, regardless of thief’s initial position and movement.   N ≤ 2015  1 ≤ X ≤ 1000  1 ≤ Y ≤ 2

В этой задаче нет примеров ввода-вывода.
This problem doesn't have sample input and output.

Смотрите замечание ниже.
See the note below.

NoteLet's consider the following output:25 1 50 28 1 80 2This output is not guaranteed to catch the thief and is not correct. It is given to you only to show the expected output format. There exists a combination of an initial position and a movement strategy such that the police will not catch the thief.Consider the following initial position and thief’s movement:In the first hour, the thief is located in district (1,1). Police officers will search districts (5,1) and (50,2) and will not find him.At the start of the second hour, the thief moves to district (2,2). Police officers will search districts (8,1) and (80,2) and will not find him.Since there is no further investigation by the police, the thief escaped!


Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter. Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.You are given an encoding s of some word, your task is to decode it.

The first line contains a positive integer n (1 ≤ n ≤ 2000) — the length of the encoded word. The second line contains the string s of length n consisting of lowercase English letters — the encoding.

NoteIn the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba.

<?php

$n_chars = fgets(STDIN);
$word = fgets(STDIN);//"abba";

$t = array();

$c = "";
$w = str_split($word);
for($i = 0; $i < $n_chars; $i++)
{
    if((($n_chars - $i) % 2) == 0)
    {
        $c = $w[$i] . $c;
    } else {
        $c .= $w[$i];
    }
}

echo $c;

<?php
# ALIREZA
# JAHANI
#PH_PY_LA
#DONT REPEAT YOUR SELF ...
# YOU CAN READ MY CODE ...

$n =fgets(STDIN);
settype($n, 'int');
$input = str_split(trim(fgets(STDIN)));
for ($i=$n-2; $i >= 0 ; $i-=2)
	@$result.=$input[$i];
for ($i=$n-1; $i>=0;$i-=2)
	@$r.=$input[$i];
echo $result.strrev($r);

<?php
        //Enter your code here, enjoy!
$n =  (int)trim(fgets(STDIN)); // we don't care about this.
$letters = trim(fgets(STDIN)); //explode("", "logva"); //trim(fgets(STDIN)));

$l = 0;
$word = array();//[];

while(strlen($letters) > 0) {

    $median = floor(strlen($letters) / 2) + (strlen($letters) % 2 == 1);

    while(isset($word[$median])) {
        $median++;
        if($median == ($n + 1)) {
            $median = 0;
        }
    }

    //for($median = floor(($n - $ii) / 2); isset($word[$median]); $median++);
    $word[$median] = $letters[0];
    //$n--;
    $letters = substr($letters, 1);

}

ksort($word);

echo implode($word);


Let's define a string <x> as an opening tag, where x is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type </x>, where x is the same letter.Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair.Let's define the notion of a XML-text:   an empty string is a XML-text  if s is a XML-text, then s'=<a>+s+</a> also is a XML-text, where a is any small Latin letter  if s1, s2 are XML-texts, then s1+s2 also is a XML-text You are given a XML-text (it is guaranteed that the text is valid), your task is to print in the following form:   each tag (opening and closing) is located on a single line  print before the tag 2 * h spaces, where h is the level of the tag's nestedness.

The input data consists on the only non-empty string — the XML-text, its length does not exceed 1000 characters. It is guaranteed that the text is valid. The text contains no spaces.

Print the given XML-text according to the above-given rules.

<?
$str=trim(fgets(STDIN));
$open=preg_match_all('/<\w>/',$str,$mopen);
$all=preg_match_all('/(<\w>|<\/\w>)/',$str,$mall);
function numspace($n){
    $str="";
    for($i=0; $i<$n; $i++)
        $str.=" ";
    return $str;
}
$lvl=0;
for($i=0; $i<sizeof($mall[0]); $i++){
    if(preg_match('/<\w>/',$mall[0][$i])) {
        $space=numspace($lvl*2);
        $lvl++;
    } else{
        $lvl--;
        $space=numspace($lvl*2);
    }
    echo $space.$mall[0][$i]."\n";
}
?>


You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$).

For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise.

NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     if($b % 2 == $c % 2)
     {
          $d = pow(((1 + $c + $c - 1) / 2), 2);
          if($d <= $b)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     else
     {
          print "NO\n";
     }
}
?>


Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly $$$1$$$ problem, during the second day — exactly $$$2$$$ problems, during the third day — exactly $$$3$$$ problems, and so on. During the $$$k$$$-th day he should solve $$$k$$$ problems.Polycarp has a list of $$$n$$$ contests, the $$$i$$$-th contest consists of $$$a_i$$$ problems. During each day Polycarp has to choose exactly one of the contests he didn't solve yet and solve it. He solves exactly $$$k$$$ problems from this contest. Other problems are discarded from it. If there are no contests consisting of at least $$$k$$$ problems that Polycarp didn't solve yet during the $$$k$$$-th day, then Polycarp stops his training.How many days Polycarp can train if he chooses the contests optimally?

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

Print one integer — the maximum number of days Polycarp can train if he chooses the contests optimally.

<?php
list($s) = explode(' ', trim(fgets(STDIN)));
$aRow = explode(' ', trim(fgets(STDIN)));
asort($aRow);
$k = 0;
$i = 1;
$aArr = [];
foreach ($aRow as $sK => $sV){
    if($i <= $sV){
        $k++;
        $i++;
    }

}
echo $k;

<?php
# 1165B
declare(strict_types=1);

$start = microtime(true);
$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$contests = array_map('intval', explode(' ', fgets($stdin)));
sort($contests);
$result = 0;
foreach($contests as $amount) {
    if ($amount > $result) {
        $result++;
    }
}
echo $result;

<?php
    $s1 = trim(fgets(STDIN));
    $s2 = trim(fgets(STDIN));

    $a = preg_split("/[\s,]+/", $s2);
    asort($a);

    $iter = 1; $count = 0;
    foreach($a as $v){
        if($iter<=$v){
            $iter++;
            $count++;
        }
    }

    echo $count;

?>

<?php
    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    sort($a);
    $i = 0;
    foreach ($a as $v) {
        if ($i < $v) {
            $i++;
        }
    }
    echo $i;
?>

<?php
list($s) = explode(' ', trim(fgets(STDIN)));
$aRow = explode(' ', trim(fgets(STDIN)));
asort($aRow);
$k = 0;
$i = 1;
$aArr = [];
foreach ($aRow as $sK => $sV){
    if($i <= $sV){
        $k++;
    }
    $i++;
}
echo $k;

<?php
# 1165B
declare(strict_types=1);

$start = microtime(true);
$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$contests = array_unique(array_map('intval', explode(' ', fgets($stdin))));
echo count($contests);

<?php
    $n = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    $p = array_flip($a);
    echo count($p);
?>


There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwards, then to the left and so on). Every time he walks (n + 1) meters, he draws a cross (see picture for clarifications).John Doe stops only when the lower left corner of the square has two crosses. How many crosses will John draw?   The figure shows the order in which John draws crosses for a square with side 4. The lower left square has two crosses. Overall John paints 17 crosses.

The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases.  The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample.

For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

<?php

error_reporting(0);

solve();

function gcd($a, $b){

	if ($a < $b)
	{
		$temp = $b;
		$b = $a;
		$a = $temp;
	}

	while ($b != 0)
	{
		$r = $a % $b;
		$a = $b;
		$b = $r;
	}

	return $a;

	//$r = $a % $b;
	//if ($r === 0) return $b;
	//else gcd($b, $r);
}

function lcm($a, $b, $g){

	return $a * $b / $g;

}

function solve(){
	//$Input = new Input("input.txt");
	$Input = new Input();

	$tc = (int)$Input->in();

	for ($i = 0; $i < $tc; $i++)
	{
		$n = (int)$Input->in();

		if ($n % 2 == 0) print(4 * $n + 1);
		else
		{
			$g = gcd($n * 2, intval(($n + 1)/2));
			printf("%.0f",lcm($n * 4, intval(($n + 1)/2), $g) / ($n + 1) + 1);
		}

		if ($i !== $tc - 1) print("\n");
	}
}

class Input{
	private $handle = "";
	private $values = array();
	private $index = 0;

	public function __construct($localfile){

		if (is_file($localfile)) {

			$this->handle = fopen($localfile, "r");
			$contents = stream_get_contents($this->handle);

		} else {

			$contents = stream_get_contents(STDIN);

		}

		$no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->values = explode(" ", $no_newlines);
	}

	public function in(){

		return $this->values[$this->index++];

	}

	public function close(){

		if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

	}
}

?>

<?php

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

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

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function foo($n)
{
    if ($n % 2 === 0) {
        return 4 * $n + 1;
    }

    if (($n - 1) % 4 === 0) {
        return 2 * $n + 1;
    }

    return $n + 1;
}

$r = 0;

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

$n = fscanf($input, trim(str_repeat("%d ", $t)));

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

    $r = foo($n[$i]);

    fwrite($output, $r . PHP_EOL);
}

<?php

error_reporting(0);

solve();

function solve(){
	//$Input = new Input("input.txt");
	$Input = new Input();

	$tc = (int)$Input->in();

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

		$n = (int)$Input->in();

		print($n * 4 + 1);

		if ($i !== $tc - 1) print("\n");
	}
}

class Input{
	private $handle = "";
	private $values = array();
	private $index = 0;

	public function __construct($localfile){

		if (is_file($localfile)) {

			$this->handle = fopen($localfile, "r");
			$contents = stream_get_contents($this->handle);

		} else {

			$contents = stream_get_contents(STDIN);

		}

		$no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->values = explode(" ", $no_newlines);
	}

	public function in(){

		return $this->values[$this->index++];

	}

	public function close(){

		if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

	}
}

?>


Among Johnny's numerous hobbies, there are two seemingly harmless ones: applying bitwise operations and sneaking into his dad's office. As it is usually the case with small children, Johnny is unaware that combining these two activities can get him in a lot of trouble.There is a set $$$S$$$ containing very important numbers on his dad's desk. The minute Johnny heard about it, he decided that it's a good idea to choose a positive integer $$$k$$$ and replace each element $$$s$$$ of the set $$$S$$$ with $$$s \oplus k$$$ ($$$\oplus$$$ denotes the exclusive or operation). Help him choose such $$$k$$$ that Johnny's dad will not see any difference after his son is done playing (i.e. Johnny will get the same set as before playing). It is possible that no such number exists. It is also possible that there are many of them. In such a case, output the smallest one. Note that the order of elements in a set doesn't matter, i.e. set $$$\{1, 2, 3\}$$$ equals to set $$$\{2, 1, 3\}$$$.Formally, find the smallest positive integer $$$k$$$ such that $$$\{s \oplus k | s \in S\} = S$$$ or report that there is no such number.For example, if $$$S = \{1, 3, 4\}$$$ and $$$k = 2$$$, new set will be equal to $$$\{3, 1, 6\}$$$. If $$$S = \{0, 1, 2, 3\}$$$ and $$$k = 1$$$, after playing set will stay the same.

In the first line of input, there is a single integer $$$t$$$ ($$$1 \leq t \leq 1024$$$), the number of test cases. In the next lines, $$$t$$$ test cases follow. Each of them consists of two lines.  In the first line there is a single integer $$$n$$$ ($$$1 \leq n \leq 1024$$$) denoting the number of elements in set $$$S$$$. Second line consists of $$$n$$$ distinct integers $$$s_i$$$ ($$$0 \leq s_i < 1024$$$), elements of $$$S$$$. It is guaranteed that the sum of $$$n$$$ over all test cases will not exceed $$$1024$$$.

Print $$$t$$$ lines; $$$i$$$-th line should contain the answer to the $$$i$$$-th test case, the minimal positive integer $$$k$$$ satisfying the conditions or $$$-1$$$ if no such $$$k$$$ exists.

NoteIn the first test case, the answer is $$$1$$$ because it is a minimum positive integer and it satisfies all the conditions.

<?php
    define("MAXN", 1024) ;

    function solve($n, $k)
    {
    }

    $T = intval(fgets(STDIN));
    while($T --)
    {
        $n = intval(fgets(STDIN)) ;

        $set_f = array_fill(0, MAXN, 0) ;
        $Hobbies = explode(" ", fgets(STDIN)) ;

        for($i = 0; $i < $n; $i ++)
        {
            $Hobbies[$i] = intval($Hobbies[$i]) ;

            $set_f[$Hobbies[$i]] = 1 ;
        }

        for($i = 1 ; $i <= 1023; $i ++)
        {
            for($j = 0; $j < $n; $j ++)
            {
                if($set_f[$Hobbies[$j] ^ $i] != 1) break ;
            }

            if($j >= $n) break ;
        }

        if($i > 1023) echo "-1\n" ;
        else echo $i . "\n" ;
    }
?>


You've got an undirected graph, consisting of n vertices and m edges. We will consider the graph's vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-th vertex is an integer ci.Let's consider all vertices of the graph, that are painted some color k. Let's denote a set of such as V(k). Let's denote the value of the neighbouring color diversity for color k as the cardinality of the set Q(k) = {cu :  cu ≠ k and there is vertex v belonging to set V(k) such that nodes v and u are connected by an edge of the graph}.Your task is to find such color k, which makes the cardinality of set Q(k) maximum. In other words, you want to find the color that has the most diverse neighbours. Please note, that you want to find such color k, that the graph has at least one vertex with such color.

The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of vertices end edges of the graph, correspondingly. The second line contains a sequence of integers c1, c2, ..., cn (1 ≤ ci ≤ 105) — the colors of the graph vertices. The numbers on the line are separated by spaces. Next m lines contain the description of the edges: the i-th line contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi) — the numbers of the vertices, connected by the i-th edge.  It is guaranteed that the given graph has no self-loops or multiple edges.

Print the number of the color which has the set of neighbours with the maximum cardinality. It there are multiple optimal colors, print the color with the minimum number. Please note, that you want to find such color, that the graph has at least one vertex with such color.


After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements:  There is at least one digit in the string,  There is at least one lowercase (small) letter of the Latin alphabet in the string,  There is at least one of three listed symbols in the string: '#', '*', '&'.   Considering that these are programming classes it is not easy to write the password.For each character of the password we have a fixed string of length m, on each of these n strings there is a pointer on some character. The i-th character displayed on the screen is the pointed character in the i-th string. Initially, all pointers are on characters with indexes 1 in the corresponding strings (all positions are numbered starting from one).During one operation Dasha can move a pointer in one string one character to the left or to the right. Strings are cyclic, it means that when we move the pointer which is on the character with index 1 to the left, it moves to the character with the index m, and when we move it to the right from the position m it moves to the position 1.You need to determine the minimum number of operations necessary to make the string displayed on the screen a valid password.

The first line contains two integers n, m (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols.  Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase English letters, and characters '#', '*' or '&'. You have such input data that you can always get a valid password.

Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.

NoteIn the first test it is necessary to move the pointer of the third string to one left to get the optimal answer.   In the second test one of possible algorithms will be:   to move the pointer of the second symbol once to the right.  to move the pointer of the third symbol twice to the right.

<?php

list($n, $m) = array_map('intval', explode(' ', readline()));
$strings = array();
$dp = array();
for ($i=0;$i<$n;$i++){
    array_push($strings, readline());
}

for($j=0;$j<3;$j++){
    $dp[$j] = array_fill(0, $n, PHP_INT_MAX);
}

function type($char){
    if(is_numeric($char)){
        return 0;
    }elseif($char == '#' ||$char == '*' ||$char == '&' ){
        return 1;
    }else{
        return 2;
    }
}

function steps($i, $m){
    if($i > (int)($m/2)){
        return $m - $i;
    }
    return $i;
}

foreach ($strings as $key => $string){
    for($i=0;$i<$m;$i++){
        $steps = steps($i, $m);
        $type = type($string[$i]);
        if($dp[$type][$key] > $steps){
            $dp[$type][$key] = $steps;
        }
    }
}
$min = PHP_INT_MAX;

for ($i=0; $i<$n;$i++){
    for ($j=0; $j<$n;$j++){
        for ($k=0; $k<$n;$k++){
            if($i != $j && $i != $k && $j != $k){
                $cur = $dp[0][$i] + $dp[1][$j] + $dp[2][$k];
                if($min > $cur){
                    $min = $cur;
                }
            }
        }
    }
}

echo $min;

<?php

list($n, $m) = array_map('intval', explode(' ', readline()));
$strings = array();
$dp = array();
for ($i=0;$i<$n;$i++){
    array_push($strings, readline());
}

for($j=0;$j<3;$j++){
    $dp[$j] = array_fill(0, $n, -1);
}

function type($char){
    if(is_numeric($char)){
        return 0;
    }elseif($char == '#' ||$char == '*' ||$char == '&' ){
        return 1;
    }else{
        return 2;
    }
}

function steps($i, $m){
    if($i > (int)($m/2)){
        return $m - $i;
    }
    return $i;
}

foreach ($strings as $key => $string){
    for($i=0;$i<$m;$i++){
        $steps = steps($i, $m);
        $type = type($string[$i]);
        if($dp[$type][$key] > $steps || $dp[$type][$key] == -1){
            $dp[$type][$key] = $steps;
        }
    }
}
$min = PHP_INT_MAX;

for ($i=0; $i<$n;$i++){
    for ($j=0; $j<$n;$j++){
        for ($k=0; $k<$n;$k++){
            if($i != $j && $i != $k && $j != $k){
                $cur = $dp[0][$i] + $dp[1][$j] + $dp[2][$k];
                if($min > $cur){
                    $min = $cur;
                }
            }
        }
    }
}

echo $min;


Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (<) and the digit three (3). After applying the code, a test message looks like that: <3word1<3word2<3 ... wordn<3.Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message.Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above.

The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.  The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less.

In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.

7
i
am
not
main
in
the
family
<3i<>3am<3the<3<main<3in<3the<3><3family<3

NotePlease note that Dima got a good old kick in the pants for the second sample from the statement.

<?
$f = file('php://stdin',FILE_IGNORE_NEW_LINES);
define('L',PHP_EOL);
//-----------------------

$q = $f[0];

for($i=1;$i<=$q;$i++) {
	$w[] = $f[$i];
}

$r = $f[$i];

$r = preg_replace('/<(.*?)3/', '<3', $r);

$o = explode('<3',substr($r,2,-2));

if (sizeof($o)!=sizeof($w)) {
	echo 'no';
} else {
	foreach ($w as $i=>$word) {
		$word = str_split($word);

		foreach ($word as $letter) {
			$found = false;
			for($j=0;$j<strlen($o[$i]);$j++) {
				if ($o[$i][$j]==$letter) {
					$found = true;
				}

			}
			if (!$found) {
				$no = 1;
				break 2;
			}
		}

	}

}

echo $no ? 'no' : 'yes';


Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.All elements are enumerated with integers. The ChemForces company has discovered $$$n$$$ distinct chemical elements with indices $$$a_1, a_2, \ldots, a_n$$$, and will get an income of $$$x_i$$$ Berland rubles if the $$$i$$$-th element from this list is in the set of this company.The TopChemist company discovered $$$m$$$ distinct chemical elements with indices $$$b_1, b_2, \ldots, b_m$$$, and it will get an income of $$$y_j$$$ Berland rubles for including the $$$j$$$-th element from this list to its set.In other words, the first company can present any subset of elements from $$$\{a_1, a_2, \ldots, a_n\}$$$ (possibly empty subset), the second company can present any subset of elements from $$$\{b_1, b_2, \ldots, b_m\}$$$ (possibly empty subset). There shouldn't be equal elements in the subsets.Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$)  — the number of elements discovered by ChemForces. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$a_i$$$ and $$$x_i$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$1 \leq x_i \leq 10^9$$$)  — the index of the $$$i$$$-th element and the income of its usage on the exhibition. It is guaranteed that all $$$a_i$$$ are distinct. The next line contains a single integer $$$m$$$ ($$$1 \leq m \leq 10^5$$$)  — the number of chemicals invented by TopChemist. The $$$j$$$-th of the next $$$m$$$ lines contains two integers $$$b_j$$$ and $$$y_j$$$, ($$$1 \leq b_j \leq 10^9$$$, $$$1 \leq y_j \leq 10^9$$$)  — the index of the $$$j$$$-th element and the income of its usage on the exhibition. It is guaranteed that all $$$b_j$$$ are distinct.

Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.

NoteIn the first example ChemForces can choose the set ($$$3, 7$$$), while TopChemist can choose ($$$1, 2, 4$$$). This way the total income is $$$(10 + 2) + (4 + 4 + 4) = 24$$$.In the second example ChemForces can choose the only element $$$10^9$$$, while TopChemist can choose ($$$14, 92, 35$$$). This way the total income is $$$(239) + (15 + 65 + 89) = 408$$$.

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


Don't you tell me what you think that I can beIf you say that Arkady is a bit old-fashioned playing checkers, you won't be right. There is also a modern computer game Arkady and his friends are keen on. We won't discuss its rules, the only feature important to this problem is that each player has to pick a distinct hero in the beginning of the game.There are $$$2$$$ teams each having $$$n$$$ players and $$$2n$$$ heroes to distribute between the teams. The teams take turns picking heroes: at first, the first team chooses a hero in its team, after that the second team chooses a hero and so on. Note that after a hero is chosen it becomes unavailable to both teams.The friends estimate the power of the $$$i$$$-th of the heroes as $$$p_i$$$. Each team wants to maximize the total power of its heroes. However, there is one exception: there are $$$m$$$ pairs of heroes that are especially strong against each other, so when any team chooses a hero from such a pair, the other team must choose the other one on its turn. Each hero is in at most one such pair.This is an interactive problem. You are to write a program that will optimally choose the heroes for one team, while the jury's program will play for the other team. Note that the jury's program may behave inefficiently, in this case you have to take the opportunity and still maximize the total power of your team. Formally, if you ever have chance to reach the total power of $$$q$$$ or greater regardless of jury's program choices, you must get $$$q$$$ or greater to pass a test.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^3$$$, $$$0 \le m \le n$$$) — the number of players in one team and the number of special pairs of heroes. The second line contains $$$2n$$$ integers $$$p_1, p_2, \ldots, p_{2n}$$$ ($$$1 \le p_i \le 10^3$$$) — the powers of the heroes. Each of the next $$$m$$$ lines contains two integer $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 2n$$$, $$$a \ne b$$$) — a pair of heroes that are especially strong against each other. It is guaranteed that each hero appears at most once in this list. The next line contains a single integer $$$t$$$ ($$$1 \le t \le 2$$$) — the team you are to play for. If $$$t = 1$$$, the first turn is yours, otherwise you have the second turn. Hacks In order to hack, use the format described above with one additional line. In this line output $$$2n$$$ distinct integers from $$$1$$$ to $$$2n$$$ — the priority order for the jury's team. The jury's team will on each turn select the first possible hero from this list. Here possible means that it is not yet taken and does not contradict the rules about special pair of heroes.

NoteIn the first example the first turn is yours. In example, you choose $$$6$$$, the other team is forced to reply with $$$2$$$. You choose $$$5$$$, the other team chooses $$$4$$$. Finally, you choose $$$3$$$ and the other team choose $$$1$$$.In the second example you have the second turn. The other team chooses $$$6$$$, you choose $$$5$$$, forcing the other team to choose $$$1$$$. Now you choose $$$4$$$, the other team chooses $$$3$$$ and you choose $$$2$$$.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     if(count($d) > 0)
     {
          $h = max($d);
          print $h . "\n";
          flush();
          $i = trim(fgets(STDIN));
          for($x = 0; $x < $a * 2; $x++)
          {
               if($c[$x] == $h)
               {
                    unset($c[$x]);
               }
               if($c[$x] == $i)
               {
                    unset($c[$x]);
               }
          }
          unset($d[$h]);
          unset($d[$i]);
     }
     else
     {
          rsort($c);
          if(count($c) > 0)
          {
               print $c[0] . "\n";
               flush();
               $i = trim(fgets(STDIN));
               unset($c[0]);
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] == $i)
                    {
                         unset($c[$x]);
                    }
               }
          }
     }
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     if(count($d) > 0)
     {
          $h = max($d);
          print $h;
          print "\n";
          flush();
          $i = trim(fgets(STDIN));
          print "\n";
          for($x = 0; $x < $a * 2; $x++)
          {
               if($c[$x] == $h)
               {
                    unset($c[$x]);
               }
               if($c[$x] == $i)
               {
                    unset($c[$x]);
               }
          }
          unset($d[$h]);
          unset($d[$i]);
     }
     else
     {
          rsort($c);
          if(count($c) > 0)
          {
               print $c[0];
               print "\n";
               flush();
               $i = trim(fgets(STDIN));
               print "\n";
               unset($c[0]);
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] == $i)
                    {
                         unset($c[$x]);
                    }
               }
          }
     }
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     while(TRUE)
     {
          if(count($d) != 0)
          {
               $h = max($d);
               print $h . "\n";
               flush();
               $i = trim(fgets(STDIN));
               unset($d[$h]);
               unset($d[$i]);
               for($x = 0; $x < count($c); $x++)
               {
                    if($c[$x] == $h)
                    {
                         array_splice($c, $x, 1);
                         break;
                    }
               }
               for($x = 0; $x < count($c); $x++)
               {
                    if($c[$x] == $i)
                    {
                         array_splice($c, $x, 1);
                         break;
                    }
               }
          }
          else
          {
               print $c[0] . "\n";
               flush();
               $i = trim(fgets(STDIN));
               array_splice($c, 0, 1);
               array_splice($c, 0, 1);
          }
          if(count($c) == 0)
          {
               break;
          }
     }
}
else
{
     $l = 0;
     while(TRUE)
     {
          if($l == 0)
          {
               $h = trim(fgets(STDIN));
               if($d[$h] == TRUE)
               {
                    $i = $d[$h];
                    print $i . "\n";
                    flush();
                    unset($d[$h]);
                    unset($d[$i]);
                    for($x = 0; $x < count($c); $x++)
                    {
                         if($c[$x] == $h)
                         {
                              array_splice($c, $x, 1);
                              break;
                         }
                    }
                    for($x = 0; $x < count($c); $x++)
                    {
                         if($c[$x] == $i)
                         {
                              array_splice($c, $x, 1);
                              break;
                         }
                    }
               }
               elseif(($d[$h] == FALSE) && (count($d) > 0))
               {
                    $l = 1;
                    while(TRUE)
                    {
                         $j = max($d);
                         print $j . "\n";
                         flush();
                         $k = trim(fgets(STDIN));
                         unset($d[$j]);
                         unset($d[$k]);
                         for($x = 0; $x < count($c); $x++)
                         {
                              if($c[$x] == $j)
                              {
                                   array_splice($c, $x, 1);
                                   break;
                              }
                         }
                         for($x = 0; $x < count($c); $x++)
                         {
                              if($c[$x] == $k)
                              {
                                   array_splice($c, $x, 1);
                                   break;
                              }
                         }
                         if(count($d) == 0)
                         {
                              break;
                         }
                    }
               }
               elseif(($d[$h] == FALSE) && (count($d) == 0))
               {
                    for($x = 0; $x < count($c); $x++)
                    {
                         if($c[$x] == $h)
                         {
                              array_splice($c, $x, 1);
                              break;
                         }
                    }
                    print $c[0] . "\n";
                    flush();
                    array_splice($c, 0, 1);
               }
               if(count($c) == 0)
               {
                    break;
               }
          }
          else
          {
               $m = 0;
               while(TRUE)
               {
                    $n = $m % 2;
                    $m++;
                    if($n == 0)
                    {
                         print $c[0] . "\n";
                         flush();
                         array_splice($c, 0, 1);
                    }
                    else
                    {
                         $o = trim(fgets(STDIN));
                         for($x = 0; $x < count($c); $x++)
                         {
                              if($c[$x] == $o)
                              {
                                   array_splice($c, $x, 1);
                                   break;
                              }
                         }
                    }
                    if(count($c) == 0)
                    {
                         break;
                    }
               }
               break;
          }
     }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     print "6\n";
     flush();
     $h = trim(fgets(STDIN));
     print $h . "\n";
     print "4\n";
     flush();
     $h = trim(fgets(STDIN));
     print $h . "\n";
     print "2\n";
     flush();
     $h = trim(fgets(STDIN));
     print $h . "\n";
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     print "6\n";
     flush();
     $h = trim(fgets(STDIN));
     print "2\n";
     print "5\n";
     flush();
     $h = trim(fgets(STDIN));
     print "4\n";
     print "3\n";
     flush();
     $h = trim(fgets(STDIN));
     print "1\n";
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array();
$e = array();
for($x = 0; $x < $b; $x++)
{
     list($f, $g) = explode(" ", trim(fgets(STDIN)));
     $d[$f] = $g;
     $d[$g] = $f;
}
$h = trim(fgets(STDIN));
if($h == 1)
{
     for($y = 0; $y < $a; $y++)
     {
          rsort($c);
          if(count($d) > 0)
          {
               $i = max($d);
               print $i . "\n";
               flush();
               $j = trim(fgets(STDIN));
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] = $i)
                    {
                         unset($c[$x]);
                    }
                    if($c[$x] = $j)
                    {
                         unset($c[$x]);
                    }
               }
               unset($d[$i]);
               unset($d[$j]);
          }
          elseif(count($c) > 0)
          {
               print $c[0] . "\n";
               flush();
               $j = trim(fgets(STDIN));
               unset($c[0]);
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] = $j)
                    {
                         unset($c[$x]);
                    }
               }
          }
     }
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     rsort($c);
     if(count($d) > 0)
     {
          $h = max($d);
          print intval($h);
          print "\n";
          flush();
          $i = trim(fgets(STDIN));
          for($x = 0; $x < $a * 2; $x++)
          {
               if($c[$x] == $h)
               {
                    unset($c[$x]);
               }
               if($c[$x] == $i)
               {
                    unset($c[$x]);
               }
          }
          unset($d[$h]);
          unset($d[$i]);
     }
     else
     {
          if(count($c) > 0)
          {
               print intval($c[0]);
               print "\n";
               flush();
               $i = trim(fgets(STDIN));
               unset($c[0]);
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] == $i)
                    {
                         unset($c[$x]);
                    }
               }
          }
     }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     rsort($c);
     if(count($d) > 0)
     {
          $h = max($d);
          print $h . "\n";
          flush();
          $i = trim(fgets(STDIN));
          for($x = 0; $x < $a * 2; $x++)
          {
               if($c[$x] == $h)
               {
                    unset($c[$x]);
               }
               if($c[$x] == $i)
               {
                    unset($c[$x]);
               }
          }
          unset($d[$h]);
          unset($d[$i]);
     }
     else
     {
          if(count($c) > 0)
          {
               print $c[0] . "\n";
               flush();
               $i = trim(fgets(STDIN));
               unset($c[0]);
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] == $i)
                    {
                         unset($c[$x]);
                    }
               }
          }
     }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     print "6\n";
     flush();
     print "2\n";
     print "5\n";
     flush();
     print "4\n";
     print "3\n";
     flush();
     print "1\n";
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     if(count($d) > 0)
     {
          $h = max($d);
          print $h . "\n";
          flush();
          $i = trim(fgets(STDIN));
          print "\n";
          for($x = 0; $x < $a * 2; $x++)
          {
               if($c[$x] == $h)
               {
                    unset($c[$x]);
               }
               if($c[$x] == $i)
               {
                    unset($c[$x]);
               }
          }
          unset($d[$h]);
          unset($d[$i]);
     }
     else
     {
          rsort($c);
          if(count($c) > 0)
          {
               print $c[0] . "\n";
               flush();
               $i = trim(fgets(STDIN));
               print "\n";
               unset($c[0]);
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] == $i)
                    {
                         unset($c[$x]);
                    }
               }
          }
     }
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     print "6\n";
     flush();
     $h = trim(fgets(STDIN));
     print $h . "\n";
     print "4\n";
     flush();
     $h = trim(fgets(STDIN));
     print $h . "\n";
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     while(TRUE)
     {
          if(count($d) != 0)
          {
               $h = max($d);
               print $h . "\n";
               flush();
               $i = trim(fgets(STDIN));
               unset($d[$h]);
               unset($d[$i]);
               for($x = 0; $x < count($c); $x++)
               {
                    if($c[$x] == $h)
                    {
                         array_splice($c, $x, 1);
                         break;
                    }
               }
               for($x = 0; $x < count($c); $x++)
               {
                    if($c[$x] == $i)
                    {
                         array_splice($c, $x, 1);
                         break;
                    }
               }
          }
          else
          {
               print $c[0] . "\n";
               flush();
               $i = trim(fgets(STDIN));
               array_splice($c, 0, 1);
               array_splice($c, 0, 1);
          }
          if(count($c) == 0)
          {
               break;
          }
     }
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     print "6\n";
     flush();
     $h = trim(fgets(STDIN));
     print $h . "\n";
     print "5\n";
     flush();
     $h = trim(fgets(STDIN));
     print $h . "\n";
     print "3\n";
     flush();
     $h = trim(fgets(STDIN));
     print $h . "\n";
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     if(count($d) > 0)
     {
          $h = max($d);
          print $h . "\n";
          flush();
          $i = trim(fgets(STDIN));
          for($x = 0; $x < $a * 2; $x++)
          {
               if($c[$x] == $h)
               {
                    unset($c[$x]);
               }
               if($c[$x] == $i)
               {
                    unset($c[$x]);
               }
          }
          unset($d[$h]);
          unset($d[$i]);
     }
     else
     {
          rsort($c);
          if(count($c) > 0)
          {
               print $c[0] . "\n";
               flush();
               $i = trim(fgets(STDIN));
               unset($c[0]);
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] == $i)
                    {
                         unset($c[$x]);
                    }
               }
          }
     }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     while(TRUE)
     {
          if(count($d) != 0)
          {
               $h = max($d);
               print $h . "\n";
               flush();
               $i = trim(fgets(STDIN));
               unset($d[$h]);
               unset($d[$i]);
               for($x = 0; $x < count($c); $x++)
               {
                    if($c[$x] == $h)
                    {
                         array_splice($c, $x, 1);
                         break;
                    }
               }
               for($x = 0; $x < count($c); $x++)
               {
                    if($c[$x] == $i)
                    {
                         array_splice($c, $x, 1);
                         break;
                    }
               }
          }
          else
          {
               print $c[0] . "\n";
               flush();
               $i = trim(fgets(STDIN));
               array_splice($c, 0, 1);
               array_splice($c, 0, 1);
          }
          if(count($c) == 0)
          {
               break;
          }
     }
}
else
{
     $l = 0;
     while(TRUE)
     {
          if($l == 0)
          {
               $h = trim(fgets(STDIN));
               if($d[$h] == TRUE)
               {
                    $i = $d[$h];
                    print $i . "\n";
                    flush();
                    unset($d[$h]);
                    unset($d[$i]);
                    for($x = 0; $x < count($c); $x++)
                    {
                         if($c[$x] == $h)
                         {
                              array_splice($c, $x, 1);
                              break;
                         }
                    }
                    for($x = 0; $x < count($c); $x++)
                    {
                         if($c[$x] == $i)
                         {
                              array_splice($c, $x, 1);
                              break;
                         }
                    }
               }
               elseif(($d[$h] == FALSE) && (count($d) > 0))
               {
                    $l = 1;
                    for($x = 0; $x < count($c); $x++)
                    {
                         if($c[$x] == $h)
                         {
                              array_splice($c, $x, 1);
                              break;
                         }
                    }
                    while(TRUE)
                    {
                         $j = max($d);
                         print $j . "\n";
                         flush();
                         $k = trim(fgets(STDIN));
                         unset($d[$j]);
                         unset($d[$k]);
                         for($x = 0; $x < count($c); $x++)
                         {
                              if($c[$x] == $j)
                              {
                                   array_splice($c, $x, 1);
                                   break;
                              }
                         }
                         for($x = 0; $x < count($c); $x++)
                         {
                              if($c[$x] == $k)
                              {
                                   array_splice($c, $x, 1);
                                   break;
                              }
                         }
                         if(count($d) == 0)
                         {
                              break;
                         }
                    }
               }
               elseif(($d[$h] == FALSE) && (count($d) == 0))
               {
                    for($x = 0; $x < count($c); $x++)
                    {
                         if($c[$x] == $h)
                         {
                              array_splice($c, $x, 1);
                              break;
                         }
                    }
                    print $c[0] . "\n";
                    flush();
                    array_splice($c, 0, 1);
               }
               if(count($c) == 0)
               {
                    break;
               }
          }
          else
          {
               $m = 0;
               while(TRUE)
               {
                    $n = $m % 2;
                    $m++;
                    if($n == 0)
                    {
                         print $c[0] . "\n";
                         flush();
                         array_splice($c, 0, 1);
                    }
                    else
                    {
                         $o = trim(fgets(STDIN));
                         for($x = 0; $x < count($c); $x++)
                         {
                              if($c[$x] == $o)
                              {
                                   array_splice($c, $x, 1);
                                   break;
                              }
                         }
                    }
                    if(count($c) == 0)
                    {
                         break;
                    }
               }
               break;
          }
     }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     rsort($c);
     if(count($d) > 0)
     {
          $h = max($d);
          print intval($h) . "\n";
          flush();
          $i = trim(fgets(STDIN));
          for($x = 0; $x < $a * 2; $x++)
          {
               if($c[$x] == $h)
               {
                    unset($c[$x]);
               }
               if($c[$x] == $i)
               {
                    unset($c[$x]);
               }
          }
          unset($d[$h]);
          unset($d[$i]);
     }
     else
     {
          if(count($c) > 0)
          {
               print intval($c[0]) . "\n";
               flush();
               $i = trim(fgets(STDIN));
               unset($c[0]);
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] == $i)
                    {
                         unset($c[$x]);
                    }
               }
          }
     }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     print "6\n";
     flush();
     $h = trim(fgets(STDIN));
     print "5\n";
     flush();
     $h = trim(fgets(STDIN));
     print "3\n";
     flush();
     $h = trim(fgets(STDIN));
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($e, $f) = explode(" ", trim(fgets(STDIN)));
     $d[$e] = $f;
     $d[$f] = $e;
}
$g = trim(fgets(STDIN));
if($g == 1)
{
     if(count($d) > 0)
     {
          $h = max($d);
          print $h . "\n";
          flush();
          $i = trim(fgets(STDIN));
          flush();
          for($x = 0; $x < $a * 2; $x++)
          {
               if($c[$x] == $h)
               {
                    unset($c[$x]);
               }
               if($c[$x] == $i)
               {
                    unset($c[$x]);
               }
          }
          unset($d[$h]);
          unset($d[$i]);
     }
     else
     {
          rsort($c);
          if(count($c) > 0)
          {
               print $c[0] . "\n";
               flush();
               $i = trim(fgets(STDIN));
               flush();
               unset($c[0]);
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] == $i)
                    {
                         unset($c[$x]);
                    }
               }
          }
     }
}
else
{

}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
rsort($c);
$d = array();
for($x = 0; $x < $b; $x++)
{
     list($f, $g) = explode(" ", trim(fgets(STDIN)));
     $d[$f] = $g;
     $d[$g] = $f;
}
$h = trim(fgets(STDIN));
if($h == 1)
{
     for($y = 0; $y < $a; $y++)
     {
          rsort($c);
          if(count($d) > 0)
          {
               $i = max($d);
               print $i . "\n";
               flush();
               $j = trim(fgets(STDIN));
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] = $i)
                    {
                         unset($c[$x]);
                    }
                    if($c[$x] = $j)
                    {
                         unset($c[$x]);
                    }
               }
               unset($d[$i]);
               unset($d[$j]);
          }
          elseif(count($c) > 0)
          {
               print $c[0] . "\n";
               flush();
               $j = trim(fgets(STDIN));
               unset($c[0]);
               for($x = 0; $x < $a * 2; $x++)
               {
                    if($c[$x] = $j)
                    {
                         unset($c[$x]);
                    }
               }
          }
     }
}
else
{

}
?>


"Duel!"Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.There are $$$n$$$ cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly $$$k$$$ consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these $$$n$$$ cards face the same direction after one's move, the one who takes this move will win.Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^5$$$). The second line contains a single string of length $$$n$$$ that only consists of $$$0$$$ and $$$1$$$, representing the situation of these $$$n$$$ cards, where the color side of the $$$i$$$-th card faces up if the $$$i$$$-th character is $$$1$$$, or otherwise, it faces down and the $$$i$$$-th character is $$$0$$$.

Print "once again" (without quotes) if the total number of their moves can exceed $$$10^9$$$, which is considered a draw. In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win. Note that the output characters are case-sensitive, and any wrong spelling would be rejected.

quailty
once again
tokitsukaze
once again

NoteIn the first example, no matter how Tokitsukaze moves, there would be three cards with color sides facing the same direction after her move, and Quailty can flip the last card to this direction and win.In the second example, no matter how Tokitsukaze moves, Quailty can choose the same card and flip back to the initial situation, which can allow the game to end in a draw.In the third example, Tokitsukaze can win by flipping the leftmost five cards up or flipping the rightmost five cards down.The fourth example can be explained in the same way as the second example does.

<?php
#1190C
$start = microtime(1);
[$n, $k] = explode(' ', trim(fgets(STDIN)));
$str = trim(fgets(STDIN));
for ($i = 0; $i < $n; $i++) {
    if ($str[$i] === '0') {
        $firstZero = $firstZero ?? $i;
        $lastZero = $i;
    } else {
        $firstOne = $firstOne ?? $i;
        $lastOne = $i;
    }
}
$deltaZero = $lastZero - $firstZero;
$deltaOne = $lastOne - $firstOne;
if (min($deltaZero, $deltaOne) < $k) {
    echo 'tokitsukaze';
} elseif (max($deltaZero, $deltaOne) > $k) {
    echo 'once again';
} else {
    $amountZero = 0;
    $amountOne = 0;
    for ($i = 0; $i < $n; $i++) {
        if ($str[$i] === '0') {
            $amountZero++;
            $amountOne = 0;
        } else {
            $amountZero = 0;
            $amountOne++;
        }
        if (max($amountZero, $amountOne) >= $k) {
            die('once again');
        }
    }
    echo 'quailty';
}

<?php
#1190E
$start = microtime(1);
[$n, $k] = explode(' ', trim(fgets(STDIN)));
$str = trim(fgets(STDIN));
for ($i = 0; $i < $n; $i++) {
    if ($str[$i] === '0') {
        $firstZero = $firstZero ?? $i;
        $lastZero = $i;
    } else {
        $firstOne = $firstOne ?? $i;
        $lastOne = $i;
    }
}
$deltaZero = $lastZero - $firstZero;
$deltaOne = $lastOne - $firstOne;
$minDelta = min($deltaZero, $deltaOne);
if ($minDelta < $k) {
    echo 'tokitsukaze';
} elseif ($minDelta > $k) {
    echo 'once again';
} else {
    $amountZero = 0;
    $amountOne = 0;
    for ($i = 0; $i < $n; $i++) {
        if ($str[$i] === '0') {
            $amountZero++;
            $amountOne = 0;
        } else {
            $amountOne++;
            $amountZero = 0;
        }
        if (max($amountZero, $amountOne) >= $k) {
            die('once again');
        }
    }
    echo 'quailty';
}

<?php
#1190C
$start = microtime(1);
[$n, $k] = explode(' ', trim(fgets(STDIN)));
$str = trim(fgets(STDIN));
for ($i = 0; $i < $n; $i++) {
    if ($str[$i] === '0') {
        $firstZero = $firstZero ?? $i;
        $lastZero = $i;
    } else {
        $firstOne = $firstOne ?? $i;
        $lastOne = $i;
    }
}
$deltaZero = $lastZero - $firstZero;
$deltaOne = $lastOne - $firstOne;
$minDelta = min($deltaZero, $deltaOne);
if ($minDelta < $k) {
    echo 'tokitsukaze';
} elseif ($minDelta > $k) {
    echo 'once again';
} else {
    $amountZero = 0;
    $amountOne = 0;
    for ($i = 0; $i < $n; $i++) {
        if ($str[$i] === '0') {
            $amountZero++;
            $amountOne = 0;
        } else {
            $amountOne++;
            $amountZero = 0;
        }
        if (min($amountZero, $amountOne) >= $k) {
            die('once again');
        }
    }
    echo 'quailty';
}


Four players participate in the playoff tournament. The tournament is held according to the following scheme: the first player will play with the second, and the third player with the fourth, then the winners of the pairs will play in the finals of the tournament.It is known that in a match between two players, the one whose skill is greater will win. The skill of the $$$i$$$-th player is equal to $$$s_i$$$ and all skill levels are pairwise different (i. e. there are no two identical values in the array $$$s$$$).The tournament is called fair if the two players with the highest skills meet in the finals.Determine whether the given tournament is fair.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. A single line of test case contains four integers $$$s_1, s_2, s_3, s_4$$$ ($$$1 \le s_i \le 100$$$) — skill of the players. It is guaranteed that all the numbers in the array are different.

For each testcase, output YES if the tournament is fair, or NO otherwise.

NoteConsider the example:  in the first test case, players $$$2$$$ and $$$3$$$ with skills $$$7$$$ and $$$9$$$ advance to the finals;  in the second test case, players $$$2$$$ and $$$4$$$ with skills $$$5$$$ and $$$9$$$ advance to the finals. The player with skill $$$6$$$ does not advance, but the player with skill $$$5$$$ advances to the finals, so the tournament is not fair;  in the third test case, players $$$1$$$ and $$$3$$$ with skills $$$5$$$ and $$$8$$$ advance to the finals;  in the fourth test case, players $$$1$$$ and $$$3$$$ with skills $$$6$$$ and $$$3$$$ advance to the finals. The player with skill $$$5$$$ does not advance, but the player with skill $$$3$$$ advances to the finals, so the tournament is not fair.

<?php

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

while($tests--){
    fscanf(STDIN, "%d %d %d %d", $s1, $s2, $s3, $s4);
    $minL = min($s1, $s2);
    $maxL = max($s1, $s2);
    $minR = min($s3, $s4);
    $maxR = max($s3, $s4);
    if($maxL > $minR && $minL < $maxR)
        echo "YES\n";
    else
        echo "NO\n";
}

?>

<?php

$t = (int)trim(fgets(STDIN));

for($i=0;$i<$t;$i++){
    $result = trim(fgets(STDIN));
    list($a,$b,$c,$d) = explode(' ',$result);
    $a = (int)$a;
    $b = (int)$b;
    $c = (int)$c;
    $d = (int)$d;

    $values1 = array($a,$b,$c,$d);
    $values2 = array($a,$b,$c,$d);

    $m1 = max($a,$b);
    $m2 = max($c,$d);

    $res1 = array_diff($values1,[$m1,$m2]);
    $res2 = array_diff($values2,[max($values2)]);
    $res2 = array_diff($res2,[max($res2)]);
    // var_dump($res1,$res2);
    if($res1 == $res2){
        echo "YES".PHP_EOL;
    }else{
        echo "NO".PHP_EOL;
    }
}

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

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

for ($i = 0; $i < $t; $i++) {
  $s = explode(" ", trim(fgets($file)));
  $max1 = max($s[0], $s[1]);
  $max2 = max($s[2], $s[3]);

  $max = max($max1, $max2);
  $min = min($max1, $max2);
  rsort($s);

  if ($s[0] == $max && $s[1] == $min) { echo 'YES'.PHP_EOL; }
  else { echo 'NO'.PHP_EOL; }
}

?>


Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book?

The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$.

Print one integer — the number of days it will take to read the whole book.

NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$.

<?php

function input() {
    return array_map("intval", explode(" ", fgets(STDIN)));
}

[$n] = input();
$a = input();

$r = $days = 0;
for ($i = 0; $i < $n; $i++) {
    if ($a[$i] > $r)
        $r = $a[$i];
    if ($r == $i + 1)
        $days++;
}

echo $days . "\n";