The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1) made of metal with density p1 g/cm3. The second part is an inner disk with radius r2 cm, it is made of metal with density p2 g/cm3. The disk is nested inside the ring.The Olympic jury decided that r1 will take one of possible values of x1, x2, ..., xn. It is up to jury to decide which particular value r1 will take. Similarly, the Olympic jury decided that p1 will take one of possible value of y1, y2, ..., ym, and p2 will take a value from list z1, z2, ..., zk.According to most ancient traditions the ratio between the outer ring mass mout and the inner disk mass min must equal , where A, B are constants taken from ancient books. Now, to start making medals, the jury needs to take values for r1, p1, p2 and calculate the suitable value of r2.The jury wants to choose the value that would maximize radius r2. Help the jury find the sought value of r2. Value r2 doesn't have to be an integer.Medal has a uniform thickness throughout the area, the thickness of the inner disk is the same as the thickness of the outer ring.

The first input line contains an integer n and a sequence of integers x1, x2, ..., xn. The second input line contains an integer m and a sequence of integers y1, y2, ..., ym. The third input line contains an integer k and a sequence of integers z1, z2, ..., zk. The last line contains two integers A and B. All numbers given in the input are positive and do not exceed 5000. Each of the three sequences contains distinct numbers. The numbers in the lines are separated by spaces.

Print a single real number — the sought value r2 with absolute or relative error of at most 10 - 6. It is guaranteed that the solution that meets the problem requirements exists.

NoteIn the first sample the jury should choose the following values: r1 = 3, p1 = 2, p2 = 1.

<?php
$a = max(array_slice(explode(" ", trim(fgets(STDIN))), 1));
$b = max(array_slice(explode(" ", trim(fgets(STDIN))), 1));
$c = min(array_slice(explode(" ", trim(fgets(STDIN))), 1));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = $a * sqrt(($b * $e) / (($b * $e) + ($c * $d)));
$f = number_format($f, 6, ".", "");
print $f;
?>

<?php

error_reporting(0);

solve();

function solve(){

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

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

	$max_x = -1;

	for ($i = 0; $i < $N; $i++)
	{
		$X = (int)$Input->in();
		$max_x = max($max_x, $X);
	}

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

	$max_y = -1;

	for ($i = 0; $i < $M; $i++)
	{
		$Y = (int)$Input->in();
		$max_y = max($max_y, $Y);
	}

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

	$min_z = 5001;

	for ($i = 0; $i < $K; $i++)
	{
		$Z = (int)$Input->in();
		$min_z = min($min_z, $Z);

	}

	$A = (int)$Input->in();
	$B = (int)$Input->in();
	$temp = ($A / $B) * ($min_z / $max_y) + 1;

	print($max_x / sqrt($temp));
}

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

//$stream = fopen( 'input.txt', 'r' );
$stream = STDIN;

// Input data
$data = stream_get_contents( $stream );

$data = str_replace( array( "\r\n", "\n\r", "\r", "\n" ), ' ', $data );

$data = explode( ' ', $data );

$x = array();
$y = array();
$z = array();

$line_counts = array();

$line_counts[0] = (int) $data[0];
$line_counts[1] = (int) $data[ $line_counts[0] + 1 ];
$line_counts[2] = (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 ];

$A =  (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 + $line_counts[2] + 1 ];
$B =  (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 + $line_counts[2] + 2 ];

for( $i = 1; $i <= $line_counts[0]; $i++ ) {
	$x[] = (int) $data[$i];
}

for( $i = $line_counts[0] + 2; $i <= $line_counts[0] + $line_counts[1] + 1; $i++ ) {
	$y[] = (int) $data[$i];
}

for( $i = $line_counts[0] + $line_counts[1] + 3; $i <= $line_counts[0] + $line_counts[1] + $line_counts[2] + 2; $i++ ) {
	$z[] = (int) $data[$i];
}

$r1 = max( $x );
$p1 = max( $y );
$p2 = min( $z );

$r2 = sqrt( 1 / ( ( ( $A / $B ) + ( $p1 / $p2 ) ) / ( ( $p1 * $r1 * $r1 ) / $p2 ) ) );

$r2 = number_format( $r2, 12, '.', '' );

echo $r2;

<?php
$x = explode(' ',trim(fgets(STDIN)),2);
$xa = explode(' ',$x[1]); sort($xa);
$r1 = $xa[count($xa) - 1];

$y = explode(' ',trim(fgets(STDIN)),2);
$ya = explode(' ',$y[1]); sort($ya);
$p1 = $ya[count($ya) - 1];

$z = explode(' ',trim(fgets(STDIN)),2);
$za = explode(' ',$z[1]); sort($za);
$p2 = $za[0];

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

$r2 = sqrt(($p1 * $r1 * $r1) / ($p2 * ($p1 / $p2 + $a / $b)));

print $r2;
?>

<?php

//$stream = fopen( 'input.txt', 'r' );
$stream = STDIN;

// Input data
$data = stream_get_contents( $stream );

$data = str_replace( array( "\r\n", "\n\r", "\r", "\n" ), ' ', $data );

$data = explode( ' ', $data );

$x = array();
$y = array();
$z = array();

$line_counts = array();

$line_counts[0] = (int) $data[0];
$line_counts[1] = (int) $data[ $line_counts[0] + 1 ];
$line_counts[2] = (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 ];

$A =  (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 + $line_counts[2] + 1 ];
$B =  (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 + $line_counts[2] + 2 ];

for( $i = 1; $i <= $line_counts[0]; $i++ ) {
	$x[] = (int) $data[$i];
}

for( $i = $line_counts[0] + 2; $i <= $line_counts[0] + $line_counts[1] + 1; $i++ ) {
	$y[] = (int) $data[$i];
}

for( $i = $line_counts[0] + $line_counts[1] + 2; $i <= $line_counts[0] + $line_counts[1] + $line_counts[2] + 2; $i++ ) {
	$z[] = (int) $data[$i];
}

$r1 = max( $x );
$p1 = max( $y );
$p2 = min( $z );

$r2 = sqrt( 1 / ( ( ( $A / $B ) + ( $p1 / $p2 ) ) / ( ( $p1 * $r1 * $r1 ) / $p2 ) ) );

$r2 = number_format( $r2, 12, '.', '' );

echo $r2;


Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has n rows of keys containing m keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they make lowercase letters uppercase.Vasya can press one or two keys with one hand. However, he can only press two keys if the Euclidean distance between the centers of the keys does not exceed x. The keys are considered as squares with a side equal to 1. There are no empty spaces between neighbouring keys.Vasya is a very lazy boy, that's why he tries to type with one hand as he eats chips with his other one. However, it is possible that some symbol can't be typed with one hand only, because the distance between it and the closest "Shift" key is strictly larger than x. In this case he will have to use his other hand. Having typed the symbol, Vasya returns other hand back to the chips.You are given Vasya's keyboard and the text. Count the minimum number of times Vasya will have to use the other hand.

The first line contains three integers n, m, x (1 ≤ n, m ≤ 30, 1 ≤ x ≤ 50). Next n lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly m keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys are marked with the "S" symbol.  Then follow the length of the text q (1 ≤ q ≤ 5·105). The last line contains the text T, which consists of q symbols, which are uppercase and lowercase Latin letters.

If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes).

3 9 4
qwertyuio
asdfghjkl
SzxcvbnmS
35
TheQuIcKbRoWnFOXjummsovertHeLazYDOG

NoteIn the first sample the symbol "A" is impossible to print as there's no "Shift" key on the keyboard.In the second sample the symbol "e" is impossible to print as there's no such key on the keyboard.In the fourth sample the symbols "T", "G" are impossible to print with one hand. The other letters that are on the keyboard can be printed. Those symbols come up in the text twice, thus, the answer is 2.


You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.

For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.

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

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

    $s = 0;
    if ($n == 1) {
        echo 2 . PHP_EOL;
    } else if ($n >= 2 && $n <= 3) {
        echo 1 . PHP_EOL;
    } else {
        if ($n % 3 == 0) {
            $s =  $n / 3;
        } else {
            $s = ($n / 3) + 1;
        }
        echo (int) $s . PHP_EOL;
    }

}

<?php

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

function readInt() {
  return (int) read() ;
}

function readStrs() {
  return explode(" ",read()) ;
}

function readIntArray() {
  return array_map('intval', readStrs());
}

function readAsArray() {
  return str_split(read()) ;
}

function puts($arg) {
  if($arg === true) print_r("true");
  elseif($arg === false) print_r("false");
  else {
    print_r($arg) ;
  }
  print_r("\n") ;
}
//-----------------------------------//

$t = readInt() ;
while($t--) {
	$a = readInt() ;
	if($a === 1) {
		puts(2) ;
	}
	else puts(ceil($a/3)) ;
}


It's a walking tour day in SIS.Winter, so $$$t$$$ groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P":   "A" corresponds to an angry student  "P" corresponds to a patient student Such string describes the row from the last to the first student.Every minute every angry student throws a snowball at the next student. Formally, if an angry student corresponds to the character with index $$$i$$$ in the string describing a group then they will throw a snowball at the student that corresponds to the character with index $$$i+1$$$ (students are given from the last to the first student). If the target student was not angry yet, they become angry. Even if the first (the rightmost in the string) student is angry, they don't throw a snowball since there is no one in front of them.Let's look at the first example test. The row initially looks like this: PPAP. Then, after a minute the only single angry student will throw a snowball at the student in front of them, and they also become angry: PPAA. After that, no more students will become angry.Your task is to help SIS.Winter teachers to determine the last moment a student becomes angry for every group.

The first line contains a single integer $$$t$$$ — the number of groups of students ($$$1 \le t \le 100$$$). The following $$$2t$$$ lines contain descriptions of groups of students. The description of the group starts with an integer $$$k_i$$$ ($$$1 \le k_i \le 100$$$) — the number of students in the group, followed by a string $$$s_i$$$, consisting of $$$k_i$$$ letters "A" and "P", which describes the $$$i$$$-th group of students.

For every group output single integer — the last moment a student becomes angry.

NoteIn the first test, after $$$1$$$ minute the state of students becomes PPAA. After that, no new angry students will appear.In the second tets, state of students in the first group is:   after $$$1$$$ minute — AAPAAPPAAPPP  after $$$2$$$ minutes — AAAAAAPAAAPP  after $$$3$$$ minutes — AAAAAAAAAAAP  after $$$4$$$ minutes all $$$12$$$ students are angry In the second group after $$$1$$$ minute, all students are angry.

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    list($sStudent) = explode(' ', trim(fgets(STDIN)));
    $sTest = stristr($sStudent,'A');
    $aTest = [];
    $k = 0;
    for ($i = 0; $i < strlen($sTest);$i++){
        if ($sTest[$i] == 'P'){
            $k++;
        } else {
            $aTest[] = $k;
            $k = 0;
        }
    }
    $aTest[] = $k;
    echo max($aTest)."\n";
}

<?php
$a = trim(fgets(STDIN));
for($j = 0; $j < $a; $j++){
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $counter = 0;
    $max = 0;
    $bool = false;
    for($i = 0; $i < $b; $i++){
        if((isset($c[$i-1]) && $c[$i-1] == 'A')){
            $bool = true;
        }
        if($c[$i] == 'P' && $bool){
           $counter++;
           if($max <= $counter){
                $max = $counter;
            }
        } else {
            if($max <= $counter){
                $max = $counter;
            }
            $counter = 0;
            $bool = false;
        }
    }
    echo $max."\n";
}

<?php

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

for ($j=0;$j<$t;$j++)
{
    $x = trim(fgets($handle));
    $a = trim(fgets($handle));
    $cnt=0;$max=0;$check=false;
    for($i=0;$i<$x;$i++)
    {
     if($a[$i]=='A')
     {
         $check=true;
         if($cnt>$max)$max=$cnt;
         $cnt=0;
     }else if($check==true)
     {
         $cnt++;
     }
    }
    if($cnt>$max)$max=$cnt;
    echo $max."\n";

}

?>

<?php
$a = trim(fgets(STDIN));
for($j = 0; $j < $a; $j++){
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $counter = 0;
    $max = 0;
    $bool = false;
    for($i = 0; $i < $b; $i++){
        if((isset($c[$i-1]) && $c[$i-1] == 'A')){
            $bool = true;
        }
        if($c[$i] == 'P' && $bool){
           $counter++;
           if($max <= $counter){
                $max = $counter;
            }
        } else {
            if($max <= $counter){
                $max = $counter;
            }
            $counter = 0;
            $bool = false;
        }
    }
    if($c[$b-1] == 'A'){
        $max = 0;
    }
    echo $max."\n";
}

<?php
$a = trim(fgets(STDIN));
for($j = 0; $j < $a; $j++){
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $counter = 0;
    $max = 0;
    for($i = 0; $i < $b; $i++){
        if($c[$i] == 'P'){
           $counter++;
           if($max <= $counter){
                $max = $counter;
            }
        } else {
            if($max <= $counter){
                $max = $counter;
            }
            $counter = 0;
        }
    }
    if($c[$b-1] == 'A'){
        $max = 0;
    }
    echo $max."\n";
}

<?php
$a = trim(fgets(STDIN));
for($j = 0; $j < $a; $j++){
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $counter = 0;
    $max = 0;
    $bool = false;
    for($i = 0; $i < $b; $i++){
        if($c[$i] == 'A' && !$bool){
            $bool = true;
        } elseif ($c[$i] == 'P' && $bool){
           $counter++;
           if($max <= $counter){
                $max = $counter;
            }
        } elseif ($c[$i] == 'A' && $counter > 0) {
            if($max <= $counter){
                $max = $counter;
            }
            $counter = 0;
            $bool = false;
        }
    }
    echo $max."\n";
}

<?php
$a = trim(fgets(STDIN));
for($j = 0; $j < $a; $j++){
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    for($i = $b-1; $i >= 0; $i--){
        if($c[$i] == 'A'){
            echo $b - ($i+1)."\n";
            break;
        }
    }
}


You are given $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. Find the maximum value of $$$max(a_l, a_{l + 1}, \ldots, a_r) \cdot min(a_l, a_{l + 1}, \ldots, a_r)$$$ over all pairs $$$(l, r)$$$ of integers for which $$$1 \le l < r \le n$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.

For each test case, print a single integer  — the maximum possible value of the product from the statement.

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aInput = explode(' ', trim(fgets(STDIN)));
    $aAnswer = [];
    for ($i = 0; $i < count($aInput) - 1; $i++) {
        $aAnswer[] = $aInput[$i] * $aInput[$i + 1];
    }
    echo max($aAnswer) .  "\n";
}

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
    foreach ($aAllResults as $sRes) {
        IO::line($sRes);
    }
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    $res = [];
    for($i = 0; $i < $n - 1; $i++) {
        $res[] = $a[$i] * $a[$i+1];
    }
    IO::line(max($res));

}

?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aInput = explode(' ', trim(fgets(STDIN)));
    $iMax = max($aInput);
    $aMaxKey = array_keys($aInput, $iMax);
    $iMin = min($aInput);
    $aAnswer = [];
    foreach ($aMaxKey as $sK => $sV) {
        $iMin1 = 0;
        $iMin2 = 0;
        if (isset($aInput[$sV - 1])) {
            $iMin1 = $aInput[$sV - 1];
        }
        if (isset($aInput[$sV + 1])) {
            $iMin2 = $aInput[$sV + 1];
        }
        $aAnswer[] = $iMax * $iMin1;
        $aAnswer[] = $iMax * $iMin2;
    }
    echo max($aAnswer) .  "\n";
}


Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place.

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces.

In the only line print the sought number of teams that got the k-th place in the final results' table.

NoteThe final results' table for the first sample is:   1-3 places — 4 solved problems, the penalty time equals 10  4 place — 3 solved problems, the penalty time equals 20  5-6 places — 2 solved problems, the penalty time equals 1  7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is:  1 place — 5 solved problems, the penalty time equals 3  2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.

<?php
error_reporting(0);

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

	$N = (int)$Scanner->Scan();
	$K = (int)$Scanner->Scan();
	for ($i = 0; $i < $N; $i++) {
		$TEAMS[$i][] = (int)$Scanner->Scan();
		$TEAMS[$i][] = 100 - (int)$Scanner->Scan();
	}

	rsort($TEAMS);

	$num = $TEAMS[$K - 1][0];
	$time = $TEAMS[$K - 1][1];
	$count = 0;
	for ($i = 0; $i < $N; $i++) {
		if ($TEAMS[$i][0] === $num && $TEAMS[$i][1] === $time)$count++;

		if ($count > 0 && ($TEAMS[$i][0] !== $num || $TEAMS[$i][1] !== $time)) break;	}
	print($count);
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

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

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

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

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

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php

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

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

$groups = array();

for($i = 0; $i < $n; $i++) {
    $lines = explode(" ", trim(fgets($stdin)));
    $groups[$i]["tasks"] = $lines[0];
    $groups[$i]["minuses"] = $lines[1];
}

rsort($groups);

for($i = 0; $i < $n; $i++) {
    for($j = $i+1; $j < $n; $j++) {
        if($groups[$j]["tasks"] < $groups[$i]["tasks"])break;

        if($groups[$i]["minuses"] > $groups[$j]["minuses"]) {
            $tmp = $groups[$j];
            $groups[$j] = $groups[$i];
            $groups[$i] = $tmp;
        }
    }
}

//for($i = 0; $i < $n; $i++) {
//    echo $groups[$i]["tasks"]. " " . $groups[$i]["minuses"]."<br>";
//}

$resTasks = $groups[$k-1]["tasks"];
$resMinuses = $groups[$k-1]["minuses"];

$result = 0;
for($i = 0; $i < $n; $i++) {
    if($groups[$i]["tasks"] == $resTasks && $groups[$i]["minuses"] == $resMinuses)
        $result++;
}

echo $result;

//file_put_contents("out.txt", $result);
?>

<?php
error_reporting(0);

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

	$N = (int)$Scanner->Scan();
	$K = (int)$Scanner->Scan();
	for ($i = 0; $i < $N; $i++) {
		$TEAMS[$i][] = (int)$Scanner->Scan();
		$TEAMS[$i][] = 100 - (int)$Scanner->Scan();
	}

	rsort($TEAMS);

	$num = $TEAMS[$K - 1][0];
	$time = $TEAMS[$K - 1][1];
	$count = 0;
	for ($i = 0; $i < $N; $i++) {
		if ($TEAMS[$i][0] === $num && $TEAMS[$i][1] === $time)$count++;

		if ($count > 0 && ($TEAMS[$i][0] !== $num || $TEAMS[$i][1] !== $time)) break;	}
	print($count);
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

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

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

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

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

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>


Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch in the i-th restaurant. If time ti exceeds the time k that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal fi - (ti - k). Otherwise, the Rabbits get exactly fi units of joy.Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.

The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the characteristics of the i-th restaurant.

In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.

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

<?php
error_reporting(0);
class stdIn{var $ntxt = 0;var $nline = 0;var $arr_txt;var $arr_line;var $linex;var $liney;
function stdIn($local = false){if($local){$dir = fopen("input.txt", 'r');}else{$dir = fopen("php://stdin", 'r');}
$datatxt = stream_get_contents($dir);$del = Array("\n","\r","\n\r");$data = explode("\n",$datatxt);	$il = 0;$id = 0;
foreach($data as $line){if(strlen($line) > 0){$line = str_replace($del,'',$line);$dataex[] = $line;$text = explode(" ",$line);
foreach($text as $txt){$arr_txt[] = $txt;$this->linex[$id] = $il;$this->liney[$il] = $id;$id++;}}$il++;}$this->arr_line = $dataex;$this->arr_txt  = $arr_txt;}
function G(){$ret = $this->arr_txt[$this->ntxt++];$this->nline = $this->linex[$this->ntxt];return $ret;}
function GL(){$this->ntxt = $this->liney[$this->nline]+1;return $this->arr_line[$this->nline++];}}
/*init*/ $dxs = new stdIn(false);
// $x = $dxs-> G(); equivalent to cin>>x;
$n=$dxs->G();
$k=$dxs->G();
$max=-10000000000000000000000000000000;
for ($i = 0; $i < $n; $i++) {
	$j=0;
	$f=$dxs->G();
	$t=$dxs->G();
	if($t>$k){$f=$f-($t-$k);}
	//echo $f;
	//echo $max;
	if($f>$max){
		$max=$f;
	}
}
echo $max;
?>

<?// BismiLahi Rahmani Rahim ?>

<?php

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

for ($i = 0; $i < $n; $i ++) {
	fscanf(STDIN, "%d %d", $f, $t);
	if ($t > $k) {
		$max = isset($max) ? max($max, $f - ($t - $k)) : $f - ($t - $k);
	} else {
		$max = isset($max) ? max($max, $f) : $f;
	}
}

printf("%d", $max);

?>


Ashish has $$$n$$$ elements arranged in a line. These elements are represented by two integers $$$a_i$$$ — the value of the element and $$$b_i$$$ — the type of the element (there are only two possible types: $$$0$$$ and $$$1$$$). He wants to sort the elements in non-decreasing values of $$$a_i$$$.He can perform the following operation any number of times:  Select any two elements $$$i$$$ and $$$j$$$ such that $$$b_i \ne b_j$$$ and swap them. That is, he can only swap two elements of different types in one move. Tell him if he can sort the elements in non-decreasing values of $$$a_i$$$ after performing any number of operations.

The first line contains one 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 one integer $$$n$$$ $$$(1 \le n \le 500)$$$ — the size of the arrays. The second line contains $$$n$$$ integers $$$a_i$$$ $$$(1 \le a_i \le 10^5)$$$  — the value of the $$$i$$$-th element. The third line containts $$$n$$$ integers $$$b_i$$$ $$$(b_i \in \{0, 1\})$$$  — the type of the $$$i$$$-th element.

For each test case, print "Yes" or "No" (without quotes) depending on whether it is possible to sort elements in non-decreasing order of their value. You may print each letter in any case (upper or lower).

NoteFor the first case: The elements are already in sorted order.For the second case: Ashish may first swap elements at positions $$$1$$$ and $$$2$$$, then swap elements at positions $$$2$$$ and $$$3$$$.For the third case: The elements are already in sorted order.For the fourth case: No swap operations may be performed as there is no pair of elements $$$i$$$ and $$$j$$$ such that $$$b_i \ne b_j$$$. The elements cannot be sorted.For the fifth case: Ashish may swap elements at positions $$$3$$$ and $$$4$$$, then elements at positions $$$1$$$ and $$$2$$$.

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

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

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

        $Trouble = array() ;

        for($i = 0; $i < $n; $i ++) array_push($Trouble, intval($in[$i])) ;

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

        $has_0 = false ;
        $has_1 = false ;
        for($i = 0; $i < $n; $i ++)
        {
            if($in[$i] == '0') $has_0 = true ;
            else $has_1 = true ;
        }

        if($has_0 && $has_1) echo "Yes\n" ;
        else
        {
            for($i = 1; $i < $n; $i ++) if($Trouble[$i] < $Trouble[$i - 1]) break;

            if($i >= $n) echo "Yes\n" ;
            else echo "No\n" ;
        }
    }
?>

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

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

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

        $Trouble = array() ;

        for($i = 0; $i < $n; $i ++) array_push($Trouble, intval($in[$i])) ;

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

        $has_0 = false ;
        $has_1 = false ;
        for($i = 0; $i < $n; $i ++)
        {
            if($in[$i] == '0') $has_0 = true ;
            else $has_1 = true ;
        }

        if($has_0 && $has_1) echo "Yes\n" ;
        else
        {
            for($i = 1; $i < $n; $i ++) if($Trouble[$i] < $$Trouble[$i - 1]) break;

            if($i >= $n) echo "Yes\n" ;
            else echo "No\n" ;
        }
    }
?>


For the given integer $$$n$$$ ($$$n > 2$$$) let's write down all the strings of length $$$n$$$ which contain $$$n-2$$$ letters 'a' and two letters 'b' in lexicographical (alphabetical) order.Recall that the string $$$s$$$ of length $$$n$$$ is lexicographically less than string $$$t$$$ of length $$$n$$$, if there exists such $$$i$$$ ($$$1 \le i \le n$$$), that $$$s_i < t_i$$$, and for any $$$j$$$ ($$$1 \le j < i$$$) $$$s_j = t_j$$$. The lexicographic comparison of strings is implemented by the operator < in modern programming languages.For example, if $$$n=5$$$ the strings are (the order does matter):  aaabb  aabab  aabba  abaab  ababa  abbaa  baaab  baaba  babaa  bbaaa It is easy to show that such a list of strings will contain exactly $$$\frac{n \cdot (n-1)}{2}$$$ strings.You are given $$$n$$$ ($$$n > 2$$$) and $$$k$$$ ($$$1 \le k \le \frac{n \cdot (n-1)}{2}$$$). Print the $$$k$$$-th string from the list.

The input contains one or more test cases. The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case is written on the the separate line containing two integers $$$n$$$ and $$$k$$$ ($$$3 \le n \le 10^5, 1 \le k \le \min(2\cdot10^9, \frac{n \cdot (n-1)}{2})$$$. The sum of values $$$n$$$ over all test cases in the test doesn't exceed $$$10^5$$$.

For each test case print the $$$k$$$-th string from the list of all described above strings of length $$$n$$$. Strings in the list are sorted lexicographically (alphabetically).

aaabb
aabab
baaba
bbaaa
abb
bab
aaaaabaaaaabaaaaaaaa


There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i > 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.

Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.

NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.

<?
$stdin = fopen('php://stdin', 'r');
ini_set('display_errors', '1');
function read() {
    return trim(fgets(STDIN));
}
$t1 = microtime(true);
$debag = 0;
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
$q = read(); // кол-во запросов
$arr = []; // n и k
$data = []; // числа
$resp = [];
for ($i = 0; $i < $q; $i++) {
    $arr[$i] = explode(" ", read());
    $data[$i] = explode(" ", read());
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

for ($i = 0; $i < $q; $i++) {
    $min = min($data[$i]);
    $max = max($data[$i]);

    if ($min+$arr[$i][1] >= $max-$arr[$i][1]) {
        $resp[$i] = $min+$arr[$i][1];
    } else {
        $resp[$i] = -1;
    }
}
for ($i = 0; $i < $q; $i++) {
    echo $resp[$i]."\n";
}

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
if ($debag === 1) {
    echo '<hr>' . round(microtime(true) - $t1, 3) . ' sec';
}

<?php
    $n = trim(fgets(STDIN));
    $res = array();
    for($i = 0; $i<$n; $i++){
        $a = explode(" ", trim(fgets(STDIN)));
        $b = explode(" ", trim(fgets(STDIN)));
        $max = max($b);
        $min = min($b);
        if($min + $a[1] >= $max - $a[1]){
            $res[] = $min + $a[1];
        } else {
            $res[] = -1;
        }
    }
    foreach($res as $v){
        echo $v."\n";
    }

 ?>

<?php
    $q = trim(fgets(STDIN));
    for ($i = 0; $i < $q; $i++) {
        list($n, $k) = explode(" ", trim(fgets(STDIN)));
        $a = explode(" ", trim(fgets(STDIN)));
        $max = max($a);
        $min = min($a);
        if ($min + $k >= $max - $k) {
            echo $min + $k . "\n";
        } else {
            echo "-1" . "\n";
        }
    }
?>

<?php
    $Q = intval(fgets(STDIN));
    while (0 < $Q--) {
        list($n,$k) = array_map('intval', preg_split('/\s+/', trim(fgets(STDIN))));
        $a = array_map('intval', preg_split('/\s+/', trim(fgets(STDIN))));
        $max = min(array_map(function($ai)use($k){ return $ai+$k; },$a));
        $min = max(array_map(function($ai)use($k){ return $ai-$k; },$a));
        echo $min<=$max ? $max : -1;
        echo "\n";
    }

<?php
    $q = trim(fgets(STDIN));
    for ($i = 0; $i < $q; $i++) {
        list($n, $k) = explode(" ", trim(fgets(STDIN)));
        $a = explode(" ", trim(fgets(STDIN)));
        $u = array_unique($a);
        //print_r($u);
        $max = max($a);
        $min = min($a);
        sort($u);
        $r = '-1';
        $b = [];
        foreach ($u AS $v) {
            if ($max - $v <= $k && $v - $min <= $k) {
                $r = $v;
                $b[] = $v;
            }
        }
        if (isset($b) && count($b) == count($u)) {
            echo $min + $k  . "\n";
        } else {
            echo $r . "\n";
        }
    }
?>

<?php
    $q = trim(fgets(STDIN));
    for ($i = 0; $i < $q; $i++) {
        list($n, $k) = explode(" ", trim(fgets(STDIN)));
        $a = explode(" ", trim(fgets(STDIN)));
        $u = array_unique($a);
        //print_r($u);
        $max = max($a);
        $min = min($a);
        sort($u);
        $r = '-1';
        foreach ($u AS $v) {
            if ($max - $v <= $k && $v - $min <= $k) {
                $r = $v;
            }
        }
        echo $r . "\n";
    }
?>


There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?Formally, we assume that two words denote the same name, if using the replacements "u"  "oo" and "h"  "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.For example, the following pairs of words denote the same name:  "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper"  "kuuper" and "kuooper"  "kuuper".  "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun"  "khoon" and "kkkhoon"  "kkhoon"  "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name.

The first line contains integer number n (2 ≤ n ≤ 400) — number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.

Print the minimal number of groups where the words in each group denote the same name.

10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon

9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi

NoteThere are four groups of words in the first example. Words in each group denote same name:  "mihail", "mikhail"  "oolyana", "ulyana"  "kooooper", "koouper"  "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name:  "hariton", "kkkhariton", "khariton"  "hkariton"  "buoi", "boooi", "boui"  "bui"  "boi" In the third example the words are equal, so they denote the same name.


A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient X — the coefficient of income growth during one year. This coefficient should satisfy the equation:A·Xn = B.Surely, the king is not going to do this job by himself, and demands you to find such number X.It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient X must be integers. The number X may be zero or negative.

The input contains three integers A, B, n (|A|, |B| ≤ 1000, 1 ≤ n ≤ 10).

Output the required integer coefficient X, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.

<?php

$input;
$buffer = Array();
init();

function getNext() {
  global $buffer;
  if( count($buffer) > 0 ) {
    return array_shift($buffer);
  }
  $line = preg_replace('/[\\r\\n]+$/', '', getLine());
  $buffer = preg_split('/\\s+/', $line);
  return getNext();
}

function getLine() {
  global $input;
  return fgets($input, 4096);
}

function init() {
  global $input;
  $input = fopen("php://stdin", "r");
}

function main() {

  $a = intval(getNext());
  $b = intval(getNext());

  $n = intval(getNext());

  $max = abs($b);

  for( $i = -$max; $i <= $max; ++$i ) {
    $cur = $a;
    for( $j = 0; $j < $n; ++ $j ) {
      $cur *= $i;
      if( abs($cur) > $max ) { break; }
    }
    if( $cur == $b ) {
      print $i . "\n";
      return;
    }
  }

  print "No solution\n";

}

main();

?>


You are given the strings $$$a$$$ and $$$b$$$, consisting of lowercase Latin letters. You can do any number of the following operations in any order:   if $$$|a| > 0$$$ (the length of the string $$$a$$$ is greater than zero), delete the first character of the string $$$a$$$, that is, replace $$$a$$$ with $$$a_2 a_3 \ldots a_n$$$;  if $$$|a| > 0$$$, delete the last character of the string $$$a$$$, that is, replace $$$a$$$ with $$$a_1 a_2 \ldots a_{n-1}$$$;  if $$$|b| > 0$$$ (the length of the string $$$b$$$ is greater than zero), delete the first character of the string $$$b$$$, that is, replace $$$b$$$ with $$$b_2 b_3 \ldots b_n$$$;  if $$$|b| > 0$$$, delete the last character of the string $$$b$$$, that is, replace $$$b$$$ with $$$b_1 b_2 \ldots b_{n-1}$$$. Note that after each of the operations, the string $$$a$$$ or $$$b$$$ may become empty.For example, if $$$a=$$$"hello" and $$$b=$$$"icpc", then you can apply the following sequence of operations:   delete the first character of the string $$$a$$$ $$$\Rightarrow$$$ $$$a=$$$"ello" and $$$b=$$$"icpc";  delete the first character of the string $$$b$$$ $$$\Rightarrow$$$ $$$a=$$$"ello" and $$$b=$$$"cpc";  delete the first character of the string $$$b$$$ $$$\Rightarrow$$$ $$$a=$$$"ello" and $$$b=$$$"pc";  delete the last character of the string $$$a$$$ $$$\Rightarrow$$$ $$$a=$$$"ell" and $$$b=$$$"pc";  delete the last character of the string $$$b$$$ $$$\Rightarrow$$$ $$$a=$$$"ell" and $$$b=$$$"p". For the given strings $$$a$$$ and $$$b$$$, find the minimum number of operations for which you can make the strings $$$a$$$ and $$$b$$$ equal. Note that empty strings are also equal.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$). Then $$$t$$$ test cases follow. The first line of each test case contains the string $$$a$$$ ($$$1 \le |a| \le 20$$$), consisting of lowercase Latin letters. The second line of each test case contains the string $$$b$$$ ($$$1 \le |b| \le 20$$$), consisting of lowercase Latin letters.

For each test case, output the minimum number of operations that can make the strings $$$a$$$ and $$$b$$$ equal.

5
a
a
abcd
bc
hello
codeforces
hello
helo
dhjakjsnasjhfksafasd
adjsnasjhfksvdafdser

<?php

# asdasd
# asa sd

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = str_split(IO::str());
    $res = [];
   for ($i = 0; $i < count($a); $i++) {
       for($j = 0; $j < count($b); $j++) {
           $k = $j;
           $len = 0;
           if($a[$i] == $b[$j]) {
               for($x = $i; $x < count($a); $x++) {
                   if(!isset($b[$k])) {
                       break;
                   }
                   if ($a[$x] == $b[$k]) {
                       $len++;
                       $k++;
                   } else {
                       break;
                   }
               }
           }
           $res[$len] = $len;
       }
   }
   $len = max($res);
   $result = (count($a) - $len) + (count($b) - $len);
    IO::line($result);
}

?>

<?php
$t = readline();

for ($i = 0; $i < $t; $i++) {
    $str1 = readline();
    $str2 = readline();
    echo equalizeStrings($str1, $str2) . PHP_EOL;
}

function equalizeStrings($string1, $string2) {
if(strlen($string1) >= strlen($string2)){
    $shortStr = $string2;
    $shortStrLen = strlen($string2);
    $longStr = $string1;
    $longStrLen = strlen($string1);
}
else{
    $shortStr = $string1;
    $shortStrLen = strlen($string1);
    $longStr = $string2;
    $longStrLen = strlen($string2);
}
//----------------------------------------
//echo $longStr."
".$shortStr."

";
//---------------------------------------

$maxSubLen = 0;
for($i = 0; $i < $shortStrLen; $i++){
    $subStr = substr($shortStr, $i, 1);
    if(strpos($longStr, $subStr) !== false){
        $len = 2;
        while(strpos($longStr, $subStr) !== false){
            //
            if($len > $shortStrLen + 1 || ($i-1 + $len) > $shortStrLen)
                break;
            $subStr = substr($shortStr, $i, $len);
            $len++;
        }
        if($len - 2 > $maxSubLen){
            $maxSubLen = $len -2;
        }
    }
    else{
        continue;
    }
}

$res = ($shortStrLen - $maxSubLen) + ($longStrLen - $maxSubLen);
echo $res.PHP_EOL;
}

<?php

function equalizeStrings($str1, $str2) {
    if (strlen($str1) > strlen($str2)) {
        $tmp = $str2;
        $str2 = $str1;
        $str1 = $tmp;
    }

    $str1_len = strlen($str1);
    $str2_len = strlen($str2);

    for ($part_len = $str1_len; $part_len > 0; $part_len--) {
        for ($i = 0; $i <= $str1_len - $part_len; $i++) {
            $part = substr($str1, $i, $part_len);
            if (false !== strpos($str2, $part)) {
                return $str1_len + $str2_len - 2 * $part_len;
            }
        }
    }

    return $str1_len + $str2_len;
}

$t = readline();

for ($i = 0; $i < $t; $i++) {
    $str1 = readline();
    $str2 = readline();
    echo equalizeStrings($str1, $str2) . PHP_EOL;
}

<?php

# asdasd
# asa sd

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = str_split(IO::str());
    $res = [];
   for ($i = 0; $i < count($a); $i++) {
       $len = 0;
       $k = $i;
       $rj = 0;
       for($j = 0; $j < count($b); $j++) {
           if($a[$k] == $b[$j]) {
               if($len == 0) {
                   $rj = $j;
               }
               $len++;
               $k++;
           } else {
               $res[$len] = $len;
               $len = 0;
               $k = $i;
               if ($len > 0) {
                   $j = $rj;
               }
           }
       }
       $res[$len] = $len;
   }
   $len = max($res);
   $result = (count($a) - $len) + (count($b) - $len);
    IO::line($result);
}

?>

<?php

# asdasd
# asa sd

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = str_split(IO::str());
    $res = [];
   for ($i = 0; $i < count($a); $i++) {
       $len = 0;
       $k = $i;
       $rj = 0;
       for($j = 0; $j < count($b); $j++) {
           if($a[$k] == $b[$j]) {
               $len++;
               $k++;
           } else {
               $res[$len] = $len;
               $len = 0;
               $k = $i;
           }
       }
       $res[$len] = $len;
   }
   $len = max($res);
   $result = (count($a) - $len) + (count($b) - $len);
    IO::line($result);
}

?>

<?php

# asdasd
# asa sd

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = str_split(IO::str());
    $res = [];
   for ($i = 0; $i < count($a); $i++) {
       $len = 0;
       $k = $i;
       for($j = 0; $j < count($b); $j++) {
           if($a[$k] == $b[$j]) {
               $len++;
               $k++;
           } elseif ($len > 0) {
               $res[$len] = $len;
               $len = 0;
               $k = $i;
           }
       }
       $res[$len] = $len;
   }
   $len = max($res);
   $result = (count($a) - $len) + (count($b) - $len);
    IO::line($result);

}

?>

<?php

# asdasd
# asa sd

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = str_split(IO::str());
    $res = [];
   for ($i = 0; $i < count($a); $i++) {
       $len = 0;
       $k = $i;
       for($j = 0; $j < count($b); $j++) {
           if($a[$k] == $b[$j]) {
               $len++;
               $k++;
           } elseif ($len > 0) {
               break;
           }
       }
       $res[] = $len;
   }
   $len = max($res);
   $result = (count($a) - $len) + (count($b) - $len);
    IO::line($result);

}

?>


You are given a permutation $$$p_1, p_2, \dots, p_n$$$. A permutation of length $$$n$$$ is a sequence such that each integer between $$$1$$$ and $$$n$$$ occurs exactly once in the sequence.Find the number of pairs of indices $$$(l, r)$$$ ($$$1 \le l \le r \le n$$$) such that the value of the median of $$$p_l, p_{l+1}, \dots, p_r$$$ is exactly the given number $$$m$$$.The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used.For example, if $$$a=[4, 2, 7, 5]$$$ then its median is $$$4$$$ since after sorting the sequence, it will look like $$$[2, 4, 5, 7]$$$ and the left of two middle elements is equal to $$$4$$$. The median of $$$[7, 1, 2, 9, 6]$$$ equals $$$6$$$ since after sorting, the value $$$6$$$ will be in the middle of the sequence.Write a program to find the number of pairs of indices $$$(l, r)$$$ ($$$1 \le l \le r \le n$$$) such that the value of the median of $$$p_l, p_{l+1}, \dots, p_r$$$ is exactly the given number $$$m$$$.

The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2\cdot10^5$$$, $$$1 \le m \le n$$$) — the length of the given sequence and the required value of the median. The second line contains a permutation $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$). Each integer between $$$1$$$ and $$$n$$$ occurs in $$$p$$$ exactly once.

NoteIn the first example, the suitable pairs of indices are: $$$(1, 3)$$$, $$$(2, 2)$$$, $$$(2, 3)$$$ and $$$(2, 4)$$$.


Little X and Little Z are good friends. They always chat online. But both of them have schedules.Little Z has fixed schedule. He always online at any moment of time between a1 and b1, between a2 and b2, ..., between ap and bp (all borders inclusive). But the schedule of Little X is quite strange, it depends on the time when he gets up. If he gets up at time 0, he will be online at any moment of time between c1 and d1, between c2 and d2, ..., between cq and dq (all borders inclusive). But if he gets up at time t, these segments will be shifted by t. They become [ci + t, di + t] (for all i).If at a moment of time, both Little X and Little Z are online simultaneosly, they can chat online happily. You know that Little X can get up at an integer moment of time between l and r (both borders inclusive). Also you know that Little X wants to get up at the moment of time, that is suitable for chatting with Little Z (they must have at least one common moment of time in schedules). How many integer moments of time from the segment [l, r] suit for that?

The first line contains four space-separated integers p, q, l, r (1 ≤  p, q ≤ 50; 0 ≤ l ≤ r ≤ 1000). Each of the next p lines contains two space-separated integers ai, bi (0 ≤ ai < bi ≤ 1000). Each of the next q lines contains two space-separated integers cj, dj (0 ≤ cj < dj ≤ 1000). It's guaranteed that bi < ai + 1 and dj < cj + 1 for all valid i and j.

Output a single integer — the number of moments of time from the segment [l, r] which suit for online conversation.


You are given a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$ and an integer $$$k$$$, such that $$$1 \leq k \leq n$$$. A permutation means that every number from $$$1$$$ to $$$n$$$ is contained in $$$p$$$ exactly once.Let's consider all partitions of this permutation into $$$k$$$ disjoint segments. Formally, a partition is a set of segments $$$\{[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]\}$$$, such that:  $$$1 \leq l_i \leq r_i \leq n$$$ for all $$$1 \leq i \leq k$$$;  For all $$$1 \leq j \leq n$$$ there exists exactly one segment $$$[l_i, r_i]$$$, such that $$$l_i \leq j \leq r_i$$$. Two partitions are different if there exists a segment that lies in one partition but not the other.Let's calculate the partition value, defined as $$$\sum\limits_{i=1}^{k} {\max\limits_{l_i \leq j \leq r_i} {p_j}}$$$, for all possible partitions of the permutation into $$$k$$$ disjoint segments. Find the maximum possible partition value over all such partitions, and the number of partitions with this value. As the second value can be very large, you should find its remainder when divided by $$$998\,244\,353$$$.

The first line contains two integers, $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 200\,000$$$) — the size of the given permutation and the number of segments in a partition. The second line contains $$$n$$$ different integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq n$$$) — the given permutation.

Print two integers — the maximum possible partition value over all partitions of the permutation into $$$k$$$ disjoint segments and the number of such partitions for which the partition value is equal to the maximum possible value, modulo $$$998\,244\,353$$$. Please note that you should only find the second value modulo $$$998\,244\,353$$$.

NoteIn the first test, for $$$k = 2$$$, there exists only two valid partitions: $$$\{[1, 1], [2, 3]\}$$$ and $$$\{[1, 2], [3, 3]\}$$$. For each partition, the partition value is equal to $$$2 + 3 = 5$$$. So, the maximum possible value is $$$5$$$ and the number of partitions is $$$2$$$.In the third test, for $$$k = 3$$$, the partitions with the maximum possible partition value are $$$\{[1, 2], [3, 5], [6, 7]\}$$$, $$$\{[1, 3], [4, 5], [6, 7]\}$$$, $$$\{[1, 4], [5, 5], [6, 7]\}$$$, $$$\{[1, 2], [3, 6], [7, 7]\}$$$, $$$\{[1, 3], [4, 6], [7, 7]\}$$$, $$$\{[1, 4], [5, 6], [7, 7]\}$$$. For all of them, the partition value is equal to $$$7 + 5 + 6 = 18$$$. The partition $$$\{[1, 2], [3, 4], [5, 7]\}$$$, however, has the partition value $$$7 + 3 + 6 = 16$$$. This is not the maximum possible value, so we don't count it.


Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci.Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can.Timofey doesn't like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn't consider the whole tree as a subtree since he can't see the color of the root vertex.A subtree of some vertex is a subgraph containing that vertex and all its descendants.Your task is to determine if there is a vertex, taking which in hands Timofey wouldn't be annoyed.

The first line contains single integer n (2 ≤ n ≤ 105) — the number of vertices in the tree. Each of the next n - 1 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v), denoting there is an edge between vertices u and v. It is guaranteed that the given graph is a tree. The next line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 105), denoting the colors of the vertices.

Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him. Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them.


The statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, $$$n$$$ is always even, and in C2, $$$n$$$ is always odd.You are given a regular polygon with $$$2 \cdot n$$$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $$$1$$$. Let's name it as $$$2n$$$-gon.Your task is to find the square of the minimum size such that you can embed $$$2n$$$-gon in the square. Embedding $$$2n$$$-gon in the square means that you need to place $$$2n$$$-gon in the square in such way that each point which lies inside or on a border of $$$2n$$$-gon should also lie inside or on a border of the square.You can rotate $$$2n$$$-gon and/or the square.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$T$$$ lines contain descriptions of test cases — one per line. Each line contains single odd integer $$$n$$$ ($$$3 \le n \le 199$$$). Don't forget you need to embed $$$2n$$$-gon, not an $$$n$$$-gon.

Print $$$T$$$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $$$2n$$$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

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

        $R = 1 / sin(M_PI / (2 * $n)) ;

        $angle = ($n - 1) * M_PI / $n ;
        $ans = 0.0 ;

        for($i = 2; $i < $n; $i ++)
        {
            $x =  (($i - 1) * M_PI - $angle * ($i - 1)) / 2 ;

            $x = M_PI / 4 - $x ;

            $ans = max($ans, $R * cos($x) ) ;
        }
        echo $ans . "\n" ;
    }
?>

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

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

        $R = 1 / sin(M_PI / (2 * $n)) ;

        $angle = ($n - 1) / $n ;
        $ans = 0.0 ;

        for($i = 2; $i < $n; $i ++)
        {
            $x =  (($i - 1) - $angle * ($i - 1)) / 2 ;

            $x = 0.25 - $x ;

            $ans = max($ans, $R * cos($x * M_PI) ) ;
        }
        echo $ans . "\n" ;
    }
?>


Hands that shed innocent blood!There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li.You are given lengths of the claws. You need to find the total number of alive people after the bell rings.

The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people. Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.

Print one integer — the total number of alive people after the bell rings.

NoteIn first sample the last person kills everyone in front of him.

<?php
  //CF 892B
  fscanf(STDIN, "%d", $n);
  $l = explode(" ", fgets(STDIN));
  $ans = 0;
  $cmp = $n;
  for ($i = $n - 1; $i >= 0; $i--) {
    if ($i < $cmp) $ans++;
    $cmp = min($cmp, $i - intval($l[$i]));
  }
  fprintf(STDOUT, "" . $ans);
?>


Naruto has sneaked into the Orochimaru's lair and is now looking for Sasuke. There are $$$T$$$ rooms there. Every room has a door into it, each door can be described by the number $$$n$$$ of seals on it and their integer energies $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$. All energies $$$a_i$$$ are nonzero and do not exceed $$$100$$$ by absolute value. Also, $$$n$$$ is even.In order to open a door, Naruto must find such $$$n$$$ seals with integer energies $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ that the following equality holds: $$$a_{1} \cdot b_{1} + a_{2} \cdot b_{2} + ... + a_{n} \cdot b_{n} = 0$$$. All $$$b_i$$$ must be nonzero as well as $$$a_i$$$ are, and also must not exceed $$$100$$$ by absolute value. Please find required seals for every room there.

The first line contains the only integer $$$T$$$ ($$$1 \leq T \leq 1000$$$) standing for the number of rooms in the Orochimaru's lair. The other lines contain descriptions of the doors. Each description starts with the line containing the only even integer $$$n$$$ ($$$2 \leq n \leq 100$$$) denoting the number of seals. The following line contains the space separated sequence of nonzero integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$|a_{i}| \leq 100$$$, $$$a_{i} \neq 0$$$) denoting the energies of seals.

For each door print a space separated sequence of nonzero integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$|b_{i}| \leq 100$$$, $$$b_{i} \neq 0$$$) denoting the seals that can open the door. If there are multiple valid answers, print any. It can be proven that at least one answer always exists.

NoteFor the first door Naruto can use energies $$$[-100, 1]$$$. The required equality does indeed hold: $$$1 \cdot (-100) + 100 \cdot 1 = 0$$$.For the second door Naruto can use, for example, energies $$$[1, 1, 1, -1]$$$. The required equality also holds: $$$1 \cdot 1 + 2 \cdot 1 + 3 \cdot 1 + 6 \cdot (-1) = 0$$$.


There is a robot staying at $$$X=0$$$ on the $$$Ox$$$ axis. He has to walk to $$$X=n$$$. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel.The $$$i$$$-th segment of the path (from $$$X=i-1$$$ to $$$X=i$$$) can be exposed to sunlight or not. The array $$$s$$$ denotes which segments are exposed to sunlight: if segment $$$i$$$ is exposed, then $$$s_i = 1$$$, otherwise $$$s_i = 0$$$.The robot has one battery of capacity $$$b$$$ and one accumulator of capacity $$$a$$$. For each segment, you should choose which type of energy storage robot will use to go to the next point (it can be either battery or accumulator). If the robot goes using the battery, the current charge of the battery is decreased by one (the robot can't use the battery if its charge is zero). And if the robot goes using the accumulator, the current charge of the accumulator is decreased by one (and the robot also can't use the accumulator if its charge is zero).If the current segment is exposed to sunlight and the robot goes through it using the battery, the charge of the accumulator increases by one (of course, its charge can't become higher than it's maximum capacity).If accumulator is used to pass some segment, its charge decreases by 1 no matter if the segment is exposed or not.You understand that it is not always possible to walk to $$$X=n$$$. You want your robot to go as far as possible. Find the maximum number of segments of distance the robot can pass if you control him optimally.

The first line of the input contains three integers $$$n, b, a$$$ ($$$1 \le n, b, a \le 2 \cdot 10^5$$$) — the robot's destination point, the battery capacity and the accumulator capacity, respectively. The second line of the input contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$0 \le s_i \le 1$$$), where $$$s_i$$$ is $$$1$$$ if the $$$i$$$-th segment of distance is exposed to sunlight, and $$$0$$$ otherwise.

Print one integer — the maximum number of segments the robot can pass if you control him optimally.

NoteIn the first example the robot can go through the first segment using the accumulator, and charge levels become $$$b=2$$$ and $$$a=0$$$. The second segment can be passed using the battery, and charge levels become $$$b=1$$$ and $$$a=1$$$. The third segment can be passed using the accumulator, and charge levels become $$$b=1$$$ and $$$a=0$$$. The fourth segment can be passed using the battery, and charge levels become $$$b=0$$$ and $$$a=1$$$. And the fifth segment can be passed using the accumulator.In the second example the robot can go through the maximum number of segments using battery two times and accumulator one time in any order.

<?php
# 1154D
$input = fopen('php://stdin', 'rb');
[$stepsCount, $batteryCharge, $accumChargeMax] = explode(' ', fgets($input));
$resultSteps = 0;
$accumCharge = (int)$accumChargeMax;
for ($i = 0; $i < $stepsCount; $i++) {
    if ($accumCharge === 0 && $batteryCharge === 0) {
        break;
    }
    $shining = fgetc($input) === '1';
    fgetc($input);
    if ($shining) {
        if ($accumCharge < $accumChargeMax && $batteryCharge > 0) {
            $accumCharge++;
            $batteryCharge--;
        } else {
            $accumCharge--;
        }
    } elseif($accumCharge > 0) {
        $accumCharge--;
    } else {
        $batteryCharge--;
    }
    $resultSteps++;
}
echo $resultSteps;

<?php
# 1154D
$input = fopen('php://stdin', 'rb');
[$stepsCount, $batteryCharge, $accumChargeMax] = explode(' ', fgets($input));
$resultSteps = 0;
$accumCharge = (int)$accumChargeMax;
for ($i = 0; $i < $stepsCount; $i++) {
    #echo "Battery: {$batteryCharge}, Accum: {$accumCharge}" . PHP_EOL;
    if ($accumCharge === 0 && $batteryCharge === 0) {
        echo $resultSteps;
        break;
    }
    $shining = (bool)fgetc($input);
    fgetc($input);
    if ($shining) {
        if ($accumCharge < $accumChargeMax && $batteryCharge > 0) {
            $accumCharge++;
            $batteryCharge--;
        } else {
            $accumCharge--;
        }
    } elseif($accumCharge > 0) {
        $accumCharge--;
    } else {
        $batteryCharge--;
    }
    $resultSteps++;
}

<?php
# 1154D
$input = fopen('php://stdin', 'rb');
[$stepsCount, $batteryCharge, $accumChargeMax] = explode(' ', fgets($input));
$resultSteps = 0;
$accumCharge = (int)$accumChargeMax;
for ($i = 0; $i < $stepsCount; $i++) {
    $shining = fgetc($input) === '1';
    fgetc($input);
    if ($shining) {
        if ($accumCharge < $accumChargeMax && $batteryCharge > 0) {
            $accumCharge++;
            $batteryCharge--;
        } else {
            $accumCharge--;
        }
    } elseif($accumCharge > 0) {
        $accumCharge--;
    } else {
        $batteryCharge--;
    }
    $resultSteps++;
    if ($accumCharge === 0 && $batteryCharge === 0) {
        echo $resultSteps;
        break;
    }
}


There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one.  At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.

The first line of the input contains integer n (3 ≤ n ≤ 1000). The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.

Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.

NoteThe first test sample is the one in the picture.

<?php
// Is local test?
$LOCALTEST = false;

// Retrieve input
if ($LOCALTEST) {
	$stdin = fopen('test.txt', 'r');
} else {
	$stdin = fopen('php://stdin', 'r');
}
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Contest 180 Div 2 Problem A
$raw = g();
$n = $raw[0];
$raw = g();
for ($i = 0; $i < $n; $i++) {
	$chr[$i] = substr($raw[0], $i, 1);
}

$met = false;
$start = 0;
$end = 0;
for ($i = 0; $i < $n; $i++) {
	if (($met !== false) && ($chr[$i] != $met) && (($start == 0) || ($end == 0))) {
		if ($met == "L") {$start = $i;} else {$end = $i+1;}
	}
	if (($met === false) && ($chr[$i] != ".")) {
		$met = $chr[$i];
		if ($met == "R") {$start = $i+1;} else {$end = $i;}
	}
}

echo $start . " " . $end;

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

<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;
$steps = $arr[1];
//$steps = '..LL...';
$left = strpos($steps, 'L');
$right = strpos($steps, 'R');

if($left && $right){
    $right++;
}

if($left == false){
    $left = strlen($steps) - strpos(strrev($steps), 'R') + 1;
    $right++;
}
if($right == false){
    $right = strlen($steps) - strpos(strrev($steps), 'L');
}
echo $right, ' ', $left;

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;
$steps = $arr[1];
//$steps = '.RRRLLLLL..';
$left = strpos($steps, 'L');
$right = strpos($steps, 'R');

if($left && $right){
    $right++;
}

if($left == false){
    $left = strlen($steps) - strpos(strrev($steps), 'R') + 1;
}
if($right == false){
    $right = strlen($steps) - strpos(strrev($steps), 'L');
}
echo $right, ' ', $left;

<?php
$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;
$steps = $arr[1];
//$steps = '..RRLL...';
$left = strpos($steps, 'L');
$right = strpos($steps, 'R');

if($left && $right){
    $right++;
}

if($left == false){
    $left = strlen($steps) - strpos(strrev($steps), 'R') + 1;
}
if($right == false){
    $right = strlen($steps) - strpos(strrev($steps), 'L');
}
echo $right, ' ', $left;


One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite! Independent researchers confirmed that the nervous system of a zombie is highly complicated – it consists of n brains (much like a cow has several stomachs). They are interconnected by brain connectors, which are veins capable of transmitting thoughts between brains. There are two important properties such a brain network should have to function properly:   It should be possible to exchange thoughts between any two pairs of brains (perhaps indirectly, through other brains).  There should be no redundant brain connectors, that is, removing any brain connector would make property 1 false. If both properties are satisfied, we say that the nervous system is valid. Unfortunately (?), if the system is not valid, the zombie stops thinking and becomes (even more) dead. Your task is to analyze a given nervous system of a zombie and find out whether it is valid.

The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 1000) denoting the number of brains (which are conveniently numbered from 1 to n) and the number of brain connectors in the nervous system, respectively. In the next m lines, descriptions of brain connectors follow. Every connector is given as a pair of brains a b it connects (1 ≤ a, b ≤ n, a ≠ b).

The output consists of one line, containing either yes or no depending on whether the nervous system is valid.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
if($a - 1 != $b)
{
     print "no";
}
else
{
     $c = range(1, $a);
     $d = array();
     $e = 0;
     for($x = 1; $x <= $b; $x++)
     {
          list($f, $g) = explode(" ", trim(fgets(STDIN)));
          $d[$e] = $f;
          $e++;
          $d[$e] = $g;
          $e++;
     }
     $d = array_unique($d);
     sort($d);
     $e = array_diff($c, $d);
     if(count($e) == 0)
     {
          print "yes";
     }
     else
     {
          print "no";
     }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
if($a - 1 != $b)
{
     print "no";
}
else
{
     $c = range(1, $a);
     $d = array();
     $e = 0;
     for($x = 1; $x <= $b; $x++)
     {
          list($f, $g) = explode(" ", trim(fgets(STDIN)));
          $d[$e] = $f;
          $e++;
          $d[$e] = $g;
          $e++;
     }
     $d = array_unique($d);
     sort($d);
     $e = array_diff($d, $c);
     if(count($e) == 0)
     {
          print "yes";
     }
     else
     {
          print "no";
     }
}
?>


The Bitlandians are quite weird people. They have very peculiar customs.As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work.The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. has got n eggs. G. named his price for painting each egg. Similarly, A. named his price for painting each egg. It turns out that for each egg the sum of the money both A. and G. want for the painting equals 1000.Uncle J. wants to distribute the eggs between the children so as to give each egg to exactly one child. Also, Uncle J. wants the total money paid to A. to be different from the total money paid to G. by no more than 500.Help Uncle J. Find the required distribution of eggs or otherwise say that distributing the eggs in the required manner is impossible.

The first line contains integer n (1 ≤ n ≤ 106) — the number of eggs. Next n lines contain two integers ai and gi each (0 ≤ ai, gi ≤ 1000; ai + gi = 1000): ai is the price said by A. for the i-th egg and gi is the price said by G. for the i-th egg.

If it is impossible to assign the painting, print "-1" (without quotes). Otherwise print a string, consisting of n letters "G" and "A". The i-th letter of this string should represent the child who will get the i-th egg in the required distribution. Letter "A" represents A. and letter "G" represents G. If we denote the money Uncle J. must pay A. for the painting as Sa, and the money Uncle J. must pay G. for the painting as Sg, then this inequality must hold: |Sa  -  Sg|  ≤  500.  If there are several solutions, you are allowed to print any of them.


Vasya is a Greencode wildlife preservation society proponent. One day he found an empty field nobody owned, divided it into n × m squares and decided to plant a forest there. Vasya will plant nm trees of all different heights from 1 to nm. For his forest to look more natural he wants any two trees growing in the side neighbouring squares to have the absolute value of difference in heights to be strictly more than 1. Help Vasya: make the plan of the forest planting for which this condition is fulfilled.

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns on Vasya's field

If there's no solution, print -1. Otherwise, print n lines containing m numbers each — the trees' planting plan. In every square of the plan the height of a tree that should be planted on this square should be written. If there are several solutions to that problem, print any of them.


Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk).The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.  Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!

The first line of the input contains fix integers n, m, x, y, z, p (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105). Each of the following p lines contains two integers xk, yk (1 ≤ xk ≤ n; 1 ≤ yk ≤ m) — the initial coordinates of the k-th candy. Two candies can lie on the same cell.

For each of the p candies, print on a single line its space-separated new coordinates.

NoteJust for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:QWER      REWQ ASDF  ->  FDSAZXCV      VCXZ


Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare. Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.

The first line contain integer t (1 ≤ t ≤ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 ≤ n ≤ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.

Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.

3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel

2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees

NoteIt is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.


You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations:  Write parity(a) to the end of a. For example, .  Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.

The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.

Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.

NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110

<?php
// Is local test?
$LOCALTEST = false;

// Retrieve input
if ($LOCALTEST) {
	$stdin = fopen('test.txt', 'r');
} else {
	$stdin = fopen('php://stdin', 'r');
}
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Contest 180 Div 2 Problem C
$raw = g();
$s = $raw[0];
for ($i = 0; $i < strlen($s); $i++) {
	$temp = substr($s, $i, 1);
	if ($temp == "1") {$start++;}
}

$raw = g();
$s = $raw[0];
for ($i = 0; $i < strlen($s); $i++) {
	$temp = substr($s, $i, 1);
	if ($temp == "1") {$end++;}
}

if ($start % 2 == 1) {$start++;}
if ($start >= $end) {echo "YES";} else {echo "NO";}

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


There are $$$n$$$ pillars aligned in a row and numbered from $$$1$$$ to $$$n$$$.Initially each pillar contains exactly one disk. The $$$i$$$-th pillar contains a disk having radius $$$a_i$$$.You can move these disks from one pillar to another. You can take a disk from pillar $$$i$$$ and place it on top of pillar $$$j$$$ if all these conditions are met:  there is no other pillar between pillars $$$i$$$ and $$$j$$$. Formally, it means that $$$|i - j| = 1$$$;  pillar $$$i$$$ contains exactly one disk;  either pillar $$$j$$$ contains no disks, or the topmost disk on pillar $$$j$$$ has radius strictly greater than the radius of the disk you move. When you place a disk on a pillar that already has some disks on it, you put the new disk on top of previously placed disks, so the new disk will be used to check the third condition if you try to place another disk on the same pillar.You may take any disk and place it on other pillar any number of times, provided that every time you do it, all three aforementioned conditions are met. Now you wonder, is it possible to place all $$$n$$$ disks on the same pillar simultaneously?

The first line contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of pillars. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_i$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the radius of the disk initially placed on the $$$i$$$-th pillar. All numbers $$$a_i$$$ are distinct.

Print YES if it is possible to place all the disks on the same pillar simultaneously, and NO otherwise. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).

NoteIn the first case it is possible to place all disks on pillar $$$3$$$ using the following sequence of actions:  take the disk with radius $$$3$$$ from pillar $$$2$$$ and place it on top of pillar $$$3$$$;  take the disk with radius $$$1$$$ from pillar $$$1$$$ and place it on top of pillar $$$2$$$;  take the disk with radius $$$2$$$ from pillar $$$4$$$ and place it on top of pillar $$$3$$$;  take the disk with radius $$$1$$$ from pillar $$$2$$$ and place it on top of pillar $$$3$$$.

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));
$iMax = max($aArray);
$iMaxIndex = array_keys($aArray, max($aArray));
$bFlag = true;
for($i = $iMaxIndex[0]; $i < count($aArray) - 1; $i++){
    if($aArray[$i] < $aArray[$i + 1]){
        $bFlag = false;
    }
}
for ($i = $iMaxIndex[0]; $i >= 1; $i--){
    if($aArray[$i - 1] >= $aArray[$i]){
        $bFlag = false;
    }
}

if($bFlag){
    echo "YES"."\n";
} else {
    echo "NO" . "\n";
}

<?php
$start = microtime(1);
$n = trim(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));
$maxV = max($a);
$maxI = array_search($maxV, $a, true);
for ($i = 0; $i < $maxI; $i++) {
    if ($a[$i] >= $a[$i + 1]) {
        die('NO');
    }
}
for ($i = $n - 1; $i > $maxI; $i--) {
    if ($a[$i] >= $a[$i - 1]) {
        die('NO');
    }
}
echo 'YES';

<?php
    $n = trim(fgets(STDIN));
    $m = explode(" ", trim(fgets(STDIN)));
    $max = max($m);
    $key = array_search($max, $m);
    for($i = $key; $i >= 1; $i--){
        if($m[$i] <= $m[$i - 1]){
            echo 'NO';
            exit;
        }
    }
    $key = array_search($max, $m);
    for($j = $key; $j < $n-1; $j++){
        if($m[$j] < $m[$j + 1]){
            echo 'NO';
            exit;
        }
    }
    echo 'YES';

 ?>