Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that user A sent user B a message at time t1, and user B sent user A a message at time t2. If 0 < t2 - t1 ≤ d, then user B's message was an answer to user A's one. Users A and B are considered to be friends if A answered at least one B's message or B answered at least one A's message.You are given the log of messages in chronological order and a number d. Find all pairs of users who will be considered to be friends.

The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at most 20 characters long, consisting of lowercase letters ('a' ... 'z'), and ti is an integer (0 ≤ ti ≤ 10000). It is guaranteed that the lines are given in non-decreasing order of ti's and that no user sent a message to himself. The elements in the lines are separated by single spaces.

In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.

4 1
vasya petya 1
petya vasya 2
anya ivan 2
ivan anya 4

NoteIn the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.

<?php
function CheckU($a, $b, $Frends){
    $FrendsCount = count($Frends);

    for($i = 0; $i < $FrendsCount; $i++){
        if((($Frends[$i]['a'] == $a) and ($Frends[$i]['b'] == $b)) or
          (($Frends[$i]['a'] == $b) and ($Frends[$i]['b'] == $a))){
            return false;
        }
    }

    return true;
}

$InStr = preg_replace('~[^0-9, ]~', '', fgets(STDIN));
list($n, $d) = explode(' ', $InStr);

$Mes = array();
for($i = 0; $i < $n; $i++){
    $InStr = preg_replace('~[^0-9,a-z, ]~', '', fgets(STDIN));
    list($sender, $to, $time) = explode(' ', $InStr);

    $Mes[$i]['sender'] = $sender;
    $Mes[$i]['to']     = $to;
    $Mes[$i]['time']   = $time;
}

$Frends = array();
$FrendsCount = 0;
for($i = 0; $i < $n; $i++){
    for($j = $i+1; $j < $n; $j++){
        if(($Mes[$i]['sender'] == $Mes[$j]['to']) and
           ($Mes[$i]['to'] == $Mes[$j]['sender']) and
           ($Mes[$j]['time'] - $Mes[$i]['time'] > 0) and
           ($Mes[$j]['time'] - $Mes[$i]['time'] <= $d) and
           (CheckU($Mes[$i]['sender'], $Mes[$i]['to'], $Frends))){

           $Frends[$FrendsCount]['a'] = $Mes[$i]['sender'];
           $Frends[$FrendsCount]['b'] = $Mes[$i]['to'];

           $FrendsCount++;

           break;
        }
    }
}

echo $FrendsCount . "\r\n";
for($i = 0; $i < $FrendsCount; $i++){
    echo $Frends[$i]['a'] . ' ' . $Frends[$i]['b'] . "\r\n";
}
?>

<?php
$n = explode(' ', trim(fgets(STDIN)));
$d = $n[1];
$n = $n[0];

$arr = array();
$result = array();
for($i = 0; $i < $n; $i++)
{
    $tmp = explode(' ', trim(fgets(STDIN)));
    $A = $tmp[0];
    $B = $tmp[1];
    $t = $tmp[2];

    if(count($arr) > 0)
    {
        foreach($arr as $user)
        {
            $diff = $t - $user[2];
            if($B == $user[0] && $A == $user[1] && $diff <= $d && $diff > 0)
            {
                $result[] = $A.' '.$B;
            }
        }
    }

    $arr[] = array($A, $B, $t);
}

$count = count($result);

$txt = '';
$pair = array();
$cnt = 0;

for($i = 0; $i < $count; $i++)
{
    $exp = explode(' ', $result[$i]);
    if(!in_array($exp[0].' '.$exp[1], $pair) && !in_array($exp[1].' '.$exp[0], $pair))
    {
        $txt.= "\n".$result[$i];
        $pair[] = $result[$i];
        $cnt++;
    }
}

echo $cnt;
if($cnt > 0)
    echo $txt;
?>

<?php
$fileOpen = fopen('php://stdin', 'r');
$lines = stream_get_contents($fileOpen);

/*   $lines = '10 2
   fxn ipntr 0
   ipntr fxn 1
   fxn ipntr 1
   pfvpfteadph ipntr 2
   fxn pfvpfteadph 4
   ipntr fxn 4
   pfvpfteadph fxn 5
   fxn pfvpfteadph 5
   pfvpfteadph ipntr 6
   ipntr pfvpfteadph 6';

$lines = '10 2
liazxawm spxwktiqjgs 0
nolq liazxawm 1
liazxawm nolq 2
liazxawm spxwktiqjgs 2
nolq liazxawm 3
spxwktiqjgs liazxawm 3
spxwktiqjgs liazxawm 3
spxwktiqjgs liazxawm 3
spxwktiqjgs nolq 3
nolq spxwktiqjgs 4';
*/
$data = explode("\n", trim($lines) );
$firstLine = explode(" " , $data[0]);
$n = $firstLine[0];
$d = $firstLine[1];
$list = array();
$result = array();
for($i = 1 ; $i <= $n ; $i++)
{
    $friend = explode(" ", trim($data[$i]));
    $list[] = array("first" => $friend[0], "second" => $friend[1], "time" => $friend[2]);
    for($j = 0 ; $j < $i ; $j++)
    {
        if($list[$j]["first"] == $list[$i-1]["second"] && $list[$j]["second"] == $list[$i-1]["first"] && ($list[$i-1]["time"] - $list[$j]["time"]) <= $d && ($list[$i-1]["time"] - $list[$j]["time"]) > 0 )
        {
            $flag = false;
            for($k = 0 ; $k < count($result) ; $k++)
            {
                if($result[$k]["first"] == $list[$i-1]["first"] && $result[$k]["second"] == $list[$i-1]["second"])
                {
                    $flag = true;
                    break;
                }
                else if($result[$k]["second"] == $list[$i-1]["first"] && $result[$k]["first"] == $list[$i-1]["second"])
                {
                    $flag = true;
                    break;
                }
            }
            if(!$flag)
            {
                $result[] = array("first" => $list[$i-1]["first"], "second" => $list[$i-1]["second"]);
            }
        }
    }
}
echo count($result)."\n";
for($i = 0 ; $i < count($result) ; $i++)
{
    echo $result[$i]["first"].' '.$result[$i]["second"];
    if($i != (count($result)-1)) echo "\n";
}
?>

<?php
$s = fopen("php://stdin", 'r');
$data_str = str_replace("\r","\n",stream_get_contents($s));
$data_str = str_replace("\n\n","\n",$data_str);
$data = explode("\n", $data_str);
$fl = isset($data[0]) ? explode(' ', $data[0]) : '0';

$n = $fl[0]; $d = $fl[1];
unset($data[0]);
$friends = array();
foreach ($data as $row){
    $message1 = explode(' ', $row);
    foreach ($data as $row1){
        $message2 = explode(' ', $row1);
        $r = abs($message2[2]-$message1[2]);
        if ($message1[0] == $message2[1] && $message1[1] == $message2[0] && 0 < $r && $r <= $d){
            $f = array($message1[0], $message1[1]);
            $f1 = array($message1[1], $message1[0]);
            if (!in_array($f, $friends) && !in_array($f1, $friends)){
                $friends[] = $f;
            }
        }
    }
}

echo $cnt = count($friends);
echo "\n";
foreach ($friends as $k => $f){
    echo $f[0] . ' ' . $f[1];
    if ( $k != $cnt - 1 ){
        echo "\n";
    }
}

<?php

$stdin = fopen("php://stdin", "r");
$line1 = trim(fgets($stdin));
$line1Array = explode(' ', $line1);
$n = (int)$line1Array[0];
$d = (int)$line1Array[1];

$messages = array();
for($i = 0; $i < $n; $i++) {
    $messages[$i] = trim(fgets($stdin));
    $messages[$i] = explode(' ', $messages[$i]);
}

$cnt = 0;
$results = array();

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

    $name1 = $messages[$i][0];
    $name2 = $messages[$i][1];
    $time = $messages[$i][2];
    for($j = 0; $j < $n; $j++) {
        if($j == $i)continue;

        $str1 = "$name1 ".$messages[$j][0];
        $str2 = $messages[$j][0]." $name1";
        if($messages[$j][1] == $name1 && $messages[$j][0] == $name2 && !in_array($str1, $results) && !in_array($str2, $results)) {
            //echo $i." ".$j.". ".$messages[$j][0]. " ". $messages[$j][1];
            //echo $i." ".$j." ".$messages[$j][2]." ".$time;
            if($j > $i)$diffTime = $messages[$j][2] - $time;
            if($i > $j)$diffTime = $time - $messages[$j][2];
            if($diffTime <= $d && $diffTime != 0) {
                $cnt++;
                $results[] = $messages[$j][0]." ".$messages[$j][1];
            }
        }

    }
}

echo $cnt . PHP_EOL;
foreach($results as $r) {
    echo $r . PHP_EOL;
}

/*
16 10000
xxx petya 1
vasya petya 2
anya petya 5
vasya ivan 8
ivan vasya 9
ivan anya 11
petya vasya 13
petya vasya 14
anya ivan 15
ivan anya 18
xxx anya 20
xxx anya 21
anya xxx 24
anya petya 25
anya petya 26
petya anya 28

2 1
a b 1
b a 3

2 1
a b 0
b a 0
 */

?>

<?php
    $line = trim(fgets(STDIN));
    $line_array=explode(" ",$line);
    $n=intval($line_array[0]);
    $d=intval($line_array[1]);

    $friends_array=array();

    $all=array();
    for($i=0;$i<$n;$i++){
        $line = trim(fgets(STDIN));
        $line_array=explode(" ",$line);
        $all[$i]=array();
        $all[$i][0]=$line_array[0];
        $all[$i][1]=$line_array[1];
        $all[$i][2]=$line_array[2];
        $j=$i-1;
        while ($j>=0){
           if ($all[$i][1]==$all[$j][0] && $all[$i][0]==$all[$j][1] && intval($all[$i][2])-intval($all[$j][2])<=$d && intval($all[$i][2])-intval($all[$j][2])>0){
                $flag=0; $z=0;
               while($z<count($friends_array)){
                 if ($friends_array[$z][0]==$all[$i][0] && $friends_array[$z][1]==$all[$i][1]){$flag=1;}
                 if ($friends_array[$z][1]==$all[$i][0] && $friends_array[$z][0]==$all[$i][1]){$flag=1;}
                  $z++;
               }
               if ($flag==0){array_push($friends_array,array($all[$i][0],$all[$i][1]));}
           }
           $j--;
       }
    }
   echo count($friends_array)."\n";
   for ($i=0;$i<count($friends_array);$i++){
       echo $friends_array[$i][0]." ".$friends_array[$i][1]."\n";
   }
?>

<?php
list($n, $d) = explode(' ', fgets(STDIN));
$a = array();
$r = array();
for ($i = 0; $i < $n; $i++) {
    $t = explode(' ', fgets(STDIN));
    $a[$t[0]][] = array($t[1], $t[2]);
}
foreach ($a as $sender => $recipients) {
    foreach ($recipients as $recipient) {
        $sendTime = $recipient[1];
        $reciever = $recipient[0];
        if (isset($a[$reciever])) {
            foreach ($a[$reciever] as $hisRecievers) {
                if ($hisRecievers[0] === $sender) {
                    if ((($hisRecievers[1] - $sendTime) > 0) && (($hisRecievers[1] - $sendTime) <= $d)) {
                        if (!isset($r[$reciever . ' ' . $sender]) && !isset($r[$sender . ' ' . $reciever])) {
                            $r[$sender . ' ' . $reciever] = 0;
                        }
                    }
                }
            }
        }
    }
}
echo count($r) . "\n";
foreach ($r as $k => $v) {
    echo $k . "\n";
}

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = array(); // сообщение
$g = array(); // время
$l = array(); // друзья
$m = 0; // пар друзей
for($x = 1; $x <= $a; $x++)
{
    list($d, $e, $f) = explode(" ", trim(fgets(STDIN)));
    array_push($c, $d . " " . $e);
    array_push($g, $f);
}
for($x = 0; $x < count($c); $x++)
{
    for($y = 0; $y < count($c); $y++)
    {
        if($x == $y)
        {
            continue;
        }
        else
        {
            list($h, $i) = explode(" ", $c[$y]);
            $j = $i . " " . $h;
            if($c[$x] == $j)
            {
                $k = $g[$y] - $g[$x];
                if(($k > 0) && ($k <= $b))
                {
                    $m++;
                    array_push($l, $j);
                }
            }
        }
    }
}
if($l == TRUE)
{
    print $m . "\n";
}
else
{
    print $m;
}
for($x = 0; $x < count($l); $x++)
{
    if($x == count($l) - 1)
    {
        print $l[$x];
    }
    else
    {
        print $l[$x] . "\n";
    }
}
?>

<?php
$n = explode(' ', trim(fgets(STDIN)));
$d = $n[1];
$n = $n[0];

$arr = array();
$result = array();
for($i = 0; $i < $n; $i++)
{
	$tmp = explode(' ', trim(fgets(STDIN)));
	$A = $tmp[0];
	$B = $tmp[1];
	$t = $tmp[2];

	$found = false;
	if(count($arr) > 0)
	{
		foreach($arr as $user)
		{
			if($B == $user[0] && $user[1] == $A)
			{
				if($t - $user[2] <= $d)
				{
					$result[] = $A.' '.$B;
				}
			}
		}
	}

	$arr[] = array($A, $B, $t);
}

$count = count($result);

$txt = '';
$pair = array();
$cnt = 0;

for($i = 0; $i < $count; $i++)
{
	if(!in_array($result[$i], $pair))
	{
		$txt.= "\n".$result[$i];
		$pair[] = $result[$i];
		$cnt++;
	}
}

echo $cnt;
if($cnt > 0)
	echo $txt;
?>

<?php
$n = explode(' ', trim(fgets(STDIN)));
$d = $n[1];
$n = $n[0];

$arr = array();
$result = array();
for($i = 0; $i < $n; $i++)
{
	$tmp = explode(' ', trim(fgets(STDIN)));
	$A = $tmp[0];
	$B = $tmp[1];
	$t = $tmp[2];

	$found = false;
	if(count($arr) > 0)
	{
		foreach($arr as $user)
		{
			if($B == $user[0] && $user[1] == $A)
			{
				if($t - $user[2] <= $d)
				{
					$result[] = $A.' '.$B;
				}
			}
		}
	}

	$arr[] = array($A, $B, $t);
}

$count = count($result);
echo $count;

if($count > 0)
{
	$pair = array();
	for($i = 0; $i < $count; $i++)
	{
		if(!in_array($result[$i], $pair))
		{
			echo "\n".$result[$i];
			$pair[] = $result[$i];
		}
	}
}
?>

<?php
$n = explode(' ', trim(fgets(STDIN)));
$d = $n[1];
$n = $n[0];

$arr = array();
$result = array();
for($i = 0; $i < $n; $i++)
{
	$tmp = explode(' ', trim(fgets(STDIN)));
	$A = $tmp[0];
	$B = $tmp[1];
	$t = $tmp[2];

	$found = false;
	if(count($arr) > 0)
	{
		foreach($arr as $user)
		{
			if($B == $user[0] && $user[1] == $A)
			{
				if($t - $user[2] <= $d)
				{
					$result[] = $A.' '.$B;
				}
			}
		}
	}

	$arr[] = array($A, $B, $t);
}

$count = count($result);

$txt = '';
$pair = array();
$cnt = 0;

for($i = 0; $i < $count; $i++)
{
	$exp = explode(' ', $result[$i]);
	if(!in_array($exp[0].' '.$exp[1], $pair) && !in_array($exp[1].' '.$exp[0], $pair))
	{
		$txt.= "\n".$result[$i];
		$pair[] = $result[$i];
		$cnt++;
	}
}

echo $cnt;
if($cnt > 0)
	echo $txt;
?>

<?php
$count = fgets(STDIN);
while ($s = fgets(STDIN))
{
    $friends[] = explode(" ", $s);
}
$param = explode(" ", $count);
$num = 0;
for ($i = 0; $i < $param[0]; $i++)
{
    for ($j = 1; $j < $param[0]; $j++)
    {
        $new_buf = $friends[$i][0] . " " . $friends[$i][1];
        $new_buf1 = $friends[$j][0] . " " . $friends[$j][1];

        if ($new_buf == $buf or $new_buf1 == $buf1)
        {
            unset($friends[$j]);
        }
        if ($friends[$i][0] == $friends[$j][1] and $friends[$i][1] == $friends[$j][0])
        {
            $buf = $friends[$i][0] . " " . $friends[$i][1];
            $buf1 = $friends[$j][0] . " " . $friends[$j][1];
            $razn = $friends[$j][2] - $friends[$i][2];
            if ($razn > 0 and $razn <= $param[1])
            {
                $itogfr[] = $friends[$i][1] . " " . $friends[$j][1];
                $num++;
                unset($friends[$j]);
                break;
            }
        }
    }

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

?>

<?php
$count = fgets(STDIN);
while ($s = fgets(STDIN))
{
    $friends[] = explode(" ", $s);
}
$param = explode(" ", $count);
$num = 0;
for ($i = 0; $i < $param[0]; $i++)
{
    for ($j = 1; $j < $param[0]; $j++)
    {
        if ($friends[$i][0] == $friends[$j][1] and $friends[$i][1] == $friends[$j][0])
        {
            $razn = $friends[$j][2] - $friends[$i][2];
            if ($razn > 0 and $razn <= $param[1])
            {
                $itogfr[] = $friends[$i][1] . " " . $friends[$j][1];
                $num++;
                unset($friends[$j]);
                break;
            }
        }
    }

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

?>

<?php
$count = fgets(STDIN);
while ($s = fgets(STDIN))
{
    $friends[] = explode(" ", $s);
}
$param = explode(" ", $count);
$num = 0;
for ($i = 0; $i < $param[0]; $i++)
{
    for ($j = 1; $j < $param[0]; $j++)
    {
        if ($friends[$i][0] == $friends[$j][1] and $friends[$i][1] == $friends[$j][0])
        {
            $razn = $friends[$i + 1][2] - $friends[$i][2];
            if ($razn > 0 and $razn <= $param[1])
            {
                $itogfr[] = $friends[$i][1] . " " . $friends[$j][1];
                $num++;
                unset($friends[$j]);
                break;
            }
        }
    }

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

?>

<?php
$count = fgets(STDIN);
while ($s = fgets(STDIN))
{
    $friends[] = explode(" ", $s);
}
$param = explode(" ", $count);
$num = 0;
for ($i = 0; $i < $param[0]; $i++)
{
    for ($j = 1; $j < $param[0]; $j++)
    {
        if ($friends[$i][0] == $friends[$j][1] and $friends[$i][1] == $friends[$j][0])
        {
            $razn = $friends[$i + 1][2] - $friends[$i][2];
            if ($razn > 0 and $razn <= $param[1])
            {
                $itogfr[] = $friends[$i][1] . " " . $friends[$i + 1][1];
                $num++;
                break;
            }
        }
    }

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

?>

<?php
$count = fgets(STDIN);
while ($s = fgets(STDIN))
{
    $friends[] = explode(" ", $s);
}
$param = explode(" ", $count);
$num = 0;
for ($i = 0; $i < $param[0]; $i++)
{
    for ($j = 1; $j < $param[0]; $j++)
    {
        if ($friends[$i][0] == $friends[$j][1] and $friends[$i][1] == $friends[$j][0])
        {
            $razn = $friends[$i + 1][2] - $friends[$i][2];
            if ($razn > 0 and $razn <= $param[1])
            {
                $itogfr[] = $friends[$i][1] . " " . $friends[$i + 1][1];
                $num++;
                unset($friends[$j]);
                break;
            }
        }
    }

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

?>

<?php
$count = fgets(STDIN);
while ($s = fgets(STDIN))
{
    $friends[] = explode(" ", $s);
}
$param = explode(" ", $count);
$num = 0;
for ($i = 0; $i < $param[0]; $i++)
{
    if ($friends[$i][0] == $friends[$i + 1][1] and $friends[$i][1] == $friends[$i + 1][0])
    {
        $razn = $friends[$i + 1][2] - $friends[$i][2];
        if ($razn > 0 and $razn <= $param[1])
        {
            $itogfr[] = $friends[$i][1] . " " . $friends[$i + 1][1];
            $num++;
        }
    }

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

?>

<?php
$base = array();
$n = '';
$d = '';

for($i = 0; ; $i++)
{
	$line = fgets(STDIN);
	if($i == 0)
	{
		$first = explode(' ', $line);
		$n = $first[0];
		$d = $first[1];
	} else {
		$line = trim($line);
		$base[] = explode(' ', $line);
	}

	if($i == $n)
		break;
}

//var_dump($base);
$friends = array();
$there_is = false;

for($i = 0; $i < count($base); $i++)
	for($j = 0; $j < count($base); $j++)
		if($base[$i][0] == $base[$j][1] && $base[$i][1] == $base[$j][0] && ((($base[$j][2] - $base[$i][2]) <= $d) && ($base[$j][2] - $base[$i][2]) > 0))
		{
			foreach($friends as $pair)
				if(($pair[0] == $base[$i][0] && $pair[1] == $base[$i][1]) || ($pair[0] == $base[$i][1] && $pair[1] == $base[$i][0]))
					$there_is = true;
			if($there_is != true)
				$friends[] = array($base[$i][1], $base[$i][0]);
		}

echo count($friends) . "\n";
foreach($friends as $string)
	echo implode(' ', $string) . "\n";
?>

<?php
$base = array();
$n = '';
$d = '';

for($i = 0; ; $i++)
{
	$line = fgets(STDIN);
	if($i == 0)
	{
		$first = explode(' ', $line);
		$n = $first[0];
		$d = $first[1];
		if($n < 1 || $n > 1000 || $d < 1 || $d > 1000)
			exit(1);
	} else {
		$line = trim($line);
		$base[] = explode(' ', $line);
		$end = end($base);
		if(iconv_strlen($end[0]) > 20 || iconv_strlen($end[1]) > 20)
			exit(1);
	}

	if($i == $n)
		break;
}

//var_dump($base);
$friends = array();
$there_is = false;

for($i = 0; $i < count($base); $i++)
	for($j = 0; $j < count($base); $j++)
		if($base[$i][0] == $base[$j][1] && $base[$i][1] == $base[$j][0] && ((($base[$j][2] - $base[$i][2]) <= $d) && ($base[$j][2] - $base[$i][2]) > 0) && ($base[$i][0] != $base[$i][1]) && $base[$j][2] <= $n)
		{
			foreach($friends as $pair)
				if(($pair[0] == $base[$i][0] && $pair[1] == $base[$i][1]) || ($pair[0] == $base[$i][1] && $pair[1] == $base[$i][0]))
					$there_is = true;
			if($there_is != true)
				$friends[] = array($base[$i][1], $base[$i][0]);
		}

echo count($friends) . "\n";
foreach($friends as $string)
	echo implode(' ', $string) . "\n";

?>

<?php
$base = array();
$n = '';
$d = '';

for($i = 0; ; $i++)
{
	$line = fgets(STDIN);
	if($i == 0)
	{
		$first = explode(' ', $line);
		$n = $first[0];
		$d = $first[1];
	} else {
		if($i == $n+1)
			break;
		$line = trim($line);
		$base[] = explode(' ', $line);
	}
}

$friends = array();

for($i = 0; $i < count($base); $i++)
	for($j = 0; $j < count($base); $j++)
		if($base[$i][0] == $base[$j][1] && $base[$i][1] == $base[$j][0] && ((($base[$j][2] - $base[$i][2]) <= $d) && ($base[$j][2] - $base[$i][2]) > 0))
			$friends[] = $base[$i][1] . ' ' . $base[$i][0] . "\n";

echo count($friends) . "\n";
foreach($friends as $string)
	echo $string;
?>

<?php

$stdin = fopen("php://stdin", "r");
$line1 = trim(fgets($stdin));
$line1Array = explode(' ', $line1);
$n = (int)$line1Array[0];
$d = (int)$line1Array[1];

$messages = array();
for($i = 0; $i < $n; $i++) {
    $messages[$i] = trim(fgets($stdin));
    $messages[$i] = explode(' ', $messages[$i]);
}

$cnt = 0;
$results = array();

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

    $name1 = $messages[$i][0];
    $name2 = $messages[$i][1];
    $time = $messages[$i][2];
    for($j = 0; $j < $n; $j++) {
        if($j == $i)continue;

        $str1 = "$name1 ".$messages[$j][0];
        $str2 = $messages[$j][0]." $name1";
        if($messages[$j][1] == $name1 && $messages[$j][0] == $name2 && !in_array($str1, $results) && !in_array($str2, $results)) {
            //echo $i." ".$j.". ".$messages[$j][0]. " ". $messages[$j][1];
            //echo $i." ".$j." ".$messages[$j][2]." ".$time;
            if(abs($messages[$j][2] - $time) <= $d) {
                $cnt++;
                $results[] = $messages[$j][0]." ".$messages[$j][1];
            }
        }

    }
}

echo $cnt . PHP_EOL;
foreach($results as $r) {
    echo $r . PHP_EOL;
}

/*
16 10000
xxx petya 1
vasya petya 2
anya petya 5
vasya ivan 8
ivan vasya 9
ivan anya 11
petya vasya 13
petya vasya 14
anya ivan 15
ivan anya 18
xxx anya 20
xxx anya 21
anya xxx 24
anya petya 25
anya petya 26
petya anya 28

2 1
a b 1
b a 3

 */

?>

<?php
    $line = trim(fgets(STDIN));
    $line_array=explode(" ",$line);
    $n=intval($line_array[0]);
    $d=intval($line_array[1]);

    $friends_array=array();

    $all=array();
    for($i=0;$i<$n;$i++){
        $line = trim(fgets(STDIN));
        $line_array=explode(" ",$line);
        $all[$i]=array();
        $all[$i][0]=$line_array[0];
        $all[$i][1]=$line_array[1];
        $all[$i][2]=$line_array[2];
        $j=$i-1;
        while ($j>=0){
           if ($all[$i][1]==$all[$j][0] && $all[$i][0]==$all[$j][1] && $all[$i][2]-$all[$j][2]<=$d){
                $flag=0; $z=0;
               while($z<count($friends_array)){
                 if ($friends_array[$z][0]==$all[$i][0] && $friends_array[$z][1]==$all[$i][1]){$flag=1;}
                 if ($friends_array[$z][1]==$all[$i][0] && $friends_array[$z][0]==$all[$i][1]){$flag=1;}
                  $z++;
               }
               if ($flag==0){array_push($friends_array,array($all[$i][0],$all[$i][1]));}
           }
           $j--;
       }
    }
   echo count($friends_array)."\n";
   for ($i=0;$i<count($friends_array);$i++){
       echo $friends_array[$i][0]." ".$friends_array[$i][1]."\n";
   }
?>


Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good.Now she is interested in good sequences. A sequence x1, x2, ..., xk is called good if it satisfies the following three conditions:  The sequence is strictly increasing, i.e. xi < xi + 1 for each i (1 ≤ i ≤ k - 1).  No two adjacent elements are coprime, i.e. gcd(xi, xi + 1) > 1 for each i (1 ≤ i ≤ k - 1) (where gcd(p, q) denotes the greatest common divisor of the integers p and q).  All elements of the sequence are good integers. Find the length of the longest good sequence.

The input consists of two lines. The first line contains a single integer n (1 ≤ n ≤ 105) — the number of good integers. The second line contains a single-space separated list of good integers a1, a2, ..., an in strictly increasing order (1 ≤ ai ≤ 105; ai < ai + 1).

Print a single integer — the length of the longest good sequence.

NoteIn the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4.

<?php
define ('Maxn', 100010);

function cinArray()
{
	$row = explode(" ", trim(fgets(STDIN)));
	return $row;
}
function cin()
{
	$row = cinArray();
	return $row[0];
}
$smallDivisor = array(0);
function getSmallDivisor()
{
	global $smallDivisor;
	$smallDivisor[1] = 1;
	for($i = 2; $i < Maxn; ++$i)
		$isPrim[$i] = true;
	$isPrim[1] = false;
	$top = 0;
	for($i = 2; $i < Maxn; ++$i)
	{
		if($isPrim[$i])
		{
			$s[$top++] = $i;
		   	$smallDivisor[$i] = $i;
		}
		for($j = 0; $j < $top && $s[$j] * $i < Maxn; ++$j)
		{
			$isPrim[$i * $s[$j]] = false;
			$smallDivisor[$i * $s[$j]] = $s[$j];
			if($i % $s[$j] == 0) break;
		}
	}
}
$n = cin();
$a = cinArray();
getSmallDivisor();
$dp = array(0);
for($i = 1; $i <= Maxn; ++$i)
	$dp[$i] = 0;
$ans = 0;
for($i = 0; $i < $n; ++$i)
{
	$ans = max($ans, $temp = solve($a[$i]));
	update($a[$i], $temp);
}
echo $ans."\n";
function solve($v)
{
	global $dp, $smallDivisor;
	$ret = 0;
	while($v > 1)
	{
		$ret = max($ret, $dp[$smallDivisor[$v]]);
		$v = $v / $smallDivisor[$v];
	}
	return $ret + 1;
}

function update($v, $tmp)
{
	global $dp, $smallDivisor;
	while($v > 1)
	{
		$p = $smallDivisor[$v];
		$dp[$p] = max($dp[$p], $tmp);
		$v /= $p;
	}
}
?>


One very important person has a piece of paper in the form of a rectangle a × b.Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?

The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100). Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).

Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.

NoteIn the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.In the third example there is no such pair of seals that they both can fit on a piece of paper.


Maria is the most active old lady in her house. She was tired of sitting at home. She decided to organize a ceremony against the coronavirus.She has $$$n$$$ friends who are also grannies (Maria is not included in this number). The $$$i$$$-th granny is ready to attend the ceremony, provided that at the time of her appearance in the courtyard there will be at least $$$a_i$$$ other grannies there. Note that grannies can come into the courtyard at the same time. Formally, the granny $$$i$$$ agrees to come if the number of other grannies who came earlier or at the same time with her is greater than or equal to $$$a_i$$$.Grannies gather in the courtyard like that.  Initially, only Maria is in the courtyard (that is, the initial number of grannies in the courtyard is $$$1$$$). All the remaining $$$n$$$ grannies are still sitting at home. On each step Maria selects a subset of grannies, none of whom have yet to enter the courtyard. She promises each of them that at the time of her appearance there will be at least $$$a_i$$$ other grannies (including Maria) in the courtyard. Maria can call several grannies at once. In this case, the selected grannies will go out into the courtyard at the same moment of time. She cannot deceive grannies, that is, the situation when the $$$i$$$-th granny in the moment of appearing in the courtyard, finds that now there are strictly less than $$$a_i$$$ other grannies (except herself, but including Maria), is prohibited. Please note that if several grannies appeared in the yard at the same time, then each of them sees others at the time of appearance. Your task is to find what maximum number of grannies (including herself) Maria can collect in the courtyard for the ceremony. After all, the more people in one place during quarantine, the more effective the ceremony!Consider an example: if $$$n=6$$$ and $$$a=[1,5,4,5,1,9]$$$, then:  at the first step Maria can call grannies with numbers $$$1$$$ and $$$5$$$, each of them will see two grannies at the moment of going out into the yard (note that $$$a_1=1 \le 2$$$ and $$$a_5=1 \le 2$$$);  at the second step, Maria can call grannies with numbers $$$2$$$, $$$3$$$ and $$$4$$$, each of them will see five grannies at the moment of going out into the yard (note that $$$a_2=5 \le 5$$$, $$$a_3=4 \le 5$$$ and $$$a_4=5 \le 5$$$);  the $$$6$$$-th granny cannot be called into the yard  — therefore, the answer is $$$6$$$ (Maria herself and another $$$5$$$ grannies).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then test cases follow. The first line of a test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of grannies (Maria is not included in this number). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 2\cdot10^5$$$). It is guaranteed that the sum of the values $$$n$$$ over all test cases of the input does not exceed $$$10^5$$$.

For each test case, print a single integer $$$k$$$ ($$$1 \le k \le n + 1$$$) — the maximum possible number of grannies in the courtyard.

NoteIn the first test case in the example, on the first step Maria can call all the grannies. Then each of them will see five grannies when they come out. Therefore, Maria and five other grannies will be in the yard.In the second test case in the example, no one can be in the yard, so Maria will remain there alone.The third test case in the example is described in the details above.In the fourth test case in the example, on the first step Maria can call grannies with numbers $$$1$$$, $$$2$$$ and $$$3$$$. If on the second step Maria calls $$$4$$$ or $$$5$$$ (one of them), then when a granny appears in the yard, she will see only four grannies (but it is forbidden). It means that Maria can't call the $$$4$$$-th granny or the $$$5$$$-th granny separately (one of them). If she calls both: $$$4$$$ and $$$5$$$, then when they appear, they will see $$$4+1=5$$$ grannies. Despite the fact that it is enough for the $$$4$$$-th granny, the $$$5$$$-th granny is not satisfied. So, Maria cannot call both the $$$4$$$-th granny and the $$$5$$$-th granny at the same time. That is, Maria and three grannies from the first step will be in the yard in total.


Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols sitting on the i-th wire.  Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the i-th wire). Consequently all the birds on the i-th wire to the left of the dead bird get scared and jump up on the wire number i - 1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number i + 1, if there exists no such wire they fly away. Shaass has shot m birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.

The first line of the input contains an integer n, (1 ≤ n ≤ 100). The next line contains a list of space-separated integers a1, a2, ..., an, (0 ≤ ai ≤ 100).  The third line contains an integer m, (0 ≤ m ≤ 100). Each of the next m lines contains two integers xi and yi. The integers mean that for the i-th time Shaass shoot the yi-th (from left) bird on the xi-th wire, (1 ≤ xi ≤ n, 1 ≤ yi). It's guaranteed there will be at least yi birds on the xi-th wire at that moment.

On the i-th line of the output print the number of birds on the i-th wire.

<?php
$a = trim(fgets(STDIN)); // количество проводов
$b = explode(" ", trim(fgets(STDIN))); // птиц на каждом проводе
array_unshift($b, " ");
unset($b[0]);
$c = trim(fgets(STDIN)); // количество подстреленных птиц
for($x = 1; $x <= $c; $x++)
{
    list($d, $e) = explode(" ", trim(fgets(STDIN)));
    if($a == 1)
    {
        if($d == 1)
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
        }
        elseif($d == $a)
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
        }
        else
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
        }
    }
    else
    {
        if($d == 1)
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
            $b[$d + 1] += $g;
        }
        elseif($d == $a)
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
            $b[$d - 1] += $f;
        }
        else
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
            $b[$d - 1] += $f;
            $b[$d + 1] += $g;
        }
    }
}
for($x = 1; $x <= count($b); $x++)
{
    if($x == count($b))
    {
        print $b[$x];
    }
    else
    {
        print $b[$x] . "\n";
    }
}
?>

<?php

//=====================================
// link: http://codeforces.com/contest/294/problem/A
//=====================================

// get inputs
$n_wires        = trim(fgets(STDIN));
$birds_on_wires = explode(' ', trim(fgets(STDIN)));
$shoots         = trim(fgets(STDIN));

// solution
for ($i = 0; $i < $shoots; $i++) {
    list($wire, $bird) = explode(' ', trim(fgets(STDIN)));
    $wire--;

    if ($wire - 1 >= 0) { // bigger than or equal first wire
        $birds_on_wires[$wire - 1] += $bird - 1;
    }

    if ($wire + 1 <= $n_wires - 1) { // smaller than or equal last wire
        $birds_on_wires[$wire + 1] += $birds_on_wires[$wire] - $bird;
    }

    $birds_on_wires[$wire] = 0;
}

foreach ($birds_on_wires as $birds) {
    echo "$birds\n";
}

<?php

//=====================================
// link: http://codeforces.com/contest/294/problem/A
//=====================================

// get inputs
$n_wires        = trim(fgets(STDIN));
$birds_on_wires = explode(' ', trim(fgets(STDIN)));
$shoots         = trim(fgets(STDIN));

// solution
for ($i = 0; $i < $shoots; $i++) {
    list($wire, $bird) = explode(' ', trim(fgets(STDIN)));
    $wire--;

    if (isset($birds_on_wires[$wire - 1])) {
        $birds_on_wires[$wire - 1] += $bird - 1;
    }

    if (isset($birds_on_wires[$wire + 1])) {
        $birds_on_wires[$wire + 1] += $birds_on_wires[$wire] - $bird;
    }

    $birds_on_wires[$wire] = 0;
}

foreach ($birds_on_wires as $birds) {
    echo "$birds\n";
}

<?php

//=====================================
// link: http://codeforces.com/contest/294/problem/A
//=====================================

// get inputs
$n_wires        = trim(fgets(STDIN));
$birds_on_wires = explode(' ', trim(fgets(STDIN)));
$shoots         = trim(fgets(STDIN));

// solution
//
for ($i = 0; $i < $shoots; $i++) {
    list($wire, $bird) = explode(' ', trim(fgets(STDIN)));
    $wire--;

    if (isset($birds_on_wires[$wire - 1])) {
        $birds_on_wires[$wire - 1] += $bird - 1;
    }

    if (isset($birds_on_wires[$wire + 1])) {
        $birds_on_wires[$wire + 1] += $birds_on_wires[$wire] - $bird;
    }

    $birds_on_wires[$wire] = 0;
}

foreach ($birds_on_wires as $birds) {
    echo "$birds\n";
}

<?php

//=====================================
// link: http://codeforces.com/contest/294/problem/A
//=====================================

// get inputs
$n_wires        = trim(fgets(STDIN));
$birds_on_wires = explode(' ', trim(fgets(STDIN)));
$shoots         = trim(fgets(STDIN));

// solution
//
for ($i = 0; $i < $shoots; $i++) {
    list($wire, $bird) = explode(' ', trim(fgets(STDIN)));
    $wire--;

    if ($wire - 1 >= 0) { // bigger than or equal first wire
        $birds_on_wires[$wire - 1] += $bird - 1;
    }

    if ($wire + 1 <= $n_wires - 1) { // smaller than or equal last wire
        $birds_on_wires[$wire + 1] += $birds_on_wires[$wire] - $bird;
    }

    $birds_on_wires[$wire] = 0;
}

foreach ($birds_on_wires as $birds) {
    echo "$birds\n";
}

<?
 $count = fgets(STDIN);
 $counts = explode(' ', trim(fgets(STDIN)));
 $m = fgets(STDIN);
 for ($a=1;$a<=$m;$a++){
  $peow = explode(' ', fgets(STDIN));
  if ($peow[0] == 1) $counts[1] += $counts[0] - $peow[1];
  elseif ($peow[0] == $m) $counts[$m-1] += $peow[1]-1;
  else{
  	$counts[$peow[0]] += $counts[$peow[0]-1] - $peow[1];
  	$counts[$peow[0]-2] += $peow[1]-1;
  }
  $counts[$peow[0]-1] = 0;
 }
 for ($b=0;$b<$count;$b++) echo $counts[$b]."\n";
?>

<?php

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

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

for( $i=0 ; $i<$m ; $i++ )
{
     fscanf( $stdin , "%d %d" , $x , $y ) ;
     $x-- ;
     if( $x == 0 )
     {
          $arr[ $x+1 ] += ( $arr[$x] - $y ) ;
          $arr[$x] = 0 ;
     }
     else if( $x == $n-1 )
     {
          $arr[ $x-1 ] += ( $y - 1 ) ;
          $arr[$x] = 0 ;
     }
     else
     {
          $arr[ $x+1 ] += ( $arr[$x] - $y ) ;
          $arr[ $x-1 ] += ( $y - 1 ) ;
          $arr[$x] = 0 ;
     }
}
for( $i=0 ; $i<$n ; $i++ )
{
     echo $arr[$i] . "\n" ;
}

fwrite($stdout);

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

?>

<?php

$scanner = new Scanner();

$n = $scanner->nextInt();
$a = array();

for ($i = 0; $i < $n; $i ++) {
  $a[] = $scanner->nextInt();
}

$m = $scanner->nextInt();

for ($i = 0; $i < $m; $i ++) {
  $x = $scanner->nextInt();
  $y = $scanner->nextInt();
  $x --;
  if ($x - 1 >= 0) {
    $a[$x-1] += $y - 1;
  }
  if ($x + 1 < $n) {
    $a[$x+1] += $a[$x] - $y;
  }
  $a[$x] = 0;
}

for ($i = 0; $i < $n; $i ++) {
  print $a[$i] . PHP_EOL;
}

class Scanner {
  private $_buffer;
  private $_buffer_size;
  private $_i;

  function __construct() {
    $this->initBuffer();
  }

  function initBuffer() {
    $line = trim(fgets(STDIN));
    $this->_buffer = explode(' ', $line);
    $this->_buffer_size = count($this->_buffer);
    $this->_i = 0;
  }

  function nextInt() {
    if ($this->_buffer_size == 0 || $this->_i >= $this->_buffer_size) {
      $this->initBuffer();
    }
    return (int)$this->_buffer[$this->_i ++];
  }
}

<?php
$a = trim(fgets(STDIN)); // количество проводов
$b = explode(" ", trim(fgets(STDIN))); // птиц на каждом проводе
array_unshift($b, " ");
unset($b[0]);
$c = trim(fgets(STDIN)); // количество подстреленных птиц
for($x = 1; $x <= $c; $x++)
{
    list($d, $e) = explode(" ", trim(fgets(STDIN)));
    if($c == 1)
    {
        if($d == 1)
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
        }
        elseif($d == $a)
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
        }
        else
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
        }
    }
    else
    {
        if($d == 1)
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
            $b[$d + 1] += $g;
        }
        elseif($d == $a)
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
            $b[$d - 1] += $f;
        }
        else
        {
            $f = $e - 1; // слева
            $g = $b[$d] - $e; // справа
            $b[$d] = 0;
            $b[$d - 1] += $f;
            $b[$d + 1] += $g;
        }
    }
}
for($x = 1; $x <= count($b); $x++)
{
    if($x == count($b))
    {
        print $b[$x];
    }
    else
    {
        print $b[$x] . "\n";
    }
}
?>

<?php
$a = trim(fgets(STDIN)); // количество проводов
$b = explode(" ", trim(fgets(STDIN))); // птиц на каждом проводе
array_unshift($b, " ");
unset($b[0]);
$c = trim(fgets(STDIN)); // количество подстреленных птиц
for($x = 1; $x <= $c; $x++)
{
    list($d, $e) = explode(" ", trim(fgets(STDIN)));
    if($d == 1)
    {
        $f = $e - 1; // слева
        $g = $b[$d] - $e; // справа
        $b[$d] = 0;
        $b[$d + 1] += $g;
    }
    elseif($d == $a)
    {
        $f = $e - 1; // слева
        $g = $b[$d] - $e; // справа
        $b[$d] = 0;
        $b[$d - 1] += $f;
    }
    else
    {
        $f = $e - 1; // слева
        $g = $b[$d] - $e; // справа
        $b[$d] = 0;
        $b[$d - 1] += $f;
        $b[$d + 1] += $g;
    }
}
for($x = 1; $x <= count($b); $x++)
{
    if($x == count($b))
    {
        print $b[$x];
    }
    else
    {
        print $b[$x] . "\n";
    }
}
?>

<?
 $count = fgets(STDIN);
 $counts = explode(' ', trim(fgets(STDIN)));
 $m = fgets(STDIN);
 for ($a=1;$a<=$m;$a++){
  $peow = explode(' ', fgets(STDIN));
  if ($peow[0] == 1) $counts[1] += $counts[0] - $peow[1];
  elseif ($peow[0] == $m) $counts[$m-1] += $peow[1]-1;
  else{
  	$counts[$peow[0]] += $counts[$peow[0]-1] - $peow[1];
  	$counts[$peow[0]-2] += $peow[1]-1;
  }
  $counts[$peow[0]-1] = 0;
 }
 for ($b=0;$b<=$m;$b++) echo $counts[$b]."\n";
?>

<?php

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

fscanf($stdin, "%d" , $n ) ;
fscanf( $stdin , "%[^\n]" , $test );
$arr = array_map( 'intval' , preg_split('/ /' , $test , -1 , PREG_SPLIT_NO_EMPTY ) ) ;
fscanf( $stdin , "%d" , $m ) ;
if( $n == 1 )
{
     echo "0" ;
     exit ;
}
for( $i=0 ; $i<$m ; $i++ )
{
     fscanf( $stdin , "%d %d" , $x , $y ) ;
     $x-- ;
     if( $x == 0 )
     {
          $arr[ $x+1 ] += ( $arr[$x] - $y ) ;
          $arr[$x] = 0 ;
     }
     else if( $x == $n-1 )
     {
          $arr[ $x-1 ] += ( $y - 1 ) ;
          $arr[$x] = 0 ;
     }
     else
     {
          $arr[ $x+1 ] += ( $arr[$x] - $y ) ;
          $arr[ $x-1 ] += ( $y - 1 ) ;
          $arr[$x] = 0 ;
     }
}
for( $i=0 ; $i<$n ; $i++ )
{
     echo $arr[$i] . "\n" ;
}

fwrite($stdout);

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

?>

<?php

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

fscanf($stdin, "%d" , $n ) ;
fscanf( $stdin , "%[^\n]" , $test );
$arr = array_map( 'intval' , preg_split('/ /' , $test , -1 , PREG_SPLIT_NO_EMPTY ) ) ;
fscanf( $stdin , "%d" , $m ) ;
if( $n == 1 )
{
     echo "0" ;
     exit ;
}
for( $i=0 ; $i<$m ; $i++ )
{
     fscanf( $stdin , "%d %d" , $x , $y ) ;
     $x-- ;
     if( $x == 0 )
     {
          $arr[ $x+1 ] += ( $arr[$x] - $y ) ;
          $arr[$x] = 0 ;
     }
     else if( $x == $m-1 )
     {
          $arr[ $x-1 ] += ( $y - 1 ) ;
          $arr[$x] = 0 ;
     }
     else
     {
          $arr[ $x+1 ] += ( $arr[$x] - $y ) ;
          $arr[ $x-1 ] += ( $y - 1 ) ;
          $arr[$x] = 0 ;
     }
}
for( $i=0 ; $i<$n ; $i++ )
{
     echo $arr[$i] . "\n" ;
}

fwrite($stdout);

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

?>


You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.

The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field.  The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall.

If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them.


Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!

The first line of the input contains two space-separated integers, n and d (1 ≤ n ≤ 105, ) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively. Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type mi, si (0 ≤ mi, si ≤ 109) — the amount of money and the friendship factor, respectively.

Print the maximum total friendship factir that can be reached.

NoteIn the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.In the second sample test we can take all the friends.

<?php

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

$n = $d = null;
$friends = array();

fscanf($stdin, "%d %d\n", $n, $d);

for ($i = 0; $i < $n; $i++) {
    $m = $s = null;
    fscanf($stdin, "%d %d\n", $m, $s);
    if (isset($friends[$m])) {
        $friends[$m] += $s;
    } else {
        $friends[$m] = $s;
    }
}

$friendsWealth = array_keys($friends);
$max = 0;
$happiness = 0;
$first = false;

sort($friendsWealth);

foreach ($friendsWealth as $key => $wealth) {
    if ($first === false) {
        $happiness = $friends[$wealth];
        $first = $key;
        continue;
    }

    if (abs($friendsWealth[$first] - $wealth) < $d) {
        $happiness += $friends[$wealth];
    } else {
        if ($max < $happiness) {
            $max = $happiness;
        }
        while (abs($friendsWealth[$first] - $wealth) >= $d) {
            $happiness -= $friends[$friendsWealth[$first]];
            $first++;
        }
        $happiness += $friends[$wealth];
    }
}

if ($max < $happiness) {
    $max = $happiness;
}

echo $max;

<?php

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

$n = $d = null;
$friends = array();

fscanf($stdin, "%d %d\n", $n, $d);

for ($i = 0; $i < $n; $i++) {
    $m = $s = null;
    fscanf($stdin, "%d %d\n", $m, $s);
    if (isset($friends[$m])) {
        $friends[$m] += $s;
    } else {
        $friends[$m] = $s;
    }
}

$friendsWealth = array_keys($friends);
$max = 0;
$happiness = 0;
$first = false;

foreach ($friendsWealth as $key => $wealth) {
    if ($first === false) {
        $happiness = $friends[$wealth];
        $first = $key;
        continue;
    }

    if (abs($friendsWealth[$first] - $wealth) <= $d) {
        $happiness += $friends[$wealth];
    } else {
        if ($max < $happiness) {
            $max = $happiness;
        }
        while (abs($friendsWealth[$first] - $wealth) > $d) {
            $happiness -= $friends[$friendsWealth[$first]];
            $first++;
        }
        $happiness += $friends[$wealth];
    }
}

if ($max < $happiness) {
    $max = $happiness;
}

echo $max;

<?php

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

$n = $d = null;
$friends = array();

fscanf($stdin, "%d %d\n", $n, $d);

for ($i = 0; $i < $n; $i++) {
    $m = $s = null;
    fscanf($stdin, "%d %d\n", $m, $s);
    if (isset($friends[$m])) {
        $friends[$m] += $s;
    } else {
        $friends[$m] = $s;
    }
}

$friendsWealth = array_keys($friends);
$max = 0;
$happiness = 0;
$first = false;

foreach ($friendsWealth as $key => $wealth) {
    if ($first === false) {
        $happiness = $friends[$wealth];
        $first = $key;
        continue;
    }

    if (abs($friendsWealth[$first] - $wealth) < $d) {
        $happiness += $friends[$wealth];
    } else {
        if ($max < $happiness) {
            $max = $happiness;
        }
        while (abs($friendsWealth[$first] - $wealth) >= $d) {
            $happiness -= $friends[$friendsWealth[$first]];
            $first++;
        }
        $happiness += $friends[$wealth];
    }
}

if ($max < $happiness) {
    $max = $happiness;
}

echo $max;


Alexey is travelling on a train. Unfortunately, due to the bad weather, the train moves slower that it should!Alexey took the train at the railroad terminal. Let's say that the train starts from the terminal at the moment $$$0$$$. Also, let's say that the train will visit $$$n$$$ stations numbered from $$$1$$$ to $$$n$$$ along its way, and that Alexey destination is the station $$$n$$$.Alexey learned from the train schedule $$$n$$$ integer pairs $$$(a_i, b_i)$$$ where $$$a_i$$$ is the expected time of train's arrival at the $$$i$$$-th station and $$$b_i$$$ is the expected time of departure.Also, using all information he has, Alexey was able to calculate $$$n$$$ integers $$$tm_1, tm_2, \dots, tm_n$$$ where $$$tm_i$$$ is the extra time the train need to travel from the station $$$i - 1$$$ to the station $$$i$$$. Formally, the train needs exactly $$$a_i - b_{i-1} + tm_i$$$ time to travel from station $$$i - 1$$$ to station $$$i$$$ (if $$$i = 1$$$ then $$$b_0$$$ is the moment the train leave the terminal, and it's equal to $$$0$$$).The train leaves the station $$$i$$$, if both conditions are met:   it's on the station for at least $$$\left\lceil \frac{b_i - a_i}{2} \right\rceil$$$ units of time (division with ceiling);  current time $$$\ge b_i$$$. Since Alexey spent all his energy on prediction of time delays, help him to calculate the time of arrival at the station $$$n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of stations. Next $$$n$$$ lines contain two integers each: $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i < b_i \le 10^6$$$). It's guaranteed that $$$b_i < a_{i+1}$$$.  Next line contains $$$n$$$ integers $$$tm_1, tm_2, \dots, tm_n$$$ ($$$0 \le tm_i \le 10^6$$$).

For each test case, print one integer — the time of Alexey's arrival at the last station.

NoteIn the first test case, Alexey arrives at station $$$1$$$ without any delay at the moment $$$a_1 = 2$$$ (since $$$tm_1 = 0$$$). After that, he departs at moment $$$b_1 = 4$$$. Finally, he arrives at station $$$2$$$ with $$$tm_2 = 2$$$ extra time, or at the moment $$$12$$$.In the second test case, Alexey arrives at the first station with $$$tm_1 = 1$$$ extra time, or at moment $$$2$$$. The train, from one side, should stay at the station at least $$$\left\lceil \frac{b_1 - a_1}{2} \right\rceil = 2$$$ units of time and from the other side should depart not earlier than at moment $$$b_1 = 4$$$. As a result, the trains departs right at the moment $$$4$$$.Using the same logic, we can figure out that the train arrives at the second station at the moment $$$9$$$ and departs at the moment $$$10$$$; at the third station: arrives at $$$14$$$ and departs at $$$15$$$; at the fourth: arrives at $$$22$$$ and departs at $$$23$$$. And, finally, arrives at the fifth station at $$$32$$$.


Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password k times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters. The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his n passwords.

Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.

NoteConsider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.

<?php

###### IO ######
error_reporting(E_ALL);
error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function pass_compare($p1, $p2) {
	$l1 = strlen($p1);
	$l2 = strlen($p2);
	if ($l1 > $l2) {
		return 1;
	} elseif ($l1 < $l2) {
		return -1;
	}
	return 0;
}

function getAnswer($is_test = false, $f = false) {
	if ($is_test)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	list($n, $k) = readStringExplodeNum($stream, ' ', true);
	$passList = array();
	for ($i = 0; $i < $n; $i++) {
		$passList[] = readString($stream);
	}

	$validPass = readString($stream);
	usort($passList, 'pass_compare');
	$passPos = range(1, $n);
	$passPos = array_combine($passList, $passPos);
	$posPass = array_combine($passPos, $passList);

	$validPassLength = strlen($validPass);

	$validPassPos = $passPos[$validPass];

	$minPassPos = $maxPassPos = $validPassPos;
	while ($minPassPos > 0 && strlen($posPass[$minPassPos - 1]) == $validPassLength) {
		$minPassPos--;
	}

	while ($maxPassPos < $n && strlen($posPass[$maxPassPos + 1]) == $validPassLength) {
		$maxPassPos++;
	}

	$minfailWaitCount = floor(($minPassPos - 1) / $k);
	$maxfailWaitCount = floor(($maxPassPos - 1) / $k);

	$minWaitTime = $minPassPos + $minfailWaitCount * 5;
	$maxWaitTime = $maxPassPos + $maxfailWaitCount * 5;
	echo "{$minWaitTime} {$maxWaitTime}";
	/* / end body */
}

if (empty($is_test))
	getAnswer();

<?php
	fscanf(STDIN,"%d%d",$N,$K);
	$S = array_fill(0, $N, "");
	for($i=0 ;$i<$N;++$i)
	{
		$S[$i] = trim(fgets(STDIN));
	}
	$T = trim(fgets(STDIN));
	function cmp1($A , $B)
	{
		if(strlen($A)!=strlen($B))
			return strlen($A)<strlen($B)?-1:1;
		return strcmp($A,$GLOBALS['T'])==0?-1:1;
	}
	function cmp2($A , $B)
	{
		if(strlen($A)!=strlen($B))
			return strlen($A)<strlen($B)?-1:1;
		return strcmp($A,$GLOBALS['T'])==0?1:-1;
	}
	usort($S,cmp1);
	for($i=0 ;$i<$N;++$i)
		if(strcmp($S[$i],$T)==0)
			break;
	printf("%d ",(floor($i/$K) * 5 + $i+1 ));
	usort($S,cmp2);
        for($i=0 ;$i<$N;++$i)
        	if($S[$i]==$T)
			break;

	printf("%d ",(floor($i/$K) * 5 + $i+1 ));

?>

<?php

###### IO ######
error_reporting(E_ALL);
error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function pass_compare($p1, $p2) {
	$l1 = strlen($p1);
	$l2 = strlen($p2);
	if ($l1 > $l2) {
		return 1;
	} elseif ($l1 < $l2) {
		return -1;
	}
	return 0;
}

function getAnswer($is_test = false, $f = false) {
	if ($is_test)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	list($n, $k) = readStringExplodeNum($stream, ' ', true);
	$passList = array();
	for ($i = 0; $i < $n; $i++) {
		$passList[] = readString($stream);
	}

	$validPass = readString($stream);
	usort($passList, 'pass_compare');
	$passPos = range(1, $n);
	$passPos = array_combine($passList, $passPos);
	$posPass = array_combine($passPos, $passList);

	$validPassLength = strlen($validPass);

	$validPassPos = $passPos[$validPass];

	$minPassPos = $maxPassPos = $validPassPos;
	while ($minPassPos > 0 && strlen($posPass[$minPassPos - 1]) == $validPassLength) {
		$minPassPos--;
	}

	while ($maxPassPos < $n && strlen($posPass[$maxPassPos + 1]) == $validPassLength) {
		$maxPassPos++;
	}

	$minfailWaitCount = floor($minPassPos / $k);
	$maxfailWaitCount = floor($maxPassPos / $k);

	$minWaitTime = $minPassPos + $minfailWaitCount * 5;
	$maxWaitTime = $maxPassPos + $maxfailWaitCount * 5;
	echo "{$minWaitTime} {$maxWaitTime}";
	/* / end body */
}

if (empty($is_test))
	getAnswer();

<?php
	fscanf(STDIN,"%d%d",$N,$K);
	$S = array_fill(0, $N, "");
	for($i=0 ;$i<$N;++$i)
	{
		$S[$i] = trim(fgets(STDIN));
	}
	$T = trim(fgets(STDIN));
	function cmp1($A , $B)
	{
		if(strlen($A)!=strlen($B))
			return strlen($A)<strlen($B)?-1:1;
		return strcmp($A,$GLOBALS['T'])==0?-1:1;
	}
	function cmp2($A , $B)
	{
		if(strlen($A)!=strlen($B))
			return strlen($A)<strlen($B)?-1:1;
		return strcmp($A,$GLOBALS['T'])==0?1:-1;
	}
	usort($S,cmp1);
	for($i=0 ;$i<$N;++$i)
		if(strcmp($S[$i],$T)==0)
			break;
	printf("%d ",(($i/$K) * 5 + $i+1 ));
	usort($S,cmp2);
        for($i=0 ;$i<$N;++$i)
        	if($S[$i]==$T)
			break;

	printf("%d ",(($i/$K) * 5 + $i+1 ));

?>

<?php
	fscanf(STDIN,"%d%d",$N,$K);
	$S = array_fill(0, $N, "");
	for($i=0 ;$i<$N;++$i)
	{
		$S[$i] = trim(fgets(STDIN));
	}
	$T = trim(fgets(STDIN));
	function cmp1($A , $B)
	{
		if(strlen($A)!=strlen($B))
			return strlen($A)<strlen($B)?-1:1;
		return strcmp($A,$GLOBALS['T'])==0?-1:1;
	}
	function cmp2($A , $B)
	{
		if(strlen($A)!=strlen($B))
			return strlen($A)<strlen($B)?-1:1;
		return strcmp($A,$GLOBALS['T'])==0?1:-1;
	}
	usort($S,cmp1);
	for($i=0 ;$i<$N;++$i)
		if(strcmp($S[$i],$T)==0)
			break;
	printf("%d ",(($i/$K) * 5 + $i+1 ));
	usort($S,cmp2);
        for($i=0 ;$i<$N;++$i)
        	if($S[$i]==$T)
			break;

	printf("%d ",(floor($i/$K) * 5 + $i+1 ));

?>


One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.

The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.

If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).

<?php

$n=(int)fgets(STDIN);

for($i=0;$i<$n;$i++)    {
	list($k,$v)=fscanf(STDIN,"%d %d");
	$ara[$k]=$v;
}

ksort($ara);
$flag=false;
$prev=0;
foreach($ara as $v)    {
	if($prev>$v)    $flag=true;
	$prev=$v;
}

if($flag)    echo "Happy Alex\n";
else    echo "Poor Alex\n";

?>

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

    for ($i = 0 ; $i < $n ; $i ++)
    {
        list($f,$s) = explode(" ",trim(fgets(STDIN)));
        $a[$i] = $f;
        $b[$i] = $s;
    }
    asort($a);
    $ord = array_keys($a);
    $can = false;
    $maxi = -1;
    for ($i = 0 ; $i < $n ; $i ++)
    {
      if ($maxi > $b[$ord[$i]]){
        $can = true;
      }
      $maxi = max($maxi,$b[$ord[$i]]);
    }
    if ($can == true){
        echo("Happy Alex");
    }else{
        echo("Poor Alex");
    }

?>

<?php
    $n = trim(fgets(STDIN));
    $laptops = array();
    for ($i = 0; $i < $n; $i ++) {
        list($a, $b) = explode(' ', trim(fgets(STDIN)));
        $laptops[$a] = $b;
    }
    ksort($laptops);
    $counter = 0;
    foreach ($laptops as $value) {
        if ($counter < $value) {
            $counter = $value;
        }
        else {
            $counter = -1;
            break;
        }
    }
    if ($counter == -1) {
        printf("Happy Alex\n");
    }
    else {
        printf("Poor Alex\n");
    }
?>

<?php
error_reporting("off");
//456A: Laptops
$n = trim(fgets(STDIN));
$laptops = array();
for ($i = 0; $i < $n; $i++) {
	list($a, $b) = explode(" ", trim(fgets(STDIN)));
	$laptops[$a] = $b;
}
ksort($laptops);
$counter = 0;
foreach ($laptops as $value) {
	if ($value > $counter) {
		$counter = $value;
	} else {
		$no = TRUE;
		break;
	}
}
if ($no == TRUE) {
	echo "Happy Alex";
} else {
	echo "Poor Alex";
}
?>

<?php

$n=(int)fgets(STDIN);

for($i=0;$i<$n;$i++)    {
	list($ara[$i][0],$ara[$i][1])=fscanf(STDIN,"%d %d");
}

asort($ara);
$flag=false;
for($i=0;$i<$n-1;$i++)    {

	if($ara[$i][1]>$ara[$i+1][1])    $flag=true;
}

if($flag)    echo "Happy Alex\n";
else    echo "Poor Alex\n";

?>

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

    for ($i = 0 ; $i < $n ; $i ++)
    {
        list($f,$s) = explode(" ",trim(fgets(STDIN)));
        $a[$i] = $f;
        $b[$i] = $s;
    }
    asort($a);
    $ord = array_keys($a);
    $can = false;
    $maxi = -1;
    for ($i = 0 ; $i < $n ; $i ++)
    {
      if ($maxi > $b[$ord[$i]]){
        $can = true;
      }
      $maxi = max($maxi,$b[$ord[$i]]);
    }
    if (can){
        echo("Happy Alex");
    }else{
        echo("Poor Alex");
    }

?>

<?php
    $n = fgets(STDIN);
    $a = array();
    $b = array();
    print_r($a);
    print_r($b);
    for ($i = 0 ; $i < n ; $i ++)
    {
        list($f,$s) = explode(" ",trim(fgets(STDIN)));
        $a[$i] = $f;
        $b[$i] = $s;
    }
    asort($a);
    $ord = array_keys($a);
    print_r($ord);
    $can = false;
    $maxi = -1;
    for ($i = 0 ; $i < n ; $i ++)
    {
      if ($maxi > $b[$ord[$i]]){
        $can = true;
      }
      $maxi = max(maxi,$b[$ord[$i]]);
    }
    if (can){
        echo("Happy Alex");
    }else{
        echo("Poor Alex");
    }

?>

<?php
    $n = fgets(STDIN);
    $a = array();
    $b = array();
    for ($i = 0 ; $i < n ; $i ++)
    {
        list($f,$s) = explode(" ",trim(fgets(STDIN)));
        $a[$i] = $f;
        $b[$i] = $s;
    }
    asort($a);
    $ord = array_keys($a);
    $can = false;
    $maxi = -1;
    for ($i = 0 ; $i < n ; $i ++)
    {
      if ($maxi > $b[$ord[$i]]){
        $can = true;
      }
      $maxi = max(maxi,$b[$ord[$i]]);
    }
    if (can){
        echo("Happy Alex");
    }else{
        echo("Poor Alex");
    }

?>

<?php
    $n = trim(fgets(STDIN));
    $a = array();
    $b = array();
    print($a);
    print($b);
    for ($i = 0 ; $i < $n ; $i ++)
    {
        list($f,$s) = explode(" ",trim(fgets(STDIN)));
        $a[$i] = $f;
        $b[$i] = $s;
    }
    asort($a);
    $ord = array_keys($a);
    $can = false;
    $maxi = -1;
    for ($i = 0 ; $i < $n ; $i ++)
    {
      if ($maxi > $b[$ord[$i]]){
        $can = true;
      }
      $maxi = max($maxi,$b[$ord[$i]]);
    }
    if (can){
        echo("Happy Alex");
    }else{
        echo("Poor Alex");
    }

?>

<?php
    $n = trim(fgets(STDIN));
    $a = array();
    $b = array();
    for ($i = 0 ; $i < $n ; $i ++)
    {
        list($f,$s) = explode(" ",trim(fgets(STDIN)));
        $a[$i] = $f;
        $b[$i] = $s;
    }
    asort($a);
    $ord = array_keys($a);
    $can = false;
    $maxi = -1;
    for ($i = 0 ; $i < $n ; $i ++)
    {
      if ($maxi > $b[$ord[$i]]){
        $can = true;
      }
      $maxi = max(maxi,$b[$ord[$i]]);
    }
    if (can){
        echo("Happy Alex");
    }else{
        echo("Poor Alex");
    }

?>


A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically.

The only line contains string s (1 ≤ |s| ≤ 2·105) consisting of only lowercase Latin letters.

Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes.


A Martian boy is named s — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets happy. For example, if s=«aba», then strings «baobab», «aabbaa», «helloabahello» make him very happy and strings «aab», «baaa» and «helloabhello» do not.However rather than being happy once, he loves twice as much being happy twice! So, when he got string t as a present, he wanted to cut it in two parts (the left part and the right part) so that each part made him happy.Help s determine the number of distinct ways to cut the given string t into two parts in the required manner.

The first line contains string s, consisting of lowercase English letters. The length of string s is from 1 to 1000 letters. The second line contains string t, that also consists of lowercase English letters. The length of string t is from 1 to 106 letters.

Print the sought number of ways to cut string t in two so that each part made s happy.


It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers x and y from the set, such that the set doesn't contain their absolute difference |x - y|. Then this player adds integer |x - y| to the set (so, the size of the set increases by one).If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.

The first line contains an integer n (2 ≤ n ≤ 100) — the initial number of elements in the set. The second line contains n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the set.

Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).

NoteConsider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.

<?php
/** SECTION 0: NOTES **/
/*
Problem:
Codeforces Contest 201 Div 1 Problem A

Author          : chaotic_iak (http://chaoticiak.comlu.com/)
Language        : PHP 5.4
Released under  : CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
Template version: 20130720 (http://chaoticiak.comlu.com/prog/assorted/templates.phps)
                           (http://ideone.com/AV2T2U)
*/

/** SECTION 1: SET UP INPUT HANDLER **/
// 0: Don't output format at all
// 1: Trim newline characters only
// 2: Assume \x00..\x20 (accaw) as delimiters and output as array

if (isset($inputstream)) {$stdin = $inputstream;} else {$stdin = fopen("php://stdin", "r");}
function g($format = 2) {
    global $stdin;
    $input = fgets($stdin);
    if ($format == 0) {return $input;}
    $input = trim($input, "\n\r");
    if ($format == 1) {return $input;}
    $input = trim($input, "\x00..\x20");
    $input = preg_replace("/[\\x00-\\x20]+/", " ", $input);
    return explode(" ", $input);
}

/** SECTION 2: IMPORT FUNCTIONS FROM chaotic_iak'S LIBRARY **/
// none

/** SECTION 3: SOLVING THE PROBLEM **/
function gcd($a,$b) {
	if ($a < $b) {return gcd($b,$a);}
	if ($b == 0) {return $a;}
	return gcd($b, $a % $b);
}

$n = g(1);
$num = g();
$gcd = $num[0];
$max = $num[0];
for ($i = 1; $i < $n; $i++) {
	$gcd = gcd($gcd, $num[$i]);
	$max = ($max > $num[$i]) ? $max : $num[$i];
}
$res = ($max / $gcd) - $n;
if ($res % 2) {echo "Alice";} else {echo "Bob";}


One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold:  x occurs in sequence a.  Consider all positions of numbers x in the sequence a (such i, that ai = x). These numbers, sorted in the increasing order, must form an arithmetic progression. Help Jeff, find all x that meet the problem conditions.

The first line contains integer n (1 ≤ n ≤ 105). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 105). The numbers are separated by spaces.

In the first line print integer t — the number of valid x. On each of the next t lines print two integers x and px, where x is current suitable value, px is the common difference between numbers in the progression (if x occurs exactly once in the sequence, px must equal 0). Print the pairs in the order of increasing x.

NoteIn the first test 2 occurs exactly once in the sequence, ergo p2 = 0.

<?

error_reporting(false);

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

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

fgets($handle);
$aa = explode(" ", trim(fgets($handle)));

$map = array();
$res = array();

foreach($aa as $pos=>$val) {

    if (!isset($map[$val])) {

        $map[$val] = array(
            "last"  => $pos,
            "ok"    => 1,
            "delay" => 0
        );

    } else {

        if ($map[$val]["ok"] == 0) continue;
        if ($map[$val]["delay"]==0) {
            $map[$val]["delay"] =  $pos - $map[$val]["last"];
        }
        else {
            if($pos - $map[$val]["last"]  != $map[$val]["delay"]) $map[$val]["ok"] = 0;
            else $map[$val]["last"] = $pos;
        }

        if ($map[$val]["ok"]) $map[$val]["last"] = $pos;

    }
    //print_r($map);

}

//print_r($map);

ksort($map);

$str = "";
$k = 0;

foreach($map as $key=>$val) {
    if ($val["ok"]) {
        $k++;
        $str.="$key $val[delay]\n";
    }
}

echo "$k\n$str";

?>

<?

error_reporting(false);

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

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

fgets($handle);
$aa = explode(" ", trim(fgets($handle)));

$map = array();
$res = array();

foreach($aa as $pos=>$val) {

    if ($res[$val]) continue;
    if (isset($map[$val])) {

        $res[$val] = $pos - $map[$val];
        unset($map[$val]);

    } else {
        $map[$val] = $pos;
    }
}

foreach($map as &$val) $val = 0;

$res = $res + $map;
ksort($res);
echo count($res)."\n";
//print_r($res);
foreach($res as $k=>$v) {
    echo "$k $v\n";
}

?>

<?

error_reporting(false);

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

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

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

$map = array();
$res = array();

foreach($aa as $pos=>$val) {

    if ($res[$val]) continue;
    if ($map[$val]) {

        $res[$val] = $pos - $map[$val];
        unset($map[$val]);

    } else {
        $map[$val] = $pos;
    }
}

foreach($map as &$val) $val = 0;

$res = $res + $map;
ksort($res);
echo count($res)."\n";
foreach($res as $k=>$v) echo "$k $v\n";

?>


Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — ai during the i-th minute. Otherwise he writes nothing.You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that  and will write down all the theorems lecturer tells.You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.

The first line of the input contains two integer numbers n and k (1 ≤ k ≤ n ≤ 105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake. The second line of the input contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 104) — the number of theorems lecturer tells during the i-th minute. The third line of the input contains n integer numbers t1, t2, ... tn (0 ≤ ti ≤ 1) — type of Mishka's behavior at the i-th minute of the lecture.

Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.

NoteIn the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.


This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You may also refer to the guide on interactive problems: https://codeforces.com/blog/entry/45307.The jury picked an integer $$$x$$$ not less than $$$0$$$ and not greater than $$$2^{14} - 1$$$. You have to guess this integer.To do so, you may ask no more than $$$2$$$ queries. Each query should consist of $$$100$$$ integer numbers $$$a_1$$$, $$$a_2$$$, ..., $$$a_{100}$$$ (each integer should be not less than $$$0$$$ and not greater than $$$2^{14} - 1$$$). In response to your query, the jury will pick one integer $$$i$$$ ($$$1 \le i \le 100$$$) and tell you the value of $$$a_i \oplus x$$$ (the bitwise XOR of $$$a_i$$$ and $$$x$$$). There is an additional constraint on the queries: all $$$200$$$ integers you use in the queries should be distinct.It is guaranteed that the value of $$$x$$$ is fixed beforehand in each test, but the choice of $$$i$$$ in every query may depend on the integers you send.

To give the answer, your program should print one line $$$!$$$ $$$x$$$ with a line break in the end. After that, it should flush the output and terminate gracefully.

NoteThe example of interaction is not correct — you should sumbit exactly $$$100$$$ integers in each query. Everything else is correct.Hacks are forbidden in this problem.


Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.

Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.

NoteIn the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black.


Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place.While playing the game Petya found spell scrolls and now he is about to use them. Let’s describe the way fighting goes on this level:1) The boss has two parameters: max — the initial amount of health and reg — regeneration rate per second.2) Every scroll also has two parameters: powi — spell power measured in percents — the maximal amount of health counted off the initial one, which allows to use the scroll (i.e. if the boss has more than powi percent of health the scroll cannot be used); and dmgi the damage per second inflicted upon the boss if the scroll is used. As soon as a scroll is used it disappears and another spell is cast upon the boss that inflicts dmgi of damage per second upon him until the end of the game.During the battle the actions per second are performed in the following order: first the boss gets the damage from all the spells cast upon him, then he regenerates reg of health (at the same time he can’t have more than max of health), then the player may use another scroll (no more than one per second).The boss is considered to be defeated if at the end of a second he has nonpositive ( ≤ 0) amount of health.Help Petya to determine whether he can win with the set of scrolls available to him and if he can, determine the minimal number of seconds he needs to do it.

The first line contains three integers N, max and reg (1 ≤ N, max, reg ≤ 1000) –– the amount of scrolls and the parameters of the boss. The next N lines contain two integers powi and dmgi each — the parameters of the i-th scroll (0 ≤ powi ≤ 100, 1 ≤ dmgi ≤ 2000).

In case Petya can’t complete this level, output in the single line NO. Otherwise, output on the first line YES. On the second line output the minimal time after which the boss can be defeated and the number of used scrolls. In the next lines for each used scroll output space-separated number of seconds passed from the start of the battle to the moment the scroll was used and the number of the scroll. Scrolls are numbered starting from 1 in the input order. The first scroll is considered to be available to be used after 0 seconds. Output scrolls in the order they were used. It is not allowed to use scrolls after the boss is defeated.

<?php
    //$handle = @fopen("input.txt", "r");
    list($n, $max, $reg) = explode(' ', trim(fgets(STDIN)));

    for ($i = 0; $i < $n; $i++) {
        list($spell[$i][0], $spell[$i][1]) = explode(' ', trim(fgets(STDIN)));
    }

    $cur = $max;
    $sum = 0;
    $sec = 0;
    $spells = 0;

    while (true) {
        $cur -= $sum;
        $cur += $reg;
        $cur = min($max, $cur);
        if ($cur <= 0) {
            break;
        }
        $mpos = 0;
        $mmax = 0;
        $mpow = 0;
        for ($i = 0; $i < $n; $i++) {
            if ((double)($spell[$i][0]) >= (double)((100 * $cur / $max))
                    && $spell[$i][1] > $mmax
                    && !isset($spell[$i][2])) {
                $mmax = $spell[$i][1];
                $mpos = $i;
                $mpow = $spell[$i][0];
            }
        }

        if ($mpow == 0 && $sum <= $reg) {
            echo 'NO';
            return;
        } else if ($mpow != 0) {
            $result[$spells][0] = $sec;
            $result[$spells][1] = $mpos + 1;
            $spells++;
            $spell[$mpos][2] = $sec;
            $sum += $mmax;
        }
        $sec++;
    }

    echo "YES\n";
    echo "$sec $spells\n";
    for ($i = 0; $i < count($result); $i++) {
        echo "{$result[$i][0]} {$result[$i][1]}\n";
    }

<?php
    //$handle = @fopen("input.txt", "r");
    list($n, $max, $reg) = explode(' ', trim(fgets(STDIN)));

    for ($i = 0; $i < $n; $i++) {
        list($spell[$i][0], $spell[$i][1]) = explode(' ', trim(fgets(STDIN)));
    }

    $cur = $max;
    $sum = 0;
    $sec = 0;
    $spells = 0;

    while (true) {
        $cur -= $sum;
        $cur += $reg;
        $cur = min($max, $cur);
        if ($cur <= 0) {
            break;
        }
        $mpos = 0;
        $mmax = 0;
        $mpow = 0;
        for ($i = 0; $i < $n; $i++) {
            if ($spell[$i][0] / 100 >= $cur / $max && $spell[$i][1] > $mmax
                    && !isset($spell[$i][2])) {
                $mmax = $spell[$i][1];
                $mpos = $i;
                $mpow = $spell[$i][0];
            }
        }

        if ($mpow == 0 && $sum <= $reg) {
            echo 'NO';
            return;
        } else if ($mpow != 0) {
            $spells++;
            $spell[$mpos][2]= $sec;
            $sum += $spell[$mpos][1];
        }
        $sec++;
    }

    echo "YES\n";
    echo "$sec $spells\n";
    for ($i = 0; $i < $n; $i++) {
        if (isset($spell[$i][2])) {
            $pos = $i + 1;
            echo "{$spell[$i][2]} {$pos}\n";
        }
    }

<?php
    $handle = @fopen("input.txt", "r");
    list($n, $max, $reg) = explode(' ', trim(fgets(STDIN)));

    for ($i = 0; $i < $n; $i++) {
        list($spell[$i][0], $spell[$i][1]) = explode(' ', trim(fgets(STDIN)));
    }

    $cur = $max;
    $sum = 0;
    $sec = 0;
    $spells = 0;

    while (true) {
        $cur -= $sum;
        $cur += $reg;
        $cur = min($max, $cur);
        if ($cur <= 0) {
            break;
        }
        $mpos = 0;
        $mmax = 0;
        $mpow = 0;
        for ($i = 0; $i < $n; $i++) {
            if ((double)($spell[$i][0]) >= (int)((100 * $cur / $max))
                    && $spell[$i][1] > $mmax
                    && !isset($spell[$i][2])) {
                $mmax = $spell[$i][1];
                $mpos = $i;
                $mpow = $spell[$i][0];
            }
        }

        if ($mpow == 0 && $sum <= $reg) {
            echo 'NO';
            return;
        } else if ($mpow != 0) {
            $spells++;
            $spell[$mpos][2]= $sec;
            $sum += $mmax;
        }
        $sec++;
    }

    echo "YES\n";
    echo "$sec $spells\n";
    for ($i = 0; $i < $n; $i++) {
        if (isset($spell[$i][2])) {
            $pos = $i + 1;
            echo "{$spell[$i][2]} {$pos}\n";
        }
    }

<?php
    //$handle = @fopen("input.txt", "r");
    list($n, $max, $reg) = explode(' ', trim(fgets(STDIN)));

    for ($i = 0; $i < $n; $i++) {
        list($spell[$i][0], $spell[$i][1]) = explode(' ', trim(fgets(STDIN)));
    }

    $cur = $max;
    $sum = 0;
    $sec = 0;
    $spells = 0;

    while (true) {
        $cur -= $sum;
        $cur += $reg;
        $cur = min($max, $cur);
        if ($cur <= 0) {
            break;
        }
        $mpos = 0;
        $mmax = 0;
        $mpow = 0;
        for ($i = 0; $i < $n; $i++) {
            if ((double)($spell[$i][0]) >= (double)(100 * $cur / $max)
                    && $spell[$i][1] > $mmax
                    && !isset($spell[$i][2])) {
                $mmax = $spell[$i][1];
                $mpos = $i;
                $mpow = $spell[$i][0];
            }
        }

        if ($mpow == 0 && $sum <= $reg) {
            echo 'NO';
            return;
        } else if ($mpow != 0) {
            $spells++;
            $spell[$mpos][2]= $sec;
            $sum += $mmax;
        }
        $sec++;
    }

    echo "YES\n";
    echo "$sec $spells\n";
    for ($i = 0; $i < $n; $i++) {
        if (isset($spell[$i][2])) {
            $pos = $i + 1;
            echo "{$spell[$i][2]} {$pos}\n";
        }
    }


You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj.Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments. Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.

Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.

NoteIn the first example the following pairs are considered correct:  (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders;  (3, 2), (4, 2), (3, 5), (4, 5) — touch one border;  (5, 2), (2, 5) — match exactly.

<?php

$n = fgets(STDIN);

$items = [];
$lengths = [];
for ($i = 1; $i <= $n; $i++) {
    $item = explode(' ', fgets(STDIN));
    $items[] = [(int) $item[0], (int) $item[1], $i];
    next($items);
}

usort($items, function($a, $b) {
    return ($a[1] - $a[0]) < ($b[1] - $b[0]);
});

$end = count($items) - 1;
$middle = intdiv($end, 2) + 1;

for ($i = 0; $i < $middle; $i++) {
    $k = $end - $i;
    $big = $items[$i];
    $small = $items[$k];

    if ($k <> $i && $big[0] <= $small[0] && $big[1] >= $small[1]) {
        echo $small[2] . ' ' . $big[2];
        exit;
    }
}

echo '-1 -1';

<?php

$n = fgets(STDIN);

$items = [];
$lengths = [];
for ($i = 1; $i <= $n; $i++) {
    $item = explode(' ', fgets(STDIN));
    $items[] = [(int) $item[0], (int) $item[1], $i];
    next($items);
}

usort($items, function($a, $b) {
    return ($a[1] - $a[0]) < ($b[1] - $b[0]);
});

$end = count($items) - 1;
$middle = intdiv($end, 2) + 1;

for ($i = 0; $i < $middle; $i++) {
    $k = $end - $i;
    $big = $items[$i];
    $small = $items[$k];

    if ($big[0] < $small[0] && $big[1] > $small[1]) {
        echo $small[2] . ' ' . $big[2];
        exit;
    }
}

echo '-1 -1';

<?php

$n = fgets(STDIN);

$items = [];
$lengths = [];
for ($i = 1; $i <= $n; $i++) {
    $item = explode(' ', fgets(STDIN));
    $items[] = [(int) $item[0], (int) $item[1], $i];
    next($items);
}

usort($items, function($a, $b) {
    return ($a[1] - $a[0]) < ($b[1] - $b[0]);
});

$end = count($items) - 1;
$middle = intdiv($end, 2) + 1;

for ($i = 0; $i < $middle; $i++) {
    $k = $end - $i;
    $big = $items[$i];
    $small = $items[$k];

    if ($big[0] <= $small[0] && $big[1] >= $small[1]) {
        echo $small[2] . ' ' . $big[2];
        exit;
    }
}

echo '-1 -1';


You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n) such, that among numbers al,  al + 1,  ...,  ar there are exactly k distinct numbers.Segment [l, r] (1 ≤ l ≤ r ≤ n; l, r are integers) of length m = r - l + 1, satisfying the given property, is called minimal by inclusion, if there is no segment [x, y] satisfying the property and less then m in length, such that 1 ≤ l ≤ x ≤ y ≤ r ≤ n. Note that the segment [l, r] doesn't have to be minimal in length among all segments, satisfying the given property.

The first line contains two space-separated integers: n and k (1 ≤ n, k ≤ 105). The second line contains n space-separated integers a1, a2, ..., an — elements of the array a (1 ≤ ai ≤ 105).

Print a space-separated pair of integers l and r (1 ≤ l ≤ r ≤ n) such, that the segment [l, r] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.

NoteIn the first sample among numbers a1 and a2 there are exactly two distinct numbers.In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.In the third sample there is no segment with four distinct numbers.


You are given an integer $$$n$$$. In one move, you can either multiply $$$n$$$ by two or divide $$$n$$$ by $$$6$$$ (if it is divisible by $$$6$$$ without the remainder).Your task is to find the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ or determine if it's impossible to do that.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow.  The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$).

For each test case, print the answer — the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ if it's possible to do that or -1 if it's impossible to obtain $$$1$$$ from $$$n$$$.

NoteConsider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer $$$15116544$$$:  Divide by $$$6$$$ and get $$$2519424$$$;  divide by $$$6$$$ and get $$$419904$$$;  divide by $$$6$$$ and get $$$69984$$$;  divide by $$$6$$$ and get $$$11664$$$;  multiply by $$$2$$$ and get $$$23328$$$;  divide by $$$6$$$ and get $$$3888$$$;  divide by $$$6$$$ and get $$$648$$$;  divide by $$$6$$$ and get $$$108$$$;  multiply by $$$2$$$ and get $$$216$$$;  divide by $$$6$$$ and get $$$36$$$;  divide by $$$6$$$ and get $$$6$$$;  divide by $$$6$$$ and get $$$1$$$.

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

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

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

        $ans = 0 ;
        $f = true ;
        while($n > 1)
        {
            if($n%3)
            {
                echo "-1\n" ;
                $f = false ;
                break ;
            }

            if($n%6)
            {
                $n *= 2 ;
                $n /= 6 ;
                $ans += 2 ;
            }
            else
            {
                $n /= 6 ;
                $ans ++ ;
            }
        }
        if($f) echo $ans . "\n" ;
    }
?>

<?php

$std_in = STDIN;
fscanf($std_in, "%d\n", $n);
for ($i = 0; $i < $n; $i++) {
    fscanf($std_in, "%d\n", $item);

    $step = 0;
    while ($item > 1) {
        if ($item % 6 == 0) {
            $item = intdiv($item, 6);
            $step++;
        } else if ($item % 2 == 0) {
            echo -1 . PHP_EOL;
            continue 2;
        } else {
            $item *= 2;
            $step++;
        }
    }

    echo $step . PHP_EOL;

}


There is a frog staying to the left of the string $$$s = s_1 s_2 \ldots s_n$$$ consisting of $$$n$$$ characters (to be more precise, the frog initially stays at the cell $$$0$$$). Each character of $$$s$$$ is either 'L' or 'R'. It means that if the frog is staying at the $$$i$$$-th cell and the $$$i$$$-th character is 'L', the frog can jump only to the left. If the frog is staying at the $$$i$$$-th cell and the $$$i$$$-th character is 'R', the frog can jump only to the right. The frog can jump only to the right from the cell $$$0$$$.Note that the frog can jump into the same cell twice and can perform as many jumps as it needs.The frog wants to reach the $$$n+1$$$-th cell. The frog chooses some positive integer value $$$d$$$ before the first jump (and cannot change it later) and jumps by no more than $$$d$$$ cells at once. I.e. if the $$$i$$$-th character is 'L' then the frog can jump to any cell in a range $$$[max(0, i - d); i - 1]$$$, and if the $$$i$$$-th character is 'R' then the frog can jump to any cell in a range $$$[i + 1; min(n + 1; i + d)]$$$.The frog doesn't want to jump far, so your task is to find the minimum possible value of $$$d$$$ such that the frog can reach the cell $$$n+1$$$ from the cell $$$0$$$ if it can jump by no more than $$$d$$$ cells at once. It is guaranteed that it is always possible to reach $$$n+1$$$ from $$$0$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The $$$i$$$-th test case is described as a string $$$s$$$ consisting of at least $$$1$$$ and at most $$$2 \cdot 10^5$$$ characters 'L' and 'R'. It is guaranteed that the sum of lengths of strings over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum |s| \le 2 \cdot 10^5$$$).

For each test case, print the answer — the minimum possible value of $$$d$$$ such that the frog can reach the cell $$$n+1$$$ from the cell $$$0$$$ if it jumps by no more than $$$d$$$ at once.

NoteThe picture describing the first test case of the example and one of the possible answers:In the second test case of the example, the frog can only jump directly from $$$0$$$ to $$$n+1$$$.In the third test case of the example, the frog can choose $$$d=3$$$, jump to the cell $$$3$$$ from the cell $$$0$$$ and then to the cell $$$4$$$ from the cell $$$3$$$.In the fourth test case of the example, the frog can choose $$$d=1$$$ and jump $$$5$$$ times to the right.In the fifth test case of the example, the frog can only jump directly from $$$0$$$ to $$$n+1$$$.In the sixth test case of the example, the frog can choose $$$d=1$$$ and jump $$$2$$$ times to the right.

<?php

$countJump = trim(fgets(STDIN));

for ($i = 0; $i < $countJump; $i++) {
    $coursor = str_split(trim(fgets(STDIN)));
    $m       = 1;
    $c = 1;
    foreach ($coursor as $k => $v) {
        if ($v != 'R') {
            $c++;
            if ($c > $m) {
                $m = $c;
            }
        } else {
            if ($c > $m) {
                $m = $c;
            }
            $c = 1;
        }
    }
    echo $m . "\n";
}

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

	for ($o = 0; $o < $t; $o++) {
		$path = explode("R", trim(fgets(STDIN)));
		$ml = 0;
		for ($i = 0; $i < count($path); $i++)
		{
			$l = strlen($path[$i]);
			if ($l > $ml)
				$ml = $l;
		}
		$ans .= ($ml+1)."\n";
	}

	print $ans;

?>

<?php

$countJump = 6;

for ($i = 0; $i < $countJump; $i++) {
    $coursor = str_split(trim(fgets(STDIN)));
    $m       = 1;
    $c = 1;
    foreach ($coursor as $k => $v) {
        if ($v != 'R') {
            $c++;
            if ($c < $m) {
                $m = $c;
            }
        } else {
            if ($c > $m) {
                $m = $c;
            }
            $c = 1;
        }
    }
    echo $m . "\n";
}

<?php

$countJump = 6;

for ($i = 0; $i < $countJump; $i++) {
    $coursor = str_split(trim(fgets(STDIN)));
    $m       = 1;
    $c = 1;
    foreach ($coursor as $k => $v) {
        if ($v != 'R') {
            $c++;
            if ($c > $m) {
                $m = $c;
            }
        } else {
            if ($c > $m) {
                $m = $c;
            }
            $c = 1;
        }
    }
    echo $m . "\n";
}