There are $$$n$$$ people in a horizontal line, each looking either to the left or the right. Each person counts the number of people in the direction they are looking. The value of the line is the sum of each person's count.For example, in the arrangement LRRLL, where L stands for a person looking left and R stands for a person looking right, the counts for each person are $$$[0, 3, 2, 3, 4]$$$, and the value is $$$0+3+2+3+4=12$$$.You are given the initial arrangement of people in the line. For each $$$k$$$ from $$$1$$$ to $$$n$$$, determine the maximum value of the line if you can change the direction of at most $$$k$$$ people.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2\cdot10^5$$$) — the length of the line. The following line contains a string consisting of $$$n$$$ characters, each of which is either L or R, representing a person facing left or right, respectively — the description of the line. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

For each test case, output $$$n$$$ space-separated non-negative integers — the maximum value of the line if you can change the direction of at most $$$k$$$ people for each $$$k$$$ from $$$1$$$ to $$$n$$$, inclusive.

6

3

LLR

5

LRRLL

1

L

12

LRRRLLLRLLRL

10

LLLLLRRRRR

9

LRLRLRLRL

NoteIn the first test case:   $$$k=1$$$: change the direction of $$$1$$$ person to make the line RLR. The total value is $$$2+1+0=3$$$.  $$$k=2$$$: change the direction of $$$2$$$ people to make the line RLL. The total value is $$$2+1+2=5$$$.  $$$k=3$$$: change the direction of $$$2$$$ people to make the line RLL. The total value is $$$2+1+2=5$$$. Note that you have to change the direction of at most $$$k$$$ people. In the second test case, it is optimal to only change the direction of the first person for all $$$k$$$ from $$$1$$$ to $$$5$$$ (that is, make the line RRRLL).

<?php

$t = (int)readline();

while ($t--) {
    $n = (int)readline();
    $line = str_split(readline());
    $value = 0;

    for ($i = 0; $i < $n; ++$i) {
        if ($line[$i] === 'L') {
            $value += $i;
        } else {
            $value += $n - $i - 1;
        }
    }

    $it = 0;
    for ($i = 0; ($i << 1) < $n; ++$i) {
        if ($line[$i] === 'L') {
            // change to R
            $value -= $i;
            $value += $n - $i - 1;
            echo $value . ' ';
            ++$it;
        }

        if ($line[$n - $i - 1] === 'R') {
            // change to L
            $value -= $i;
            $value += $n - $i - 1;
            echo $value . ' ';
            ++$it;
        }
    }

    while ($it < $n) {
        echo $value . ' ';
        ++$it;
    }

    echo PHP_EOL;
}


Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning.Mahmoud knows that the i-th word can be sent with cost ai. For each word in his message, Mahmoud can either replace it with another word of the same meaning or leave it as it is. Can you help Mahmoud determine the minimum cost of sending the message?The cost of sending the message is the sum of the costs of sending every word in it.

The first line of input contains integers n, k and m (1 ≤ k ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively. The second line contains n strings consisting of lowercase English letters of length not exceeding 20 which represent the words. It's guaranteed that the words are distinct. The third line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) where ai is the cost of sending the i-th word. The next k lines describe the groups of words of same meaning. The next k lines each start with an integer x (1 ≤ x ≤ n) which means that there are x words in this group, followed by x integers which represent the indices of words in this group. It's guaranteed that each word appears in exactly one group. The next line contains m space-separated words which represent Mahmoud's message. Each of these words appears in the list of language's words.

The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning.

5 4 4
i loser am the second
100 1 1 5 10
1 1
1 3
2 2 5
1 4
i am the second

5 4 4
i loser am the second
100 20 1 5 10
1 1
1 3
2 2 5
1 4
i am the second

NoteIn the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116.

<?php

//fscanf(STDIN, "%d", $t);
$values = array_map('intval', explode(' ',trim(fgets(STDIN))));
$n = $values[0];
$k = $values[1];
$m = $values[2];

//words
$strings = explode(' ',trim(fgets(STDIN)));
//costs
$price = array_map('intval', explode(' ',trim(fgets(STDIN))));

for($i = 0; $i < $n; $i++) {
	$cost[$strings[$i]] = $price[$i];
}

$mini = max($cost);
while($k--) {
	$words = array_map('intval', explode(' ',trim(fgets(STDIN))));
	$min_cost = $mini;
	//minimum cost
	for($i = 1; $i < count($words); $i++) {
		if ( $price[$words[$i]-1] < $min_cost) {
			$min_cost = $cost[$strings[$words[$i]-1]];
		}
	}
	//update costs
	for($i = 1; $i < count($words); $i++) {
			$cost[$strings[$words[$i]-1]] = $min_cost;
	}
}

$sentence = explode(' ',trim(fgets(STDIN)));
$res = 0;
for($i = 0; $i < $m; $i++) {
	$res += $cost[$sentence[$i]];
}

echo $res."\n";

<?php

//მე რა მამღერებს, უძირო ზეცა, ზამბახისფერი (:)

$diadiSityva = 0;

list($n,$k,$m) = explode(" ",trim(fgets(STDIN)));

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

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

for($i = 0; $i < $n; $i++)
    $tinatini[$names[$i]]=$cost[$i];

for($i = 0; $i < $k; $i++){
    $indexes = explode(" ",trim(fgets(STDIN)));

    $minimumi = 1000000001;

    for($x = 1; $x < count($indexes); $x++)
        $minimumi = min($minimumi,$tinatini[$names[$indexes[$x]-1]]);

    for($x = 1; $x < count($indexes); $x++)
        $tinatini[$names[$indexes[$x]-1]] = $minimumi;
}

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

for($i = 0; $i < count($newNames); $i++)
    $diadiSityva+=$tinatini[$newNames[$i]];

echo $diadiSityva;

?>

<?php
list($n,$k,$m) = explode(" ",trim(fgets(STDIN)));
$words = explode(" ",trim(fgets(STDIN)));
$prices = explode(" ",trim(fgets(STDIN)));
$max_val = 1e9;
$group_of_word = array_fill(0,$n,-1);
$min_price_per_group = array_fill(0,$k,$max_val);
for($group=0; $group<$k; $group++){
	$pertenecen = explode(" ",trim(fgets(STDIN)));
	for($index = 1; $index < count($pertenecen); $index++){
		$group_of_word[$words[$pertenecen[$index]-1]] = $group;
		$min_price_per_group[$group] = min($min_price_per_group[$group],$prices[$pertenecen[$index]-1]);
	}
}
$message = explode(" ",trim(fgets(STDIN)));
$ans = 0;
for($i=0; $i<count($message); $i++){
	$ans += $min_price_per_group[$group_of_word[$message[$i]]];
}
print $ans
?>


Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.For example, the following matrices are palindromic:  The following matrices are not palindromic because they change after the order of rows is reversed:  The following matrices are not palindromic because they change after the order of columns is reversed:  You are given $$$n^2$$$ integers. Put them into a matrix of $$$n$$$ rows and $$$n$$$ columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".

The first line contains one integer $$$n$$$ ($$$1 \le n \le 20$$$). The second line contains $$$n^2$$$ integers $$$a_1, a_2, \dots, a_{n^2}$$$ ($$$1 \le a_i \le 1000$$$) — the numbers to put into a matrix of $$$n$$$ rows and $$$n$$$ columns.

If it is possible to put all of the $$$n^2$$$ numbers into a matrix of $$$n$$$ rows and $$$n$$$ columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print $$$n$$$ lines with $$$n$$$ space-separated numbers — the resulting matrix. If it's impossible to construct any matrix, then print "NO". You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.

NoteNote that there exist multiple answers for the first two examples.


Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters. It is guaranteed that all handles are distinct.

Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.

3
Burunduk1 2526 2537
BudAlNik 2084 2214
subscriber 2833 2749

3
Applejack 2400 2400
Fluttershy 2390 2431
Pinkie_Pie -2500 -2450

NoteIn the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.

<?php
$dir = fopen("php://stdin", 'r');
$s = stream_get_contents($dir);
$a = explode("\n", $s);
//$s = str_replace("\n", "", $s);
/*
$handle = fopen ("php://stdin","r");
fscanf($handle,"%d",$n);
$a = array();
for($a_i = 0; $a_i < $n; $a_i++) {
   $a_temp = fgets($handle);
   $a[] = explode(" ",$a_temp);
  array_walk($a[$a_i],'intval');
}
*/
/*
$n=3;

$a = [
	['Burunduk1', 2400, 2400],
	['BudAlNik', 2390, 2431],
	['subscriber', -2500, -2450]
];
*/
$n=$a[0];
$good = false;
for($i=0; $i<$n ;$i++){
	$x = explode(" ", $a[$i+1]);
	if(intval($x[1]) >= 2400 &&  intval($x[2]) > intval($x[1])){
		$good = true;
		break;
	}
}
if($good){
	print "YES";
}else{
	print "NO";
}

<?php
$n = trim(fgets(STDIN));
$g = false;
for ($i = 1; $i <= $n; $i++) {
    $s = explode(" ", trim(fgets(STDIN)));
    if (($s[1] >= 2400) and ($s[2] > $s[1])) {
        $g = true;
    }
}
if ($g) {
    print "YES";
} else {
    print "NO";
}
?>

<?php

fscanf(STDIN, "%d\n", $number);
for ($i = 0; $i < $number;$i++) {
    $string = trim(fgets(STDIN));
    $pieces = explode(" ", $string);
    if($pieces[2] > $pieces[1] && $pieces[1] > 2399) {
        echo 'YES';
        die();
    }
}
echo 'NO';

<?php

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

$answer = 'NO';

for( $i=0; $i<$n; $i++ ) {
	$line = trim(fgets(STDIN));
	$outscoredParticipantInfo = explode(' ',$line);

	$before = intval($outscoredParticipantInfo[1]);
	$after = intval($outscoredParticipantInfo[2]);
	if( 2400 <= $before && $before < $after )
	{
		$answer = 'YES';
	}
}

print $answer.PHP_EOL;

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$answ="NO";
$i=0;
while ($i<(int)$s) {
	$i++;
	list($name,$before,$after)=explode(" ",trim(fgets($stdin)));
	if($before>=2400&&($after>2400&&$after>$before)){
		$answ="YES";

		break;

	}

}
echo $answ;

<?php
$fp = fopen('php://stdin', 'r');
$n = (int)fgets($fp);
for($i = 0; $i < $n; ++$i) {
	list($name, $before, $after) = explode(' ', fgets($fp));
	$before = intval($before);
	$after = intval($after);
	if ($after > $before && $before >= 2400) {
		die('YES');
	}
}
die('NO');

<?php
$dir = fopen("php://stdin", 'r');
$s = stream_get_contents($dir);
$a = explode("\n", $s);
//$s = str_replace("\n", "", $s);
/*
$handle = fopen ("php://stdin","r");
fscanf($handle,"%d",$n);
$a = array();
for($a_i = 0; $a_i < $n; $a_i++) {
   $a_temp = fgets($handle);
   $a[] = explode(" ",$a_temp);
  array_walk($a[$a_i],'intval');
}
*/
/*
$n=3;

$a = [
	['Burunduk1', 2400, 2400],
	['BudAlNik', 2390, 2431],
	['subscriber', -2500, -2450]
];
*/
$n=$a[0];
$good = false;
for($i=0; $i<3 ;$i++){
	$x = explode(" ", $a[$i+1]);
	if(intval($x[1]) >= 2400 &&  intval($x[2]) > intval($x[1])){
		$good = true;
		break;
	}
}
if($good){
	print "YES";
}else{
	print "NO";
}

$handle = fopen ("php://stdin","r");
fscanf($handle,"%d",$n);
$arr_temp = fgets($handle);
$arr = explode(" ",$arr_temp);
array_walk($handles,'intval');

$n=3;
$handles = [
	['Burunduk1', 2526, 2537],
	['BudAlNik', 2084, 2214],
	['subscriber', 2833, 2749]
];
$good = false;
for($i=0; $i<3 ;$i++){
	if($handles[$i][1] > 2400 &&  $handles[$i][2] > $handles[$i][1]){
		$good = true;
		break;
	}
}
if($good){
	echo "YES";
}else{
	echo "NO";
}

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$answ="NO";
while (!feof($stdin)) {
	list($name,$before,$after)=explode(" ",trim(fgets($stdin)));
	if($before>=2400&&$after>2400){
		$answ="YES";
	}

}

echo $answ;

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$answ="NO";
$i=0;
while ($i<(int)$s) {
	$i++;
	list($name,$before,$after)=explode(" ",trim(fgets($stdin)));
	if($before>=2400&&$after>2400){
		$answ="YES";

		break;

	}

}
echo $answ;

<?php
$fp = fopen('php://stdin', 'r');
$n = (int)fgets($fp);
for($i = 0; $i < $n; ++$i) {
	list($name, $before, $after) = explode(' ', fgets($fp));
	if ($after > $before && $before > 2400) {
		die('YES');
	}
}
die('NO');

<?php
$fp = fopen('php://stdin', 'r');
$n = (int)fgets($fp);
for($i = 0; $i < $n; ++$i) {
	list($name, $before, $after) = explode(' ', fgets($fp));
	if ($after > $before && $before >= 2400) {
		die('YES');
	}
}
die('NO');


According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.

The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.

Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.

<?php

$line0 = trim(fgets(STDIN));
$line1 = trim(fgets(STDIN));

$data = explode(' ', $line0);
$delta = $data[1]; //  разница в росте

$heights = explode(' ', $line1);

for ($j = 0; $j < count($heights); $j++) {
	for ($i = 0; $i < count($heights); $i++) {
		if ($j != $i) {
			$d = abs($heights[$j] - $heights[$i]);
			$pairs[] = $d;
		}
	}
}

$agents = 0;

for ($i = 0; $i < count($pairs); $i++) {
	if ($pairs[$i] <= $delta) {
		$agents = $agents + 1;
	}
}

echo $agents . "\n";

?>

<?php
$stdout = fopen('php://stdout', 'w');
$h = fopen('php://stdin', 'r');

$s1 = trim(fgets($h));
$s = trim(fgets($h));

$vhdannie=explode(' ', $s1);
$n=(int)$vhdannie[0];
$d=(int)$vhdannie[1];
$otryad=explode(' ', $s);
if ((is_integer($n) && $n>=1 && $n<=1000)&&(is_integer($d) && $d>=1 && $d<=exp(9*log(10))))
{ //проверка диапозона для n
    $f=true;
    for ($i=0; $i<=$n-1; $i++)
    {// проверка данных роста солдат
        if (($otryad[$i]<1)||($otryad[$i]>exp(9*log(10))))
        {$f=false;}
    }
    if ($f)
    {
        $count=0;
        for ($i=0; $i<$n-1; $i++)
        {
            for ($j=$i+1; $j<$n; $j++)
            {
                $h=abs($otryad[$i]-$otryad[$j]);
                if ($h<=$d) {$count++;}
            }
        }
        $count=$count*2;
        fputs(STDOUT, "$count");
    }
}
?>

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

$h=explode(' ',fgets($stdin));

$ans=0;
foreach($h as $i => $a)
    foreach($h as $j => $b)
        if($i!=$j && abs($a-$b)<=$d) $ans++;

echo $ans;

<?php
// last submit in this semester
$stdin=fopen('php://stdin','r');
fscanf($stdin,"%d %d",$n,$d);

$height=explode(' ',fgets($stdin));

$ans=0;
for($i=0 ;$i<$n ;$i++)
{
	for($j=$i+1 ;$j<$n ;$j++)
	{
		if(abs($height[$i]-$height[$j])<=$d) $ans+=2;
	}
}
printf("%d\n",$ans);

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

$height=explode(' ',fgets($stdin));

$ans=0;
foreach($height as $i => $a)
    foreach($height as $j => $b)
        if($i!=$j && abs($a-$b)<=$d) $ans++;

echo $ans;

<?php
    $stdin = fopen('php://stdin', 'r');
    $stdout = fopen('php://stdout', 'w');

    $n_d = explode(" ", fgets($stdin));
    $numbers = explode(" ", fgets($stdin));

    $count_pairs=0;
    for($i=0;$i<$n_d[0];++$i){
        for($j=0;$j<$n_d[0];++$j){
            if((abs($numbers[$i]-$numbers[$j]) <= $n_d[1])&&($i!=$j)) $count_pairs++;
        }
    }

    fputs($stdout, $count_pairs++);
?>

<?php
$stdout = fopen('php://stdout', 'w');
fputs(STDOUT, "Vhodnie dannie:  ");
$h = fopen('php://stdin', 'r');
$s1 = trim(fgets($h));
$s = trim(fgets($h));
$len1 = strlen($s1);
$len = strlen($s);
$r=stripos($s1,' ');
$n=(int)substr($s1, 0, $r);
$d=(int)substr($s1, $r+1, $len1-$r-1);
if (($n>=1 && $n<=1000)&&($d>=1 && $d<=exp(9*log(10))))
	{
for ($i=1; $i<=$n-1; $i++)
{
	$r=stripos($s,' ');
	$mas[$i]=substr($s, 0, $r);
	$s=substr($s, $r+1, $len-$r-1);
	}
	$mas[$n]=$s;
fputs(STDOUT, "Vihodnie dannie:  ");
	$count=0;
	for ($i=1; $i<=$n-1; $i++)
	{
		for ($j=$i+1; $j<=$n; $j++)
		{
			$h=abs($mas[$i]-$mas[$j]);
			if ($h<=$d) {$count++;}
			}
		}
		$count=$count*2;
		fputs(STDOUT, "$count");
	}
	else
	{fputs(STDOUT, "Nevernii diapazon");
		}
?>

<?php
// last submit in this semester
fscanf(STDIN,"%d %d",$n,$d);

$height=array();
for($i=0 ;$i<$n ;$i++)
{
	fscanf(STDIN,"%d",$tmp);
	$height[]=$tmp;
}

$ans=0;
for($i=0 ;$i<$n ;$i++)
{
	for($j=$i+1 ;$j<$n ;$j++)
	{
		if(abs($height[i]-$height[j])<=$d) $ans+=2;
	}
}
printf("%d\n",$ans);

<?php
// last submit in this semester
fscanf(STDIN,"%d %d",$n,$d);

$height=array($n);
for($i=0 ;$i<$n ;$i++) fscanf(STDIN,"%d",$height[$i]);

$ans=0;
for($i=0 ;$i<$n ;$i++)
{
	for($j=$i+1 ;$j<$n ;$j++)
	{
		if(abs($height[$i]-$height[$j])<=$d) $ans+=2;
	}
}
printf("%d\n",$ans);

<?php
// last submit in this semester
fscanf(STDIN,"%d %d",$n,$d);

$height=array($n);
for($i=0 ;$i<$n ;$i++) fscanf(STDIN,"%d",$height[$i]);
for($i=0 ;$i<$n ;$i++) echo $height[$i];

$ans=0;
for($i=0 ;$i<$n ;$i++)
{
	for($j=$i+1 ;$j<$n ;$j++)
	{
		if(abs($height[$i]-$height[$j])<=$d) $ans+=2;
	}
}
printf("%d\n",$ans);

<?php
// last submit in this semester
$stdin=fopen(STDIN,'r');
fscanf($stdin,"%d %d",$n,$d);

$height=explode(' ',fgets($stdin));

$ans=0;
for($i=0 ;$i<$n ;$i++)
{
	for($j=$i+1 ;$j<$n ;$j++)
	{
		if(abs($height[$i]-$height[$j])<=$d) $ans+=2;
	}
}
printf("%d\n",$ans);

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

$height=explode(' ',fgets($stdin));

$ans=0;
foreach($height as $a)
	foreach($height as $b)
		if(abs($a-$b)<=$d) $ans++;

echo $ans;


The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:  The query to swap two table rows;  The query to swap two table columns;  The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.

The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly. Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106. Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers.   If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y);  If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y);  If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m).  The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.

For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.

NoteLet's see how the table changes in the second test case.After the first operation is fulfilled, the table looks like that:2 1 41 3 5After the second operation is fulfilled, the table looks like that:1 3 52 1 4So the answer to the third query (the number located in the first row and in the third column) will be 5.


You have a description of a lever as string s. We'll represent the string length as record |s|, then the lever looks as a horizontal bar with weights of length |s| - 1 with exactly one pivot. We will assume that the bar is a segment on the Ox axis between points 0 and |s| - 1.The decoding of the lever description is given below.  If the i-th character of the string equals "^", that means that at coordinate i there is the pivot under the bar.  If the i-th character of the string equals "=", that means that at coordinate i there is nothing lying on the bar.  If the i-th character of the string equals digit c (1-9), that means that at coordinate i there is a weight of mass c on the bar. Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn't weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance.

The first line contains the lever description as a non-empty string s (3 ≤ |s| ≤ 106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar. To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs.

Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance.

NoteAs you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.The pictures to the examples:

<?php

$a = trim(fgets(STDIN));

while($a[$i] !='^')
   $i++;
 $right = $i;
    $right2 = $i;
while($i>0)
{
    if($a[$j] == '=')
      $temp = 0;
    else
      $temp = $a[$j];

    $totalL = $totalL +($temp * $i);

    $i--;
    $j++;
}
$right++;
while($a[$right])
{
    if($a[$right] == '=')
      $temp = 0;
    else
      $temp = $a[$right];

    $totalR = $totalR +($temp * ($right-$right2));

    $right++;
}

if($totalR > $totalL)
   echo"right";
else if($totalR < $totalL)
    echo"left";
else
    echo"balance";
    ?>

<?php
$str=fgets(STDIN);
$de=explode("^",$str);
$s1=strrev($de[0]);
$s2=$de[1];
$left=0;
$right=0;
for($i=0;$i<strlen($s1);$i++){
    $te=$s1[$i];
    if($te!="="){
        $left+=($i+1)*intval($te,10);
    }
}

for($i=0;$i<strlen($s2);$i++){
    $te=$s2[$i];
    if($te!="="){
        $right+=($i+1)*intval($te,10);
    }
}

if($left==$right) echo "balance";
else if($left>$right) echo "left";
else echo "right";
?>

<?php
$handle = fopen ("php://stdin","r");
$n = fgets($handle);

$n=explode("^",$n);
$left = $n[0];
$right = $n[1];

$sr=0;
$sl=0;
$ctmp=1;

for($i=strlen($left)-1;$i>=0;$i--)
{
        if($left[$i] != "=")
        $sl+=$left[$i]*$ctmp;

$ctmp++;
}
$ctmp=1;
for($i=0;$i<strlen($right);$i++)
{
        if($right[$i] != "=")
        $sr+=$right[$i]*$ctmp;
$ctmp++;
}

if($sr==$sl)
echo 'balance';
else if ($sr>$sl)
echo 'right';
else
echo 'left';

?>

<?php
error_reporting("off");
//376A: Lever
$lever = trim(fgets(STDIN)); //$lever = "=^==";
$fulcrum = strpos($lever, "^");
$left = substr($lever, 0, $fulcrum);
$right = str_split(substr($lever, $fulcrum + 1));
$left = str_split(strrev($left));
$leftweight = 0;
$rightweight = 0;
foreach ($left as $key => $value) {
    if ($value !== "=") {
        $pos = $key + 1;
        $leftweight += $value * $pos;
    }
}
foreach ($right as $key => $value) {
    if ($value !== "=") {
        $pos = $key + 1;
        $rightweight += $value * $pos;
    }
}

if ($leftweight == $rightweight) {
    echo "balance";
} elseif ($leftweight > $rightweight) {
    echo "left";
} else {
    echo "right";
}
?>

<?php
error_reporting("off");
//376C: Divisible by Seven
$pieces = str_split(trim(fgets(STDIN))); //$pieces = str_split("2419323689");
$one = array_search("1", $pieces);
$six = array_search("6", $pieces);
$eight = array_search("8", $pieces);
$nine = array_search("9", $pieces);
unset($pieces[$one]);
unset($pieces[$six]);
unset($pieces[$eight]);
unset($pieces[$nine]);
sort($pieces);
$zeros = count(array_keys($pieces, "0"));
for ($i = 0; $i < $zeros; $i++) {
    unset($pieces[$i]);
}
$whatsleft = implode($pieces);
$modseven = fmod($whatsleft * 10000, 7);

if ($modseven == 0) {
    $special = 1869;
} elseif ($modseven == 1) {
    $special = 8196;
} elseif ($modseven == 2) {
    $special = 8916;
} elseif ($modseven == 3) {
    $special = 1698;
} elseif ($modseven == 4) {
    $special = 6891;
} elseif ($modseven == 5) {
    $special = 9186;
} elseif ($modseven == 6) {
    $special = 6189;
}

echo $whatsleft.$special.str_repeat("0", $zeros);
?>

<?php
error_reporting("off");
//376A: Lever
$lever = trim(fgets(STDIN)); $lever = "=^==";
$fulcrum = strpos($lever, "^");
$left = substr($lever, 0, $fulcrum);
$right = str_split(substr($lever, $fulcrum + 1));
$left = str_split(strrev($left));
$leftweight = 0;
$rightweight = 0;
foreach ($left as $key => $value) {
    if ($value !== "=") {
        $pos = $key + 1;
        $leftweight += $value * $pos;
    }
}
foreach ($right as $key => $value) {
    if ($value !== "=") {
        $pos = $key + 1;
        $rightweight += $value * $pos;
    }
}

if ($left == $right) {
    echo "balance";
} elseif ($left > $right) {
    echo "left";
} else {
    echo "right";
}
?>

<?php
error_reporting("off");
//376A: Lever
$lever = trim(fgets(STDIN)); //$lever = "=^==";
$fulcrum = strpos($lever, "^");
$left = substr($lever, 0, $fulcrum);
$right = str_split(substr($lever, $fulcrum + 1));
$left = str_split(strrev($left));
$leftweight = 0;
$rightweight = 0;
foreach ($left as $key => $value) {
    if ($value !== "=") {
        $pos = $key + 1;
        $leftweight += $value * $pos;
    }
}
foreach ($right as $key => $value) {
    if ($value !== "=") {
        $pos = $key + 1;
        $rightweight += $value * $pos;
    }
}

if ($left == $right) {
    echo "balance";
} elseif ($left > $right) {
    echo "left";
} else {
    echo "right";
}
?>


Acingel is a small town. There was only one doctor here — Miss Ada. She was very friendly and nobody has ever said something bad about her, so who could've expected that Ada will be found dead in her house? Mr Gawry, world-famous detective, is appointed to find the criminal. He asked $$$m$$$ neighbours of Ada about clients who have visited her in that unlucky day. Let's number the clients from $$$1$$$ to $$$n$$$. Each neighbour's testimony is a permutation of these numbers, which describes the order in which clients have been seen by the asked neighbour.However, some facts are very suspicious – how it is that, according to some of given permutations, some client has been seen in the morning, while in others he has been seen in the evening? "In the morning some of neighbours must have been sleeping!" — thinks Gawry — "and in the evening there's been too dark to see somebody's face...". Now he wants to delete some prefix and some suffix (both prefix and suffix can be empty) in each permutation, so that they'll be non-empty and equal to each other after that — some of the potential criminals may disappear, but the testimony won't stand in contradiction to each other.In how many ways he can do it? Two ways are called different if the remaining common part is different.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100\,000$$$, $$$1 \le m \le 10$$$) — the number of suspects and the number of asked neighbors. Each of the next $$$m$$$ lines contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$). It is guaranteed that these integers form a correct permutation (that is, each number from $$$1$$$ to $$$n$$$ appears exactly once).

Output a single integer denoting the number of ways to delete some prefix and some suffix of each permutation (possibly empty), such that the remaining parts will be equal and non-empty.

NoteIn the first example, all possible common parts are $$$[1]$$$, $$$[2]$$$, $$$[3]$$$ and $$$[2, 3]$$$.In the second and third examples, you can only leave common parts of length $$$1$$$.


A positive integer $$$x$$$ is called a power of two if it can be represented as $$$x = 2^y$$$, where $$$y$$$ is a non-negative integer. So, the powers of two are $$$1, 2, 4, 8, 16, \dots$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to represent $$$n$$$ as the sum of exactly $$$k$$$ powers of two.

The only line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le k \le 2 \cdot 10^5$$$).

If it is impossible to represent $$$n$$$ as the sum of $$$k$$$ powers of two, print NO. Otherwise, print YES, and then print $$$k$$$ positive integers $$$b_1, b_2, \dots, b_k$$$ such that each of $$$b_i$$$ is a power of two, and $$$\sum \limits_{i = 1}^{k} b_i = n$$$. If there are multiple answers, you may print any of them.

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

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

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

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

$ir = new InputReader();

/* TASK */

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

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

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

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

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

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

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

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

$ir = new InputReader();

/* TASK */

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

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

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

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

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

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

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

$ir = new InputReader();

/* TASK */

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

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

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


You have $$$n$$$ rectangular wooden blocks, which are numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th block is $$$1$$$ unit high and $$$\lceil \frac{i}{2} \rceil$$$ units long.Here, $$$\lceil \frac{x}{2} \rceil$$$ denotes the result of division of $$$x$$$ by $$$2$$$, rounded up. For example, $$$\lceil \frac{4}{2} \rceil = 2$$$ and $$$\lceil \frac{5}{2} \rceil = \lceil 2.5 \rceil = 3$$$.For example, if $$$n=5$$$, then the blocks have the following sizes: $$$1 \times 1$$$, $$$1 \times 1$$$, $$$1 \times 2$$$, $$$1 \times 2$$$, $$$1 \times 3$$$.  The available blocks for $$$n=5$$$ Find the maximum possible side length of a square you can create using these blocks, without rotating any of them. Note that you don't have to use all of the blocks.  One of the ways to create $$$3 \times 3$$$ square using blocks $$$1$$$ through $$$5$$$

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the number of blocks.

For each test case, print one integer — the maximum possible side length of a square you can create.

NoteIn the first test case, you can create a $$$1 \times 1$$$ square using only one of the blocks.In the second test case, one of the possible ways to create a $$$3 \times 3$$$ square is shown in the statement. It is impossible to create a $$$4 \times 4$$$ or larger square, so the answer is $$$3$$$.

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s,$t] = explode(' ', trim(fgets(STDIN)));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$s = explode(' ', trim(fgets(STDIN)));
//function decr($v){return --$v;}
//$alpha='abcdefghijklmnopqrstuvwxyz';
//$mod=1000000009;
//$mod=1000000007;
//$mod=998244353;
//$a=[];
//$b=[];
//for($i=0;$i<$n;$i++){
//    [$a[],$b[]] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//}

for($x=0;$x<$t;$x++){
    [$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $ans[] = intdiv($n+1,2);
}
echo implode(PHP_EOL, $ans);


Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.

The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.

If the given sequence has the second order statistics, output this order statistics, otherwise output NO.

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

<?php

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

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

    if ($die) {
        die();
    }

    echo '</pre>';
}

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

    return $stdin;
}

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

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

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

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

?>

<?php

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

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

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

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

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

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

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

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

<?php

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

<?php

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

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

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


The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task?

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days.

Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution.


There is a country with $$$n$$$ citizens. The $$$i$$$-th of them initially has $$$a_{i}$$$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $$$x$$$ are paid accordingly so that after the payout they have exactly $$$x$$$ money. In this case the citizens don't send a receipt.You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{5}$$$) — the numer of citizens. The next line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$0 \le a_{i} \le 10^{9}$$$) — the initial balances of citizens. The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^{5}$$$) — the number of events. Each of the next $$$q$$$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($$$1 \le p \le n$$$, $$$0 \le x \le 10^{9}$$$), or 2 x ($$$0 \le x \le 10^{9}$$$). In the first case we have a receipt that the balance of the $$$p$$$-th person becomes equal to $$$x$$$. In the second case we have a payoff with parameter $$$x$$$.

Print $$$n$$$ integers — the balances of all citizens after all events.

NoteIn the first example the balances change as follows: 1 2 3 4 $$$\rightarrow$$$ 3 3 3 4 $$$\rightarrow$$$ 3 2 3 4 $$$\rightarrow$$$ 3 2 3 4In the second example the balances change as follows: 3 50 2 1 10 $$$\rightarrow$$$ 3 0 2 1 10 $$$\rightarrow$$$ 8 8 8 8 10 $$$\rightarrow$$$ 8 8 20 8 10


There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any betting decisions, he/she may only do so if all other players have a status of either "ALLIN" or "FOLDED". The player's own status may be either "ALLIN" or "IN".Find the number of cows that can currently show their hands without affecting any betting decisions.

The first line contains a single integer, n (2 ≤ n ≤ 2·105). The second line contains n characters, each either "A", "I", or "F". The i-th character is "A" if the i-th player's status is "ALLIN", "I" if the i-th player's status is "IN", or "F" if the i-th player's status is "FOLDED".

The first line should contain a single integer denoting the number of players that can currently show their hands.

NoteIn the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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