After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received a Safety Studies marks and b PE marks (a + b = n). Now Polycarp wants to write a subject's name in front of each mark so that:   there are exactly a Safety Studies marks,  there are exactly b PE marks,  the total average score in both subjects is maximum. An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the x1 + x2, where x1 is the average score in the first subject (Safety Studies), and x2 is the average score in the second one (Physical Education).

The first line contains an integer n (2 ≤ n ≤ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 ≤ a, b ≤ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 5), they are Polycarp's marks.

Print the sequence of integers f1, f2, ..., fn, where fi (1 ≤ fi ≤ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically. The sequence p1, p2, ..., pn is lexicographically less than q1, q2, ..., qn if there exists such j (1 ≤ j ≤ n) that pi = qi for all 1 ≤ i < j, аnd pj < qj.

NoteIn the first sample the average score in the first subject is equal to 4, and in the second one — to 4.5. The total average score is 8.5.


Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible. Help Petya to split the integers. Each of n integers should be exactly in one group.

The first line contains a single integer n (2 ≤ n ≤ 60 000) — the number of integers Petya has.

Print the smallest possible absolute difference in the first line. In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.

NoteIn the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.

<?php

$n = (int)trim(fgets(STDIN));
$div_n = $n % 4;

$sum1 = 0;
$sum2 = 0;
$res_list = [];

foreach (range($n, 1) as $value)
{
	if ($sum1 <= $sum2)
	{
		$sum1 += $value;
		$res_list[] = $value;
	}
	else
	{
		$sum2 += $value;
	}
}

echo abs($sum1 - $sum2).PHP_EOL;
echo count($res_list).' '.implode(' ', array_reverse($res_list));


Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.Little Tommy has n lanterns and Big Banban has m lanterns. Tommy's lanterns have brightness a1, a2, ..., an, and Banban's have brightness b1, b2, ..., bm respectively.Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.You are asked to find the brightness of the chosen pair if both of them choose optimally.

The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 50). The second line contains n space-separated integers a1, a2, ..., an. The third line contains m space-separated integers b1, b2, ..., bm. All the integers range from  - 109 to 109.

Print a single integer — the brightness of the chosen pair.

NoteIn the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.

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

    $a = maxPro($a, $b);
    print maxPro($a, $b, true);

    function maxPro($a, $b, $bool = false) {
        $aMax = array();
        $aMax[] = bcmul(max($a), max($b));
        $aMax[] = bcmul(max($a), min($b));
        $aMax[] = bcmul(min($a), max($b));
        $aMax[] = bcmul(min($a), min($b));
        if ($bool) {
            return max($aMax);
        }

        $key = array_search(max($aMax), $aMax);
        if ($key == 0 || $key == 1) {
            $key2 = array_search(max($a), $a);
            unset($a[$key2]);
            return $a;
        } else {
            $key3 = array_search(min($a), $a);
            unset($a[$key3]);
            return $a;
        }
    }

?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
sort($d);
$e = $c[count($c) - 2];
$f = $e * $d[count($d) - 1];
$g = $c[1];
$h = $g * $d[0];
$i = abs($h);
if($f >= $i)
{
     printf("%.0f", $f);
}
else
{
     printf("%.0f", $h);
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
sort($d);
$e = $c[count($c) - 2];
$f = $e * $d[count($d) - 1];
$g = $c[1];
$h = $g * $d[0];
$i = max($f, $h);
printf("%.0f", $i);
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
sort($d);
$e = $c[count($c) - 2];
$f = $e * $d[count($d) - 1];
$g = $c[1];
$h = $g * $d[0];
print max($f, $h);
?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));
    echo count($a);
    $max = max($a);
    $maxb = max($b);
    if ($max < 0) {
        $min = min($a);
        $minb = min($b);
        foreach($a AS $k=> $v) {
            if ($min == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo min($a) * min($b);
    } else {
        foreach($a AS $k=> $v) {
            if ($max == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo max($a) * max($b);
    }

?>

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

    $max = max($a);
    $maxb = max($b);
    if ($max < 0) {
        $min = min($a);
        $minb = min($b);
        foreach($a AS $k=> $v) {
            if ($min == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo min($a) * min($b);
    } else {
        foreach($a AS $k=> $v) {
            if ($max == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo max($a) * max($b);
    }

?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));
    $max = max($a);
    $maxb = max($b);
    if ($max < 0 && $maxb < 0) {
        $min = min($a);
        $minb = min($b);
        foreach($a AS $k=> $v) {
            if ($min == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo min($a) * min($b);
    } else {
        foreach($a AS $k=> $v) {
            if ($max == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo max($a) * max($b);
    }

?>

<?php
    list($n, $m) = explode(' ', trim(fgets(STDIN)));
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));
    $max = max($a);
    foreach($a AS $k=> $v) {
        if ($max == $v) {
            unset($a[$k]);
        }
    }
    echo max($a) * max($b);
?>

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

    $maxa = max($a);
    $maxb = max($b);
    $mina = min($a);
    $minb = min($b);

    if ($maxa*$maxb > $mina*$minb ) {
        foreach($a AS $k=> $v) {
            if ($maxa == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo max($a) * max($b);
    } else {
        foreach($a AS $k=> $v) {
            if ($mina == $v) {
                unset($a[$k]);
                break;
            }
        }
        echo min($a) * min($b);
    }

?>

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

    $a = maxPro($a, $b);
    echo maxPro($a, $b, true);

    function maxPro($a, $b, $bool = false) {
        $aMax = array();
        $aMax[] = max($a) * max($b);
        $aMax[] = max($a) * min($b);
        $aMax[] = min($a) * max($b);
        $aMax[] = min($a) * min($b);
        if ($bool) {
            return (int)max($aMax);
        }

        $key = array_search(max($aMax), $aMax);
        if ($key == 0 || $key == 1) {
            $key2 = array_search(max($a), $a);
            unset($a[$key2]);
            return $a;
        } else {
            $key3 = array_search(min($a), $a);
            unset($a[$key3]);
            return $a;
        }
    }

?>

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

    $a = maxPro($a, $b);
    echo maxPro($a, $b, true);

    function maxPro($a, $b, $bool = false) {
        $aMax = array();
        $aMax[] = max($a) * max($b);
        $aMax[] = max($a) * min($b);
        $aMax[] = min($a) * max($b);
        $aMax[] = min($a) * min($b);
        if ($bool) {
            return max($aMax);
        }

        $key = array_search(max($aMax), $aMax);
        if ($key == 0 || $key == 1) {
            $key2 = array_search(max($a), $a);
            unset($a[$key2]);
            return $a;
        } else {
            $key3 = array_search(min($a), $a);
            unset($a[$key3]);
            return $a;
        }
    }

?>

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

    $a = maxPro($a, $b);
    print maxPro($a, $b, true);

    function maxPro($a, $b, $bool = false) {
        $aMax = array();
        $aMax[] = max($a) * max($b);
        $aMax[] = max($a) * min($b);
        $aMax[] = min($a) * max($b);
        $aMax[] = min($a) * min($b);
        if ($bool) {
            return max($aMax);
        }

        $key = array_search(max($aMax), $aMax);
        if ($key == 0 || $key == 1) {
            $key2 = array_search(max($a), $a);
            unset($a[$key2]);
            return $a;
        } else {
            $key3 = array_search(min($a), $a);
            unset($a[$key3]);
            return $a;
        }
    }

?>

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

    $a = maxPro($a, $b);
    echo maxPro($a, $b, true);

    function maxPro($a, $b, $bool = false) {
        $aMax = array();
        $aMax[] = max($a) * max($b);
        $aMax[] = max($a) * min($b);
        $aMax[] = min($a) * max($b);
        $aMax[] = min($a) * min($b);
        if ($bool) {
            return ceil(max($aMax));
        }

        $key = array_search(max($aMax), $aMax);
        if ($key == 0 || $key == 1) {
            $key2 = array_search(max($a), $a);
            unset($a[$key2]);
            return $a;
        } else {
            $key3 = array_search(min($a), $a);
            unset($a[$key3]);
            return $a;
        }
    }

?>

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

    $maxa = max($a);
    $maxb = max($b);
    $mina = min($a);
    $minb = min($b);

    if ($maxa*$maxb > $mina*$minb ) {
        foreach($a AS $k=> $v) {
            if ($maxa == $v) {
                unset($a[$k]);
                break;
            }
        }
        $i = max($a) * max($b);
        echo (string)$i;
    } else {
        foreach($a AS $k=> $v) {
            if ($mina == $v) {
                unset($a[$k]);
                break;
            }
        }
        $i = min($a) * min($b);
        echo (string)$i;
    }

?>


In this task you need to process a set of stock exchange orders and use them to create order book.An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price pi, direction di — buy or sell, and integer qi. This means that the participant is ready to buy or sell qi stocks at price pi for one stock. A value qi is also known as a volume of an order.All orders with the same price p and direction d are merged into one aggregated order with price p and direction d. The volume of such order is a sum of volumes of the initial orders.An order book is a list of aggregated orders, the first part of which contains sell orders sorted by price in descending order, the second contains buy orders also sorted by price in descending order.An order book of depth s contains s best aggregated orders for each direction. A buy order is better if it has higher price and a sell order is better if it has lower price. If there are less than s aggregated orders for some direction then all of them will be in the final order book.You are given n stock exhange orders. Your task is to print order book of depth s for these orders.

The input starts with two positive integers n and s (1 ≤ n ≤ 1000, 1 ≤ s ≤ 50), the number of orders and the book depth. Next n lines contains a letter di (either 'B' or 'S'), an integer pi (0 ≤ pi ≤ 105) and an integer qi (1 ≤ qi ≤ 104) — direction, price and volume respectively. The letter 'B' means buy, 'S' means sell. The price of any sell order is higher than the price of any buy order.

Print no more than 2s lines with aggregated orders from order book of depth s. The output format for orders should be the same as in input.

NoteDenote (x, y) an order with price x and volume y. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample.You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders.

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($ordersT, $s) = explode(" ", trim(fgets($file)));
$bArray = array();
$sArray = array();
for ($i = 1 ; $i<=$ordersT; $i++) {
    list($t, $p, $q) = explode(" ", trim(fgets($file)));
    switch ($t) {
        case 'B':
            if (isset($bArray[$p])) {
                $bArray[$p] += $q;
            }else{
                $bArray[$p] = $q;
            }
            break;
        case 'S':
            if (isset($sArray[$p])) {
                $sArray[$p] += $q;
            }else{
                $sArray[$p] = $q;
            }
            break;
    }
}

krsort($bArray);
ksort($sArray);

$printed = 0;
$sP = array();
foreach ($sArray as $p => $q) {
    if ($printed < $s) {
        $sP[] = "S $p $q";
        $printed++;
    }
}
$sP = array_reverse($sP);
echo implode(PHP_EOL, $sP).PHP_EOL;

$printed = 0;
foreach ($bArray as $p => $q) {
    if ($printed < $s) {
        echo "B $p $q".PHP_EOL;
        $printed++;
    }
}


You have got a shelf and want to put some books on it.You are given $$$q$$$ queries of three types:  L $$$id$$$ — put a book having index $$$id$$$ on the shelf to the left from the leftmost existing book;  R $$$id$$$ — put a book having index $$$id$$$ on the shelf to the right from the rightmost existing book;  ? $$$id$$$ — calculate the minimum number of books you need to pop from the left or from the right in such a way that the book with index $$$id$$$ will be leftmost or rightmost. You can assume that the first book you will put can have any position (it does not matter) and queries of type $$$3$$$ are always valid (it is guaranteed that the book in each such query is already placed). You can also assume that you don't put the same book on the shelf twice, so $$$id$$$s don't repeat in queries of first two types.Your problem is to answer all the queries of type $$$3$$$ in order they appear in the input.Note that after answering the query of type $$$3$$$ all the books remain on the shelf and the relative order of books does not change.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ lines follow. The $$$i$$$-th line contains the $$$i$$$-th query in format as in the problem statement. It is guaranteed that queries are always valid (for query type $$$3$$$, it is guaranteed that the book in each such query is already placed, and for other types, it is guaranteed that the book was not placed before). It is guaranteed that there is at least one query of type $$$3$$$ in the input. In each query the constraint $$$1 \le id \le 2 \cdot 10^5$$$ is met.

Print answers to queries of the type $$$3$$$ in order they appear in the input.

NoteLet's take a look at the first example and let's consider queries:   The shelf will look like $$$[1]$$$;  The shelf will look like $$$[1, 2]$$$;  The shelf will look like $$$[1, 2, 3]$$$;  The shelf looks like $$$[1, \textbf{2}, 3]$$$ so the answer is $$$1$$$;  The shelf will look like $$$[4, 1, 2, 3]$$$;  The shelf looks like $$$[4, \textbf{1}, 2, 3]$$$ so the answer is $$$1$$$;  The shelf will look like $$$[5, 4, 1, 2, 3]$$$;  The shelf looks like $$$[5, 4, \textbf{1}, 2, 3]$$$ so the answer is $$$2$$$. Let's take a look at the second example and let's consider queries:   The shelf will look like $$$[100]$$$;  The shelf will look like $$$[100, 100000]$$$;  The shelf will look like $$$[100, 100000, 123]$$$;  The shelf will look like $$$[101, 100, 100000, 123]$$$;  The shelf looks like $$$[101, 100, 100000, \textbf{123}]$$$ so the answer is $$$0$$$;  The shelf will look like $$$[10, 101, 100, 100000, 123]$$$;  The shelf will look like $$$[10, 101, 100, 100000, 123, 115]$$$;  The shelf looks like $$$[10, 101, \textbf{100}, 100000, 123, 115]$$$ so the answer is $$$2$$$;  The shelf will look like $$$[10, 101, 100, 100000, 123, 115, 110]$$$;  The shelf looks like $$$[10, 101, 100, 100000, 123, \textbf{115}, 110]$$$ so the answer is $$$1$$$.

<?php
    $q = (int)fgets(STDIN);
    $i=0;
    $all = [];
    $res=[];

    $ind = 200000;
    $left = 200000;
    $right = 200000;

    while($i<$q) {
        $str = fgets(STDIN);

        $str = explode(' ', $str);
        $ch = (string)$str[0];
        $id = (int)$str[1];

        if ($i==0) {
            $all[$id]=$ind;
        } else {
            switch ($ch) {
                case 'L':
                    $left--;
                    $all[$id] = $left;
                    break;
                case 'R':
                    $right++;
                    $all[$id] = $right;
                    break;
                case '?':
                    //если всего одна книга на полке
                    if ($i == 1) {
                        $res[] = 0;
                        break;
                    }

                    $key = $all[$id];
                    $l = $key - $left;
                    $r = $right - $key;
                    $res[] = $l < $r ? $l : $r;

                    break;
            }
        }
        $i++;
    }

    foreach ($res as $r) {
        echo $r.'
';
    }
?>


You are given a permutation $$$p_1, p_2, \ldots, p_n$$$ of length $$$n$$$. You have to choose two integers $$$l,r$$$ ($$$1 \le l \le r \le n$$$) and reverse the subsegment $$$[l,r]$$$ of the permutation. The permutation will become $$$p_1,p_2, \dots, p_{l-1},p_r,p_{r-1}, \dots, p_l,p_{r+1},p_{r+2}, \dots ,p_n$$$.Find the lexicographically smallest permutation that can be obtained by performing exactly one reverse operation on the initial permutation.Note that for two distinct permutations of equal length $$$a$$$ and $$$b$$$, $$$a$$$ is lexicographically smaller than $$$b$$$ if at the first position they differ, $$$a$$$ has the smaller element.A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — 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 500$$$) — the length of the permutation. The second line of each test case contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$) — the elements of the permutation.

For each test case print the lexicographically smallest permutation you can obtain.

NoteIn the first test case, the permutation has length $$$1$$$, so the only possible segment is $$$[1,1]$$$. The resulting permutation is $$$[1]$$$.In the second test case, we can obtain the identity permutation by reversing the segment $$$[1,2]$$$. The resulting permutation is $$$[1,2,3]$$$.In the third test case, the best possible segment is $$$[2,3]$$$. The resulting permutation is $$$[1,2,4,3]$$$.In the fourth test case, there is no lexicographically smaller permutation, so we can leave it unchanged by choosing the segment $$$[1,1]$$$. The resulting permutation is $$$[1,2,3,4,5]$$$.

<?php
function inputInt($sys)
{
    fscanf($sys, "%d", $n);
    return $n;
}

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

$stdin = fopen('php://stdin', 'r');
$T = inputInt($stdin);
function solve($sys)
{
    $n = inputInt($sys);
    $arr = inputArray($sys);
    //print_r($arr);
    $start = -1;
    $end = -1;
    for ($i = 0; $i < $n; $i++) {
        if ($arr[$i] != $i + 1) {
            $start = $i;
            break;
        }
    }

    for ($i = $start; $i < $n; $i++) {
        if ($start != -1 && $arr[$i] == $start + 1) {
            $end = $i;
        }
    }
    $array = array();
    $toReverse = array();
    $toReverseFrom = min($start, $end);
    for ($i = 0; $i < $toReverseFrom; $i++) {
        $array[$i] = $arr[$i];
    }

    $reverseTo = max($start, $end);
    for ($i = $toReverseFrom; $i <= $reverseTo; $i++) {
        $array[$reverseTo - $i + $toReverseFrom] = $arr[$i];
    }
    //TODO: the input 1 1 3 is not output anything check for the probleme

    for ($i = $reverseTo + 1; $i < $n; $i++) {
        $array[$i] = $arr[$i];
    }
    for ($i = 0; $i < $n; $i++) {
        echo $array[$i] . " ";
    }
    echo "\n";
}
while ($T--) {
    solve($stdin);
}


One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.Your task is to write a program that will determine the required number of seconds t.

The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero. The numbers in the lines are separated by single spaces.

In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.

<?php
$lines  = @file("php://stdin");
$boxes_num = array_shift($lines);
$left_boxes_opened = 0;
$right_boxes_opened = 0;
$actions_num = 0;
foreach($lines  as $line ){
$box_state = explode(' ', $line);
$left_boxes_opened +=$box_state[0];
$right_boxes_opened +=$box_state[1];
}
if($right_boxes_opened > $boxes_num/2)
    $actions_num = $boxes_num - $right_boxes_opened;
else
    $actions_num = $right_boxes_opened;

if($left_boxes_opened > $boxes_num/2)
    $actions_num += $boxes_num - $left_boxes_opened;
else
    $actions_num += $left_boxes_opened;

echo $actions_num;

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

$count = fgets($f);

$leftOpen = 0;
$rightOpen = 0;

for ($i = 0; $i < $count; $i++) {
    $line = explode(" ", fgets($f));
    if ($line[0] > 0) $leftOpen += 1;
    if ($line[1] > 0) $rightOpen += 1;
}

$ans = 0;
if (($count/2) > $leftOpen) $ans += $leftOpen;
else $ans += $count-$leftOpen;
if (($count/2) > $rightOpen ) $ans += $rightOpen;
else $ans += $count-$rightOpen;

echo $ans;

<?
$a = trim(fgets(STDIN));
$ar = Array();
$br = Array();
for($i = 0; $i < $a; $i++){
    list($ar[], $br[]) = explode(' ', trim(fgets(STDIN)));
}
$x = array_sum($ar);
if($x == $a and $x == 0)
    $tmp1 = 0;
else
    if($x < $a/2)
        $tmp1 = $x;
    else
        $tmp1 = $a - $x;
$y = array_sum($br);
if($y == $a and $y == 0)
    $tmp2 = 0;
else
    if($y < $a/2)
        $tmp2 = $y;
    else
        $tmp2 = $a - $y;
echo $tmp1+$tmp2;

<?php
$lines  = @file("php://stdin");
$boxes_num = array_shift($lines);
$left_boxes_opened = 0;
$right_boxes_opened = 0;
$actions_num = 0;
foreach($lines  as $line ){
$box_state = explode(' ', $line);
$left_boxes_opened +=$box_state[0];
$right_boxes_opened +=$box_state[1];
}

if($right_boxes_opened > $left_boxes_opened){
    $actions_num = $boxes_num - $right_boxes_opened;
    $actions_num += $left_boxes_opened;
}
else{
    $actions_num = $boxes_num - $left_boxes_opened;
    $actions_num += $right_boxes_opened;
}

echo $actions_num;

<?
$a = trim(fgets(STDIN));
$ar = Array();
$br = Array();
for($i = 0; $i < $a; $i++){
    list($ar[], $br[]) = explode(' ', trim(fgets(STDIN)));
}
$tmp = array_sum(array_merge($ar, $br));
if($tmp <= $a){
    echo $tmp;
}else{
    echo $a*2-$tmp;
}

<?
$a = trim(fgets(STDIN));
$ar = Array();
$br = Array();
for($i = 0; $i < $a; $i++){
    list($ar[], $br[]) = explode(' ', trim(fgets(STDIN)));
}
$x1 = array_sum($ar);
$y1 = $a - array_sum($br);
$x2 = $a - array_sum($ar);
$y2 = array_sum($br);
echo min($x1+$y1,$y2+$x2);


Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.Your program has to support two operations:   Paint all cells in row ri in color ai;  Paint all cells in column ci in color ai. If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.Your program has to print the resulting table after k operation.

The first line of the input contains three integers n, m and k (1  ≤  n,  m  ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively. Each of the next k lines contains the description of exactly one query:    1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;  2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.

Print n lines containing m integers each — the resulting table after all operations are applied.

NoteThe figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.


The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect some of them.The Resistance already has measures in place that will, when the time is right, enable them to control every planet that is not remote. A planet is considered to be remote if it is connected to the rest of the planets only via a single hyperspace tunnel.How much work is there left to be done: that is, how many remote planets are there?

The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy. The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunnel between the planets u and v. It is guaranteed that every two planets are connected by a path of tunnels, and that each tunnel connects a different pair of planets.

A single integer denoting the number of remote planets.

NoteIn the first example, only planets 2, 3 and 5 are connected by a single tunnel.In the second example, the remote planets are 2 and 3.Note that this problem has only two versions – easy and medium.


The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has n observation binoculars located at the OX axis. For each i between 1 and n, inclusive, there exists a single binocular located at the point with coordinates (i, 0). There are m flamingos in the Zoo, located at points with positive coordinates. The flamingos are currently sleeping and you can assume that they don't move.In order to get a good view over the flamingos, each of the binoculars can be independently rotated to face any angle (not necessarily integer). Then, the binocular can be used to observe all flamingos that is located at the straight line passing through the binocular at the angle it is set. In other words, you can assign each binocular a direction corresponding to any straight line passing through the binocular, and the binocular will be able to see all flamingos located on that line.Today, some kids from the prestigious Codeforces kindergarten went on a Field Study to the Zoo. Their teacher would like to set each binocular an angle to maximize the number of flamingos that can be seen by the binocular. The teacher is very interested in the sum of these values over all binoculars. Please help him find this sum.

The first line contains two space-separated integers n and m (1 ≤ n ≤ 106, 1 ≤ m ≤ 250), denoting the number of binoculars and the number of flamingos, respectively. Then m lines follow, the i-th line will contain two space-separated integers xi and yi (1 ≤ xi, yi ≤ 109), which means that the i-th flamingo is located at point (xi, yi).  All flamingos will be located at distinct points.

Print a single integer denoting the maximum total number of flamingos that can be seen by all the binoculars.

NoteThis picture shows the answer to the example test case.


Stepan had a favorite string s which consisted of the lowercase letters of the Latin alphabet. After graduation, he decided to remember it, but it was a long time ago, so he can't now remember it. But Stepan remembers some information about the string, namely the sequence of integers c1, c2, ..., cn, where n equals the length of the string s, and ci equals the number of substrings in the string s with the length i, consisting of the same letters. The substring is a sequence of consecutive characters in the string s.For example, if the Stepan's favorite string is equal to "tttesst", the sequence c looks like: c = [7, 3, 1, 0, 0, 0, 0].Stepan asks you to help to repair his favorite string s according to the given sequence c1, c2, ..., cn.

The first line contains the integer n (1 ≤ n ≤ 2000) — the length of the Stepan's favorite string. The second line contains the sequence of integers c1, c2, ..., cn (0 ≤ ci ≤ 2000), where ci equals the number of substrings of the string s with the length i, consisting of the same letters. It is guaranteed that the input data is such that the answer always exists.

Print the repaired Stepan's favorite string. If there are several answers, it is allowed to print any of them. The string should contain only lowercase letters of the English alphabet.

NoteIn the first test Stepan's favorite string, for example, can be the string "kkrrrq", because it contains 6 substrings with the length 1, consisting of identical letters (they begin in positions 1, 2, 3, 4, 5 and 6), 3 substrings with the length 2, consisting of identical letters (they begin in positions 1, 3 and 4), and 1 substring with the length 3, consisting of identical letters (it begins in the position 3).


Burenka and Tonya are playing an old Buryat game with a chip on a board of $$$n \times m$$$ cells.At the beginning of the game, the chip is located in the lower left corner of the board. In one move, the player can move the chip to the right or up by any odd number of cells (but you cannot move the chip both to the right and up in one move). The one who cannot make a move loses.Burenka makes the first move, the players take turns. Burenka really wants to win the game, but she is too lazy to come up with a strategy, so you are invited to solve the difficult task of finding it. Name the winner of the game (it is believed that Burenka and Tonya are masters of playing with chips, so they always move in the optimal way).    Chip's starting cell is green, the only cell from which chip can't move is red. if the chip is in the yellow cell, then blue cells are all options to move the chip in one move.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The following is a description of the input data sets. The only line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^9$$$) — the dimensions of the game board.

For each test case print a single line — the name of the winner of the game ("Burenka" or "Tonya").

Tonya
Burenka
Burenka
Tonya
Burenka
Burenka

NoteIn the first case, Burenka has no move, so Tonya wins.In the second case, Burenka can move $$$3$$$ cells to the right, after which Tony will not be able to make a move, which means that Burenka wins.In the third case, Burenka can move $$$5$$$ squares to the right. Then we can say that we have a game on a board of $$$1 \times 5$$$ cells, and Tonya is the first player. In such game the second player wins, so in the original one Burenka will win.

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

$t;
fscanf($cin, "%d\n", $t);
for ($T = 0; $T < $t; $T++) {
    $x; $y;
    fscanf($cin, "%d %d\n", $x, $y);
    if ($x % 2 + $y % 2 != 1) fprintf($cout, "Tonya\n");
    else fprintf($cout, "Burenka\n");
} ?>

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

$t;
fscanf($cin, "%d\n", $t);
for ($T = 0; $T < $t; $T++) {
    $x; $y;
    fscanf($cin, "%d %d\n", $x, $y);
    if ($x == $y) fprintf($cout, "Tonya\n");
    else fprintf($cout, "Burenka\n");
} ?>


It is winter now, and Max decided it's about time he watered the garden.The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.  The garden from test 1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.   The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed. Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!

The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 200). Then t test cases follow. The first line of each test case contains two integers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n) — the number of garden beds and water taps, respectively. Next line contains k integers xi (1 ≤ xi ≤ n) — the location of i-th water tap. It is guaranteed that for each  condition xi - 1 < xi holds. It is guaranteed that the sum of n over all test cases doesn't exceed 200. Note that in hacks you have to set t = 1.

For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.

NoteThe first example consists of 3 tests:  There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.  There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.  There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.


There are $$$n$$$ segments $$$[l_i, r_i]$$$ for $$$1 \le i \le n$$$. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.To optimize testing process you will be given multitest.

The first line contains one integer $$$T$$$ ($$$1 \le T \le 50000$$$) — the number of queries. Each query contains description of the set of segments. Queries are independent. First line of each query contains single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — number of segments. It is guaranteed that $$$\sum{n}$$$ over all queries does not exceed $$$10^5$$$. The next $$$n$$$ lines contains two integers $$$l_i$$$, $$$r_i$$$ per line ($$$1 \le l_i \le r_i \le 2 \cdot 10^5$$$) — the $$$i$$$-th segment.

For each query print $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$t_i \in \{1, 2\}$$$) — for each segment (in the same order as in the input) $$$t_i$$$ equals $$$1$$$ if the $$$i$$$-th segment will belongs to the first group and $$$2$$$ otherwise. If there are multiple answers, you can print any of them. If there is no answer, print $$$-1$$$.

NoteIn the first query the first and the second segments should be in different groups, but exact numbers don't matter.In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is $$$-1$$$.In the third query we can distribute segments in any way that makes groups non-empty, so any answer of $$$6$$$ possible is correct.

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

$t = $ir->readInt();
for ($tt=0; $tt<$t; $tt++) {
	$n = $ir->readInt();
	$a = [];
	for ($nn=0; $nn<$n; $nn++) {
		$a[] = $ir->readArrayOfInt(2);
	}

	$b = array_fill(0, $n, 2);

	uasort($a, function($x, $y) { return $x[0]<=>$y[0];});

	reset($a);
	$x = current($a);
	//var_dump($a);
	$R = $x[1];
	reset($a);
	foreach ($a as $k=>$v){
		//echo "R = $R; checking {$v[0]} : {$v[1]}\n";
		if ($v[0]<=$R) {
			$R = max([$v[1], $R]);
			$b[$k] = 1;
		}
		else {
			echo implode(' ', $b)."\n";
			flush();
			continue 2;
		}
	}

	echo "-1\n";
	flush();
}


This is an hard version of the problem. The only difference between an easy and a hard version is the constraints on $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$.You are given $$$4$$$ positive integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ with $$$a < c$$$ and $$$b < d$$$. Find any pair of numbers $$$x$$$ and $$$y$$$ that satisfies the following conditions: $$$a < x \leq c$$$, $$$b < y \leq d$$$, $$$x \cdot y$$$ is divisible by $$$a \cdot b$$$.Note that required $$$x$$$ and $$$y$$$ may not exist.

The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10$$$), the number of test cases. The descriptions of the test cases follow. The only line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$1 \leq a < c \leq 10^9$$$, $$$1 \leq b < d \leq 10^9$$$).

For each test case print a pair of numbers $$$a < x \leq c$$$ and $$$b < y \leq d$$$ such that $$$x \cdot y$$$ is divisible by $$$a \cdot b$$$. If there are multiple answers, print any of them. If there is no such pair of numbers, then print -1 -1.


There is a grid with $$$n$$$ rows and $$$m$$$ columns. Some cells are colored black, and the rest of the cells are colored white.In one operation, you can select some black cell and do exactly one of the following:   color all cells in its row black, or  color all cells in its column black. You are given two integers $$$r$$$ and $$$c$$$. Find the minimum number of operations required to make the cell in row $$$r$$$ and column $$$c$$$ black, or determine that it is impossible.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains four integers $$$n$$$, $$$m$$$, $$$r$$$, and $$$c$$$ ($$$1 \leq n, m \leq 50$$$; $$$1 \leq r \leq n$$$; $$$1 \leq c \leq m$$$) — the number of rows and the number of columns in the grid, and the row and column of the cell you need to turn black, respectively. Then $$$n$$$ lines follow, each containing $$$m$$$ characters. Each of these characters is either 'B' or 'W' — a black and a white cell, respectively.

For each test case, if it is impossible to make the cell in row $$$r$$$ and column $$$c$$$ black, output $$$-1$$$.  Otherwise, output a single integer — the minimum number of operations required to make the cell in row $$$r$$$ and column $$$c$$$ black.

9

3 5 1 4

WBWWW

BBBWB

WWBBB

4 3 2 1

BWW

BBW

WBB

WWB

2 3 2 2

WWW

WWW

2 2 1 1

WW

WB

5 9 5 9

WWWWWWWWW

WBWBWBBBW

WBBBWWBWW

WBWBWBBBW

WWWWWWWWW

1 1 1 1

B

1 1 1 1

W

1 2 1 1

WB

2 1 1 1

W

B

NoteThe first test case is pictured below.  We can take the black cell in row $$$1$$$ and column $$$2$$$, and make all cells in its row black. Therefore, the cell in row $$$1$$$ and column $$$4$$$ will become black.  In the second test case, the cell in row $$$2$$$ and column $$$1$$$ is already black.In the third test case, it is impossible to make the cell in row $$$2$$$ and column $$$2$$$ black.The fourth test case is pictured below.  We can take the black cell in row $$$2$$$ and column $$$2$$$ and make its column black.   Then, we can take the black cell in row $$$1$$$ and column $$$2$$$ and make its row black.   Therefore, the cell in row $$$1$$$ and column $$$1$$$ will become black.

<?php

$ar = [];

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

for($q = 0; $q < $t; $q++)
{
  list($n, $m, $r, $c) = explode(' ', trim(fgets(STDIN)));

  for($i = 0; $i < $n; $i++)
  {
    $ar[$i] = str_split(trim(fgets(STDIN)));
  }

  // -1
  $hasBlack = false;

  for($row = 0; $row < $n; $row++)
  {
    if(in_array("B", $ar[$row]))
    {
      $hasBlack = true;
      break;
    }
  }

  if(!$hasBlack)
  {
    echo "-1\n";
    continue;
  }

  //0
  if($ar[$r - 1][$c - 1] === "B")
  {
    echo "0\n";
    continue;
  }

  if(in_array("B", $ar[$r - 1]))
  {
    echo "1\n";
    continue;
  }

  $in_column = false;
  for($row = 0; $row < $n; $row++)
  {
    if($ar[$row][$c - 1] === "B")
    {
      $in_column = true;
      break;
    }
  }

  if($in_column)
  {
    echo "1\n";
    continue;
  }

  echo "2\n";
}

?>


There are $$$n$$$ children numbered from $$$1$$$ to $$$n$$$ in a kindergarten. Kindergarten teacher gave $$$a_i$$$ ($$$1 \leq a_i \leq n$$$) candies to the $$$i$$$-th child. Children were seated in a row in order from $$$1$$$ to $$$n$$$ from left to right and started eating candies. While the $$$i$$$-th child was eating candies, he calculated two numbers $$$l_i$$$ and $$$r_i$$$ — the number of children seating to the left of him that got more candies than he and the number of children seating to the right of him that got more candies than he, respectively.Formally, $$$l_i$$$ is the number of indices $$$j$$$ ($$$1 \leq j < i$$$), such that $$$a_i < a_j$$$ and $$$r_i$$$ is the number of indices $$$j$$$ ($$$i < j \leq n$$$), such that $$$a_i < a_j$$$.Each child told to the kindergarten teacher the numbers $$$l_i$$$ and $$$r_i$$$ that he calculated. Unfortunately, she forgot how many candies she has given to each child. So, she asks you for help: given the arrays $$$l$$$ and $$$r$$$ determine whether she could have given the candies to the children such that all children correctly calculated their values $$$l_i$$$ and $$$r_i$$$, or some of them have definitely made a mistake. If it was possible, find any way how she could have done it.

On the first line there is a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of children in the kindergarten. On the next line there are $$$n$$$ integers $$$l_1, l_2, \ldots, l_n$$$ ($$$0 \leq l_i \leq n$$$), separated by spaces. On the next line, there are $$$n$$$ integer numbers $$$r_1, r_2, \ldots, r_n$$$ ($$$0 \leq r_i \leq n$$$), separated by spaces.

If there is no way to distribute the candies to the children so that all of them calculated their numbers correctly, print «NO» (without quotes). Otherwise, print «YES» (without quotes) on the first line. On the next line, print $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$, separated by spaces — the numbers of candies the children $$$1, 2, \ldots, n$$$ received, respectively. Note that some of these numbers can be equal, but all numbers should satisfy the condition $$$1 \leq a_i \leq n$$$. The number of children seating to the left of the $$$i$$$-th child that got more candies than he should be equal to $$$l_i$$$ and the number of children seating to the right of the $$$i$$$-th child that got more candies than he should be equal to $$$r_i$$$. If there is more than one solution, find any of them.

NoteIn the first example, if the teacher distributed $$$1$$$, $$$3$$$, $$$1$$$, $$$2$$$, $$$1$$$ candies to $$$1$$$-st, $$$2$$$-nd, $$$3$$$-rd, $$$4$$$-th, $$$5$$$-th child, respectively, then all the values calculated by the children are correct. For example, the $$$5$$$-th child was given $$$1$$$ candy, to the left of him $$$2$$$ children were given $$$1$$$ candy, $$$1$$$ child was given $$$2$$$ candies and $$$1$$$ child — $$$3$$$ candies, so there are $$$2$$$ children to the left of him that were given more candies than him.In the second example it is impossible to distribute the candies, because the $$$4$$$-th child made a mistake in calculating the value of $$$r_4$$$, because there are no children to the right of him, so $$$r_4$$$ should be equal to $$$0$$$.In the last example all children may have got the same number of candies, that's why all the numbers are $$$0$$$. Note that each child should receive at least one candy.


Everybody knows that the $$$m$$$-coder Tournament will happen soon. $$$m$$$ schools participate in the tournament, and only one student from each school participates.There are a total of $$$n$$$ students in those schools. Before the tournament, all students put their names and the names of their schools into the Technogoblet of Fire. After that, Technogoblet selects the strongest student from each school to participate. Arkady is a hacker who wants to have $$$k$$$ Chosen Ones selected by the Technogoblet. Unfortunately, not all of them are the strongest in their schools, but Arkady can make up some new school names and replace some names from Technogoblet with those. You can't use each made-up name more than once. In that case, Technogoblet would select the strongest student in those made-up schools too.You know the power of each student and schools they study in. Calculate the minimal number of schools Arkady has to make up so that $$$k$$$ Chosen Ones would be selected by the Technogoblet.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 100$$$, $$$1 \le m, k \le n$$$) — the total number of students, the number of schools and the number of the Chosen Ones. The second line contains $$$n$$$ different integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ denotes the power of $$$i$$$-th student. The bigger the power, the stronger the student. The third line contains $$$n$$$ integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le m$$$), where $$$s_i$$$ denotes the school the $$$i$$$-th student goes to. At least one student studies in each of the schools.  The fourth line contains $$$k$$$ different integers $$$c_1, c_2, \ldots, c_k$$$ ($$$1 \le c_i \le n$$$)  — the id's of the Chosen Ones.

Output a single integer  — the minimal number of schools to be made up by Arkady so that $$$k$$$ Chosen Ones would be selected by the Technogoblet.

NoteIn the first example there's just a single Chosen One with id $$$3$$$. His power is equal to $$$3$$$, but in the same school $$$1$$$, there's a student with id $$$5$$$ and power $$$6$$$, and that means inaction would not lead to the latter being chosen. If we, however, make up a new school (let its id be $$$4$$$) for the Chosen One, Technogoblet would select students with ids $$$2$$$ (strongest in $$$3$$$), $$$5$$$ (strongest in $$$1$$$), $$$6$$$ (strongest in $$$2$$$) and $$$3$$$ (strongest in $$$4$$$).In the second example, you can change the school of student $$$3$$$ to the made-up $$$5$$$ and the school of student $$$4$$$ to the made-up $$$6$$$. It will cause the Technogoblet to choose students $$$8$$$, $$$7$$$, $$$6$$$, $$$5$$$, $$$3$$$ and $$$4$$$.


Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write bi essays. He can raise the exam grade multiple times.What is the minimum number of essays that Vanya needs to write to get scholarship?

The first line contains three integers n, r, avg (1 ≤ n ≤ 105, 1 ≤ r ≤ 109, 1 ≤ avg ≤ min(r, 106)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers ai and bi (1 ≤ ai ≤ r, 1 ≤ bi ≤ 106).

In the first line print the minimum number of essays.

NoteIn the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = array();
$e = 0;
for($x = 1; $x <= $a; $x++)
{
     list($f, $g) = explode(" ", trim(fgets(STDIN)));
     $d[$g] += $b - $f;
     $e += $f;
}
ksort($d);
$h = bcdiv($e, $a);
$i = 0;
if($h < $c)
{
     while(TRUE)
     {
          $j = each($d);
          $e = bcadd($e, $j[1]);
          $h = bcdiv($e, $a);
          if($h < $c)
          {
               $i = bcadd($i, bcmul($j[0], $j[1]));
          }
          elseif($h == $c)
          {
               $i = bcadd($i, bcmul($j[0], $j[1]));
               break;
          }
          elseif($h > $c)
          {
               $e = bcsub($e, $j[1]);
               $k = bcmul($a, bcsub($c, $e));
               $i = bcadd($i, bcmul($k, $j[0]));
               break;
          }
     }
     print $i;
}
else
{
     print "0";
}
?>


Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train.

Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query.

NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path.

<?php
    $num =(int)fgets(STDIN);
    $res=[];
    while ($num-->0){
        $str=fgets(STDIN);
        $str = explode(' ',$str);
        $ll=(int)$str[0];
        $v=(int)$str[1];
        $l=(int)$str[2];
        $r=(int)$str[3];

        //первый столб после поезда
        if ($v>$r) {
            $count = floor($ll/$v);
            $res[]=$count;
            continue;
        }

        //первый столб до поезда
        if ($v<=$l) {
            $a = floor($l/$v);
            if (!($l%$v)) {
                $a--;
            }
            $b = floor($r/$v);
            $c = floor($ll/$v);
            $count = $c-($b-$a);
            $res[]=$count;
            continue;
        }

        //первый фонарь между поездом
        if ($l<$v && $v<=$r) {
            $b = floor($r/$v);
            $c = floor($ll/$v);
            $count = $c-$b;
            $res[]=$count;
            continue;
        }

        //ll - пункт назначения
        //v - позиция фонаря
        //l - начало длины поезда
        //r - конец длины поезда

        //686817107 73138233 67053564 180837627
        //7

        //868494849 135243336 281738625 468972539
        //5

        //100 51 51 51
        //0

        //10 2 3 7
        //3

        //1234 1 100 199
        //1134

        //99 200
    }
    /*
echo '______
';
    */
    foreach ($res as $r) {
        echo $r.'
';
    }

?>

<?php
    $num =(int)fgets(STDIN);
    $res=[];
    while ($num-->0){
        $str=fgets(STDIN);
        $str = explode(' ',$str);
        $ll=(int)$str[0];
        $v=(int)$str[1];
        $l=(int)$str[2];
        $r=(int)$str[3];

        if ($v>$r) {
            $count = floor($ll/$v);
            $res[]=$count;
            continue;
        }

        if ($v<$l && $r<$ll) {
            $a = floor($l/$v);
            if (!($l%$v)) {
                $a--;
            }
            $b = floor($r/$v);
            $c = floor($ll/$v);
            $count = $c-($b-$a);
            $res[]=$count;
            continue;
        }

        //первый фонарь между поездом
        if ($l<$v && $v<$r) {
            $b = floor($r/$v);
            $c = floor($ll/$v);
            $count = $c-$b;
            $res[]=$count;
            continue;
        }

        if ($v > $r) {
            $c = floor($ll/$v);
            $count = $c;
            $res[]=$count;
            continue;
        }

        $i = $v;
        $count = 0;

        if ($i<$l) {
            $c = floor($l / $v);
            if (!($l%$v)) {
                $c--;
            }
/*
            echo $c.' (1)
';
*/
            $count+=$c;
        }

        $k2 = 0;
        if ($r>$v){
            $k2 = floor($r / $v);
        }

        $k3 = ($k2+1) *$v;
        if ($ll>$k3 && !(($ll-$k3)%$v)) {
            $count+=1;
/*
            echo '1 (2)
';
*/
        }

        if ($r<$ll) {
            $k = $ll - $k3;
            $c = floor($k / $v);
            if ($c<0){
                $c=0;
            }
            $count += $c;
/*
            echo $c . ' (3)
';
*/

        }

/*

        while ($i<=$ll) {
            if ($i<$l || $i>$r) {
                $count++;
                echo $i.'
';
            }
            $i+=$v;

        }
*/
        //echo $count;
        $res[]=$count;

        //ll - пункт назначения
        //v - позиция фонаря
        //l - начало длины поезда
        //r - конец длины поезда

        //686817107 73138233 67053564 180837627
        //7

        //868494849 135243336 281738625 468972539
        //5

        //100 51 51 51
        //0

        //10 2 3 7
        //3

        //1234 1 100 199
        //1134

        //99 200
    }
    /*
echo '______
';
    */
    foreach ($res as $r) {
        echo $r.'
';
    }

?>


Timur's grandfather gifted him a chessboard to practice his chess skills. This chessboard is a grid $$$a$$$ with $$$n$$$ rows and $$$m$$$ columns with each cell having a non-negative integer written on it. Timur's challenge is to place a bishop on the board such that the sum of all cells attacked by the bishop is maximal. The bishop attacks in all directions diagonally, and there is no limit to the distance which the bishop can attack. Note that the cell on which the bishop is placed is also considered attacked. Help him find the maximal sum he can get.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains the integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 200$$$, $$$1 \leq m \leq 200$$$). The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element of the $$$i$$$-th line $$$a_{ij}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row $$$(0\leq a_{ij} \leq 10^6)$$$ It is guaranteed that the sum of $$$n\cdot m$$$ over all test cases does not exceed $$$4\cdot10^4$$$.

For each test case output a single integer, the maximum sum over all possible placements of the bishop.

NoteFor the first test case here the best sum is achieved by the bishop being in this position:

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";

  $t = getT();
//   $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = 0;
      list($n, $m) = getA();
      $a = [];
      $b = [];
      $c = [];
      for($i=0; $i<$n; $i++) {
          $a[$i] = getA();
          for($j = 0; $j < $m; $j++) {
              $b[$i][$j] = $c[$i][$j] = $a[$i][$j];
               if ($i > 0 && $j > 0) {
                    $b[$i][$j] += $b[$i - 1][$j - 1];
                 }
                 if ($i > 0 && $j + 1 < $m) {
                    $c[$i][$j] += $c[$i - 1][$j + 1];
                 }
          }

      }

      for ($i = $n - 1; $i > 0; $i--) {
        for ($j = 0; $j < $m; $j++) {
            if ($j > 0) {
                $b[$i - 1][$j - 1] = $b[$i][$j];
            }
            if ($j + 1 < $m) {
                $c[$i - 1][$j + 1] = $c[$i][$j];
            }
        }
    }
    for ($i = 0; $i < $n; $i++) {
        for ($j = 0; $j < $m; $j++) {
            $ans = getMaxValue($ans, $b[$i][$j] + $c[$i][$j] - $a[$i][$j]);
        }
    }

    // for($i = 0; $i < $n; $i++) {
    //     for($j = 0; $j < $m; $j++) {
    //         $total=0;
    //         for($k = 0; $k < $n; $k++) {
    //             if($k+$j-$i>=0 && $k+$j-$i<$m) {
    //                 $total+=$a[$k][$k+$j-$i];
    //             }
    //             if($i+$j-$k>=0 && $i+$j-$k <$m) {
    //                 $total+=$a[$k][$i+$j-$k];
    //             }
    //         }
    //         $total-=$a[$i][$j];
    //         $ans=getMaxValue($ans, $total);
    //     }
    // }
    pr($ans);

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
function getDar($n) {
    $dar = [2];
    for($i=0; $i<$n; $i++) {
        $dar[] = $dar[$i] * 2;
    }
    return $dar;
}
function getDar2($n, $k) {
    if($k == 0) {
        return 1;
    }
    return bcmul($n, getDar2($n, $k-1));
}

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

  function is_prime($n) {
    $d = 2;
        while ($n % $d != 0) {
        	 $d += 1;
        }

        return $d == $n;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

    function getMaxValueBc($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    function getRotate($a, $s, $e, $ind) {
 		$ar = [];
        for ($i= $s; $i<=$e; $i++) {
        	$ar[$i] = $a[$i];
        	$j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
        	// echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
        	$a[$i] = $j < $i ? $ar[$j] : $a[$j];
        }
        return $a;
    }
    function pr($s) {
        if(is_array($s)) {
            echo implode( ' ', $s), PHP_EOL;
        } else {
            echo $s, PHP_EOL;
        }
    }
    function fab2($n, $a) {
        if($n <= 1) {
            return $a[$n];
        }
       for($i=2; $i<=$n; $i++) {
           $a[$i] = $a[$i-1] + $a[$i-2];
       }

        return $a[$n];
    }


Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the і-th row and j-th column that describes the result of the collision of the і-th and the j-th car:    - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix.  0: if no car turned over during the collision.  1: if only the i-th car turned over during the collision.  2: if only the j-th car turned over during the collision.  3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?

The first line contains integer n (1 ≤ n ≤ 100) — the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A.  It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.

Print the number of good cars and in the next line print their space-separated indices in the increasing order.

<?php
$a = trim(fgets(STDIN));
$b = range(1, $a);
$c = array();
for($x = 1; $x <= $a; $x++)
{
    $d = explode(" ", trim(fgets(STDIN)));
    for($y = 0; $y < $a; $y++)
    {
        if($d[$y] == "1")
        {
            array_push($c, $x);
        }
        if($d[$y] == "3")
        {
            array_push($c, $x);
            array_push($c, $y + 1);
        }
    }
}
$d = array_diff($b, $c);
sort($d);
if(count($d) == 0)
{
    print "0";
}
else
{
    print count($d) . "\n";
    print implode(" ", $d);
}
?>


Adilbek was assigned to a special project. For Adilbek it means that he has $$$n$$$ days to run a special program and provide its results. But there is a problem: the program needs to run for $$$d$$$ days to calculate the results.Fortunately, Adilbek can optimize the program. If he spends $$$x$$$ ($$$x$$$ is a non-negative integer) days optimizing the program, he will make the program run in $$$\left\lceil \frac{d}{x + 1} \right\rceil$$$ days ($$$\left\lceil a \right\rceil$$$ is the ceiling function: $$$\left\lceil 2.4 \right\rceil = 3$$$, $$$\left\lceil 2 \right\rceil = 2$$$). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to $$$x + \left\lceil \frac{d}{x + 1} \right\rceil$$$.Will Adilbek be able to provide the generated results in no more than $$$n$$$ days?

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of test cases. The next $$$T$$$ lines contain test cases – one per line. Each line contains two integers $$$n$$$ and $$$d$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le d \le 10^9$$$) — the number of days before the deadline and the number of days the program runs.

Print $$$T$$$ answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in $$$n$$$ days or NO (case insensitive) otherwise.

NoteIn the first test case, Adilbek decides not to optimize the program at all, since $$$d \le n$$$.In the second test case, Adilbek can spend $$$1$$$ day optimizing the program and it will run $$$\left\lceil \frac{5}{2} \right\rceil = 3$$$ days. In total, he will spend $$$4$$$ days and will fit in the limit.In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program $$$2$$$ days, it'll still work $$$\left\lceil \frac{11}{2+1} \right\rceil = 4$$$ days.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     if($b < $c)
     {
          $d = 0;
          for($y = 0; $y <= floor(sqrt($c)); $y++)
          {
               $e = ceil($c / ($y + 1));
               if($b >= $y + $e)
               {
                    $d = 1;
                    break;
               }
          }
          if($d == 0)
          {
               print "NO\n";
          }
          else
          {
               print "YES\n";
          }
     }
     else
     {
          print "YES\n";
     }
}
?>

<?php
list($m) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $m; $j++) {
    list($n,$d) = explode(' ', trim(fgets(STDIN)));
    if ($d <= $n) {
        echo 'YES'. "\n";
    } else {
        $bFlag = false;
        $c = $d;
        $k = 1;
        for ($i = 1; $i < $n; $i++) {
            $c = $k + ceil($d/($k + 1));
            if ($c <= $n) {
                //echo 'Дней на оптимизацию = ' . $k . "  Итог =   " .  $c  . "   День до дедлайна = " . $n . "  \n";
                $bFlag = true;
                break;
            }
            $k++;
        }
        if ($bFlag) {
            echo 'YES'. "\n";
        } else {
            echo 'NO'. "\n";
        }
    }
}

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

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

       if($d > $n) {
           $bR = 0;
            for($j=1; $j<$n; $j++) {
                if($j + ceil($d/($j+1)) <= $n) {
                    $bR++;
                    break;
                }
            }
            if($bR > 0) {
                echo "YES\n";
            }else{
                echo "NO\n";
            }

        } else {
            echo "YES\n";
        }

    }

<?php
$f = file_get_contents('php://stdin');

$ex = explode("\n", $f);
$r = [];
foreach (array_slice($ex, 1) as $task) {
    if (!$task) {
        continue;
    }
    $possible = false;
    $t = explode(' ', $task);
    $n = $t[0];
    $d = $t[1];

    for ($i = 0; $i < $n; ++$i) {
        if ($i + $d / ($i + 1) <= $n) {
            $possible = true;
            break;
        }
    }

    if ($possible) {
        $r[] = "YES";
    } else {
        $r[] = "NO";
    }
}
echo implode("\n", $r);

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     if($b < $c)
     {
          $d = 0;
          for($y = 0; $y <= floor(sqrt($b)); $y++)
          {
               $e = ceil($c / ($y + 1));
               if($b >= $y + $e)
               {
                    $d = 1;
                    break;
               }
          }
          if($d == 0)
          {
               print "NO\n";
          }
          else
          {
               print "YES\n";
          }
     }
     else
     {
          print "YES\n";
     }
}
?>

<?php
$f = file_get_contents('php://stdin');

$ex = explode("\n", $f);
array_shift($ex);
print_r($ex);
foreach ($ex as $task) {
    $possible = false;
    $t = explode(' ', $task);
    $n = $t[0];
    $d = $t[1];

    for ($i = 0; $i < $n; ++$i) {
        if ($i + $d / ($i + 1) <= $n) {
            $possible = true;
            break;
        }
    }

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

<?php
$f = file_get_contents('php://stdin');

$ex = explode("\n", $f);
array_shift($ex);

foreach ($ex as $task) {
    $possible = false;
    $t = explode(' ', $task);
    $n = $t[0];
    $d = $t[1];

    for ($i = 0; $i < $n; ++$i) {
        if ($i + $d / ($i + 1) <= $n) {
            $possible = true;
            break;
        }
    }

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

<?php
$f = file_get_contents('php://stdin');

$ex = explode("\n", $f);
array_shift($ex);
$r = [];
foreach ($ex as $task) {
    $possible = false;
    $t = explode(' ', $task);
    $n = $t[0];
    $d = $t[1];

    for ($i = 0; $i < $n; ++$i) {
        if ($i + $d / ($i + 1) <= $n) {
            $possible = true;
            break;
        }
    }

    if ($possible) {
        $r[] = "YES";
    } else {
        $r[] = "NO";
    }
}
echo implode("\n", $r);

<?php
$f = file_get_contents('php://stdin');

$ex = explode("\n", $f);
$r = [];
foreach (array_slice($ex, 1) as $task) {
    $possible = false;
    $t = explode(' ', $task);
    $n = $t[0];
    $d = $t[1];

    for ($i = 0; $i < $n; ++$i) {
        if ($i + $d / ($i + 1) <= $n) {
            $possible = true;
            break;
        }
    }

    if ($possible) {
        $r[] = "YES";
    } else {
        $r[] = "NO";
    }
}
echo implode("\n", $r);


Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.

First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.

Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.

ross rachel
4
ross joey
rachel phoebe
phoebe monica
monica chandler

ross rachel
joey rachel
joey phoebe
joey monica
joey chandler

NoteIn first example, the killer starts with ross and rachel.   After day 1, ross is killed and joey appears.  After day 2, rachel is killed and phoebe appears.  After day 3, phoebe is killed and monica appears.  After day 4, monica is killed and chandler appears.

<?php
$kill=array();
$replace=array();
fscanf(STDIN,"%s %s",$kill[0],$replace[0]);	# code...

fscanf(STDIN,"%d",$day);

for ($i=1; $i <=$day ; $i++)
{
        fscanf(STDIN,"%s %s",$kill[$i],$replace[$i]);	# code...
}
echo "$kill[0] $replace[0]\n";
$newKill=$kill[0];
$newRep=$replace[0];

for ($i=1; $i <= $day ; $i++)
{
   //echo $i." ".$kill[$i].' '.$newKill." before if ".$kill[$i].' '.$newRep."\n";

  if ($kill[$i]==$newKill)
   {
   	$newKill=$replace[$i];
   	//$newRep=$replace[$i-1];
      echo $newKill." ".$newRep."\n";

   }
   else
   {
    	$newRep=$replace[$i];
    	//$newKill=$newKill;
      echo $newKill." ".$newRep."\n";

    }

}
/*
echo "All input shown\n";
//var_dump($initial);
echo "day=$day\n";
echo "kill\n";
var_dump($kill);
echo "replace\n";
var_dump($replace);
*/

<?php

// your code goes here

$initial = fgets(STDIN);
$initial = trim($initial);

// echo the initial
echo $initial . PHP_EOL;

$names = explode(" ", $initial);

$n = fgets(STDIN);
$n = trim($n);
$n += 0;

for($i = 0; $i < $n; $i++)
{
	$c = fgets(STDIN);
	$c = explode(" ", trim($c));
	if($names[0] == $c[0])
		$names[0] = $c[1];
	else
		$names[1] = $c[1];

	echo $names[0] . " " . $names[1] . PHP_EOL;
}

<?php
$kill=array();
$replace=array();
fscanf(STDIN,"%s %s",$kill[0],$replace[0]);	# code...

fscanf(STDIN,"%d",$day);

for ($i=1; $i <=$day ; $i++)
{
        fscanf(STDIN,"%s %s",$kill[$i],$replace[$i]);	# code...
}
echo "output:\n$kill[0] $replace[0]\n";
$newKill=$kill[0];
$newRep=$replace[0];

for ($i=1; $i <= $day ; $i++)
{
   //echo $i." ".$kill[$i].' '.$newKill." before if ".$kill[$i].' '.$newRep."\n";

  if ($kill[$i]==$newKill)
   {
   	$newKill=$replace[$i];
   	//$newRep=$replace[$i-1];
      echo $newKill." ".$newRep."\n";

   }
   else
   {
    	$newRep=$replace[$i];
    	//$newKill=$newKill;
      echo $newKill." ".$newRep."\n";

    }

}
/*
echo "All input shown\n";
//var_dump($initial);
echo "day=$day\n";
echo "kill\n";
var_dump($kill);
echo "replace\n";
var_dump($replace);
*/

<?php
$kill=array();
$replace=array();
fscanf(STDIN,"%s %s",$kill[0],$replace[0]);	# code...

fscanf(STDIN,"%d",$day);

for ($i=1; $i <=$day ; $i++)
{
        fscanf(STDIN,"%s %s",$kill[$i],$replace[$i]);	# code...
}
echo "output:\n$kill[0] $replace[0]\n";
$newKill=$kill[0];
$newRep=$replace[0];

for ($i=1; $i <= $day ; $i++)
{
   //echo $kill[$i].' '.$newKill." before if ".$kill[$i].' '.$newRep."\n";

  if ($kill[$i]==$newKill)
   {
   	$newKill=$replace[$i];
   	$newRep=$replace[$i-1];
      echo $newKill." ".$newRep."\n";

   }
   if($kill[$i]==$newRep)
    {
    	$newRep=$replace[$i];
      echo $newKill." ".$newRep."\n";

    }

}
/*
echo "All input shown\n";
//var_dump($initial);
echo "day=$day\n";
echo "kill\n";
var_dump($kill);
echo "replace\n";
var_dump($replace);
*/

<?php

// your code goes here

$initial = fgets(STDIN);
$initial = trim($initial);

// echo the initial
echo $initial . PHP_EOL;

$n = fgets(STDIN);
$n = trim($n);
$n += 0;

for($i = 0; $i < $n; $i++)
{
	$c = fgets(STDIN);
	$c = explode(" ", trim($c));
	$initial = str_replace($c[0], $c[1], $initial);
	echo $initial . PHP_EOL;
}

<?php
$kill=array();
$replace=array();
fscanf(STDIN,"%s %s",$kill[0],$replace[0]);	# code...

fscanf(STDIN,"%d",$day);

for ($i=1; $i <=$day ; $i++)
{
        fscanf(STDIN,"%s %s",$kill[$i],$replace[$i]);	# code...
}
echo "$kill[0] $replace[0]\n";
$newKill=$kill[0];
$newRep=$replace[0];

for ($i=1; $i <= $day ; $i++)
{
   //echo $kill[$i].' '.$newKill." before if ".$kill[$i].' '.$newRep."\n";

  if ($kill[$i]==$newKill)
   {
   	$newKill=$replace[$i];
   	$newRep=$replace[$i-1];
      echo $newKill." ".$newRep."\n";

   }
   if($kill[$i]==$newRep)
    {
    	$newRep=$replace[$i];
      echo $newKill." ".$newRep."\n";

    }

}
/*
echo "All input shown\n";
//var_dump($initial);
echo "day=$day\n";
echo "kill\n";
var_dump($kill);
echo "replace\n";
var_dump($replace);
*/


You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally?

The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door.

Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally.

NoteClarifications about the optimal strategy will be ignored.

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($d);
if($b <= $c)
{
     $e = 0;
     for($x = 0; $x < $a; $x++)
     {
          if($d[$x] <= $b)
          {
               $e++;
          }
          else
          {
               break;
          }
     }
     $f = ceil($e / 2);
     print $f;
}
elseif($b > $c)
{
     print $a;
}
?>

<?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 readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

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

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

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

$ir = new InputReader();

/* TASK */

list($n, $x, $y) = $ir->readArrayOfInt(3);
$b = $ir->readArrayOfInt($n);

if ($x>$y) {
	$cnt = $n;
} else {
	$c = 0;
	for ($i=0; $i<$n; $i++) {
		if ($b[$i]<=$x) {
			$c++;
		}
	}

	$cnt = ceil($c/2);
}

echo $cnt;

<?php

$dat = explode(' ', trim(fgets(STDIN)));
$a = explode(' ', trim(fgets(STDIN)));
$n = $dat[0];
$x = $dat[1];
$y = $dat[2];

$c = 0;

if($x > $y){
    fwrite(STDOUT, $n);
}else{
    for($i = 0; $i<$n; $i++){
        if($a[$i] <= $x) $c++;
    }
    fwrite(STDOUT, round($c/2));
}

?>

<?php

$in = fopen('php://stdin', 'r');
//$in = fopen('khaled.in', 'r');

$line = explode(" ", rtrim(fgets($in)));

$n = $line[0];
$x = $line[1];
$y = $line[2];

$line = explode(" ", rtrim(fgets($in)));

for($i = 0; $i<$n; ++$i){
    $a[$i] = $line[$i];
    $a[$i] *= 1;
}

if ($x > $y){
    echo $n;
    return false;
}

sort($a);

for($i = 0; $i<$n; ++$i){
        if ($a[$i] > $x) {
            echo  floor(($i + 1) / 2);
            return false;
        }
}

echo floor(($n + 1) / 2);

function what($x){fprintf(STDERR, $x . "\n");}
?>


In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part.  If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part. If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order?

The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data.

If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).

<?php

    $a = trim(fgets(STDIN));
    $t=explode('.', $a);
    $cel=$t[0];$dr=$t[1];
    $cel_l=strlen($cel);
    if($cel[$cel_l-1]!=9){
if($dr[0]<5){printf("%s\n", $cel);}else{$cel[$cel_l-1]=$cel[$cel_l-1]+1;printf("%s\n", $cel);

}

    }else{printf("%s\n", "GOTO Vasilisa.");}

?>

<?php

while (FALSE !== ($line = fgets(STDIN))) {

    list($intPart, $fracPart) =  explode('.', $line,2);

    $index = strlen($intPart);
    $index--;

    if($intPart[$index] == 9){
        echo 'GOTO Vasilisa.' . PHP_EOL;
        continue;
    }

    if($fracPart[0] >= 5){
        $intPart[$index] = $intPart[$index] + 1;
    }
    echo $intPart . PHP_EOL;
}

<?php
fscanf(STDIN, "%s", $s);
$parts = explode(".",$s);
if ($parts[0][strlen($parts[0])-1]=="9")
    echo "GOTO Vasilisa.";
else
    echo (bccomp(".".$parts[1],"0.5",strlen($parts[1]))==-1)?$parts[0]:bcadd($parts[0], 1);
?>

<?
$arr=explode('.',trim(fgets(STDIN)));
$num=strlen($arr[0]);
$cel=$arr[0];
$dr=$arr[1];
if($cel[$num-1]!=9){
    if($dr[0]>=5) {$cel[$num-1]=$cel[$num-1]+1; echo $cel;}
    else echo $cel;
} else{
    echo "GOTO Vasilisa.";
}
?>

<?php
error_reporting("off");
//99A: Help Far Away Kingdom
$n = str_split(trim(fgets(STDIN))); //$n = str_split("123456789123456789.999");
$dot = array_search(".", $n);
$lastint = $n[$dot - 1];
$firstdec = $n[$dot + 1];
$beforedot = array();
for ($i = 0; $i < $dot; $i++) {
    $beforedot[] = $n[$i];
}
$int = implode($beforedot);
if ($lastint == 9) {
    echo "GOTO Vasilisa.";
} else {
    if ($firstdec >= 5) {
        $int = substr($int, 0, -1);
        $int .= $lastint + 1;
    }
    echo $int;
}
?>

<?php
$a = trim(fgets(STDIN));
$b = str_split($a);
$c = array_search(".", $b);
$d = implode(array_slice($b, $c + 1));
if(($b[$c - 1] != 9) && (0 . "." . $d < 0.5))
{
    print implode(array_slice($b, 0, $c));
}
elseif(($b[$c - 1] != 9) && (0 . "." . $d >= 0.5))
{
    print implode(array_slice($b, 0, $c)) + 1;
}
elseif($b[$c - 1] == 9)
{
    print "GOTO Vasilisa.";
}
?>

<?php
fscanf(STDIN, "%s", $s);
$parts = explode(".",$s);
echo "=".$parts[0][strlen($parts[0])-1]."=";
if ($parts[0][strlen($parts[0])-1]=="9")
	echo "GOTO Vasilisa.";
else
	echo (bccomp(".".$parts[1],"0.5",strlen($parts[1]))==-1)?$parts[0]:bcadd($parts[0], 1);
?>

<?php
fscanf(STDIN, "%s", $s);
echo (strpos($s,"9.")!==false)?"GOTO Vasilisa.":number_format(round($s),0,".","");
?>

<?php
fscanf(STDIN, "%s", $s);
echo (strpos($s,"9.")!==false)?"GOTO vasilisa":number_format(round($s),0,".","");
?>

<?php
fscanf(STDIN, "%s", $s);
$parts = explode(".",$s);
echo (strpos("".$s,"9.")!==false)?"GOTO Vasilisa.":(bccomp(".".$parts[1],"0.5",strlen($parts[1]))==-1)?$parts[0]:bcadd($parts[0], 1);
?>

<?
$arr=explode('.',trim(fgets(STDIN)));
$num=strlen($arr[0]);
$cel=$arr[0];
$dr=$arr[1];
if($cel[$num-1]!=9){
    if($dr[0]<5) echo $arr[0];
    elseif($dr[0]>=5) echo $arr[0]+1;
} else{
    echo "GOTO Vasilisa.";
}
?>


Did you know you can download more RAM? There is a shop with $$$n$$$ different pieces of software that increase your RAM. The $$$i$$$-th RAM increasing software takes $$$a_i$$$ GB of memory to run (temporarily, once the program is done running, you get the RAM back), and gives you an additional $$$b_i$$$ GB of RAM (permanently). Each software can only be used once. Your PC currently has $$$k$$$ GB of RAM.Note that you can't use a RAM-increasing software if it takes more GB of RAM to use than what you currently have.Since RAM is the most important thing in the world, you wonder, what is the maximum possible amount of RAM achievable?

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains the integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$, $$$1 \le k \le 1000$$$). Then two lines follow, each containing $$$n$$$ integers describing the arrays $$$a$$$ and $$$b$$$ ($$$1 \le a_i, b_i \le 1000$$$).

For each test case, output a single line containing the largest amount of RAM you can achieve.

NoteIn the first test case, you only have enough RAM to run the third software initially, but that increases your RAM to $$$20$$$ GB, which allows you to use the first software, increasing your RAM to $$$29$$$ GB. The only software left needs $$$30$$$ GB of RAM, so you have to stop here.In the second test case, you can use the first, second, fourth and fifth software that need only $$$1$$$ GB of RAM per software to run to increase your RAM to $$$5$$$ GB, and then use the last remaining one to increase your RAM to $$$6$$$ GB.In the third test case, all the software need more than $$$1$$$ GB of RAM to run, so the amount of RAM you have stays at $$$1$$$ GB.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = explode(" ", trim(fgets(STDIN)));
     $e = explode(" ", trim(fgets(STDIN)));
     asort($d);
     $f = array_keys($d);
     $g = array();
     for($y = 0; $y < $b; $y++)
     {
          $g[$y] = $e[$f[$y]];
     }
     sort($d);
     for($y = 0; $y < $b; $y++)
     {
          if($d[$y] <= $c)
          {
               $c += $g[$y];
          }
          else
          {
               break;
          }
     }
     print $c . "\n";
}
?>


Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to n in their order. Dima performs several steps, on step i he reverses the segment of cubes from i-th to (n - i + 1)-th. He does this while i ≤ n - i + 1.After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location.

The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.

Print n integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.

NoteConsider the first sample.  At the begining row was [2, 3, 9, 6, 7, 1, 4].  After first operation row was [4, 1, 7, 6, 9, 3, 2].  After second operation row was [4, 3, 9, 6, 7, 1, 2].  After third operation row was [4, 3, 7, 6, 9, 1, 2].  At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4].