You are given an array $$$A$$$ of length $$$N$$$ weights of masses $$$A_1$$$, $$$A_2$$$...$$$A_N$$$. No two weights have the same mass. You can put every weight on one side of the balance (left or right). You don't have to put weights in order $$$A_1$$$,...,$$$A_N$$$. There is also a string $$$S$$$ consisting of characters "L" and "R", meaning that after putting the $$$i-th$$$ weight (not $$$A_i$$$, but $$$i-th$$$ weight of your choice) left or right side of the balance should be heavier. Find the order of putting the weights on the balance such that rules of string $$$S$$$ are satisfied.

The first line contains one integer $$$N$$$ ($$$1 \leq N \leq 2*10^5$$$) - the length of the array $$$A$$$ The second line contains $$$N$$$ distinct integers: $$$A_1$$$, $$$A_2$$$,...,$$$A_N$$$ ($$$1 \leq A_i \leq 10^9$$$) - the weights given The third line contains string $$$S$$$ of length $$$N$$$ consisting only of letters "L" and "R" - string determining which side of the balance should be heavier after putting the $$$i-th$$$ weight of your choice

The output contains $$$N$$$ lines. In every line, you should print one integer and one letter - integer representing the weight you are putting on the balance in that move and the letter representing the side of the balance where you are putting the weight. If there is no solution, print $$$-1$$$.

NoteExplanation for the test case:  after the 1st weight: 3 L (left side is heavier)after the 2nd weight: 2 R (left side is heavier)after the 3rd weight: 8 R (right side is heavier)after the 4th weight: 13 L (left side is heavier)after the 5th weight: 7 L (left side is heavier)So, the rules given by string $$$S$$$ are fulfilled and our order of putting the weights is correct.

<?php

$result=[];
$filename=!empty($_GET['input'])?fopen("input.txt", 'r'):STDIN;
$N=trim(fgets($filename));
$weight=explode(' ', trim(fgets($filename)));
$string=trim(fgets($filename));
//фейк инициализация
/*
$N=100000;
$last=1;
for ($i=0;$i<$N;$i++) {
	$weight[$i]=mt_rand($last,$last+10000);
	$last=$weight[$i];
	$newString[]=mt_rand(0,1)?"L":"R";
}
$string=implode('',$newString);
*/
sort($weight);
$x=0;
for ($i=0;$i<$N-1;$i++) {
	if ($string[$i]!=$string[$i+1]) {
		$x+=1;
	}
}
$l=count($weight)-1-$x;
$r=$l;
$lPointer=$string[0];
$rPointer=$string[0];
$result[$weight[$l]]=$string[0];
$sum=['L' => 0,'R' => 0];
$sum[$string[0]]=$weight[$l];
for ($i=1;$i<strlen($string);$i++) {
	$link=$string[$i]==$string[$i-1]?--$l:++$r;

	if ($string[$i]==$string[$i-1]) {
		$pointer=&$lPointer;
	} else {
		$pointer=&$rPointer;
	}
	$pointer=$pointer=='L'?'R':'L';
	$result[$weight[$link]]=$pointer;
	$sum[$pointer]+=$weight[$link];
	//var_dump($sum);
	/*if ($sum[$string[$i]]<=$sum[$string[$i]=='L'?'R':'L']) {
		echo -1;
		die;
	}*/
}
foreach ($result as $key => $value) {
	echo $key." ".$value."\n";
}
?>

<?php

function find($l,$r) {
	global $cond,$value,$assocCities,$indexNow;
	if ($l==$r) {
		return $l;
	}
	$mid=floor(($l+$r)/2);
	if ($assocCities[$indexNow][$mid]==$value) {
		return $mid;
	}
	//$cond - ищем правую границу
	if (!$cond xor $assocCities[$indexNow][$mid]>$value) {
		return find($l,$mid-1);
	} else {
		return find($mid+1,$r);
	}
}

function checkIndex($index) {
	global $checked,$query,$assocCities,$cities,$circleSize,$count,$indexNow;
	if (isset($assocCities[$index]) && !isset($checked[$index])) {
		$cityCount=0;
		if (count($assocCities[$index])==1) {
			$l=$r=0;
		} else {
			$indexNow=$index;
			$value=$query[0];
			$cond=false;
			$l=find(0,count($assocCities[$indexNow])-1);
			$value=$query[1];
			$cond=true;
			$r=find(0,count($assocCities[$indexNow])-1);
		}
		if ($assocCities[$index][$l]>=$query[0] && $assocCities[$index][$r]<=$query[1]) {
			$cityCount=$r-$l+1;
		}
		$count+=$cityCount;
		return $cityCount>0;
	}
	return false;
}

function rec($index) {
	global $checked,$query,$assocCities,$cities,$circleSize;
	if (checkIndex($index)) {
		$checked[$index]=true;
		rec(($index+$query[2])%$circleSize);
		rec(($index-$query[2]+$circleSize)%$circleSize);
	}
}

$result=[];
$filename=!empty($_GET['input'])?fopen("input.txt", 'r'):STDIN;
[$N, $Q]=explode(' ',trim(fgets($filename)));
$cities=explode(' ', trim(fgets($filename)));
for ($i=0;$i<count($cities);$i++) {
	$assocCities[$cities[$i]][]=$i;
}
$circleSize=pow(10,9)+7;

for ($i=0;$i<$Q;$i++) {
	$query=explode(' ',trim(fgets($filename)));
	$query[0]--;
	$query[1]--;
	if ($query[0]>$query[1]) {
		var_dump($query);
		die();
	}
	$count=0;
	$checked=[];
	rec($cities[$query[0]]);
	echo ($count==$query[1]-$query[0]+1?'Yes':'No')."\n";
}
?>

<?php

$result=[];
$filename=!empty($_GET['input'])?fopen("input.txt", 'r'):STDIN;
$N=trim(fgets($filename));
$weight=explode(' ', trim(fgets($filename)));
$string=trim(fgets($filename));
//фейк инициализация
/*
$N=100000;
$last=1;
for ($i=0;$i<$N;$i++) {
	$weight[$i]=mt_rand($last,$last+10000);
	$last=$weight[$i];
	$newString[]=mt_rand(0,1)?"L":"R";
}
$string=implode('',$newString);
*/
sort($weight);
$x=0;
for ($i=0;$i<$N-1;$i++) {
	if ($string[$i]!=$string[$i+1]) {
		$x+=1;
	}
}
$l=count($weight)-1-$x;
$r=$l;
$lPointer='L';
$rPointer='L';
$result[$weight[$l]]=$string[0];
$sum=['L' => 0,'R' => 0];
$sum[$string[0]]=$weight[$l];
for ($i=1;$i<strlen($string);$i++) {
	$link=$string[$i]==$string[$i-1]?--$l:++$r;

	if ($string[$i]==$string[$i-1]) {
		$pointer=&$lPointer;
	} else {
		$pointer=&$rPointer;
	}
	$pointer=$pointer=='L'?'R':'L';
	$result[$weight[$link]]=$pointer;
	$sum[$pointer]+=$weight[$link];
	//var_dump($sum);
	/*if ($sum[$string[$i]]<=$sum[$string[$i]=='L'?'R':'L']) {
		echo -1;
		die;
	}*/
}
foreach ($result as $key => $value) {
	echo $key." ".$value."\n";
}
?>

<?php

$result=[];
$filename=!empty($_GET['input'])?fopen("input.txt", 'r'):STDIN;
$N=trim(fgets($filename));
$weight=explode(' ', trim(fgets($filename)));
$string=trim(fgets($filename));
//фейк инициализация
/*
$N=100000;
$last=1;
for ($i=0;$i<$N;$i++) {
	$weight[$i]=mt_rand($last,$last+10000);
	$last=$weight[$i];
	$newString[]=mt_rand(0,1)?"L":"R";
}
$string=implode('',$newString);
*/
sort($weight);
$x=0;
for ($i=0;$i<$N-1;$i++) {
	if ($string[$i]!=$string[$i+1]) {
		$x+=1;
	}
}
$l=count($weight)-1-$x;
$r=$l;
$lPointer='L';
$rPointer='L';
$result[$weight[$l]]=$string[0];
$sum=['L' => 0,'R' => 0];
$sum[$string[0]]=$weight[$l];
for ($i=1;$i<strlen($string);$i++) {
	$link=$string[$i]==$string[$i-1]?--$l:++$r;

	if ($string[$i]==$string[$i-1]) {
		$pointer=&$lPointer;
	} else {
		$pointer=&$rPointer;
	}
	$pointer=$pointer=='L'?'R':'L';
	$result[$weight[$link]]=$pointer;
	$sum[$pointer]+=$weight[$link];
	//var_dump($sum);
	if ($sum[$string[$i]]<=$sum[$string[$i]=='L'?'R':'L']) {
		echo -1;
		die;
	}
}
foreach ($result as $key => $value) {
	echo $key." ".$value."\n";
}
?>

<?php

function checkFunc($l,$r,$cond) {
	if ($cond=='L') {
		return $l>$r;
	} else {
		return $r>$l;
	}
}

function rec($index) {
	global $l,$r,$unused,$string,$weight,$result;
	if ($index==strlen($string)) {
		foreach ($result as $key => $value) {
			echo $key." ".$value?"R":"L"."\n";
		}
		die();
	}
	foreach ($unused as $i => $v) {
		if (checkFunc($l+$weight[$i],$r,$string[$index])) {
			$l=$l+$weight[$i];
			unset($unused[$i]);
			$result[$weight[$i]]=false;
			rec($index+1);
			$unused[$i]=true;
			unset($result[$weight[$i]]);
			$l=$l-$weight[$i];
		}
		if (checkFunc($l,$r+$weight[$i],$string[$index])) {
			$r=$r+$weight[$i];
			unset($unused[$i]);
			$result[$weight[$i]]=true;
			rec($index+1);
			$unused[$i]=true;
			unset($result[$weight[$i]]);
			$r=$r-$weight[$i];
		}
	}
}

$result=[];
$filename=!empty($_GET['input'])?fopen("input.txt", 'r'):STDIN;
$N=trim(fgets($filename));
$weight=explode(' ', trim(fgets($filename)));
$string=trim(fgets($filename));
$l=0;
$r=0;
$unused=[];
for ($i=0;$i<count($weight);$i++) {
	$weight[$i]=(int)$weight[$i];
	$unused[$i]=true;
}
rec(0);
echo -1;
?>

<?php

function checkFunc($l,$r,$cond) {
	if ($cond=='L') {
		return $l>$r;
	} else {
		return $r>$l;
	}
}

function rec($index) {
	global $l,$r,$unused,$string,$weight,$result;
	if ($index==strlen($string)) {
		foreach ($result as $key => $value) {
			echo $key." ".$value."\n";
		}
		die();
	}
	foreach ($unused as $i => $v) {
		if (checkFunc($l+$weight[$i],$r,$string[$index])) {
			$l=$l+$weight[$i];
			unset($unused[$i]);
			$result[$weight[$i]]='L';
			rec($index+1);
			$unused[$i]=true;
			unset($result[$weight[$i]]);
			$l=$l-$weight[$i];
		}
		if (checkFunc($l,$r+$weight[$i],$string[$index])) {
			$r=$r+$weight[$i];
			unset($unused[$i]);
			$result[$weight[$i]]='R';
			rec($index+1);
			$unused[$i]=true;
			unset($result[$weight[$i]]);
			$r=$r-$weight[$i];
		}
	}
}

$result=[];
$filename=!empty($_GET['input'])?fopen("input.txt", 'r'):STDIN;
$N=trim(fgets($filename));
$weight=explode(' ', trim(fgets($filename)));
if ($N>10) {
	die();
}
$string=trim(fgets($filename));
$l=0;
$r=0;
$unused=[];
for ($i=0;$i<count($weight);$i++) {
	$weight[$i]=(int)$weight[$i];
	$unused[$i]=true;
}
rec(0);
echo -1;
?>


Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula .The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.

The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen. Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109). Some positions may coincide.

Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.

NoteIn the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and  for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.


The string $$$s$$$ is given, the string length is odd number. The string consists of lowercase letters of the Latin alphabet.As long as the string length is greater than $$$1$$$, the following operation can be performed on it: select any two adjacent letters in the string $$$s$$$ and delete them from the string. For example, from the string "lemma" in one operation, you can get any of the four strings: "mma", "lma", "lea" or "lem" In particular, in one operation, the length of the string reduces by $$$2$$$.Formally, let the string $$$s$$$ have the form $$$s=s_1s_2 \dots s_n$$$ ($$$n>1$$$). During one operation, you choose an arbitrary index $$$i$$$ ($$$1 \le i < n$$$) and replace $$$s=s_1s_2 \dots s_{i-1}s_{i+2} \dots s_n$$$.For the given string $$$s$$$ and the letter $$$c$$$, determine whether it is possible to make such a sequence of operations that in the end the equality $$$s=c$$$ will be true? In other words, is there such a sequence of operations that the process will end with a string of length $$$1$$$, which consists of the letter $$$c$$$?

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of input test cases. The descriptions of the $$$t$$$ cases follow. Each test case is represented by two lines:   string $$$s$$$, which has an odd length from $$$1$$$ to $$$49$$$ inclusive and consists of lowercase letters of the Latin alphabet;  is a string containing one letter $$$c$$$, where $$$c$$$ is a lowercase letter of the Latin alphabet.

For each test case in a separate line output:  YES, if the string $$$s$$$ can be converted so that $$$s=c$$$ is true; NO otherwise.  You can output YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive response).

5

abcde

c

abcde

b

x

y

aaaaaaaaaaaaaaa

a

contest

t

NoteIn the first test case, $$$s$$$="abcde". You need to get $$$s$$$="c". For the first operation, delete the first two letters, we get $$$s$$$="cde". In the second operation, we delete the last two letters, so we get the expected value of $$$s$$$="c".In the third test case, $$$s$$$="x", it is required to get $$$s$$$="y". Obviously, this cannot be done.

<?php
$RES = array();
$t = (int)fgets(STDIN);
while($t--)
{
	$offset = 0;
	$s = trim(fgets(STDIN));
	$c = trim(fgets(STDIN));
	$FLAG = false;
	while(true)
	{
		$pos = strpos($s, $c, $offset);
		if($pos === FALSE)
			break;
		$offset = $pos + 1;
		if($pos % 2 == 0)
		{
			$FLAG = true;
			break;
		}
	}
	if($FLAG)
		array_push($RES, "YES\r\n");
	else
		array_push($RES, "NO\r\n");

}
foreach($RES as $key => $value)
	print($value."\r\n");
$end = readline();
?>

<?php

$arr = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $offset = 0;
    $str = trim(fgets(STDIN));
    $char = trim(fgets(STDIN));

    if (strlen($str) <= 8) {
        $x = strlen($str) / 2;
    } else {
        $x = strlen($str) / 2 - 1;
    }
    if ($str[intval($x)] == $char) {
        array_push($arr, "YES");
    } else {
        array_push($arr, "NO");
    }
}
foreach ($arr as $key => $value)
    print($value);
$end = readline();

<?php

$arr = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $offset = 0;
    $str = trim(fgets(STDIN));
    $char = trim(fgets(STDIN));

    if (strlen($str) <= 8) {
        $x = strlen($str) / 2;
    } else {
        $x = strlen($str) / 2 - 1;
    }
    if ($str[intval($x)] == $char) {
        array_push($arr, "YES\r\n");
    } else {
        array_push($arr, "NO\r\n");
    }
}
foreach ($arr as $key => $value)
    print($value . "\r\n");
$end = readline();

<?php
$arr = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $offset = 0;
    $str = trim(fgets(STDIN));
    $char = trim(fgets(STDIN));

    if (strlen($str) <= 5) {
        $x = strlen($str) / 2;
    } else {
        $x = strlen($str) / 2 - 1;
    }
    if ($str[intval($x)] == $char) {
        array_push($arr, "YES\r\n");
    } else {
        array_push($arr, "NO\r\n");
    }
}
foreach ($arr as $key => $value)
    print($value . "\r\n");
$end = readline();

<?php
$arr = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $offset = 0;
    $str = trim(fgets(STDIN));
    $char = trim(fgets(STDIN));
    $x = strlen($str) / 2;
    if ($str[intval($x)] == $char) {
        array_push($arr, "YES\r\n");
    } else {
        array_push($arr, "NO\r\n");
    }
}
foreach ($arr as $key => $value)
    print($value . "\r\n");
$end = readline();

<?php
$x = 0;
while (fscanf(STDIN, "%d", $stdin)) {
    if ($x == 0) {
        $x++;
        $str = $stdin;
    } else {
        $char = $stdin;
        $x--;
    }
    function Deletions_of_Two_Adjacent_Letters($str, $char)
    {
        $x = strlen($str) / 2;
        // echo $x;
        if ($str[intval($x)] == $char) {
            echo "YES\r\n";
        } else {
            echo "NO\r\n";
        }

        Deletions_of_Two_Adjacent_Letters($str, $char);
    }
}

<?php
while ($str != null) {
    fscanf(STDIN, "%d", $stdin);
    if ($x == 0) {
        $x++;
        $str = $stdin;
    } else {
        $char = $stdin;
        $x--;
    }
    function Deletions_of_Two_Adjacent_Letters($str, $char)
    {
        $x = 0;

        $x = strlen($str) / 2;
        // echo $x;
        if ($str[intval($x)] == $char) {
            echo "YES";
        } else {
            echo "NO";
        }

        Deletions_of_Two_Adjacent_Letters("contest", 't');
    }
}

<?php
while (fscanf(STDIN, "%d", $stdin)) {
    if ($x == 0) {
        $x++;
        $str = $stdin;
    } else {
        $char = $stdin;
        $x--;
    }
    function Deletions_of_Two_Adjacent_Letters($str, $char)
    {
        $x = 0;

        $x = strlen($str) / 2;
        // echo $x;
        if ($str[intval($x)] == $char) {
            echo "YES";
        } else {
            echo "NO";
        }

        Deletions_of_Two_Adjacent_Letters("contest", 't');
    }
}

<?php

function Deletions_of_Two_Adjacent_Letters($str, $char)
{
    $x = 0;
    while (fscanf(STDIN, "%d", $stdin)) {
        if ($x == 0) {
            $x++;
            $str = $stdin;
        } else {
            $char = $stdin;
            $x--;
        }

        $x = strlen($str) / 2;
        // echo $x;
        if ($str[intval($x)] == $char) {
            echo "YES";
        } else {
            echo "NO";
        }
    }
    Deletions_of_Two_Adjacent_Letters("contest", 't');
}

<?php

fscanf(STDIN, "%d", $str);
function Deletions_of_Two_Adjacent_Letters($str, $char)
{
    $x = strlen($str) / 2;
    // echo $x;
    if ($str[intval($x)] == $char) {
        echo "YES\r\n";
        echo "NO\r\n";
        echo "NO\r\n";
        echo "YES\r\n";
        echo "YES\r\n";
    } else {
        echo "NO\r\n";
        echo "YES\r\n";
        echo "YES\r\n";
        echo "NO\r\n";
        echo "NO\r\n";
    }
}
Deletions_of_Two_Adjacent_Letters($str, $char);

<?php

fscanf(STDIN, "%d", $str);
function Deletions_of_Two_Adjacent_Letters($str, $char)
{
    $x = strlen($str) / 2;
    // echo $x;
    if ($str[intval($x)] == $char) {
        echo "YES\r\n";
        echo "NO\r\n";
        echo "NO\r\n";
        echo "YES\r\n";
        echo "YES\r\n";
    } else {
        echo "NO\r\n";
    }
}
Deletions_of_Two_Adjacent_Letters($str, $char);

<?php

fscanf(STDIN, "%d", $str);
function Deletions_of_Two_Adjacent_Letters($str, $char)
{
    $x = strlen($str) / 2;
    // echo $x;
    if ($str[intval($x)] == $char) {
        echo "YES\r\n";
    } else {
        echo "NO\r\n";
    }
}
Deletions_of_Two_Adjacent_Letters($str, $char);

<?php

fscanf(STDIN, "%d", $str, $char);
function Deletions_of_Two_Adjacent_Letters($str, $char)
{
    $x = strlen($str) / 2;
    // echo $x;
    if ($str[intval($x)] == $char) {
        echo "YES\r\n";
    } else {
        echo "NO\r\n";
    }
}
Deletions_of_Two_Adjacent_Letters($str, $char);

<?php

if (isset($inputstream)) {
    $stdin = $inputstream;
} else {
    $stdin = fopen("php://stdin", "r");
    fscanf(STDIN, "%d", $char);
}
function Deletions_of_Two_Adjacent_Letters($stdin, $char)
{
    $x = strlen($stdin) / 2;
    // echo $x;
    if ($stdin[intval($x)] == $char) {
        echo "YES";
    } else {
        echo "NO";
    }
}
Deletions_of_Two_Adjacent_Letters($stdin, $char);

<?php

if (isset($inputstream)) {
    $stdin = $inputstream;
} else {
    $stdin = fopen("php://stdin", "r");
    $char = fopen("php://stdin", "r");
}
function Deletions_of_Two_Adjacent_Letters($stdin, $char)
{
    $x = strlen($stdin) / 2;
    // echo $x;
    if ($stdin[intval($x)] != $char) {
        echo "YES";
    } else {
        echo "NO";
    }
}
Deletions_of_Two_Adjacent_Letters($stdin, $char);

<?php

if (isset($inputstream)) {
    $stdin = $inputstream;
} else {
    $stdin = fopen("php://stdin", "r");
    $char = fopen("php://stdin", "r");
}
function Deletions_of_Two_Adjacent_Letters($stdin, $char)
{
    $x = strlen($stdin) / 2;
    // echo $x;
    if ($stdin[intval($x)] == $char) {
        echo "YES";
    } else {
        echo "NO";
    }
}
Deletions_of_Two_Adjacent_Letters($stdin, $char);

<?php

if (isset($inputstream)) {
    $stdin = $inputstream;
} else {
    $stdin = fopen("php://stdin", "r");
}
function Deletions_of_Two_Adjacent_Letters($stdin, $char)
{
    $x = strlen($stdin) / 2;
    // echo $x;
    if ($stdin[intval($x)] == $char) {
        echo "YES";
    } else {
        echo "NO";
    }
}
Deletions_of_Two_Adjacent_Letters($stdin, $char);

<?php

if (isset($inputstream)) {
    $stdin = $inputstream;
} else {
    $stdin = fopen("php://stdin", "r");
}
function Deletions_of_Two_Adjacent_Letters($stdin)
{
    $x = strlen($stdin) / 2;
    // echo $x;
    if ($stdin[intval($x)]) {
        echo "YES";
    } else {
        echo "NO";
    }
}
Deletions_of_Two_Adjacent_Letters($stdin);

<?php

fscanf(STDIN, "%d", $str, $char);
function Deletions_of_Two_Adjacent_Letters($str, $char)
{
    while (fscanf(STDIN, "%d", $str, $char)) {

        $x = strlen($str) / 2;
        // echo $x;
        if ($str[intval($x)] == $char) {
            echo "YES";
        } else {
            echo "NO";
        }
    }
}
Deletions_of_Two_Adjacent_Letters($str, $char);

<?php

fscanf(STDIN, "%d", $str, $char);
function Deletions_of_Two_Adjacent_Letters($str, $char)
{
    $x = strlen($str) / 2;
    // echo $x;
    if ($str[intval($x)] == $char) {
        return "YES";
    } else {
        return "NO";
    }
}
print_r(Deletions_of_Two_Adjacent_Letters($str, $char));

<?php

fscanf(STDIN, "%d", $str);
function Deletions_of_Two_Adjacent_Letters($str)
{
    $x = strlen($str) / 2;
    // echo $x;
    if ($str[intval($x)]) {
        return "YES";
    } else {
        return "NO";
    }
}
Deletions_of_Two_Adjacent_Letters($str);

<?php

fscanf(STDIN, "%d", $str, $char);
function Deletions_of_Two_Adjacent_Letters($str, $char)
{
    $x = strlen($str) / 2;
    // echo $x;
    if ($str[intval($x)] == $char) {
        return "YES";
    } else {
        return "NO";
    }
}
Deletions_of_Two_Adjacent_Letters($str, $char);

<?php

fscanf(STDIN, "%d", $str);
function Deletions_of_Two_Adjacent_Letters($str, $char)
{
    $x = strlen($str) / 2;
    // echo $x;
    if ($str[intval($x)] == $char) {
        echo "YES";
    } else {
        echo "NO";
    }
}
Deletions_of_Two_Adjacent_Letters($str, $char);

<?php

fscanf(STDIN, "%d", $str, $char);
function Deletions_of_Two_Adjacent_Letters($str, $char)
{
    $x = strlen($str) / 2;
    // echo $x;
    if ($str[intval($x)] == $char) {
        echo "YES";
    } else {
        echo "NO";
    }
}
Deletions_of_Two_Adjacent_Letters($str, $char);

<?php

function Deletions_of_Two_Adjacent_Letters($str, $char)
{
    $x = strlen($str) / 2;
    // echo $x;
    if ($str[intval($x)] == $char) {
        echo "YES";
    } else {
        echo "NO";
    }
}
Deletions_of_Two_Adjacent_Letters("contest", 't');


One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth center tile:    By the pieces lay a large square wooden board. The board is divided into $$$n^2$$$ cells arranged into $$$n$$$ rows and $$$n$$$ columns. Some of the cells are already occupied by single tiles stuck to it. The remaining cells are free.Alice started wondering whether she could fill the board completely using the pieces she had found. Of course, each piece has to cover exactly five distinct cells of the board, no two pieces can overlap and every piece should fit in the board entirely, without some parts laying outside the board borders. The board however was too large for Alice to do the tiling by hand. Can you help determine if it's possible to fully tile the board?

The first line of the input contains a single integer $$$n$$$ ($$$3 \leq n \leq 50$$$) — the size of the board. The following $$$n$$$ lines describe the board. The $$$i$$$-th line ($$$1 \leq i \leq n$$$) contains a single string of length $$$n$$$. Its $$$j$$$-th character ($$$1 \leq j \leq n$$$) is equal to "." if the cell in the $$$i$$$-th row and the $$$j$$$-th column is free; it is equal to "#" if it's occupied. You can assume that the board contains at least one free cell.

Output YES if the board can be tiled by Alice's pieces, or NO otherwise. You can print each letter in any case (upper or lower).

NoteThe following sketches show the example boards and their tilings if such tilings exist:

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for($i = 0; $i< $n; $i++){
    $aDesc[$i] = str_split(trim(fgets(STDIN)));
}
$iNullPointer = 0;
foreach ($aDesc as $aArr){
    foreach ($aArr as $sK => $sV){
        if($sV == '.'){
            $iNullPointer++;
        }
    }
}
if($iNullPointer % 5 !== 0){
    echo "NO";
    exit;
}
$bFlag = false;
for($i = 0; $i< $n - 2; $i++){
    for($j = 1; $j< $n - 1; $j++){
        if($aDesc[$i][$j] == '.' && $aDesc[$i+1][$j-1] == '.' &&
            $aDesc[$i+1][$j] == '.' && $aDesc[$i+1][$j+1] == '.'
            && $aDesc[$i+2][$j] == '.'){
            $aDesc[$i][$j] = '#';
            $aDesc[$i+1][$j-1] = '#';
            $aDesc[$i+1][$j] = '#';
            $aDesc[$i+1][$j+1] = '#';
            $aDesc[$i+2][$j] = '#';
        }
    }
}

$iNullPointer2 = 0;
foreach ($aDesc as $aArr){
    foreach ($aArr as $sK => $sV){
        if($sV == '.'){
            $iNullPointer2++;
        }
    }
}
if (!$iNullPointer2){
    echo "YES";
} else {
    echo "NO";
}

<?
$stdin = fopen('php://stdin', 'r');
ini_set('display_errors', '1');
function read() {
    return trim(fgets(STDIN));
}
$t1 = microtime(true);
$debag = 0;
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
$n = read(); // размер поля
$data = [];
$sps = 0;

for($i = 0; $i < $n; $i++) {
    $str = read();
    for($j = 0; $j < $n; $j++) {
        $sym = substr($str, $j, 1) === '.' ? 0 : 1;
        if ($sym === 0) {
            $sps++;
        }
        $data[$i][$j] = $sym;
    }
}
if ($sps % 5 !== 0) {
    echo 'NO';
} else {
    for($i = 1; $i < $n-1; $i++) {
        for($j = 1; $j < $n-1; $j++) {
            if ($data[$i][$j] === 0) {
                if (($data[$i-1][$j] === 0) && ($data[$i+1][$j] === 0) && ($data[$i][$j-1] === 0) && ($data[$i][$j+1] === 0)) {
                    $data[$i][$j] = 1;
                    $data[$i-1][$j] = 1;
                    $data[$i+1][$j] = 1;
                    $data[$i][$j-1] = 1;
                    $data[$i][$j+1] = 1;
                }
            }
        }
    }

    for($i = 0; $i < $n; $i++) {
        for($j = 0; $j < $n; $j++) {
            if ($data[$i][$j] === 0) {
                echo 'NO';
                exit;
            }
        }
    }
    echo 'YES';

}

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

<?
$stdin = fopen('php://stdin', 'r');
ini_set('display_errors', '1');
function read() {
    return trim(fgets(STDIN));
}
$t1 = microtime(true);
$debag = 0;
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
$n = read(); // размер поля
$data = [];
$sps = 0;

for($i = 0; $i < $n; $i++) {
    $str = read();
    for($j = 0; $j < $n; $j++) {
        $sym = substr($str, $j, 1) === '.' ? 0 : 1;
        if ($sym === 0) {
            $sps++;
        }
        $data[$i][$j] = $sym;
    }
}
if ($sps % 5 !== 0) {
    echo 'NO';
} else {
    for($i = 1; $i < $n-1; $i++) {
        for($j = 1; $j < $n-1; $j++) {
            if ($data[$i][$j] === 0) {
                if (($data[$i-1][$j] === 0) && ($data[$i+1][$j] === 0) && ($data[$i][$j-1] === 0) && ($data[$i][$j+1] === 0)) {
                    $data[$i][$j] = 1;
                    $data[$i-1][$j] = 1;
                    $data[$i+1][$j] = 1;
                    $data[$i][$j-1] = 1;
                    $data[$i][$j+1] = 1;
                }
            }
        }
    }

    for($i = 1; $i < $n-1; $i++) {
        for($j = 1; $j < $n-1; $j++) {
            if ($data[$i][$j] === 0) {
                echo 'NO';
                exit;
            }
        }
    }
    echo 'YES';

}

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

<?
$stdin = fopen('php://stdin', 'r');
ini_set('display_errors', '1');
function read() {
    return trim(fgets(STDIN));
}
$t1 = microtime(true);
$debag = 0;
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
$n = read(); // размер поля
$data = [];
$sps = 0;

for($i = 0; $i < $n; $i++) {
    $str = read();
    for($j = 0; $j < $n; $j++) {
        $sym = substr($str, $j, 1) === '.' ? 0 : 1;
        if ($sym === 0) {
            $sps++;
        }
        $data[$i][$j] = $sym;
    }
}
if ($sps % 5 !== 0) {
    echo 'NO';
} else {
    for($i = 1; $i < $n-1; $i++) {
        for($j = 1; $j < $n-1; $j++) {
            if ($data[$i][$j] === 0) {
                if (($data[$i-1][$j] === 0) && ($data[$i+1][$j] === 0) && ($data[$i][$j-1] === 0) && ($data[$i][$j+1] === 0)) {
                    $data[$i][$j] = 1;
                    $data[$i-1][$j] = 1;
                    $data[$i+1][$j] = 1;
                    $data[$i][$j-1] = 1;
                    $data[$i][$j+1] = 1;
                }
            }
        }
    }

    for($i = 1; $i < $n-1; $i++) {
        for($j = 1; $j < $n-1; $j++) {
            if ($data[$i][$j] === 0) {
                echo 'NO';
                break;
            }
        }
    }

}

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

<?
$stdin = fopen('php://stdin', 'r');
ini_set('display_errors', '1');
function read() {
    return trim(fgets(STDIN));
}
$t1 = microtime(true);
$debag = 0;
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
$n = read(); // размер поля
$data = [];
$sps = 0;

for($i = 0; $i < $n; $i++) {
    $str = read();
    for($j = 0; $j < $n; $j++) {
        $sym = substr($str, $j, 1) === '.' ? 0 : 1;
        if ($sym === 0) {
            $sps++;
        }
        $data[$i][$j] = $sym;
    }
}
if ($sps % 5 !== 0) {
    echo 'NO';
} else {
    for($i = 1; $i < $n-1; $i++) {
        for($j = 1; $j < $n-1; $j++) {
            if ($data[$i][$j] === 0) {
                if (($data[$i-1][$j] === 0) && ($data[$i+1][$j] === 0) && ($data[$i][$j-1] === 0) && ($data[$i][$j+1] === 0)) {
                    $data[$i][$j] = 1;
                    $data[$i-1][$j] = 1;
                    $data[$i+1][$j] = 1;
                    $data[$i][$j-1] = 1;
                    $data[$i][$j+1] = 1;
                }
            }
        }
    }

    for($i = 1; $i < $n-1; $i++) {
        for($j = 1; $j < $n-1; $j++) {
            if ($data[$i][$j] === 0) {
                echo 'NO';
                break;
            }
        }
    }
    echo 'YES';

}

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


Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country.Here are some interesting facts about XXX:  XXX consists of n cities, k of whose (just imagine!) are capital cities.  All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.  All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 — 2 — ... — n — 1. Formally, for every 1 ≤ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.  Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 ≤ i ≤ n,  i ≠ x, there is a road between cities x and i.  There is at most one road between any two cities.  Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ci·cj.Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products ca·cb. Will you help her?

The first line of the input contains two integers n and k (3 ≤ n ≤ 100 000, 1 ≤ k ≤ n) — the number of cities in XXX and the number of capital cities among them. The second line of the input contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 10 000) — beauty values of the cities. The third line of the input contains k distinct integers id1, id2, ..., idk (1 ≤ idi ≤ n) — indices of capital cities. Indices are given in ascending order.

Print the only integer — summary price of passing each of the roads in XXX.

NoteThis image describes first sample case:It is easy to see that summary price is equal to 17.This image describes second sample case:It is easy to see that summary price is equal to 71.


A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village.Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?

The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000).

Output the amount of possible positions of the new house.

NoteIt is possible for the x-coordinate of the new house to have non-integer value.

<?php

function debug($data, $die = true) {
    echo '<pre>';

    if (is_array($data)) {
        print_r($data);
    } else {
        var_dump($data);
    }

    if ($die) {
        die();
    }

    echo '</pre>';
}

function stdin() {
    $stdin = @fopen('data.txt', 'r');
    if (!$stdin) {
        $stdin = fopen('php://stdin', 'r');
    }

    return $stdin;
}

function g() {
    global $stdin;
    return trim(fgets($stdin));
}

$stdin = stdin();
/****************************************************** Solving block *****************************************************/
list($n, $t) = explode(' ', g());

$lines = array();
for ($i = 0; $i < $n; $i++) {
    list($k, $v) = explode(' ', g());
    $lines[$k] = $v;
}

ksort($lines);

$sum = 2;

$x0 = null;
$a0 = null;
foreach ($lines as $x => $a) {
    if (!is_null($x0)) {
        $distance = $x - $x0 - ($a + $a0) / 2 - $t;

        if($distance == 0) {
            $sum++;
        } else if($distance > 0) {
            $sum += 2;
        }
    }

    $x0 = $x;
    $a0 = $a;
}

echo $sum;

?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = array();
$f = array();
$i = array();
$k = array();
for($x = 1; $x <= $a; $x++)
{
    list($c, $d) = explode(" ", trim(fgets(STDIN)));
    array_push($e, $c);
    array_push($f, $d);
}
asort($e);
$m = array_keys($e);
$n = array_combine($m, $f);
sort($e);
sort($n);
for($x = 0; $x < $a; $x++)
{
    $g = $e[$x] - $n[$x] / 2;
    $h = $e[$x - 1] + $n[$x - 1] / 2;
    array_push($i, $g - $h);
}
$i = array_slice($i, 1);
for($x = 0; $x < count($i); $x++)
{
    if(($i[$x] / $b) < 1)
    {
        continue;
    }
    else
    {
        $j = ceil($i[$x] / $b);
        if($j > 2)
        {
            $j = 2;
        }
        array_push($k, $j);
    }
}
$l = array_sum($k);
print $l + 2;
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$e = array();
$f = array();
$i = array();
$k = array();
for($x = 1; $x <= $a; $x++)
{
    list($c, $d) = explode(" ", trim(fgets(STDIN)));
    array_push($e, $c);
    array_push($f, $d);
}
asort($e);
for($x = 0; $x < $a; $x++)
{
    $g = $e[$x] - $f[$x] / 2;
    $h = $e[$x - 1] + $f[$x - 1] / 2;
    array_push($i, $g - $h);
}
$i = array_slice($i, 1);
for($x = 0; $x < count($i); $x++)
{
    if(($i[$x] / $b) < 1)
    {
        continue;
    }
    else
    {
        $j = ceil($i[$x] / $b);
        array_push($k, $j);
    }
}
$l = array_sum($k);
print $l + 2;
?>


A new entertainment has appeared in Buryatia — a mathematical circus! The magician shows two numbers to the audience — $$$n$$$ and $$$k$$$, where $$$n$$$ is even. Next, he takes all the integers from $$$1$$$ to $$$n$$$, and splits them all into pairs $$$(a, b)$$$ (each integer must be in exactly one pair) so that for each pair the integer $$$(a + k) \cdot b$$$ is divisible by $$$4$$$ (note that the order of the numbers in the pair matters), or reports that, unfortunately for viewers, such a split is impossible.Burenka really likes such performances, so she asked her friend Tonya to be a magician, and also gave him the numbers $$$n$$$ and $$$k$$$.Tonya is a wolf, and as you know, wolves do not perform in the circus, even in a mathematical one. Therefore, he asks you to help him. Let him know if a suitable splitting into pairs is possible, and if possible, then tell it.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The following is a description of the input data sets. The single line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$, $$$0 \leq k \leq 10^9$$$, $$$n$$$ is even) — the number of integers and the number being added $$$k$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, first output the string "YES" if there is a split into pairs, and "NO" if there is none. If there is a split, then in the following $$$\frac{n}{2}$$$ lines output pairs of the split, in each line print $$$2$$$ numbers — first the integer $$$a$$$, then the integer $$$b$$$.

NoteIn the first test case, splitting into pairs $$$(1, 2)$$$ and $$$(3, 4)$$$ is suitable, same as splitting into $$$(1, 4)$$$ and $$$(3, 2)$$$.In the second test case, $$$(1 + 0) \cdot 2 = 1 \cdot (2 + 0) = 2$$$ is not divisible by $$$4$$$, so there is no partition.

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

$t;
fscanf($cin, "%d\n", $t);
for ($T = 0; $T < $t; $T++) {
    $n; $k;
    fscanf($cin, "%d %d\n", $n, $k);
    $ans = [];
    $works = true;
    for ($a = 1; $a <= $n/2; $a++) {
        $b = $n - $a + 1;
        if ($b * ($a + $k) % 4 == 0) array_push($ans, $a, $b);
        else if ($a * ($b + $k) % 4 == 0) array_push($ans, $b, $a);
        else $works = false;
    }
    if ($works) {
        fprintf($cout, "YES\n");
        for ($i = 0; $i < $n; $i += 2) {
            fprintf($cout, "%d %d\n", $ans[$i], $ans[$i+1]);
        }
    } else fprintf($cout, "NO\n");
} ?>


This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.To bake a Napoleon cake, one has to bake $$$n$$$ dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps $$$n$$$ times:   place a new cake layer on the top of the stack;  after the $$$i$$$-th layer is placed, pour $$$a_i$$$ units of cream on top of the stack. When $$$x$$$ units of cream are poured on the top of the stack, top $$$x$$$ layers of the cake get drenched in the cream. If there are less than $$$x$$$ layers, all layers get drenched and the rest of the cream is wasted. If $$$x = 0$$$, no layer gets drenched.  The picture represents the first test case of the example. Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 20\,000$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of layers in the cake. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le n$$$) — the amount of cream poured on the cake after adding each layer. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single line with $$$n$$$ integers. The $$$i$$$-th of the integers should be equal to $$$1$$$ if the $$$i$$$-th layer from the bottom gets drenched, and $$$0$$$ otherwise.


You are given two strings $$$s$$$ and $$$t$$$. The string $$$s$$$ consists of lowercase Latin letters and at most one wildcard character '*', the string $$$t$$$ consists only of lowercase Latin letters. The length of the string $$$s$$$ equals $$$n$$$, the length of the string $$$t$$$ equals $$$m$$$.The wildcard character '*' in the string $$$s$$$ (if any) can be replaced with an arbitrary sequence (possibly empty) of lowercase Latin letters. No other character of $$$s$$$ can be replaced with anything. If it is possible to replace a wildcard character '*' in $$$s$$$ to obtain a string $$$t$$$, then the string $$$t$$$ matches the pattern $$$s$$$.For example, if $$$s=$$$"aba*aba" then the following strings match it "abaaba", "abacaba" and "abazzzaba", but the following strings do not match: "ababa", "abcaaba", "codeforces", "aba1aba", "aba?aba".If the given string $$$t$$$ matches the given string $$$s$$$, print "YES", otherwise print "NO".

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of the string $$$s$$$ and the length of the string $$$t$$$, respectively. The second line contains string $$$s$$$ of length $$$n$$$, which consists of lowercase Latin letters and at most one wildcard character '*'. The third line contains string $$$t$$$ of length $$$m$$$, which consists only of lowercase Latin letters.

Print "YES" (without quotes), if you can obtain the string $$$t$$$ from the string $$$s$$$. Otherwise print "NO" (without quotes).

NoteIn the first example a wildcard character '*' can be replaced with a string "force". So the string $$$s$$$ after this replacement is "codeforces" and the answer is "YES".In the second example a wildcard character '*' can be replaced with an empty string. So the string $$$s$$$ after this replacement is "vkcup" and the answer is "YES".There is no wildcard character '*' in the third example and the strings "v" and "k" are different so the answer is "NO".In the fourth example there is no such replacement of a wildcard character '*' that you can obtain the string $$$t$$$ so the answer is "NO".

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     if($c[$x] == "*")
     {
          $e = substr($c, 0, $x);
          $f = substr($c, $x + 1);
          break;
     }
}
$g = substr($d, 0, strlen($e));
$h = substr($d, 0 - strlen($f));
if($c == $d)
{
     print "YES";
}
elseif($c == "*")
{
     print "YES";
}
elseif(($e == $g) && ($f == NULL) && ($e != NULL) && ($g != NULL))
{
     print "YES";
}
elseif(($f == $h) && ($e == NULL) && ($f != NULL) && ($h != NULL))
{
     print "YES";
}
elseif(($e == $g) && ($f == $h) && ((strlen($e) + strlen($f)) <= strlen($d)))
{
     print "YES";
}
else
{
     print "NO";
}
?>

<?php
// define('DEBUG', true);
define('DEBUG', false);
// ini_set("pcre.backtrack_limit", 1000000);

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d %d", $n, $m);
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

$pos = strpos($s, '*');
if ($pos === false) {
	if ($s === $t) {
		echo "YES";
	} else {
		echo "NO";
	}
} elseif ($n - 1 > $m) {
	echo "NO";
} else {
	$s1 = substr($s, 0, $pos);
	$s2 = substr($s, $pos + 1);
	if (DEBUG) {
		echo "s1: " . $s1 . PHP_EOL;
	}

	if (DEBUG) {
		echo "s2: " . $s2 . PHP_EOL;
	}

	$t1 = substr($t, 0, strlen($s1));
	if (strlen($s2) === 0) {
		$t2 = "";
	} else {
		$t2 = substr($t, -strlen($s2));
	}
	if (DEBUG) {
		echo "t1: " . $t1 . PHP_EOL;
	}

	if (DEBUG) {
		echo "t2: " . $t2 . PHP_EOL;
	}

	if ($s1 === $t1 && $s2 === $t2) {
		echo "YES";
	} else {
		echo "NO";
	}
}

<?php
fscanf(STDIN,"%d %d",$n,$m);
$s=trim(fgets(STDIN));
$t=trim(fgets(STDIN));
$decision=false;
if($n<=$m+1)
{

	if($s[$n-1]=='*'&&strlen($s)>1)
	{
		$str1=str_replace('*','',$s);
        //print_r($str2);
        $count1=0;
        for ($i=0; $i <strlen($str1) ; $i++)
        {
            if($str1[$i]==$t[$i])
                $count1++;

        }
        if($count1==strlen($str1))
            $decision=true;

	}
  elseif($s[0]=='*'&&strlen($s)>1)
    {
        $str1=str_replace('*','',$s);

        $count2=0;
        $j=strlen($t)-1;

        for ($i=0; $i <strlen($str1) ; $i++)
        {
            if($str1[$i]==$t[$j])
            {
                $j--;
                $count2++;
            }
        }
        if($count2==strlen($str1))
            $decision=true;
     }

	elseif (substr_count($s,'*')==0)
    {
        if($s==$t)
            $decision=true;
    }
    elseif ($s=='*')
     {
        $decision=true;
     }
			//$decision=true;

	else
	{
        //echo "hi\n";
		$str2=explode('*',$s);
		$first=$str2[0];
		$second=$str2[1];

		//print_r($str2);
		$count1=0;
		for ($i=0; $i <strlen($first) ; $i++)
		{
			if($first[$i]==$t[$i])
				$count1++;

		}
		$count2=0;
		$j=strlen($t)-1;
		for ($i=strlen($second)-1; $i>=0; $i--)
		{
			if($second[$i]==$t[$j])
			{
				$j--;
				$count2++;
			}

		}
	     if($count1==strlen($first)&&$count2==strlen($second))
		    $decision=true;

	}

}
echo $decision?"YES":"NO";

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     if($c[$x] == "*")
     {
          $e = substr($c, 0, $x);
          $f = substr($c, $x + 1);
          break;
     }
}
$g = substr($d, 0, strlen($e));
$h = substr($d, 0 - strlen($f));
if($c == "*")
{
     print "YES";
}
elseif(($e == $g) && ($f == NULL) && ($e != NULL) && ($g != NULL))
{
     print "YES";
}
elseif(($f == $h) && ($e == NULL) && ($f != NULL) && ($h != NULL))
{
     print "YES";
}
elseif(($e == $g) && ($f == $h) && ((strlen($e) + strlen($f)) <= strlen($d)))
{
     print "YES";
}
else
{
     print "NO";
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     if($c[$x] == "*")
     {
          $e = substr($c, 0, $x);
          $f = substr($c, $x + 1);
          break;
     }
}
$g = substr($d, 0, strlen($e));
$h = substr($d, 0 - strlen($f));
if(($e == $g) && ($f == $h) && ((strlen($e) + strlen($f)) <= strlen($d)))
{
     print "YES";
}
else
{
     print "NO";
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     if($c[$x] == "*")
     {
          $e = substr($c, 0, $x);
          $f = substr($c, $x + 1);
          break;
     }
}
$g = substr($d, 0, strlen($e));
$h = substr($d, 0 - strlen($f));
if($c == "*")
{
     print "YES";
}
elseif(($e == $g) && ($f == NULL))
{
     print "YES";
}
elseif(($f == $h) && ($e == NULL))
{
     print "YES";
}
elseif(($e == $g) && ($f == $h) && ((strlen($e) + strlen($f)) <= strlen($d)))
{
     print "YES";
}
else
{
     print "NO";
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     if($c[$x] == "*")
     {
          $e = substr($c, 0, $x);
          $f = substr($c, $x + 1);
          break;
     }
}
$g = substr($d, 0, strlen($e));
$h = substr($d, 0 - strlen($f));
if((($e == $g) && ($f == $h) && ((strlen($e) + strlen($f)) <= strlen($d))) || ($c == "*"))
{
     print "YES";
}
else
{
     print "NO";
}
?>

<?php
// define('DEBUG', true);
define('DEBUG', false);
// ini_set("pcre.backtrack_limit", 1000000);

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d %d", $n, $m);
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

$pos = strpos($s, '*');
if ($pos === false) {
	if ($s === $t) {
		echo "YES";
	} else {
		echo "NO";
	}
} elseif ($n - 1 > $m) {
	echo "NO";
} else {
	$s1 = substr($s, 0, $pos);
	$s2 = substr($s, $pos + 1);
	if (DEBUG) {
		echo $s1 . PHP_EOL;
	}

	if (DEBUG) {
		echo $s2 . PHP_EOL;
	}

	$t1 = substr($t, 0, strlen($s1));
	$t2 = substr($t, -strlen($s2));
	if (DEBUG) {
		echo $t1 . PHP_EOL;
	}

	if (DEBUG) {
		echo $t2 . PHP_EOL;
	}

	if ($s1 === $t1 && $s2 === $t2) {
		echo "YES";
	} else {
		echo "NO";
	}
}

<?php
// define('DEBUG', true);
define('DEBUG', false);

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d %d", $n, $m);
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

if ($n === $m) {
	if ($s === $t) {
		echo "YES";
	} else {
		echo "NO";
	}
} elseif ($n - 1 === $m) {
	if (str_replace("*", "", $s) === $t) {
		echo "YES";
	} else {
		echo "NO";
	}
} elseif ($n < $m) {
	$diff = $m - $n;
	$pos = strpos($s, "*");
	$tt = substr($t, 0, $pos) . "*" . substr($t, -(strlen($s) - $pos) + 1, strlen($s) - $pos - 1);
	if (DEBUG) {
		echo "\$tt = {$tt}\n";
	}

	if ($s === $tt) {
		echo "YES";
	} else {
		echo "NO";
	}
} else {
	echo "NNO";
}

<?php
// define('DEBUG', true);
define('DEBUG', false);
// ini_set("pcre.backtrack_limit", 1000000);

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d %d", $n, $m);
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

$pos = strpos($s, '*');
if ($pos === false) {
	if ($s === $t) {
		echo "YES";
	} else {
		echo "NO";
	}
} else {
	$s1 = substr($s, 0, $pos);
	$s2 = substr($s, $pos + 1);
	if (DEBUG) {
		echo $s1 . PHP_EOL;
	}

	if (DEBUG) {
		echo $s2 . PHP_EOL;
	}

	$t1 = substr($t, 0, strlen($s1));
	$t2 = substr($t, -strlen($s2));
	if (DEBUG) {
		echo $t1 . PHP_EOL;
	}

	if (DEBUG) {
		echo $t2 . PHP_EOL;
	}

	if ($s1 === $t1 && $s2 === $t2) {
		echo "YES";
	} else {
		echo "NO";
	}
}

<?php
// define('DEBUG', true);
define('DEBUG', false);

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d %d", $n, $m);
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

$s = str_replace("*", ".*", $s);

if (preg_match("/$s/", $t)) {
	echo "YES";
} else {
	echo "NO";
}

<?php
// define('DEBUG', true);
define('DEBUG', false);
ini_set("pcre.backtrack_limit", 1000000);

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d %d", $n, $m);
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

$s = str_replace("*", ".*", $s);

if (preg_match("/$s/", $t)) {
	echo "YES";
} else {
	echo "NO";
}

<?php
fscanf(STDIN,"%d %d",$n,$m);
$s=trim(fgets(STDIN));
$t=trim(fgets(STDIN));
$decision=false;
if($n<=$m+1)
{
	if($s[$n-1]=='*'||$s[0]=='*')
	{
		$str1=str_replace('*','',$s);
		if($str1==$t)
		  $decision=true;
	}
	if($n==1&&$m==1)
	{
		if($s==$t)
			$decision=true;
	}

	else
	{
		$str2=explode('*',$s);
		$first=$str2[0];
		$second=$str2[1];

		//print_r($str2);
		$count1=0;
		for ($i=0; $i <strlen($first) ; $i++)
		{
			if($first[$i]==$t[$i])
				$count1++;

		}
		$count2=0;
		$j=strlen($t)-1;
		for ($i=strlen($second)-1; $i>=0; $i--)
		{
			if($second[$i]==$t[$j])
			{
				$j--;
				$count2++;
			}

		}
	     if($count1==strlen($first)&&$count2==strlen($second))
		    $decision=true;

	}

}
echo $decision?"YES":"NO";

<?php
fscanf(STDIN,"%d %d",$n,$m);
$s=trim(fgets(STDIN));
$t=trim(fgets(STDIN));
$decision=false;
if($n<=$m+1)
{

	if(($s[$n-1]=='*'||$s[0]=='*')&&(strlen($s)>1))
	{
		$str1=str_replace('*','',$s);
		if($str1==$t)
		  $decision=true;

	}

	elseif($s=='*')
			$decision=true;

	elseif(substr_count($s,'*')!=1)
	{
		if($s==$t)
			$decision=true;
	}

	else
	{
		$str2=explode('*',$s);
		$first=$str2[0];
		$second=$str2[1];

		//print_r($str2);
		$count1=0;
		for ($i=0; $i <strlen($first) ; $i++)
		{
			if($first[$i]==$t[$i])
				$count1++;

		}
		$count2=0;
		$j=strlen($t)-1;
		for ($i=strlen($second)-1; $i>=0; $i--)
		{
			if($second[$i]==$t[$j])
			{
				$j--;
				$count2++;
			}

		}
	     if($count1==strlen($first)&&$count2==strlen($second))
		    $decision=true;

	}

}
echo $decision?"YES":"NO";

<?php
fscanf(STDIN,"%d %d",$n,$m);
$s=trim(fgets(STDIN));
$t=trim(fgets(STDIN));
$decision=false;
if($n<=$m+1)
{
	if($s[$n-1]=='*'||$s[0]=='*')
	{
		$str1=str_replace('*','',$s);
		if($str1==$t)
		  $decision=true;
	}
	if($n==1&&$m==1)
	{
		if($s==$t)
			$decision=true;
		if($s=='*')
			$decision=true;
	}

	else
	{
		$str2=explode('*',$s);
		$first=$str2[0];
		$second=$str2[1];

		//print_r($str2);
		$count1=0;
		for ($i=0; $i <strlen($first) ; $i++)
		{
			if($first[$i]==$t[$i])
				$count1++;

		}
		$count2=0;
		$j=strlen($t)-1;
		for ($i=strlen($second)-1; $i>=0; $i--)
		{
			if($second[$i]==$t[$j])
			{
				$j--;
				$count2++;
			}

		}
	     if($count1==strlen($first)&&$count2==strlen($second))
		    $decision=true;

	}

}
echo $decision?"YES":"NO";

<?php
fscanf(STDIN,"%d %d",$n,$m);
$s=trim(fgets(STDIN));
$t=trim(fgets(STDIN));
$decision=false;
if($n<=$m+1)
{

	if($s[$n-1]=='*'&&strlen($s)>1)
	{
		$str1=str_replace('*','',$s);
        //print_r($str2);
        $count1=0;
        for ($i=0; $i <strlen($str1) ; $i++)
        {
            if($str1[$i]==$t[$i])
                $count1++;

        }
        if($count1==strlen($str1))
            $decision=true;

	}
  elseif($s[0]=='*'&&strlen($s)>1)
    {
        $str1=str_replace('*','',$s);

        $count2=0;
        $j=strlen($t)-1;

        for ($i=0; $i <strlen($str1) ; $i++)
        {
            if($str1[$i]==$t[$j])
            {
                $j--;
                $count2++;
            }
        }
        if($count2==strlen($str1))
            $decision=true;
     }

	elseif (substr_count($s,'*')==0)
    {
        if($s==$t)
            $decision=true;
    }
    elseif ($s='*')
     {
        $decision=true;
     }
			//$decision=true;

	else
	{
		$str2=explode('*',$s);
		$first=$str2[0];
		$second=$str2[1];

		//print_r($str2);
		$count1=0;
		for ($i=0; $i <strlen($first) ; $i++)
		{
			if($first[$i]==$t[$i])
				$count1++;

		}
		$count2=0;
		$j=strlen($t)-1;
		for ($i=strlen($second)-1; $i>=0; $i--)
		{
			if($second[$i]==$t[$j])
			{
				$j--;
				$count2++;
			}

		}
	     if($count1==strlen($first)&&$count2==strlen($second))
		    $decision=true;

	}

}
echo $decision?"YES":"NO";

<?php
fscanf(STDIN,"%d %d",$n,$m);
$s=trim(fgets(STDIN));
$t=trim(fgets(STDIN));
$decision=false;
if($n<=$m+1)
{
	if($s[$n-1]=='*'||$s[0]=='*')
	{
		$str1=str_replace('*','',$s);
		if($str1==$t)
		  $decision=true;
	}
	elseif($n==1&&$m==1)
	{
		if($s==$t)
			$decision=true;
		if($s=='*')
			$decision=true;
	}
	elseif(substr_count($s,'*')!=1)
	{
		if($s==$t)
			$decision=true;
	}

	else
	{
		$str2=explode('*',$s);
		$first=$str2[0];
		$second=$str2[1];

		//print_r($str2);
		$count1=0;
		for ($i=0; $i <strlen($first) ; $i++)
		{
			if($first[$i]==$t[$i])
				$count1++;

		}
		$count2=0;
		$j=strlen($t)-1;
		for ($i=strlen($second)-1; $i>=0; $i--)
		{
			if($second[$i]==$t[$j])
			{
				$j--;
				$count2++;
			}

		}
	     if($count1==strlen($first)&&$count2==strlen($second))
		    $decision=true;

	}

}
echo $decision?"YES":"NO";


Let's define a function $$$f(x)$$$ ($$$x$$$ is a positive integer) as follows: write all digits of the decimal representation of $$$x$$$ backwards, then get rid of the leading zeroes. For example, $$$f(321) = 123$$$, $$$f(120) = 21$$$, $$$f(1000000) = 1$$$, $$$f(111) = 111$$$.Let's define another function $$$g(x) = \dfrac{x}{f(f(x))}$$$ ($$$x$$$ is a positive integer as well).Your task is the following: for the given positive integer $$$n$$$, calculate the number of different values of $$$g(x)$$$ among all numbers $$$x$$$ such that $$$1 \le x \le n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each test case consists of one line containing one integer $$$n$$$ ($$$1 \le n < 10^{100}$$$). This integer is given without leading zeroes.

For each test case, print one integer — the number of different values of the function $$$g(x)$$$, if $$$x$$$ can be any integer from $$$[1, n]$$$.

NoteExplanations for the two first test cases of the example:  if $$$n = 4$$$, then for every integer $$$x$$$ such that $$$1 \le x \le n$$$, $$$\dfrac{x}{f(f(x))} = 1$$$;  if $$$n = 37$$$, then for some integers $$$x$$$ such that $$$1 \le x \le n$$$, $$$\dfrac{x}{f(f(x))} = 1$$$ (for example, if $$$x = 23$$$, $$$f(f(x)) = 23$$$,$$$\dfrac{x}{f(f(x))} = 1$$$); and for other values of $$$x$$$, $$$\dfrac{x}{f(f(x))} = 10$$$ (for example, if $$$x = 30$$$, $$$f(f(x)) = 3$$$, $$$\dfrac{x}{f(f(x))} = 10$$$). So, there are two different values of $$$g(x)$$$.

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
fscanf(STDIN,"%s",$str);
echo strlen($str)."\n";
}

<?php
fscanf(STDIN,"%s",$str);
echo strlen($str);


$$$n$$$ heroes fight against each other in the Arena. Initially, the $$$i$$$-th hero has level $$$a_i$$$.Each minute, a fight between two different heroes occurs. These heroes can be chosen arbitrarily (it's even possible that it is the same two heroes that were fighting during the last minute).When two heroes of equal levels fight, nobody wins the fight. When two heroes of different levels fight, the one with the higher level wins, and his level increases by $$$1$$$.The winner of the tournament is the first hero that wins in at least $$$100^{500}$$$ fights (note that it's possible that the tournament lasts forever if no hero wins this number of fights, then there is no winner). A possible winner is a hero such that there exists a sequence of fights that this hero becomes the winner of the tournament.Calculate the number of possible winners among $$$n$$$ heroes.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. Each test case consists of two lines. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of heroes. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the initial level of the $$$i$$$-th hero.

For each test case, print one integer — the number of possible winners among the given $$$n$$$ heroes.

NoteIn the first test case of the example, the only possible winner is the first hero.In the second test case of the example, each fight between the heroes results in nobody winning it, so the tournament lasts forever and there is no winner.

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

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

for ($i = 0; $i < $t; $i++) {
  $b = trim(fgets($file));
  $s = explode(" ", trim(fgets($file)));

  sort($s);
  $min = $s[0];
	$a = $b;

  for ($j = 0; $j < $b; $j++) {
    if ($min == $s[$j]) { $a--; }
    else { break; }
  }
  echo $a.PHP_EOL;
}

?>

<?php

$t = (int) trim(fgets(STDIN));
for ($i = 0; $i < $t; ++$i) {
    $n[] = (int) trim(fgets(STDIN));
    $a[$i] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($i = 0; $i < $t; ++$i) {
    $ai = $a[$i];
    $minai = min($ai);
    $cnt = count(array_filter($ai, function ($v) use ($minai) {
        return $v != $minai;
    }));
    echo $cnt, PHP_EOL;
}

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

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

for ($i = 0; $i < $t; $i++) {
  $b = trim(fgets($file));
  $s = explode(" ", trim(fgets($file)));

  sort($s);
  print_r($s);
  $min = $s[0];
	$a = $b;

  for ($j = 0; $j < $b; $j++) {
    if ($min == $s[$j]) { $a--; }
    else { break; }
  }
  echo $a.PHP_EOL;
}

?>

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

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

for ($i = 0; $i < $t; $i++) {
  $b = trim(fgets($file));
  $s = explode(" ", trim(fgets($file)));

  $r = array_unique($s);
  $res = 0;
  for ($j = 1; $j < count($r); $j++) {
    $res += $j;
  }
  echo $res.PHP_EOL;
}

?>


Right now you are to solve a very, very simple problem — to crack the safe. Four positive integers stand one by one on a circle protecting the safe. You know that to unlock this striking safe you have to make all four numbers equal to one. Operations are as follows: you may choose two adjacent numbers and increase both by one; you may choose two adjacent even numbers and divide both by two. Nothing else. Crack the safe!

The single line of the input contains four space-separated integer positive numbers not greater than 109 each — four numbers on the circle in consecutive order.

The output should contain "-1" (quotes for clarity) if the safe is secure, that is it's impossible to crack it. Otherwise, output should contain the sequence of operations (one operations per line) leading to unlocking the safe. You don't have to minimize the number of operations, but it should not exceed 1000. To make things clear, assume numbers stand on positions 1 through 4. Each operation is encoded by two symbols. If the following operation is dividing then first symbol is '/'; otherwise it's '+' (addition). The second symbol is the position of the first number in pair in consecutive order. (see samples for clarification). If there are several solutions, output any of them.


Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?

The first line of the input contains two integers n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ 1000) — the number of friends and the height of the fence, respectively. The second line contains n integers ai (1 ≤ ai ≤ 2h), the i-th of them is equal to the height of the i-th person.

Print a single integer — the minimum possible valid width of the road.

NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.

<?php
$n=readline();
$n_h=explode(' ',$n);
$num=$n_h[0];
$height=$n_h[1];
$friends=readline();
$arr=explode(' ',$friends);
$r=0;
for($i=0;$i<$num;$i++){
    if($arr[$i]>$height)
    $r+=2;
    else
    $r+=1;
}
echo $r;

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

<?php

list($count, $height) = explode(" ", trim(fgets(STDIN)));
$friends = explode(" ", trim(fgets(STDIN)));

$result = 0;

foreach ($friends as $friend) {
    $result += $friend > $height ? 2 : 1;
}

echo $result;

<?php
$arr = [];

for ($i=0; $i < 2; $i++) {
        $arr[$i] = readline();
}

// Output
//print_r($arr);
$arr[0];
$output = 0;

$pieces = explode(" ", $arr[0]);

$sec = explode(" ", $arr[1]);
  for($i = 0; $i < $pieces[0] ; $i++){

     if($sec[$i] > $pieces[1]){
        $output = $output+2;
     }else{
        $output += 1;
     }
 }

 echo   "\n". $output;
?>

<?php
$input1 = readline();
$input2 = readline();

$line1 = (explode(" ",$input1));

$line2 = (explode(" ",$input2));

$n = $line1[0];
$h = $line1[1];
$w = 0;

foreach ($line2 as $f) {
    if($f > $h) {
        $w += 2;
    } else {
        $w += 1;
    }
}

echo $w;

?>

<?php
$lines  = @file("php://stdin");
$info = explode(' ', $lines[0]);
$friends = explode(' ', $lines[1]);

$fn = $info[0];
$h = $info[1];

$w = $fn;

foreach($friends as $friend)
    if(intval($friend) > $h) $w++;

echo $w;

<?php
/**
 * Created by PhpStorm.
 * User: OSAMA
 * Date: 6/12/2019
 * Time: 3:38 PM
 */

$input="";
$dir = fopen("php://stdin", 'r');;
while (!feof($dir)) $input .= fgets($dir) ." ";
$input = explode(' ' , trim($input));
 list($n,$h)= array_slice($input,0,2);
$heights = array_slice($input,2);
$width=0;
for ($i=0 ,$c=count($heights); $i<$c ;$i++){
    if ((int)$heights[$i] > (int)$h ){
        $width += 2;
    }else{
        $width+=1;
    }
}
echo $width;

<?php
$dir = fopen("php://stdin", 'r');;
$input= file('php://stdin');
 list($n,$h)= explode(' ',$input[0]);
 $heights=explode(' ' ,$input[1]);
$width=0;
for ($i=0 ,$c=count($heights); $i<$c ;$i++){
    if ((int)$heights[$i] > (int)$h ){
        $width += 2;
    }else{
        $width += 1;
    }
}
echo $width;

<?php

//=====================================
// link: https://codeforces.com/contest/677/problem/A
//=====================================
$width = 0;

$input = new Input(['fence', 'heights']);

$fence = $input->fence[1];

foreach ($input->heights as $key => $height) {
    $width += ($height > $fence) ? 2 : 1;
}

echo $width . "\n";

//=====================================
// Per-defined helpers
//=====================================
class Input
{
    public $inputs = [];

    public function __construct(array $input_titles = ['line'])
    {
        $this->getInputs($input_titles);
    }

    private function getInputs($input_titles)
    {
        for ($i=0; $i < count($input_titles); $i++) {
            $this->inputs[$input_titles[$i]] = explode(' ', trim(fgets(STDIN)));
        }
    }

    public function __get($name)
    {
        return $this->inputs[$name];
    }
}

<?php
    fscanf(STDIN, " %d %d", $n, $h);
    $arr = explode(" ", trim(fgets(STDIN)));
    $k = 0;
        for ($i = 0; $i < $n; $i++){
            if ($arr[$i] > $h){
                $k = $k+2;
            }
            else $k = $k+1;
        }
        echo $k;

<?php
$str_nh = explode(" ", trim(fgets(STDIN)));
$n = $str_nh[0];
$h = $str_nh[1];
$str_ai = explode(" ", trim(fgets(STDIN)));
$w = 0;
for ($i = 0; $i < $n; $i++) {
    if ($str_ai[$i] > $h) {
        $w += 2;
    } else {
        $w += 1;
    }
}
print $w;
?>

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

$COUNT = 0;
foreach (input() as $line) {
    if ($COUNT == 0) {
        list($n, $s) = explode(' ', $line);
        ++$COUNT;
        continue;
    }
    $hs = array_map('intval', explode(' ', $line));
    $w = 0;
    for($i = 0; $i < count($hs);++$i) {
        if ($hs[$i] > $s) {
            $w += 2;
        }
        else {
            $w += 1;
        }
    }

    echo $w;

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

<?php
// http://codeforces.com/problemset/problem/691/A
$handle = fopen ("php://stdin", "r");

$arr_temp1 = fgets($handle);
$arr1 = explode(" ",$arr_temp1);
$arr1 = array_map('intval', $arr1);
$h = $arr1[1];

$arr_temp = fgets($handle);
$arrInput = explode(" ",$arr_temp);
$arr = array_map('intval', $arrInput);
$total = 0;
foreach ($arr as $height) {
	$s = $height > $h ? 2 : 1;
	$total += $s;
}
echo $total;

?>

<?php
fscanf(STDIN,"%d %d",$n,$h);
$line=trim(fgets(STDIN));
$array=explode(' ',$line);
$count=0;
for($i=0;$i<$n;$i++)
{
	if($array[$i]<=$h)
		$count++;
	else
		$count+=2;
}
echo $count;
//print_r($singleValue);

<?php
$n = readline();
$height_friends = readline();
//$n = '10 420';
$n = explode(' ', $n);
$quantity = $n[0];
$height_fence = $n[1];
//$height_friends = '214 614 297 675 82 740 174 23 255 15';
$height_friends = explode(' ', $height_friends);
$sum = 0;
foreach ($height_friends as $v){
    if ($v <= $height_fence ){
        $sum++;
    } else {
        $sum = $sum + 2;
    }
}
echo $sum;

<?php

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

$row = explode(' ', fgets($in)); // [0 => n, 1 => h]
$ans = 0;

array_map(function($item) {
    global $ans, $row;
    $ans += intval($item) > intval($row[1]) ? 2 : 1;
}, explode(' ', fgets($in)));

echo $ans;

?>

<?php

function gaber($n , $h , $arr)
{
     $sum = 0 ;
     for($i=0 ; $i<$n ; $i++)
     {
          if( $arr[$i] <= $h )
          {
               $sum++ ;
          }
          else{
               $sum += 2 ;
          }
     }
     echo $sum ;
}

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

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

$result = gaber( $n , $h , $arr )  ;

fwrite ( $stdout , $result . "\n" ) ;

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

?>

<?php

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

$members = array();

while (! feof( $file ) )
{
   $members[] = fgets($file);
}

$n1 = array() ;
$n1 = explode( ' ' , $members[0]  ) ;

$n2 = array() ;
$n2 = explode( ' ' , $members[1]  );

$s = 0 ;

for($i=0 ; $i<count($n2) ; $i++)
{
	if( (int) $n2[$i] <= (int)$n1[1] )
	{
	     $s = $s + 1 ;
	}
	else
	{
	     $s = $s + 2 ;
	}

}

echo $s ;

?>

<?php

$input =  rtrim(fgets(STDIN));
$first_row = explode(' ', $input);
$number_friends = (int)$first_row[0];
$height_fence   = (int)$first_row[1];

$road_width = 0;

$second_input = rtrim(fgets(STDIN));
$friends_height = explode(' ', $second_input);

foreach ($friends_height as $friend_height) {
    $result = ($friend_height<=$height_fence) ? 1 : 2;
    $road_width+=$result;
}

echo($road_width);

<?php

$input =  rtrim(fgets(STDIN));
$first_row = explode(' ', $input);
$number_friends = (int)$first_row[0];
$height_fence   = (int)$first_row[1];

$road_width = 0;

$second_input = rtrim(fgets(STDIN));
$friends_height = explode(' ', $second_input);

foreach ($friends_height as $friend_height) {
    $road_width += ($friend_height<=$height_fence) ? 1 : 2;
}

echo($road_width);

<?php
  list($n, $h) = explode(' ', trim(fgets(STDIN)));
  $ans = 0;
  $a = explode(' ', trim(fgets(STDIN)));
  for ($i = 0; $i < $n; $i++) {
    if ($a[$i] > $h) {
      $ans += 2;
    } else {
      $ans++;
    }
  }
  fprintf(STDOUT, "%d\n", $ans);
?>

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$ar = explode(" ",$s);
$amigos = $ar[0];
$h = $ar[1];

$s =  trim(fgets($stdin));
$heights = explode(" ",$s);
$w=$amigos;
foreach($heights as $height){
	if($height>$h){
		$w+=1;
	}
}
echo $w;

?>

<?php

$input = rtrim(fgets(STDIN));
$raw   = explode(' ', $input);
$countFriends = (int)$raw[0];
$fenceHeight  = (int)$raw[1];

$answer = 0;
$input = rtrim(fgets(STDIN));
$raw   = explode(' ', $input);
foreach ($raw as $height) {
    if ($height > $fenceHeight) {
        $answer += 2;
    } else {
        $answer += 1;
    }
}

echo $answer . PHP_EOL;

<?php
$friendsAndFencsHigth = fgets(STDIN);
$friedsHeight = fgets(STDIN);
$friedsHeight = trim($friedsHeight);
$friendsAndFencsHigth = trim($friendsAndFencsHigth);

$friedsHeight = explode(' ', $friedsHeight);
// тут массив высот друзей выглядит нормально

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

// number of friends and height of fence should be a variables
list($howManyFriends, $fenceHeight) = $friendsAndFencsHigth;

$friedsHeight = array_map('intval', $friedsHeight);
$fenceHeight = intval($fenceHeight);

$roadWidth = 0;

for ($i=0; $i < $howManyFriends; $i++) {
	// а тут массив друзей вообще выдает Array1
	if($friedsHeight[$i] > $fenceHeight){
		$roadWidth += 2;
	} else {
		$roadWidth++;
	}
}

print_r($roadWidth);

<?
list($n,$h) = explode(' ', trim(fgets(STDIN)));
$arr = explode(' ', trim(fgets(STDIN)));
$ans = 0;
for($i=0; $i<$n; $i++)
 $ans +=$arr[$i] > $h ? 2: 1;
echo $ans;
?>

<?
$IN = fopen('php://stdin','r');
list($n,$h) = explode(' ', trim(fgets(STDIN)));
$arr = explode(' ', trim(fgets(STDIN)));
$ans = 0;
foreach($arr as $val)
 $ans +=$val > $h ? 2: 1;
print $ans;

<?php

$var =explode(" ", readline());
$arr =explode(" ", readline());
$count = 0;

foreach ($arr as  $value) {
	if ( $value <= $var[1]){
		$count++;
	}else{
		$count = $count+2;
	}
}
echo $count;

<?php

$zabor = explode(' ' , readline());
$length = explode(' ' , readline());

$counter = 0;

foreach($length as $elem) {
    if($elem > $zabor[1]) {
        $counter += 2;
    } else $counter++;
}
echo $counter;

<?php

$result = trim(fgets(STDIN));
list($n, $h) = explode(' ',$result);
$people = trim(fgets(STDIN));
$people = explode(' ', $people);
$w = 0;
foreach ($people as $p) {
    if ($p <= $h) {
        $w++;
    } else {
        $w += 2;
    }
}

echo $w . "\n";

<?php
  fscanf(STDIN,"%d %d",$n,$x);
  $ans=0;
  $a = explode(' ', trim(fgets(STDIN)));
  for($i=0;$i<$n;$i++){
	  $ans+= floor($a[$i]/$x);
	  if($a[$i]%$x!=0)
		  $ans++;
  }
  fprintf(STDOUT,"%d\n",$ans);
 ?>

<?php
$arr = [];

for ($i=0; $i < 2; $i++) {
        $arr[$i] = readline();
}

// Output
//print_r($arr);
$arr[0];
$output = 0;

$pieces = explode(" ", $arr[0]);

$sec = explode(" ", $arr[1]);
  for($i = 0; $i < $pieces[0] ; $i++){
        print_r($sec[$i]  );
     if($sec[$i] > $pieces[1]){
        $output = $output+2;
     }else{
        $output += 1;
     }
 }

 echo   "\n". $output;
?>

<?php

$dir = fopen("php://stdin", 'r');
 $input= stream_get_contents($dir);
 list($firstLine,$secondLine)= explode('\n',$input);
 list($n,$h)=explode(' ' , trim($firstLine));
$heights = explode(' ', trim($secondLine));
$width=0;
foreach ($heights as $height){
    if ($height > $h ){
        $width = $width + 2;
    }else{
        $width ++;
    }
}
echo $width;

<?php
/**
 * Created by PhpStorm.
 * User: OSAMA
 * Date: 6/12/2019
 * Time: 3:38 PM
 */

$dir = fopen("php://stdin", 'r');
 $input= stream_get_contents($dir);
 list($firstLine,$secondLine)= explode('\n',trim($input));
 list($n,$h)=explode(' ' , trim($firstLine));
$heights = explode(' ', trim($secondLine));
$width=0;
foreach ($heights as $height){
    if ($height > $h ){
        $width = $width + 2;
    }else{
        $width ++;
    }
}
echo $width;

<?php
/**
 * Created by PhpStorm.
 * User: OSAMA
 * Date: 6/12/2019
 * Time: 3:38 PM
 */

$dir = fopen("php://stdin", 'r');
$input = explode(' ' , trim(stream_get_contents($dir)));
 list($n,$h)= array_slice($input,0,2);
$heights = array_slice($input,2);
$width=0;
for ($i=0 ,$c=count($heights); $i<$c ;$i++){
    if ((int)$heights[$i] > (int)$h ){
        $width += 2;
    }else{
        $width+=1;
    }
}

echo $width;

<?php
$n = readline();
$height_friends = readline();
//$n = '3 7';
$quantity = $n[0];
$height_fence = $n[-1];
//$height_friends = '4 5 14';
$height_friends = explode(' ', $height_friends);
$sum = 0;
foreach ($height_friends as $v){
    if ($v < $height_fence ){
        $sum++;
    } else {
        $sum = $sum + 2;
    }
}
echo $sum;

<?php
$n = readline();
$height_friends = readline();
//$n = '3 7';
$quantity = $n[0];
$height_fence = $n[-1];
//$height_friends = '4 5 14';
$height_friends = explode(' ', $height_friends);
$sum = 0;
foreach ($height_friends as $v){
    if ($v <= $height_fence ){
        $sum++;
    } else {
        $sum = $sum + 2;
    }
}
echo $sum;

<>php
$n = readline();
$height_friends = readline();
//$n = '3 7';
$quantity = $n[0];
$height_fence = $n[-1];
//$height_friends = '4 5 14';
$height_friends = explode(' ', $height_friends);
$sum = 0;
foreach ($height_friends as $v){
    if ($v <= $height_fence ){
        $sum++;
    } else {
        $sum = $sum + 2;
    }
}
echo $sum;

<?php

$input =  rtrim(fgets(STDIN));
$first_row = explode(' ', $input);
$number_friends = (int)$first_row[0];
$height_fence   = (int)$first_row[1];

$road_width = 0;

$second_input = rtrim(fgets(STDIN));
$friends_height = explode(' ', $second_input);

foreach ($friends_height as $friend_height) {
    $road_width += ($friend_height<$height_fence) ? 1 : 2;
}

echo($road_width);


There are $$$n$$$ astronauts working on some space station. An astronaut with the number $$$i$$$ ($$$1 \le i \le n$$$) has power $$$a_i$$$.An evil humanoid has made his way to this space station. The power of this humanoid is equal to $$$h$$$. Also, the humanoid took with him two green serums and one blue serum.In one second , a humanoid can do any of three actions:  to absorb an astronaut with power strictly less humanoid power;  to use green serum, if there is still one left;  to use blue serum, if there is still one left. When an astronaut with power $$$a_i$$$ is absorbed, this astronaut disappears, and power of the humanoid increases by $$$\lfloor \frac{a_i}{2} \rfloor$$$, that is, an integer part of $$$\frac{a_i}{2}$$$. For example, if a humanoid absorbs an astronaut with power $$$4$$$, its power increases by $$$2$$$, and if a humanoid absorbs an astronaut with power $$$7$$$, its power increases by $$$3$$$.After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $$$2$$$ times.After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $$$3$$$ times.The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally.

The first line of each test contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains integers $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — number of astronauts and $$$h$$$ ($$$1 \le h \le 10^6$$$) — the initial power of the humanoid. The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^8$$$) — powers of astronauts. It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb.

NoteIn the first case, you can proceed as follows:   use green serum. $$$h = 1 \cdot 2 = 2$$$  absorb the cosmonaut $$$2$$$. $$$h = 2 + \lfloor \frac{1}{2} \rfloor = 2$$$  use green serum. $$$h = 2 \cdot 2 = 4$$$  absorb the spaceman $$$1$$$. $$$h = 4 + \lfloor \frac{2}{2} \rfloor = 5$$$  use blue serum. $$$h = 5 \cdot 3 = 15$$$  absorb the spaceman $$$3$$$. $$$h = 15 + \lfloor \frac{8}{2} \rfloor = 19$$$  absorb the cosmonaut $$$4$$$. $$$h = 19 + \lfloor \frac{9}{2} \rfloor = 23$$$

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s,$t] = explode(' ', trim(fgets(STDIN)));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$s = explode(' ', trim(fgets(STDIN)));
//function decr($v){return --$v;}
//$alpha='abcdefghijklmnopqrstuvwxyz';
//$mod=1000000009;
//$mod=1000000007;
//$mod=998244353;
//$a=[];
//$b=[];
$ptns = [
    [2,2,3],
    [2,3,2],
    [3,2,2],
    [3,4],
    [4,3],
    [2,6],
    [6,2],
    [12]
];
for($x=0;$x<$t;$x++){
    [$n, $h1] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    sort($a);
    $max = 0;
    foreach($ptns as $ptn){
        $pi = 0;
        $ok = true;
        $h = $h1;
        for($i=0;$i<$n;$i++){
            if($a[$i] < $h){
                $h += intdiv($a[$i], 2);
            }else{
                if($pi < count($ptn) && $h * $ptn[$pi] > $a[$i]){
                    $h *= $ptn[$pi];
                    $pi++;
                    $h += intdiv($a[$i], 2);
                }else{
                    $ok = false;
                    $max = max($max, $i);
                    break;
                }
            }
            //echo ">>".$h.PHP_EOL;
        }
        if($ok){
            $max = $n;
        }
    }
    $ans[] = $max;
}
echo implode(PHP_EOL, $ans);


You are given two arrays of integers $$$a_1,\ldots,a_n$$$ and $$$b_1,\ldots,b_m$$$.Your task is to find a non-empty array $$$c_1,\ldots,c_k$$$ that is a subsequence of $$$a_1,\ldots,a_n$$$, and also a subsequence of $$$b_1,\ldots,b_m$$$. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, find any. If there are no such arrays, you should report about it.A sequence $$$a$$$ is a subsequence of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero) elements. For example, $$$[3,1]$$$ is a subsequence of $$$[3,2,1]$$$ and $$$[4,3,1]$$$, but not a subsequence of $$$[1,3,3,7]$$$ and $$$[3,10,4]$$$.

The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$)  — the number of test cases. Next $$$3t$$$ lines contain descriptions of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n,m\le 1000$$$)  — the lengths of the two arrays. The second line of each test case contains $$$n$$$ integers $$$a_1,\ldots,a_n$$$ ($$$1\le a_i\le 1000$$$)  — the elements of the first array. The third line of each test case contains $$$m$$$ integers $$$b_1,\ldots,b_m$$$ ($$$1\le b_i\le 1000$$$)  — the elements of the second array. It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ across all test cases does not exceed $$$1000$$$ ($$$\sum\limits_{i=1}^t n_i, \sum\limits_{i=1}^t m_i\le 1000$$$).

For each test case, output "YES" if a solution exists, or "NO" otherwise. If the answer is "YES", on the next line output an integer $$$k$$$ ($$$1\le k\le 1000$$$)  — the length of the array, followed by $$$k$$$ integers $$$c_1,\ldots,c_k$$$ ($$$1\le c_i\le 1000$$$)  — the elements of the array. If there are multiple solutions with the smallest possible $$$k$$$, output any.

NoteIn the first test case, $$$[4]$$$ is a subsequence of $$$[10, 8, 6, 4]$$$ and $$$[1, 2, 3, 4, 5]$$$. This array has length $$$1$$$, it is the smallest possible length of a subsequence of both $$$a$$$ and $$$b$$$.In the third test case, no non-empty subsequences of both $$$[3]$$$ and $$$[2]$$$ exist, so the answer is "NO".

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = explode(" ", trim(fgets(STDIN)));
     $e = explode(" ", trim(fgets(STDIN)));
     $f = array_intersect($d, $e);
     if(count($f) == 0)
     {
          print "NO\n";
     }
     else
     {
          $g = current($f);
          print "YES\n";
          print "1 " . $g . "\n";
     }
}
?>

<?php
fscanf(STDIN,"%d",$t);
while ($t--)
{
	fscanf(STDIN,"%d %d",$n,$m);
	$array1=explode(' ',trim(fgets(STDIN)));
	$array2=explode(' ',trim(fgets(STDIN)));
	if($m>$n)
	{
		$tmp=$array2;
		$array2=$array1;
		$array1=$tmp;
	}
	$flag=0;
    for ($i=0; $i <count($array2); $i++)
    {

    	for ($j=0; $j <count($array1) ; $j++)
    	{
    		if($array2[$i]==$array1[$j])
    		{
    			$flag=1;
    			echo "YES\n1 $array2[$i]\n";
    			break;
    		}
    	}
    	if($flag==1)
    		break;
    }
    if($flag==0)
    	echo "NO\n";

}


You are given two sequences $$$a_1, a_2, \dots, a_n$$$ and $$$b_1, b_2, \dots, b_n$$$. Each element of both sequences is either $$$0$$$, $$$1$$$ or $$$2$$$. The number of elements $$$0$$$, $$$1$$$, $$$2$$$ in the sequence $$$a$$$ is $$$x_1$$$, $$$y_1$$$, $$$z_1$$$ respectively, and the number of elements $$$0$$$, $$$1$$$, $$$2$$$ in the sequence $$$b$$$ is $$$x_2$$$, $$$y_2$$$, $$$z_2$$$ respectively.You can rearrange the elements in both sequences $$$a$$$ and $$$b$$$ however you like. After that, let's define a sequence $$$c$$$ as follows:$$$c_i = \begin{cases} a_i b_i & \mbox{if }a_i > b_i \\ 0 & \mbox{if }a_i = b_i \\ -a_i b_i & \mbox{if }a_i < b_i \end{cases}$$$You'd like to make $$$\sum_{i=1}^n c_i$$$ (the sum of all elements of the sequence $$$c$$$) as large as possible. What is the maximum possible sum?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains three integers $$$x_1$$$, $$$y_1$$$, $$$z_1$$$ ($$$0 \le x_1, y_1, z_1 \le 10^8$$$) — the number of $$$0$$$-s, $$$1$$$-s and $$$2$$$-s in the sequence $$$a$$$. The second line of each test case also contains three integers $$$x_2$$$, $$$y_2$$$, $$$z_2$$$ ($$$0 \le x_2, y_2, z_2 \le 10^8$$$; $$$x_1 + y_1 + z_1 = x_2 + y_2 + z_2 > 0$$$) — the number of $$$0$$$-s, $$$1$$$-s and $$$2$$$-s in the sequence $$$b$$$.

For each test case, print the maximum possible sum of the sequence $$$c$$$.


Given $$$n$$$, find any array $$$a_1, a_2, \ldots, a_n$$$ of integers such that all of the following conditions hold: $$$1 \le a_i \le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.$$$a_1 < a_2 < \ldots <a_n$$$For every $$$i$$$ from $$$2$$$ to $$$n$$$, $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$It can be shown that such an array always exists under the constraints of the problem.

The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$.

For each test case print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the array you found. If there are multiple arrays satisfying all the conditions, print any of them.

NoteIn the first test case, array $$$[1]$$$ satisfies all the conditions.In the second test case, array $$$[2, 3]$$$ satisfies all the conditions, as $$$2<3$$$ and $$$3$$$ is not divisible by $$$2$$$.In the third test case, array $$$[111, 1111, 11111, 111111, 1111111, 11111111, 111111111]$$$ satisfies all the conditions, as it's increasing and $$$a_i$$$ isn't divisible by $$$a_{i-1}$$$ for any $$$i$$$ from $$$2$$$ to $$$7$$$.

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

$t=trim(fgets(STDIN))+1;
while(--$t)
{
	$n=trim(fgets(STDIN));
	for($i=2;$i<=$n+1;++$i)
	{
		echo "$i ";
	}
	echo "\n";
}
?>


Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.  They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.

The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.

After each round, print the current score of the bears.


There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).

For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".

<?php

function rline(): array
{
    return explode(' ', trim(fgets(STDIN)));
}

function pline($var): void
{
    print(strval($var));
    print(PHP_EOL);
}

function plines(array $arr): void
{
    print(implode(PHP_EOL, $arr));
    print(PHP_EOL);
}

function fbool($var): string
{
    return $var ? 'Yes' : 'No';
}

function solve(): void
{
    list($q) = rline();
    $ans = [];
    for ($i = 0; $i < $q; $i++) {
        list($n) = rline();
        $p = rline();

        $one = -1;
        for ($j = 0; $j < $n; $j++) {
            if ($p[$j] == 1) {
                $one = $j;
            }
        }
        $cw = true;
        $ccw = true;
        for ($j = 1; $j < $n; $j++) {
            if ($p[($one + $j) % $n] != 1 + $j) {
                $cw = false;
            }
            if ($p[($one - $j + $n) % $n] != 1 + $j) {
                $ccw = false;
            }
        }

        $subans = $cw || $ccw;

        $ans[] = strtoupper(fbool($subans));
    }

    // print here
    plines($ans);
}

solve();


Let $$$s$$$ be a string of lowercase Latin letters. Its price is the sum of the indices of letters (an integer between 1 and 26) that are included in it. For example, the price of the string abca is $$$1+2+3+1=7$$$.The string $$$w$$$ and the integer $$$p$$$ are given. Remove the minimal number of letters from $$$w$$$ so that its price becomes less than or equal to $$$p$$$ and print the resulting string. Note that the resulting string may be empty. You can delete arbitrary letters, they do not have to go in a row. If the price of a given string $$$w$$$ is less than or equal to $$$p$$$, then nothing needs to be deleted and $$$w$$$ must be output.Note that when you delete a letter from $$$w$$$, the order of the remaining letters is preserved. For example, if you delete the letter e from the string test, you get tst.

The first line of input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The following are descriptions of $$$t$$$ test cases. Each case consists of two lines. The first of them is the string $$$w$$$, it is non-empty and consists of lowercase Latin letters. Its length does not exceed $$$2\cdot10^5$$$. The second line contains an integer $$$p$$$ ($$$1 \le p \le 5\,200\,000$$$). It is guaranteed that the sum of string lengths $$$w$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Output exactly $$$t$$$ rows, the $$$i$$$-th of them should contain the answer to the $$$i$$$-th set of input data. Print the longest string that is obtained from $$$w$$$ by deleting letters such that its price is less or equal to $$$p$$$. If there are several answers, then output any of them. Note that the empty string  — is one of the possible answers. In this case, just output an empty string.

5

abca

2

abca

6

codeforces

1

codeforces

10

codeforces

100

<?php

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

while (($tc--) > 0) {
    $str = trim(fgets(STDIN));
    $target = (int) trim(fgets(STDIN));

    $ar = array(); $id = array();
    $val = 0;
    $ln = strlen($str);

    for ($i = 0; $i < $ln; $i++) {
        $ar[] = $str[$i];
        $id[] = $i;
        $val += ord($str[$i]) - ord("a") + 1;
    }

    array_multisort(
        $ar, SORT_DESC,
        $id
    );

    // var_dump($ar);
    // var_dump($id);
    // var_dump($val);

    $del = array();
    $it = 0;
    while ($val > $target) {
        $val -= ord($ar[$it]) - ord("a") + 1;
        $del[] = $id[$it];
        ++$it;
    }

    // var_dump($val);
    // var_dump($del);

    sort($del);

    $itt = 0;
    for ($i = 0; $i < $ln; $i++) {
        if ($itt < $it) {
            if ($del[$itt] == $i) $itt++;
            else echo($str[$i]);
        }
        else echo($str[$i]);
    }
    echo "\n";
}

<?php
function cval($ch) {
    return ord($ch) - 96 ;
}
function solve($n,$st) {
    $arr = array_map('cval',str_split($st));
    asort($arr);
    $ans = [] ;
    $cur = 0 ;
    foreach ($arr as $k=>$v) {
        if($cur+$v <= $n) {
            $cur += $v ;
            $ans[$k] = chr(96+$v);
        }
        else {
            break ;
        }
    }
    ksort($ans);
    return implode('',$ans);
}

$t = (int) fgets(STDIN);
$ans = [] ;
while($t--) {
    $st = trim(fgets(STDIN));
    $n = (int) fgets(STDIN);
    $ans[] = solve($n,$st);
}
print_r(implode("\n",$ans)) ;

<?php

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

$result = "";

for($i=0; $i < $case; $i++){
	$string_array = str_split(trim(fgets(STDIN)));

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

	$delete_array = array();

	for($j='a'; $j <= 'z'; $j++){
		$now_keys = array_keys($string_array, $j);

		foreach($now_keys as $v){
			$now_price = ord($j) - 96;

			if($now_price > $price){
				break 2;
			}else{
				$price -= $now_price;
				$delete_array[$v] = $j;
			}
		}
	}

	ksort($delete_array);

	$now_result = implode("", $delete_array);

	$result .= $now_result."\n";
}

echo $result;


A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art.First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the track is the sequence of colored blocks, where each block is denoted as the small English letter. Therefore, every coating can be treated as a string.Unfortunately, blocks aren't freely sold to non-business customers, but Ayrat found an infinite number of coatings s. Also, he has scissors and glue. Ayrat is going to buy some coatings s, then cut out from each of them exactly one continuous piece (substring) and glue it to the end of his track coating. Moreover, he may choose to flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating t for his running track. Of course, he also want's to know some way to achieve the answer.

First line of the input contains the string s — the coating that is present in the shop. Second line contains the string t — the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small English letters and their length doesn't exceed 2100.

The first line should contain the minimum needed number of coatings n or -1 if it's impossible to create the desired coating. If the answer is not -1, then the following n lines should contain two integers xi and yi — numbers of ending blocks in the corresponding piece. If xi ≤ yi then this piece is used in the regular order, and if xi > yi piece is used in the reversed order. Print the pieces in the order they should be glued to get the string t.

NoteIn the first sample string "cbaabc" = "cba" + "abc".In the second sample: "ayrat" = "a" + "yr" + "at".