You are given a string $$$s$$$, consisting of $$$n$$$ letters, each letter is either 'a' or 'b'. The letters in the string are numbered from $$$1$$$ to $$$n$$$.$$$s[l; r]$$$ is a continuous substring of letters from index $$$l$$$ to $$$r$$$ of the string inclusive. A string is called balanced if the number of letters 'a' in it is equal to the number of letters 'b'. For example, strings "baba" and "aabbab" are balanced and strings "aaab" and "b" are not.Find any non-empty balanced substring $$$s[l; r]$$$ of string $$$s$$$. Print its $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$). If there is no such substring, then print $$$-1$$$ $$$-1$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the string. The second line of the testcase contains a string $$$s$$$, consisting of $$$n$$$ letters, each letter is either 'a' or 'b'.

For each testcase print two integers. If there exists a non-empty balanced substring $$$s[l; r]$$$, then print $$$l$$$ $$$r$$$ ($$$1 \le l \le r \le n$$$). Otherwise, print $$$-1$$$ $$$-1$$$.

NoteIn the first testcase there are no non-empty balanced subtrings.In the second and third testcases there are multiple balanced substrings, including the entire string "abbaba" and substring "baba".

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $s = IO::str();
    $a = str_split($s);
    $res = [-1, -1];
    foreach ($a as $k => $v) {
        if (isset($a[$k+1])) {
            if ($v != $a[$k+1]) {
                $res = [$k+1, $k+2];
                break;
            }
        }
    }
    IO::line(implode(' ', $res));

}

?>


For the first place at the competition, Alex won many arrays of integers and was assured that these arrays are very expensive. After the award ceremony Alex decided to sell them. There is a rule in arrays pawnshop: you can sell array only if it can be compressed to a generator.This generator takes four non-negative numbers $$$n$$$, $$$m$$$, $$$c$$$, $$$s$$$. $$$n$$$ and $$$m$$$ must be positive, $$$s$$$ non-negative and for $$$c$$$ it must be true that $$$0 \leq c < m$$$. The array $$$a$$$ of length $$$n$$$ is created according to the following rules:   $$$a_1 = s \bmod m$$$, here $$$x \bmod y$$$ denotes remainder of the division of $$$x$$$ by $$$y$$$;  $$$a_i = (a_{i-1} + c) \bmod m$$$ for all $$$i$$$ such that $$$1 < i \le n$$$. For example, if $$$n = 5$$$, $$$m = 7$$$, $$$c = 4$$$, and $$$s = 10$$$, then $$$a = [3, 0, 4, 1, 5]$$$.Price of such an array is the value of $$$m$$$ in this generator.Alex has a question: how much money he can get for each of the arrays. Please, help him to understand for every array whether there exist four numbers $$$n$$$, $$$m$$$, $$$c$$$, $$$s$$$ that generate this array. If yes, then maximize $$$m$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of arrays. The first line of array description contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the size of this array. The second line of array description contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$ ) — elements of the array.  It is guaranteed that the sum of array sizes does not exceed $$$10^5$$$.

For every array print:    $$$-1$$$, if there are no such four numbers that generate this array;  $$$0$$$, if $$$m$$$ can be arbitrary large;  the maximum value $$$m$$$ and any appropriate $$$c$$$ ($$$0 \leq c < m$$$) in other cases.


Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points.

The first line contains an integer n, which is the number of contestants in the room (1 ≤ n ≤ 50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" — it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers:    0 ≤ plusi, minusi ≤ 50;  150 ≤ ai ≤ 500 or ai = 0, if problem A is not solved;  300 ≤ bi ≤ 1000 or bi = 0, if problem B is not solved;  450 ≤ ci ≤ 1500 or ci = 0, if problem C is not solved;  600 ≤ di ≤ 2000 or di = 0, if problem D is not solved;  750 ≤ ei ≤ 2500 or ei = 0, if problem E is not solved.  All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points).

Print on the single line the handle of the room leader.

NoteThe number of points that each participant from the example earns, are as follows:   Petr — 3860  tourist — 4140  Egor — 4030  c00lH4x0R —  - 350  some_participant — 2220 Thus, the leader of the room is tourist.

<?php
$a = trim(fgets(STDIN));
$j = array();
$k = array();
for($x = 1; $x <= $a; $x++)
{
    list($b, $c, $d, $e, $f, $g, $h, $i) = explode(" ", trim(fgets(STDIN)));
    array_push($j, $b);
    $l = $c * 100 - $d * 50 + $e + $f + $g + $h + $i;
    array_push($k, $l);
}
arsort($k);
$m = array_keys($k);
print $j[$m[0]];
?>

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=explode(' ',trim(fgets(STDIN)));

//print_r($arr);
foreach($arr as $val){
    $sum[]=array($val[0],$val[1]*100-$val[2]*50+$val[3]+$val[4]+$val[5]+$val[6]+$val[7]);
}
function cmp($a,$b){
    return $a[1]<$b[1];
}
//print_r($sum);
usort($sum,'cmp');
//print_r($sum);
echo $sum[0][0];
?>


The only difference between easy and hard versions is constraints.There are $$$n$$$ kids, each of them is reading a unique book. At the end of any day, the $$$i$$$-th kid will give his book to the $$$p_i$$$-th kid (in case of $$$i = p_i$$$ the kid will give his book to himself). It is guaranteed that all values of $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i.e. $$$p$$$ is a permutation). The sequence $$$p$$$ doesn't change from day to day, it is fixed.For example, if $$$n=6$$$ and $$$p=[4, 6, 1, 3, 5, 2]$$$ then at the end of the first day the book of the $$$1$$$-st kid will belong to the $$$4$$$-th kid, the $$$2$$$-nd kid will belong to the $$$6$$$-th kid and so on. At the end of the second day the book of the $$$1$$$-st kid will belong to the $$$3$$$-th kid, the $$$2$$$-nd kid will belong to the $$$2$$$-th kid and so on.Your task is to determine the number of the day the book of the $$$i$$$-th child is returned back to him for the first time for every $$$i$$$ from $$$1$$$ to $$$n$$$.Consider the following example: $$$p = [5, 1, 2, 4, 3]$$$. The book of the $$$1$$$-st kid will be passed to the following kids:  after the $$$1$$$-st day it will belong to the $$$5$$$-th kid,  after the $$$2$$$-nd day it will belong to the $$$3$$$-rd kid,  after the $$$3$$$-rd day it will belong to the $$$2$$$-nd kid,  after the $$$4$$$-th day it will belong to the $$$1$$$-st kid. So after the fourth day, the book of the first kid will return to its owner. The book of the fourth kid will return to him for the first time after exactly one day.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of kids in the query. The second line of the query contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$, all $$$p_i$$$ are distinct, i.e. $$$p$$$ is a permutation), where $$$p_i$$$ is the kid which will get the book of the $$$i$$$-th kid.

For each query, print the answer on it: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ is the number of the day the book of the $$$i$$$-th child is returned back to him for the first time in this query.


During a daily walk Alina noticed a long number written on the ground. Now Alina wants to find some positive number of same length without leading zeroes, such that the sum of these two numbers is a palindrome. Recall that a number is called a palindrome, if it reads the same right to left and left to right. For example, numbers $$$121, 66, 98989$$$ are palindromes, and $$$103, 239, 1241$$$ are not palindromes.Alina understands that a valid number always exist. Help her find one!

The first line of input data contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. Next, descriptions of $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 100\,000$$$) — the length of the number that is written on the ground. The second line of contains the positive $$$n$$$-digit integer without leading zeroes — the number itself. It is guaranteed that the sum of the values $$$n$$$ over all test cases does not exceed $$$100\,000$$$.

For each of $$$t$$$ test cases print an answer — a positive $$$n$$$-digit integer without leading zeros, such that the sum of the input integer and this number is a palindrome. We can show that at least one number satisfying the constraints exists. If there are multiple solutions, you can output any of them.

NoteIn the first test case $$$99 + 32 = 131$$$ is a palindrome. Note that another answer is $$$12$$$, because $$$99 + 12 = 111$$$ is also a palindrome.In the second test case $$$1023 + 8646 = 9669$$$.In the third test case $$$385 + 604 = 989$$$.

<?php

$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $h = trim(fgets(STDIN));
    $num = trim(fgets(STDIN));
    $str = "";
    if ($num[0] == 9) {
        for ($m = 1; $m <= $h + 1; $m++) {
            $str .= 1;
        }

    } else {
        for ($m = 1; $m <= $h; $m++) {
            $str .= 9;
        }
    }

    array_push($array, bcsub($str, $num));
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $h = trim(fgets(STDIN));
    $num = trim(fgets(STDIN));
    $str = "";
    if ($num[0] <= 8) {
        for ($m = 1; $m <= $h; $m++) {
            $str .= 9;
        }
    } else {
        for ($m = 1; $m <= $h + 1; $m++) {
            $str .= 1;
        }
    }

    array_push($array, bcsub($str, $num));
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}

function solve()
{
    $n = IO::get();
    $s = IO::get();
   $sPolindrom = '';
   if($s[0] == '9') {
        $ss = 1;
        $n +=1;
   } else {
      $ss = '9';
   }
     for($i=0; $i<$n; $i++) {
          $sPolindrom .= $ss;
     }
     $ans = bcsub($sPolindrom, $s);
       IO::pr($ans);

}

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

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

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d", $n);
    fscanf(STDIN, "%s", $a);
    $b = ($value = $a[0]+2) . substr($a, 1);
    $k = intval((strlen($value) + $n - 1)/2);
    printf("%s\n", bcsub(($b = substr($b, 0, $k*-1)).strrev(substr($b, 0, $k)), $a));
}

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $h = trim(fgets(STDIN));
    $num = trim(fgets(STDIN));
    $str = "";
    if ($num[0] <= 8) {
        for ($m = 1; $m <= $h; $m++) {
            $str .= 7;
        }
    } else {
        for ($m = 1; $m <= $h + 1; $m++) {
            $str .= 1;
        }
    }

    array_push($array, bcsub($str, $num));
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $h = trim(fgets(STDIN));
    $num = trim(fgets(STDIN));
    $str = "";
    if ($num[0] <= 8) {
        for ($m = 1; $m <= $h; $m++) {
            $str .= 7;
        }
    } else {
        for ($m = 1; $m <= $h+1; $m++) {
            $str .= 1;
        }
    }

    $sum = $str - $num;
    array_push($array, $sum);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $h = trim(fgets(STDIN));
    $num = trim(fgets(STDIN));
    $str = "";
    if ($num[0] <= 8) {
        for ($m = 1; $m <= $h; $m++) {
            $str .= 9;
        }
    } else {
        for ($m = 1; $m <= $h; $m++) {
            $str .= 1;
        }
    }

    $sum = $str - $num;
    array_push($array, $sum);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php

$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $h = trim(fgets(STDIN));
    $num = trim(fgets(STDIN));
    $str = "";
    if ($num[0] <= 8) {
        for ($m = 1; $m <= $h; $m++) {
            $str .= 9;
        }
    } else {
        for ($m = 1; $m <= $h + 1; $m++) {
            $str .= 1;
        }
    }

    $sum = $str - $num;
    array_push($array, $sum);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}

function solve()
{
    $n = IO::get();
    $s = IO::get();
   $sPolindrom = '';
   $ss = (int)$s[0] + 1;
   if($ss == 10) {
        $ss = 1;
        $n +=1;
   }
     for($i=0; $i<$n; $i++) {
          $sPolindrom .= $ss;
     }
     $ans = bcsub($sPolindrom, $s);
       IO::pr($ans);

}

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

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

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}

function solve()
{
    $n = IO::get();
    $s = IO::get();
   $sPolindrom = '';
     for($i=0; $i<$n+1; $i++) {
          $sPolindrom .= '9';
     }
     $ans = bcsub($sPolindrom, $s);
       IO::pr($ans);

}

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

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

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}

function solve()
{
     $n = IO::get();
     $s = IO::get();
     $ss = [];
     for($i=0; $i<$n; $i++) {
          if(isset($ss[$s[$i]])) {
              $ss[$s[$i]] += 1;
          } else {
               $ss[$s[$i]] = 1;
          }
     }
     $sa = array_keys($ss);
     $pN = 0;

     for($i=1; $i < 10; $i++) {
         if(!isset($ss[$i])) {
             $pN = $i;
             break;
         }
     }
     if($pN == 0) {
        $sRev = strrev($s);
        $tt = bcadd($s, $sRev);
        for($i=1; $i<10; $i++) {
             $sPolindrom = '';
            for($w=0; $w<strlen($tt) + 1; $w++) {
                   $sPolindrom .= $i;
            }
          $ans = bcsub($sPolindrom, $s);
          $bs = true;
          for($j=1; $j<strlen($ans) ; $j++) {
               if($ans[$i] == 0 && $ans[$i] == $ans[$i-1]) {
                   $bs = false;
                   break;
               }
          }
          if($bc) {
               break;
          }

        }

     } else {
         if($pN > max($sa)) {
                $nCount = $n;
          } else {
              $nCount = $n +1;
          }
          $sPolindrom = '';
          for($i=0; $i<$nCount; $i++) {
              $sPolindrom .= $pN;
          }
          $ans = bcsub($sPolindrom, $s);
     }

       IO::pr($ans);

}

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

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

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}

function solve()
{
     $n = IO::get();
     $s = IO::get();
     $ss = [];
     for($i=0; $i<$n; $i++) {
         $ss[$s[$i]] = 1;
     }
     $sa = array_keys($ss);
     $pN = 0;

     for($i=1; $i < 10; $i++) {
         if(!isset($ss[$i])) {
             $pN = $i;
             break;
         }
     }
     if($pN > max($sa)) {
         $nCount = $n;
     } else {
         $nCount = $n +1;
     }
     $sPolindrom = '';
     for($i=0; $i<$nCount; $i++) {
         $sPolindrom .= $pN;
     }
     $ans = bcsub($sPolindrom, $s);

       IO::pr($ans);

}

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

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

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}

function solve()
{
     $n = IO::get();
     $s = IO::get();
     $ss = [];
     for($i=0; $i<$n; $i++) {
         $ss[$s[$i]] = 1;
     }
     $pN = 0;
     $nCount = $n;
     for($i=9; $i > 0; $i--) {
         if(!isset($ss[$i])) {
             $pN = $i;
             if($i < 9) {
                 $nCount += 1;
             }
             break;
         }
     }
     $sPolindrom = '';
     for($i=0; $i<$nCount; $i++) {
         $sPolindrom .= $pN;
     }
     $ans = bcsub($sPolindrom, $s);

       IO::pr($ans);

}

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

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

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d", $n);
    fscanf(STDIN, "%s", $a);
    $k = intval($n/2);
    $b = substr($a, 0, $k*-1);
    $value = $b[0]+2;
    $b = $value . substr($b, strlen($value));
    printf("%s\n", bcsub($b.strrev(substr($b, 0, $k)), $a));
}


Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.The game rules are like this. Firstly Alice chooses some color A, then Bob chooses some color B (A ≠ B). After each car they update the number of cars of their chosen color that have run past them. Let's define this numbers after i-th car cntA(i) and cntB(i).  If cntA(i) > cntB(i) for every i then the winner is Alice.  If cntB(i) ≥ cntA(i) for every i then the winner is Bob.  Otherwise it's a draw. Bob knows all the colors of cars that they will encounter and order of their appearance. Alice have already chosen her color A and Bob now wants to choose such color B that he will win the game (draw is not a win). Help him find this color.If there are multiple solutions, print any of them. If there is no such color then print -1.

The first line contains two integer numbers n and A (1 ≤ n ≤ 105, 1 ≤ A ≤ 106) – number of cars and the color chosen by Alice. The second line contains n integer numbers c1, c2, ..., cn (1 ≤ ci ≤ 106) — colors of the cars that Alice and Bob will encounter in the order of their appearance.

Output such color B (1 ≤ B ≤ 106) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1. It is guaranteed that if there exists any solution then there exists solution with (1 ≤ B ≤ 106).

NoteLet's consider availability of colors in the first example:   cnt2(i) ≥ cnt1(i) for every i, and color 2 can be the answer.  cnt4(2) < cnt1(2), so color 4 isn't the winning one for Bob.  All the other colors also have cntj(2) < cnt1(2), thus they are not available. In the third example every color is acceptable except for 10.


There's a chessboard of size $$$n \times n$$$. $$$m$$$ rooks are placed on it in such a way that:   no two rooks occupy the same cell;  no two rooks attack each other. A rook attacks all cells that are in its row or column.Is it possible to move exactly one rook (you can choose which one to move) into a different cell so that no two rooks still attack each other? A rook can move into any cell in its row or column if no other rook stands on its path.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the size of the chessboard and the number of the rooks. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$) — the position of the $$$i$$$-th rook: $$$x_i$$$ is the row and $$$y_i$$$ is the column. No two rooks occupy the same cell. No two rooks attack each other.

For each testcase, print "YES" if it's possible to move exactly one rook into a different cell so that no two rooks still attack each other. Otherwise, print "NO".

NoteIn the first testcase, the rooks are in the opposite corners of a $$$2 \times 2$$$ board. Each of them has a move into a neighbouring corner, but moving there means getting attacked by another rook.In the second testcase, there's a single rook in a middle of a $$$3 \times 3$$$ board. It has $$$4$$$ valid moves, and every move is fine because there's no other rook to attack it.

<?php
      $inp = preg_split('#\s+#', trim(file_get_contents("php://stdin")));
      $p = 0;
      $tests = intval($inp[$p++]);
      for($test=0;$test<$tests;$test++)
      {
        $n = intval($inp[$p++]);
        $m = intval($inp[$p++]);
        $p += 2*$m;
        if ($m < $n) printf("YES\n"); else printf("NO\n");

      }


You are given an integer $$$x$$$. Can you make $$$x$$$ by summing up some number of $$$11, 111, 1111, 11111, \ldots$$$? (You can use any number among them any number of times).For instance,   $$$33=11+11+11$$$  $$$144=111+11+11+11$$$

The first line of input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10000)$$$ — the number of testcases. The first and only line of each testcase contains a single integer $$$x$$$ $$$(1 \leq x \leq 10^9)$$$ — the number you have to make.

For each testcase, you should output a single string. If you can make $$$x$$$, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower).

NoteWays to make $$$33$$$ and $$$144$$$ were presented in the statement. It can be proved that we can't present $$$69$$$ this way.

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $f = 0;

  if ($n < 11) { echo 'NO'.PHP_EOL; }
  else {
    if ($n % 11 == 0) { echo 'YES'.PHP_EOL; }
    else {
      if (111 * ($n % 11) <= $n) { echo 'YES'.PHP_EOL; }
      else { echo 'NO'.PHP_EOL; }

    }
  }
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $f = 0;

  if ($n < 11) { echo 'NO'.PHP_EOL; }
  else {
    if ($n % 11 == 0) { echo 'YES'.PHP_EOL; }
    else {

      while ($n > 10) {
        $n -= 111;

        if ($n == 0) { echo 'YES'.PHP_EOL; $f = 1; break; }
        if ($n % 11 == 0) { echo 'YES'.PHP_EOL; $f = 1; break; }
      }

      if ($f == 0) { echo 'NO'.PHP_EOL; }
    }
  }
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $f = 0;

  if ($n < 11) { echo 'NO'.PHP_EOL; }
  else {
    if ($n % 11 == 0) { echo 'YES'.PHP_EOL; }
    else {

      while ($n > 0) {
        $n -= 111;
        if ($n <= 0) { break; }
        if ($n % 11 == 0) { echo 'YES'.PHP_EOL; $f = 1; break; }
      }

      if ($f == 0) { echo 'NO'.PHP_EOL; }
    }
  }
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $f = 0;

  if ($n < 11) { echo 'NO'.PHP_EOL; }
  else {
    if ($n % 11 == 0) { echo 'YES'.PHP_EOL; }
    else {

      while ($n > 0) {
        if ($n % 11 == 0) { echo 'YES'.PHP_EOL; $f = 1; break; }
        $n -= 111;
      }

      if ($f == 0) { echo 'NO'.PHP_EOL; }
    }
  }
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $f = 0;

  if ($n < 11) { echo 'NO'.PHP_EOL; }
  else {

    while ($n > 10) {
      if ($n % 11 == 0) { echo 'YES'.PHP_EOL; $f = 1; break; }
      $n -= 111;
    }

    if ($f == 0) { echo 'NO'.PHP_EOL; }
  }
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $f = 0;

  if ($n < 11) { echo 'NO'.PHP_EOL; }
  else {
    if ($n % 11 == 0) { echo 'YES'.PHP_EOL; }
    else {

      while ($n > 10) {
        $n -= 111;
        if ($n % 11 == 0) { echo 'YES'.PHP_EOL; $f = 1; break; }
      }

      if ($f == 0) { echo 'NO'.PHP_EOL; }
    }
  }
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $f = 0;

  if ($n < 11) { echo 'NO'.PHP_EOL; }
  else {
    if ($n % 11 == 0) { echo 'YES'.PHP_EOL; }
    else {
      $len = strlen($n);
      while ($n > 10) {
        $c = '';
        $len = strlen($n);
        while ($len--) { $c .= 1; }
        $n = $n - $c;
        if ($n % 11 == 0) { echo 'YES'.PHP_EOL; $f = 1; break; }
      }

      if ($f == 0) { echo 'NO'.PHP_EOL; }
    }
  }
}

?>


Today the «Z» city residents enjoy a shell game competition. The residents are gathered on the main square to watch the breath-taking performance. The performer puts 3 non-transparent cups upside down in a row. Then he openly puts a small ball under one of the cups and starts to shuffle the cups around very quickly so that on the whole he makes exactly 3 shuffles. After that the spectators have exactly one attempt to guess in which cup they think the ball is and if the answer is correct they get a prize. Maybe you can try to find the ball too?

The first input line contains an integer from 1 to 3 — index of the cup which covers the ball before the shuffles. The following three lines describe the shuffles. Each description of a shuffle contains two distinct integers from 1 to 3 — indexes of the cups which the performer shuffled this time. The cups are numbered from left to right and are renumbered after each shuffle from left to right again. In other words, the cup on the left always has index 1, the one in the middle — index 2 and the one on the right — index 3.

In the first line output an integer from 1 to 3 — index of the cup which will have the ball after all the shuffles.


You are given an array $$$a_1, a_2, \dots a_n$$$. Count the number of pairs of indices $$$1 \leq i, j \leq n$$$ such that $$$a_i < i < a_j < j$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the number of pairs of indices satisfying the condition in the statement. Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

<?php

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

function readInt() {
	return (int) read() ;
}

function readStrs() {
	return explode(" ",read()) ;
}

function readIntArray() {
	return array_map('intval', readStrs());
}

function readAsArray() {
	return str_split(read()) ;
}

function printLine($arg) {

	print_r($arg) ;
	print_r("\n") ;

}

$t = readInt() ;

while($t--) {
	$n = readInt() ;
	$arr = readIntArray() ;
	asort($arr) ;
	$con = array();
	$tot = 0;
	$glue = array() ;
	foreach($arr as $k=>$v) {
		if($k < $v) {
			continue ;
		}
		if(!isset($con[$v])) {
			$con[$v] = [] ;
		}
		$tot += 1 ;
		array_push($con[$v],$k+1) ;
		array_push($glue,$k+1,$v) ;
	}
	// printLine($con);
	$glue = array_unique($glue);
	sort($glue) ;
	// printLine($glue);
	$tl = count($glue) ;
	$susu  = array() ;
	$mew = 0 ;
	$fans = 0 ;
	foreach($con as $k=>$v) {
		$mew += count($v) ;
		$susu[$k] = $mew ;
	}
	// printLine($tl);
	// printLine(!isset($susu[$glue[1]]));
	for($i=0;$i<$tl;$i++) {
		if(!isset($susu[$glue[$i]])) {
			$susu[$glue[$i]] = $susu[$glue[$i-1]] ;
		}
	}
	// printLine($susu);

	foreach($con as $k=>$v) {
		$sz = count($v);
		for($j=0;$j<$sz;$j++) {
			$fans += $tot - $susu[$v[$j]] ;
		}
	}
	printLine($fans);
}


Gregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them.Gregor's favorite prime number is $$$P$$$. Gregor wants to find two bases of $$$P$$$. Formally, Gregor is looking for two integers $$$a$$$ and $$$b$$$ which satisfy both of the following properties.  $$$P \bmod a = P \bmod b$$$, where $$$x \bmod y$$$ denotes the remainder when $$$x$$$ is divided by $$$y$$$, and  $$$2 \le a < b \le P$$$. Help Gregor find two bases of his favorite prime number!

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Each subsequent line contains the integer $$$P$$$ ($$$5 \le P \le {10}^9$$$), with $$$P$$$ guaranteed to be prime.

Your output should consist of $$$t$$$ lines. Each line should consist of two integers $$$a$$$ and $$$b$$$ ($$$2 \le a < b \le P$$$). If there are multiple possible solutions, print any.

NoteThe first query is $$$P=17$$$. $$$a=3$$$ and $$$b=5$$$ are valid bases in this case, because $$$17 \bmod 3 = 17 \bmod 5 = 2$$$. There are other pairs which work as well.In the second query, with $$$P=5$$$, the only solution is $$$a=2$$$ and $$$b=4$$$.

<?php

list($t) = explode(' ', trim(fgets(STDIN)));

for ($i = 0; $i < $t; $i++) {
    list($p) = explode(' ', trim(fgets(STDIN)));
    echo "2 ". strval($p - 1) . "\n";
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $n -= 1;
  echo '2'.' '.$n.PHP_EOL;
}

?>


Petya and Vasya are competing with each other in a new interesting game as they always do.At the beginning of the game Petya has to come up with an array of $$$N$$$ positive integers. Sum of all elements in his array should be equal to $$$S$$$. Then Petya has to select an integer $$$K$$$ such that $$$0 \leq K \leq S$$$.In order to win, Vasya has to find a non-empty subarray in Petya's array such that the sum of all selected elements equals to either $$$K$$$ or $$$S - K$$$. Otherwise Vasya loses.You are given integers $$$N$$$ and $$$S$$$. You should determine if Petya can win, considering Vasya plays optimally. If Petya can win, help him to do that.

The first line contains two integers $$$N$$$ and $$$S$$$ ($$$1 \leq N \leq S \leq 10^{6}$$$) — the required length of the array and the required sum of its elements.

If Petya can win, print "YES" (without quotes) in the first line. Then print Petya's array in the second line. The array should contain $$$N$$$ positive integers with sum equal to $$$S$$$. In the third line print $$$K$$$. If there are many correct answers, you can print any of them. If Petya can't win, print "NO" (without quotes). You can print each letter in any register (lowercase or uppercase).

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

//     $t = intval(trim(fgets(STDIN))) ;
//     while($t --)
//     {
//     }

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

    $n = intval($in_str[0]) ;
    $k = intval($in_str[1]) ;

    if(2 * $n - 1 >= $k ) echo "NO\n" ;
    else
    {
        $ans = array_fill(0, $n, 1) ;
        $ans[$n - 1] = $k - $n + 1 ;

        echo "YES\n" ;
        echo implode(" ", $ans) . "\n" ;
        echo $n . "\n" ;
    }
?>

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

//     $t = intval(trim(fgets(STDIN))) ;
//     while($t --)
//     {
//     }

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

    $n = intval($in_str[0]) ;
    $k = intval($in_str[1]) ;

    if($n == 1 && $k == 1)
    {
        echo "NO\n" ;
        exit() ;
    }

    if(2 * $n - 2 >= $k) echo "NO\n" ;
    else
    {
        $ans = array_fill(0, $n, 1) ;
        $ans[$n - 1] = $k - $n + 1 ;

        echo "YES\n" ;
        echo implode(" ", $ans) . "\n" ;
        echo $n . "\n" ;
    }
?>

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

//     $t = intval(trim(fgets(STDIN))) ;
//     while($t --)
//     {
//     }

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

    $n = intval($in_str[0]) ;
    $k = intval($in_str[1]) ;

    if(2 * $n - 2 >= $k) echo "NO\n" ;
    else
    {
        $ans = array_fill(0, $n, 1) ;
        $ans[$n - 1] = $k - $n + 1 ;

        echo "YES\n" ;
        echo implode(" ", $ans) . "\n" ;
        echo $n . "\n" ;
    }
?>

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

//     $t = intval(trim(fgets(STDIN))) ;
//     while($t --)
//     {
//     }

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

    $n = intval($in_str[0]) ;
    $k = intval($in_str[1]) ;

    if(2 * $n - 2 >= $k) echo "NO\n" ;
    else
    {
        $ans = array_fill(0, $n, 1) ;
        $ans[$n - 1] = $k - $n + 1 ;

        echo implode(" ", $ans) . "\n" ;
        echo $n . "\n" ;
    }
?>


William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ is picked, which is then used to perform one of the following operations: (note, that for each operation you can choose a new positive integer $$$k$$$)  add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or  add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or  add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.

For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.

NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$:  Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$.  Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$.  Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$.  Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d %d", $c, $d);
    if (0 == $c && 0 == $d) {
        echo 0;
    } elseif ($c == $d) {
        echo 1;
    } elseif ((abs($c) + abs($d)) & 1) {
        echo -1;
    } else {
        echo 2;
    }
    echo "\n";
}


For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operations grew. So the King ordered to found the Bank of Far Far Away and very soon even the rounding didn't help to quickly determine even the order of the numbers involved in operations. Besides, rounding a number to an integer wasn't very convenient as a bank needed to operate with all numbers with accuracy of up to 0.01, and not up to an integer.The King issued yet another order: to introduce financial format to represent numbers denoting amounts of money. The formal rules of storing a number in the financial format are as follows:   A number contains the integer part and the fractional part. The two parts are separated with a character "." (decimal point).  To make digits in the integer part of a number easier to read, they are split into groups of three digits, starting from the least significant ones. The groups are separated with the character "," (comma). For example, if the integer part of a number equals 12345678, then it will be stored in the financial format as 12,345,678  In the financial format a number's fractional part should contain exactly two digits. So, if the initial number (the number that is converted into the financial format) contains less than two digits in the fractional part (or contains no digits at all), it is complemented with zeros until its length equals 2. If the fractional part contains more than two digits, the extra digits are simply discarded (they are not rounded: see sample tests).  When a number is stored in the financial format, the minus sign is not written. Instead, if the initial number had the minus sign, the result is written in round brackets.  Please keep in mind that the bank of Far Far Away operates using an exotic foreign currency — snakes ($), that's why right before the number in the financial format we should put the sign "$". If the number should be written in the brackets, then the snake sign should also be inside the brackets. For example, by the above given rules number 2012 will be stored in the financial format as "$2,012.00" and number -12345678.9 will be stored as "($12,345,678.90)".The merchants of Far Far Away visited you again and expressed much hope that you supply them with the program that can convert arbitrary numbers to the financial format. Can you help them?

The input contains a number that needs to be converted into financial format. The number's notation length does not exceed 100 characters, including (possible) signs "-" (minus) and "." (decimal point). The number's notation is correct, that is:    The number's notation only contains characters from the set {"0" – "9", "-", "."}.  The decimal point (if it is present) is unique and is preceded and followed by a non-zero quantity on decimal digits  A number cannot start with digit 0, except for a case when its whole integer part equals zero (in this case the integer parts is guaranteed to be a single zero: "0").  The minus sign (if it is present) is unique and stands in the very beginning of the number's notation  If a number is identically equal to 0 (that is, if it is written as, for example, "0" or "0.000"), than it is not preceded by the minus sign.  The input data contains no spaces.  The number's notation contains at least one decimal digit.

Print the number given in the input in the financial format by the rules described in the problem statement.

NotePay attention to the second and third sample tests. They show that the sign of a number in the financial format (and consequently, the presence or absence of brackets) is determined solely by the sign of the initial number. It does not depend on the sign of the number you got after translating the number to the financial format.

<?php
error_reporting("off");
//143B: Help Kingdom of Far Far Away 2
$n = str_split(trim(fgets(STDIN))); //$n = str_split("-12345678.9");
$negative = FALSE;
if ($n[0] == "-") { //if negative, set negative to true and pop the - sign off the front and reset keys
    $negative = TRUE;
    unset($n[0]);
    $n = array_values($n);
}
$nodot = FALSE;
$explodeint = array(); //the integer part, in pieces in an array
$dot = array_search(".", $n);
if ($dot == FALSE) { //if there's no dot we need to know
    $nodot = TRUE;
    $explodeint = $n;
} else {
    for ($i = 0; $i < $dot; $i++) {
        $explodeint[] = $n[$i];
    }
}

//ahh string manipuation. love it. except for the fact that this has to involve arrays.
$reverse = array_reverse($explodeint); //the only reason explodeint is in an array in the first place
$implode = implode($reverse);
$threechunk = str_split($implode, 3);
$commas = implode(",", $threechunk);
$splitagain = str_split($commas);
$reverseagain = array_reverse($splitagain);
$int = implode($reverseagain);

if ($nodot == TRUE) { //if there's no dot, the decimal is just 00.
    $decimal = "00";
} elseif (!isset($n[$dot + 2])) { //if only one decimal place is set, you need to add a zero.
    $decimal = $n[$dot + 1]."0";
} else { //otherwise, just choose the first two decimal places.
    $decimal = $n[$dot + 1].$n[$dot + 2];
}

$value = $int.".".$decimal;
$snake = "$".$value; //dat "snake" sign

if ($negative == TRUE) { //if it's negative, wrap in parentheses
    echo "(".$snake.")";
} else {
    echo $snake;
}
?>


Vasya decided to go to the grocery store. He found in his wallet $$$a$$$ coins of $$$1$$$ burle and $$$b$$$ coins of $$$2$$$ burles. He does not yet know the total cost of all goods, so help him find out $$$s$$$ ($$$s > 0$$$): the minimum positive integer amount of money he cannot pay without change or pay at all using only his coins.For example, if $$$a=1$$$ and $$$b=1$$$ (he has one $$$1$$$-burle coin and one $$$2$$$-burle coin), then:  he can pay $$$1$$$ burle without change, paying with one $$$1$$$-burle coin,  he can pay $$$2$$$ burle without change, paying with one $$$2$$$-burle coin,  he can pay $$$3$$$ burle without change by paying with one $$$1$$$-burle coin and one $$$2$$$-burle coin,  he cannot pay $$$4$$$ burle without change (moreover, he cannot pay this amount at all). So for $$$a=1$$$ and $$$b=1$$$ the answer is $$$s=4$$$.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The description of each test case consists of one line containing two integers $$$a_i$$$ and $$$b_i$$$ ($$$0 \le a_i, b_i \le 10^8$$$) — the number of $$$1$$$-burle coins and $$$2$$$-burles coins Vasya has respectively.

For each test case, on a separate line print one integer $$$s$$$ ($$$s > 0$$$): the minimum positive integer amount of money that Vasya cannot pay without change or pay at all.

Note  The first test case of the example is clarified into the main part of the statement.  In the second test case, Vasya has only $$$1$$$ burle coins, and he can collect either any amount from $$$1$$$ to $$$4$$$, but $$$5$$$ can't.  In the second test case, Vasya has only $$$2$$$ burle coins, and he cannot pay $$$1$$$ burle without change.  In the fourth test case you don't have any coins, and he can't even pay $$$1$$$ burle.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     if($b == 0)
     {
          print "1\n";
     }
     else
     {
          print $c * 2 + $b + 1 . "\n";
     }
}
?>

<?php
// $stdin = fopen('input.txt', 'r');

$solve = function ($a, $b) {

	if($a == 0){
		return 1;
	} else {
		return $b * 2 + $a + 1;
	}

};

$t = intval(fgets(STDIN));

for (; $t > 0; $t--) {

	$a = explode(' ', fgets(STDIN));

	echo $solve(intval($a[0]), intval($a[1]));
	echo "\n";

}


The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. n best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. n·(n - 1) / 2 games were played during the tournament, and each participant had a match with each other participant. The rules of the game are quite simple — the participant who falls asleep first wins. The secretary made a record of each game in the form «xi yi», where xi and yi are the numbers of participants. The first number in each pair is a winner (i.e. xi is a winner and yi is a loser). There is no draws.Recently researches form the «Institute Of Sleep» have found that every person is characterized by a value pj — the speed of falling asleep. The person who has lower speed wins. Every person has its own value pj, constant during the life. It is known that all participants of the tournament have distinct speeds of falling asleep. Also it was found that the secretary made records about all the games except one. You are to find the result of the missing game.

The first line contains one integer n (3 ≤ n ≤ 50) — the number of participants. The following n·(n - 1) / 2 - 1 lines contain the results of the games. Each game is described in a single line by two integers xi, yi (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi и yi are the numbers of the opponents in this game. It is known that during the tournament each of the n participants played n - 1 games, one game with each other participant.

Output two integers x and y — the missing record. If there are several solutions, output any of them.


Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≤ bi ≤ ai for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array.Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.

Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.

NoteIn the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.To reach the answer to the second sample case one must not decrease any of the array elements.

<?php
$fp = fopen('php://stdin', 'r');
$n = (int)fgets($fp);
$numbers = array_map('intval', explode(' ', fgets($fp)));
sort($numbers);
$mex = 1;
foreach($numbers as $number) {
	if ($mex <= $number) {
		++$mex;
	}
}
echo $mex;


You are given an array $$$a$$$ of $$$n$$$ integers, where $$$n$$$ is odd. You can make the following operation with it:  Choose one of the elements of the array (for example $$$a_i$$$) and increase it by $$$1$$$ (that is, replace it with $$$a_i + 1$$$). You want to make the median of the array the largest possible using at most $$$k$$$ operations.The median of the odd-sized array is the middle element after the array is sorted in non-decreasing order. For example, the median of the array $$$[1, 5, 2, 3, 5]$$$ is $$$3$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$n$$$ is odd, $$$1 \le k \le 10^9$$$) — the number of elements in the array and the largest number of operations you can make. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).

Print a single integer — the maximum possible median after the operations.

NoteIn the first example, you can increase the second element twice. Than array will be $$$[1, 5, 5]$$$ and it's median is $$$5$$$.In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $$$3$$$.In the third example, you can make four operations: increase first, fourth, sixth, seventh element. This way the array will be $$$[5, 1, 2, 5, 3, 5, 5]$$$ and the median will be $$$5$$$.

<?php
	$cin = fopen("php://stdin", "r");
	$s = fgets($cin);
	$a = explode(" ", $s);
	$n = intval($a[0]);
	$k = intval($a[1]);
	$s = fgets($cin);
	$a = explode(" ", $s);
	sort($a,SORT_NUMERIC);
	$ans = 0;
	$mid = intval($n / 2);
	for($i = $mid+1; $i < $n; $i++){
		if($k >= ($i - $mid) * (intval($a[$i]) - intval($a[$i-1]))){
			$k = $k - ($i - $mid) * (intval($a[$i]) - intval($a[$i-1]));
			$ans = $ans + (intval($a[$i]) - intval($a[$i-1]));
		}
		else{
			break;
		}
	}
	if($k > 0){
		$ans = $ans + intval($k / ($i - $mid));
	}
	print_r(intval($ans + intval($a[$mid]))."\n");
	fclose($cin);
?>

<?php
	$cin = fopen("php://stdin", "r");
	$s = fgets($cin);
	$a = explode(" ", $s);
	$n = intval($a[0]);
	$k = intval($a[1]);
	$s = fgets($cin);
	$a = explode(" ", $s);
	for($i = 0; $i < sizeof($a); $i++){
		$a[$i] = intval($a[$i]);
	}
	sort($a);
	$ans = 0;
	$mid = intval($n / 2);
	for($i = $mid+1; $i < $n; $i++){
		if($k >= ($i - $mid) * (intval($a[$i]) - intval($a[$i-1]))){
			$k = $k - ($i - $mid) * (intval($a[$i]) - intval($a[$i-1]));
			$ans = $ans + (intval($a[$i]) - intval($a[$i-1]));
		}
		else{
			break;
		}
	}
	if($k > 0){
		$ans = $ans + intval($k / ($i - $mid));
	}
	print_r(intval($ans + intval($a[$mid]))."\n");
	fclose($cin);
?>

<?php
	$cin = fopen("php://stdin", "r");
	$s = fgets($cin);
	$a = explode(" ", $s);
	$n = intval($a[0]);
	$k = intval($a[1]);
	$s = fgets($cin);
	$a = explode(" ", $s);
	sort($a);
	$ans = 0;
	$mid = intval($n / 2);
	for($i = $mid+1; $i < $n; $i++){
		if($k >= ($i - $mid) * (intval($a[$i]) - intval($a[$i-1]))){
			$k = $k - ($i - $mid) * (intval($a[$i]) - intval($a[$i-1]));
			$ans = $ans + (intval($a[$i]) - intval($a[$i-1]));
		}
		else{
			break;
		}
	}
	if($k > 0){
		$ans = $ans + intval($k / ($i - $mid));
	}

	print_r(intval($ans + intval($a[$mid]))."\n");
	fclose($cin);
?>


International Women's Day is coming soon! Polycarp is preparing for the holiday.There are $$$n$$$ candy boxes in the shop for sale. The $$$i$$$-th box contains $$$d_i$$$ candies.Polycarp wants to prepare the maximum number of gifts for $$$k$$$ girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by $$$k$$$. In other words, two boxes $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) can be combined as a gift if $$$d_i + d_j$$$ is divisible by $$$k$$$.How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le k \le 100$$$) — the number the boxes and the number the girls. The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$), where $$$d_i$$$ is the number of candies in the $$$i$$$-th box.

Print one integer — the maximum number of the boxes Polycarp can give as gifts.

NoteIn the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):   $$$(2, 3)$$$;  $$$(5, 6)$$$;  $$$(1, 4)$$$. So the answer is $$$6$$$.In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):   $$$(6, 8)$$$;  $$$(2, 3)$$$;  $$$(1, 4)$$$;  $$$(5, 7)$$$. So the answer is $$$8$$$.In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):   $$$(1, 2)$$$;  $$$(6, 7)$$$. So the answer is $$$4$$$.


One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai rating units as a present.The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.Help site X cope with the challenging task of rating distribution. Find the optimal distribution.

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 ≤ ai ≤ 109).

Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.  If there are multiple optimal solutions, print any of them.


Vlad, like everyone else, loves to sleep very much.Every day Vlad has to do $$$n$$$ things, each at a certain time. For each of these things, he has an alarm clock set, the $$$i$$$-th of them is triggered on $$$h_i$$$ hours $$$m_i$$$ minutes every day ($$$0 \le h_i < 24, 0 \le m_i < 60$$$). Vlad uses the $$$24$$$-hour time format, so after $$$h=12, m=59$$$ comes $$$h=13, m=0$$$ and after $$$h=23, m=59$$$ comes $$$h=0, m=0$$$.This time Vlad went to bed at $$$H$$$ hours $$$M$$$ minutes ($$$0 \le H < 24, 0 \le M < 60$$$) and asks you to answer: how much he will be able to sleep until the next alarm clock.If any alarm clock rings at the time when he went to bed, then he will sleep for a period of time of length $$$0$$$.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the test. The first line of the case contains three integers $$$n$$$, $$$H$$$ and $$$M$$$ ($$$1 \le n \le 10, 0 \le H < 24, 0 \le M < 60$$$) — the number of alarms and the time Vlad went to bed. The following $$$n$$$ lines contain two numbers each $$$h_i$$$ and $$$m_i$$$ ($$$0 \le h_i < 24, 0 \le m_i < 60$$$) — the time of the $$$i$$$ alarm. It is acceptable that two or more alarms will trigger at the same time. Numbers describing time do not contain leading zeros.

Output $$$t$$$ lines, each containing the answer to the corresponding test case. As an answer, output two numbers  — the number of hours and minutes that Vlad will sleep, respectively. If any alarm clock rings at the time when he went to bed, the answer will be 0 0.

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
     list($n, $h, $m) = IO::getArray();
     $sl = $h * 60 + $m;
     $min = 2147483646;
    for($i=0; $i<$n; $i++) {
         list($p, $k) = IO::getArray();
         $w = $p * 60 + $k;

         $temp = $sl > $w ? $w - $sl + 24*60 : $w - $sl;
     //    IO::pr($min . " " . $temp);
         $min = min($min, $temp);
    }
    $h1 = floor($min / 60);
    $m1 = $min % 60;

    $ans = $h1 . " " . $m1;
    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;
    }
}


A sequence $$$(b_1, b_2, \ldots, b_k)$$$ is called strange, if the absolute difference between any pair of its elements is greater than or equal to the maximum element in the sequence. Formally speaking, it's strange if for every pair $$$(i, j)$$$ with $$$1 \le i<j \le k$$$, we have $$$|a_i-a_j|\geq MAX$$$, where $$$MAX$$$ is the largest element of the sequence. In particular, any sequence of length at most $$$1$$$ is strange.For example, the sequences $$$(-2021, -1, -1, -1)$$$ and $$$(-1, 0, 1)$$$ are strange, but $$$(3, 0, 1)$$$ is not, because $$$|0 - 1| < 3$$$.Sifid has an array $$$a$$$ of $$$n$$$ integers. Sifid likes everything big, so among all the strange subsequences of $$$a$$$, he wants to find the length of the longest one. Can you help him?A sequence $$$c$$$ is a subsequence of an array $$$d$$$ if $$$c$$$ can be obtained from $$$d$$$ by deletion of several (possibly, zero or all) elements.

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

For each test case output a single integer — the length of the longest strange subsequence of $$$a$$$.

NoteIn the first test case, one of the longest strange subsequences is $$$(a_1, a_2, a_3, a_4)$$$In the second test case, one of the longest strange subsequences is $$$(a_1, a_3, a_4, a_5, a_7)$$$.In the third test case, one of the longest strange subsequences is $$$(a_1, a_3, a_4, a_5)$$$.In the fourth test case, one of the longest strange subsequences is $$$(a_2)$$$.In the fifth test case, one of the longest strange subsequences is $$$(a_1, a_2, a_4)$$$.


You are given an array $$$a$$$ of length $$$n$$$, which initially is a permutation of numbers from $$$1$$$ to $$$n$$$. In one operation, you can choose an index $$$i$$$ ($$$1 \leq i < n$$$) such that $$$a_i < a_{i + 1}$$$, and remove either $$$a_i$$$ or $$$a_{i + 1}$$$ from the array (after the removal, the remaining parts are concatenated). For example, if you have the array $$$[1, 3, 2]$$$, you can choose $$$i = 1$$$ (since $$$a_1 = 1 < a_2 = 3$$$), then either remove $$$a_1$$$ which gives the new array $$$[3, 2]$$$, or remove $$$a_2$$$ which gives the new array $$$[1, 2]$$$.Is it possible to make the length of this array equal to $$$1$$$ with these operations?

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 2 \cdot 10^4$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$)  — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \leq a_i \leq n$$$, $$$a_i$$$ are pairwise distinct) — elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.

For each test case, output on a single line the word "YES" if it is possible to reduce the array to a single element using the aforementioned operation, or "NO" if it is impossible to do so.

NoteFor the first two test cases and the fourth test case, we can operate as follow (the bolded elements are the pair chosen for that operation):$$$[\text{1}, \textbf{2}, \textbf{3}] \rightarrow [\textbf{1}, \textbf{2}] \rightarrow [\text{1}]$$$$$$[\text{3}, \textbf{1}, \textbf{2}, \text{4}] \rightarrow [\text{3}, \textbf{1}, \textbf{4}] \rightarrow [\textbf{3}, \textbf{4}] \rightarrow [\text{4}]$$$$$$[\textbf{2}, \textbf{4}, \text{6}, \text{1}, \text{3}, \text{5}] \rightarrow [\textbf{4}, \textbf{6}, \text{1}, \text{3}, \text{5}] \rightarrow [\text{4}, \text{1}, \textbf{3}, \textbf{5}] \rightarrow [\text{4}, \textbf{1}, \textbf{5}] \rightarrow [\textbf{4}, \textbf{5}] \rightarrow [\text{4}]$$$

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     if($c[0] > $c[$b - 1])
     {
          print "NO\n";
     }
     else
     {
          print "YES\n";
     }
}
?>


A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of $$$n$$$ rows and $$$m$$$ columns. The rows of the floor are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and columns of the floor are numbered from $$$1$$$ to $$$m$$$ from left to right. The cell on the intersection of the $$$r$$$-th row and the $$$c$$$-th column is denoted as $$$(r,c)$$$. The initial position of the robot is $$$(r_b, c_b)$$$.In one second, the robot moves by $$$dr$$$ rows and $$$dc$$$ columns, that is, after one second, the robot moves from the cell $$$(r, c)$$$ to $$$(r + dr, c + dc)$$$. Initially $$$dr = 1$$$, $$$dc = 1$$$. If there is a vertical wall (the left or the right walls) in the movement direction, $$$dc$$$ is reflected before the movement, so the new value of $$$dc$$$ is $$$-dc$$$. And if there is a horizontal wall (the upper or lower walls), $$$dr$$$ is reflected before the movement, so the new value of $$$dr$$$ is $$$-dr$$$.Each second (including the moment before the robot starts moving), the robot cleans every cell lying in the same row or the same column as its position. There is only one dirty cell at $$$(r_d, c_d)$$$. The job of the robot is to clean that dirty cell.  Illustration for the first example. The blue arc is the robot. The red star is the target dirty cell. Each second the robot cleans a row and a column, denoted by yellow stripes. Given the floor size $$$n$$$ and $$$m$$$, the robot's initial position $$$(r_b, c_b)$$$ and the dirty cell's position $$$(r_d, c_d)$$$, find the time for the robot to do its job.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. A test case consists of only one line, containing six integers $$$n$$$, $$$m$$$, $$$r_b$$$, $$$c_b$$$, $$$r_d$$$, and $$$c_d$$$ ($$$1 \le n, m \le 100$$$, $$$1 \le r_b, r_d \le n$$$, $$$1 \le c_b, c_d \le m$$$) — the sizes of the room, the initial position of the robot and the position of the dirt cell.

For each test case, print an integer — the time for the robot to clean the dirty cell. We can show that the robot always cleans the dirty cell eventually.

NoteIn the first example, the floor has the size of $$$10\times 10$$$. The initial position of the robot is $$$(6, 1)$$$ and the position of the dirty cell is $$$(2, 8)$$$. See the illustration of this example in the problem statement.In the second example, the floor is the same, but the initial position of the robot is now $$$(9, 9)$$$, and the position of the dirty cell is $$$(1, 1)$$$. In this example, the robot went straight to the dirty cell and clean it.   In the third example, the floor has the size $$$9 \times 8$$$. The initial position of the robot is $$$(5, 6)$$$, and the position of the dirty cell is $$$(2, 1)$$$.   In the fourth example, the floor has the size $$$6 \times 9$$$. The initial position of the robot is $$$(2, 2)$$$ and the position of the dirty cell is $$$(5, 8)$$$.   In the last example, the robot was already standing in the same column as the dirty cell, so it can clean the cell right away.

<?php

$t = trim(readline());

for ($i = 0; $i < $t; $i++) {
    list($n, $m, $rb, $cb, $rd, $cd) = explode(" ", readline());

    $turn_r = 0;
    $turn_c = 0;

    if ($rb > $rd) {
        $turn_r = ($n - $rb) * 2;
    }

    if ($cb > $cd) {
        $turn_c = ($m - $cb) * 2;
    }

    $to_r = abs($rb - $rd) + $turn_r;
    $to_c = abs($cb - $cd) + $turn_c;

    print min($to_r, $to_c) . "\n";
}

<?php

$file = fopen('php://stdin', 'd');

function solve()
{
    global $file;

    list($n, $m, $robotX, $robotY, $dirtX, $dirtY) = array_map('intval', explode(' ', trim(fgets($file))));

    $time = 0;

    $dx = 1;
    $dy = 1;

    while($robotX !== $dirtX && $robotY !== $dirtY)
    {
        if($robotX + $dx > $n || $robotX + $dx < 1)
        {
            $dx = -$dx;
        }

        if($robotY + $dy > $m || $robotY + $dy < 1)
        {
            $dy = -$dy;
        }

        $robotX += $dx;
        $robotY += $dy;

        $time++;
    }

    echo $time;
    echo PHP_EOL;
}

$t = + fgets($file);

while($t--) solve();


You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.For instance, if we are given an array $$$[10, 20, 30, 40]$$$, we can permute it so that it becomes $$$[20, 40, 10, 30]$$$. Then on the first and the second positions the integers became larger ($$$20>10$$$, $$$40>20$$$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $$$2$$$. Read the note for the first example, there is one more demonstrative test case.Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.

Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.

NoteIn the first sample, one of the best permutations is $$$[1, 5, 5, 3, 10, 1, 1]$$$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.In the second sample, there is no way to increase any element with a permutation, so the answer is 0.

<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

$answer = 0;

fscanf(STDIN, "%d", $N);
$a = explode(" ", trim(fgets(STDIN)));
sort($a);
// var_dump($a);
$sort = $a;
$cur1 = 0;
$cur2 = 0;
while ($cur2 < $N) {
	if ($a[$cur1] < $a[$cur2]) {
		$answer++;
		$cur1++;
		$cur2++;
	} else {
		$cur2++;
	}
}
echo $answer;

<?php

$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));

//$b = "10 1 1 1 5 5 3";
$input = $b;
$input = explode(" ", $input);

$copy = new ArrayObject($input);
$copy = $copy->getArrayCopy();

//按照value由小到大sorting,但保留key的位置
asort($copy);
$keys = array_keys($copy);
$values = array_values($copy);
$finds = array();
$count = count($values);

$jump = 100;

$offset = 1;
for($i = 0; $i < $count; $i++){
    $value = $values[$i];
	//$offset = 1;

    while($offset < $count){
        $nextValue = $values[$offset];
        $nextKey = $keys[$offset];
		if($nextValue <= $value || isset($finds[$nextKey])){
            $offset++;
            continue;
        }
        if($nextValue > $value){
            $finds[$nextKey] = 1;
            break;
        }
     }
}

echo count($finds);

<?

$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));

//$b = "10 1 1 1 5 5 3";
$input = $b;
$input = explode(" ", $input);

$copy = new ArrayObject($input);
$copy = $copy->getArrayCopy();

//按照value由小到大sorting,但保留key的位置
asort($copy);
$keys = array_keys($copy);
$values = array_values($copy);
$finds = array();
$count = count($values);

if(count($copy) >= 100000){
    echo 'stop';
}

for($i = 0; $i < $count; $i++){
    $value = $values[$i];
    $find = false;
    $offset = 1;

    while($offset+$i < $count){
        $next100Offset = 1000;
        $next100Value = $values[$i+$offset+$next100Offset];
        if(isset($next100Value) && $next100Value <= $value){
            while($offset+$i+$next100Offset < $count){
                if($next100Value <= $value){
                     $next100Offset+=1000;
                     $next100Value = $values[$i+$offset+$next100Offset];
                }else{
                    break;
                }
            }
            $offset+=$next100Offset;
        }

        $nextValue = $values[$i+$offset];
        $nextKey = $keys[$i+$offset];
        if($nextValue <= $value || isset($finds[$nextKey])){
            $offset++;
            continue;
        }
        if($nextValue > $value){
            $finds[$nextKey] = 1;
            break;
        }
     }
}
echo count($finds);

<?php

//$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
//$b = "10 1 1 1 5 5 3";

$input = $b;
$input = explode(" ", $input);

$copy = new ArrayObject($input);
$copy = $copy->getArrayCopy();

//按照value由小到大sorting,但保留key的位置
asort($copy);
$keys = array_keys($copy);                                                                       $values = array_values($copy);
$finds = array();

for($i = 0; $i < count($values); $i++){
    $value = $values[$i];
    $find = false;
    $offset = 1;
    while($offset+$i < count($values)){
        $nextValue = $values[$i+$offset];
        $nextKey = $keys[$i+$offset];
        if(isset($finds[$nextKey])){
            $offset++;
            continue;
        }
        if($nextValue > $value){
            $finds[$nextKey] = 1;
            break;
        }else{
            $offset++;
        }
    }
}

echo count($finds);

<?

$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));

//$b = "10 1 1 1 5 5 3";
$input = $b;
$input = explode(" ", $input);

$copy = new ArrayObject($input);
$copy = $copy->getArrayCopy();

if(count($input)>=10000){
    echo "date 1 is " . microtime();
}

//按照value由小到大sorting,但保留key的位置
asort($copy);
$keys = array_keys($copy);
$values = array_values($copy);
$finds = array();
$count = count($values);

if(count($input)>=10000){
    echo "date 2 is " . microtime();
}

for($i = 0; $i < $count; $i++){
    $value = $values[$i];
    $find = false;
    $offset = 1;

    while($offset+$i < $count){
        $next100Offset = 1000;
        $next100Value = $values[$i+$offset+$next100Offset];
        if(isset($next100Value) && $next100Value <= $value){
            while($offset+$i+$next100Offset < $count){
                if($next100Value <= $value){
                     $next100Offset+=1000;
                     $next100Value = $values[$i+$offset+$next100Offset];
                }else{
                    break;
                }
            }
            $offset+=$next100Offset;
        }

        $nextValue = $values[$i+$offset];
        $nextKey = $keys[$i+$offset];
        if($nextValue <= $value || isset($finds[$nextKey])){
            $offset++;
            continue;
        }
        if($nextValue > $value){
            $finds[$nextKey] = 1;
            break;
        }
     }
}

echo count($finds);
if(count($input)>=10000){
    echo "date 3 is " . microtime();
}

<?php

//$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
//$b = "10 1 1 1 5 5 3";

$input = $b;
$input = explode(" ", $input);

$copy = new ArrayObject($input);
$copy = $copy->getArrayCopy();

//按照value由小到大sorting,但保留key的位置
asort($copy);
$keys = array_keys($copy);                                                                       $values = array_values($copy);
$finds = array();

for($i = 0; $i < count($values); $i++){
    $value = $values[$i];
    $find = false;
    $offset = 1;
    while($offset+$i < count($values)){
        $nextValue = $values[$i+$offset];
        $nextKey = $keys[$i+$offset];
        if(isset($finds[$nextKey])){
            $offset++;
            continue;
        }
        if($nextValue > $value){
            $finds[$nextKey] = 1;
            break;
        }else{
            $offset++;
        }
    }
}

echo "result = ". count($finds);

<?php

$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));

//$b = "10 1 1 1 5 5 3";
$input = $b;
$input = explode(" ", $input);

$copy = new ArrayObject($input);
$copy = $copy->getArrayCopy();

//按照value由小到大sorting,但保留key的位置
asort($copy);
$keys = array_keys($copy);
$values = array_values($copy);
$finds = array();
$count = count($values);

$jump = 100;
if(count($input)>=10000){
	echo "jump = ".$jump;
		$value = $values[500];
		echo "lai = $value
";
		$value = $values[700];
		echo "lai2 = $value
";
}

$offset = 1;
for($i = 0; $i < $count; $i++){
    $value = $values[$i];
    $find = false;
	//$offset = 1;

    while($offset+$i < $count){
        $next100Offset = $jump;
        $next100Value = $values[$i+$offset+$next100Offset];
		if(count($input)>=10000){
			echo "num:".$i.",next 100: ".$next100Value . ", current value = ".$value."
";
		}
        if(isset($next100Value) && $next100Value <= $value){
			 if(count($input)>=10000){
                echo "next 100 value = " . $next100Value . ", value  = " + $value;
            }
            while($offset+$i+$next100Offset < $count){
                if($next100Value <= $value){
                     $next100Offset+= $jump;
                     $next100Value = $values[$i+$offset+$next100Offset];
                }else{
                    break;
                }
            }
            if(count($input)>=10000){
                echo "add more offset : ".$next100Offset;
            }
            $offset+=$next100Offset;
        }

        $nextValue = $values[$i+$offset];
        $nextKey = $keys[$i+$offset];

		if(count($input)>=10000){
			echo "nextValue = ".$nextValue;
		}
		if($nextValue <= $value || isset($finds[$nextKey])){
            $offset++;
            continue;
        }
        if($nextValue > $value){
            $finds[$nextKey] = 1;
            break;
        }
     }
}

echo count($finds);

<?php

$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));

//$b = "10 1 1 1 5 5 3";
$input = $b;
$input = explode(" ", $input);

$copy = new ArrayObject($input);
$copy = $copy->getArrayCopy();

//按照value由小到大sorting,但保留key的位置
asort($copy);
$keys = array_keys($copy);
$values = array_values($copy);
$finds = array();
$count = count($values);

$jump = 100;

$offset = 1;
for($i = 0; $i < $count; $i++){
    $value = $values[$i];
    $find = false;
	//$offset = 1;

    while($offset+$i < $count){
        $next100Offset = $jump;
        $next100Value = $values[$i+$offset+$next100Offset];
        if(isset($next100Value) && $next100Value <= $value){
            while($offset+$i+$next100Offset < $count){
                if($next100Value <= $value){
                     $next100Offset+= $jump;
                     $next100Value = $values[$i+$offset+$next100Offset];
                }else{
                    break;
                }
            }
            $offset+=$next100Offset;
        }

        $nextValue = $values[$i+$offset];
        $nextKey = $keys[$i+$offset];
		if($nextValue <= $value || isset($finds[$nextKey])){
            $offset++;
            continue;
        }
        if($nextValue > $value){
            $finds[$nextKey] = 1;
            break;
        }
     }
}

echo count($finds);

<?php

$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
//$b = "10 1 1 1 5 5 3";

$input = $b;
$input = explode(" ", $input);

$copy = new ArrayObject($input);
$copy = $copy->getArrayCopy();

//按照value由小到大sorting,但保留key的位置
asort($copy);
$usedIndex = [];
$keys = array_keys($copy);
$values = array_values($copy);
$success = 0;

for($i = 0; $i < sizeof($input); $i++){
    $current = $input[$i];
    $currentIndex = array_search($i, $keys);

    $offset = 1;
    $next = $values[$currentIndex +$offset];

    while(isset($next)){
        if($next == $current|| in_array($keys[$currentIndex+$offset], $usedIndex)){
            $offset++;
            $next = $values[$currentIndex+$offset];
        }else{
            //找到比自己大的
            $nextKey = $keys[$currentIndex+$offset];
            array_push($usedIndex, $nextKey);
			$success++;
			echo "got $next";
            break;
        }
    }

    if(!isset($next)){
        //沒有比這個元素大的
        foreach($copy as $key => $value){
            if(in_array($key, $usedIndex)){
                continue;
            }
            array_push($usedIndex, $key);
			break;
        }
    }
}
echo "$success";

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

//$b = "10 1 1 1 5 5 3";
$input = $b;
$input = explode(" ", $input);

$copy = new ArrayObject($input);
$copy = $copy->getArrayCopy();

//按照value由小到大sorting,但保留key的位置
asort($copy);

echo '4';

<?

$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));

//$b = "10 1 1 1 5 5 3";
$input = $b;
$input = explode(" ", $input);

$copy = new ArrayObject($input);
$copy = $copy->getArrayCopy();

//按照value由小到大sorting,但保留key的位置
asort($copy);
$keys = array_keys($copy);
$values = array_values($copy);
$finds = array();
$count = count($values);

if(count($input)>=10000){
    echo "date is " . date("Y-m-d h:i:sa");
}

for($i = 0; $i < $count; $i++){
    $value = $values[$i];
    $find = false;
    $offset = 1;

    while($offset+$i < $count){
        $next100Offset = 1000;
        $next100Value = $values[$i+$offset+$next100Offset];
        if(isset($next100Value) && $next100Value <= $value){
            while($offset+$i+$next100Offset < $count){
                if($next100Value <= $value){
                     $next100Offset+=1000;
                     $next100Value = $values[$i+$offset+$next100Offset];
                }else{
                    break;
                }
            }
            $offset+=$next100Offset;
        }

        $nextValue = $values[$i+$offset];
        $nextKey = $keys[$i+$offset];
        if($nextValue <= $value || isset($finds[$nextKey])){
            $offset++;
            continue;
        }
        if($nextValue > $value){
            $finds[$nextKey] = 1;
            break;
        }
     }
}

echo count($finds);
if(count($input)>=10000){
    echo "date 2 is " . date("Y-m-d h:i:sa");
}


Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic. One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon. The dragon has a hit point of $$$x$$$ initially. When its hit point goes to $$$0$$$ or under $$$0$$$, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.  Void Absorption Assume that the dragon's current hit point is $$$h$$$, after casting this spell its hit point will become $$$\left\lfloor \frac{h}{2} \right\rfloor + 10$$$. Here $$$\left\lfloor \frac{h}{2} \right\rfloor$$$ denotes $$$h$$$ divided by two, rounded down. Lightning Strike This spell will decrease the dragon's hit point by $$$10$$$. Assume that the dragon's current hit point is $$$h$$$, after casting this spell its hit point will be lowered to $$$h-10$$$.Due to some reasons Kana can only cast no more than $$$n$$$ Void Absorptions and $$$m$$$ Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$)  — the number of test cases. The next $$$t$$$ lines describe test cases. For each test case the only line contains three integers $$$x$$$, $$$n$$$, $$$m$$$ ($$$1\le x \le 10^5$$$, $$$0\le n,m\le30$$$)  — the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.

If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower).

NoteOne possible casting sequence of the first test case is shown below: Void Absorption $$$\left\lfloor \frac{100}{2} \right\rfloor + 10=60$$$. Lightning Strike $$$60-10=50$$$. Void Absorption $$$\left\lfloor \frac{50}{2} \right\rfloor + 10=35$$$. Void Absorption $$$\left\lfloor \frac{35}{2} \right\rfloor + 10=27$$$. Lightning Strike $$$27-10=17$$$. Lightning Strike $$$17-10=7$$$. Lightning Strike $$$7-10=-3$$$.

<?php
// $stdin = fopen('input.txt', 'r');

$calc = function ($x, $n, $m) {
	if ($m == 0) {
		return false;
	} else if($x <= $m * 10){
		return true;
	}

	for (; $n > 0; $n--) {
		$x = floor($x / 2) + 10;
		if($x <= $m * 10){
			return true;
		}
	}

	return false;
};

for ($t = intval(fgets(STDIN)); $t > 0; $t--) {

	list($x, $n, $m) = explode(' ', fgets(STDIN));

	echo ($calc($x, $n, $m) ? 'YES' : 'NO') . "\n";

}

<?php

main();

function main() {
  $num_cases = trim(fgets(STDIN));

  for ($i = 1; $i <= $num_cases; $i++) {

    list($hp, $n, $m) = explode(" ", trim(fgets(STDIN)));
    $res = run_case($hp, $n, $m);

    print $res . "\n";
  }
}

function run_case($hp, $n, $m) {
	for ($i = 0; $i < $n; $i++) {
			$new_hp = intdiv($hp, 2)+10;
			if ($new_hp < $hp) {
				$hp = $new_hp;
			} else {
				break;
			}
	}
	for ($i = 0; $i < $m; $i++) {
		$hp = $hp - 10;
	}

	if ($hp <= 0) {
		return "YES";
	} else {
		return "NO";
	}

}

?>

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $in_str = explode(" ", trim(fgets(STDIN))) ;

        $x = intval($in_str[0]) ;
        $n = intval($in_str[1]) ;
        $m = intval($in_str[2]) ;

        for($i = 0; $i < $n; $i ++)
        {
            if($x <= 20) break ;
            $x = intval($x / 2) + 10 ;
        }
        for($i = 0; $i < $m ; $i ++) $x -= 10 ;

        echo $x <= 0 ? "YES\n" : "NO\n" ;
    }
?>

<?php

main();

function main() {
  $num_cases = trim(fgets(STDIN));

  for ($n = 1; $n <= $num_cases; $n++) {
    list($hp, $n, $m) = explode(" ", trim(fgets(STDIN)));
    $res = run_case($hp, $n, $m);

    print $res . "\n";
  }
}

function run_case($hp, $n, $m) {
	for ($i = 0; $i < $n; $i++) {
			$new_hp = intdiv($hp, 2)+10;
			if ($new_hp < $hp) {
				$hp = $new_hp;
			} else {
				break;
			}
	}
	for ($i = 0; $i < $m; $i++) {
		$hp = $hp - 10;
	}

	if ($hp <= 0) {
		return "YES";
	} else {
		return "NO";
	}

}

?>


Eugeny loves listening to music. He has n songs in his play list. We know that song number i has the duration of ti minutes. Eugeny listens to each song, perhaps more than once. He listens to song number i ci times. Eugeny's play list is organized as follows: first song number 1 plays c1 times, then song number 2 plays c2 times, ..., in the end the song number n plays cn times.Eugeny took a piece of paper and wrote out m moments of time when he liked a song. Now for each such moment he wants to know the number of the song that played at that moment. The moment x means that Eugeny wants to know which song was playing during the x-th minute of his listening to the play list.Help Eugeny and calculate the required numbers of songs.

The first line contains two integers n, m (1 ≤ n, m ≤ 105). The next n lines contain pairs of integers. The i-th line contains integers ci, ti (1 ≤ ci, ti ≤ 109) — the description of the play list. It is guaranteed that the play list's total duration doesn't exceed 109 . The next line contains m positive integers v1, v2, ..., vm, that describe the moments Eugeny has written out. It is guaranteed that there isn't such moment of time vi, when the music doesn't play any longer. It is guaranteed that vi < vi + 1 (i < m). The moment of time vi means that Eugeny wants to know which song was playing during the vi-th munite from the start of listening to the playlist.

Print m integers — the i-th number must equal the number of the song that was playing during the vi-th minute after Eugeny started listening to the play list.


Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows:   $$$a_1 = -1$$$  $$$a_2 = 2$$$  $$$a_3 = -3$$$  $$$a_4 = 4$$$  $$$a_5 = -5$$$  And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.

Print $$$q$$$ lines, each containing one number — the answer to the query.

NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.

#!/usr/bin/env php
<?php

if (PHP_OS == 'WINNT') {
    $count = stream_get_line(STDIN, 1024, PHP_EOL);
    $queries = [];
    $arr = [];
    for ($i = 0; $i < $count; $i++) {
        $range = stream_get_line(STDIN, 1024, PHP_EOL);
        $queries[$i] = [
            'l' => explode(' ', $range)[0],
            'r' => explode(' ', $range)[1],
        ];

    }

} else {
    $count = readline();
    $arr = [];
    $queries = [];
    for ($i = 0; $i < $count; $i++) {
        $range = readline();;
        $queries[$i] = [
            'l' => explode(' ', $range)[0],
            'r' => explode(' ', $range)[1],
        ];
    }
}

$result = [];

foreach ($queries as $query) {
    $len = $query['r'] - ($query['l']-1);

    if ($len%2 == 0){ //чётное
        $sum = ($len/2);
        if ($query['l']%2 == 0){
            $sum *=-1;
        }
    }else{
        if ($query['r']%2 == 0){
            $sum = floor($len/2)*(-1)+$query['r'];
        }else{
            $sum = floor($len/2)-$query['r'];
        }
    }

    array_push($result, $sum);
}

foreach ($result as $res){
    echo $res.PHP_EOL;
}

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

/* Perform action N times. Can return values in array */
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. */
function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}

/* Difference. Keys preserved. By reference. */
function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}

function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
/*****************************************/

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();

function sn($n)
{
	return ($n>>1) - $n*($n&1);
}

ntimes($n, function() use ($ir) {
	list($l, $r) = $ir->readArrayOfInt(2);
	echo sn($r) - sn($l-1);
	echo "\n";
});

#!/usr/bin/env php
<?php

if (PHP_OS == 'WINNT') {
    $count = stream_get_line(STDIN, 1024, PHP_EOL);
    $queries = [];
    $arr = [];
    for ($i = 0; $i < $count; $i++) {
        $range = stream_get_line(STDIN, 1024, PHP_EOL);
        $queries[$i] = [
            'l' => explode(' ', $range)[0],
            'r' => explode(' ', $range)[1],
        ];

    }

} else {
    $count = readline();
    $arr = [];
    $queries = [];
    for ($i = 0; $i < $count; $i++) {
        $range = readline();;
        $queries[$i] = [
            'l' => explode(' ', $range)[0],
            'r' => explode(' ', $range)[1],
        ];
    }
}

$result = [];

foreach ($queries as $query) {
    $len = $query['r'] - ($query['l']-1);

    if ($len%2 == 0){ //чётное
        $sum = ($len/2);
        if ($query['l']%2 == 0){
            $sum *=-1;
        }
    }else{
        if ($query['r']%2 == 0){
            $sum = floor($len/2)+$query['r'];
        }else{
            $sum = floor($len/2)-$query['r'];
        }
    }

    array_push($result, $sum);
}

foreach ($result as $res){
    echo $res.PHP_EOL;
}

#!/usr/bin/env php
<?php

if (PHP_OS == 'WINNT') {
    $count = stream_get_line(STDIN, 1024, PHP_EOL);
    $queries = [];
    $arr = [];
    for ($i = 0; $i < $count; $i++) {
        $range = stream_get_line(STDIN, 1024, PHP_EOL);
        $queries[$i] = [
            'l' => explode(' ', $range)[0],
            'r' => explode(' ', $range)[1],
        ];
        $arr[$i] = ($i + 1) * pow(-1, $i + 1);
    }

} else {
    $count = readline();
    $arr = [];
    $queries = [];
    for ($i = 0; $i < $count; $i++) {
        $range = readline();;
        $queries[$i] = [
            'l' => explode(' ', $range)[0],
            'r' => explode(' ', $range)[1],
        ];
    }
    $arr[$i] = ($i + 1) * pow(-1, $i + 1);
}

$result = [];

foreach ($queries as $query) {
    $len = $query['r'] - ($query['l']-1);
    $arr2 = array_slice($arr, $query['l']-1, $len);
    $sum = 0;
    foreach ($arr2 as $a){
        $sum+=$a;
    }
    array_push($result, $sum);
}

foreach ($result as $res){
    echo $res.PHP_EOL;
}