Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled:  Each boy plays for exactly one team (x + y = n).  The sizes of teams differ in no more than one (|x - y| ≤ 1).  The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.

The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills.

On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.

NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled.

<?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(){

	$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(){

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


Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on the rear wheel axle has bj (0 < b1 < b2 < ... < bm) teeth. Any pair (i, j) (1 ≤ i ≤ n; 1 ≤ j ≤ m) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (i, j) has a gear ratio, equal to the value .Since Vasya likes integers, he wants to find such gears (i, j), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (i, j) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.In the problem, fraction  denotes division in real numbers, that is, no rounding is performed.

The first input line contains integer n (1 ≤ n ≤ 50) — the number of stars on the bicycle's pedal axle. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 104) in the order of strict increasing. The third input line contains integer m (1 ≤ m ≤ 50) — the number of stars on the rear wheel axle. The fourth line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 104) in the order of strict increasing. It is guaranteed that there exists at least one gear (i, j), that its gear ratio is an integer. The numbers on the lines are separated by spaces.

Print the number of "integer" gears with the maximum ratio among all "integer" gears.

NoteIn the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them a1 = 4, b1 = 12, and for the other a2 = 5, b3 = 15.

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

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


Polycarp has to solve exactly $$$n$$$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $$$k$$$ days. It means that Polycarp has exactly $$$k$$$ days for training!Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of $$$k$$$ days. He also doesn't want to overwork, so if he solves $$$x$$$ problems during some day, he should solve no more than $$$2x$$$ problems during the next day. And, at last, he wants to improve his skill, so if he solves $$$x$$$ problems during some day, he should solve at least $$$x+1$$$ problem during the next day.More formally: let $$$[a_1, a_2, \dots, a_k]$$$ be the array of numbers of problems solved by Polycarp. The $$$i$$$-th element of this array is the number of problems Polycarp solves during the $$$i$$$-th day of his training. Then the following conditions must be satisfied:   sum of all $$$a_i$$$ for $$$i$$$ from $$$1$$$ to $$$k$$$ should be $$$n$$$;  $$$a_i$$$ should be greater than zero for each $$$i$$$ from $$$1$$$ to $$$k$$$;  the condition $$$a_i < a_{i + 1} \le 2 a_i$$$ should be satisfied for each $$$i$$$ from $$$1$$$ to $$$k-1$$$. Your problem is to find any array $$$a$$$ of length $$$k$$$ satisfying the conditions above or say that it is impossible to do it.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^9, 1 \le k \le 10^5$$$) — the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.

If it is impossible to find any array $$$a$$$ of length $$$k$$$ satisfying Polycarp's rules of training, print "NO" in the first line. Otherwise print "YES" in the first line, then print $$$k$$$ integers $$$a_1, a_2, \dots, a_k$$$ in the second line, where $$$a_i$$$ should be the number of problems Polycarp should solve during the $$$i$$$-th day. If there are multiple answers, you can print any.

<?php
# 1157D
declare(strict_types=1);

$start = microtime(true);

[$n, $k] = fscanf(STDIN, '%u %u');

if ($k === 1) {
    die('YES' . PHP_EOL . $n);
}
$summ = (int)($k * ($k + 1) / 2);

if ($summ > $n) {
    die('NO');
}

$arr = [];

for ($i = 0; $i < $k; $i++) {
    $arr[$i] = $i + 1;
}

$delta = (int)floor(($n - $summ) / $k);
if ($delta) {
    for ($i = 0; $i < $k; $i++) {
        $arr[$i] = $i + $delta;
    }
}

$n -= array_sum($arr);

$lastIndex = $k - 1;
while($n > 0) {
    $i = $lastIndex;
    while ($n > 0 && $i >= 0 && $arr[$i] < ($delta + $arr[0] * 2 ** $i)) {
        $arr[$i]++;
        $n--;
        $i--;
    }
    if ($arr[$lastIndex] === (int)($delta + $arr[0] * 2 ** $lastIndex)) {
        break;
    }
}
if ($n !== 0) {
    echo 'NO';
} else {
    echo 'YES' . PHP_EOL . implode(' ', $arr);
}


DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?

The first line contains a single string s (1 ≤ |s| ≤ 103). The second line contains a single integer k (0 ≤ k ≤ 103). The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.

Print a single integer — the largest possible value of the resulting string DZY could get.

NoteIn the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.

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


You are given an array $$$a$$$ consisting of $$$n$$$ integers.Let's call a pair of indices $$$i$$$, $$$j$$$ good if $$$1 \le i < j \le n$$$ and $$$\gcd(a_i, 2a_j) > 1$$$ (where $$$\gcd(x, y)$$$ is the greatest common divisor of $$$x$$$ and $$$y$$$).Find the maximum number of good index pairs if you can reorder the array $$$a$$$ in an arbitrary way.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of the test case contains a single integer $$$n$$$ ($$$2 \le n \le 2000$$$) — the number of elements in the array. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.

For each test case, output a single integer — the maximum number of good index pairs if you can reorder the array $$$a$$$ in an arbitrary way.

NoteIn the first example, the array elements can be rearranged as follows: $$$[6, 3, 5, 3]$$$.In the third example, the array elements can be rearranged as follows: $$$[4, 4, 2, 1, 1]$$$.


Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task.

The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number.

Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1.


$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied:   All scores are integers  $$$0 \leq a_{i} \leq m$$$  The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied.

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$)  — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$)  — scores of the students.

For each testcase, output one integer  — the highest possible score you can assign to yourself such that both conditions are satisfied._

NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$.

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


You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during $$$n$$$ consecutive days. During the $$$i$$$-th day you have to write exactly $$$a_i$$$ names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly $$$m$$$ names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from $$$1$$$ to $$$n$$$.

The first line of the input contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 10^9$$$) — the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ means the number of names you will write in the notebook during the $$$i$$$-th day.

Print exactly $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$, where $$$t_i$$$ is the number of times you will turn the page during the $$$i$$$-th day.

NoteIn the first example pages of the Death Note will look like this $$$[1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]$$$. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.


Cowboy Vlad has a birthday today! There are $$$n$$$ children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.Formally, let's number children from $$$1$$$ to $$$n$$$ in a circle order, that is, for every $$$i$$$ child with number $$$i$$$ will stand next to the child with number $$$i+1$$$, also the child with number $$$1$$$ stands next to the child with number $$$n$$$. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.

The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the number of the children who came to the cowboy Vlad's birthday. The second line contains integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) denoting heights of every child.

Print exactly $$$n$$$ integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child. If there are multiple possible answers, print any of them.

NoteIn the first example, the discomfort of the circle is equal to $$$1$$$, since the corresponding absolute differences are $$$1$$$, $$$1$$$, $$$1$$$ and $$$0$$$. Note, that sequences $$$[2, 3, 2, 1, 1]$$$ and $$$[3, 2, 1, 1, 2]$$$ form the same circles and differ only by the selection of the starting point.In the second example, the discomfort of the circle is equal to $$$20$$$, since the absolute difference of $$$10$$$ and $$$30$$$ is equal to $$$20$$$.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
rsort($b);
$c = array($b[0]);
for($x = 1; $x < $a; $x++)
{
     if($x % 2 == 0)
     {
          array_unshift($c, $b[$x]);
     }
     else
     {
          array_push($c, $b[$x]);
     }
}
print implode(" ", $c);
?>


Mahmoud was trying to solve the vertex cover problem on trees. The problem statement is:Given an undirected tree consisting of n nodes, find the minimum number of vertices that cover all the edges. Formally, we need to find a set of vertices such that for each edge (u, v) that belongs to the tree, either u is in the set, or v is in the set, or both are in the set. Mahmoud has found the following algorithm:  Root the tree at node 1.  Count the number of nodes at an even depth. Let it be evenCnt.  Count the number of nodes at an odd depth. Let it be oddCnt.  The answer is the minimum between evenCnt and oddCnt. The depth of a node in a tree is the number of edges in the shortest path between this node and the root. The depth of the root is 0.Ehab told Mahmoud that this algorithm is wrong, but he didn't believe because he had tested his algorithm against many trees and it worked, so Ehab asked you to find 2 trees consisting of n nodes. The algorithm should find an incorrect answer for the first tree and a correct answer for the second one.

The only line contains an integer n (2 ≤ n ≤ 105), the number of nodes in the desired trees.

The output should consist of 2 independent sections, each containing a tree. The algorithm should find an incorrect answer for the tree in the first section and a correct answer for the tree in the second. If a tree doesn't exist for some section, output "-1" (without quotes) for that section only. If the answer for a section exists, it should contain n - 1 lines, each containing 2 space-separated integers u and v (1 ≤ u, v ≤ n), which means that there's an undirected edge between node u and node v. If the given graph isn't a tree or it doesn't follow the format, you'll receive wrong answer verdict. If there are multiple answers, you can print any of them.

NoteIn the first sample, there is only 1 tree with 2 nodes (node 1 connected to node 2). The algorithm will produce a correct answer in it so we printed  - 1 in the first section, but notice that we printed this tree in the second section.In the second sample:In the first tree, the algorithm will find an answer with 4 nodes, while there exists an answer with 3 nodes like this:  In the second tree, the algorithm will find an answer with 3 nodes which is correct:


You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.

The first line contains two integers, n and m (1 ≤ n ≤ 3000, 1 ≤ m ≤ 3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains n space-separated strings c1, c2, ..., cn — the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.

Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.

4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest

5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll

codeforces round letter round
hbnyiyc joll joll un joll

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


You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.  Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.

The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.

In a single line print a real number — the area of the region which belongs to both given rectangles. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.

NoteThe second sample has been drawn on the picture above.


You are given a string $$$s$$$ consisting only of lowercase Latin letters.You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible to do it.Let's call a string good if it is not a palindrome. Palindrome is a string which is read from left to right the same as from right to left. For example, strings "abacaba", "aa" and "z" are palindromes and strings "bba", "xd" are not.You have to answer $$$t$$$ independent queries.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — number of queries. Each of the next $$$t$$$ lines contains one string. The $$$i$$$-th line contains a string $$$s_i$$$ consisting only of lowercase Latin letter. It is guaranteed that the length of $$$s_i$$$ is from $$$1$$$ to $$$1000$$$ (inclusive).

Print $$$t$$$ lines. In the $$$i$$$-th line print the answer to the $$$i$$$-th query: -1 if it is impossible to obtain a good string by rearranging the letters of $$$s_i$$$ and any good string which can be obtained from the given one (by rearranging the letters) otherwise.

NoteIn the first query we cannot rearrange letters to obtain a good string.Other examples (not all) of correct answers to the second query: "ababaca", "abcabaa", "baacaba".In the third query we can do nothing to obtain a good string.

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


A flowerbed has many flowers and two fountains.You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, the distance between the flower and the first fountain doesn't exceed r1, or the distance to the second fountain doesn't exceed r2. It's OK if some flowers are watered by both fountains.You need to decrease the amount of water you need, that is set such r1 and r2 that all the flowers are watered and the r12 + r22 is minimum possible. Find this minimum value.

The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000,  - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain. Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flower. It is guaranteed that all n + 2 points in the input are distinct.

Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.

NoteThe first sample is (r12 = 5, r22 = 1):  The second sample is (r12 = 1, r22 = 32):

<?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();
}