<?php
// main:
$s1 = readline ();
$s2 = readline ();
// Get their size
$s1l = strlen ($s1);
$s2l = strlen ($s2);
// Reverse both
$s1 = strrev ($s1);
$s2 = strrev ($s2);

// Potentials
$potential_moves = $s1l + $s2l;
$length = ($s1l > $s2l) ? $s2l : $s1l;

// Get valid
$i = 0;
for (; $i < $length; ++$i)
{
        if ($s1[$i] != $s2[$i]) {
                break;
        }
}

// Moves
echo $potential_moves - 2*$i;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
for($j=$t;$j>=1;$j=$j-100) {
 if (substr($a,-$j) == substr($b, -$j)) {
   break;
  }
}

for($i=$j+100;$i>=1;$i--) {
  if ($i <= $t && substr($a,-$i) == substr($b, -$i)) {
    break;
  }
}
echo strlen($a) - $i + strlen($b) - $i;

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = 0;
if(strlen($a) < strlen($b))
{
     $c += strlen($b) - strlen($a);
     $b = substr($b, $c);
}
elseif(strlen($a) > strlen($b))
{
     $c += strlen($a) - strlen($b);
     $a = substr($a, $c);
}
$c += strlen($a) * 2;
for($x = strlen($a) - 1; $x >= 0; $x--)
{
     if($a[$x] == $b[$x])
     {
          $c -= 2;
     }
     else
     {
          break;
     }
}
print $c;
?>

<?php
$str1=trim(fgets(STDIN));
$str2=trim(fgets(STDIN));

if (strlen($str2)>strlen($str1))
{
	$temp=$str2;
	$str2=$str1;
	$str1=$temp;
}

$lstr1=strlen($str1);
$lstr2=strlen($str2);
//echo "$lstr1 $lstr2";
if($str1[$lstr1-1]!=$str2[$lstr2-1])
	echo $lstr1+$lstr2;
else
{
		$diff=$lstr1-$lstr2;
		$count=0;
		for ($i=$diff,$j=0; $i <$lstr1 ; $i++)
		{
		  if($str1[$i]!=$str2[$j++])
		  {
		  	$count+=2;
		  }
		}
		echo $count+$diff."\n";
}

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 100) {
$m = 100;
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j+$m;$i>=$j;$i--) {
  if ($i <= $t && substr($a,-$i) == substr($b, -$i)) {
    break 2;
  }
}
}
}
echo strlen($a) - $i + strlen($b) - $i;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 100) {
$m = 100;
echo $b;
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j;$i<$j+$m;$i++) {
  if (substr($a,-$i) == substr($b, -$i)) {
    $num = $i;
  }
}
break;
}
}
echo strlen($a) - $num + strlen($b) - $num;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 100) {
$m = 100;
echo substr($a,-10);
echo "\n";
echo substr($b,-10);
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j;$i<$j+$m;$i++) {
  if (substr($a,-$i) == substr($b, -$i)) {
    $num = $i;
  }
}
break;
}
}
echo strlen($a) - $num + strlen($b) - $num;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen(a);

for($i=$t;$i<1;$i--) {
  if (substr($a,-$i) == substr($b, -$i)) {
    break;
  }
}

echo strlen($a) - $i + strlen($b) - $i;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 10) {
$m = 10;
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j+$m;$i>=$j;$i--) {
  if ($i <= $t && substr($a,-$i) == substr($b, -$i)) {
    break 2;
  }
}
}
}
echo strlen($a) - $i + strlen($b) - $i;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 100) {
$m = 100;
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j+$m;$i<$j;$i--) {
  if (substr($a,-$i) == substr($b, -$i)) {
    break 2;
  }
}
}
}
echo strlen($a) - $i + strlen($b) - $i;

Last login: Thu Jul 12 09:43:57 on console
xiaoxiaode-Mac-mini:~ eooe$ cd firebase/
xiaoxiaode-Mac-mini:firebase eooe$ cd hahamut/
xiaoxiaode-Mac-mini:hahamut eooe$ l
total 32
drwxr-xr-x  6 eooe  staff   204  7  6 11:04 .
drwxr-xr-x  8 eooe  staff   272  3 23 16:25 ..
-rw-r--r--  1 eooe  staff    54 10  2  2017 .firebaserc
-rw-r--r--  1 eooe  staff  6009 11 29  2017 a.js
-rw-r--r--  1 eooe  staff     3 10  2  2017 firebase.json
drwxr-xr-x  9 eooe  staff   306  7 10 15:15 functions
xiaoxiaode-Mac-mini:hahamut eooe$ cd functions/
xiaoxiaode-Mac-mini:functions eooe$ l
total 7696
drwxr-xr-x    9 eooe  staff      306  7 10 15:15 .
drwxr-xr-x    6 eooe  staff      204  7  6 11:04 ..
-rw-r--r--    1 eooe  staff  3597255  3 27 14:20 go-pear.phar
-rw-r--r--    1 eooe  staff    62023  7 10 15:14 index.js
drwxr-xr-x  351 eooe  staff    11934  3 12 18:20 node_modules
-rw-r--r--    1 eooe  staff   221196  3 12 18:20 package-lock.json
-rw-r--r--    1 eooe  staff      352  3 12 18:25 package.json
-rw-r--r--    1 eooe  staff    17795 10 23  2017 pk.js
-rw-r--r--    1 eooe  staff    22541  6  6 17:47 pk2.js
xiaoxiaode-Mac-mini:functions eooe$ vim index.js
xiaoxiaode-Mac-mini:functions eooe$ firebase deploy --only functions:messages_create

=== Deploying to 'hahamut-8888'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...

Error: Error occurred while parsing your function triggers.

/Users/eooe/firebase/hahamut/functions/index.js:497
                 ) {
                 ^

SyntaxError: Unexpected token )
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:599:28)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11
xiaoxiaode-Mac-mini:functions eooe$ vim index.js
xiaoxiaode-Mac-mini:functions eooe$ firebase deploy --only functions:messages_create

┌──────────────────────────────────────────────┐
│ Update available: 3.19.3 (current: 3.17.6)   │
│ Run npm install -g firebase-tools to update. │
└──────────────────────────────────────────────┘

=== Deploying to 'hahamut-8888'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (842.32 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: current functions in project: abuse, badfriend, bot_message_get, bottalk, chatListCreate, chatListDelete, chatlist_field_update_delete_member_cd, chatlist_field_update_favorite_order, chatlist_field_update_has_chat, chatlist_field_update_is_favorite, chatlist_field_update_is_friend, chatlist_field_update_is_inviting, chatlist_field_update_is_mute, chatlist_field_update_last_read_time, chatlist_field_update_name, chatlist_field_update_noreadnum, chatlist_field_update_related_acg_name, chatlist_field_update_related_c1, chatlist_field_update_type, chatlist_is_mute, crontab, fansbadfriend, fcmToken_change, fcmToken_new, hala_promotion_create, has_new_message, hot_forum, imgthumb, infoChange, info_name_update, isHotForum, is_friendUpdate, messageSend, messages_create, messages_create2, messages_delete, pk, pkRD, pkgirl, pking, pktest, reflashChatlist, sticker_check, sticker_create, sticker_ctime, sticker_delete, sticker_update, testfcm, testpubsub, time5s, userInfo, userNameChange, user_create
i  functions: uploading functions in project: messages_create
i  functions: updating function messages_create...
✔  functions[messages_create]: Successful update operation.

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/hahamut-8888/overview
xiaoxiaode-Mac-mini:functions eooe$ cd -
/Users/eooe/firebase/hahamut
xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php

^C
xiaoxiaode-Mac-mini:hahamut eooe$
xiaoxiaode-Mac-mini:hahamut eooe$
xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
PHP Notice:  Use of undefined constant a - assumed 'a' in /Users/eooe/firebase/hahamut/a.php on line 7

Notice: Use of undefined constant a - assumed 'a' in /Users/eooe/firebase/hahamut/a.php on line 7
6xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
0xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
0xiaoxiaode-Mac-mini:hahamut eooe$ err
-bash: err: command not found
xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
40xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
4west--test
est--est
2xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
west
test
2xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
west
test
PHP Notice:  Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 7

Notice: Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 7
PHP Notice:  Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 7

Notice: Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 7
PHP Notice:  Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 15

Notice: Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 15
PHP Notice:  Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 15

Notice: Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 15
8xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
test
west
PHP Notice:  Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 15

Notice: Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 15
PHP Notice:  Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 15

Notice: Undefined variable: i in /Users/eooe/firebase/hahamut/a.php on line 15
8xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
test
west
6xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
test
west
6xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
test
west
3216xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
test
west
3216xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
test
west
332xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
test
west
2xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
test
west
4xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
test
west
4xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
test
west
432xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
z
z
-2xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
z
z
2
-2xiaoxiaode-Mac-mini:hahamut eooe$
xiaoxiaode-Mac-mini:hahamut eooe$
xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
z
z
-2xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
z
z
1-2xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
z
z
1-2xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
xz
z
1-1xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
z
z
1-2xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
z
z
1-2xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
z
z
1210xiaoxiaode-Mac-mini:hahamut eooe$
xiaoxiaode-Mac-mini:hahamut eooe$
xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
zzzzzzzzzz
61xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
z
z
0xiaoxiaode-Mac-mini:hahamut eooe$ php a.php
west
test
2xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php
xiaoxiaode-Mac-mini:hahamut eooe$ vim a.php

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 100) {
$m = 100;
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j;$i<$j+$m;$i++) {
  if (substr($a,-$i) == substr($b, -$i)) {
    $num = $i;
  }
}
break;
}
}

if( $num == 0 ) {
  for($i=100;$i<=1;$i--) {
    if (substr($a,-$i) == substr($b, -$i)) {
      $num = $i;
      break;
    }
  }
}
echo strlen($a) - $num + strlen($b) - $num;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
for($j=$t;$j>=1;$j=$j-100) {
 if (substr($a,-$j) == substr($b, -$j)) {
   break;
  }
}

for($i=$j+100;$i>=$j;$i--) {
  if ($i <= $t && substr($a,-$i) == substr($b, -$i)) {
    break;
  }
}
echo strlen($a) - $i + strlen($b) - $i;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 100) {
$m = 100;
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j+$m;$i>$j;$i--) {
  if (substr($a,-$i) == substr($b, -$i)) {
    break 2;
  }
}
}
}
echo strlen($a) - $i + strlen($b) - $i;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 100) {
$m = 100;
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j;$i<$j+$m;$i++) {
  if (substr($a,-$i) == substr($b, -$i)) {
    $num = $i;
  }
}
break;
}
}
echo strlen($a) - $num + strlen($b) - $num;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 100) {
$m = 100;
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j;$i<=$j+$m;$i++) {
  if (substr($a,-$i) == substr($b, -$i)) {
    break 2;
  }
}
}
}
echo strlen($a) - $i + strlen($b) - $i;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 100) {
$m = 100;
echo strlen($a).','.substr($a,-10);
echo "\n";
echo strlen($b).','.substr($b,-10);
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j;$i<$j+$m;$i++) {
  if (substr($a,-$i) == substr($b, -$i)) {
    $num = $i;
  }
}
break;
}
}
echo strlen($a) - $num + strlen($b) - $num;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 100) {
$m = 100;
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j+m;$i<=$j;$i--) {
  if (substr($a,-$i) == substr($b, -$i)) {
    break 2;
  }
}
}
}
echo strlen($a) - $i + strlen($b) - $i;

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

$t = (strlen($a) > strlen($b)) ? strlen($b) : strlen($a);
if ($t > 100) {
$m = 100;
}else{
$m = 1;
}
for($j=$t;$j>=1;$j=$j-$m) {
if (substr($a,-$j) == substr($b, -$j)) {
for($i=$j+$m;$i<=$j;$i--) {
  if (substr($a,-$i) == substr($b, -$i)) {
    break 2;
  }
}
}
}
echo strlen($a) - $i + strlen($b) - $i;


<?php

$handle = fopen("php://stdin", "r");
fscanf($handle, '%d', $n);

$max = 0;

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

    fscanf($handle, '%d %d', $x, $y);

    $m = $x + $y;
    if ($m > $max) {
        $max = $m;
    }
}

echo $max;

<?php
	// $in = fopen("input.txt", "r");
	// $out = fopen("output.txt", "w");
	$i = 0;
	$res = -1001000;
	$a = array();

	$n = (int) fgets(STDIN);

	while ($i < $n) {

		$str = fgets(STDIN);
		$a = explode(" ", $str);
		$i++;

		$x = $a[0];
		$y = $a[1];

		if ($x + $y > $res) {
			$res = $x + $y;
		}
	}
	print($res);

	// fclose($in);
	// fclose($out);
 ?>

<?php

fscanf(STDIN, "%d\n", $number);
bcscale(0);

$max = "0";
for ($i = 0; $i < $number; $i++) {
    fscanf(STDIN, "%s %s\n", $x, $y);
    $sum = bcadd($x, $y);
    if (bccomp($sum, $max) > 0) {
        $max = $sum;
    }
}

echo $max;

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

<?php

$handle = fopen("php://stdin", "r");
fscanf($handle, '%d', $n);

$max_x_x = 0;
$max_x_y = 0;

$max_y_x = 0;
$max_y_y = 0;

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

    fscanf($handle, '%d %d', $x, $y);

    if ($x >= $max_x_x) {

        if ($y >= $max_x_y) {
            $max_x_x = $x;
            $max_x_y = $y;
        }
    }

    if ($y >= $max_y_y) {

        if ($x >= $max_y_x) {

            $max_y_x = $x;
            $max_y_y = $y;
        }

    }
}

echo max($max_x_y + $max_x_x, $max_y_x + $max_y_y);


<?php
#1189B
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
sort($arr);
$last = $arr[$n - 1];
for ($i = 0; $i < $n; $i++) {
    $prev = $arr[$n - 2];
    $prevPrev = $arr[$n - 3];
    if ($arr[$i] >= ($prev + $prevPrev)) {
        die('NO');
    }
}
echo 'YES' . PHP_EOL . $arr[$n - 2] . ' ';
unset ($arr[$n - 2]);
echo implode(' ', $arr);

<?php
#1189B
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
sort($arr);
if ($arr[$n - 1] >= ($arr[$n - 2] + $arr[$n - 3])) {
    die('NO');
}
echo 'YES' . PHP_EOL . $arr[$n - 2] . ' ';
unset ($arr[$n - 2]);
echo implode(' ', $arr);

<?php

$n = trim(fgets(STDIN));

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

sort($numbers);

$lastIndex = count($numbers) - 1;

$temp = $numbers[$lastIndex];

$numbers[$lastIndex] = $numbers[$lastIndex-1];
$numbers[$lastIndex-1] = $temp;

$flag = false;

if($numbers[$lastIndex-1] < $numbers[$lastIndex-2] + $numbers[$lastIndex]) $flag = true;

if($flag){
    print("YES \n");
    foreach($numbers as $num){
        print($num." ");
    }
}
else{
    print("NO");
}

<?php
#1189B
$n = trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
sort($arr);
$last = $arr[$n - 1];
for ($i = 0; $i < $n; $i++) {
    $left = $arr[$i - 1] ?? $last;
    $right = $arr[$i + 1] ?? $arr[0];
    if ($arr[$i] >= (($arr[$i - 1] ?? $last) + ($arr[$i + 1] ?? $arr[0]))) {
        die('NO');
    }
}
echo 'YES' . PHP_EOL . implode(' ', $arr);

<?php

$n = trim(fgets(STDIN));

$numbers = explode(" ", fgets(STDIN));

sort($numbers);

$lastIndex = count($numbers) - 1;

$temp = $numbers[$lastIndex];

$numbers[$lastIndex] = $numbers[$lastIndex-1];
$numbers[$lastIndex-1] = $temp;

$flag = false;

if($numbers[$lastIndex-1] < $numbers[$lastIndex-2] + $numbers[$lastIndex]) $flag = true;

if($flag){
    print("YES \n");
    foreach($numbers as $num){
        print($num." ");
    }
}
else{
    print("NO");
}


<?php
$l1 = trim(fgets(STDIN));
$l2 = trim(fgets(STDIN));
$l3 = trim(fgets(STDIN));
$l4 = trim(fgets(STDIN));

list($c1, $c2, $c3, $c4) = explode(' ', $l1);
list($n, $m) = explode(' ', $l2);
$buses = explode(' ', $l3);
$trolley = explode(' ', $l4);
$btmp = 0;
$ttmp = 0;
foreach ($buses as $b) {
    if (($b * $c1) > $c2) {
        $btmp += $c2;
    } else {
        $btmp += $b * $c1;
    }
}
if ($btmp > $c3) {
    $btmp = $c3;
}
foreach ($trolley as $t) {
    if (($t * $c1) > $c2) {
        $ttmp += $c2;
    } else {
        $ttmp += $t * $c1;
    }
}
if ($btmp > $c3) {
    $btmp = $c3;
}
if ($ttmp > $c3) {
    $ttmp = $c3;
}
if (($btmp + $ttmp) > $c4) {
    echo $c4;
} else {
    echo $btmp + $ttmp;
}

<?
list($c1,$c2,$c3, $c4)=explode(' ', trim(fgets(STDIN)));
list($m,$n) = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$b = explode(' ', trim(fgets(STDIN)));
//$start_time = microtime(true);
foreach($a as $a1){
    $bablo_a += min($a1*$c1,$c2,$c3,$c4);
    if($bablo_a>=$c4 || $bablo_a>=$c3){
        $bablo_a=min($c3,$c4);
        break;
    }
}
if($bablo_a<$c4){
    foreach ($b as $b1) {
        $bablo_t += min($b1*$c1,$c2,$c3,$c4);
        if($bablo_t>=$c4 || $bablo_t>=$c3){
            $bablo_t=min($c3,$c4);
            break;
        }
    }
}
$bablo=min($bablo_a+$bablo_t,$c3+$c3,$c4);
print $bablo;

<?php
list($c1, $c2, $c3, $c4) = explode(" ", trim(fgets(STDIN)));
list($n, $m) = explode(" ", trim(fgets(STDIN)));
$nv=explode(" ", trim(fgets(STDIN)));
$mv=explode(" ", trim(fgets(STDIN)));
$Bus=0;
$Train=0;
$i=0;
$l=0;
while($n!==0){
$f1=$nv[$i]*$c1;
$f2=$c2;
$Bus=$Bus+min($f1,$f2);
$i++;
$n--;
        }
$Bustotal=min($Bus,$c3);

while($m!==0){
$t1=$mv[$l]*$c1;
$t2=$c2;
$Train=$Train+min($t1,$t2);
$l++;
$m--;
        }
$Traintotal=min($Train,$c3);

echo min($Traintotal+$Bustotal,$c4) ;

?>

<?
        list($c1,$c2,$c3, $c4)=explode(' ', fgets(STDIN));
        list($m,$n) = explode(' ', fgets(STDIN));
        $a = explode(' ', fgets(STDIN));
        $b = explode(' ', fgets(STDIN));

        //$start_time = microtime(true);
        foreach($a as $a1){
            $bablo_a += min($a1*$c1,$c2,$c3,$c4);
            if($bablo_a>=$c4 || $bablo_a>=$c3){
                $bablo_a=min($c3,$c4);
                break;
            }
        }
        if($bablo_a<$c4){
            foreach ($b as $b1) {
                $bablo_t += min($b1*$c1,$c2,$c3,$c4);
                if($bablo_t>=$c4 || $bablo_t>=$c3){
                    $bablo_t=min($c3,$c4);
                    break;
                }
            }
        }
        $bablo=min($bablo_a+$bablo_t,$c3+$c3,$c4);
        print $bablo;

<?php
echo"
<form method=post action=#>
c1  <input type=text name=c1> , c2  <input type=text name=c2>, c3  <input type=text name=c3>, c4  <input type=text name=c4>

n  <input type=text name=n>   , m  <input type=text name=m>

a  <input type=text name=a>

b  <input type=text name=b>
<input type=submit name=submit>
</form>
";
if(isset($_POST["submit"])){
$c1=$_POST["c1"];
$c2=$_POST["c2"];
$c3=$_POST["c3"];
$c4=$_POST["c4"];
$n=$_POST["n"];
$m=$_POST["m"];
$a=$_POST["a"];
$Bus=0;
$Train=0;
$i=0;
$l=0;
$nv=explode(" ",$_POST["a"]);
$b=$_POST["b"];
$mv=explode(" ",$_POST["b"]);
while($n!==0){
$f1=$nv[$i]*$c1;
$f2=$c2;
$Bus=$Bus+min($f1,$f2);
$i++;
$n--;
        }
$Bustotal=min($Bus,$c3);

while($m!==0){
$t1=$mv[$l]*$c1;
$t2=$c2;
$Train=$Train+min($t1,$t2);
$l++;
$m--;
        }
$Traintotal=min($Train,$c3);

echo min($Traintotal+$Bustotal,$c4) ;

							}

?>

<?php
if(isset($_POST["submit"])){
$c1=$_POST["c1"];
$c2=$_POST["c2"];
$c3=$_POST["c3"];
$c4=$_POST["c4"];
$n=$_POST["n"];
$m=$_POST["m"];
$a=$_POST["a"];
$Bus=0;
$Train=0;
$i=0;
$l=0;
$nv=explode(" ",$_POST["a"]);
$b=$_POST["b"];
$mv=explode(" ",$_POST["b"]);
while($n!==0){
$f1=$nv[$i]*$c1;
$f2=$c2;
$Bus=$Bus+min($f1,$f2);
$i++;
$n--;
        }
$Bustotal=min($Bus,$c3);

while($m!==0){
$t1=$mv[$l]*$c1;
$t2=$c2;
$Train=$Train+min($t1,$t2);
$l++;
$m--;
        }
$Traintotal=min($Train,$c3);

echo min($Traintotal+$Bustotal,$c4) ;

							}else{
							echo"
<form method=post action=#>
c1  <input type=text name=c1> , c2  <input type=text name=c2>, c3  <input type=text name=c3>, c4  <input type=text name=c4>

n  <input type=text name=n>   , m  <input type=text name=m>

a  <input type=text name=a>

b  <input type=text name=b>
<input type=submit name=submit>
</form>
";}

?>


<?php
fscanf(STDIN, "%d", $count);
$result = array();
for ($i = 0; $i < $count; $i++) {
    fscanf(STDIN, "%d", $number);
    $turns_number = 0;
    if ($number == 1)
        $turns_number = 0;
    else if ($number == 2)
        $turns_number = 1;
    else if ($number == 3)
        $turns_number = 2;
    else if ($number % 2 == 0)
        $turns_number = 2;
    else if ($number % 2 != 0)
        $turns_number = 3;
    array_push($result, $turns_number);
}

for ($i = 0; $i < $count; $i++){
    echo $result[$i];
    if ($i < $count - 1)
        echo "\n";
}
?>

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

   for ($i = 0; $i < $t; $i++) {
        $n = intval(fgets(STDIN));
        $iCount = 0;
        while ($n !== 1) {
            $div = printDivisors($n);
            if ($div == 0 ) {
                $n = $n -1;
                $iCount++;
            } else {
                $n = $n /$div;
                $iCount++;
            }
        }
        echo $iCount."\n";
   }

function printDivisors($n){
    // Note that this loop
    // runs till square root
    $iMax = 0;
    for ($i = 2; $i <= sqrt($n); $i++) {
        if ($n%$i == 0) {
            $i2 = $n/$i;
            if ($i2 > $iMax) {
                $iMax = $i2;
            }
            if ($i > $iMax) {
                $iMax = $i;
            }
        }
    }
    return $iMax;
}

?>

<?php
fscanf(STDIN, "%d", $count);
$result = array();
for ($i = 0; $i < $count; $i++) {
    fscanf(STDIN, "%d", $number);
    $turns_number = 0;
    while ($number > 1) {
        $success = false;
        for ($j = 2; $j <= sqrt($number); $j++) {
            if ($number % $j == 0) {
                $number = $j;
                $turns_number++;
                $success = true;
                break;
            }
        }
        if (!$success){
            $number--;
            $turns_number++;
        }
    }
    array_push($result, $turns_number);
}

for ($i = 0; $i < $count; $i++){
    echo $result[$i];
    if ($i < $count - 1)
        echo "\n";
}
?>


<?php
error_reporting("off");
//469DC: 24 Game
$n = trim(fgets(STDIN));
if ($n < 4) {
	echo "NO";
} elseif ($n % 2 == 0) {
	echo "YES\n";
	$switch = false;
	$zerocount = 0;
	for ($i = $n; $i > 4; $i = $i - 2) {
		$minus = $i - 1;
		echo $i." - ".$minus." =  1\n";
		if ($switch == true) {
			echo "1 - 1 = 0\n";
			$zerocount++;
			$switch = false;
		} else {
			$switch = true;
		}
	}
	if ($switch == true) {
		echo "1 * 1 = 1\n";
	}
	echo str_repeat("0 + 0 = 0\n", $zerocount - 1);
	if ($n > 6) {  echo "1 + 0 = 1\n"; }
	echo "4 * 3 = 12\n";
	echo "12 * 2 = 24\n";
	echo "24 * 1 = 24\n";
} else {
	echo "YES\n";
	$switch = false;
	$zerocount = 0;
	for ($i = $n; $i > 5; $i = $i - 2) {
		$minus = $i - 1;
		echo $i." - ".$minus." =  1\n";
		if ($switch == true) {
			echo "1 - 1 = 0\n";
			$zerocount++;
			$switch = false;
		} else {
			$switch = true;
		}
	}
	if ($switch == true) {
		echo "1 * 1 = 1\n";
	}
	echo str_repeat("0 + 0 = 0\n", $zerocount - 1);
	if ($n > 7) {  echo "1 + 0 = 1\n"; }
	echo "2 * 4 = 8\n";
	echo "3 - 1 = 2\n";
	echo "5 - 2 = 3\n";
	echo "8 * 3 = 24\n";
}
?>


<?php
$fl =STDIN;//fopen("input.txt","r");
$n = trim(fgets(STDIN));
$c = explode(" ", trim(fgets(STDIN)));
sort($c);
$arr = array();

for($i=0;$i<$n;++$i)
{
    if ($i > 0) {
        $arr[] = ($c[$i] - $c[$i-1]);
    }
}
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}
/*
function gcd_array($array, $a = 0)
{
    $b = array_pop($array);
    return ($b === null) ?
        (int)$a :
        gcd_array($array, gcd($a, $b));
}*/
//$arrgcd = gcd_array($arr);
$arrgcd = $arr[0];
for ($i = 0; $i < $n-1; $i++)
    $arrgcd = gcd($arrgcd,$arr[$i]);
$ans = 0;
for ($i=1; $i<$n;++$i) {
    $dif = $c[$i] - $c[$i-1];
    $ans += ($dif / $arrgcd) - 1;
}
printf("%d",$ans);
?>

<?php
$n = 0;
fscanf(STDIN, "%d", $n);

$a = array_map('intval', explode(' ',trim(fgets(STDIN))));
sort($a);

$b = [];
for ($i = 1; $i < $n; ++$i) {
    ++$b[$a[$i] - $a[$i - 1]];
}

function gcd($a, $b) {
    if (!$b) return $a;
    else return gcd($b, $a % $b);
}

$gcd = 0;
foreach ($b as $bi => $ci) {
    $gcd = gcd($gcd, $bi);
}

$ans = 0;
foreach ($b as $bi => $ci) {
    $ans += ($bi / $gcd - 1) * $ci;
}
echo $ans;

<?php

function euclid($a, $b) {
  if ($b == 0) return $a;
  return euclid($b, $a % $b);
}

$n = intval(trim(fgets(STDIN)));
$astr = explode(" ", trim(fgets(STDIN)));
$a = array();
for ($i = 0; $i < $n; ++$i) {
  array_push($a, intval($astr[$i]));
}

sort($a);

$gcd = -1;
for ($i = 1; $i < $n; ++$i) {
  if ($gcd == -1) {
    $gcd = $a[1] - $a[0];
  } else {
    $gcd = euclid($gcd, $a[$i] - $a[$i - 1]);
  }
}

$rs = 0;
for ($i = 1; $i < $n; ++$i) {
  $rs += ($a[$i] - $a[$i - 1]) / $gcd - 1;
}

printf("%d\n",$rs);
?>

<?php
function euclid($a, $b) {
  if ($b == 0) return $a;
  return euclid($b, $a % $b);
}

$n = intval(trim(fgets(STDIN)));
$astr = explode(" ", trim(fgets(STDIN)));
$a = array();
for ($i = 0; $i < $n; ++$i) {
  array_push($a, intval($astr[$i]));
}

sort($a);

$gcd = -1;
for ($i = 1; $i < $n; ++$i) {
  if ($gcd == -1) {
    $gcd = $a[1] - $a[0];
  } else {
    $gcd = euclid($gcd, $a[$i] - $a[$i - 1]);
  }
}

$rs = 0;
for ($i = 1; $i < $n; ++$i) {
  $rs += ($a[$i] - $a[$i - 1]) / $gcd - 1;
}

fwrite(STDOUT, strval($rs) . "\n");
?>

<?php
function gcd($num1, $num2) {
   while ($num2 != 0){
     $t = $num1 % $num2;
     $num1 = $num2;
     $num2 = $t;
   }
   return $num1;
}

$fl =STDIN;
fscanf($fl,"%d",$n);

$inp = array();

$array = array();
$prev = 0;
$curs = explode(" ", fgets(STDIN));
for($i = 0; $i< $n; ++$i)
{
 $cur = (int)$curs[$i];

 array_push($inp, $cur);
}

sort($inp);

for($i = 0; $i< $n; ++$i)
{
 if ($i != 0)
 {
    $dist = abs($inp[$i] - $prev);
    array_push($array, $dist);
 }

 $prev = $inp[$i];
}

$sz = count($array);

for($i = 0; $i< $sz; ++$i)
{
 if ($i != 0)
 {
  $g = gcd($g, $array[$i]);
 }
 else
 {
  $g = $array[$i];
 }
}

$result = 0;

for($i=0; $i< $sz; ++$i)
{
 $result += (($array[$i]) / $g) - 1;
}

echo $result;

?>

<?php

function gcd($a, $b) {
    if ($b === 0) {
        return abs($a);
    }
    return gcd($b, $a % $b);
}

fscanf(STDIN, "%d", $n);
foreach (explode(" ", fgets(STDIN)) as $i => $str) {
    $arr[$i] = intval($str);
}
sort($arr);
$min = $arr[0];
$max = $arr[$n - 1];
$res = $max - $min;
foreach ($arr as $x) {
    $res = gcd($res, $x - $min);
}
print(($max - $min) / $res - $n + 1);
print("\n");

<?php
$n = (int)fgets(STDIN);
$a = array_map('intval',explode(' ',trim(fgets(STDIN))));
sort($a);

$gcd = 0;
$gcdf = false;

function fgcd($a,$b) {
    return ($a % $b) ? fgcd($b,$a % $b) : $b;
}

for($i = 0; $i < ($n) - 1; $i++) {
    $delt = $a[($i)+1]-$a[0];
    if(!$gcdf) {
        $gcd = $delt;
        $gcdf = true;
    } else {
        $gcd = fgcd($gcd, $delt);
    }
}
$ans = 1 + intdiv(($a[$n - 1] - $a[0]),$gcd) - $n;

echo $ans;

<?php
$fl =STDIN;//fopen("input.txt","r");
fscanf($fl,"%d\n",$n);
$numbers = explode(" ", trim(fgets($fl)));
$fi = false;
$se = false;
$l = 0;
$ans = 0;
function gcd ($a, $b) {
    return $b ? gcd($b, $a % $b) : $a;
}
sort($numbers);
foreach ($numbers as &$number)
{
    $x = intval($number);
    if($fi) {
        if($se) {
            $ans = gcd($ans, $x-$l);
        }else{
            $ans = $x-$l;
        }
        $se = true;
    }
    $fi = true;
    $l = $x;
}
printf("%d\n", 1+($numbers[$n-1]-$numbers[0])/$ans - $n);
?>

<?php
$n = (int)fgets(STDIN);
$a = array_map('intval',explode(' ',trim(fgets(STDIN))));
sort($a);

$gcd = 0;
$gcdf = false;

function fgcd($a,$b) {
    return ($a % $b) ? fgcd($b,$a % $b) : $b;
}

for($i = 0; $i < ($n) - 1; $i++) {
    $delt = $a[($i)+1]-$a[$i];
    if(!$gcdf) {
        $gcd = delt;
        $gcdf = true;
    } else {
        $gcd = fgcd($gcd, $delt);
    }
}
$ans = 1 + intdiv(($a[$n - 1] - $a[0]),$gcd) - $n;

echo $ans;

<?php
$n = (int)fgets(STDIN);
$a = array_map('intval',explode(' ',trim(fgets(STDIN))));
sort($a);

$gcd = 0;
$gcdf = false;

function fgcd($a,$b) {
    return ($a % $b) ? fgcd($b,$a % $b) : $b;
}

for($i = 0; $i < ($n) - 1; $i++) {
    $delt = $a[($i)+1]-$a[0];
    if(!$gcdf) {
        $gcd = delt;
        $gcdf = true;
    } else {
        $gcd = fgcd($gcd, $delt);
    }
}
$ans = 1 + intdiv(($a[$n - 1] - $a[0]),$gcd) - $n;

echo $ans;

function euclid($a, $b) {
  if ($b == 0) return $a;
  return euclid($b, $a % $b);
}

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

$n = intval(fgets($handle));
$astr = explode(" ", fgets($handle));
$a = array();
for ($i = 0; $i < $n; ++$i) {
  array_push($a, intval($astr[$i]));
}

sort($a);

$gcd = -1;
for ($i = 1; $i < $n; ++$i) {
  if ($gcd == -1) {
    $gcd = $a[1] - $a[0];
  } else {
    $gcd = euclid($gcd, $a[$i] - $a[$i - 1]);
  }
}

$rs = 0;
for ($i = 1; $i < $n; ++$i) {
  $rs += ($a[$i] - $a[$i - 1]) / $gcd - 1;
}

print(strval($rs));

function euclid($a, $b) {
  if ($b == 0) return $a;
  return euclid($b, $a % $b);
}

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

$n = intval(fgets($handle));
$astr = explode(" ", fgets($handle));
$a = array();
for ($i = 0; $i < $n; ++$i) {
  array_push($a, intval($astr[$i]));
}

sort($a);

$gcd = -1;
for ($i = 1; $i < $n; ++$i) {
  if ($gcd == -1) {
    $gcd = $a[1] - $a[0];
  } else {
    $gcd = euclid($gcd, $a[$i] - $a[$i - 1]);
  }
}

$rs = 0;
for ($i = 1; $i < $n; ++$i) {
  $rs += ($a[$i] - $a[$i - 1]) / $gcd - 1;
}

fwrite(STDOUT, strval($rs));

function euclid($a, $b) {
  if ($b == 0) return $a;
  return euclid($b, $a % $b);
}

$n = intval(readline());
$astr = explode(" ", readline());
$a = array();
for ($i = 0; $i < $n; ++$i) {
  array_push($a, intval($astr[$i]));
}

sort($a);

$gcd = -1;
for ($i = 1; $i < $n; ++$i) {
  if ($gcd == -1) {
    $gcd = $a[1] - $a[0];
  } else {
    $gcd = euclid($gcd, $a[$i] - $a[$i - 1]);
  }
}

$rs = 0;
for ($i = 1; $i < $n; ++$i) {
  $rs += ($a[$i] - $a[$i - 1]) / $gcd - 1;
}

print(strval($rs));

<?php
$fl =STDIN;//fopen("input.txt","r");
$n = trim(fgets(STDIN));
$c = explode(" ", trim(fgets(STDIN)));
sort($c);
$arr = array();

for($i=0;$i<$n;++$i)
{
    if ($i > 0) {
        $arr[] = ($c[$i] - $c[$i-1]);
    }
}
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}
/*
function gcd_array($array, $a = 0)
{
    $b = array_pop($array);
    return ($b === null) ?
        (int)$a :
        gcd_array($array, gcd($a, $b));
}*/
//$arrgcd = gcd_array($arr);
$arrgcd = 0;
for ($i = 0; $i < $n; $i++)
    $arrgcd = gcd($arrgcd,$c[$i]);
$ans = 0;
for ($i=1; $i<$n;++$i) {
    $dif = $c[$i] - $c[$i-1];

    $ans += ($dif / $arrgcd) - 1;
}
printf("%d",$ans);
?>

<?php
$fl =STDIN;//fopen("input.txt","r");
$n = trim(fgets(STDIN));
$c = explode(" ", trim(fgets(STDIN)));
sort($c);
$arr = array();

for($i=0;$i<$n;++$i)
{
    if ($i > 0) {
        $arr[] = ($c[$i] - $c[$i-1]);
    }
}
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}
/*
function gcd_array($array, $a = 0)
{
    $b = array_pop($array);
    return ($b === null) ?
        (int)$a :
        gcd_array($array, gcd($a, $b));
}*/
//$arrgcd = gcd_array($arr);
$arrgcd = $c[0];
for ($i = 0; $i < $n; $i++)
    $arrgcd = gcd($arrgcd,$c[$i]);
$ans = 0;
for ($i=1; $i<$n;++$i) {
    $dif = $c[$i] - $c[$i-1];

    $ans += ($dif / $arrgcd) - 1;
}
printf("%d",$ans);
?>


<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt ="This  is

// Codeforces
// Beta
// Round
// 5
// ";
$text = array_map('trim',explode("\n",$datatxt));
unset($text[count($text)-1]);
$maxlen = max(array_map('strlen', $text))+2;
echo echo_line($maxlen,"*");
echo "\n";
// var_dump($text);
$not = true;
foreach($text as $value) {
$right = ceil(($maxlen - strlen($value))/2)-1;
$left = $right;
if (($maxlen - strlen($value))%2 !=0) {
if ($not){
$left--;
$not=false;
}else {
$right--;
$not=true;
}
}
echo "*".echo_line($left," ").$value.echo_line($right," ")."*"."\n";
}
echo echo_line($maxlen,"*");
function echo_line($number,$str){
$re = "";
for($i=0;$i<$number;$i++){
$re.=$str;
}
return $re;
}
?>

<?php
$array = array();

// Разбиваем по принципу по строка = 1000 символов
for($x = 1; $x <= 1000; $x++)
{
    $string = fgets(STDIN);
    if($string)
    {
        // Вставляем данные в массив, заодно избавлясь от переносов строк
        array_push($array, trim($string));
    }
}

// Проходимся по всем элементам массива функций strlen (длина строки) и формируем массив с результатами
$array_length = array_map('strlen', $array);

// Длина самой большой строки
$max_length = max($array_length);

// Первая и последная строки
$first_and_end_string = str_repeat("*", $max_length+2);

// Выводим результат
printf('%s', $first_and_end_string."\n");

$w=true;
foreach ($array as $key => $text) {
    // Длина строки
    $length = strlen($text);

    // Генерируем пробелы, проверяя на четность деления
    $space_left = ceil(($max_length-$length)/2);
    $space_right = $space_left;
    if( ($max_length - $length) % 2 !=0 ) {
        if($w) {
            $space_left--;
            $w=false;
        } else {
            $space_right--;
            $w=true;
        }
    }

    $sting = '*' . str_repeat(" ", $space_left) . $text . str_repeat(" ", $space_right) . '*';
    printf('%s', $sting."\n");
}
printf('%s', $first_and_end_string."\n");
?>

<?php
	define('ENDL', "\r\n");
	define('SP', ' ');
	$text = array();
	$width = 0;
	$fr = fopen("php://stdin","r");
	#$fr = fopen("input.txt","r");
	while ( $input = fgets($fr) )
		$text[] = trim($input);
	fclose ($fr);

	foreach ( $text as $line )
		$width = max($width, strlen($line));

	$bAlignLeft = true;

	echo str_repeat('*', $width + 2).ENDL;
	foreach ( $text as $line )
	{
		echo '*';

		if ( !$bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			$bAlignLeft = !$bAlignLeft;
			echo SP;
			echo str_pad($line, $width - 1, SP, STR_PAD_BOTH);
		}
		else
		if ( $bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			$bAlignLeft = !$bAlignLeft;
			echo str_pad($line, $width - 1, SP, STR_PAD_BOTH);
			echo SP;
		}
		else
			echo str_pad($line, $width, SP, STR_PAD_BOTH);

		echo '*'.ENDL;
	}
	echo str_repeat('*', $width + 2);
?>

<?php
$array =  explode("\n", fgets(STDIN));

// Проходимся по всем элементам массива функций strlen (длина строки) и формируем массив с результатами
$array_length = array_map('strlen', $array);

// Длина самой большой строки
$max_length = max($array_length);

// Первая и последная строки
$first_and_end_string = str_repeat("*", $max_length+2);

printf('%s', $first_and_end_string."\n");
foreach ($array as $key => $text) {
    // Длина строки
    $length = strlen($text);
    // Пробелы до
    $space_left = ceil(($max_length-$length)/2);
    // Пробелы после
    $space_right = ($max_length-$length) - $space_left;
    $sting = '*' . str_repeat(" ", $space_left) . $text . str_repeat(" ", $space_right) . '*';
    printf('%s', $sting."\n");
}
printf('%s', $first_and_end_string."\n");
?>

<?php
$array = array();

// Разбиваем по принципу по строка = 1000 символов
for($x = 1; $x <= 1000; $x++)
{
    $string = fgets(STDIN);
    if($string)
    {
        // Вставляем данные в массив, заодно избавлясь от переносов строк
        array_push($array, trim($string));
    }
}

// Проходимся по всем элементам массива функций strlen (длина строки) и формируем массив с результатами
$array_length = array_map('strlen', $array);

// Длина самой большой строки
$max_length = max($array_length);

// Первая и последная строки
$first_and_end_string = str_repeat("*", $max_length+2);

// Выводим результат
printf('%s', $first_and_end_string."\n");
foreach ($array as $key => $text) {
    // Длина строки
    $length = strlen($text);

    // Пробелы до
    $space_left = ceil(($max_length-$length)/2);

    // Пробелы после
    $space_right = ($max_length-$length) - $space_left;
    $sting = '*' . str_repeat(" ", $space_left) . $text . str_repeat(" ", $space_right) . '*';
    printf('%s', $sting."\n");
}
printf('%s', $first_and_end_string."\n");
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt ="This  is

// Codeforces
// Beta
// Round
// 5
// ";
$text = array_map('trim',explode("\n",$datatxt));
unset($text[count($text)-1]);
$maxlen = max(array_map('strlen', $text))+2;
echo echo_line($maxlen,"*");
// echo "\n";
var_dump($text);
foreach($text as $value) {
$right = ceil(($maxlen - strlen($value))/2)-1;
$left = ($maxlen - strlen($value))%2 ==0 ? $right : $right-1;
echo "*".echo_line($left," ").$value.echo_line($right," ")."*"."\n";
}
echo echo_line($maxlen,"*");
function echo_line($number,$str){
$re = "";
for($i=0;$i<$number;$i++){
$re.=$str;
}
return $re;
}
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt ="This  is

// Codeforces
// Beta
// Round
// 5
// ";
$text = array_map('trim',explode("\n",$datatxt));
unset($text[count($text)-1]);
$maxlen = max(array_map('strlen', $text))+2;
echo echo_line($maxlen,"*");
echo "\n";
// var_dump($text);
foreach($text as $value) {
$right = ceil(($maxlen - strlen($value))/2)-1;
$left = ($maxlen - strlen($value))%2 ==0 ? $right : $right-1;
echo "*".echo_line($left," ").$value.echo_line($right," ")."*"."\n";
}
echo echo_line($maxlen,"*");
function echo_line($number,$str){
$re = "";
for($i=0;$i<$number;$i++){
$re.=$str;
}
return $re;
}
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt ="This  is

// Codeforces
// Beta
// Round
// 5
// ";
$text = array_map('trim',explode("\n",$datatxt));
unset($text[count($text)-1]);
$maxlen = max(array_map('strlen', $text))+2;
echo echo_line($maxlen,"*");
// echo "\n";
// var_dump($text);
foreach($text as $value) {
$right = ceil(($maxlen - strlen($value))/2)-1;
$left = ($maxlen - strlen($value))%2 ==0 ? $right : $right-1;
echo "*".echo_line($left," ").$value.echo_line($right," ")."*"."\n";
}
echo echo_line($maxlen,"*");
function echo_line($number,$str){
$re = "";
for($i=0;$i<$number;$i++){
$re.=$str;
}
return $re;
}
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt ="h1
// b2";
$text = explode("\n",$datatxt);
unset($text[count($text)-1]);
$maxlen = max(array_map('strlen', $ary));
echo_line($maxlen+2,"*");
echo "\n";
foreach($text as $value) {
$right = ceil(($maxlen - strlen($value))/2);
$left = ($maxlen - strlen($value))%2 ==0 ? $right : $right-1;
echo "*";
echo_line($left," ");
echo $value;
echo_line($right," ");
echo "*";
echo "\n";
}
echo_line($maxlen+2,"*");
function echo_line($number,$str){
for($i=0;$i<$number;$i++){
echo $str;
}
}
?>

<?php
	define('ENDL', "\r\n");
	$text = array();
	$width = 0;
	$fr = fopen("php://stdin","r");
	while ( $input = fgets($fr) )
	{
		$text[] = trim($input);
		$width = max($width, strlen($input));
	}
	fclose ($fr);

	$bAlignLeft = true;

	echo str_repeat('*', $width + 2).ENDL;
	foreach ( $text as $line )
	{
		echo '*';

		if ( !$bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
			echo ' ';

		$n = (int) (($width - strlen($line)) / 2);

		echo str_repeat(' ', $n);
		echo $line;
		echo str_repeat(' ', $n);

		if ( $bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
			echo ' ';

		echo '*'.ENDL;
	}
	echo str_repeat('*', $width + 2).ENDL;
?>

<?php
	define('ENDL', "\r\n");
	$text = array();
	$width = 0;
	$fr = fopen("php://stdin","r");
	#$fr = fopen("input.txt","r");
	while ( $input = fgets($fr) )
	{
		$text[] = trim($input);
		$width = max($width, strlen($input));
	}
	fclose ($fr);

	$bAlignLeft = true;
	$bChange = false;

	echo str_repeat('*', $width + 2).ENDL;
	foreach ( $text as $line )
	{
		echo '*';

		if ( !$bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			echo ' ';
			$bChange = true;
		}

		$n = (int) (($width - strlen($line)) / 2);

		echo str_repeat(' ', $n);
		echo $line;
		echo str_repeat(' ', $width - strlen($line) - $n);

		if ( $bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			echo ' ';
			$bChange = true;
		}
		if ( $bChange )
			$bAlignLeft = !$bAlignLeft;

		echo '*'.ENDL;
	}
	echo str_repeat('*', $width + 2).ENDL;
?>

<?php
	define('ENDL', "\r\n");
	$text = array();
	$width = 0;
	$fr = fopen("php://stdin","r");
	while ( $input = fgets($fr) )
	{
		$text[] = trim($input);
		$width = max($width, strlen($input));
	}
	fclose ($fr);

	$bAlignLeft = true;

	echo str_repeat('*', $width + 2).ENDL;
	foreach ( $text as $line )
	{
		echo '*';

		if ( !$bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
			echo ' ';

		$n = (int) (($width - strlen($line)) / 2);

		echo str_repeat(' ', $n);
		echo $line;
		echo str_repeat(' ', $n);

		if ( $bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
			echo ' ';

		echo '*'.ENDL;
	}
?>

<?php
	define('ENDL', "\r\n");
	define('SP', ' ');
	$text = array();
	$width = 0;
	$fr = fopen("php://stdin","r");
	#$fr = fopen("input.txt","r");
	while ( $input = fgets($fr) )
	{
		$text[] = trim($input);
		$width = max($width, strlen($input));
	}
	fclose ($fr);

	$bAlignLeft = true;

	echo str_repeat('*', $width + 2).ENDL;
	foreach ( $text as $line )
	{
		echo '*';

		if ( !$bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			$bAlignLeft = !$bAlignLeft;
			echo SP;
			echo str_pad($line, $width - 1, SP, STR_PAD_BOTH);
		}
		else
		if ( $bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			$bAlignLeft = !$bAlignLeft;
			echo str_pad($line, $width - 1, SP, STR_PAD_BOTH);
			echo SP;
		}
		else
			echo str_pad($line, $width, SP, STR_PAD_BOTH);

		echo '*'.ENDL;
	}
	echo str_repeat('*', $width + 2).ENDL;
?>

<?php
	define('ENDL', "\r\n");
	$text = array();
	$width = 0;
	$fr = fopen("php://stdin","r");
	#$fr = fopen("input.txt","r");
	while ( $input = fgets($fr) )
	{
		$text[] = trim($input);
		$width = max($width, strlen($input));
	}
	fclose ($fr);

	$bAlignLeft = true;
	$bChange = false;

	echo str_repeat('*', $width + 2).ENDL;
	foreach ( $text as $line )
	{
		echo '*';

		if ( !$bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			echo ' ';
			$bChange = true;
		}

		$n = (int) (($width - strlen($line)) / 2);

		echo str_repeat(' ', $n);
		echo $line;
		echo str_repeat(' ', $width - strlen($line) - $n);

		if ( $bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			echo ' ';
			$bChange = true;
		}
		if ( $bChange )
		{
			$bAlignLeft = !$bAlignLeft;
			$bChange = false;
		}

		echo '*'.ENDL;
	}
	echo str_repeat('*', $width + 2).ENDL;
?>

<?php
	define('ENDL', "\r\n");
	$text = array();
	$width = 0;
	$fr = fopen("php://stdin","r");
	while ( $input = fgets($fr) )
	{
		$text[] = trim($input);
		$width = max($width, strlen($input));
	}
	fclose ($fr);

	$bAlignLeft = true;
	$bChange = false;

	echo str_repeat('*', $width + 2).ENDL;
	foreach ( $text as $line )
	{
		echo '*';

		if ( !$bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			echo ' ';
			$bChange = true;
		}

		$n = (int) (($width - strlen($line)) / 2);

		echo str_repeat(' ', $n);
		echo $line;
		echo str_repeat(' ', $n);

		if ( $bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			echo ' ';
			$bChange = true;
		}
		if ( $bChange )
			$bAlignLeft = !$bAlignLeft;

		echo '*'.ENDL;
	}
	echo str_repeat('*', $width + 2).ENDL;
?>

<?php
	define('ENDL', "\r\n");
	define('SP', ' ');
	$text = array();
	$width = 0;
	$fr = fopen("php://stdin","r");
	#$fr = fopen("input.txt","r");
	while ( $input = fgets($fr) )
	{
		$text[] = trim($input);
		$width = max($width, strlen($input));
	}
	fclose ($fr);

	$bAlignLeft = true;

	echo str_repeat('*', $width + 2).ENDL;
	foreach ( $text as $line )
	{
		echo '*';

		if ( !$bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			$bAlignLeft = !$bAlignLeft;
			echo SP;
			echo str_pad($line, $width - 1, SP, STR_PAD_BOTH);
		}
		else
		if ( $bAlignLeft && ((strlen($line) % 2) != ($width % 2)) )
		{
			$bAlignLeft = !$bAlignLeft;
			echo str_pad($line, $width - 1, SP, STR_PAD_BOTH);
			echo SP;
		}
		else
			echo str_pad($line, $width, SP, STR_PAD_BOTH);

		echo '*'.ENDL;
	}
	echo str_repeat('*', $width + 2);
?>


<?php
list($n, $s) = explode(' ',trim(fgets(STDIN)));
$max = array();
$sugar = array();

for( $i=0; $i<$n; $i++ ){
    list($d, $ds) = explode(' ',fgets(STDIN));

    if( $s >= doubleval($d.'.'.$ds) && $ds != 0 ){
        $max[] = (100 - $ds);
    }elseif($s >=$d && $ds ==0){
        $sugar[] = $ds;
    }
}

if(getArrayMax( $max ) > 0){
    print getArrayMax($max);
}elseif( count( $sugar ) > 0 ){
    print 0;
}
else{
    print '-1';
}

function getArrayMax( $array ){
    $maxV = 0;
    foreach( $array as $key=>$value ){
        if( $value > $maxV ){
            $maxV = $value;
        }
    }

    return $maxV;
}

<?php
list($n, $s) = explode(' ',trim(fgets(STDIN)));
$max = array();

for( $i=0; $i<$n; $i++ ){
    list($d, $ds) = explode(' ',fgets(STDIN));
    if( $s >= $d && $ds != 0 ){
        $max[] = (100 - $ds);
    }
}

if( count($max) == 0 ){
    print '-1';
}else{
    print getArrayMax( $max );
}

function getArrayMax( $array ){
    $maxV = 0;
    foreach( $array as $key=>$value ){
        if( $value > $maxV ){
            $maxV = $value;
        }
    }

    return $maxV;
}

<?php
list($n, $s) = explode(' ',trim(fgets(STDIN)));
$max = array();
$sugar = array();

for( $i=0; $i<$n; $i++ ){
    list($d, $ds) = explode(' ',fgets(STDIN));
    if( $s >= $d && $ds != 0 ){
        $max[] = (100 - $ds);
    }elseif($s >=$d && $ds ==0){
        $sugar[] = $ds;
    }
}

if(getArrayMax( $max ) > 0){
    print getArrayMax($max);
}elseif( count( $sugar ) > 0 ){
    print 0;
}
else{
    print '-1';
}

function getArrayMax( $array ){
    $maxV = 0;
    foreach( $array as $key=>$value ){
        if( $value > $maxV ){
            $maxV = $value;
        }
    }

    return $maxV;
}

<?php
list($n, $s) = explode(' ',trim(fgets(STDIN)));
$max = array();
$sugar = array();

for( $i=0; $i<$n; $i++ ){
    list($d, $ds) = explode(' ',fgets(STDIN));
    if( $s >= $d && $s >= $d.$ds && $ds != 0 ){
        $max[] = (100 - $ds);
    }elseif($s >=$d && $ds ==0){
        $sugar[] = $ds;
    }
}

if(getArrayMax( $max ) > 0){
    print getArrayMax($max);
}elseif( count( $sugar ) > 0 ){
    print 0;
}
else{
    print '-1';
}

function getArrayMax( $array ){
    $maxV = 0;
    foreach( $array as $key=>$value ){
        if( $value > $maxV ){
            $maxV = $value;
        }
    }

    return $maxV;
}


<?php
$slov = fgets(STDIN);
$string = fgets(STDIN);

$dp = [];
$n = strlen($string)-2;
$min = $n;
//запись слов
$words = [];
$word = '';

for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==$n-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}

for ($i=0; $i<count($words); $i++) {
    for ($j=0; $j<count($words); $j++) {
        $dp[$i][$j] = 0;
    }
}

for ($i=$slov-1; $i>=0; $i--) {
    for ($j=$slov-1; $j>=0; $j--) {
        if ($words[$i]==$words[$j]) {
            if ($i==$slov-1||$j==$slov-1) {
                $dp[$i][$j] = 1;
            } else {
                $dp[$i][$j] = $dp[$i+1][$j+1]+1;
            }
        }
    }
}

$ans = $n;
for ($i=0; $i<$slov; $i++) {
    $sum = 0;
    $word = '';
    for ($length=0; $length<$slov-$i; $length++) {
        $j = 0;
        $number = 0;
        if ($length==0) {
            $word = $words[$i+$length];
            $sum = strlen($words[$i+$length]);
        } else {
             $word = $word.' '.$words[$i+$length];
            $sum = $sum + strlen($words[$i+$length]) + 1;
        }
        while ($j<$slov) {
            //echo $j.' ';
            if ($dp[$i][$j]>$length) {
                $number++;
                $j = $j + $length + 1;
            } else {
                $j++;
            }
        }
       // echo PHP_EOL;
        $res = $n + $number*($length+1) - $number*$sum;
        //echo $word.'sum= '.$sum.' n='.$n.'res='.$res.'number ='.$number.'length ='.$length.PHP_EOL;
        if ($number>1) {
            if ($ans>$res) {
                $ans=$res;
            }
        }
    }
}
echo $ans.PHP_EOL;
/*for ($i=0; $i<count($words); $i++) {
    for ($j=0; $j<count($words); $j++) {
        echo $dp[$i][$j].' ';
    }
    echo PHP_EOL;
}*/
?>

<?php
$nn = fgets(STDIN);
$string = fgets(STDIN);

$w = [];
$n = strlen($string)-2;
$min = $n;
//запись слов
$words = [];
$word = '';

for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==$n-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}
//print_r($words);

for ($i=0; $i<count($words); $i++) {
    $replace = '';
    $search = '';
    for ($j=$i; $j<count($words); $j++) {
        $replace = $replace.strtoupper($words[$j][0]);
        if ($j==$i) {
            $search = $words[$j];
        } else {
            $search = $search.' '.$words[$j];
        }
        if (isset($w[$search])) {
            continue;
        }
        $repeat = substr_count($string, $search);
        if ($repeat>=2) {
            //$length = $n-$repeat*strlen($search) + $repeat*strlen($replace);
            $w[$search] = strlen(str_replace($search, $replace, $string))-2;
            if ($min>$w[$search]) {
                $min = $w[$search];
            }
        }
    }
}

echo $min;
?>

<?php
$nn = fgets(STDIN);
$string = fgets(STDIN);

$w = [];
$n = strlen($string)-2;
$min = $n;
//запись слов
$words = [];
$word = '';
for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==$n-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}
//print_r($words);

for ($i=0; $i<count($words); $i++) {
    $replace = '';
    $search = '';
    for ($j=$i; $j<count($words); $j++) {
        $replace = $replace.$words[$j][0];
        if ($j==$i) {
            $search = $words[$j];
        } else {
            $search = $search.' '.$words[$j];
        }
        //echo 'search = '.$search.'  replace = '.$replace.PHP_EOL;
        /*if (isset($w[$search])) {
            continue;
        }*/
        $repeat = substr_count($string, $search);
        if ($repeat>=2) {
            $length = $n-$repeat*strlen($search) + $repeat*strlen($replace);
            $w[$search] = $length;
            if ($min>$length) {
                $min = $length;
            }
        }
    }
}
echo $min;
?>

<?php
$slov = fgets(STDIN);
$string = fgets(STDIN);

$w = [];
$n = strlen($string)-2;
$min = $n;
//запись слов
$words = [];
$word = '';

for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==$n-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}
//print_r($words);
//dasdsa
for ($i=0; $i<$slov; $i++) {
    $replace = '';
    $search = '';
    for ($j=$i; $j<$slov; $j++) {
        $replace = $replace.strtoupper($words[$j][0]);
        if ($j==$i) {
            $search = $words[$j];
        } else {
            $search = $search.' '.$words[$j];
        }
        if (isset($w[$search])) {
            continue;
        }
        $repeat = substr_count($string, $search);
        if ($repeat>=2) {
            //$length = $n-$repeat*strlen($search) + $repeat*strlen($replace);
            $w[$search] = strlen(str_replace($search, $replace, $string))-2;
            if ($min>$w[$search]) {
                $min = $w[$search];
            }
        }
    }
}

echo $min;
?>

<?php
$n = fgets(STDIN);
$string = fgets(STDIN);

$w = [];
//$n = strlen($string);
$min = $n;
//запись слов
$words = [];
$word = '';
for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==strlen($string)-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}
//print_r($words);
for ($i=0; $i<count($words); $i++) {
    for ($j=$i; $j<count($words); $j++) {
        $search = '';
        $replace = '';
        for ($k=$i; $k<=$j; $k++) {
            $replace = $replace.$words[$k][0];
            if ($k==$i) {
                $search = $words[$k];
            } else {
                $search = $search.' '.$words[$k];
            }
        }
        if (substr_count($string, $search)>=2) {
            $w[$i][$j] = strlen(str_replace($search, $replace, $string));
            if ($min>$w[$i][$j]) {
                $min = $w[$i][$j];
            }
        }
        //$w[$i][$j] = 'search = '.$search.' replace = '.$replace;
    }
}
print_r($min);
?>

<?php
$nn = fgets(STDIN);
$string = fgets(STDIN);

$w = [];
$n = strlen($string);
$min = $n;
//запись слов
$words = [];
$word = '';
for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==strlen($string)-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}
//print_r($words);
for ($i=0; $i<count($words); $i++) {
    for ($j=$i; $j<count($words); $j++) {
        $search = '';
        $replace = '';
        for ($k=$i; $k<=$j; $k++) {
            $replace = $replace.$words[$k][0];
            if ($k==$i) {
                $search = $words[$k];
            } else {
                $search = $search.' '.$words[$k];
            }
        }
        if (substr_count($string, $search)>=2) {
            $w[$i][$j] = strlen(str_replace($search, $replace, $string));
            if ($min>$w[$i][$j]) {
                $min = $w[$i][$j];
            }
        }
        //$w[$i][$j] = 'search = '.$search.' replace = '.$replace;
    }
}
print_r($min);
?>

<?php
$slov = fgets(STDIN);
$string = fgets(STDIN);

$w = [];
$n = strlen($string)-2;
$min = $n;
//запись слов
$words = [];
$word = '';

for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==$n-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}
//print_r($words);

for ($i=0; $i<$slov; $i++) {
    $replace = '';
    $search = '';
    for ($j=$i; $j<$slov; $j++) {
        $replace = $replace.strtoupper($words[$j][0]);
        if ($j==$i) {
            $search = $words[$j];
        } else {
            $search = $search.' '.$words[$j];
        }
        if (isset($w[$search])) {
            continue;
        }
        $repeat = substr_count($string, $search);
        if ($repeat>=2) {
            //$length = $n-$repeat*strlen($search) + $repeat*strlen($replace);
            $w[$search] = strlen(str_replace($search, $replace, $string))-2;
            if ($min>$w[$search]) {
                $min = $w[$search];
            }
        }
    }
}

echo $min;
?>

<?php
$nnn = fgets(STDIN);
$string = fgets(STDIN);

$w = [];
$n = strlen($string);
$min = $n;
//запись слов
$words = [];
$word = '';
for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==strlen($string)-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}
//print_r($words);
for ($i=0; $i<count($words); $i++) {
    for ($j=$i; $j<count($words); $j++) {
        $search = '';
        $replace = '';
        for ($k=$i; $k<=$j; $k++) {
            $replace = $replace.$words[$k][0];
            if ($k==$i) {
                $search = $words[$k];
            } else {
                $search = $search.' '.$words[$k];
            }
        }
        if (substr_count($string, $search)>=2) {
            $w[$i][$j] = strlen(str_replace($search, $replace, $string));
            if ($min>$w[$i][$j]) {
                $min = $w[$i][$j];
            }
        }
        //$w[$i][$j] = 'search = '.$search.' replace = '.$replace;
    }
}
print_r($min);
?>

<?php
$nn = fgets(STDIN);
$string = fgets(STDIN);

$w = [];
$n = strlen($string)-2;
$min = $n;
//запись слов
$words = [];
$word = '';
for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==$n-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}
//print_r($words);

for ($i=0; $i<count($words); $i++) {
    $replace = '';
    $search = '';
    for ($j=$i; $j<count($words); $j++) {
        $replace = $replace.$words[$j][0];
        if ($j==$i) {
            $search = $words[$j];
        } else {
            $search = $search.' '.$words[$j];
        }
        //echo 'search = '.$search.'  replace = '.$replace.PHP_EOL;
        /*if (isset($w[$search])) {
            continue;
        }*/
        $repeat = substr_count($string, $search);
        if ($repeat>=2) {
            //$length = $n-$repeat*strlen($search) + $repeat*strlen($replace);
            $w[$search] = strlen(str_replace($search, $replace, $string))-2;
            if ($min>$w[$search]) {
                $min = $w[$search];
            }
        }
    }
}
echo $min;
?>

<?php
$nn = fgets(STDIN);
$string = fgets(STDIN);

$w = [];
$n = strlen($string)-2;
$min = $n;
//запись слов
$words = [];
$word = '';
for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==$n-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}
//print_r($words);

for ($i=0; $i<count($words); $i++) {
    $replace = '';
    $search = '';
    for ($j=$i; $j<count($words); $j++) {
        $replace = $replace.$words[$j][0];
        if ($j==$i) {
            $search = $words[$j];
        } else {
            $search = $search.' '.$words[$j];
        }
        //echo 'search = '.$search.'  replace = '.$replace.PHP_EOL;
        if (isset($w[$search])) {
            continue;
        }
        $repeat = substr_count($string, $search);
        if ($repeat>=2) {
            $length = $n-$repeat*strlen($search) + $repeat*strlen($replace);
            $w[$search] = $length;
            if ($min>$length) {
                $min = $length;
            }
        }
    }
}
print_r($min);
?>

<?php
$slov = fgets(STDIN);
$string = fgets(STDIN);

$w = [];
$n = strlen($string)-2;
$min = $n;
//запись слов
$words = [];
$word = '';

for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==$n-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}
//print_r($words);

for ($i=0; $i<$slov; $i++) {
    $replace = '';
    $search = '';
    for ($j=$i; $j<$slov; $j++) {
        $replace = $replace.strtoupper($words[$j][0]);
        if ($j==$i) {
            $search = $words[$j];
        } else {
            $search = $search.' '.$words[$j];
        }
        /*if (isset($w[$search])) {
            continue;
        }*/
        $repeat = substr_count($string, $search);
        if ($repeat>=2) {
            //$length = $n-$repeat*strlen($search) + $repeat*strlen($replace);
            $w[$search] = strlen(str_replace($search, $replace, $string))-2;
            if ($min>$w[$search]) {
                $min = $w[$search];
            }
        }
    }
}

echo $min;
?>

<?php
$string = fgets(STDIN);

$w = [];
$n = strlen($string);
$min = $n;
//запись слов
$words = [];
$word = '';
for ($i=0; $i<strlen($string); $i++) {
    if ($string[$i]==' ') {
        $words[] = $word;
        $word = '';
    } elseif ($i==strlen($string)-1) {
        $word = $word.$string[$i];
        $words[] = $word;
    } else {
        $word = $word.$string[$i];
    }
}
//print_r($words);
for ($i=0; $i<count($words); $i++) {
    for ($j=$i; $j<count($words); $j++) {
        $search = '';
        $replace = '';
        for ($k=$i; $k<=$j; $k++) {
            $replace = $replace.$words[$k][0];
            if ($k==$i) {
                $search = $words[$k];
            } else {
                $search = $search.' '.$words[$k];
            }
        }
        if (substr_count($string, $search)>=2) {
            $w[$i][$j] = strlen(str_replace($search, $replace, $string));
            if ($min>$w[$i][$j]) {
                $min = $w[$i][$j];
            }
        }
        //$w[$i][$j] = 'search = '.$search.' replace = '.$replace;
    }
}
print_r($min);
?>


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c, $d, $e) = explode(" ", trim(fgets(STDIN)));
     print $c . " " . $d . " " . $d . "\n";
}
?>

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

for($t = intval(fgets(STDIN)); $t > 0; $t--){

	$a = explode(' ', fgets(STDIN));

	echo $a[1]. ' ' . $a[2]. ' '. $a[2] ."\n";

}

<?php

main();

function main() {
  $num_cases = trim(fgets(STDIN));

  for ($n = 1; $n <= $num_cases; $n++) {
    list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
    $res = run_case($a, $b, $c, $d);

    print join(" ", $res) . "\n";
  }
}

function run_case($a, $b, $c, $d) {
	return [$b, max(min($c - $b + 1, $c), $b), $c];
}

?>

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

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

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $in_str = explode(" ", trim(fgets(STDIN))) ;

        echo implode(" ", array($in_str[1], $in_str[2], $in_str[2])) . "\n" ;
    }
?>


<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
    fgetc(STDIN);
}
for ($i = $upper; $i <= $bottom; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
    }
    if ($i != $bottom) {
        echo "\n";
    }
}

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

$entries = array();
for ($i = 0; $i < $data[0]; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    $emptyRow = true;
        for ($i = 0; $i < strlen($value); $i++) {
            if ($value[$i] != 'x') {
            $emptyRow = false;
            echo($value[$i]);
            }
        }
    if (!$emptyRow) echo "\n";
}

/*
foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
        else next($entries);
    }
    echo "\n";
}
*/

?>

<?php
list($n,$m)=explode(' ',rtrim(fgets(STDIN)));
$min_x=$min_y=100;
$max_x=$max_y=-1;
$letter=array();
for ($i=0;$i<$n;$i++) {
  $line=rtrim(fgets(STDIN));
  $letter[]=$line;
  for ($j=0;$j<$m;$j++) {
    if ($line[$j]=='*') {
      $min_x=min($min_x,$j);
      $min_y=min($min_y,$i);
      $max_x=max($max_x,$j);
      $max_y=max($max_y,$i);
    }
  }
}
for ($i=$min_y;$i<=$max_y;$i++) {
  for ($j=$min_x;$j<=$max_x;$j++) {
    echo $letter[$i][$j];
  }
  echo "\n";
}
?>

<?php
function cut($letter) {
  $h=count($letter);
  $w=count($letter[0]);
  $blank=true;
  for ($i=0;$i<$h;$i++) {
    for ($j=0;$j<$w;$j++) {
      if ($letter[$i][$j]=='*') {
        $blank=false;
        break;
      }
    }
    if (! $blank) {
      $letter = array_slice($letter,$i);
      break;
    }
  }
  return $letter;
}

function rotate($letter) {
  $h=count($letter);
  $w=count($letter[0]);
  $new_letter=array();
  for ($i=0;$i<$w;$i++) $new_letter[]=array();
  for ($i=0;$i<$h;$i++) {
    for ($j=0;$j<$w;$j++) {
      $new_letter[$j][$h-$i-1]=$letter[$i][$j];
    }
  }
  return $new_letter;
}

list($n,$m)=explode(' ',rtrim(fgets(STDIN)));
$letter = array();
for ($i=0;$i<$n;$i++) {
  $line = rtrim(fgets(STDIN));
  $letter[$i]=array();
  for ($j=0;$j<strlen($line);$j++) {
    $letter[$i][]=$line[$j];
  }
}

$letter=cut($letter);
$letter=rotate($letter);
$letter=cut($letter);
$letter=rotate($letter);
$letter=cut($letter);
$letter=rotate($letter);
$letter=cut($letter);
$letter=rotate($letter);

for ($i=0;$i<count($letter);$i++) {
  for ($j=0;$j<count($letter[0]);$j++) {
    echo $letter[$i][$j];
  }
  echo "\n";
}

<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
$leftJ = -1;
$rightI = 0;
$leftI = -1;
$rightJ = 0;
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;

			$rightJ = max($rightJ, $j);
			$rightI = max($rightI, $i);
			if ($leftJ < 0)
				$leftJ = $j;
			if ($leftI < 0)
				$leftI = $i;
			$leftI = min($leftI, $i);
			$leftJ = min($leftJ, $j);

		}
	}
}
if ($leftJ < 0)
	return;
if ($leftI < 0)
	return;
for($j = $leftJ;$j<=$rightJ;$j++){
	echo substr($lines[$j], $leftI, $rightI-$leftI+1) . "\n";
}

<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft;
for(;$j<=$jLeft;$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}

<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			if (!isset($cols[$i]))
				$cols[$i] = 0;
			if (!isset($rows[$j]))
				$rows[$j] = 0;
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
if ($i == $iLeft)
	$iLeft = 1;
else
	$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft;
for(;$j<=$jLeft;$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}

<?php

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

$arr = file($in);
//$data = file_get_contents($in);
//$r = fopen($in, 'r');
list($n, $m) = explode(' ', array_shift($arr));

while (!$arr[count($arr) - 1]) {
	array_pop($arr);
}

foreach ($arr as $k1 => &$valf) {
	$valf = trim($valf);
	$valf = str_split($valf);
	foreach ($valf as $k => $a) {
		$arr2[$k][$k1] = $a;
	}

}
foreach ($arr as $k => $val) {
	if (in_array('*', $val)) {
		$minx = isset($minx) ? $minx : $k;
		$maxx = $k;
	}
}

foreach ($arr2 as $k => $val) {
	if (in_array('*', $val)) {
		$miny = isset($miny) ? $miny : $k;
		$maxy = $k;
	}
}

for ($i = $minx; $i <= $maxx; $i++) {
	for ($j = $miny; $j <= $maxy; $j++) {
		echo $arr[$i][$j];
	}
	echo "\n";
}

<?php
function emptyColumn($j) {
	global $n, $s;
	for ($i = 0; $i < $n; $i++)
		if ($s[$i][$j] == '*')
			return false;
	return true;
}
function emptyRow($i) {
	global $m, $s;
	for ($j = 0; $j < $m; $j++)
		if ($s[$i][$j] == '*')
			return false;
	return true;
}

fscanf(STDIN, "%d %d", $n, $m);
$s = array();
for ($i = 0; $i < $n; $i++)
	$s[$i] = fgets(STDIN);
$li = 0; $ri = $n - 1;
$lj = 0; $rj = $m - 1;
while (emptyRow($li)) $li++;
while (emptyRow($ri)) $ri--;
while (emptyColumn($lj)) $lj++;
while (emptyColumn($rj)) $rj--;
for ($i = $li; $i <= $ri; $i++)
	print(substr($s[$i], $lj, $rj - $lj + 1)."\n")
?>

<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = trim(fgets(STDIN));
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for(;$j<=$y && isset($rows[$j]);$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}

//var_dump($lines);
//var_dump($cols);
//var_dump($rows);

<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
$leftJ = -1;
$rightI = 0;
$leftI = -1;
$rightJ = 0;
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;
			$rightJ = $j;
			$rightI = $i;
			if ($leftJ < 0)
				$leftJ = $j;
			if ($leftI < 0)
				$leftI = $i;

		}
	}
}
if ($leftJ < 0)
	return;
if ($leftI < 0)
	return;

for($j = $leftJ;$j<$rightJ;$j++){
	echo substr($lines[$j], $leftI, $rightI-$leftI+1) . "\n";
}

<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			if (!isset($cols[$i]))
				$cols[$i] = 0;
			if (!isset($rows[$j]))
				$rows[$j] = 0;
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft++;
$jLeft = $jLeft-$j;
for(;$j<=$jLeft-1;$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}

<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
var_dump($line);
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = trim(fgets(STDIN));
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);
for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft = $x-$iLeft;
for($j=0;$j<$y && !isset($rows[$j]);$j++);
for(;$j<$y && isset($rows[$j]);$j++){
	echo substr($lines[$j], $i, $iLeft) . "\n";
}

var_dump($lines);

<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
$leftJ = -1;
$rightI = 0;
$leftI = -1;
$rightJ = 0;
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;
			$rightJ = $j;
			$rightI = $i;
			if ($leftJ < 0)
				$leftJ = $j;
			if ($leftI < 0)
				$leftI = $i;

		}
	}
}
if ($leftJ < 0)
	return;
if ($leftI < 0)
	return;

for($j = $leftJ;$j<=$rightJ;$j++){
	echo substr($lines[$j], $leftI, $rightI-$leftI+1) . "\n";
}

<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
$leftJ = -1;
$rightI = 0;
$leftI = -1;
$rightJ = 0;
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;

			$rightJ = max($rightJ, $j);
			$rightI = max($rightI, $i);
			if ($leftJ < 0)
				$leftJ = $j;
			if ($leftI < 0)
				$leftI = $i;
			$leftI = min($leftI, $i);
			$leftJ = min($leftJ, $j);

		}
	}
}
if ($leftJ < 0)
	return;
if ($leftI < 0)
	return;
echo "$leftI $rightI, $leftJ $rightJ\n";
for($j = $leftJ;$j<=$rightJ;$j++){
	echo substr($lines[$j], $leftI, $rightI-$leftI+1) . "\n";
}

<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
for($j=0;$j<$y;$j++){
	$line = trim(fgets(STDIN));
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){
			$cols[$i]++;
			$rows[$j]++;
		}
	}
}
$j=0;
$i=0;
$iLeft = 0;
$jLeft = 0;
for($i=0;$i<$x && !isset($cols[$i]);$i++);

for($iLeft=$x;$iLeft>0 && !isset($cols[$iLeft]);$iLeft--);
$iLeft++;
$iLeft = $iLeft-$i;

for($j=0;$j<$y && !isset($rows[$j]);$j++);
for($jLeft=$y;$jLeft>0 && !isset($rows[$jLeft]);$jLeft--);
$jLeft++;
$jLeft = $jLeft-$j;
for(;$j<=$jLeft;$j++){
	if (isset($rows[$j]))
		echo substr($lines[$j], $i, $iLeft) . "\n";
}

//var_dump($lines);
//var_dump($cols);
//var_dump($rows);

<?

$line = trim(fgets(STDIN)); // reads one line from STDIN
list($y,$x) = explode(' ', $line);
$arr = array();

$cols = array();
$rows = array();
$lines = array();
$leftJ = -1;
$rightJ = 0;
$leftI = -1;
$rightJ = 0;
for($j=0;$j<$y;$j++){
	$line = fgets(STDIN);
	$lines[] = $line;
	for($i=0;$i<$x;$i++){
		if ($line[$i] == '*'){

			$cols[$i]++;
			$rows[$j]++;
			$rightJ = $j;
			$rightI = $i;
			if ($leftJ < 0)
				$leftJ = $j;
			if ($leftI < 0)
				$leftI = $i;

		}
	}
}
for($j = $leftJ;$j<=$rightJ;$j++){
	echo substr($lines[$j], $leftI, $rightI-$leftI+1) . "\n";
}

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1] - 1; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    unset($array[$row]);
/*
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
*/
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

/*
foreach ($entries as $value) {
    $emptyRow = true;
        for ($i = 0; $i < strlen($value); $i++) {
            if ($value[$i] != 'x') {
            $emptyRow = false;
            echo($value[$i]);
            }
        }
    if (!$emptyRow) echo "\n";
}
*/

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
        else next($entries);
    }
    echo "\n";
}

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1] - 1; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    unset($array[$row]);
/*
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
*/
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
 $emptyRow = true;
 for ($i = 0; $i < strlen($value); $i++) {
  if ($value[$i] != 'x') {$emptyRow = false; echo($value[$i]);}
 }
 if (!$emptyRow) echo "\n";
}

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1]; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
    }
    echo "\n";
}
//

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1]; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
    }
    echo "\n";
}

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1] - 1; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    unset($array[$row]);
/*
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
*/
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
    }
    echo "\n";
}

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1] - 1; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
    }
    echo "\n";
}

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1] - 1; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    $emptyRow = true;
        for ($i = 0; $i < strlen($value); $i++) {
            if ($value[$i] != 'x') {
            $emptyRow = false;
            echo($value[$i]);
            }
        }
    if (!$emptyRow) echo "\n";
}

/*
foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
        else next($entries);
    }
    echo "\n";
}
*/

?>

<?php

$line = trim(fgets(STDIN));
$data = explode(" ", $line);

for ($i = 0; $i < $data[1]; $i++) {
    $entries[] = trim(fgets(STDIN));
}

$rows = $data[0];
$cols = $data[1];

function check_if_empty_row($array, $row) {
    if (strpos($array[$row], '*') === false) return true;
    else return false;
}

function check_if_empty_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        if ($array[$i][$col] != '.') return false;
    }
    return true;
}

function delete_col($array, $col) {
    for ($i = 0; $i < count($array); $i++) {
        $array[$i] = substr_replace($array[$i], 'x', $col, 1);
    }
    return $array;
}

function delete_row($array, $row) {
    $length = strlen($array[$row]);
    $array[$row] = '';
        for ($i = 0; $i < $length; $i++) {
            $array[$row] .= 'x';
        }
    return $array;
}

for ($i = 0; $i < $cols; $i++) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = $cols - 1; $i >= 0; $i--) {
    if (check_if_empty_col($entries, $i)) $entries = delete_col($entries, $i);
    else break;
}

for ($i = 0; $i < $rows; $i++) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

for ($i = $rows - 1; $i >= 0; $i--) {
    if (check_if_empty_row($entries, $i)) $entries = delete_row($entries, $i);
    else break;
}

foreach ($entries as $value) {
    for ($i = 0; $i < strlen($value); $i++) {
        if ($value[$i] != 'x') print_r($value[$i]);
    }
    echo "\n";
}
print_r($entries);

?>

<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
    fgetc(STDIN);
}
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
        if ($j == $m - 1) {
            echo "\n";
        }
    }
}

<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
}
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
        if ($j == $m - 1) {
            echo "\n";
        }
    }
}

<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
    fgetc(STDIN);
}
for ($i = $upper; $i <= $bottom; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
    }
}

<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
//    fgetc(STDIN);
}
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
        if ($j == $m - 1) {
            echo "\n";
        }
    }
}

<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
}
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
        }
    }
    echo "\n";
}

<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
}
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
//        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
            echo $pixels[$i][$j];
//        }
        if ($j == $m - 1) {
            echo "\n";
        }
    }
}

<?php
$input = fscanf(STDIN, '%d%d');
$n = $input[0];
$m = $input[1];
$upper = $n;
$bottom = 0;
$left = $m;
$right = 0;
$pixels = array();
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $j < $m; $j++) {
        $pixel = fgetc(STDIN);
        $pixels[$i][$j] = $pixel;
        if ($pixel == '*') {
            if ($left > $j) {
                $left = $j;
            }
            if ($right < $j) {
                $right = $j;
            }
            if ($upper > $i) {
                $upper = $i;
            }
            if ($bottom < $i) {
                $bottom = $i;
            }
        }
    }
    fgetc(STDIN);
}
//for ($i = 0; $i < $n; $i++) {
//    for ($j = 0; $j < $m; $j++) {
//        if ($i <= $bottom && $i >= $upper && $j <= $right && $j >= $left) {
//            echo $pixels[$i][$j];
//        }
//        if ($j == $m - 1) {
//            echo "\n";
//        }
//    }
//}

print_r($pixels);