Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.

Print the index of the day when Polycarp will celebrate the equator.

NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.

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

<?php

fscanf(STDIN, "%d", $t);
$values = array_map('intval', explode(' ',trim(fgets(STDIN))));
$sum = array_sum($values);
$ct = 0;
$res = 0;

for ($i = 0; $i < count($values); $i++) {
	$ct += $values[$i];
	if ($ct >= ($sum / 2)) {
		$res = $i + 1;
		break ;
	}
}

echo $res."\n";

<?php

//თენდება აღარ თენდება

$n = trim(fgets(STDIN));

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

$tetrbatknianebi = 0;
$shavbatknianebi = 0;

for($i = 0; $i < $n; $i++){
    $tetrbatknianebi += $arr[$i];
}

$tetrbatknianebi /=2;

for($i = 0; $i<$n;$i++){
    $shavbatknianebi+=$arr[$i];
    if($shavbatknianebi>=$tetrbatknianebi){
        echo($i+1);
        exit();
    }
}

?>

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

$total = 0;
foreach ($b as $key => $value) {
	$total += $value;
}

$cur = 0;
$day = 0;
foreach ($b as $key => $value) {
	$day++;
	$cur += $value;
	if ($cur >= $total/2) {
		break;
	}
}

echo $day;
?>


You are given two arrays $$$a$$$ and $$$b$$$, both consisting of $$$n$$$ integers.In one move, you can choose two indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$; $$$i \neq j$$$) and swap $$$a_i$$$ with $$$a_j$$$ and $$$b_i$$$ with $$$b_j$$$. You have to perform the swap in both arrays.You are allowed to perform at most $$$10^4$$$ moves (possibly, zero). Can you make both arrays sorted in a non-decreasing order at the end? If you can, print any sequence of moves that makes both arrays sorted.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of elements in both arrays. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the first array. The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le n$$$) — the second array.

For each testcase, print the answer. If it's impossible to make both arrays sorted in a non-decreasing order in at most $$$10^4$$$ moves, print -1. Otherwise, first, print the number of moves $$$k$$$ $$$(0 \le k \le 10^4)$$$. Then print $$$i$$$ and $$$j$$$ for each move $$$(1 \le i, j \le n$$$; $$$i \neq j)$$$. If there are multiple answers, then print any of them. You don't have to minimize the number of moves.

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";
define("INTMAXVALUE",     2147483646);

   $t = IO::getInt();
//   $point = ord('a') + ord('b') ;

   for($q=0; $q <$t; $q++) {
       $ans = "";
       $n = IO::getInt();
       $a = IO::getArray();
       $b = IO::getArray();
       $count = 0;
       for($i=0; $i<$n; $i++) {
          for($j=$i+1; $j<$n; $j++) {
            if($a[$i] >= $a[$j] && $b[$i] >= $b[$j]) {
                 $temp = $a[$i];
                 $a[$i] = $a[$j];
                 $a[$j] = $temp;

                 $temp = $b[$i];
                 $b[$i] = $b[$j];
                 $b[$j] = $temp;
                 $tt = $i+1;
                 $bb = $j+1;
                 $ans .= "$tt $bb\n";
                 $count++;
            }
          }
       }

       $sol = true;
       for($i=0; $i<$n-1; $i++) {
            if($a[$i] > $a[$i+1] || $b[$i] > $b[$i+1]) {
                $sol = false;
                break;
            }
       }
       if(!$sol) {
            IO::pr('-1');
       } else {
           echo $count, PHP_EOL;
           if($count > 0) {
                echo $ans, PHP_EOL;
           }

          //  for($i=0; $i<$count; $i++) {
          //      echo $ans[$i], PHP_EOL;
          //  }
       }

   }

function maxVal($x) {
     $max = $x[0];
          for($i=1; $i<strlen($x); $i++) {
              $max = IO::getMaxValue($max, $x[$i]);
              if($max == 9) {
                   break;
              }
          }
          return $max;
}

 class IO {
      public static function getInt()
      {
          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;
     }
 }

 class Algor {
    public static function isPrime($n) {
         $d = 2;
         while ($n % $d != 0) {
         $d += 1;
         }

        return $d == $n;
    }

     public static function fabicon($n, $a) {
         if($n <= 1) {
             return $a[$n];
         }
         for($i=2; $i<=$n; $i++) {
             $a[$i] = $a[$i-1] + $a[$i-2];
         }

         return $a[$n];
     }

     function getRotate($a, $s, $e, $ind) {
         $ar = [];
         for ($i= $s; $i<=$e; $i++) {
             $ar[$i] = $a[$i];
             $j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
             // echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
             $a[$i] = $j < $i ? $ar[$j] : $a[$j];
         }
         return $a;
     }

}

class bigOperation {
    public static function  isBigNumber($n)
    {
        return bccomp($n, INTMAXVALUE) == 1;
    }
    // bcadd — Сложить 2 числа произвольной точности
    public static function  bcAdd($x, $y)
    {
        return bcadd($x, $y);
    }
// bccomp — Сравнение двух чисел произвольной точности
//return 1 if x>y, 0= x==y, -1 x < y
    public static function  bcComp($x, $y)
    {
        return bccomp($x, $y);
    }
// bcdiv — Операция деления для чисел произвольной точности
    public static function  bcDiv($x, $y)
    {
        return bcdiv($x, $y);
    }
// bcmod — Получает остаток от деления чисел с произвольной точностью
    public static function  bcMod($x, $y)
    {
        return bcmod($x, $y);
    }
// bcmul — Умножение двух чисел с произвольной точностью
    public static function  bcMul($x, $y)
    {
        return bcmul($x, $y);
    }
// bcpow — Возведение в степень чисел с произвольной точностью
    public static function  bcPow($x, $y)
    {
        return bcpow($x, $y);
    }
// bcpowmod — Возводит одно число в степень другого и возвращает остаток от деления результата на третье число
// bcscale — Задает количество чисел после десятичной точки по умолчанию для всех bc math функций.
// bcsqrt — Извлекает квадратный корень из числа с произвольной точностью
    public static function  bcSqrt($x, $y)
    {
        return bcsqrt($x, $y);
    }
// bcsub — Вычитает одно число с произвольной точностью из другого
    public static function  bcSub($x, $y)
    {
        return bcsub($x, $y);
    }
    public static function getMaxValue($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    public static function getMinValue($x, $y) {
        return bccomp($x, $y) == 1 ? $y : $x;
    }

    public static function getDareje($n, $k) {
        if($k == 0) {
            return 1;
        }
        return bcmul($n, self::getDareje($n, $k-1));
    }
}

class Sorting
{
    public static function mergeSort($aArray) {
        if(count($aArray) <= 1) {
            return $aArray;
        }
        $aLeft = [];
        $aRight = [];
        $n =floor(count($aArray) / 2);
        for($i = 0; $i <$n; $i++) {
            $aLeft[] = $aArray[$i];
        }
        for($i = $n; $i <count($aArray); $i++) {
            $aRight[] = $aArray[$i];
        }

        return self::merge(self::mergeSort($aLeft), self::mergeSort($aRight));
    }

    public static function merge($aLeft, $aRight) {
        $aResult = [];
        $iL = 0;
        $iR = 0;

        while($iL < count($aLeft) && $iR < count($aRight)) {
            if($aLeft[$iL] <= $aRight[$iR]) {
                $aResult[] = $aLeft[$iL];
                $iL++;
            } else {
                $aResult[] = $aRight[$iR];
                $iR++;
            }
        }

        while($iL < count($aLeft)) {
            $aResult[] = $aLeft[$iL];
            $iL++;
        }
        while($iR < count($aRight)) {
            $aResult[] = $aRight[$iR];
            $iR++;
        }

        return $aResult;

    }
}

class SolveArchive
{

}

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

        $iLeft = 0;
        $iRight = 0;
        $aCheck = [];
        for ($i = 0; $i < $n; $i++) {
            for ($j = $i+1; $j < $n; $j++) {
                if ($a[$i] > $a[$j]) {
                    $iRight++;
                    $sA = $a[$j];

                    $a[$j] = $a[$i];
                    $a[$i] = $sA;

                    $sB = $b[$j];

                    $b[$j] = $b[$i];
                    $b[$i] = $sB;

                    $i1 = $j+1;
                    $i2 = $i+1;

                    $aCheck[] = "$i1 $i2";

                    if ($b[$i] > $b[$j]) {
                        $iLeft++;
                    }
                }

                if ($b[$i] > $b[$j]) {
                    $iLeft++;
                }

            }
        }

        //echo $iRight . '--' . $iLeft . PHP_EOL;
        //exit;

        if ($iRight > 0 &&  $iLeft == 0) {
            echo $iRight . PHP_EOL;
            foreach ($aCheck as $sVal) {
                echo $sVal . PHP_EOL;
            }
        } else if ($iRight == 0 && $iLeft == 0){
            echo 0 . PHP_EOL;
        } else {
            echo -1 . PHP_EOL;
        }
    }
?>

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

        $iLeft = 0;
        $iRight = 0;
        $aCheck = [];
        for ($i = 0; $i < $n; $i++) {
            for ($j = $i+1; $j < $n; $j++) {
                if ($a[$i] > $a[$j]) {
                    $iRight++;
                    $sA = $a[$j];

                    $a[$j] = $a[$i];
                    $a[$i] = $sA;

                    $sB = $b[$j];

                    $b[$j] = $b[$i];
                    $b[$i] = $sB;

                    $i1 = $j+1;
                    $i2 = $i+1;

                    $aCheck[] = "$i1 $i2";

                    if ($b[$i] > $b[$j]) {
                        $iLeft++;
                    }
                }

            }
        }

        //echo $iRight . PHP_EOL;
        //echo $iLeft;
        //exit;

        if ($iRight > 0 &&  $iLeft == 0) {
            echo $iRight . PHP_EOL;
            foreach ($aCheck as $sVal) {
                echo $sVal . PHP_EOL;
            }
        } else if ($iRight == 0 && $iLeft == 0){
            echo 0 . PHP_EOL;
        } else {
            echo -1 . PHP_EOL;
        }
    }
?>

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

        $iCheck = 0;
        $aCheck = [];
        for ($i = 0; $i < $n; $i++) {
            for ($j = $i+1; $j < $n; $j++) {
                if ($a[$i] > $a[$j]) {
                    $iCheck++;
                    $sA = $a[$j];

                    $a[$j] = $a[$i];
                    $a[$i] = $sA;

                    $sB = $b[$j];

                    $b[$j] = $b[$i];
                    $b[$i] = $sB;

                    $i1 = $j+1;
                    $i2 = $i+1;

                    if ($b[$i] > $b[$j]) {
                        $iCheck = -1;
                        break;
                    }

                    $aCheck[] = "$i1 $i2";
                }

            }
        }
        if ($iCheck < 0) {
            echo -1 . PHP_EOL;
        }
        else if ($iCheck == 0){
            echo 0 . PHP_EOL;
        } else {
            echo $iCheck . PHP_EOL;
            foreach ($aCheck as $sVal) {
                echo $sVal . PHP_EOL;
            }
        }
    }
?>


Given three distinct integers $$$a$$$, $$$b$$$, and $$$c$$$, find the medium number between all of them.The medium number is the number that is neither the minimum nor the maximum of the given three numbers. For example, the median of $$$5,2,6$$$ is $$$5$$$, since the minimum is $$$2$$$ and the maximum is $$$6$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 6840$$$) — the number of test cases. The description of each test case consists of three distinct integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \leq a, b, c \leq 20$$$).

For each test case, output a single integer — the medium number of the three numbers.

<?php
$Test=(int)readline();
while($Test--)
{
    $Number=explode(' ',readline());
    sort($Number);
    echo $Number[1]."\n";
}
?>

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

for($i=0; $i <$iter; $i++) {
    $ans = 0;
    $a = InOutPut::getArr();
    $s = sort($a);
    InOutPut::print($a[1]);
}
class InOutPut {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

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

<?php

    $t = readline();

    while($t--)
    {
        $values = explode(' ', readline());

        sort($values);

        print($values[1] . "\n");
    }

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

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

    IO::pr($a[1]);
}

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
$t = trim(fgets(STDIN));

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

    sort($a);
    echo $a[1] . PHP_EOL;
}

<?php

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    $xs = getLineInts();

    sort($xs, SORT_NUMERIC);

    $results[] = $xs[1];
}

echo(implode(PHP_EOL, $results));

// Helpers

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

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

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

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

<?php
$Test=(int)readline();
while($Test--)
{
    $Number_1=(int) readline();
    $Number_2=(int) readline();
    $Number_3=(int) readline();
    $Sum=$Number_1+$Number_2+$Number_3;
    echo $Sum-max($Number_1,$Number_2,$Number_3)-min($Number_1,$Number_2,$Number_3)."\n";
}
?>

<?php
$Test=(int)readline();
while($Test--)
{
    $Number_1=(int) readline();
    $Number_2=(int) readline();
    $Number_3=(int) readline();
    $Sum=$Number_1+$Number_2+$Number_3;
    echo $Sum-max($Number_1,$Number_2,$Number_3)-min($Number_1,$Number_2,$Number_3);
    echo "<br>";
}
?>

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

for($i=0; $i <$iter; $i++) {
    $ans = 0;
    $a = InOutPut::getArr();
    $len = count($a);
    $a = sort($a);
    InOutPut::print($a[1]);
}
class InOutPut {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

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


Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.

The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan. Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.

Print the only integer a — the cost of the dinner for Jack and Emma.

NoteIn the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.

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

<?php
$str_nm = trim(fgets(STDIN));
$arr_nm = explode(" ", $str_nm);
$n = $arr_nm[0];
$m = $arr_nm[1];
for ($i = 0; $i < $n; $i++){
    $str_c = trim(fgets(STDIN));
    $arr_c = explode(" ", $str_c);
    $arr_min_c[$i] = min($arr_c);
}
echo max($arr_min_c);
?>


Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows:   if a word was written by one person — that person gets 3 points,  if a word was written by two people — each of the two gets 1 point,  if a word was written by all — nobody gets any points.  In the end, how many points does each player have?

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.

For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.

3

1

abc

def

abc

3

orz for qaq

qaq orz for

cod for ces

5

iat roc hem ica lly

bac ter iol ogi sts

bac roc lly iol iat

NoteIn the first test case:   The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point.  The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.

<?php

$inp = fopen('php://stdin', 'rb');

fscanf($inp, '%d', $t);

while ($t--) {
    fscanf($inp, '%d', $n);
    $format = str_repeat('%s ', $n);

    $fi = array_flip(fscanf($inp, $format));
    $se = array_flip(fscanf($inp, $format));
    $th = array_flip(fscanf($inp, $format));

    $r1 = count(array_diff_key($fi, $se, $th)) * 3 +
        count(array_diff_key(array_intersect_key($fi, $se), $th)) +
        count(array_diff_key(array_intersect_key($fi, $th), $se));
    echo "$r1 ";

    $r2 = count(array_diff_key($se, $fi, $th)) * 3 +
        count(array_diff_key(array_intersect_key($se, $fi), $th)) +
        count(array_diff_key(array_intersect_key($se, $th), $fi));
    echo "$r2 ";

    $r3 = count(array_diff_key($th, $fi, $se)) * 3+
        count(array_diff_key(array_intersect_key($th, $fi), $se))+
        count(array_diff_key(array_intersect_key($th, $se), $fi));
    echo "$r3 ";

    echo PHP_EOL;
}

<?php

$inp = fopen('php://stdin', 'rb');

fscanf($inp, '%d', $t);

while ($t--) {
    fscanf($inp, '%d', $n);
    $format = str_repeat('%s ', $n);

    $fi = fscanf($inp, $format);
    $se = fscanf($inp, $format);
    $th = fscanf($inp, $format);

    $r1 = count(array_diff($fi, $se, $th)) * 3 +
        count(array_diff(array_intersect($fi, $se), $th)) +
        count(array_diff(array_intersect($fi, $th), $se));
    echo "$r1 ";

    $r2 = count(array_diff($se, $fi, $th)) * 3 +
        count(array_diff(array_intersect($se, $fi), $th)) +
        count(array_diff(array_intersect($se, $th), $fi));
    echo "$r2 ";

    $r3 = count(array_diff($th, $fi, $se)) * 3+
        count(array_diff(array_intersect($th, $fi), $se))+
        count(array_diff(array_intersect($th, $se), $fi));
    echo "$r3 ";

    echo PHP_EOL;
}


Not so long ago, Vlad had a birthday, for which he was presented with a package of candies. There were $$$n$$$ types of candies, there are $$$a_i$$$ candies of the type $$$i$$$ ($$$1 \le i \le n$$$).Vlad decided to eat exactly one candy every time, choosing any of the candies of a type that is currently the most frequent (if there are several such types, he can choose any of them). To get the maximum pleasure from eating, Vlad does not want to eat two candies of the same type in a row.Help him figure out if he can eat all the candies without eating two identical candies in a row.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of input test cases. The following is a description of $$$t$$$ test cases of input, two lines for each. The first line of the case contains the single number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of types of candies in the package. The second line of the case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — the number of candies of the type $$$i$$$. It is guaranteed that the sum of $$$n$$$ for all cases does not exceed $$$2 \cdot 10^5$$$.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case of input. As an answer, output "YES" if Vlad can eat candy as planned, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteIn the first example, it is necessary to eat sweets in this order: a candy of the type $$$2$$$, it is the most frequent, now $$$a = [2, 2]$$$; a candy of the type $$$1$$$, there are the same number of candies of the type $$$2$$$, but we just ate one, now $$$a = [1, 2]$$$; a candy of the type $$$2$$$, it is the most frequent, now $$$a = [1, 1]$$$; a candy of the type $$$1$$$, now $$$a = [0, 1]$$$; a candy of the type $$$2$$$, now $$$a = [0, 0]$$$ and the candy has run out.In the second example, all the candies are of the same type and it is impossible to eat them without eating two identical ones in a row.In the third example, first of all, a candy of the type $$$2$$$ will be eaten, after which this kind will remain the only kind that is the most frequent, and you will have to eat a candy of the type $$$2$$$ again.

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

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

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

	$max = 0; $pos = -1;

	foreach($a as $i => $aa){
		if($aa > $max){
			$pos = $i; $max = $aa;
		}
	}
	$minD = $max;
	foreach($a as $i => $aa){
		if($i !== $pos && ($d = $max - $aa) < $minD){
			$minD = $d;
		}
	}

	return $minD < 2;

};

$t = intval(fgets(STDIN));

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

	$n = intval(fgets(STDIN));
	$a = array_map('intval', explode(' ', fgets(STDIN)));

	echo $solve($n, $a) ? 'YES' : 'NO';
	echo "\n";

}


A frog is currently at the point $$$0$$$ on a coordinate axis $$$Ox$$$. It jumps by the following algorithm: the first jump is $$$a$$$ units to the right, the second jump is $$$b$$$ units to the left, the third jump is $$$a$$$ units to the right, the fourth jump is $$$b$$$ units to the left, and so on.Formally:   if the frog has jumped an even number of times (before the current jump), it jumps from its current position $$$x$$$ to position $$$x+a$$$;  otherwise it jumps from its current position $$$x$$$ to position $$$x-b$$$. Your task is to calculate the position of the frog after $$$k$$$ jumps.But... One more thing. You are watching $$$t$$$ different frogs so you have to answer $$$t$$$ independent queries.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of queries. Each of the next $$$t$$$ lines contain queries (one query per line). The query is described as three space-separated integers $$$a, b, k$$$ ($$$1 \le a, b, k \le 10^9$$$) — the lengths of two types of jumps and the number of jumps, respectively.

Print $$$t$$$ integers. The $$$i$$$-th integer should be the answer for the $$$i$$$-th query.

NoteIn the first query frog jumps $$$5$$$ to the right, $$$2$$$ to the left and $$$5$$$ to the right so the answer is $$$5 - 2 + 5 = 8$$$.In the second query frog jumps $$$100$$$ to the right, $$$1$$$ to the left, $$$100$$$ to the right and $$$1$$$ to the left so the answer is $$$100 - 1 + 100 - 1 = 198$$$.In the third query the answer is $$$1 - 10 + 1 - 10 + 1 = -17$$$.In the fourth query the answer is $$$10^9 - 1 + 10^9 - 1 + 10^9 - 1 = 2999999997$$$.In the fifth query all frog's jumps are neutralized by each other so the answer is $$$0$$$.The sixth query is the same as the fifth but without the last jump so the answer is $$$1$$$.

<?php
$a = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
     list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
     $e = $d % 2;
     $f = floor($d / 2);
     $g = ceil($d / 2);
     $h = $d / 2;
     if($e == 0)
     {
          print bcsub(bcmul($b, $h), bcmul($c, $h)) . "\n";
     }
     else
     {
          print bcsub(bcmul($b, $g), bcmul($c, $f)) . "\n";
     }
}
?>

<?php

$tst = intval(readline());

while ($tst--)
{
	list($a, $b, $c) = explode(' ', readline());
	if($c%2 == 0) $ans = bcmul(($a-$b),strval(intval($c/2)));
	else $ans = bcadd(bcmul(($a-$b),strval(intval($c/2))),$a);
	echo strval($ans)."\n";
}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	fscanf(STDIN,"%s %s %s",$a,$b,$k);
	 $right=bcmul(bcdiv(bcadd($k,1),2),$a);
	 $left=bcmul(bcdiv($k,2),$b);
	 echo bcsub($right,$left)."\n";

}

<?php

$tst = intval(readline());

while ($tst--)
{
	list($a, $b, $c) = explode(' ', readline());
	if($c%2 == 0) $ans = ($a-$b)*intval($c/2);
	else $ans = ($a-$b)*intval($c/2)+$a;
	echo $ans."\n";
}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	fscanf(STDIN,"%d %d %d",$a,$b,$k);
	$right=ceil($k/2)*$a;
	$left=floor($k/2)*$b;
	echo ($right)-($left)."\n";
}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	  fscanf(STDIN,"%d",$len);
	  fscanf(STDIN,"%s",$num);
	  //$digits='123456789';
	  //$str="";
	  $len=strlen($num);

      if($len==2)
       	{
       		if($num[0]<$num[1])
       	 	   echo "YES\n2\n$num[0] $num[1]\n";
       	 	else
       	 		echo "NO\n";

       	}

       	else
       	{
       	 	echo "YES\n2\n$num[0] ";
       	 	echo substr($num,1,$len-1)."\n";
       	}
}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	fscanf(STDIN,"%s %s %s",$a,$b,$k);
	 $right=bcmul(bcdiv(bcadd($k,1),2),$a);
	 $left=bcmul(bcdiv($k,2),$b);
	 echo bcsub($right,abs($left))."\n";

}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	fscanf(STDIN,"%s %s %s",$a,$b,$k);
	 $right=bcmul(bcdiv(bcadd($k,1),2),$a);
	 $left=bcmul(bcdiv($k,2),$b);
	 echo $right-abs($left)."\n";

}


You are given an array $$$a$$$ of $$$n$$$ positive integers. Determine if, by rearranging the elements, you can make the array strictly increasing. In other words, determine if it is possible to rearrange the elements such that $$$a_1 < a_2 < \dots < a_n$$$ holds.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.

For each test case, output "YES" (without quotes) if the array satisfies the condition, and "NO" (without quotes) otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteIn the first test case any rearrangement will keep the array $$$[1,1,1,1]$$$, which is not strictly increasing.In the second test case, you can make the array $$$[1,3,4,7,8]$$$.

<?php

fscanf(STDIN, '%u', $t);

while ($t--) {
    fscanf(STDIN, '%u', $n);
    $ar = fscanf(STDIN, str_repeat('%u ', $n));
    sort($ar);

    $last = -1;
    $res = true;
    foreach($ar as $it) {
        if ($last < $it) {
            $last = $it;
            continue;
        }

        $res = false;
        break;
    }

    echo ($res ? 'YES' : 'NO').PHP_EOL;
}

<?php

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

for ($index = 0; $index < $t; $index++)
{
    $n = (int) trim(fgets(STDIN));

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

    echo((count(array_unique($a, SORT_NUMERIC)) < $n ? "NO" : "YES") . PHP_EOL);
}