After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer!Some days before the contest, the teacher took a very simple-looking exam and all his n students took part in the exam. The teacher gave them 3 strings and asked them to concatenate them. Concatenating strings means to put them in some arbitrary order one after the other. For example from concatenating Alireza and Amir we can get to AlirezaAmir or AmirAlireza depending on the order of concatenation.Unfortunately enough, the teacher forgot to ask students to concatenate their strings in a pre-defined order so each student did it the way he/she liked.Now the teacher knows that Shapur is such a fast-calculating genius boy and asks him to correct the students' papers.Shapur is not good at doing such a time-taking task. He rather likes to finish up with it as soon as possible and take his time to solve 3-SAT in polynomial time. Moreover, the teacher has given some advice that Shapur has to follow. Here's what the teacher said:   As I expect you know, the strings I gave to my students (including you) contained only lowercase and uppercase Persian Mikhi-Script letters. These letters are too much like Latin letters, so to make your task much harder I converted all the initial strings and all of the students' answers to Latin.  As latin alphabet has much less characters than Mikhi-Script, I added three odd-looking characters to the answers, these include "-", ";" and "_". These characters are my own invention of course! And I call them Signs.  The length of all initial strings was less than or equal to 100 and the lengths of my students' answers are less than or equal to 600  My son, not all students are genius as you are. It is quite possible that they make minor mistakes changing case of some characters. For example they may write ALiReZaAmIR instead of AlirezaAmir. Don't be picky and ignore these mistakes.  Those signs which I previously talked to you about are not important. You can ignore them, since many students are in the mood for adding extra signs or forgetting about a sign. So something like Iran;;-- is the same as --;IRAN  You should indicate for any of my students if his answer was right or wrong. Do this by writing "WA" for Wrong answer or "ACC" for a correct answer.  I should remind you that none of the strings (initial strings or answers) are empty.  Finally, do these as soon as possible. You have less than 2 hours to complete this.

The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively. In the fourth line there is a single integer n (0 ≤ n ≤ 1000), the number of students. Next n lines contain a student's answer each. It is guaranteed that the answer meets what the teacher said. Each answer iconsists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). Length is from 1 to 600, inclusively.

For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.

Iran_
Persian;
W_o;n;d;e;r;f;u;l;
7
WonderfulPersianIran
wonderful_PersIAN_IRAN;;_
WONDERFUL___IRAN__PERSIAN__;;
Ira__Persiann__Wonderful
Wonder;;fulPersian___;I;r;a;n;
__________IranPersianWonderful__________
PersianIran_is_Wonderful

Shapur;;
is___
a_genius
3
Shapur__a_is___geniUs
is___shapur___a__Genius;
Shapur;;is;;a;;geni;;us;;


On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length $$$k$$$ ($$$k \ge 3$$$). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains.Mountains are described by a sequence of heights $$$a_1, a_2, \dots, a_n$$$ in order from left to right ($$$k \le n$$$). It is guaranteed that neighboring heights are not equal to each other (that is, $$$a_i \ne a_{i+1}$$$ for all $$$i$$$ from $$$1$$$ to $$$n-1$$$).Peaks of mountains on the segment $$$[l,r]$$$ (from $$$l$$$ to $$$r$$$) are called indexes $$$i$$$ such that $$$l < i < r$$$, $$$a_{i - 1} < a_i$$$ and $$$a_i > a_{i + 1}$$$. It is worth noting that the boundary indexes $$$l$$$ and $$$r$$$ for the segment are not peaks. For example, if $$$n=8$$$ and $$$a=[3,1,4,1,5,9,2,6]$$$, then the segment $$$[1,8]$$$ has only two peaks (with indexes $$$3$$$ and $$$6$$$), and there are no peaks on the segment $$$[3, 6]$$$.To break the door, Nastya throws it to a segment $$$[l,l+k-1]$$$ of consecutive mountains of length $$$k$$$ ($$$1 \le l \le n-k+1$$$). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to $$$p+1$$$, where $$$p$$$ is the number of peaks on the segment $$$[l,l+k-1]$$$.Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains $$$[l, l+k-1]$$$ that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value $$$l$$$ is minimal.Formally, you need to choose a segment of mountains $$$[l, l+k-1]$$$ that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value $$$l$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$)  — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$3 \leq k \leq n \leq 2 \cdot 10^5$$$)  — the number of mountains and the length of the door. The second line of the input data set contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \leq a_i \leq 10 ^ 9$$$, $$$a_i \neq a_{i + 1}$$$)  — the heights of mountains. It is guaranteed that the sum of $$$n$$$ over all the test cases will not exceed $$$2 \cdot 10^5$$$.

For each test case, output two integers $$$t$$$ and $$$l$$$  — the maximum number of parts that the door can split into, and the left border of the segment of length $$$k$$$ that the door should be reset to.

NoteIn the first example, you need to select a segment of mountains from $$$2$$$ to $$$7$$$. In this segment, the indexes $$$3$$$ and $$$6$$$ are peaks, so the answer is $$$3$$$ (only $$$2$$$ peaks, so the door will break into $$$3$$$ parts). It is not difficult to notice that the mountain segments $$$[1, 6]$$$ and $$$[3, 8]$$$ are not suitable since they only have a $$$1$$$ peak (for the first segment, the $$$6$$$ index is not a peak, and for the second segment, the $$$3$$$ index is not a peak).In the second example, you need to select a segment of mountains from $$$2$$$ to $$$4$$$. In this segment, the index $$$3$$$ is a peak, so the answer is $$$2$$$ (only $$$1$$$ peak, so the door will break into $$$2$$$ parts).In the third example, you need to select a segment of mountains from $$$1$$$ to $$$4$$$. In this segment, the index $$$3$$$ is a peak, so the answer is $$$2$$$ (only $$$1$$$ peak, so the door will break into $$$2$$$ parts). You can see that on the segments $$$[2, 5]$$$, $$$[4, 7]$$$ and $$$[5, 8]$$$ the number of peaks is also $$$1$$$, but these segments have a left border greater than the segment $$$[1, 4]$$$, so they are not the correct answer.

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

    $Nastya = array_fill(0, MAXN, 0) ;

    function solve($n, $k)
    {
        global $Nastya ;

        $sum = array_fill(0, $n, 0) ;

        for($i = 1; $i < $n; $i ++)
        {
            if($i + 1 < $n && $Nastya[$i] > $Nastya[$i - 1] && $Nastya[$i] > $Nastya[$i + 1])
                $sum[$i] = $sum[$i - 1] + 1 ;
            else
                $sum[$i] = $sum[$i - 1] ;
        }

        //var_dump($sum) ;

        $max_ans = 0 ;
        $max_pos = 1 ;

        for($i = 1; $i + $k - 1 < $n; $i ++)
        {
            $tmp = $sum[$i + $k - 1] - $sum[$i - 1] ;

            if($tmp > $max_ans)
            {
                $max_ans = $tmp ;
                $max_pos = $i ;
            }
        }
        echo $max_ans + 1 . " " . $max_pos . "\n" ;
    }

    $T = intval(fgets(STDIN));
    while($T --)
    {
        $tmp_in = explode(" ", trim(fgets(STDIN))) ;

        $n = intval($tmp_in[0]) ;
        $k = intval($tmp_in[1]) - 2 ;

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

        for($i = 0; $i < $n; $i ++) $Nastya[$i] = intval($tmp_in[$i]) ;

        solve($n, $k) ;
    }
?>

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

    $Nastya = array_fill(0, MAXN, 0) ;

    function solve($n, $k)
    {
        global $Nastya ;

        $sum = array_fill(0, $n, 0) ;

        for($i = 1; $i < $n; $i ++)
        {
            if($i + 1 < $n && $Nastya[$i] > $Nastya[$i - 1] && $Nastya[$i] > $Nastya[$i + 1])
                $sum[$i] = $sum[$i - 1] + 1 ;
            else
                $sum[$i] = $sum[$i - 1] ;
        }

        //var_dump($sum) ;

        $max_ans = 0 ;
        $max_pos = 0 ;

        for($i = 1; $i + $k - 1 < $n; $i ++)
        {
            $tmp = $sum[$i + $k - 1] - $sum[$i - 1] ;

            if($tmp > $max_ans)
            {
                $max_ans = $tmp ;
                $max_pos = $i ;
            }
        }
        echo $max_ans + 1 . " " . $max_pos . "\n" ;
    }

    $T = intval(fgets(STDIN));
    while($T --)
    {
        $tmp_in = explode(" ", trim(fgets(STDIN))) ;

        $n = intval($tmp_in[0]) ;
        $k = intval($tmp_in[1]) - 2 ;

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

        for($i = 0; $i < $n; $i ++) $Nastya[$i] = intval($tmp_in[$i]) ;

        solve($n, $k) ;
    }
?>


Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take? Note: A Pokemon cannot fight with itself.

The input consists of two lines. The first line contains an integer n (1 ≤ n ≤ 105), the number of Pokemon in the lab. The next line contains n space separated integers, where the i-th of them denotes si (1 ≤ si ≤ 105), the strength of the i-th Pokemon.

Print single integer — the maximum number of Pokemons Bash can take.

Notegcd (greatest common divisor) of positive integers set {a1, a2, ..., an} is the maximum positive integer that divides all the integers {a1, a2, ..., an}.In the first sample, we can take Pokemons with strengths {2, 4} since gcd(2, 4) = 2.In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with gcd ≠ 1.

<?php

    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    ini_set('memory_limit', '512M');

    define('MMAX', pow(10, 5));

    // define('DEBUG', true);
    define('DEBUG', false);

    $arrP = array();

    $rt = floor(sqrt(MMAX));
    for ($i = 2; $i < MMAX; $i++) {
        if (isset($arrP[$i])) continue;
        // echo "{$i} ";
        $arrP[$i][] = $i;
        $loop = floor(MMAX / $i);
        for ($j = 2; $j <= $loop; $j++) {
            $arrP[$i*$j][] = $i;
        }
    }
    for ($i = 4; $i <= MMAX; $i++) {
        if (!isset($arrP[$i])) {
            $arrP[$i][] = $i;
        }
    }

    if (DEBUG) {
        $tm1 = microtime(true);
    }

    fscanf(STDIN, "%d", $N);
    $a = explode(" ", trim(fgets(STDIN)));
    // var_dump($a);

    // for TEST
    // $a = range(1, 100000);
    // $N = count($a);

    $sum = array(1 => 1);

    for ($i = 0; $i < $N; $i++) {
        // echo "\nRET:\n";
        // var_dump($ret);
        if (DEBUG) var_dump($arrP[$a[$i]]);
        if (is_array($arrP[$a[$i]])) {
            $cnt = count($arrP[$a[$i]]);
            for ($j = 0; $j < $cnt; $j++) {
                $sum[$arrP[$a[$i]][$j]]++;
            }
        }
    }

    // var_dump($sum);
    // echo "answer:";

    echo max($sum);

    if (DEBUG) {
        $tm2 = microtime(true);
        echo PHP_EOL . "Time: " . ($tm2 - $tm1);
    }

<?php

    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    ini_set('memory_limit', '512M');

    define('MMAX', pow(10, 5));

    // define('DEBUG', true);
    define('DEBUG', false);

    $arrP = array();

    $rt = floor(sqrt(MMAX));
    for ($i = 2; $i < $rt; $i++) {
        if (isset($arrP[$i])) continue;
        // echo "{$i} ";
        $arrP[$i][] = $i;
        $loop = floor(MMAX / $i);
        for ($j = 2; $j <= $loop; $j++) {
            $arrP[$i*$j][] = $i;
        }
    }
    for ($i = 4; $i <= MMAX; $i++) {
        if (!isset($arrP[$i])) {
            $arrP[$i] = $i;
        }
    }

    if (DEBUG) {
        $tm1 = microtime(true);
    }

    fscanf(STDIN, "%d", $N);
    $a = explode(" ", trim(fgets(STDIN)));
    // var_dump($a);

    // for TEST
    // $a = range(1, 100000);
    // $N = count($a);

    $sum = array(1 => 1);

    for ($i = 0; $i < $N; $i++) {
        // echo "\nRET:\n";
        // var_dump($ret);
        // var_dump($arrP[$a[$i]]);
        if (is_array($arrP[$a[$i]])) {
            $cnt = count($arrP[$a[$i]]);
            for ($j = 0; $j < $cnt; $j++) {
                $sum[$arrP[$a[$i]][$j]]++;
            }
        }
    }

    // var_dump($sum);
    // echo "answer:";

    echo max($sum);

    if (DEBUG) {
        $tm2 = microtime(true);
        echo PHP_EOL . "Time: " . ($tm2 - $tm1);
    }

<?php
    // $tm1 = microtime(true);

    $erat = array();
    $arrP = array();
    define('MMAX', pow(10, 5));
    for ($i = 2; $i <= sqrt(MMAX); $i++) {
        $erat[$i] = 1;
    }
    for ($i = 2; $i <= sqrt(MMAX); $i++) {
        for ($j = 2; $j <= sqrt(MMAX); $j++) {
            unset($erat[$i*$j]);
        }
    }
    $arrP = array_keys($erat);

    fscanf(STDIN, "%d", $N);
    $a = explode(" ", trim(fgets(STDIN)));
    // $a = range(1, 100000);
    $cnt = count($a);
    $sum = array();

    for ($i = 0; $i < $cnt; $i++) {
        foreach ($arrP as $pnum) {
            // echo "{$a[$i]} {$pnum}\n";
            // if ($pnum > $a[$i]) break;
            if ($a[$i] % $pnum == 0) {
                $sum[$pnum]++;
            }
        }
    }

    // var_dump($sum);

    echo max($sum);

    // $tm2 = microtime(true);

    // echo PHP_EOL . ($tm2 - $tm1);

<?php

    ini_set('error_reporting', E_ALL & ~E_NOTICE);
    ini_set('memory_limit', '512M');

    define('MMAX', pow(10, 5));

    // define('DEBUG', true);
    define('DEBUG', false);

    $arrP = array();

    $rt = floor(sqrt(MMAX));
    for ($i = 2; $i < $rt; $i++) {
        if (isset($arrP[$i])) continue;
        // echo "{$i} ";
        $arrP[$i][] = $i;
        $loop = floor(MMAX / $i);
        for ($j = 2; $j <= $loop; $j++) {
            $arrP[$i*$j][] = $i;
        }
    }
    for ($i = 4; $i <= MMAX; $i++) {
        if (!isset($arrP[$i])) {
            $arrP[$i][] = $i;
        }
    }

    if (DEBUG) {
        $tm1 = microtime(true);
    }

    fscanf(STDIN, "%d", $N);
    $a = explode(" ", trim(fgets(STDIN)));
    // var_dump($a);

    // for TEST
    // $a = range(1, 100000);
    // $N = count($a);

    $sum = array(1 => 1);

    for ($i = 0; $i < $N; $i++) {
        // echo "\nRET:\n";
        // var_dump($ret);
        // if (DEBUG) var_dump($arrP[$a[$i]]);
        if (is_array($arrP[$a[$i]])) {
            $cnt = count($arrP[$a[$i]]);
            for ($j = 0; $j < $cnt; $j++) {
                $sum[$arrP[$a[$i]][$j]]++;
            }
        }
    }

    // var_dump($sum);
    // echo "answer:";

    echo max($sum);

    if (DEBUG) {
        $tm2 = microtime(true);
        echo PHP_EOL . "Time: " . ($tm2 - $tm1);
    }


The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:  ti = 1, if the i-th child is good at programming,  ti = 2, if the i-th child is good at maths,  ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?

The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.

In the first line output integer w — the largest possible number of teams.  Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.

<?php
$fp = fopen("php://STDIN", "r");
$n = fgets($fp);
$member = explode(" ", fgets($fp));

$memberA = array();
$memberB = array();
$memberC = array();

for($i=0;$i<count($member);$i++){
    switch ($member[$i]) {
        case 1:
            $memberA[] = $i;
            break;
        case 2:
            $memberB[] = $i;
            break;
        case 3:
            $memberC[] = $i;
            break;
    }
}
$minPos = min(count($memberA),count($memberB),count($memberC));
echo $minPos."\n";
for($m=0;$m<$minPos;$m++){
    $posA = $memberA[$m]+1;
    $posB = $memberB[$m]+1;
    $posC = $memberC[$m]+1;
    echo $posA." ".$posB." ".$posC." "."\n";
}

?>

<?php

$n = readline();
$uchastniki = readline();

//$n = 4;
//$uchastniki = '2 1 1 2';
$uchastniki = explode(' ',$uchastniki);
$prog = array();
$mat = array();
$sport = array();
$i = 0;
$skills = array();
foreach ($uchastniki as $v) {
    if ($v == 1) {
        $skills['кодер'] += 1;
        $prog[] = $i+1;
    } elseif ($v == 2) {
        $skills['математик'] += 1;
        $mat[] = $i+1;
    } else {
        $skills['физкультурник'] += 1;
        $sport[] = $i+1;
    }
    $i += 1;
}

if (count($skills) < 3) {
    echo 0;
} else {
    $teams = min($skills);
    echo $teams . "\n";
    $i = 0;

    while ($i < $teams) {
        echo $prog[$i] . ' ' . $mat[$i] . ' ' . $sport[$i] . "\n";
        $i += 1;
    }
}

<?php

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

fscanf($stdin, "%d" , $n ) ;
fscanf($stdin, "%[^\n]" , $test ) ;

$numbers = array_map( "intval" , preg_split( "/ /" , $test , -1 , PREG_SPLIT_NO_EMPTY )  );
$ones = [] ;
$twos = [] ;
$threes = [] ;

for( $i=0 ; $i<$n ; $i++ )
{
     switch( $numbers[$i] )
     {
          case 1:
               $ones[] = $i+1 ;
               break ;
          case 2:
               $twos[] = $i+1 ;
               break ;
          default:
               $threes[] = $i+1 ;
               break ;
     }
}

$w = min( count( $ones ) , count( $twos ) , count( $threes ) ) ;

echo $w ."\n";

for( $i=0 ; $i<$w ; $i++ )
{
     echo $ones[$i] . " " . $twos[$i] . " " . $threes[$i] . "\n" ;
}

fwrite($stdout);

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

?>

<?php
// 490A     Командная олимпиада
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$n = (int) $input_line;

$input_line = fgets($in);
$arr = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$arr1 = $arr2 = $arr3 = array();

for ($i=0; $i < $n; $i++) {
    switch ($arr[$i]) {
        case '1':
            array_push($arr1, $i + 1);
            break;
        case '2':
            array_push($arr2, $i + 1);
            break;
        case '3':
            array_push($arr3, $i + 1);
            break;
    }
}

$min = min(count($arr1), count($arr2), count($arr3));

echo $min."\n";

for ($i=0; $i < $min; $i++) {
    echo $arr1[$i]." ".$arr2[$i]." ".$arr3[$i]."\n";
}

?>

<?php
    trim(fgets(STDIN));
    $vals = explode(" ", trim(fgets(STDIN)));

    $cnt = $used = array();
    $cnt[] = $used[] = array();
    for($i=0; $i<sizeof($vals); $i++)
    {
        $cnt[$vals[$i]][] = $i+1;
        $used[$vals[$i]]++;
    }

    rsort($used);

    echo (!$used[3]) ? 0 : $used[3] . PHP_EOL;
    for($i=0; $i<$used[3]; $i++)
        echo $cnt[1][$i] . " " . $cnt[2][$i] . " " . $cnt[3][$i] . PHP_EOL;
?>

<?php

$n = readline();
$uchastniki = readline();
$uchastniki = explode(' ',$uchastniki);
$prog = array();
$mat = array();
$sport = array();
$i = 0;
$skills = array();
foreach ($uchastniki as $v) {
    if ($v == 1) {
        $skills['кодер'] += 1;
        $prog[] = $i+1;
    } elseif ($v == 2) {
        $skills['математик'] += 1;
        $mat[] = $i+1;
    } else {
        $skills['физкультурник'] += 1;
        $sport[] = $i+1;
    }
    $i += 1;
}

$teams = min($skills);
echo $teams . "\n";
$i = 0;

while ($i < $teams) {
    echo $prog[$i] . ' ' . $mat[$i] . ' ' . $sport[$i] . "\n";
    $i += 1;
}


A tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered 1 through n.Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only three values n, d and h:  The tree had exactly n vertices.  The tree had diameter d. In other words, d was the biggest distance between two vertices.  Limak also remembers that he once rooted the tree in vertex 1 and after that its height was h. In other words, h was the biggest distance between vertex 1 and some other vertex. The distance between two vertices of the tree is the number of edges on the simple path between them.Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1".

The first line contains three integers n, d and h (2 ≤ n ≤ 100 000, 1 ≤ h ≤ d ≤ n - 1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively.

If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes). Otherwise, describe any tree matching Limak's description. Print n - 1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order.

NoteBelow you can see trees printed to the output in the first sample and the third sample.


You've got another geometrical task. You are given two non-degenerate polygons A and B as vertex coordinates. Polygon A is strictly convex. Polygon B is an arbitrary polygon without any self-intersections and self-touches. The vertices of both polygons are given in the clockwise order. For each polygon no three consecutively following vertices are located on the same straight line.Your task is to check whether polygon B is positioned strictly inside polygon A. It means that any point of polygon B should be strictly inside polygon A. "Strictly" means that the vertex of polygon B cannot lie on the side of the polygon A.

The first line contains the only integer n (3 ≤ n ≤ 105) — the number of vertices of polygon A. Then n lines contain pairs of integers xi, yi (|xi|, |yi| ≤ 109) — coordinates of the i-th vertex of polygon A. The vertices are given in the clockwise order. The next line contains a single integer m (3 ≤ m ≤ 2·104) — the number of vertices of polygon B. Then following m lines contain pairs of integers xj, yj (|xj|, |yj| ≤ 109) — the coordinates of the j-th vertex of polygon B. The vertices are given in the clockwise order. The coordinates of the polygon's vertices are separated by a single space. It is guaranteed that polygons A and B are non-degenerate, that polygon A is strictly convex, that polygon B has no self-intersections and self-touches and also for each polygon no three consecutively following vertices are located on the same straight line.

Print on the only line the answer to the problem — if polygon B is strictly inside polygon A, print "YES", otherwise print "NO" (without the quotes).


You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.

Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise.

NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm".

<?php
function next_char ($a) {
  return chr(ord($a)+1);
}
function prev_char ($a) {
  return chr(ord($a)-1);
}
$nt = intval(readline());
for ($i = 0; $i < $nt; ++$i)
{
	$l = intval(readline())-1;
	$s = readline();
	$t = true;
	for ($a = 0, $z = $l; $a < $l; ++$a, $z = $l-$a)
	{
		if ((next_char($s[$a]) == next_char($s[$z]))
		 || (next_char($s[$a]) == prev_char($s[$z]))
		 || (prev_char($s[$a]) == next_char($s[$z]))
		 || (prev_char($s[$a]) == prev_char($s[$z])))
		{
			continue;
		}
		echo "NO\n";
		$t = false;
		break;
	}
	if ($t) echo "YES\n";
}


And where the are the phone numbers?You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s is lexicographically smaller than t.It's guaranteed that the answer exists.Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {a, b, d}.String p is lexicographically smaller than string q, if p is a prefix of q, is not equal to q or there exists i, such that pi < qi and for all j < i it is satisfied that pj = qj. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a.

The first line of input contains two space separated integers n and k (1 ≤ n, k ≤ 100 000) — the length of s and the required length of t. The second line of input contains the string s consisting of n lowercase English letters.

Output the string t conforming to the requirements above. It's guaranteed that the answer exists.

NoteIn the first example the list of strings t of length 3, such that the set of letters of t is a subset of letters of s is as follows: aaa, aab, aac, aba, abb, abc, aca, acb, .... Among them, those are lexicographically greater than abc: aca, acb, .... Out of those the lexicographically smallest is aca.


You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the greatest common divisor.What is the minimum number of operations you need to make all of the elements equal to 1?

The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements in the array. The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.

Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1.

NoteIn the first sample you can turn all numbers to 1 using the following 5 moves:  [2, 2, 3, 4, 6].  [2, 1, 3, 4, 6]  [2, 1, 3, 1, 6]  [2, 1, 1, 1, 6]  [1, 1, 1, 1, 6]  [1, 1, 1, 1, 1] We can prove that in this case it is not possible to make all numbers one using less than 5 moves.


In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.

The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.

In the only line print the integer S — the minimum number of burles which are had to spend.

NoteIn the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.

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

<?php
$n = readline();
$ara = explode(' ', readline());
echo (max($ara)*$n)-array_sum($ara)."\n";

<?php

$n = readline();

$ara = explode(' ', readline());

rsort($ara);
$add = 0;

for($i=0; $i<$n; $i++)
	$add += $ara[$i];
echo ($ara[0]*$n)-$add."\n";

<?php

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

    // define('DEBUG', true);
    define('DEBUG', false);

    fscanf(STDIN, "%d", $n);
    $a = explode(" ", trim(fgets(STDIN)));

    $a_max = max($a);
    $a_sum = array_sum($a);

    $target = $a_max * $n;
    echo $target - $a_sum;

<?php
$peoples = readline();
$many = readline();
//$peoples = 5;
//$many = '1 1 0 1 1';
$many = explode(' ', $many);
$max_many = max($many);
$summa = 0;
  foreach ($many as $v) {
      if($v<$max_many){
        $summa = $summa + ($max_many-$v);
      }
  }
echo $summa;

<?php
fscanf(STDIN, "%d", $n);
$a = explode(" ", trim(fgets(STDIN)));
$x = max($a);
echo ($x*count($a)) - array_sum($a);
?>

<?
$dir = fopen("php://stdin", 'r');
$string =  stream_get_contents($dir);

$parametros = explode(PHP_EOL,$string);
//var_dump($parametros);

$n=$parametros[0];
$welfare=$parametros[1];

$welfareI = explode(" ",$welfare);
$max_welfare = max($welfareI);

foreach($welfareI as $w) {
    $total += $max_welfare - $w;
}

echo $total;
?>

<?php
    $stdin = fopen("php://stdin", "r");
    trim(fgets(STDIN));
    $arr = explode(' ', trim(fgets(STDIN)));
    fclose($stdin);

    sort($arr);

    foreach($arr as $x)
        $ans += $arr[sizeof($arr)-1] - $x;

    echo $ans . PHP_EOL;
?>


Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:  Include a person to the chat ('Add' command).  Remove a person from the chat ('Remove' command).  Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.

Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:   +<name> for 'Add' command.  -<name> for 'Remove' command.  <sender_name>:<message_text> for 'Send' command.  <name> and <sender_name> is a non-empty sequence of Latin letters and digits. <message_text> can contain letters, digits and spaces, but can't start or end with a space. <message_text> can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.

Print a single number — answer to the problem.

+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate

+Mike
-Mike
+Mike
Mike:Hi   I am here
-Mike
+Kate
-Kate

<?php

error_reporting(0);

solve();

function solve(){

	$user = 0;
	$bytes = 0;

	//$fp = @fopen("input.txt", "r");
	while(true)
	{
		//$com = rtrim(fgets($fp));
		$com = rtrim(fgets(STDIN));
		if ($com === "") break;

		if (strpos($com, "+") === 0) $user++;
		else if (strpos($com, "-") === 0) $user--;
		else $bytes += (strlen($com) - strpos($com, ":") - 1) * $user;
	}

	printf("%d",$bytes);
}
?>

<?php
while($s = fgets(STDIN)){
    $data .= $s;
}

$data = explode("\r\n", $data);
$bytes = 0;
$users = 0;

foreach($data as $line) {
    $line = trim($line);
    if(substr($line, 0, 1) == '+') {
        $users++;
        continue;
    }

    if(substr($line, 0, 1) == '-') {
        $users--;
        continue;
    }

    list($author, $message) = explode(":", $line);
    $bytes += strlen($message) * $users;
}

echo $bytes;

<?php
$input = file_get_contents("php://stdin");

$e = explode("\r\n",$input);

$count=0;
$data = 0;
foreach($e as $a)
{
    if($a[0]=="+")
    {
        $count++;
    }
    else if($a[0]=="-")
    {
        $count--;
    }
    else
    {
        $r = explode(":",$a);
        $data+=strlen($r[1])*$count;
    }
}
echo $data;
?>

<?php
function getName($item){
    $name = FALSE;
    if ($item{0} == "+"){
        $name = trim(ltrim(stristr($item, '+'), '+'));
    }elseif($item{0} == "-"){
        $name = trim(ltrim(stristr($item, '-'), '-'));
    }elseif(isMessage($item)){
        $name = trim(stristr($item, ':', true));
    }

    return $name;
}

function getMessageSize($item){
    $message = trim(ltrim(stristr($item, ':'), ":"));
    $size = strlen($message);
    return $size;
}

function isMessage($item){
    if (($item{0} != '+') && ($item{0} != '-') && (strpos($item, ":") != FALSE)){
        return TRUE;
    }else{
        return FALSE;
    }
}

function checkUser(&$arrUsers, $item){
    $name = getName($item);
    $res  = FALSE;
    foreach ($arrUsers as $login) {
        if ($login === $name){
            $res = TRUE;
        }
    }
    return $res;
}

function addUser(&$arrUsers, $name){
    $arrUsers[] = $name;
}

function deleteUser(&$arrUsers, $name){
    $res = FALSE;
    foreach ($arrUsers as $index =>$login) {
        if ($name === $login){
            unset($arrUsers[$index]);
            $res = TRUE;
            sort($arrUsers);
        }
    }
    return $res;
}

#получить файл и сформировать из него массив
$chat = file_get_contents("php://stdin");

//$chat = file_get_contents("test.txt");
$arrLogChat = explode("\n", $chat);

$arrActUser = array();
$size = 0;

foreach ($arrLogChat as $logItem) {
    if ($logItem{0} == "+"){
        addUser($arrActUser, getName($logItem));
        next;
    }elseif($logItem{0} == "-"){
        deleteUser($arrActUser, getName($logItem));
        next;
    }else{
        if (isMessage($logItem)){
            if (checkUser($arrActUser, $logItem)){
                $size = $size + (getMessageSize($logItem) * count($arrActUser));
            }else{
                next;
            }
        }else{
            next;
        }
    }
}

fwrite(STDOUT, $size);
//echo $size;
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt ="Input
// +Mike
// Mike:hello
// +Kate
// +Dmitry
// -Dmitry
// Kate:hi
// -Kate
// ";

$text = explode("\n",$datatxt);
$users = array();
$length = 0;
foreach ($text as $value) {
if (strlen($value)>0){
if (preg_match("/^\+/",$value)){
$user = substr($value,1);
if (!isset($users[$user])) $users[$user] = $user;
} else if (preg_match("/^\-/",$value)){
$user = substr($value,1);
if (isset($users[$user])) unset($users[$user]);
} else {
$send = preg_split("/:/",$value,2);
$length+=strlen(trim($send[1]))*count($users);
}
}
}
echo $length;
?>

<?php
    $data = '';
    $inputData = fopen('php://stdin','r');
    while(!feof($inputData)) {
        $data .= fgetc($inputData);
    }
    fclose($inputData);

    $dataRaw = explode(PHP_EOL, $data);

    $users = array();
    $usersCount = 0;
    $totalBytes = 0;
    foreach($dataRaw as $str) {
         if(empty($str)) continue;
         if($str[0] == '+') {
              $userName = substr($str, 1, strlen($str));
              $users[$userName] = 0;
              $usersCount++;
         } elseif($str[0] == '-') {
             $userName = substr($str, 1, strlen($str));
             unset($users[$userName]);
             $usersCount--;
         }  else {
             $tmp = explode(':', $str);
             $msg = $tmp[1];
             if($msg[0]==" " || substr($msg,0,-1) == " ") {
                 continue;
             }  else {
//                 if(isset($users[$tmp[0]])) {
//                     $mn = $usersCount - 1;
//                 }  else {
                     $mn = $usersCount;
                 //}
                 $totalBytes += strlen($msg)*$mn;
             }
         }
    }
    echo $totalBytes;

<?php
	$list = array();
	$out = 0;
	$fr = fopen("php://stdin","r");
	while ( $input = fgets($fr) )
	{
		$input = trim($input);
		switch ( $input[0] )
		{
			case '+':
				$input = substr($input, 1);
				$list[$input] = true;
				break;
			case '-':
				$input = substr($input, 1);
				unset( $list[$input] );
				break;
			default:
				$input = explode(':', $input, 2);
				$input = ltrim($input[1]);
				$out+= strlen($input) * count($list);
		}
	}
	fclose ($fr);

	echo $out;
?>

<?php
$u = 0;
$l = 0;
while($c = fgets(STDIN)){
 $c = trim($c);
 switch($c[0]){
  case '+': $u ++; break;
  case '-': $u --; break;
  default: list($user, $message) = explode(':',$c);
           $l += strlen($message) * $u;
           break;
 }
}
print $l;
?>

<?
$stdin = fopen('php://stdin', 'r');
$lines = stream_get_contents($stdin);

$lines=explode("\n", $lines);

$size=0;
$users=0;
foreach ($lines as $line)
{
    $line=trim($line);
    if ($line{0}=="+")
        $users++;
    elseif ($line{0}=="-")
        $users--;
    else
    {
        list($from, $mess)=explode(":", $line);
        $size+=strlen($mess)*$users;

    }
}
echo $size;
?>

<?php

error_reporting(0);

solve();

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

	$user = 0;
	$bytes = 0;

	while(true)
	{
		$com = $Input->in();
		if ($com === "") break;

		if (strpos($com, "+") === 0) $user++;
		else if (strpos($com, "-") === 0) $user--;
		else $bytes += (strlen($com) - strpos($com, ":") - 1) * $user;
	}

	print($bytes);
}

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

	public function __construct($localfile){

		if (is_file($localfile)) {

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

		} else {

			$contents = stream_get_contents(STDIN);

		}

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

	public function in(){

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

	}

	public function close(){

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

	}
}

?>

<?php
function getName($item){
    $name = FALSE;
    if ($item{0} == "+"){
        $name = trim(ltrim(stristr($item, '+'), '+'));
    }elseif($item{0} == "-"){
        $name = trim(ltrim(stristr($item, '-'), '-'));
    }elseif(isMessage($item)){
        $name = trim(stristr($item, ':', true));
    }

    return $name;
}

function getMessageSize($item){
    $message = trim(ltrim(stristr($item, ':'), ":"));
    $size = strlen($message);
    return $size;
}

function isMessage($item){
    if (($item{0} != '+') && ($item{0} != '-') && (strpos($item, ":") != FALSE)){
        return TRUE;
    }else{
        return FALSE;
    }
}

function checkUser(&$arrUsers, $item){
    $name = getName($item);
    $res  = FALSE;
    foreach ($arrUsers as $login) {
        if ($login === $name){
            $res = TRUE;
        }
    }
    return $res;
}

function addUser(&$arrUsers, $name){
    $arrUsers[] = $name;
}

function deleteUser(&$arrUsers, $name){
    $res = FALSE;
    foreach ($arrUsers as $index =>$login) {
        if ($name === $login){
            unset($arrUsers[$index]);
            $res = TRUE;
            sort($arrUsers);
        }
    }
    return $res;
}

#получить файл и сформировать из него массив
$chat = file_get_contents("php://stdin");

//$chat = file_get_contents("test.txt");
$arrLogChat = explode("\n", $chat);

$arrActUser = array();
$size = 0;

foreach ($arrLogChat as $logItem) {
    if ($logItem{0} == "+"){
        addUser($arrActUser, getName($logItem));
        next;
    }elseif($logItem{0} == "-"){
        deleteUser($arrActUser, getName($logItem));
        next;
    }else{
        if (isMessage($logItem)){
            if (checkUser($arrActUser, $logItem)){
                $size = $size + getMessageSize($logItem);
            }else{
                next;
            }
        }else{
            next;
        }
    }
}

echo $size;
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt ="h1
// b2";
$text = explode("\n",$datatxt);
$users = array();
$length = 0;
foreach ($text as $value) {
if (strlen($value)>0){
if (preg_match("/^\+/",$value)){
$user = substr($value,1);
if (!isset($users[$user])) $users[] = $user;
} else if (preg_match("/^\-/",$value)){
$user = substr($value,1);
if (isset($users[$user])) unset($users[$user]);
} else {
$send = preg_split("/:/",$value,2);
$length+=strlen(trim($send[1]))*count($users);
}
}
}
echo $length;
exit;
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt ="h1
// b2";
$text = explode("\n",$datatxt);
$users = array();
$length = 0;
foreach ($text as $value) {
if (strlen($value)>0){
if (preg_match("/^\+/",$value)){
$user = substr($value,1);
if (!isset($users[$user])) $users[] = $user;
} else if (preg_match("/^\-/",$value)){
$user = substr($value,1);
if (isset($users[$user])) unset($users[$user]);
} else {
$send = preg_split("/:/",$value,2);
$length+=strlen(trim($send[1]))*count($users);
}
}
}
echo $length;
?>

<?
$stdin = fopen('php://stdin', 'r');
$lines = stream_get_contents($stdin);

$lines=explode("\n", $lines);

$size=0;
foreach ($lines as $line)
{
    $line=trim($line);
    if ($line{0}=="+")
        $users[]=$line;
    elseif ($line{0}=="-")
        unset($users[array_search(line, $users)]);
    else
    {
        list($from, $mess)=explode(":", $line);
        $size+=strlen($mess)*(count($users));

    }

}
echo $size;
?>


Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:   The product of all numbers in the first set is less than zero ( < 0).  The product of all numbers in the second set is greater than zero ( > 0).  The product of all numbers in the third set is equal to zero.  Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array.

The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an (|ai| ≤ 103) — the array elements.

In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set. In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set. In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.

<?php
while($s = fgets(STDIN)){
    $input .= $s;
}
$input = explode("\r\n", $input);
$a=explode(" ", $input[1]);
$fl=0;
foreach($a as $number) {
    if ($number < 0) {
        $i++ ;
    }
    elseif ($number > 0) {
        $n++;
    }
}

foreach($a as $number) {
    if($number == 0) {
        $b[3][]=$number;
    }
    elseif ($number < 0) {
        if ($fl == 0) {
            $b[1][]=$number;
            $fl++;
        }
        elseif ($n == 0) {
            if ($i % 2 != 0) {
                $b[2][]=$number;
            }
            elseif (count($b[2]) == 0 || count($b[2]) % 2 != 0) {
                $b[2][]=$number;
            }
            else $b[3][]=$number;
        }
        else $b[3][]=$number;
    }
    else $b[2][]=$number;
}
echo count($b[1])." ";
foreach($b[1] as $number) {
    echo $number." ";
}
echo "\r\n".count($b[2])." ";
foreach($b[2] as $number) {
    echo $number." ";
}
echo "\r\n".count($b[3])." ";
foreach($b[3] as $number) {
    echo $number." ";
}
?>

<?php
while($s = fgets(STDIN)){
    $input .= $s;
}
$input = explode("\r\n", $input);
$a=explode(" ", $input[1]);
$fl=0;
foreach($a as $number) {
    if ($number < 0) {
        $i++ ;
    }
    elseif ($number > 0) {
        $n++;
    }
}

foreach($a as $number) {
    if($number == 0) {
        $b[3][]=$number;
    }
    elseif ($number < 0) {
        if ($fl == 0) {
            $b[1][]=$number;
            $fl++;
        }
        elseif ($n==0) {
            $b[2][]=$number;
        }
        else $b[3][]=$number;
    }
    else $b[2][]=$number;
}
echo count($b[1])." ";
foreach($b[1] as $number) {
    echo $number." ";
}
echo "\r\n".count($b[2])." ";
foreach($b[2] as $number) {
    echo $number." ";
}
echo "\r\n".count($b[3])." ";
foreach($b[3] as $number) {
    echo $number." ";
}
?>


The Smart Beaver from ABBYY loves puzzles. One of his favorite puzzles is the magic square. He has recently had an idea to automate the solution of this puzzle. The Beaver decided to offer this challenge to the ABBYY Cup contestants.The magic square is a matrix of size n × n. The elements of this matrix are integers. The sum of numbers in each row of the matrix is equal to some number s. The sum of numbers in each column of the matrix is also equal to s. In addition, the sum of the elements on the main diagonal is equal to s and the sum of elements on the secondary diagonal is equal to s. Examples of magic squares are given in the following figure:   Magic squares  You are given a set of n2 integers ai. It is required to place these numbers into a square matrix of size n × n so that they form a magic square. Note that each number must occur in the matrix exactly the same number of times as it occurs in the original set.It is guaranteed that a solution exists!

The first input line contains a single integer n. The next line contains n2 integers ai ( - 108 ≤ ai ≤ 108), separated by single spaces. The input limitations for getting 20 points are:    1 ≤ n ≤ 3  The input limitations for getting 50 points are:    1 ≤ n ≤ 4  It is guaranteed that there are no more than 9 distinct numbers among ai.  The input limitations for getting 100 points are:    1 ≤ n ≤ 4

The first line of the output should contain a single integer s. In each of the following n lines print n integers, separated by spaces and describing the resulting magic square. In the resulting magic square the sums in the rows, columns and diagonals must be equal to s. If there are multiple solutions, you are allowed to print any of them.


Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.Sonya has drawn $$$n$$$ numbers in a row, $$$a_i$$$ is located in the $$$i$$$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.For example, if the numbers $$$[1, 5, 4, 1, 3]$$$ are written, and Sonya gives the number $$$1$$$ to the first robot and the number $$$4$$$ to the second one, the first robot will stop in the $$$1$$$-st position while the second one in the $$$3$$$-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $$$4$$$ to the first robot and the number $$$5$$$ to the second one, they will meet since the first robot will stop in the $$$3$$$-rd position while the second one is in the $$$2$$$-nd position.Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ($$$p$$$, $$$q$$$), where she will give $$$p$$$ to the first robot and $$$q$$$ to the second one. Pairs ($$$p_i$$$, $$$q_i$$$) and ($$$p_j$$$, $$$q_j$$$) are different if $$$p_i\neq p_j$$$ or $$$q_i\neq q_j$$$.Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.

The first line contains a single integer $$$n$$$ ($$$1\leq n\leq 10^5$$$) — the number of numbers in a row. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1\leq a_i\leq 10^5$$$) — the numbers in a row.

Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.


Squirrel Liss loves nuts. There are n trees (numbered 1 to n from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree i is hi. Liss wants to eat all nuts.Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the following actions:  Walk up or down one unit on a tree.  Eat a nut on the top of the current tree.  Jump to the next tree. In this action the height of Liss doesn't change. More formally, when Liss is at height h of the tree i (1 ≤ i ≤ n - 1), she jumps to height h of the tree i + 1. This action can't be performed if h > hi + 1. Compute the minimal time (in seconds) required to eat all nuts.

The first line contains an integer n (1  ≤  n ≤ 105) — the number of trees. Next n lines contains the height of trees: i-th line contains an integer hi (1 ≤ hi ≤ 104) — the height of the tree with the number i.

Print a single integer — the minimal time required to eat all nuts in seconds.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = array($b);
$e = array($b);
for($x = 1; $x < $a; $x++)
{
    $d = trim(fgets(STDIN));
    if($d == $c[$x - 1])
    {
        array_push($c, $d);
    }
    elseif($d < $c[$x - 1])
    {
        array_push($c, $d);
        array_push($e, $c[$x - 1] - $d);
    }
    elseif($d > $c[$x - 1])
    {
        array_push($c, $d);
        array_push($e, $d - $c[$x - 1]);
    }
}
print array_sum($e) + $a + $a - 1;
?>

<?php

function cin()
{
	$row = explode(" ", trim(fgets(STDIN)));
	return $row[0];
}
$n = cin();
$last = 0;
$ans = 2 * $n - 1;
for($i = 0; $i < $n; ++$i)
{
	$a[$i] = cin();
	$ans += abs($a[$i] - $last);
	$last = $a[$i];
}
echo $ans."\n";

?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = array($b);
$e = array($b);
for($x = 1; $x < $a; $x++)
{
    $d = trim(fgets(STDIN));
    if($d == $c[$x - 1])
    {
        array_push($d);
    }
    elseif($d > $c[$x - 1])
    {
        array_push($c, $d);
        array_push($e, $d - $c[$x - 1]);
    }
    elseif($d < $c[$x - 1])
    {
        array_push($c, $d);
        array_push($e, $c[$x - 1] - $d);
    }
}
print array_sum($e) + $a + $a - 1;
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = array($b);
for($x = 1; $x < $a; $x++)
{
    $d = trim(fgets(STDIN));
    if($d == $c[$x - 1])
    {
        array_push($c);
    }
    elseif($d > $c[$x - 1])
    {
        array_push($c, $d - $c[$x - 1]);
    }
    elseif($d < $c[$x - 1])
    {
        array_push($c, $c[$x - 1] - $d);
    }
}
print array_sum($c) + $a + $a - 1;
?>


A sequence of $$$n$$$ numbers is called permutation if it contains all numbers from $$$1$$$ to $$$n$$$ exactly once. For example, the sequences $$$[3, 1, 4, 2]$$$, [$$$1$$$] and $$$[2,1]$$$ are permutations, but $$$[1,2,1]$$$, $$$[0,1]$$$ and $$$[1,3,4]$$$ are not.For a given number $$$n$$$ you need to make a permutation $$$p$$$ such that two requirements are satisfied at the same time:  For each element $$$p_i$$$, at least one of its neighbors has a value that differs from the value of $$$p_i$$$ by one. That is, for each element $$$p_i$$$ ($$$1 \le i \le n$$$), at least one of its neighboring elements (standing to the left or right of $$$p_i$$$) must be $$$p_i + 1$$$, or $$$p_i - 1$$$.  the permutation must have no fixed points. That is, for every $$$i$$$ ($$$1 \le i \le n$$$), $$$p_i \neq i$$$ must be satisfied. Let's call the permutation that satisfies these requirements funny.For example, let $$$n = 4$$$. Then [$$$4, 3, 1, 2$$$] is a funny permutation, since:   to the right of $$$p_1=4$$$ is $$$p_2=p_1-1=4-1=3$$$;  to the left of $$$p_2=3$$$ is $$$p_1=p_2+1=3+1=4$$$;  to the right of $$$p_3=1$$$ is $$$p_4=p_3+1=1+1=2$$$;  to the left of $$$p_4=2$$$ is $$$p_3=p_4-1=2-1=1$$$.  for all $$$i$$$ is $$$p_i \ne i$$$. For a given positive integer $$$n$$$, output any funny permutation of length $$$n$$$, or output -1 if funny permutation of length $$$n$$$ does not exist.

The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows. Each test case consists of f single line containing one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print on a separate line:    any funny permutation $$$p$$$ of length $$$n$$$;  or the number -1 if the permutation you are looking for does not exist.

NoteThe first test case is explained in the problem statement.In the second test case, it is not possible to make the required permutation: permutations $$$[1, 2, 3]$$$, $$$[1, 3, 2]$$$, $$$[2, 1, 3]$$$, $$$[3, 2, 1]$$$ have fixed points, and in $$$[2, 3, 1]$$$ and $$$[3, 1, 2]$$$ the first condition is met not for all positions.

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   if($n == 3) {
        $ans = -1;
   } elseif($n == 1) {
        $ans = '1';
   } else {
        $ans = '';
        $temp = $n;
        $z = false;
        if($n == 5) {
            $ans = '5 4 1 2 3';
        } else {
           for($i=1; $i<= $n; $i++) {
             if($i == $temp ) {
                  $z = true;
                  $r = $temp -1;
                  $ans .= $r . ' ';
             } else {
                  if($z) {
                    $ans .= $temp + 1 . ' ';
                    $z = false;
                  } else {
                     $ans .= $temp . ' ';
                  }

             }
             $temp--;

        }
        }

   }
   IO::pr($ans);
}

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$n] = 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++){
    [$p] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    if($p==2){
        $ans[] = "2 1";
        continue;
    }
    if($p==3){
        $ans[] = -1;
        continue;
    }
    $str = "";
    for($j=$p-1;$j<=$p;$j++){
        $str .= $j." ";
    }
    for($j=1;$j<=$p-2;$j++){
        $str .= $j." ";
    }
    $ans[] = substr($str,0,strlen($str)-1);
}
echo implode(PHP_EOL,$ans);

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   if($n == 3 || $n==1) {
        $ans = -1;
   } else {
        $ans = '';
        $temp = $n;
        $z = false;
        for($i=1; $i<= $n; $i++) {
             if($i == $temp ) {
                  $z = true;
                  $r = $temp -1;
                  $ans .= $r . ' ';
             } else {
                  if($z) {
                    $ans .= $temp + 1 . ' ';
                    $z = false;
                  } else {
                     $ans .= $temp . ' ';
                  }

             }
             $temp--;

        }
   }
   IO::pr($ans);
}

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}


Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:  the final tournament features n teams (n is always even)  the first n / 2 teams (according to the standings) come through to the knockout stage  the standings are made on the following principle: for a victory a team gets 3 points, for a draw — 1 point, for a defeat — 0 points. In the first place, teams are ordered in the standings in decreasing order of their points; in the second place — in decreasing order of the difference between scored and missed goals; in the third place — in the decreasing order of scored goals  it's written in Berland's Constitution that the previous regulation helps to order the teams without ambiguity. You are asked to write a program that, by the given list of the competing teams and the results of all the matches, will find the list of teams that managed to get through to the knockout stage.

The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) / 2 lines describe the held matches in the format name1-name2 num1:num2, where name1, name2 — names of the teams; num1, num2 (0 ≤ num1, num2 ≤ 100) — amount of the goals, scored by the corresponding teams. Accuracy of the descriptions is guaranteed: there are no two team names coinciding accurate to the letters' case; there is no match, where a team plays with itself; each match is met in the descriptions only once.

Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.

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

$teams = array();
for ($i = 0; $i < $n; $i++) {
    $teams[g()] = array('score' => 0, 'diffr' => 0, 'goals' => 0);
}

$games = $n * ($n - 1) / 2;
for ($i = 0; $i < $games; $i++) {
    list($team, $score) = explode(' ', g());
    list($team1, $team2) = explode('-', $team);
    list($score1, $score2) = explode(':', $score);

    $teams[$team1]['score'] += $score1 > $score2 ? 3 : ($score1 == $score2 ? 1 : 0);
    $teams[$team1]['diffr'] += $score1 - $score2;
    $teams[$team1]['goals'] += $score1;

    $teams[$team2]['score'] += $score2 > $score1 ? 3 : ($score1 == $score2 ? 1 : 0);
    $teams[$team2]['diffr'] += $score2 - $score1;
    $teams[$team2]['goals'] += $score2;
}

$list = array_keys($teams);

$size = sizeof($list);
for($i = 0; $i < $size; $i++) {
    for($j = $i+1; $j < $size; $j++) {
        $team1 = $list[$i];
        $team2 = $list[$j];
        $score1 = $teams[$team1]['score'];
        $score2 = $teams[$team2]['score'];
        $diffr1 = $teams[$team1]['diffr'];
        $diffr2 = $teams[$team2]['diffr'];
        $goals1 = $teams[$team1]['goals'];
        $goals2 = $teams[$team2]['goals'];

        $swap = $score1 < $score2 || $score1 == $score2 && $diffr1 < $diffr2 || $score1 == $score2 && $diffr1 == $diffr2 && $goals1 < $goals2;
        if($swap) {
            $list[$i] = $team2;
            $list[$j] = $team1;
        }
    }
}

$off = $n / 2;
$play = array();
for($i = 0; $i < $off; $i++) {
    $play[] = $list[$i];
}

sort($play);

echo implode("\n", $play)

?>


You are given an array $$$a$$$ of $$$n$$$ integers. Initially there is only one copy of the given array.You can do operations of two types:  Choose any array and clone it. After that there is one more copy of the chosen array.  Swap two elements from any two copies (maybe in the same copy) on any positions. You need to find the minimal number of operations needed to obtain a copy where all elements are equal.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case output a single integer — the minimal number of operations needed to create at least one copy where all elements are equal.

NoteIn the first test case all elements in the array are already equal, that's why the answer is $$$0$$$.In the second test case it is possible to create a copy of the given array. After that there will be two identical arrays:$$$[ \ 0 \ 1 \ 3 \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ 0 \ 1 \ 3 \ 3 \ 7 \ 0 \ ]$$$After that we can swap elements in a way so all zeroes are in one array:$$$[ \ 0 \ \underline{0} \ \underline{0} \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ \underline{1} \ 1 \ 3 \ 3 \ 7 \ \underline{3} \ ]$$$Now let's create a copy of the first array:$$$[ \ 0 \ 0 \ 0 \ 3 \ 7 \ 0 \ ]$$$, $$$[ \ 0 \ 0 \ 0 \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ 1 \ 1 \ 3 \ 3 \ 7 \ 3 \ ]$$$Let's swap elements in the first two copies:$$$[ \ 0 \ 0 \ 0 \ \underline{0} \ \underline{0} \ 0 \ ]$$$, $$$[ \ \underline{3} \ \underline{7} \ 0 \ 3 \ 7 \ 0 \ ]$$$ and $$$[ \ 1 \ 1 \ 3 \ 3 \ 7 \ 3 \ ]$$$.Finally, we made a copy where all elements are equal and made $$$6$$$ operations.It can be proven that no fewer operations are enough.


Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.There are $$$n$$$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $$$i$$$-th position. Thus each of $$$n$$$ positions should contain exactly one flower: a rose or a lily.She knows that exactly $$$m$$$ people will visit this exhibition. The $$$i$$$-th visitor will visit all flowers from $$$l_i$$$ to $$$r_i$$$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies.Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\leq n, m\leq 10^3$$$) — the number of flowers and visitors respectively. Each of the next $$$m$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1\leq l_i\leq r_i\leq n$$$), meaning that $$$i$$$-th visitor will visit all flowers from $$$l_i$$$ to $$$r_i$$$ inclusive.

Print the string of $$$n$$$ characters. The $$$i$$$-th symbol should be «0» if you want to put a rose in the $$$i$$$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any.

NoteIn the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;  in the segment $$$[1\ldots3]$$$, there are one rose and two lilies, so the beauty is equal to $$$1\cdot 2=2$$$;  in the segment $$$[2\ldots4]$$$, there are one rose and two lilies, so the beauty is equal to $$$1\cdot 2=2$$$;  in the segment $$$[2\ldots5]$$$, there are two roses and two lilies, so the beauty is equal to $$$2\cdot 2=4$$$. The total beauty is equal to $$$2+2+4=8$$$.In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions;  in the segment $$$[5\ldots6]$$$, there are one rose and one lily, so the beauty is equal to $$$1\cdot 1=1$$$;  in the segment $$$[1\ldots4]$$$, there are two roses and two lilies, so the beauty is equal to $$$2\cdot 2=4$$$;  in the segment $$$[4\ldots6]$$$, there are two roses and one lily, so the beauty is equal to $$$2\cdot 1=2$$$. The total beauty is equal to $$$1+4+2=7$$$.

<?php

function main() {
    # I/O stream.
    define('INSTREAM', STDIN, FALSE);
    define('OUTSTREAM', STDOUT, FALSE);
    // define('INSTREAM', fopen("in.txt", "r"), FALSE);
    // define('OUTSTREAM', fopen("out.txt", "w"), FALSE);

    fscanf(INSTREAM, "%d %d", $n, $m);

    for($i = 0; $i < $m; ++$i) {
        fscanf(INSTREAM, "%*d %*d");
    }

    for($i = 0; $i < $n; ++$i) {
        echo ($i & 1)? '0' : '1';
    }

    echo "\n";
}

main();

?>

<?php
$dir                    = fopen("php://stdin", 'r');
$contents               = stream_get_contents($dir);
$inputs                 = explode("\n",$contents);
$flowersCount           = (int) explode(' ', $inputs[0])[0];
$visitorsCount          = (int) explode(' ', $inputs[0])[1];
getString($flowersCount, $visitorsCount);
function getString($flowersCount, $visitorsCount)
{
    $arr = [];
    for($i = 0; $i < $flowersCount; $i++)
    {
        if($i % 2 == 0)
        {
            $arr[] = 0;
        } else{
            $arr[] = 1;
        }
    }
    echo implode('',$arr);
}
?>


In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u > v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u > v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to:  $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$,  $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$,  $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$,  $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$,  $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$,  $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.

The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).

Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.

NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.


Today at the lesson of mathematics, Petya learns about the digital root.The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached. Let's denote the digital root of $$$x$$$ as $$$S(x)$$$. Then $$$S(5)=5$$$, $$$S(38)=S(3+8=11)=S(1+1=2)=2$$$, $$$S(10)=S(1+0=1)=1$$$.As a homework Petya got $$$n$$$ tasks of the form: find $$$k$$$-th positive number whose digital root is $$$x$$$.Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all $$$n$$$ tasks from Petya's homework.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$) — the number of tasks in Petya's homework. The next $$$n$$$ lines contain two integers $$$k_i$$$ ($$$1 \le k_i \le 10^{12}$$$) and $$$x_i$$$ ($$$1 \le x_i \le 9$$$) — $$$i$$$-th Petya's task in which you need to find a $$$k_i$$$-th positive number, the digital root of which is $$$x_i$$$.

Output $$$n$$$ lines, $$$i$$$-th line should contain a single integer — the answer to the $$$i$$$-th problem.

<?php
$a = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = ($b - 1) * 9 + $c;
     printf("%.0f", $d);
     print "\n";
}
?>


There are $$$n$$$ participants in a competition, participant $$$i$$$ having a strength of $$$s_i$$$. Every participant wonders how much of an advantage they have over the other best participant. In other words, each participant $$$i$$$ wants to know the difference between $$$s_i$$$ and $$$s_j$$$, where $$$j$$$ is the strongest participant in the competition, not counting $$$i$$$ (a difference can be negative).So, they ask you for your help! For each $$$i$$$ ($$$1 \leq i \leq n$$$) output the difference between $$$s_i$$$ and the maximum strength of any participant other than participant $$$i$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The descriptions of the test cases follow. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2\cdot10^5$$$) — the length of the array. The following line contains $$$n$$$ space-separated positive integers $$$s_1$$$, $$$s_2$$$, ..., $$$s_n$$$ ($$$1 \leq s_i \leq 10^9$$$) — the strengths of the participants. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, output $$$n$$$ space-separated integers. For each $$$i$$$ ($$$1 \leq i \leq n$$$) output the difference between $$$s_i$$$ and the maximum strength of any other participant.

NoteFor the first test case: The first participant has a strength of $$$4$$$ and the largest strength of a participant different from the first one is $$$7$$$, so the answer for the first participant is $$$4 - 7 = -3$$$.  The second participant has a strength of $$$7$$$ and the largest strength of a participant different from the second one is $$$5$$$, so the answer for the second participant is $$$7 - 5 = 2$$$. The third participant has a strength of $$$3$$$ and the largest strength of a participant different from the third one is $$$7$$$, so the answer for the third participant is $$$3 - 7 = -4$$$. The fourth participant has a strength of $$$5$$$ and the largest strength of a participant different from the fourth one is $$$7$$$, so the answer for the fourth participant is $$$5 - 7 = -2$$$.

<?php
$t = trim(fgets(STDIN));
for ($t1=1; $t1<=$t; $t1++) {
    $n =  trim(fgets(STDIN));
    $a =  explode(' ', trim(fgets(STDIN)));

    $iMax = max($a);
    $newArr = [];
    $aCach = [];
    for ($i = 0; $i < $n; $i++) {
        $iNum = $a[$i];
        unset($a[$i]);

        if (isset($aCach[$iNum])) {
            $newArr[$i] = $aCach[$iNum];
        } else {
            if ($iMax == $iNum) {
                $iMax2 = max($a);
                $newArr[$i] = $iNum - $iMax2;
            } else {
                $newArr[$i] = $iNum - $iMax;
            }
        }

        $a[$i] = $iNum;
        $aCach[$iNum] = $newArr[$i];
    }

    echo implode(' ', $newArr) . PHP_EOL;
}

<?php
$t = trim(fgets(STDIN));
for($i=0; $i <$t; $i++) {
    $n =  trim(fgets(STDIN));
	$a =  explode(' ', trim(fgets(STDIN)));
    $max = max($a);
    $copyArr = $a;
    sort($copyArr);
    $max2 = $copyArr[sizeof($copyArr)-2];
    for($j = 0; $j < $n; $j++){
            if ($a[$j] == $max)
            {
                $diff = $max - $max2;
            } else {
                $diff = $a[$j] - $max;
            }
        echo $diff . " ";
    }
    echo "\n";
}

<?php

$tests = getLineInt();

for ($test = 0; $test < $tests; $test++)
{
    $n = getLineInt();

    $s = getLineInts();

    $result = array();

    list($max1, $max2) = max2($s);

    for ($index = 0; $index < $n; $index++)
    {
        $result[] = $s[$index] - ($s[$index] < $max1 ? $max1 : $max2);
    }

    echo(implode(' ', $result) . PHP_EOL);
}

// Helpers

function getLineInt()
{
    return (int) trim(fgets(STDIN));
}

function getLineInts()
{
    return array_map("intval", explode(' ', trim(fgets(STDIN))));
}

function getLine()
{
    return trim(fgets(STDIN));
}

function getLineWords()
{
    return explode(' ', trim(fgets(STDIN)));
}

function max2(array $array)
{
    $max1 = $max2 = 0;

    for ($index = 0; $index < count($array); $index++)
    {
        if ($array[$index] > $max1)
        {
            $max2 = $max1;
            $max1 = $array[$index];
        }

        else if ($array[$index] > $max2)
        {
            $max2 = $array[$index];
        }
    }

    return array($max1, $max2);
}

<?php

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    $n = getLineInt();

    $s = getLineInts();

    list($max1, $max2) = max2($s);

    for ($index = 0; $index < $n; $index++)
    {
        $results[$test][] = $s[$index] - ($s[$index] < $max1 ? $max1 : $max2);
    }

    $results[$test] = implode(' ', $results[$test]);
}

echo(implode(PHP_EOL, $results));

// Helpers

function getLineInt()
{
    return (int) trim(fgets(STDIN));
}

function getLineInts()
{
    return array_map("intval", explode(' ', trim(fgets(STDIN))));
}

function getLine()
{
    return trim(fgets(STDIN));
}

function getLineWords()
{
    return explode(' ', trim(fgets(STDIN)));
}

function max2(array $array)
{
    $max1 = $max2 = 0;

    for ($index = 0; $index < count($array); $index++)
    {
        if ($array[$index] > $max1)
        {
            $max2 = $max1;
            $max1 = $array[$index];
        }

        else if ($array[$index] > $max2)
        {
            $max2 = $array[$index];
        }
    }

    return array($max1, $max2);
}

<?php
$iter = InOutPut::get();

for($i=0; $i <$iter; $i++) {
    $iterA = InOutPut::get();
    $arr = InOutPut::getArr();
    $max = max($arr);
    $copyArr = $arr;
    sort($copyArr);
    $max2 = $copyArr[sizeof($copyArr)-2];
    for($j = 0; $j < $iterA; $j++){
            if ($arr[$j] == $max)
            {
                $diff = $max - $max2;
            } else {
                $diff = $arr[$j] - $max;
            }
        echo $diff . " ";
    }
    echo "\n";
}

class InOutPut {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArr()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function print($string)
    {
        echo $string . "\n";
    }
}
?>

<?php
$t = trim(fgets(STDIN));
for ($t1=1; $t1<=$t; $t1++) {
    $n =  trim(fgets(STDIN));
    $a =  explode(' ', trim(fgets(STDIN)));

    $iMax = max($a);
    $newArr = [];
    $aCach = [];
    for ($i = 0; $i < $n; $i++) {
        $iNum = $a[$i];
        unset($a[$i]);

        if (isset($aCach[$iNum])) {
            $newArr[$i] = $aCach[$iNum];
        } else {
            if ($iMax == $iNum) {
                $iMax2 = max($a);
                $newArr[$i] = $iNum - $iMax2;
            } else {
                $newArr[$i] = $iNum - $iMax;
            }
        }

        $a[$i] = $iNum;
        $aCach[$iNum] = $iNum;
    }

    echo implode(' ', $newArr) . PHP_EOL;
}

<?php
$t = trim(fgets(STDIN));
for($i=0; $i <$iter; $i++) {
    $n =  trim(fgets(STDIN));
	$a =  explode(' ', trim(fgets(STDIN)));
    $max = max($a);
    $copyArr = $a;
    sort($copyArr);
    $max2 = $copyArr[sizeof($copyArr)-2];
    for($j = 0; $j < $n; $j++){
            if ($a[$j] == $max)
            {
                $diff = $max - $max2;
            } else {
                $diff = $a[$j] - $max;
            }
        echo $diff . " ";
    }
    echo "\n";
}


In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced.

The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.

Print the k-th pronounced identifier (assume that the numeration starts from 1).

NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.

<?php
list($n,$k)=explode(' ',trim(fgets(STDIN)));
$A=explode(' ',trim(fgets(STDIN)));
for ($i=1;$i<=$n;$i++){
	if ($k<=$i){
		echo $A[$k-1];
		return;
	} else $k-=$i;
}
?>


You have a garland consisting of $$$n$$$ lamps. Each lamp is colored red, green or blue. The color of the $$$i$$$-th lamp is $$$s_i$$$ ('R', 'G' and 'B' — colors of lamps in the garland).You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $$$1$$$) have distinct colors.In other words, if the obtained garland is $$$t$$$ then for each $$$i$$$ from $$$1$$$ to $$$n-1$$$ the condition $$$t_i \ne t_{i + 1}$$$ should be satisfied.Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of lamps. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ characters 'R', 'G' and 'B' — colors of lamps in the garland.

In the first line of the output print one integer $$$r$$$ — the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $$$t$$$ of length $$$n$$$ — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $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 */

$n = $ir->readInt();
$s = $ir->readString();
$not = [
	'R' => 'G',
	'G' => 'B',
	'B' => 'R',
	'R.R' => 'G',
	'G.G' => 'B',
	'B.B' => 'R',
	'R.G' => 'B',
	'G.R' => 'B',
	'G.B' => 'R',
	'B.G' => 'R',
	'R.B' => 'G',
	'B.R' => 'G',
];

$cnt = 0;
$s = $s . $not[$s[$n-1]];
for ($i=1; $i<$n; $i++) {
	if ($s[$i]==$s[$i-1]) {
		$cnt++;
		$s[$i] = $not[$s[$i] .'.'. $s[$i+1]];
	}
}

echo $cnt."\n";
echo substr($s, 0, $n);


Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health points and an attack power of a2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.Vova's character has h1 health points and an attack power of a1. Also he has a large supply of healing potions, each of which increases his current amount of health points by c1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that c1 > a2.The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a1) or drink a healing potion (it increases Vova's health by c1; Vova's health can exceed h1). Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a2. The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's attack.Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win.

The first line contains three integers h1, a1, c1 (1 ≤ h1, a1 ≤ 100, 2 ≤ c1 ≤ 100) — Vova's health, Vova's attack power and the healing power of a potion. The second line contains two integers h2, a2 (1 ≤ h2 ≤ 100, 1 ≤ a2 < c1) — the Modcrab's health and his attack power.

In the first line print one integer n denoting the minimum number of phases required to win the battle. Then print n lines. i-th line must be equal to HEAL if Vova drinks a potion in i-th phase, or STRIKE if he attacks the Modcrab. The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after Vova's last action. If there are multiple optimal solutions, print any of them.

NoteIn the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win.In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = ceil($d / $b);
$g = $c - $e;
$h = 0;
while(TRUE)
{
     $i = ceil($a / $e);
     if($i >= $f)
     {
          break;
     }
     else
     {
          $a += $g;
          $h++;
     }
}
print ($f + $h) . "\n";
for($x = 0; $x < $h; $x++)
{
     print "HEAL\n";
}
for($x = 0; $x < $f; $x++)
{
     print "STRIKE\n";
}
?>

<?php

list($h1, $a1, $c1) = explode(' ', trim(fgets(STDIN)));
list($h2, $a2) = explode(' ', trim(fgets(STDIN)));

$action_list = [];
while (true)
{
	if ($h1 - $a2 <= 0 && ($h2 - $a1) > 0)
	{
		$h1 += $c1;
		$action_list[] = 'HEAL';
	}
	else
	{
		$h2 -= $a1;
		$action_list[] = 'STRIKE';
	}

	if ($h2 <= 0)
	{
		break;
	}
	$h1 -= $a2;
}

echo count($action_list).PHP_EOL;
foreach ($action_list as $action)
{
	echo $action.PHP_EOL;
}

<?php

list($h1,$a1,$c1) = explode(" ",trim(fgets(STDIN)));
list($h2,$a2) = explode(" ",trim(fgets(STDIN)));

$liparitBagvashi = "";
$demnaUfliswuli = 0;

while($h2>0){
    $demnaUfliswuli++;

    if($h2-$a1<=0){
        $liparitBagvashi .= "STRIKE"."\n";
        $h2-=$a1;
    }

    elseif($h1 - $a2 > 0){
        $liparitBagvashi .= "STRIKE"."\n";
        $h2-=$a1;
    }

    else{
        $liparitBagvashi .= "HEAL"."\n";
        $h1+=$c1;
    }
    $h1-=$a2;
}

echo $demnaUfliswuli."\n".$liparitBagvashi;

?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = array();
while(TRUE)
{
     $g = $a - $e;
     $h = $d - $b;
     if($g <= 0)
     {
          $a += $c;
          $f[count($f)] = "HEAL";
     }
     else
     {
          $a -= $e;
          $d -= $b;
          if($h <= 0)
          {
               $f[count($f)] = "STRIKE";
               break;
          }
          else
          {
               $f[count($f)] = "STRIKE";
          }
     }
}
print count($f) . "\n";
for($x = 0; $x < count($f); $x++)
{
     print $f[$x] . "\n";
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = array();
while(TRUE)
{
     $g = $d - $b;
     $h = $a - $e;
     if($h <= 0)
     {
          $a += $c;
          $f[count($f)] = "HEAL";
     }
     elseif($h > 0)
     {
          $a -= $e;
          if($g <= 0)
          {
               $f[count($f)] = "STRIKE";
               break;
          }
          else
          {
               $d -= $b;
               $f[count($f)] = "STRIKE";
          }
     }
}
print count($f) . "\n";
for($x = 0; $x < count($f); $x++)
{
     print $f[$x] . "\n";
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = array();
while(TRUE)
{
     $g = $d - $b;
     $h = $a - $e;
     if($h <= 0)
     {
          if($g <= 0)
          {
               $f[count($f)] = "STRIKE";
               break;
          }
          else
          {
               $a += $c;
               $f[count($f)] = "HEAL";
          }
     }
     elseif($h > 0)
     {
          $a -= $e;
          if($g <= 0)
          {
               $f[count($f)] = "STRIKE";
               break;
          }
          else
          {
               $d -= $b;
               $f[count($f)] = "STRIKE";
          }
     }
}
print count($f) . "\n";
for($x = 0; $x < count($f); $x++)
{
     print $f[$x] . "\n";
}
?>

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = array();
while(TRUE)
{
     $g = $d - $b;
     $h = $a - $e;
     if($g <= 0)
     {
          $f[count($f)] = "STRIKE";
          break;
     }
     elseif($g > 0)
     {
          $d -= $b;
          $f[count($f)] = "STRIKE";
     }
     if($h <= 0)
     {
          $a += $c;
          $f[count($f)] = "HEAL";
     }
     elseif($h > 0)
     {
          $a -= $e;
     }
}
print count($f) . "\n";
for($x = 0; $x < count($f); $x++)
{
     print $f[$x] . "\n";
}
?>

<?php

list($h1, $a1, $c1) = explode(' ', trim(fgets(STDIN)));
list($h2, $a2) = explode(' ', trim(fgets(STDIN)));

$action_list = [];
while (true)
{
	if ($h1 - $a2 <= 0)
	{
		$h1 += $c1;
		$action_list[] = 'HEAL';
	}
	else
	{
		$h2 -= $a1;
		$action_list[] = 'STRIKE';
	}

	if ($h2 <= 0)
	{
		break;
	}
	$h1 -= $a2;
}

echo count($action_list).PHP_EOL;
foreach ($action_list as $action)
{
	echo $action.PHP_EOL;
}

<?php

//while coding listening to this => https://youtu.be/ZenkI6QvosE
//ჩამოთოვა ისევ მამუკა ჩარკვიანი

list($h1,$a1,$c1) = explode(" ",trim(fgets(STDIN)));
list($h2,$a2) = explode(" ",trim(fgets(STDIN)));

$liparitBagvashi = "";
$demnaUfliswuli = 0;

while($h2>0){
    $demnaUfliswuli++;

    if($h2-$a1<0){
        $liparitBagvashi .= "STRIKE"."\n";
        $h2-=$a1;
    }

    elseif($h1 - $a2 > 0){
        $liparitBagvashi .= "STRIKE"."\n";
        $h2-=$a1;
    }

    else{
        $liparitBagvashi .= "HEAL"."\n";
        $h1+=$c1;
    }
    $h1-=$a2;
}

echo $demnaUfliswuli."\n".$liparitBagvashi;

?>