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

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

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

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

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

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

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

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

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

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

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

	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	}

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

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

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

	}

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

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

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

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

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

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

	}

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

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

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

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

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

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

	}

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

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

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

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

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

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

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

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

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

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

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

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

	}

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

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

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

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

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

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

	}

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


<?php

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

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

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

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

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

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

?>

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

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

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

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

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

?>

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

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

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

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

?>


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

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

$w = $fn;

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

echo $w;

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

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

<?php

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

$result = 0;

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

echo $result;

<?php
$arr = [];

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

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

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

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

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

 echo   "\n". $output;
?>

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

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

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

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

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

echo $w;

?>

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

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

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

<?php

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

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

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

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

echo $width . "\n";

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

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

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

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

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

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

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

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

    echo $w;

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

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

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

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

?>

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

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

<?php

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

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

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

echo $ans;

?>

<?php

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

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

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

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

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

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

?>

<?php

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

$members = array();

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

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

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

$s = 0 ;

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

}

echo $s ;

?>

<?php

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

$road_width = 0;

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

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

echo($road_width);

<?php

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

$road_width = 0;

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

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

echo($road_width);

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

<?

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

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

?>

<?php

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

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

echo $answer . PHP_EOL;

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

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

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

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

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

$roadWidth = 0;

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

print_r($roadWidth);

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

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

<?php

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

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

<?php

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

$counter = 0;

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

<?php

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

echo $w . "\n";

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

<?php
$arr = [];

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

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

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

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

 echo   "\n". $output;
?>

<?php

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

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

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

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

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

echo $width;

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

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

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

<?php

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

$road_width = 0;

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

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

echo($road_width);


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

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

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

}


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

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


<?php

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

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

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

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

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

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

        $subans = $cw || $ccw;

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

    // print here
    plines($ans);
}

solve();


<?php

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

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

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

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

    array_multisort(
        $ar, SORT_DESC,
        $id
    );

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

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

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

    sort($del);

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

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

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

<?php

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

$result = "";

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

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

	$delete_array = array();

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

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

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

	ksort($delete_array);

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

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

echo $result;


<?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
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

$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
$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
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";
   }
?>


<?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
$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

$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);

?>


<?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;


<?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 - 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

###### 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 ));

?>


<?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 = 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

$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=(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");
    }

?>


<?

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";

?>


<?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";
        }
    }


<?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';


<?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;

}


<?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 = 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

$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";
}


<?php
function oddSet($n2){
    $countOdd = 0;
    $countEven = 0;
    for($i=0;$i<count($n2);$i++){
        if($n2[$i] % 2 === 0){
            $countEven += 1;
            continue;
        }
        $countOdd += 1;
    }
    if($countOdd === $countEven){
        return "Yes\n";
    }
    return "No\n";
}

$t = readline();
$i = 0;
while($i<$t){
    $n = readline();
    $n2 = readline();
    $n2 = explode(" ",$n2);
    print_r(oddSet($n2));
    $i++;
}

<?php

$t = readline();

while($t){
    $n = readline();

    $a = readline();
    $arr = explode(" ",$a);
    $x = TRUE;
    $odd = 0;
    $even = 0;
    for($i = 0; $i< $n*2; $i++){
        if($arr[$i]%2 == 0)
            $even++;
        else $odd++;
    }
    if($odd == $even)
        echo "Yes";
    else echo "No";
    echo PHP_EOL;

    $t--;
}

?>

<?php
function oddSet($n2){
    $countOdd = 0;
    $countEven = 0;
    for($i=0;$i<count($n2);$i++){
        if($n2[$i] % 2 === 0){
            $countEven += 1;
            continue;
        }
        $countOdd += 1;
    }
    if($countOdd === $countEven){
        return "Yes";
    }
    return "No";
}

$t = readline();
$i = 0;
while($i<$t){
    $n = readline();
    $n2 = readline();
    $n2 = explode(" ",$n2);
    print_r(oddSet($n2));
    $i++;
}

<?php

$t = readline();

while($t){
    $n = readline();

    $a = readline();
    $arr = explode(" ",$a);
    $x = TRUE;
    for($i = 0; $i< $n*2; $i+=2){
        if(( $arr[$i] + $arr[$i+1] )%2 == 0){
            $x = FALSE;;
        }
    }
    if($x)
        echo "Yes";
    else echo "No";

    $t--;
}

?>


<?php
	$a = trim( fgets(STDIN)) ; //kol-vo naborov
	for ($x=0; $x <$a ; $x++) {
		$n = trim (fgets(STDIN)) ;   //$n - kolvo cisel
		$arr = explode(" ", trim(fgets(STDIN)));
		$result = 1;
		for ($y=0; $y < $n -1; $y++) {
			if ($arr[$y] == $arr[$y+1]) {
				$result ++;
			}
		}
		if ($n == $result) {
			print  $n."\n";
		}
		else
		{
			print "1\n";
		}
	}

	/*
$a = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     $d = 1;
     for($y = 0; $y < $b - 1; $y++)
     {
          if($c[$y] == $c[$y + 1])
          {
               $d++;
          }
     }
     if($b == $d)
     {
          echo $b . "\n";
     }
     else
     {
          echo "1\n";
     }
}

*/

?>

<?php
	$a = trim( fgets(STDIN)) ; //kol-vo naborov
	for ($y=0; $y <$a ; $y++) {
		$n = trim (fgets(STDIN)) ;   //$n - kolvo cisel
		$arr = explode(" ", trim(fgets(STDIN)));
		$result = 1;
		for ($y=0; $y < $n -1; $y++) {
			if ($arr[$y] == $arr[$y+1]) {
				$result ++;
			}
		}
		if ($n == $result) {
			print  $n."\n";
		}
		else
		{
			print "1\n";
		}
	}
?>

<?php
	$a = trim( fgets(STDIN)) ; //kol-vo naborov
	for ($y=0; $y <$a ; $y++) {
		$n = trim (fgets(STDIN)) ;   //$n - kolvo cisel
		$arr = explode(" ", (trim(fgets(STDIN))) );
		$result = 1;
		for ($y=0; $y < $n -1; $y++) {
			if ($arr[$y] == $arr[$y+1]) {
				$result ++;
			}
		}
		if ($n == $result) {
			print  $result."\n";
		}
		else
		{
			print "1\n";
		}
	}
?>

<?php
	$a = trim( fgets(STDIN)) ; //kol-vo naborov
	for ($y=0; $y <$a ; $y++) {
		$n = trim (fgets(STDIN)) ;   //$n - kolvo cisel
		$arr = explode(" ", trim(fgets(STDIN)) );
		$result = 1;
		for ($y=0; $y < $n -1; $y++) {
			if ($arr[$y] == $arr[$y+1]) {
				$result ++;
			}
		}
		if ($n == $result) {
			print  $result."\n";
		}
		else
		{
			print "1\n";
		}
	}
?>

<?php
	$a = trim( fgets(STDIN)) ; //kol-vo naborov
	for ($y=0; $y <$a ; $y++) {
		$n = trim (fgets(STDIN)) ;   //$n - kolvo cisel
		$arr = explode(" ", trim(fgets(STDIN)));
		$result = 1;
		for ($y=0; $y < $n -1; $y++) {
			if ($arr[$y] == $arr[$y+1]) {
				$result ++;
			}
		}
		if ($n == $result) {
			print  $result."\n";
		}
		else
		{
			print "1\n";
		}
	}
?>