Permutation p is an ordered set of integers p1,  p2,  ...,  pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1,  p2,  ...,  pn.The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≤ i < n), that pi > pi + 1.You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k.

The single line contains two space-separated integers: n, k (1 ≤ n ≤ 105, 0 ≤ k < n) — the permutation length and the decreasing coefficient.

In a single line print n space-separated integers: p1, p2, ..., pn — the permutation of length n with decreasing coefficient k.  If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = range(1, $a);
$d = array_slice($c, 0, -$b);
$e = array_slice($c, -$b);
$f = array_reverse($e);
$g = array_merge($f, $d);
if($b == 0)
{
    print implode(" ", $c);
}
else
{
    print implode(" ", $g);
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = range(1, $a);
$d = array_slice($c, 0, -$b);
$e = array_slice($c, -$b);
$f = array();
for($x = 0; $x < $a; $x++)
{
    if($e[$x] != "")
    {
        array_push($f, $e[$x]);
    }
    if($d[$x] != "")
    {
        array_push($f, $d[$x]);
    }
}
print implode(" ", $f);
?>


This is an interactive problem.Homer likes arrays a lot and he wants to play a game with you. Homer has hidden from you a permutation $$$a_1, a_2, \dots, a_n$$$ of integers $$$1$$$ to $$$n$$$. You are asked to find any index $$$k$$$ ($$$1 \leq k \leq n$$$) which is a local minimum. For an array $$$a_1, a_2, \dots, a_n$$$, an index $$$i$$$ ($$$1 \leq i \leq n$$$) is said to be a local minimum if $$$a_i < \min\{a_{i-1},a_{i+1}\}$$$, where $$$a_0 = a_{n+1} = +\infty$$$. An array is said to be a permutation of integers $$$1$$$ to $$$n$$$, if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Initially, you are only given the value of $$$n$$$ without any other information about this permutation.At each interactive step, you are allowed to choose any $$$i$$$ ($$$1 \leq i \leq n$$$) and make a query with it. As a response, you will be given the value of $$$a_i$$$. You are asked to find any index $$$k$$$ which is a local minimum after at most $$$100$$$ queries.

NoteIn the example, the first line contains an integer $$$5$$$ indicating that the length of the array is $$$n = 5$$$.The example makes five "?" queries, after which we conclude that the array is $$$a = [3,2,1,4,5]$$$ and $$$k = 3$$$ is local minimum.

<?php

$n = (int)readline();

if (1 === $n) {
    echo "! 1\n";
    exit(0);
}

$cache = [];

$cache[0] = PHP_INT_MAX / 2 - 2;
$cache[$n + 1] = PHP_INT_MAX / 2 - 1;

function item(int $idx): int
{
    global $cache;

    return $cache[$idx]
        ?? ($cache[$idx] = fetch($idx));
}

function fetch(int $idx): int
{
    print "? $idx\n";

    return (int)readline();
}

$l = 1;
$r = $n;

while ($l < $r) {
    $mid = ($l + $r) >> 1;

    if (item($mid) > item($mid + 1)) {
        $l = $mid + 1;
    } elseif (item($mid) <= item($mid + 1)) {
        $r = $mid;
    }
}

print "! $l\n";
exit(0);


Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1, r1], [l2, r2], ..., [ln, rn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1, rn].

The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start and the end of the i-th period of work.

<?php
list($a, $b, $c, $d, $e, $f) = explode(" ", trim(fgets(STDIN)));
$i = array();
$j = array();
$k = array();
$l = array();
$p = array();
$s = array();
$u = array();
for($x = 0; $x < $a; $x++)
{
    list($g, $h) = explode(" ", trim(fgets(STDIN)));
    array_push($i, $h - $g);
    array_push($j, $g);
    array_push($k, $h);
    array_push($l, $j[$x] - $k[$x - 1]);
}
$l = array_splice($l, 1);
$m = array_sum($i);
$o = $m * $b; // нормальный режим
for($x = 0; $x < count($l); $x++)
{
    if($l[$x] - $e > 0)
    {
        $n = $e * $b; // нормальный режим
        array_push($p, $n);
        if($l[$x] - $e - $f > 0)
        {
            $r = $f * $c; // скринсейвер
            array_push($s, $r);
            $t = ($l[$x] - $e - $f) * $d; // спящий режим
            array_push($u, $t);
        }
        else
        {
            $r = ($l[$x] - $e) * $c; // скринсейвер
            array_push($s, $r);
        }
    }
    else
    {
        $n = $l[$x] * $b; // нормальный режим
        array_push($p, $n);
    }
}
$v = array_sum($p);
$q = array_sum($s);
$w = array_sum($u);
print $o + $v + $q + $w;
?>

<?php
list($a, $b, $c, $d, $e, $f) = explode(" ", trim(fgets(STDIN)));
$i = array();
$j = array();
$k = array();
$l = array();
$p = array();
$s = array();
$u = array();
for($x = 0; $x < $a; $x++)
{
    list($g, $h) = explode(" ", trim(fgets(STDIN)));
    array_push($i, $h - $g);
    array_push($j, $g);
    array_push($k, $h);
    array_push($l, $j[$x] - $k[$x - 1]);
}
$l = array_splice($l, 1);
$m = array_sum($i);
$o = $m * $b; // нормальный режим
for($x = 0; $x < count($l); $x++)
{
    if($l[$x] - $e > 0)
    {
        $n = $e * $b; // нормальный режим
        array_push($p, $n);
        if($l[$x] - $e - $f > 0)
        {
            $r = $f * $c; // скринсейвер
            array_push($s, $r);
            $t = ($l[$x] - $e - $f) * $d; // спящий режим
            array_push($u, $t);
        }
        else
        {
            $r = $f * $c; // скринсейвер
            array_push($s, $r);
        }
    }
    else
    {
        $n = $l[$x] * $b; // нормальный режим
        array_push($p, $n);
    }
}
$v = array_sum($p);
$q = array_sum($s);
$w = array_sum($u);
print $o + $v + $q + $w;
?>


An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.

A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.

In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |ai - ai + 1| ≠ 1 for all i from 1 to k - 1. If there are several possible answers, output any of them.

<?php
$a = trim(fgets(STDIN));
$b = array();
for($x = 1; $x <= $a; $x++)
{
    $b[$x] = $x;
}
$c = array();
$d = array();
for($x = 1; $x <= $a; $x++)
{
    $e = $x % 2;
    if($e != 0)
    {
        array_push($c, $b[$x]);
    }
    else
    {
        array_push($d, $b[$x]);
    }
}
$f = array_merge($c, $d);
if(count($f) == 2)
{
    unset($f[count($f) - 1]);
}
elseif(count($f) == 3)
{
    unset($f[count($f) - 1]);
}
elseif(count($f) == 4)
{
    array_unshift($f, $f[count($f) - 1]);
    unset($f[4]);
    array_unshift($f, $f[count($f) - 1]);
    unset($f[4]);
}
print count($f) . "\n";
print implode(" ", $f);
?>

<?php

fscanf(STDIN, "%d", $size); // читает число из STDIN

$data = array();

if($size >= 5) {
    $data = range(1, $size);
    $result = array();

    $head = array();
    $tail = array();

    $i = 1;
    foreach($data as $elem) {
        if($i % 2 == 0) {
          $head[] = $elem;
        } else {
          $tail[] = $elem;
        }
        $i++;
    }
    $result = array_merge($head, $tail);
} else {
    if($size == 1 || $size == 2) {
        $result = array(1);
    } else {
        $result = range(1, $size);
        if($size == 4) {
            $result = array(2, 4, 1, 3);
        } elseif ($size == 3) {
            $result = array(1, 3);
        }

    }
}
echo count($result) . "\n";
array_map(function($e) {echo $e . " ";}, $result);

<?php
$z = fopen('php://stdin','r');
$n = intval(fgets($z));
switch ($n) {
    case 1: case 2: echo "1\n1"; break;
    case 3: echo "2\n1 3"; break;
    default:
        echo "$n\n";
        for ($i = 2; $i <= $n; $i+=2) echo "$i ";
        for ($i = 1; $i <= $n; $i+=2) echo "$i ";
        break;
}

<?php
$a = trim(fgets(STDIN));
$b = array();
for($x = 1; $x <= $a; $x++)
{
    $b[$x] = $x;
}
$c = array();
$d = array();
for($x = 1; $x <= $a; $x++)
{
    $e = $x % 2;
    if($e != 0)
    {
        array_push($c, $b[$x]);
    }
    else
    {
        array_push($d, $b[$x]);
    }
}
$f = array_merge($c, $d);
if(count($f) == 2)
{
    unset($f[count($f) - 1]);
}
elseif(count($f) == 3)
{
    unset($f[count($f) - 1]);
}
elseif(count($f) == 4)
{
    array_unshift($f, $f[count($f) - 1]);
    unset($f[3]);
    unset($f[4]);
}
print count($f) . "\n";
print implode(" ", $f);
?>

fscanf(STDIN, "%d", $size); // читает число из STDIN

$data = [];

if($size >= 5) {
        $data = range(1, $size);
        $result = [];

        $head = [];
        $tail = [];

        $i = 1;
        foreach($data as $elem) {
                if($i % 2 == 0) {
                  $head[] = $elem;
                } else {
                  $tail[] = $elem;
                }
                $i++;
        }
        $result = array_merge($head, $tail);
} else {
        if($size == 1 || $size == 2) {
                $result = [1];
        } else {
                $result = range(1, $size);
                if($size == 4) {
                        $result = [4, 1, 3];
                } elseif ($size == 3) {
                        $result = [1, 3];
                }
        }
}
echo count($result) . "\n";
array_map(function($e) {echo $e . " ";}, $result);
~
~
~

fscanf(STDIN, "%d", $size); // читает число из STDIN

$data = [];

if($size >= 5) {
    $data = range(1, $size);
    $result = [];

    $head = [];
    $tail = [];

    $i = 1;
    foreach($data as $elem) {
        if($i % 2 == 0) {
          $head[] = $elem;
        } else {
          $tail[] = $elem;
        }
        $i++;
    }
    $result = array_merge($head, $tail);
} else {
    if($size == 1) {
        $result = [1];
    } else {
        $result = range(1, $size);
        if($size == 4) {
            $result = [4, 1, 3];
        } elseif ($size == 3 || $size == 2) {
            $result = [1, 3];
        }

    }
}
echo count($result) . "\n";
array_map(function($e) {echo $e . " ";}, $result);

<?php

fscanf(STDIN, "%d", $size); // читает число из STDIN

$data = array();

if($size >= 5) {
    $data = range(1, $size);
    $result = array();

    $head = array();
    $tail = array();

    $i = 1;
    foreach($data as $elem) {
        if($i % 2 == 0) {
          $head[] = $elem;
        } else {
          $tail[] = $elem;
        }
        $i++;
    }
    $result = array_merge($head, $tail);
} else {
    if($size == 1 || $size == 2) {
        $result = array(1);
    } else {
        $result = range(1, $size);
        if($size == 4) {
            $result = array(4, 1, 3);
        } elseif ($size == 3) {
            $result = array(1, 3);
        }

    }
}
echo count($result) . "\n";
array_map(function($e) {echo $e . " ";}, $result);

<?php

fscanf(STDIN, "%d", $size); // читает число из STDIN

$data = array();

if($size >= 5) {
    $data = range(1, $size);
    $result = array();

    $head = array();
    $tail = array();

    $i = 1;
    foreach($data as $elem) {
        if($i % 2 == 0) {
          $head[] = $elem;
        } else {
          $tail[] = $elem;
        }
        $i++;
    }
    $result = array_merge($head, $tail);
} else {
    if($size == 1) {
        $result = array(1);
    } else {
        $result = range(1, $size);
        if($size == 4) {
            $result = array(4, 1, 3);
        } elseif ($size == 3 || $size == 2) {
            $result = array(1, 3);
        }

    }
}
echo count($result) . "\n";
array_map(function($e) {echo $e . " ";}, $result);

<?php
function scanf($format) {
    return fscanf(STDIN, $format);
}

list($n) = scanf("%d");

if ($n == 3) {
    printf("2\n1 3");
    die();
} else if ($n == 4) {
    printf("4\n2 4 1 3");
    die();
}
echo "$n\n";
$x = ceil($n / 2);
$y = floor($n / 2);
if ($n % 2) {
    echo $x . " ";
}
for ($i = 1; $i <= $y; $i ++) {
    echo "$i " . ($i + $x) . " ";
}


Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.Codeforces scores are computed as follows: If the maximum point value of a problem is x, and Kevin submitted correctly at minute m but made w wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.

The first line of the input contains five space-separated integers m1, m2, m3, m4, m5, where mi (0 ≤ mi ≤ 119) is the time of Kevin's last submission for problem i. His last submission is always correct and gets accepted. The second line contains five space-separated integers w1, w2, w3, w4, w5, where wi (0 ≤ wi ≤ 10) is Kevin's number of wrong submissions on problem i. The last line contains two space-separated integers hs and hu (0 ≤ hs, hu ≤ 20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.

Print a single integer, the value of Kevin's final score.

NoteIn the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets  of the points on each problem. So his score from solving problems is . Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));

$a = explode(" ",$a);
$b = explode(" ",$b);
$c = explode(" ",$c);

$inputTime = $a;
$inputFail = $b;
$inputExtraScore = $c;
$defaultScore = [500.0, 1000.0, 1500.0, 2000.0, 2500.0];
$finalScore = 0.0;

foreach($defaultScore as $key => $value){
 $score = calculateScore($key+1, $value, $inputFail[$key], $inputTime[$key]);
 $finalScore += $score;
}
$finalScore = $finalScore + $inputExtraScore[0] * 100;
$finalScore = $finalScore - $inputExtraScore[1] * 50;
echo "$finalScore";

function calculateScore ($num, $defaultScore, $failNum, $time){
   $score = (1-($time/250.0))*$defaultScore - 50.0*$failNum;
   return max((0.3*$defaultScore), $score);
}
?>


Polycarp was presented with some sequence of integers $$$a$$$ of length $$$n$$$ ($$$1 \le a_i \le n$$$). A sequence can make Polycarp happy only if it consists of different numbers (i.e. distinct numbers).In order to make his sequence like this, Polycarp is going to make some (possibly zero) number of moves.In one move, he can:   remove the first (leftmost) element of the sequence. For example, in one move, the sequence $$$[3, 1, 4, 3]$$$ will produce the sequence $$$[1, 4, 3]$$$, which consists of different numbers.Determine the minimum number of moves he needs to make so that in the remaining sequence all elements are different. In other words, find the length of the smallest prefix of the given sequence $$$a$$$, after removing which all values in the sequence will be unique.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the given sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — elements of the given sequence $$$a$$$. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print your answer on a separate line — the minimum number of elements that must be removed from the beginning of the sequence so that all remaining elements are different.

NoteThe following are the sequences that will remain after the removal of prefixes:  $$$[1, 4, 3]$$$;  $$$[1]$$$;  $$$[1]$$$;  $$$[6, 5, 4, 3, 2, 1]$$$;  $$$[2, 1]$$$. It is easy to see that all the remaining sequences contain only distinct elements. In each test case, the shortest matching prefix was removed.

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d", $n);
    $a = fgetcsv(STDIN, 0, ' ');
    for ($i = $n-1, $b = []; $i >= 0; $i--) {
        if (isset($b[$a[$i]])) break;
        $b[$a[$i]] = true;
    }
    echo count($a) - count($b), "\n";
}

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
     $n = IO::get();
     $a = IO::getArray();
     $ans = 0;
     $tt = [];
    for($i=$n-1; $i>= 0; $i--) {
         if(isset($tt[$a[$i]])) {
              $ans = $i + 1;
              break;
         }
         $tt[$a[$i]] = 1;

    }
    IO::pr( $ans);

}

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

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


The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within m cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the m cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.

The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 100). Then follow n lines describing instructions. The i-th line contains m integers: xi1, xi2, ..., xim (0 ≤ xij ≤ k), where xij is the instruction that must be executed by the i-th core at the j-th cycle. If xij equals 0, then the corresponding instruction is «do nothing». But if xij is a number from 1 to k, then the corresponding instruction is «write information to the memory cell number xij». We assume that the cores are numbered from 1 to n, the work cycles are numbered from 1 to m and the memory cells are numbered from 1 to k.

Print n lines. In the i-th line print integer ti. This number should be equal to 0 if the i-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.


You play a computer game. In this game, you lead a party of $$$m$$$ heroes, and you have to clear a dungeon with $$$n$$$ monsters. Each monster is characterized by its power $$$a_i$$$. Each hero is characterized by his power $$$p_i$$$ and endurance $$$s_i$$$.The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated $$$k$$$ monsters, the hero fights with the monster $$$k + 1$$$). When the hero fights the monster, there are two possible outcomes:  if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;  otherwise, the monster is defeated. After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the $$$i$$$-th hero cannot defeat more than $$$s_i$$$ monsters during each day), or if all monsters are defeated — otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then the test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of monsters in the dungeon. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the power of the $$$i$$$-th monster. The third line contains one integer $$$m$$$ ($$$1 \le m \le 2 \cdot 10^5$$$) — the number of heroes in your party. Then $$$m$$$ lines follow, each describing a hero. Each line contains two integers $$$p_i$$$ and $$$s_i$$$ ($$$1 \le p_i \le 10^9$$$, $$$1 \le s_i \le n$$$) — the power and the endurance of the $$$i$$$-th hero. It is guaranteed that the sum of $$$n + m$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print one integer — the minimum number of days you have to spend to defeat all of the monsters (or $$$-1$$$ if it is impossible).


Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.The park is a rectangular table with $$$n$$$ rows and $$$m$$$ columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length $$$1$$$. For example, park with $$$n=m=2$$$ has $$$12$$$ streets.You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).    The park sizes are: $$$n=4$$$, $$$m=5$$$. The lighted squares are marked yellow. Please note that all streets have length $$$1$$$. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit. Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$n$$$, $$$m$$$ ($$$1 \le n, m \le 10^4$$$) — park sizes.

Print $$$t$$$ answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.

NotePossible optimal arrangement of the lanterns for the $$$2$$$-nd test case of input data example: Possible optimal arrangement of the lanterns for the $$$3$$$-rd test case of input data example:

<?php

$handle = fopen('php://stdin', 'r');
$count = fgets($handle);
for($i = 0; $i < $count; $i++){
    $tmp_string = fgets($handle);
    $tmp_arr = explode(' ', $tmp_string);
    print_r(intval($tmp_arr[0] * $tmp_arr[1] / 2) + ($tmp_arr[0] * $tmp_arr[1] % 2));
    echo "\n";
}

fclose($handle);

?>

<?php

$fh = fopen('php://stdin','r');

$t = fgets($fh);

$data = [];

for ($i = 0; $i < $t; $i++)
{
     $line = fgets($fh);
     $left = explode(' ', $line)[0];
     $right = explode(' ', $line)[1];

     if ($right == 1 && $left == 1)
                    $res = 1;
                    else
     if ($right == 1 && $left > 1)
                     $res = ceil($left/2)  ;

     else
     if ($right > 1 && $left == 1)
               $res = ceil($right/2) ;
                    else
     if ($left % 2 == 0)
     {
       $res = ($left/2) * $right;
     }
     else
     {
       $res = (($left -1)/2) * $right + ceil($right/2);
     }

     echo $res. "\n";
}

fclose($fh);

?>

<?php

$file = fopen("php://stdin", "r");

$t = fgets($file);

for ($i = 0; $i < $t; $i++) {
  $pair = explode(" ", fgets($file));
  $n = $pair[0];
  $m = $pair[1];
  $nm = $n * $m;
  $result = $nm % 2 == 0 ? $nm / 2 : ($nm + 1) / 2;
  echo $result . "\n";
}


Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office.All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to n in the order they go in the line. Every child is associated with the value of his cofidence pi. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor.While Gennady treats the teeth of the i-th child, the child is crying with the volume of vi. At that the confidence of the first child in the line is reduced by the amount of vi, the second one — by value vi - 1, and so on. The children in the queue after the vi-th child almost do not hear the crying, so their confidence remains unchanged.If at any point in time the confidence of the j-th child is less than zero, he begins to cry with the volume of dj and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the j-th one in the line is reduced by the amount of dj.All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office.Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.

The first line of the input contains a positive integer n (1 ≤ n ≤ 4000) — the number of kids in the line.  Next n lines contain three integers each vi, di, pi (1 ≤ vi, di, pi ≤ 106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the i-th child.

In the first line print number k — the number of children whose teeth Gennady will cure. In the second line print k integers — the numbers of the children who will make it to the end of the line in the increasing order.

NoteIn the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to  - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit.In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5,  - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.


There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1 ≤ i, j ≤ N2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.

The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.

Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.


Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name1price1name2price2...namenpricen", where namei (name of the i-th purchase) is a non-empty string of length not more than 10, consisting of lowercase English letters, and pricei (the price of the i-th purchase) is a non-empty string, consisting of digits and dots (decimal points). It is possible that purchases with equal names have different prices.The price of each purchase is written in the following format. If the price is an integer number of dollars then cents are not written.Otherwise, after the number of dollars a dot (decimal point) is written followed by cents in a two-digit format (if number of cents is between 1 and 9 inclusively, there is a leading zero).Also, every three digits (from less significant to the most) in dollars are separated by dot (decimal point). No extra leading zeroes are allowed. The price always starts with a digit and ends with a digit.For example:  "234", "1.544", "149.431.10", "0.99" and "123.05" are valid prices,  ".333", "3.33.11", "12.00", ".33", "0.1234" and "1.2" are not valid. Write a program that will find the total price of all purchases in the given bill.

The only line of the input contains a non-empty string s with length not greater than 1000 — the content of the bill. It is guaranteed that the bill meets the format described above. It is guaranteed that each price in the bill is not less than one cent and not greater than 106 dollars.

Print the total price exactly in the same format as prices given in the input.

<?php
$line1 = trim(fgets(STDIN));
$itog = preg_replace('/[a-z]+/', '#', $line1);
$mach = explode('#', $itog);
$sum = 0;
$koope = 0;
foreach($mach as $item){
    $reo = explode('.', $item);
    if($reo[0] == ''){
        continue;
    }
    $kop = 0;
    if(strlen($reo[count($reo)-1]) == 2){
        $kop = $reo[count($reo)-1];
        unset($reo[count($reo)-1]);
    }
    $l = 0;
    $chisl = 0;
    while($l <= count($reo)-1){
        $chisl += $reo[$l] * pow(1000, count($reo)-1-$l);
        $l++;
    }
    $sum += $chisl;
    $koope += $kop;
}
$nsum = 0;
if($koope >= 100){
    $nsum = floor($koope/100);
    $koope = $koope % 100;
}
$sum += $nsum;

if($koope == 0){
    echo number_format($sum, 0, ',', '.');
}else{
   if($koope < 10){
    $koope = '.0'.$koope;
}else{
	$koope = '.'.$koope;
}
    echo number_format($sum, 0, ',', '.').$koope;
}

<?php
$s = file_get_contents("php://stdin");
preg_match_all("/[a-z]+((?:\\d\\d?\\d?)(?:\.\\d\\d\\d)*(?:\.\d\d)?)/", $s, $matches);
$ans = 0;
foreach($matches[1] as $price) {
  if (strlen($price) >= 3 && substr($price, -3, 1) == '.') {
    $ans += str_replace(".", "", $price) / 100;
  } else {
    $ans += str_replace(".", "", $price);
  }
}
$t = str_replace(",", ".", number_format($ans, 2));
if (substr($t, -3, 3) == ".00") {
  echo substr($t, 0, strlen($t) - 3);
} else {
  echo $t;
}

<?php

###### IO ######
error_reporting(E_ALL);
error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	if ($is_test)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	$str = readString($stream);

	$preg = '![a-z]{1,10}(?<price>[0-9.]+)!i';
	if (preg_match_all($preg, $str, $res)) {
		$sum = 0;
		foreach ($res['price'] as $price) {
			$parts = explode('.', $price);
			$lastPart = $parts[count($parts) - 1];
			if (strlen($lastPart) == 2) {
				$kop = array_pop($parts);
				$rub = intval(implode('', $parts));
				$add = $rub + $kop / 100;

				$sum+=$add;
			} else {
				$rub = intval(implode('', $parts));
				$add = $rub;
				$sum+=$add;
			}
		}
		$signs = 0;
		if (floor($sum) != $sum)
			$signs = 2;
		echo number_format($sum, $signs, '.', '.');
	} else {
		echo 'invalid';
	}
	/* / end body */
}

if (empty($is_test))
	getAnswer();

<?php
$line1 = trim(fgets(STDIN));
$itog = preg_replace('/[a-z]+/', '#', $line1);
$mach = explode('#', $itog);
$sum = 0;
$koope = 0;
foreach($mach as $item){
    $reo = explode('.', $item);
    if($reo[0] == ''){
        continue;
    }
    $kop = 0;
    if(strlen($reo[count($reo)-1]) == 2){
        $kop = $reo[count($reo)-1];
        unset($reo[count($reo)-1]);
    }
    $l = 0;
    $chisl = 0;
    while($l <= count($reo)-1){
        $chisl += $reo[$l] * pow(1000, count($reo)-1-$l);
        $l++;
    }
    $sum += $chisl;
    $koope += $kop;
}
$nsum = 0;
if($koope >> 100){
    $nsum = floor($koope/100);
    $koope = $koope % 100;
}
$sum += $nsum;
if($koope < 10){
    $koope = '.0'.$koope;
}else if($koope == 0){
	$koope = '';
}else{
	$koope = '.'.$koope;
}
echo number_format($sum, 0, ',', '.').$koope;

<?php
$line1 = trim(fgets(STDIN));
$itog = preg_replace('/[a-z]+/', '#', $line1);
$mach = explode('#', $itog);
$sum = 0;
$koope = 0;
foreach($mach as $item){
    $reo = explode('.', $item);
    if($reo[0] == ''){
        continue;
    }
    $kop = 0;
    if(strlen($reo[count($reo)-1]) == 2){
        $kop = $reo[count($reo)-1];
        unset($reo[count($reo)-1]);
    }
    $l = 0;
    $chisl = 0;
    while($l <= count($reo)-1){
        $chisl += $reo[$l] * pow(1000, count($reo)-1-$l);
        $l++;
    }
    $sum += $chisl;
    $koope += $kop;
}
$nsum = 0;
if($koope >> 100){
    $nsum = floor($koope/100);
    $koope = $koope % 100;
}
$sum += $nsum;
if($koope < 10){
    $koope = '0'.$koope;
}
echo number_format($sum, 0, ',', '.').'.'.$koope;

<?php
$s = file_get_contents("php://stdin");
preg_match_all("/[a-z]+((?:\\d\\d?\\d?)(?:\.\\d\\d\\d)*(?:\.\d\d)?)/", $s, $matches);
$ans = 0;
foreach($matches[1] as $price) {
  if (strlen($price) >= 3 && substr($price, -3, 1) == '.') {
    $ans += str_replace(".", "", $price) / 100;
  } else {
    $ans += str_replace(".", "", $price);
  }
}
echo str_replace(",", ".", number_format($ans, 2));

<?php
$s = 'chipsy48.32televizor12.390';//file_get_contents("php://stdin");
preg_match_all("/[a-z]+((?:\\d\\d?\\d?)(?:\.\\d\\d\\d)*(?:\.\d\d)?)/", $s, $matches);
$ans = 0;
foreach($matches[1] as $price) {
  if (strlen($price) >= 3 && substr($price, -3, 1) == '.') {
    $ans += str_replace(".", "", $price) / 100;
  } else {
    $ans += str_replace(".", "", $price);
  }
}
echo str_replace(",", ".", number_format($ans, 2));

<?php

###### IO ######
error_reporting(E_ALL);
error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	if ($is_test)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	$str = readString($stream);

	$preg = '![a-z]{1,10}(?<price>[0-9.]+)!i';
	if (preg_match_all($preg, $str, $res)) {
		$sum = 0;
		foreach ($res['price'] as $price) {
			$parts = explode('.', $price);
			$lastPart = $parts[count($parts) - 1];
			if (strlen($lastPart) == 2) {
				$kop = array_pop($parts);
				$rub = intval(implode('', $parts));
				$add = $rub + $kop / 100;

				$sum+=$add;
			} else {
				$rub = intval(implode('', $parts));
				$add = $rub;
				$sum+=$add;
			}
		}
		echo number_format($sum, 2, '.', '.');
	} else {
		echo 'invalid';
	}
	/* / end body */
}

if (empty($is_test))
	getAnswer();


Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that:  the first elevator is currently on the floor $$$a$$$ (it is currently motionless),  the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.

The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.

Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output:   $$$1$$$, if it is better to call the first elevator;  $$$2$$$, if it is better to call the second one;  $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).

NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows:  At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor;  in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$;  in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.

<?php
// https://codeforces.com/contest/1729/problem/A

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

$t;
fscanf($cin, "%d\n", $t);
for ($T = 0; $T < $t; $T++) {
	$a; $b; $c;
	fscanf($cin, "%d %d %d\n", $a, $b, $c);
	$first = abs($a - 1);
	$second = abs($b - $c) + abs($c - 1);
	if ($first == $second) {
		fprintf($cout, "3\n");
	} else if ($first > $second) {
		fprintf($cout, "2\n");
	} else {
		fprintf($cout, "1\n");
	}
} ?>