<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

list($n, $k) = $ir->readArrayOfInt(2);

$bc = Utils::bitCount($n);
if ($bc > $k || $n<$k) {
	echo "NO";
	exit();
} else {
	$stack = str_split(strrev(decbin($n)), 1);

	$d = $k - $bc;
	while ($d > 0) {
		$top = array_pop($stack);
		if ($top === null) {echo "NO";exit();}
		if ($top <= $d) {
			$d -= $top;
			$x = array_pop($stack);
			if ($x === null) {echo "NO";exit();}
			$x+= $top*2;
			array_push($stack, $x);
		} else {
			$x = array_pop($stack);
			if ($x === null) {echo "NO";exit();}
			$x+= $d*2;
			array_push($stack, $x);
			array_push($stack, $top-$d);
			$d -= $d;
		}

	}
	$s = '';
	foreach ($stack as $degree=>$count) {
		$s .= str_repeat(' ' . (1<<$degree), $count);
	}
	echo "YES\n";
	echo trim($s);
}

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

list($n, $k) = $ir->readArrayOfInt(2);

$bc = Utils::bitCount($n);
if ($bc > $k) {
	echo "NO";
	exit();
} else {
	$stack = str_split(strrev(decbin($n)), 1);

	$d = $k - $bc;
	while ($d > 0) {
		$top = array_pop($stack);
		if ($top <= $d) {
			$d -= $top;
			$x = array_pop($stack);
			$x+= $top*2;
			array_push($stack, $x);
		} else {
			$x = array_pop($stack);
			$x+= $d*2;
			array_push($stack, $x);
			array_push($stack, $top-$d);
			$d -= $d;
		}
	}
	$s = '';
	foreach ($stack as $degree=>$count) {
		$s .= str_repeat(' ' . (1<<$degree), $count);
	}
	echo "YES\n";
	echo trim($s);
}

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

list($n, $k) = $ir->readArrayOfInt(2);

$bc = Utils::bitCount($n);
if ($bc > $k || $n<$k) {
	echo "NO";
	exit();
} else {
	$stack = str_split(strrev(decbin($n)), 1);
	var_dump($stack);

	$d = $k - $bc;
	while ($d > 0) {
		$top = array_pop($stack);
		if ($top === null) {echo "NO";exit();}
		if ($top <= $d) {
			$d -= $top;
			$x = array_pop($stack);
			if ($x === null) {echo "NO";exit();}
			$x+= $top*2;
			array_push($stack, $x);
		} else {
			$x = array_pop($stack);
			if ($x === null) {echo "NO";exit();}
			$x+= $d*2;
			array_push($stack, $x);
			array_push($stack, $top-$d);
			$d -= $d;
		}
		var_dump($stack);
	}
	$s = '';
	foreach ($stack as $degree=>$count) {
		$s .= str_repeat(' ' . (1<<$degree), $count);
	}
	echo "YES\n";
	echo trim($s);
}


<?php

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

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

    if ($die) {
        die();
    }

    echo '</pre>';
}

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

    return $stdin;
}

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

$stdin = stdin();
/****************************************************** Solving block *****************************************************/
$n = g();

$stat = explode(' ', g());
$stat = array_unique($stat);
sort($stat);

echo isset($stat[1]) ? $stat[1] : 'NO';

?>

<?php

$stdin = fopen('php://stdin', 'r');
$cnt = trim(fgets($stdin));
$numbers = explode(" ",trim(fgets($stdin)));
if ($cnt == 1) {
    echo "NO";
} else {
    sort($numbers);
    $min = min($numbers);
    if ($numbers[$cnt - 1] == $min) {
        echo "NO";
    } else {
        foreach ($numbers as $number) {
            if ($number > $min) {
                echo $number;
                break;
            }
        }
    }
}

<?
$n=trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
sort($arr);
function stat2(&$arr){
    for($i=1,$n=sizeof($arr);$i<$n;$i++){
        if($arr[0]!=$arr[$i])
            return $arr[$i];
    }
}
$res = stat2($arr);
$r=($res!=null) ? $res : "NO";
echo $r;
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = array_unique($b);
$d = array();
for($x = 0; $x < count($c); $x++)
{
    array_push($d, $x);
}
$e = array_combine($d, $c);
if(($e[1]) && ($e[1] != $e[0]))
{
    print $e[1];
}
else
{
    print "NO";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = array_unique($b);
$d = array();
for($x = 0; $x < count($c); $x++)
{
    array_push($d, $x);
}
$e = array_combine($d, $c);
print $e[1];
?>

<?php
$k=trim(fgets(STDIN));
$p=explode(" ",(fgets(STDIN)));
sort($p);
$i=0;
foreach ($p as $key)
{ if ($p[$i]!=$p[$i+1]) { $r=$p[$i+1]; } else { $i++;} ;}
if (!isset($p[1])) {print "NO";};
print $r;
?>

<?php
$k=trim(fgets(STDIN));
$p=explode(" ",(fgets(STDIN)));
sort($p);
$i=0;
foreach ($p as $key)
{ if ($p[$i]==$p[$i+1])  { $i++;}  else { $r=$p[$i+1]; }  ;}
if (!isset($p[1])) {print "NO";};
print $r;
?>

<?php
$k=trim(fgets(STDIN));
$p=explode(" ",trim(fgets(STDIN)));
sort($p);
$i=0;
foreach ($p as $key)
{ if ($p[$i]==$p[$i+1])  { $i++;}  else { $r=$p[$i+1]; }  ;}
if (!isset($p[1])) {$l="NO";};
if ($r>0) {print $r;} else {print $l;};
?>

<?php
$k=trim(fgets(STDIN));
$p=explode(" ",trim(fgets(STDIN)));
sort($p);
$i=0;
foreach ($p as $key)
{ if ($p[$i]==$p[$i+1])  { $i++;}  else { $r=$p[$i+1]; }  ;}
if (!isset($p[1])) {print "NO";};
print $r;
?>

<?php
$k=trim(fgets(STDIN));
$p=explode(" ",trim(fgets(STDIN)));
sort($p);
$i=0;
foreach ($p as $key)
{ if ($p[$i]==$p[$i+1])  { $i++;}  else { $r=$p[$i+1]; }  ;}
if (!isset($p[1])) {print "NO";};
if ($r>0) {print $r;} else {print "NO";};
?>

<?php

$stdin = fopen('php://stdin', 'r');
$cnt = trim(fgets($stdin));
$numbers = [];
for ($i = 0; $i < $cnt; $i++) {
    $numbers[] = trim(fgets($stdin));
}
if (count($numbers) == 1) {
    echo "NO";
} else {
    sort($numbers);
    $min = min($numbers);
    if ($numbers[count($numbers) - 1] == $min) {
        echo "NO";
    } else {
        foreach ($numbers as $number) {
            if ($number > $min) {
                echo $number;
                break;
            }
        }
    }
}

<?php

$stdin = fopen('php://stdin', 'r');
$cnt = trim(fgets($stdin));
for ($i = 0; $i < $cnt; $i++) {
    $numbers[] = trim(fgets($stdin));
}
sort($numbers);
$min = min($numbers);
foreach ($numbers as $number)
{
    if($number > $min)
    {
        echo $number;
        break;
    }
}

<?
$n=trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
sort($arr);
function stat2(&$arr){
    for($i=1,$n=sizeof($arr);$i<$n;$i++){
        if($arr[0]!=$arr[$i])
            return $arr[$i];
    }
}
$res = stat2($arr);
$res=(!null) ? $res : "NO";
echo $res;
?>

<?
$n=trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
sort($arr);
function stat2(&$arr){
    for($i=1,$n=sizeof($arr);$i<$n;$i++){
        if($arr[0]!=$arr[$i])
            return $arr[$i];
    }
}
echo stat2($arr);
?>


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

    $gamers = array("I" => 0, "A" => 0, "F" => 0);
    $in = 0;
    $all = 0;

    for ($i = 0; $i < $n; ++$i) {
        if ($str[$i] == "I")
            ++$in;
        if ($str[$i] == "A")
            ++$all;
    }

    if ($in > 1)
        print(0);
    else if ($in == 1)
        print(1);
    else
        print($all);
?>

<?
	fgets(STDIN);
	$d = trim(fgets(STDIN));
	$a = substr_count($d, 'I');
	print ($a<1 ? substr_count($d, 'A') : ($a>1 ? 0 : 1));
 ?>

<?
	fgets(STDIN);
	$d = trim(fgets(STDIN));
	$a = substr_count($d, 'I');
	echo ($a<1 ? substr_count($d, 'A') : ($a>1 ? 0 : 1));
 ?>

<?
 fgets(STDIN);
 $data = trim(fgets(STDIN));
 $a = substr_count($data, 'I');
 if ($a == 1) print 1;
 elseif ($a > 1) print 0;
 else print substr_count($data, 'A');
?>

<?
 fgets(STDIN);
 $data = trim(fgets(STDIN));
 $a = substr_count($data, 'I');
 if ($a == 1){
 	print 1;
 }elseif ($a > 1){
 	print 1;
 }else print substr_count($data, 'A');
 ?>

<?
 fgets(STDIN);
 $data = trim(fgets(STDIN));
 $arr = array();
 for ($i=0;$i<strlen($data);$i++){
 	$arr[$data{$i}]++;
 }
 if (isset($arr['I'])) print $arr['I'];
 elseif (isset($arr['A'])) print $arr['A'];
 else print 0;
 ?>

<?
 fgets(STDIN);
 $data = trim(fgets(STDIN));
 $c = strlen($data);
 if ($c<2 || $c>200000) print 0;
 else{
    $sc = substr_count($data, 'I');
 	if ($sc>0) print $sc;
 	else print substr_count($data, 'A');
 }
 ?>

<?
 fgets(STDIN);
 $data = trim(fgets(STDIN));
 $arr = array();
 $c = strlen($data);
 for ($i=0;$i<$c;$i++)
 	$arr[$data{$i}]++;

 if (isset($arr['I'])) print $arr['I'];
 elseif (isset($arr['A'])) print $arr['A'];
 else print 0;
 ?>

<?
 $a = fgets(STDIN);
 $data = trim(fgets(STDIN));
 $arr = array();
 for ($i=0;$i<$a;$i++){
 	$arr[$data{$i}]++;
 }
  if (isset($arr['I'])) print $arr['I'];
  elseif (isset($arr['A'])) print $arr['A'];
  else print 0;
 ?>

<?
 fgets(STDIN);
 $data = trim(fgets(STDIN));
 $a = substr_count($data, 'I');
 if ($a == 1){
 	print 1;
 }elseif ($a > 1){
 	print $a - 1;
 }else print substr_count($data, 'A');
 ?>

<?
 fgets(STDIN);
 $data = trim(fgets(STDIN));
 $sc = substr_count($data, 'I');
 if ($sc>0) print $sc;
 else print substr_count($data, 'A');
 ?>

<?
 fgets(STDIN);
 $data = trim(fgets(STDIN));
 $arr = array();
 for ($i=0;$i<strlen($data);$i++){
 	$arr[$data{$i}]++;
 }
 if (isset($arr['I'])) print $arr['I'];
 elseif (isset($arr['A'])) print $arr['A'];
 else print $arr['F'];
 ?>


<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

/*	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	//for ($i = 0; $i < $temp_len / 2; $i++) {
	if ((int)($temp_len / 2) % 2 === 1 && $temp_len !== 3){
		for ($i = 0; $i < (int)($temp_len / 2) - 1; $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
		if ($temp_len % 2 === 1) {
			$temp_arr_1[] = $arr_key[(int)($temp_len / 2) - 1] + 1;
			$temp_arr_2[] = $arr_key[(int)($temp_len / 2) + 1] + 1;
		} else {
			$temp_arr_1[] = $arr_key[(int)($temp_len / 2) - 1] + 1;
			$temp_arr_2[] = $arr_key[(int)($temp_len / 2)] + 1;
		}
	} else {
		for ($i = 0; $i < (int)($temp_len / 2); $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
	}
	//if ($temp_len % 2 === 1) $temp_arr_1[] = $arr_key[$temp_len / 2 + 1] + 1;
	if ($temp_len % 2 === 1) $temp_arr_2[] = $arr_key[(int)($temp_len / 2)] + 1;

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.ループのキャスト
2.残った1つを入れる配列
3.indexのキャスト
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.ループのキャスト
2.残った1つを入れる配列
3.indexのキャスト
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;
	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}

/*	another way roop numbers is half.
	$len = count($arr_key);
	for ($i = 0; $i < $len / 2; $i++) {
		if ($temp_c % 2 === 1) {
			$temp_arr_1[] = $arr_key[$i] + 1;
			$temp_arr_1[] = $arr_key[$len - $i - 1] + 1;
		} else {
			$temp_arr_2[] = $arr_key[$i] + 1;
			$temp_arr_2[] = $arr_key[$len - $i - 1] + 1;
	}
	if ($len % 2 === 1) $temp_arr_1[] = $arr_key[$len % 2 + 1] + 1;
	}
*/
	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.runtime err クラスの名称
2.output 01
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

/* basic coding (this code is not best, because changing token and float is not good)
	$vp = (float)strtok(rtrim(fgets(STDIN, 10), "\n"), " ");
	$vd = (float)strtok(" ");
	$t = (float)strtok(" ");
	$f = (float)strtok(" ");
	$c = (float)strtok(" ");
*/
	//use Token class(advatage of using this class is changing token and float is more easy)
	//$Token = new Token(rtrim(fgets(STDIN, 5), "\n"), " ");
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray(12);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;
	foreach ($arr_key as $as_i) {
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		$temp_c++;
	}
		array_printf($temp_arr_1);
		print("\n");
		array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.runtime err クラスの名称
2.output 01
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

/*	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	//for ($i = 0; $i < $temp_len / 2; $i++) {
	if ((int)($temp_len / 2) / 2 === 1){
		for ($i = 0; $i < (int)($temp_len / 2) - 1; $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
		$temp_arr_1[(int)($temp_len / 2) - 1];
		$temp_arr_2[(int)($temp_len / 2)];
	} else {
		for ($i = 0; $i < (int)($temp_len / 2) - 1; $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
	}
	//if ($temp_len % 2 === 1) $temp_arr_1[] = $arr_key[$temp_len / 2 + 1] + 1;
	if ($temp_len % 2 === 1) $temp_arr_2[] = $arr_key[(int)($temp_len / 2)] + 1;

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.ループのキャスト
2.残った1つを入れる配列
3.indexのキャスト
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

/*	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	//for ($i = 0; $i < $temp_len / 2; $i++) {
	if ((int)($temp_len / 2) % 2 === 1 && $temp_len !== 3){
		for ($i = 0; $i < (int)($temp_len / 2) - 1; $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
		$temp_arr_1[] = $arr_key[(int)($temp_len / 2) - 1] + 1;
		$temp_arr_2[] = $arr_key[(int)($temp_len / 2)] + 1;
	} else {
		for ($i = 0; $i < (int)($temp_len / 2); $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
	}
	//if ($temp_len % 2 === 1) $temp_arr_1[] = $arr_key[$temp_len / 2 + 1] + 1;
	if ($temp_len % 2 === 1) $temp_arr_2[] = $arr_key[(int)($temp_len / 2)] + 1;

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.ループのキャスト
2.残った1つを入れる配列
3.indexのキャスト
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

/*	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	//for ($i = 0; $i < $temp_len / 2; $i++) {
	for ($i = 0; $i < (int)($temp_len / 2); $i++) {
		if ($temp_c % 2 === 1) {
			$temp_arr_1[] = $arr_key[$i] + 1;
			$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
		} else {
			$temp_arr_2[] = $arr_key[$i] + 1;
			$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
		}
		$temp_c++;
	}
	if ($temp_len % 2 === 1) $temp_arr_2[] = $arr_key[(int)($temp_len / 2) + 1] + 1;

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.runtime err クラスの名称
2.output 01
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

/*	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	//for ($i = 0; $i < $temp_len / 2; $i++) {
	if ((int)($temp_len / 2) % 2 === 1 && $temp_len !== 3){
		for ($i = 0; $i < (int)($temp_len / 2) - 1; $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
		$temp_arr_1[] = $arr_key[(int)($temp_len / 2) - 1];
		$temp_arr_2[] = $arr_key[(int)($temp_len / 2)];
	} else {
		for ($i = 0; $i < (int)($temp_len / 2); $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
	}
	//if ($temp_len % 2 === 1) $temp_arr_1[] = $arr_key[$temp_len / 2 + 1] + 1;
	if ($temp_len % 2 === 1) $temp_arr_2[] = $arr_key[(int)($temp_len / 2)] + 1;

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.ループのキャスト
2.残った1つを入れる配列
3.indexのキャスト
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

/*	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	//for ($i = 0; $i < $temp_len / 2; $i++) {
	if ((int)($temp_len / 2) / 2 === 1 && $temp_len !== 3){
		for ($i = 0; $i < (int)($temp_len / 2) - 1; $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
		$temp_arr_1[(int)($temp_len / 2) - 1];
		$temp_arr_2[(int)($temp_len / 2)];
	} else {
		for ($i = 0; $i < (int)($temp_len / 2); $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
	}
	//if ($temp_len % 2 === 1) $temp_arr_1[] = $arr_key[$temp_len / 2 + 1] + 1;
	if ($temp_len % 2 === 1) $temp_arr_2[] = $arr_key[(int)($temp_len / 2)] + 1;

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.ループのキャスト
2.残った1つを入れる配列
3.indexのキャスト
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;
	foreach ($arr_key as $as_i) {
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		$temp_c++;
	}

/*	another way roop numbers is half.
	$len = count($arr_key);
	for ($i = 0; $i < $len / 2; $i++) {
		if ($temp_c % 2 === 1) {
			$temp_arr_1[] = $arr_key[$i];
			$temp_arr_1[] = $arr_key[$len - $i - 1];
		} else {
			$temp_arr_2[] = $arr_key[$i];
			$temp_arr_2[] = $arr_key[$len - $i - 1];
	}
	if ($len % 2 === 1) $temp_arr_1[] = $arr_key[$len % 2 + 1];
	}
*/
	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.runtime err クラスの名称
2.output 01
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

/*	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	//for ($i = 0; $i < $temp_len / 2; $i++) {
	if ((int)($temp_len / 2) / 2 === 1 && $temp_len !== 3){
		for ($i = 0; $i < (int)($temp_len / 2) - 1; $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
		$temp_arr_1[(int)($temp_len / 2) - 1];
		$temp_arr_2[(int)($temp_len / 2)];
	} else {
		for ($i = 0; $i < (int)($temp_len / 2) - 1; $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
	}
	//if ($temp_len % 2 === 1) $temp_arr_1[] = $arr_key[$temp_len / 2 + 1] + 1;
	if ($temp_len % 2 === 1) $temp_arr_2[] = $arr_key[(int)($temp_len / 2)] + 1;

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.ループのキャスト
2.残った1つを入れる配列
3.indexのキャスト
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();

/*	$temp_c = 1;
	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	for ($i = 0; $i < $temp_len / 2; $i++) {
		if ($temp_c % 2 === 1) {
			$temp_arr_1[] = $arr_key[$i] + 1;
			$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
		} else {
			$temp_arr_2[] = $arr_key[$i] + 1;
			$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
	}
	if ($temp_len % 2 === 1) $temp_arr_1[] = $arr_key[$temp_len % 2 + 1] + 1;
	}

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.runtime err クラスの名称
2.output 01
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

/*	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	//for ($i = 0; $i < $temp_len / 2; $i++) {
	for ($i = 0; $i < (int)($temp_len / 2); $i++) {
		if ($temp_c % 2 === 1) {
			$temp_arr_1[] = $arr_key[$i] + 1;
			$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
		} else {
			$temp_arr_2[] = $arr_key[$i] + 1;
			$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
		}
		$temp_c++;
	}
	//if ($temp_len % 2 === 1) $temp_arr_1[] = $arr_key[$temp_len / 2 + 1] + 1;
	if ($temp_len % 2 === 1) $temp_arr_2[] = $arr_key[(int)($temp_len / 2)] + 1;

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.ループのキャスト
2.残った1つを入れる配列
3.indexのキャスト
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

/*	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	//for ($i = 0; $i < $temp_len / 2; $i++) {
	for ($i = 0; $i < (int)$temp_len / 2; $i++) {
		if ($temp_c % 2 === 1) {
			$temp_arr_1[] = $arr_key[$i] + 1;
			$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
		} else {
			$temp_arr_2[] = $arr_key[$i] + 1;
			$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
		}
		$temp_c++;
	}
	if ($temp_len % 2 === 1) $temp_arr_2[] = $arr_key[$temp_len / 2 + 1] + 1;

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.runtime err クラスの名称
2.output 01
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

/*	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	//for ($i = 0; $i < $temp_len / 2; $i++) {
	if ((int)($temp_len / 2) % 2 === 1 && $temp_len !== 3){
		for ($i = 0; $i < (int)($temp_len / 2) - 1; $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
		$temp_arr_1[(int)($temp_len / 2) - 1];
		$temp_arr_2[(int)($temp_len / 2)];
	} else {
		for ($i = 0; $i < (int)($temp_len / 2); $i++) {
			if ($temp_c % 2 === 1) {
				$temp_arr_1[] = $arr_key[$i] + 1;
				$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
			} else {
				$temp_arr_2[] = $arr_key[$i] + 1;
				$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
			}
			$temp_c++;
		}
	}
	//if ($temp_len % 2 === 1) $temp_arr_1[] = $arr_key[$temp_len / 2 + 1] + 1;
	if ($temp_len % 2 === 1) $temp_arr_2[] = $arr_key[(int)($temp_len / 2)] + 1;

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.ループのキャスト
2.残った1つを入れる配列
3.indexのキャスト
*/
?>

<?php
//input -  $inp_
//block    $temp_
//as 	   $as_
//instance $(Upper)

//class menba $_

class Token {
	private $_token;
	private $_tok;

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

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

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

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

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

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

function solve(){

	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_k = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$inp_arr = $Token->nextIntArray($inp_k);

	if (arsort(&$inp_arr) === false) {
		print(-1);
		return;
	}
	$arr_key =  array_keys($inp_arr);
	$temp_arr_1 = array();
	$temp_arr_2 = array();
	$temp_c = 1;

/*	foreach ($arr_key as $as_i) {
		//if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i;
		if ($temp_c % 2 === 1) $temp_arr_1[] = $as_i + 1;
		//else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i;
		else if ($temp_c % 2 === 0) $temp_arr_2[] = $as_i + 1;
		$temp_c++;
	}
*/
	//another way roop numbers is half.
	$temp_len = count($arr_key);
	for ($i = 0; $i < $temp_len / 2; $i++) {
		if ($temp_c % 2 === 1) {
			$temp_arr_1[] = $arr_key[$i] + 1;
			$temp_arr_1[] = $arr_key[$temp_len - $i - 1] + 1;
		} else {
			$temp_arr_2[] = $arr_key[$i] + 1;
			$temp_arr_2[] = $arr_key[$temp_len - $i - 1] + 1;
		}
		$temp_c++;
	}
	if ($temp_len % 2 === 1) $temp_arr_1[] = $arr_key[$temp_len % 2 + 1] + 1;

	$len_arr1 = count($temp_arr_1);
	$len_arr2 = count($temp_arr_2);
	printf("%d\n", $len_arr1);
	array_printf($temp_arr_1);
	printf("\n%d\n", $len_arr2);
	array_printf($temp_arr_2);
}

function run(){
	solve();
}

ob_end_clean();
run();
/*
1.runtime err クラスの名称
2.output 01
*/
?>


<?php

error_reporting(0);

solve();

function solve(){

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

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

	for ($i = 0; $i < $N; $i++)
	{
		$A[] = (int)$Input->in();
	}

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

	$max = -1;
	$c = 0;

	for ($i = 0; $i < $M; $i++)
	{
		$B = (int)$Input->in();

		foreach ($A as $a)
		{
			if ($B % $a === 0)
			{
				if ($max < intval($B / $a))
				{
					$max = intval($B / $a);
					$c = 1;
				}
				else if ($max === intval($B / $a))
				{
					$c++;
				}
			}
		}

	}

	print($c);
}

class Input{
	private $handle = "";
	private $values = array();
	private $index = 0;

	public function __construct($localfile){

		if (is_file($localfile)) {

			$this->handle = fopen($localfile, "r");
			$contents = stream_get_contents($this->handle);

		} else {

			$contents = stream_get_contents(STDIN);

		}

		$no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->values = explode(" ", $no_newlines);
	}

	public function in(){

		return $this->values[$this->index++];

	}

	public function close(){

		if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

	}
}

?>

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

<?php
$n = trim(fgets(STDIN));
$a = explode(' ',trim(fgets(STDIN)));
$m = trim(fgets(STDIN));
$b = explode(' ',trim(fgets(STDIN)));

$max = 0;
$r = 0;
for($i=0;$i<$n;$i++)
 for($j=0;$j<$m;$j++)
  if($b[$j] % $a[$i] == 0)
   if($b[$j]/$a[$i] == $max) $r++; else {$max = $b[$j]/$a[$i]; $r = 1;}

print $r;
?>


<?php

$s = trim(fgets(STDIN));
$k = (int)fgets(STDIN);
$values = array_map('intval', explode(' ', trim(fgets(STDIN))));
$index = array_search(max($values), $values);
$char = chr(ord('a') + $index);

for ($i = 0; $i < $k; $i++) {
	$s .= $char;
}

$res = 0;
for ($i = 0; $i < strlen($s); $i++) {
	$res += ($i+1) * $values[ord($s[$i])-ord('a')];
}

echo $res."\n";


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

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t= trim(fgets($handle));
for($k=0;$k<$t;$k++)
{
    $h= trim(fgets($handle));
    $h=explode(' ',$h);
    $n=$h[0];$m=$h[1];
    $a= trim(fgets($handle));
    $a=explode(' ',$a);
    $sum=0;
    $max=0;
    foreach ($a as $b)
    {
        if($max<$b)
        {
            $max=$b;
        }
        $sum+=$b;
    }
    if($sum<$m)
        echo $sum."\n";
    else
        echo $m."\n";
}

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t= trim(fgets($handle));
for($k=0;$k<$t;$k++)
{
    $h= trim(fgets($handle));
    $h=explode(' ',$h);
    $n=$h[0];$m=$h[1];
    $a= trim(fgets($handle));
    $a=explode(' ',$a);
    echo $m."\n";
}


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

$s = trim(fgets($f));
list($n,$m) = explode(" ",$s);

$repl = array();
for($i=0;$i<$m;$i++){
    $s = trim(fgets($f));
    list($a,$b) = explode(" ",$s);

    if (strlen($b)<strlen($a)){
        $repl[$a] = $b;
    }
}

$s = trim(fgets($f));
$x = explode(" ",$s);
$y = array();
foreach($x as $item){
    if (isset($repl[$item])) $y[] = $repl[$item]; else $y[] = $item;
}

echo implode(" ",$y);

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));

	$mp = array();
	while ($b>0)
	{
list($c, $d) = explode(" ", trim(fgets(STDIN)));
		if(strlen($c)>strlen($d))
			$mp[$c]=$d;
		else
			$mp[$c]=$c;
	$b--;}

$qw = explode(" ", trim(fgets(STDIN)));
	for ($i=0;$i<$a;$i++)
	{
		if ($i != $a-1)
		echo $mp[$qw[$i]]." ";
else echo $mp[$qw[$i]].PHP_EOL;
	}

?>

<?php
$string=explode(" ", readline());
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo1 = array();
$arreglo2 = array();
for($i = 0; $i <$palabras+1; $i++){
    if($i == $palabras){
        $ultimas= explode(" ",readline() );
    }else{
 list($a,$b) = explode(" ",readline());
    $arreglo1[$a] = $b;
    $arreglo2[$b] = $a;
    }
}

$resultado = [];
foreach($ultimas as $ultima){
        if(strlen($ultima) <= strlen($arreglo1[$ultima])){
            $resultado[] = $ultima;
        }else{
            $resultado[] = $arreglo1[$ultima];
        }
}
echo implode(" ",$resultado);

<?php

$head_str = readline();

$head_info = explode(' ', $head_str);
$lection_size = $head_info[0];
$voc_size = $head_info[1];

$voc = [];

for($a = 0;$a < $voc_size; $a++){

    $voc_str = trim(readline());
    $data = explode(' ', $voc_str);

    if(strlen($data[0]) > strlen($data[1])){
        $short_sting = $data[1];
    }
    else{
        $short_sting = $data[0];
    }

    $voc[$data[0]] = $short_sting;

}

$lection = readline();

$lection_array = explode(' ', $lection);
$new_lect = [];
for($a = 0;$a < $lection_size; $a++){
    $new_lect[] = $voc[$lection_array[$a]];
}

$return = implode(' ', $new_lect);

print_r($return);

return 0;

?>

<?php
/*
 * Secdra @2020
 */

fscanf(STDIN, "%d %d", $n, $m);
$dic = [];
for ($i = 0; $i < $m; $i++) {
    fscanf(STDIN, "%s %s", $a, $b);
    $dic[$a] = $b;
}

$sentence = explode(' ', trim(fgets(STDIN)));
foreach ($sentence as $word) {
    printf("%s ", (strlen($word) <= strlen($dic[$word])) ? $word : $dic[$word]);
}

<?php

$line = array_map('intval',explode(' ', trim(fgets(STDIN))));
$n = $line[0];
$m = $line[1];
$trans = [];
for ($i = 0; $i < $m; $i++) {
	$couple = explode(' ', trim(fgets(STDIN)));
	if (strlen($couple[0]) <= strlen($couple[1])) {
		$key = $couple[0];
		$val = $couple[0];
	}
	else {
		$key = $couple[0];
		$val = $couple[1];
	}
	$trans[$key] = $val;
}

for ($i = 0; $i < $n; $i++) {
	$words = explode(' ', trim(fgets(STDIN)));
	foreach ($words as $word) {
		echo $trans[$word]." ";
	}
}

echo $res;

<?php
$numletter=trim(fgets(STDIN));
settype($numletter,'string');
$numletter=explode(' ',$numletter)[1];
$array=[];
$help1=[];
for ($i=0;$i<$numletter;$i++) {
$help=fgets(STDIN);
$help1=str_word_count($help,1);
$array[$help1[0]]=$help1[1];
}
 $result=null;
 $jomle=str_word_count(fgets(STDIN),1);
foreach ($jomle as $key => $kalame) {
     if(strlen($array[$kalame]) < strlen($kalame)){
        $jomle[$key]=$array[$kalame];
     }
}
echo join(' ',$jomle);

<?php
fscanf(STDIN,"%d %d",$n,$m);
for($i=0;$i<$m;$i++)
{
	$line[$i]=explode(" ",trim(fgets(STDIN)));
     if(strlen($line[$i][0])<=strlen($line[$i][1]))
     	 $str[$i]=$line[$i][0];
     	else
     		$str[$i]=$line[$i][1];

}
//print_r($str);
$text=explode(" ",trim(fgets(STDIN)));
//print_r($text);

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

    // echo "text=$text[$i]\n";
	if($text[$i]==$line[$j][0])
	{

         if($i==$n-1)
         	echo "$str[$j]";
         else
         	echo "$str[$j] ";
	}
}
}

<?php
list($m, $n) = explode(' ',fgets(STDIN));
$ab = [];
$ba = [];
for($i = 0; $i < $n; $i++){
    list($a,$b) = explode(' ',trim(fgets(STDIN)));
    $ab[$a] = $b;
    $ba[$b] = $a;
}
$words = explode(' ',trim(fgets(STDIN)));
$res = [];
foreach($words as $w){
    if(isset($ab[$w])){
        if(strlen($w) <= strlen($ab[$w])){
            $res[] = $w;
        }else{
            $res[] = $ab[$w];
        }
    }else{
        if(isset($ba[$w])){
            if(strlen($w) <= strlen($ba[$w])){
                $res[] = $w;
            }else{
                $res[] = $ba[$w];
            }
        }
    }
}
echo implode(' ',$res) . PHP_EOL;

<?php
list($m, $n) = explode(" ",fgets(STDIN));
$idioma1 = array();
$idioma2 = array();
for($i = 0; $i < $n; $i++){
    list($a,$b) = explode(" ",trim(fgets(STDIN)));
    $idioma1[$a] = $b;
    $idioma2[$b] = $a;
    //echo "este es a: ".$a." este es b: ".$b." este es idioma1[a]: ". $idioma1[$a] . " este es idioma2[b]: " . $idioma2[$b];
}
//var_dump($idioma1);
//var_dump($idioma2);
$palabras = explode(" ",trim(fgets(STDIN)));
$resultado = [];
foreach($palabras as $palabra){
    if(isset($idioma1[$palabra])){
        if(strlen($palabra) <= strlen($idioma1[$palabra])){
            $resultado[] = $palabra;
        }else{
            $resultado[] = $idioma1[$palabra];
        }
    }elseif(isset($idioma2[$palabra])){
            if(strlen($palabra) <= strlen($idioma2[$palabra])){
                $resultado[] = $palabra;
            }else{
                $resultado[] = $idioma2[$palabra];
            }
        }
}
echo implode(" ",$resultado);

<?php

$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo1 = array();
$arreglo2 = array();
for($i = 0; $i < $numero+1; $i++){

    if($i == $numero-1){
        $palabras = explode(" ",readline() );
    }else{
 list($a,$b) = explode(" ",trim(fgets(STDIN)));
    $arreglo1[$a] = $b;
    $arreglo2[$b] = $a;
    }
}

$resultado = [];
foreach($palabras as $palabra){
        if(strlen($palabra) <= strlen($arreglo1[$palabra])){
            $resultado[] = $palabra;
        }else{
            $resultado[] = $arreglo1[$palabra];
        }
}
echo implode(" ",$resultado);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ",readline());
$impresion=[];
for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
     $aux2=$arreglo[$j];
    $porciones2=explode(" ",$aux2);
   // echo $arreglo[$j]."****". $porciones[$i]."\n" ;
    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
      if( strlen ( $porciones2[0])==strlen ($porciones[$i]) ){
 $impresion[]=$porciones2[0];
      }

       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
      if( strlen ( $porciones2[1])==strlen ($porciones[$i]) ){
 $impresion[]=$porciones2[1];
      }

         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }

  }

}

}
//echo implode(" ",$impresion);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ",readline());
$impresion=[];
for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) ){
     $aux2=$arreglo[$j];
    $porciones2=explode(" ",$aux2);
   // echo $arreglo[$j]."****". $porciones[$i]."\n" ;
    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
      $impresion[]=$porciones2[0];

       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
      $impresion[]=$porciones2[1];

         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ", $arreglo[$palabras]);
$impresion=[];
for($i=0;$i< $numero;$i++){
 for($j=0;$j< $palabras;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
    $porciones2=explode(" ", $arreglo[$j]);

    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
        $impresion[]=$porciones2[1];
        // echo $porciones2[1]." ".$porciones[$i]."\n";
    }
    $porciones2[1]="";
    $porciones2[0]="";

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ", $arreglo[$palabras]);
$impresion=[];

for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
    $porciones2=explode(" ", $arreglo[$j]);

    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
        $impresion[]=$porciones2[1];
         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ",readline());
$impresion=[];
for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
     $aux2=$arreglo[$j];
    $porciones2=explode(" ",$aux2);
   // echo $arreglo[$j]."****". $porciones[$i]."\n" ;
    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
      if( strlen ( $porciones2[0])==strlen ($porciones[$i]) ){
 $impresion[]=$porciones2[0];
      }

       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
      if( strlen ( $porciones2[1])==strlen ($porciones[$i]) ){
 $impresion[]=$porciones2[1];
      }

         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}
 $aux= $arreglo[$palabras];
$porciones=explode(" ",$aux);
$impresion=[];

for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
     $aux2=$arreglo[$j];
    $porciones2=explode(" ",$aux2);
 //echo $arreglo[$j]."****". $porciones[$i]."\n" ;
    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
        $impresion[]=$porciones2[1];
         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ", $arreglo[$palabras]);
$impresion=[];

for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
    $porciones2=explode(" ", $arreglo[$j]);

    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
        $impresion[]=$porciones2[1];
         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }
    $porciones2[1]="";
    $porciones2[0]="";

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ",readline());
$impresion=[];
for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if($arreglo[$j] != $porciones[$i]){
     $aux2=$arreglo[$j];
    $porciones2=explode(" ",$aux2);
   // echo $arreglo[$j]."****". $porciones[$i]."\n" ;
    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
        $impresion[]=$porciones2[1];
         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }

  }

}

}
//echo implode(" ",$impresion);

<?php
$linea=fgets(STDIN);
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ", $arreglo[$palabras]);
$string="";
for($i=0;$i< $numero;$i++){
 for($j=0;$j< $palabras;$j++){
  if(strpos($arreglo[$j], $porciones[$i] ) !== false){

    $porciones2=explode(" ", $arreglo[$j]);

     if( strlen ($porciones2[0])  == strlen ($porciones2[1]) )  {
        if($i==0){$string.=  $porciones2[0];}else{$string.= " ".$porciones2[0];}
    }elseif(strlen ($porciones2[0])  < strlen ($porciones2[1])){
       if($i==0){$string.=  $porciones2[0];}else{$string.= " ".$porciones2[0];}
    }else{
       if($i==0){$string.=  $porciones2[1];}else{$string.= " ".$porciones2[1];}
    }

   unset($porciones2);
  }

}

}
echo $string;

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ",readline());
$impresion=[];
for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
     $aux2=$arreglo[$j];
    $porciones2=explode(" ",$aux2);
   // echo $arreglo[$j]."****". $porciones[$i]."\n" ;
    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
      if( strlen ( $porciones2[0])==strlen ($porciones[$i]) || strlen ( $porciones2[1])==strlen ($porciones[$i]) ){
 $impresion[]=$porciones2[0];
      }

       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
      if( strlen ( $porciones2[1])==strlen ($porciones[$i])||strlen ( $porciones2[0])==strlen ($porciones[$i])  ){
 $impresion[]=$porciones2[1];
      }

         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=fgets(STDIN);
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ", $arreglo[$palabras]);
$impresion=[];
$pos=0;
for($i=0;$i< $numero;$i++){
 for($j=0;$j< $palabras;$j++){
  if(strpos($arreglo[$j], $porciones[$i] ) !== false){

    $porciones2=explode(" ", $arreglo[$j]);

     if( strlen ($porciones2[0])  == strlen ($porciones2[1]) )  {
        $impresion[]=$porciones2[0];
    }elseif(strlen ($porciones2[0])  < strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
    }else{
        $impresion[]=$porciones2[1];
    }

   unset($porciones2);
  }

}

}
echo implode(" ",$impresion);

<?php
$linea=fgets(STDIN);
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ", $arreglo[$palabras]);

for($i=0;$i< $numero;$i++){
 for($j=0;$j< $palabras;$j++){
  if(strpos($arreglo[$j], $porciones[$i] ) !== false){

    $porciones2=explode(" ", $arreglo[$j]);
     if( strlen ($porciones2[0])  == strlen ($porciones2[1]) )  {
        echo $porciones2[0];
    }elseif(strlen ($porciones2[0])  < strlen ($porciones2[1])){
      echo $porciones2[0];
    }else{
      echo $porciones2[1];
    }
    if($i!= $numero-1){
      echo " ";
    }

   unset($porciones2);
  }

}

}

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ", $arreglo[$palabras]);
$impresion=[];
$pos=0;
for($i=0;$i< $numero;$i++){
 for($j=0;$j< $palabras;$j++){
  if(strpos($arreglo[$j], $porciones[$i] ) !== false){

    $porciones2=explode(" ", $arreglo[$j]);

     if( strlen ($porciones2[0])  == strlen ($porciones2[1]) )  {
        $impresion[]=$porciones2[0];
    }elseif(strlen ($porciones2[0])  < strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
    }else{
        $impresion[]=$porciones2[1];
    }

   unset($porciones2);
  }

}

}
echo implode(" ",$impresion);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}
 $aux= $arreglo[$palabras];
$porciones=explode(" ",$aux);
$impresion=[];

for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
     $aux2=$arreglo[$j];
    $porciones2=explode(" ",$aux2);
 echo $arreglo[$j]."****". $porciones[$i]."\n" ;
    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
        $impresion[]=$porciones2[1];
         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ", $arreglo[$palabras]);
$impresion=[];

for($i=0;$i< $palabras;$i++){
 for($j=0;$j< $numero;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
    $porciones2=explode(" ", $arreglo[$j]);

    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
        $impresion[]=$porciones2[1];
         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }
    $porciones2[1]="";
    $porciones2[0]="";

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ",readline());
$impresion=[];

for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
     $aux2=$arreglo[$j];
    $porciones2=explode(" ",$aux2);
 //echo $arreglo[$j]."****". $porciones[$i]."\n" ;
    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
        $impresion[]=$porciones2[1];
         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=fgets(STDIN);
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ", $arreglo[$palabras]);

for($i=0;$i< $numero;$i++){
 for($j=0;$j< $palabras;$j++){
  if(strpos($arreglo[$j], $porciones[$i] ) !== false){

    $porciones2=explode(" ", $arreglo[$j]);
     if( strlen ($porciones2[0])  == strlen ($porciones2[1]) )  {
        echo $porciones2[0];
    }elseif(strlen ($porciones2[0])  < strlen ($porciones2[1])){
      echo $porciones2[0];
    }else{
      echo $porciones2[1];
    }
    echo " ";
   unset($porciones2);
  }

}

}

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ", $arreglo[$palabras]);
$impresion=[];
for($i=0;$i< $numero;$i++){
 for($j=0;$j< $palabras;$j++){
   $porciones2=explode(" ", $arreglo[$j]);
  if(strpos($arreglo[$j],$porciones[$i]) !== false  &&( strlen ($porciones2[0])== strlen ($porciones[$i])  ||  strlen ($porciones2[1])== strlen ($porciones[$i])) ){

    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
        $impresion[]=$porciones2[1];
        // echo $porciones2[1]." ".$porciones[$i]."\n";
    }
    $porciones2[1]="";
    $porciones2[0]="";

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ",readline());
$impresion=[];
for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
     $aux2=$arreglo[$j];
    $porciones2=explode(" ",$aux2);
   // echo $arreglo[$j]."****". $porciones[$i]."\n" ;
    if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
      if( (strlen ( $porciones2[0])==strlen ($porciones[$i])) ||( strlen ( $porciones2[1])==strlen ($porciones[$i])) ){
 $impresion[]=$porciones2[0];
      }

       // $porciones2[0]." ".$porciones[$i]."\n";
    }else{
      if( (strlen ( $porciones2[1])==strlen ($porciones[$i]))||(strlen ( $porciones2[0])==strlen ($porciones[$i])  )){
 $impresion[]=$porciones2[1];
      }

         //echo $porciones2[1]." ".$porciones[$i]."\n";
    }

  }

}

}
echo implode(" ",$impresion);

<?php
$linea=fgets(STDIN);
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras+1;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ", $arreglo[$palabras]);
$impresion=[];
$pos=0;
for($i=0;$i< $numero;$i++){
 for($j=0;$j< $palabras;$j++){
  if(strpos($arreglo[$j], $porciones[$i] ) !== false){

    $porciones2=explode(" ", $arreglo[$j]);

     if( strlen ($porciones2[0])  == strlen ($porciones2[1]) )  {
        $impresion[]=$porciones2[0];
    }elseif(strlen ($porciones2[0])  < strlen ($porciones2[1])){
       $impresion[]=$porciones2[0];
    }else{
        $impresion[]=$porciones2[1];
    }

    $porciones2[0]="";
 $porciones2[1]="";

  }

}

}
echo implode(" ",$impresion);

<?php

$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo1 = array();
$arreglo2 = array();
for($i = 0; $i < $numero+1; $i++){
    list($a,$b) = explode(" ",trim(fgets(STDIN)));
    $arreglo1[$a] = $b;
    $arreglo2[$b] = $a;
    if($i == $numero-1){
        $palabras = explode(" ",readline() );
    }
}

$resultado = [];
foreach($palabras as $palabra){
        if(strlen($palabra) <= strlen($arreglo1[$palabra])){
            $resultado[] = $palabra;
        }else{
            $resultado[] = $arreglo1[$palabra];
        }
}
echo implode(" ",$resultado);

<?php
$linea=readline();
$string=explode(" ", $linea);
$numero= intval($string[0]);
$palabras= intval($string[1]);
$arreglo=array( $palabras+1);
for($i=0;$i< $palabras;$i++){
  $palabra=readline();
  $arreglo[$i]= $palabra;
}

$porciones=explode(" ",readline());
$impresion=[];
for($i=0;$i<$numero;$i++){
 for($j=0;$j< $palabras ;$j++){
  if(strpos($arreglo[$j],$porciones[$i]) !== false){
    $porciones2=explode(" ", $arreglo[$j]);
   if(strlen ($porciones2[0]) ==  strlen ($porciones[$i]) ||strlen ($porciones2[1]) ==  strlen ($porciones[$i]) ){
       if(strlen ($porciones2[0])  <= strlen ($porciones2[1])){
      $impresion[]=$porciones2[0];
    }else{
    $impresion[]=$porciones2[1];

    }
   }

  }

}

}
echo implode(" ",$impresion);

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

$s = trim(fgets($f));
list($n,$m) = explode(" ",$s);

$repl = array();
for($i=0;$i<$m;$i++){
    $s = trim(fgets($f));
    list($a,$b) = explode(" ",$s);

    if (strlen($b)<strlen($a)){
        $repl[$a] = $b;
    }
}

$s = trim(fgets($f));
$s=$s." ";
foreach($repl as $k=>$item){
    $s = str_replace($k." ",$item." ",$s);
}

echo $s;

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

$s = trim(fgets($f));
list($n,$m) = explode(" ",$s);

$repl = array();
for($i=0;$i<$m;$i++){
    $s = trim(fgets($f));
    list($a,$b) = explode(" ",$s);

    if (strlen($b)<strlen($a)){
        $repl[$a] = $b;
    }
}

$s = trim(fgets($f));
$s=" ".$s." ";
foreach($repl as $k=>$item){
    $s = str_replace(" ".$k." "," ".$item." ",$s);
}

echo trim($s);


<?php
$t = trim(fgets(STDIN));
for ($i = 0; $i < $t; $i++){
    $str = trim(fgets(STDIN));
    $arr = str_split($str);
    sort($arr);
    $first = reset($arr);
    $last = end($arr);
    print_r(($first == $last ? -1 : implode('',$arr)). PHP_EOL);
}

<?php
fscanf(STDIN, "%u",$N);
$resultArr = [];
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%s", $str);
    $arr1 = str_split($str);
    sort($arr1);
    if (count(array_unique($arr1)) == 1) {
        $resultArr[] = -1;
    } else $resultArr[] = implode('', $arr1);
}
foreach($resultArr as $v) {
    echo $v . PHP_EOL;
}

<?php
$a = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     $b = str_split(trim(fgets(STDIN)));
     if(count(array_unique($b)) == 1)
     {
          print "-1\n";
     }
     else
     {
          sort($b);
          print implode($b) . "\n";
     }
}
?>

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

for ($i = 0; $i < $number ; $i++) {
	$string = trim(fgets(STDIN));
	$array = str_split($string);
	sort($array);
	$a = array_unique($array);
	if(count($a) == 1){
		echo "-1\n";
		continue;
	}
	echo implode('',$array)."\n";
}

<?php
$t = readline();

for ($i = 0; $i < $t; $i++){
    $str = readline();
    $arr = str_split($str);
    sort($arr);
    $first = $arr[0];
    $tot = count($arr);
    $last = $arr[$tot - 1];
    if($first == $last) {
        echo "-1\n";
    }
    else {
        $len = count($arr);
        for($j = 0 ; $j < $len ; $j++) {
            echo $arr[$j];
        }
        print "\n";
    }
}

<?php
$t = readline();
for ($i = 0; $i < $t; $i++){
    $str = readline();
    $arr = str_split($str);
    sort($arr);
    $first = reset($arr);
    $last = end($arr);
    print_r(($first == $last ? -1 : implode('',$arr)). PHP_EOL);
}

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

for ($i = 0; $i < $number ; $i++) {
	$string = trim(fgets(STDIN));
		for ($j = 0; $j < strlen($string); $j++) {
				if($string[0] != $string[$j]){
					echo $string."\n";
					$a = true;
					break;
				}
			}
			if(!isset($a)){
				echo "-1\n";
			}
}

<?php
$t = readline();

for ($i = 0; $i < $t; $i++){
    $str = readline();
    $arr = str_split($str);
    sort($arr);
    $first = $arr[0];
    $tot = count($arr);
    $last = $arr[$tot - 1];
    if($first == $last) {
        echo '-1';
    }
    else {
        $len = count($arr);
        for($j = 0 ; $j < $len ; $j++) {
            echo $arr[$j];
        }
    }
}

<?php
$t = readline();

for ($i = 0; $i < $t; $i++){
    $str = readline();
    $arr = str_split($str);
    sort($arr);
    $first = $arr[0];
    $tot = count($arr);
    $last = $arr[$tot - 1];
    if($first == $last) {
        echo '-1\n';
    }
    else {
        $len = count($arr);
        for($j = 0 ; $j < $len ; $j++) {
            echo $arr[$j];
        }
        echo '\n';
    }
}


<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/25  9:09
 */
while( fscanf(STDIN,"%f %f %f %f %f",$n,$x1,$y1,$x2,$y2) ){
    $dist = array();
    for($i = 0 ; $i < $n ; $i++){
        fscanf(STDIN,"%f %f",$fwx,$fwy);
        array_push($dist,[ pow($fwx-$x1,2)+pow($fwy-$y1,2) , pow($fwx-$x2,2)+pow($fwy-$y2,2) ]);
    }
    $result = 8e18;
    //思路，先确定第一个喷泉的范围，再选第二个。

    $dist[] = [0,0];
    for($i = 0 ; $i < $n+1 ; $i++){
        $r1 = $dist[$i][0];
        $r2 = 0;
        for($j = 0 ; $j < $n ; $j++){
            //当其它点到第一个喷泉的距离大于第一个的时候，我们需要使用第二个。
            //保存到第二个喷泉的最大距离。
            if($dist[$j][0] > $r1) {
                $r2 = max($r2, $dist[$j][1]);
            }
        }
        $result = min($result,$r1+$r2);
    }
    fprintf(STDOUT,"%.0f",$result);
    exit();
}

<?php
list($a, $b, $c, $d, $e) = explode(" ", trim(fgets(STDIN)));
$f = array();
$g = array();
for($x = 0; $x < $a; $x++)
{
     list($h, $i) = explode(" ", trim(fgets(STDIN)));
     $j = bcpow(bcsqrt(bcadd(bcpow(bcsub($h, $b), 2), bcpow(bcsub($i, $c), 2))), 2);
     $f[$x] = $j;
     $k = bcpow(bcsqrt(bcadd(bcpow(bcsub($h, $d), 2), bcpow(bcsub($i, $e), 2))), 2);
     $g[$x] = $k;
}
$l = max($f);
$m = max($g);
$n = array($l, $m);
$o = 2;
array_unshift($f, " ");
unset($f[0]);
array_unshift($g, " ");
unset($g[0]);
$p = 0;
for($x = 1; $x <= $a; $x++)
{
     $r = max($f);
     $s = array_search($r, $f);
     $p = max($p, $g[$s]);
     unset($f[$s]);
     $n[$o] = max($f) + $p;
     $o++;
}
print min($n);
?>

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/25  9:09
 */
//从这个例子中我们也可以看到自己的php版本是32位的。
//如果使用浮点数，会形成误差。
function mypow($d){
    $d = (string)$d;
    return bcpow($d,"2");
}
while( fscanf(STDIN,"%d %d %d %d %d",$n,$x1,$y1,$x2,$y2) ){
    $dist = array();
    for($i = 0 ; $i < $n ; $i++){
        fscanf(STDIN,"%d %d",$fwx,$fwy);
        array_push($dist,[ bcadd(mypow($fwx-$x1),mypow($fwy-$y1)) , bcadd(mypow($fwx-$x2),mypow($fwy-$y2)) ]);
    }
    $result = "9000000000000000000000";
    //思路，先确定第一个喷泉的范围，再选第二个。

    $dist[] = ["0","0"];
    for($i = 0 ; $i < $n+1 ; $i++){
        $r1 = $dist[$i][0];
        $r2 = "0";
        for($j = 0 ; $j < $n ; $j++){
            //当其它点到第一个喷泉的距离大于第一个的时候，我们需要使用第二个。
            //保存到第二个喷泉的最大距离。
            if(strcmp($dist[$j][0] , $r1) > 0) {
                if(strcmp($dist[$j][1],$r2) > 0){
                    $r2 = $dist[$j][1];
                }

            }
        }
      //  var_dump($r1);
       // var_dump($r2);
        if(strcmp($result,bcadd($r1,$r2))) {
            $result = bcadd($r1, $r2);
        }
    }
    fprintf(STDOUT,"%s",$result);

    exit();
}

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/25  9:09
 */
//从这个例子中我们也可以看到自己的php版本是32位的。
//如果使用浮点数，会形成误差。
function mypow($d){
    $d = (string)$d;
    return bcpow($d,"2");
}
while( fscanf(STDIN,"%d %d %d %d %d",$n,$x1,$y1,$x2,$y2) ){
    $dist = array();
    for($i = 0 ; $i < $n ; $i++){
        fscanf(STDIN,"%d %d",$fwx,$fwy);
        array_push($dist,[ bcadd(mypow($fwx-$x1),mypow($fwy-$y1)) , bcadd(mypow($fwx-$x2),mypow($fwy-$y2)) ]);
    }
    $result = "9000000000000000000000";
    //思路，先确定第一个喷泉的范围，再选第二个。

    $dist[] = ["0","0"];
    for($i = 0 ; $i < $n+1 ; $i++){
        $r1 = $dist[$i][0];
        $r2 = "0";
        for($j = 0 ; $j < $n ; $j++){
            //当其它点到第一个喷泉的距离大于第一个的时候，我们需要使用第二个。
            //保存到第二个喷泉的最大距离。
            if(strcmp($dist[$j][0] , $r1) > 0) {
                if(strcmp($dist[$j][1],$r2) > 0){
                    $r2 = $dist[$j][1];
                }

            }
        }
      //  var_dump($r1);
       // var_dump($r2);
        if(strcmp($result,bcadd($r1,$r2)) > 0) {
            $result = bcadd($r1, $r2);
        }
    }
    fprintf(STDOUT,"%s",$result);

    exit();
}

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/25  9:09
 */
while( fscanf(STDIN,"%f %f %f %f %f",$n,$x1,$y1,$x2,$y2) ){
    $dist = array();
    for($i = 0 ; $i < $n ; $i++){
        fscanf(STDIN,"%f %f",$fwx,$fwy);
        array_push($dist,[ pow($fwx-$x1,2)+pow($fwy-$y1,2) , pow($fwx-$x2,2)+pow($fwy-$y2,2) ]);
    }
    $result = 8e18;
    //思路，先确定第一个喷泉的范围，再选第二个。
    for($i = 0 ; $i < $n ; $i++){
        $r1 = $dist[$i][0];
        $r2 = 0;
        for($j = 0 ; $j < $n ; $j++){
            //当其它点到第一个喷泉的距离大于第一个的时候，我们需要使用第二个。
            //保存到第二个喷泉的最大距离。
            if($dist[$j][0] > $r1) {
                $r2 = max($r2, $dist[$j][1]);
            }
        }
        $result = min($result,$r1+$r2);
    }
    fprintf(STDOUT,"%.0f",$result);
    exit();
}


<?php
function inputInt($sys){
    fscanf($sys,"%d",$n);
    return $n;
}
function inputArray($sys){
    fscanf($sys, "%[^\n]", $tempA);
    $arr = array_map('intval', preg_split('/ /', $tempA, -1, PREG_SPLIT_NO_EMPTY));
    return $arr;
}

$stdin = fopen('php://stdin', 'r');
$T=inputInt($stdin);
function solve($sys){
    $n=inputInt($sys);
    $arr=inputArray($sys);
    sort($arr);
    $min=1e9;
    for ($i=1;$i<$n;++$i){
           $min=min($arr[$i]-$arr[$i-1],$min);
    }
    echo $min."\n";
}
while ($T--){
    solve($stdin);
}


<?php
#1187A
$n = (int)trim(fgets(STDIN));
$str = trim(fgets(STDIN));
$m = (int)trim(fgets(STDIN));
$posAll = [];
for ($i = 0; $i < $n; $i++) {
    $posAll[$str[$i]][] = $i;
}
while ($m--) {
    $name = trim(fgets(STDIN));
    $max = 0;
    $nameLength = strlen($name);
    $pos = [];
    for ($i = 0; $i < $nameLength; $i++) {
        $letter = $name[$i];
        $p = $pos[$letter] ?? 0;
        $pos[$letter] = $p + 1;
        $max = max($max, $posAll[$letter][$p]);
    }
    echo ($max + 1) . PHP_EOL;
}

<?php
#1187A
$n = (int)trim(fgets(STDIN));
$str = trim(fgets(STDIN));
$n = (int)trim(fgets(STDIN));
while ($n--) {
    $name = trim(fgets(STDIN));
    $max = 0;
    $nameLength = strlen($name);
    $pos = [];
    for ($i = 0; $i < $nameLength; $i++) {
        $letter = $name[$i];
        if (!isset($pos[$letter])) {
            $pos[$letter] = strpos($str, $letter);
            $max = max($max, $pos[$letter]);
        }
    }
    echo ($max + 1) . PHP_EOL;
}


<?php
list($p) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $p; $i++){
    list($n,$m,$k) = explode(' ', trim(fgets(STDIN)));
    $aArray = [];
    $aArray = explode(' ', trim(fgets(STDIN)));
    $c = $m;
    $bFlag = true;
    for($j = 0; $j < $n - 1; $j++){
        $c += $aArray[$j] - max(($aArray[$j + 1] - $k),0);
        if($c < 0){
            $bFlag = false;
        }
    }

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

}


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

    $n = intval(trim(fgets(STDIN))) ;

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

    $map_a = array_fill(0, $n + 1, 0) ;
    for($i = 0; $i < $n ; $i ++) $map_a[intval($arr_a[$i])] = $i ;

    $arr_b = explode(" ", trim(fgets(STDIN))) ;
    $map_b = array_fill(0, $n + 1, 0) ;

    $ans = 0 ;
    for($i = 0; $i < $n; $i ++)
    {
        $offset = ($map_a[intval($arr_b[$i])] - $i + $n)%$n ;

        $map_b[$offset] ++ ;

        $ans = max($ans, $map_b[$offset]) ;
    }

    echo $ans . "\n" ;
?>

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

    $n = intval(trim(fgets(STDIN))) ;

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

    $map_a = array_fill(0, $n + 1, 0) ;
    for($i = 0; $i < $n ; $i ++) $map_a[intval($arr_a[$i])] = $i ;

    $arr_b = explode(" ", trim(fgets(STDIN))) ;
    $map_b = array_fill(0, $n + 1, 0) ;

    $ans = 0 ;
    for($i = 0; $i < $n; $i ++)
    {
        $offset = $map_a[intval($arr_b[$i])] - $i ;
        if($offset < 0) $offset += $n ;

        $map_b[$offset] ++ ;
        $ans = max($ans, $map_b[$offset]) ;
    }

    echo $ans . "\n" ;
?>


<?php
$x = rtrim(fgets(STDIN));
for($i = 0; $i < $x; $i++){
    $y = rtrim(fgets(STDIN));
    $a = rtrim(fgets(STDIN));
    $arr = explode(" ",$a);
    $arr = array_reverse($arr);
    $s = $arr[0]; $z = 0;
    for ($j = 1; $j < $y; $j++){
        if ($arr[$j] > $s){
            $z++;
        }
        $s = min($s, $arr[$j]);
    }
    printf("%d\n", $z);
}
?>


<?php
// Retrieve input
$stdin = fopen('php://stdin', 'r');
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Contest 157 Div 2 Problem C
$raw = g();
$str = $raw[0];

$res = "";
for ($i = 1; $i < strlen($str); $i++) {
	if (substr($str, $i, 1) == "0") {
		$res = substr($str, 0, $i) . substr($str, $i+1, strlen($str)-$i-1);
		break;
	}
}
if ($res == "") {$res = substr($str, 0, strlen($str)-1);}

while ((substr($res, 0, 1) == "0") && (strlen($res) > 1)) {
	$res = substr($res, 1, strlen($res) - 1);
}

echo $res;

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

<?php
$a = str_split(trim(fgets(STDIN)));
$b = 0;
$d = $a;
for($x = 0; $x < count($d); $x++)
{
    if($a[$x] == 0)
    {
        $b = 1;
        array_splice($a, $x, 1);
        break;
    }
}
if($b == 1)
{
    $c = array_reverse($a);
    $e = 0;
    for($x = 0; $x < count($a); $x++)
    {
        $f = $c[$x] * (pow(2, $x));
        $e += $f;
    }
    $a = array_reverse($c);
    print implode("", $a);
}
else
{
    array_splice($a, -1, 1);
    $c = array_reverse($a);
    $e = 0;
    for($x = 0; $x < count($a); $x++)
    {
        $f = $c[$x] * (pow(2, $x));
        $e += $f;
    }
    $a = array_reverse($c);
    print implode("", $a);
}
?>


<?php

$line1 = fgets(STDIN);
$line2 = fgets(STDIN);

list($n, $x) = explode(' ', $line1); // n := number of segments; x := length of crossword
$encoding = explode(' ', $line2); // encoding of crossword

$sumOfSegments = array_sum($encoding);

if ($sumOfSegments == $x - $n + 1) {
    echo 'YES';
} else {
    echo 'NO';
}

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array_sum($c);
$e = $d + ($a - 1);
if($e == $b)
{
     print "YES";
}
else
{
     print "NO";
}
?>


<?php
fscanf(STDIN,"%d %d",$n,$q);
$superior_index = fgets(STDIN);
$superior_index = explode(' ',trim($superior_index));
$dfs_id = 0;
$left_id = array();
$right_id = array();
$edge = array();
$value_map = array();
for($i = 0;$i <= $n-2;$i++){
    $id = (int)$superior_index[$i];
    if(!isset($edge[$id])){
      $edge[$id] = array();
    }
    array_push($edge[$id],$i+2);
}
dfs(1);
while($q)
{
  $q--;
  fscanf(STDIN,"%d %d",$u,$k);
  $k--;
  $id = $left_id[$u] + $k;
  if($id > $right_id[$u])
    echo "-1\n";
  else echo "$value_map[$id]\n";
}
function dfs($node){
  global $dfs_id;
  global $edge;
  global $left_id;
  global $right_id;
  global $value_map;
    $left_id[$node] = ++$dfs_id;
    $value_map[$dfs_id] = $node;
    //var_dump($node);
    if(isset($edge[$node])){
      $child_count = count($edge[$node]);
      for($i = 0;$i < $child_count;$i++){
        dfs($edge[$node][$i]);
      }
    }
    $right_id[$node] = $dfs_id;
}


<?php
$sec=[];
$first = [];
while ($input = fgets(STDIN))
{
	if ($input==='' || strpos($input,' ')=== false)
	{
		continue;
	}
	$r = explode(' ', $input);
	$first[$r[0]] = true;
	$sec[$r[1]] = true;

}
fwrite(STDOUT,min(count($first),count($sec)));

<?php
error_reporting("off");
//390A: Inna and Alarm Clock
$n = trim(fgets(STDIN));
$x = array();
$y = array();
for ($i = 0; $i < $n; $i++) {
	list($x[], $y[]) = explode(" ", trim(fgets(STDIN)));
}
$xdis = count(array_count_values($x));
$ydis = count(array_count_values($y));
if ($xdis <= $ydis) {
	echo $xdis;
} else {
	echo $ydis;
}
?>

<?php
$a = trim(fgets(STDIN));
$d = array();
$e = array();
for($x = 1; $x <= $a; $x++)
{
    list($b, $c) = explode(" ", trim(fgets(STDIN)));
    array_push($d, $b);
    array_push($e, $c);
}
$f = array_unique($d);
$g = array_unique($e);
print min(count($f), count($g));
?>

<?php
//define('STDIN', fopen('input.txt', 'r'));
$countIteration = trim(fgets(STDIN));

$xArr = []; $yArr = [];
for ($i = 1; $i <= $countIteration; $i++) {
	list($x, $y) = explode(' ', trim(fgets(STDIN)));
	$xArr[(int)$x]++;
	$yArr[(int)$y]++;
}
echo( min( count($xArr), count($yArr) ) );
fclose(STDIN);
?>

<?php
//define('STDIN', fopen('input.txt', 'r'));
$fStr = fgets(STDIN);

$xArr = []; $yArr = [];
while (!feof(STDIN)) {
	list($x, $y) = explode(' ', trim(fgets(STDIN)));
	$xArr[(int)$x]++;
	$yArr[(int)$y]++;
}
echo( min( count($xArr), count($yArr) ) );
fclose(STDIN);
?>

<?php
$input = fgets(STDIN);
array_shift($input);
array_pop($input);
$first = [];
foreach ($input as $item)
{
	$r = explode(' ', $item);
	$first[$r[0]] = true;
}
fwrite(STDOUT,count($first));

<?php

$first = [];
while ($input = fgets(STDIN))
{
	if ($input==='' || strpos($input,' ')=== false)
	{
		continue;
	}
	$r = explode(' ', $input);
	$first[$r[0]] = true;

}
fwrite(STDOUT,count($first));


<?php

$t = intval(trim(fgets(STDIN)));

for ($index = 0; $index < $t; $index++)
{
	echo(intval(trim(fgets(STDIN))) . PHP_EOL);
}

<?php
    $test_case = readline();
    while($test_case--){
        echo readline() . PHP_EOL;
    }