Monocarp is a little boy who lives in Byteland and he loves programming.Recently, he found a permutation of length $$$n$$$. He has to come up with a mystic permutation. It has to be a new permutation such that it differs from the old one in each position.More formally, if the old permutation is $$$p_1,p_2,\ldots,p_n$$$ and the new one is $$$q_1,q_2,\ldots,q_n$$$ it must hold that $$$$$$p_1\neq q_1, p_2\neq q_2, \ldots ,p_n\neq q_n.$$$$$$Monocarp is afraid of lexicographically large permutations. Can you please help him to find the lexicographically minimal mystic permutation?

There are several test cases in the input data. The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 200$$$) — the number of test cases. This is followed by the test cases description. The first line of each test case contains a positive integer $$$n$$$ ($$$1\leq n\leq 1000$$$) — the length of the permutation. The second line of each test case contains $$$n$$$ distinct positive integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq n$$$). It's guaranteed that $$$p$$$ is a permutation, i. e. $$$p_i \neq p_j$$$ for all $$$i \neq j$$$.  It is guaranteed that the sum of $$$n$$$ does not exceed $$$1000$$$ over all test cases.

For each test case, output $$$n$$$ positive integers — the lexicographically minimal mystic permutations. If such a permutation does not exist, output $$$-1$$$ instead.

NoteIn the first test case possible permutations that are mystic are $$$[2,3,1]$$$ and $$$[3,1,2]$$$. Lexicographically smaller of the two is $$$[2,3,1]$$$.In the second test case, $$$[1,2,3,4,5]$$$ is the lexicographically minimal permutation and it is also mystic.In third test case possible mystic permutations are $$$[1,2,4,3]$$$, $$$[1,4,2,3]$$$, $$$[1,4,3,2]$$$, $$$[3,1,4,2]$$$, $$$[3,2,4,1]$$$, $$$[3,4,2,1]$$$, $$$[4,1,2,3]$$$, $$$[4,1,3,2]$$$ and $$$[4,3,2,1]$$$. The smallest one is $$$[1,2,4,3]$$$.

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

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

 function solve()
 {
     // list($n, $m, $k) = IO::getArray();
     $n = IO::getInt();
     $a = IO::getArray();
     $ans = [];

    if($n == 1) {
        IO::pr('-1');
    } else {
         $count = 0;
         $ans = $a;
         sort($ans);

              for($i=0; $i < $n; $i++) {
                   if($a[$i] == $ans[$i]) {
                        if($i+1 < $n) {
                            $temp = $ans[$i+1];
                            $ans[$i+1] = $ans[$i];
                            $ans[$i] = $temp;
                       } else {
                            $temp = $ans[$i-1];
                            $ans[$i-1] = $ans[$i];
                            $ans[$i] = $temp;
                       }
                   }

             }
             IO::prArray($ans);

    }

 }

 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 efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    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 efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    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
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     // list($n, $m, $k) = IO::getArray();
     $n = IO::getInt();
     $a = IO::getArray();
     $ans = [];

    if($n == 1) {
        IO::pr('-1');
    } else {
         $count = 0;
         $ans = $a;
         sort($ans);

              for($i=0; $i < $n; $i++) {
                   if($a[$i] = $ans[$i]) {
                        if($i+1 < $n) {
                            $temp = $ans[$i+1];
                            $ans[$i+1] = $ans[$i];
                            $ans[$i] = $temp;
                       } else {
                            $temp = $ans[0];
                            $ans[0] = $ans[$i];
                            $ans[$i] = $temp;
                       }
                   }

             }
             IO::prArray($ans);

    }

 }

 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 efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    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 efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    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
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     // list($n, $m, $k) = IO::getArray();
     $n = IO::getInt();
     $a = IO::getArray();
     $ans = [];

    if($n == 1) {
        IO::pr('-1');
    } else {
         $count = 0;
         $ans = $a;
         sort($ans);

              for($i=0; $i < $n; $i++) {
                  if($i+1 < $n) {
                       $temp = $a[$i+1];
                       $a[$i+1] = $a[$i];
                       $a[$i] = $temp;
                  } else {
                       $temp = $a[0];
                       $a[0] = $a[$i];
                       $a[$i] = $temp;
                  }
             }
             IO::prArray($a);

    }

 }

 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 efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    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 efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    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
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     // list($n, $m, $k) = IO::getArray();
     $n = IO::getInt();
     $a = IO::getArray();
     $ans = [];

    if($n == 1) {
        IO::pr('-1');
    } else {
         $count = 0;
         $ans = $a;
         sort($ans);
         for($i=0; $i < $n-1; $i++) {
              if($ans[$i] == $ans[$i+1]) {
                $count++;
              }
         }
         if($count > $n/2) {
              IO::pr('-1');
         } else {
              for($i=0; $i < $n; $i++) {
                  if($ans[$i] == $a[$i]) {
                       $temp = $ans[$i];
                       for($j=0; $j < $n; $j++) {
                            $tt = $i-$j == 0 ? $n : $i-$j-1;
                            if($ans[$tt] != $a[$i] && $ans[$i] != $a[$tt]) {
                                 break;
                            }
                       }

                       $ans[$i]  = $ans[$tt];
                       $ans[$tt] =  $temp;
                  }
             }
             IO::prArray($ans);
         }

    }

 }

 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 efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    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 efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    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
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     // list($n, $m, $k) = IO::getArray();
     $n = IO::getInt();
     $a = IO::getArray();
     $ans = [];

    if($n == 1) {
        IO::pr('-1');
    } else {
         $ans = $a;
         sort($ans);
        for($i=0; $i < $n; $i++) {
             if($ans[$i] == $a[$i]) {
                  $temp = $ans[$i];
                  for($j=0; $j < $n; $j++) {
                       $tt = $i-$j == 0 ? $n : $i-$j-1;
                       if($ans[$tt] != $a[$i]) {
                            break;
                       }
                  }

                  $ans[$i]  = $ans[$tt];
                  $ans[$tt] =  $temp;
             }

        }
   IO::prArray($ans);
    }

 }

 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 efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    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 efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    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
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     // list($n, $m, $k) = IO::getArray();
     $n = IO::getInt();
     $a = IO::getArray();
     $ans = [];

    if($n == 1) {
        IO::pr('-1');
    } else {
         $ans = $a;
         sort($ans);
        for($i=0; $i < $n; $i++) {
             if($ans[$i] == $a[$i]) {
                  $temp = $ans[$i];
                  $tt = $i == 0 ? $n : $i-1;
                  $ans[$i]  = $ans[$tt];
                  $ans[$tt] =  $temp;
             }

        }
   IO::prArray($ans);
    }

 }

 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 efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    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 efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    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
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     // list($n, $m, $k) = IO::getArray();
     $n = IO::getInt();
     $a = IO::getArray();
     $ans = [];

    if($n == 1) {
        IO::pr('-1');
    } else {
         $ans = $a;
         sort($ans);
        for($i=0; $i < $n; $i++) {
             if($ans[$i] == $a[$i]) {
                  $temp = $ans[$i];
                  $tt = $i+1 == $n ? 0 : $i+1;
                  $ans[$i]  = $ans[$tt];
                  $ans[$tt] =  $temp;
             }

        }
   IO::prArray($ans);
    }

 }

 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 efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    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 efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    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
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     // list($n, $m, $k) = IO::getArray();
     $n = IO::getInt();
     $a = IO::getArray();
     $ans = [];

    if($n == 1) {
        IO::pr('-1');
    } else {
         $ans = $a;
         sort($ans);
        for($i=1; $i < $n; $i++) {
             if($ans[$i] == $a[$i]) {
                  $temp = $ans[$i];
                  $tt = $i+1 == $n ? 0 : $i+1;
                  $ans[$i]  = $ans[$tt];
                  $ans[$tt] =  $temp;
             }

        }
   IO::prArray($ans);
    }

 }

 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 efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    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 efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    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
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     // list($n, $m, $k) = IO::getArray();
     $n = IO::getInt();
     $a = IO::getArray();
     $ans = [];

    if($n == 1) {
        IO::pr('-1');
    } else {
        for($i=0; $i < $n-1; $i++) {
           $ans[$i]  = $a[$i+1];
           $a[$i+1] =  $a[$i];
        }
        $ans[$n-1] = $a[$n-1];
   IO::prArray($ans);
    }

 }

 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 efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    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 efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    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
{

}


Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.The valid sizes of T-shirts are either "M" or from $$$0$$$ to $$$3$$$ "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not.There are $$$n$$$ winners to the cup for both the previous year and the current year. Ksenia has a list with the T-shirt sizes printed for the last year cup and is yet to send the new list to the printing office. Organizers want to distribute the prizes as soon as possible, so now Ksenia is required not to write the whole list from the scratch but just make some changes to the list of the previous year. In one second she can choose arbitrary position in any word and replace its character with some uppercase Latin letter. Ksenia can't remove or add letters in any of the words.What is the minimal number of seconds Ksenia is required to spend to change the last year list to the current one?The lists are unordered. That means, two lists are considered equal if and only if the number of occurrences of any string is the same in both lists.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of T-shirts. The $$$i$$$-th of the next $$$n$$$ lines contains $$$a_i$$$ — the size of the $$$i$$$-th T-shirt of the list for the previous year. The $$$i$$$-th of the next $$$n$$$ lines contains $$$b_i$$$ — the size of the $$$i$$$-th T-shirt of the list for the current year. It is guaranteed that all the sizes in the input are valid. It is also guaranteed that Ksenia can produce list $$$b$$$ from the list $$$a$$$.

Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0.

NoteIn the first example Ksenia can replace "M" with "S" and "S" in one of the occurrences of "XS" with "L".In the second example Ksenia should replace "L" in "XXXL" with "S".In the third example lists are equal.

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

fscanf(STDIN, "%d", $n);
$list1 = array();
$list2 = array();

for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s", $S);
    $list1[$S]++;
}
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s", $S);
    $list2[$S]++;
}

foreach ($list1 as $key => $val) {
    if (isset($list2[$key])) {
        $sub = min($list1[$key], $list2[$key]);
        $list1[$key] -= $sub;
        $list2[$key] -= $sub;
    }
}
foreach ($list2 as $key => $val) {
    if (isset($list1[$key])) {
        $sub = min($list1[$key], $list2[$key]);
        $list1[$key] -= $sub;
        $list2[$key] -= $sub;
    }
}

echo array_sum($list1), "\n";

<?php
$a = trim(fgets(STDIN));
$b = array();
$c = array();
for($x = 0; $x < $a; $x++)
{
     $d = trim(fgets(STDIN));
     $b[$x] = $d;
}
for($x = 0; $x < $a; $x++)
{
     $e = trim(fgets(STDIN));
     $c[$x] = $e;
}
sort($b);
sort($c);
$f = 0;
for($x = 0; $x < count($b); $x++)
{
     $g = str_split($b[$x]);
     $h = str_split($c[$x]);
     $i = array_diff($h, $g);
     $f += count($i);
}
print $f;
?>

<?php
$a = trim(fgets(STDIN));
$b = array();
$c = array();
for($x = 0; $x < $a; $x++)
{
     $d = trim(fgets(STDIN));
     $b[$x] = $d;
}
for($x = 0; $x < $a; $x++)
{
     $e = trim(fgets(STDIN));
     $c[$x] = $e;
}
sort($b);
sort($c);
$f = 0;
for($x = 0; $x < count($b); $x++)
{
     $g = str_split($b[$x]);
     $h = str_split($c[$x]);
     $i = array_diff($g, $h);
     $f += count($i);
}
print $f;
?>

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

fscanf(STDIN, "%d", $n);
$list1 = array();
$list2 = array();

for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s", $S);
    $list1[$S]++;
}
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s", $S);
    $list2[$S]++;
}

foreach ($list1 as $key => $val) {
    $ans += abs($list1[$key] - $list2[$key]);
}

echo $ans;


A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time li and the finish time ri (li ≤ ri).Restaurant management can accept and reject orders. What is the maximal number of orders the restaurant can accept?No two accepted orders can intersect, i.e. they can't share even a moment of time. If one order ends in the moment other starts, they can't be accepted both.

The first line contains integer number n (1 ≤ n ≤ 5·105) — number of orders. The following n lines contain integer values li and ri each (1 ≤ li ≤ ri ≤ 109).

Print the maximal number of orders that can be accepted.


Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the vertices with cats in them.The leaf vertices of the park contain restaurants. Kefa wants to choose a restaurant where he will go, but unfortunately he is very afraid of cats, so there is no way he will go to the restaurant if the path from the restaurant to his house contains more than m consecutive vertices with cats. Your task is to help Kefa count the number of restaurants where he can go.

The first line contains two integers, n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ n) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains n integers a1, a2, ..., an, where each ai either equals to 0 (then vertex i has no cat), or equals to 1 (then vertex i has a cat). Next n - 1 lines contains the edges of the tree in the format "xi yi" (without the quotes) (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the vertices of the tree, connected by an edge.  It is guaranteed that the given set of edges specifies a tree.

A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most m consecutive vertices with cats.

NoteLet us remind you that a tree is a connected graph on n vertices and n - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if it has no children.Note to the first sample test:  The vertices containing cats are marked red. The restaurants are at vertices 2, 3, 4. Kefa can't go only to the restaurant located at vertex 2.Note to the second sample test:  The restaurants are located at vertices 4, 5, 6, 7. Kefa can't go to restaurants 6, 7.

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$cArray = explode(" ", trim(fgets($file)));
array_unshift($cArray, "T");
unset($cArray[0]);
$map = array();
for ($i = 1; $i < $n; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $map[$x][] = $y;
    $map[$y][] = $x;
}
$result = 0;
function solve($dest, $cur, $cN, $mCN)
{
    global $result, $map, $m, $cArray;
    $c = count($map[$cur]);
    if ($c == 1 && $map[$cur][0] == $dest) {
        if (max($cN+$cArray[$cur], $mCN)<= $m) {
            $result++;
        }
        return;
    }
    if ($cArray[$cur] == 1) {
        $cN++;
        $mCN = max($cN, $mCN);
        if ($mCN>$m) {
            return;
        }
    }else{
        $cN = 0;
    }
    for ($i = 0; $i < $c; $i++) {
        if ($map[$cur][$i] == $dest) {
            continue;
        }
        solve($cur, $map[$cur][$i], $cN, $mCN);
    }

}

solve(0, 1, 0, 0);
echo $result;

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$cArray = explode(" ", trim(fgets($file)));
array_unshift($cArray, "T");
unset($cArray[0]);
$map = array();
for ($i = 1; $i < $n; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $map[$x][] = $y;
    $map[$y][] = $x;
}
$result = 0;
function solve($dest, $cur, $cN)
{
    global $result, $map, $m, $cArray;
    $c = count($map[$cur]);
    if ($cArray[$cur]) {
        $cN++;
        if ($cN>$m) {
            return;
        }
    }else{
        $cN = 0;
    }
    if ($c == 1 && $map[$cur][0] == $dest) {
        $result++;
        return;
    }

    for ($i = 0; $i < $c; $i++) {
        if ($map[$cur][$i] == $dest) {
            continue;
        }
        solve($cur, $map[$cur][$i], $cN);
    }

}

solve(0, 1, 0);
echo $result;

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$cArray = explode(" ", trim(fgets($file)));
array_unshift($cArray, "T");
unset($cArray[0]);
$map = array();
for ($i = 1; $i < $n; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $map[$x][] = $y;
    $map[$y][] = $x;
}
$result = 0;
function solve($dest, $cur, $cN)
{
    global $result, $map, $m, $cArray;
    $c = count($map[$cur]);
    if ($c == 1) {
        if ($cN+$cArray[$cur]<= $m) {
            $result++;
        }
        return;
    }
    if ($cArray[$cur] == 1) {
        $cN++;
        if ($cN>$m) {
            return;
        }
    }else{
        $cN = 0;
    }
    for ($i = 0; $i < $c; $i++) {
        if ($map[$cur][$i] == $dest) {
            continue;
        }
        solve($cur, $map[$cur][$i], $cN);
    }

}

solve(0, 1, 0);
echo $result;

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$cArray = explode(" ", trim(fgets($file)));
array_unshift($cArray, "T");
unset($cArray[0]);
$map = array();
for ($i = 1; $i < $n; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $map[$x][] = $y;
    $map[$y][] = $x;
}
$result = 0;
function solve($dest, $cur, $cN, $mCN)
{
    global $result, $map, $m, $cArray;
    $c = count($map[$cur]);
    if ($c == 1) {
        if (max($cN+$cArray[$cur], $mCN)<= $m) {
            $result++;
        }
        return;
    }
    if ($cArray[$cur] == 1) {
        $cN++;
        $mCN = max($cN, $mCN);
        if ($mCN>$m) {
            return;
        }
    }else{
        $cN = 0;
    }
    for ($i = 0; $i < $c; $i++) {
        if ($map[$cur][$i] == $dest) {
            continue;
        }
        solve($cur, $map[$cur][$i], $cN, $mCN);
    }

}

solve(0, 1, 0, 0);
echo $result;

<?php
$file = fopen('input.in', 'r');
//$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$cArray = explode(" ", trim(fgets($file)));
array_unshift($cArray, "T");
unset($cArray[0]);
$map = array();
for ($i = 1; $i < $n; $i++) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $map[$x][] = $y;
    $map[$y][] = $x;
}
$result = 0;
function solve($dest, $cur, $cN)
{
    global $result, $map, $m, $cArray;
    $c = count($map[$cur]);
    if ($cArray[$cur]) {
        $cN++;
    }else{
        $cN = 0;
    }
    if ($c == 1 && $map[$cur][0] == $dest) {
        if ($cN<= $m) {
            $result++;
        }
        return;
    }

    for ($i = 0; $i < $c; $i++) {
        if ($map[$cur][$i] == $dest) {
            continue;
        }
        solve($cur, $map[$cur][$i], $cN);
    }

}

solve(0, 1, 0);
echo $result;


Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to 1. Also, he has m queries:  Query number i is given as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n).  The response to the query will be integer 1, if the elements of array a can be rearranged so as the sum ali + ali + 1 + ... + ari = 0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries.

The first line contains integers n and m (1 ≤ n, m ≤ 2·105). The second line contains n integers a1, a2, ..., an (ai = -1, 1). Next m lines contain Eugene's queries. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n).

Print m integers — the responses to Eugene's queries in the order they occur in the input.


Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place:   A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars.  Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally.

The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000).

Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.

7
win 10
win 5
win 3
sell 5
sell 3
win 10
sell 10


ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then everything on the screen disappears and after that the word you have typed appears on the screen.For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.

The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.

Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.

NoteThe first sample is already explained in the problem statement.For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1.

<?php
function write($text){
	file_put_contents('php://stdout', $text);
}
function read(){
	return trim(fgets(STDIN));
}

$count = 1;

$config = explode(' ', read());
$n = $config[0];
$c = $config[1];

$data = explode(' ', read());

$a = $data[0];

for($i=1; $i<$n; $i++){
	if(($data[$i]-$a) <= $c)
		$count++;
	elseif(($data[$i]-$a) > $c)
		$count = 1;

	$a = $data[$i];
}

write($count);

<?php
$dir = fopen("php://stdin", 'r');
$data = stream_get_contents($dir);
$data = explode("\n", $data);
$n = explode(' ',$data[0])[0];
$maxTime = explode(' ',$data[0])[1];
$data = explode(' ',$data[1]);
$mes = array();
for ($i = 0; $i<$n; $i++){
    $mes[$i] = $data[$i];
}
$sum = 0;
foreach ($mes as $num => $time){
  if ($mes[$num+1] - $time > $maxTime){
      $sum = 0;
  }else{
      $sum++;
  }

}
echo ($sum);

?>

<?php
function write($text){
	file_put_contents('php://stdout', $text);
}
function read(){
	return trim(fgets(STDIN));
}

$count = 0;

$config = explode(' ', read());
$n = $config[0];
$c = $config[1];

$data = explode(' ', read());

$a = $data[0];

for($i=1; $i<$n; $i++){
	if(($data[$i]-$a) <= $c)
		$count++;
	elseif(($data[$i]-$a) > $c)
		$count = 1;

	$a = $data[$i];
}

write($count);


You are given two arrays $$$a$$$ and $$$b$$$ both consisting of $$$n$$$ positive (greater than zero) integers. You are also given an integer $$$k$$$.In one move, you can choose two indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$) and swap $$$a_i$$$ and $$$b_j$$$ (i.e. $$$a_i$$$ becomes $$$b_j$$$ and vice versa). Note that $$$i$$$ and $$$j$$$ can be equal or different (in particular, swap $$$a_2$$$ with $$$b_2$$$ or swap $$$a_3$$$ and $$$b_9$$$ both are acceptable moves).Your task is to find the maximum possible sum you can obtain in the array $$$a$$$ if you can do no more than (i.e. at most) $$$k$$$ such moves (swaps).You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 30; 0 \le k \le n$$$) — the number of elements in $$$a$$$ and $$$b$$$ and the maximum number of moves you can do. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 30$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. The third line of the test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 30$$$), where $$$b_i$$$ is the $$$i$$$-th element of $$$b$$$.

For each test case, print the answer — the maximum possible sum you can obtain in the array $$$a$$$ if you can do no more than (i.e. at most) $$$k$$$ swaps.

NoteIn the first test case of the example, you can swap $$$a_1 = 1$$$ and $$$b_2 = 4$$$, so $$$a=[4, 2]$$$ and $$$b=[3, 1]$$$.In the second test case of the example, you don't need to swap anything.In the third test case of the example, you can swap $$$a_1 = 1$$$ and $$$b_1 = 10$$$, $$$a_3 = 3$$$ and $$$b_3 = 10$$$ and $$$a_2 = 2$$$ and $$$b_4 = 10$$$, so $$$a=[10, 10, 10, 4, 5]$$$ and $$$b=[1, 9, 3, 2, 9]$$$.In the fourth test case of the example, you cannot swap anything.In the fifth test case of the example, you can swap arrays $$$a$$$ and $$$b$$$, so $$$a=[4, 4, 5, 4]$$$ and $$$b=[1, 2, 2, 1]$$$.

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

    fscanf($stdin, "%d\n", $t);

    while($t--){
        fscanf($stdin, "%d%d", $n, $k);

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

        $a = array_map('intval', preg_split('/ /', $tempA, -1, PREG_SPLIT_NO_EMPTY));

        fscanf($stdin, "%[^\n]", $tempB);
        $b = array_map('intval', preg_split('/ /', $tempB, -1, PREG_SPLIT_NO_EMPTY));

        sort($a);
        rsort($b);
        $sum = 0;
        for($i=0; $i<$n; $i++){
            if($i < $k) $sum += max($a[$i], $b[$i]);
            else $sum += $a[$i];
        }

        //print_r($a);
        //print_r($b);

        echo $sum."\n";
    }
?>

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

<?php

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

$stdin = fopen('php://stdin', 'r');
function slove($sys){
    fscanf($sys,"%d%d",$n,$k);
    $arrA=inputArray($sys);
    $arrB=inputArray($sys);
    sort($arrB);
    sort($arrA);
    for($i=0;$i<$k;++$i){
        if($arrB[$n-$i-1] > $arrA[$i]){
            $arrA[$i]=$arrB[$n-$i-1];
        }else break;
    }
    $sum=0;
    for ($i=0; $i < $n; $i++) {
        $sum+=$arrA[$i];
    }
    echo $sum."\n";
}

$T=inputInt($stdin);
while($T--){
    slove($stdin);
}


You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input().

The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits.

Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=".

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if ($a > $b) echo ">";
if ($a < $b) echo "<";
if ($a == $b) echo "=";
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if($a < $b)
{
    print "<";
}
elseif($a == $b)
{
    print "=";
}
elseif($a > $b)
{
    print ">";
}
?>

//Br34k
<?php
$str1 = trim(fgets(STDIN));
$str2 = trim(fgets(STDIN));
if($str1 < $str2)
    print "<";
elseif($str1 == $str2)
    print "=";
elseif($str1 > $str2)
    print ">";

?>


It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!There are exactly n distinct countries in the world and the i-th country added ai tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.

The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line contains n non-negative integers ai without leading zeroes — the number of tanks of the i-th country. It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these number's representations doesn't exceed 100 000.

Print a single number without leading zeroes — the product of the number of tanks presented by each country.

NoteIn sample 1 numbers 10 and 1 are beautiful, number 5 is not not.In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.In sample 3 number 3 is not beautiful, all others are beautiful.

<?php

$n = intval( trim(fgets(STDIN)) );
$sLine = trim(fgets(STDIN));

$aLine = explode(' ',$sLine);

$bZero = TRUE;

$sNum = 0;

for($i = 0; $i < $n; $i ++){
    if($aLine[$i] == '0'){
        echo 0;
        exit;
    }
    if(!isBecaufulNum($aLine[$i])){
        $sNum = $aLine[$i];
    } else {
        $iLen += intval( strlen($aLine[$i]) ) - 1;
    }
}
if(empty($sNum)) $sNum = '1';
$L = strlen($sNum);
for($i = 0 ;$i < $L ;$i++){
    echo $sNum[$i];
    #var_dump($sNum[$i]);
}
if($sNum == 0) exit;
for($i = 0; $i < $iLen ;$i++){
    echo 0;
}

function isBecaufulNum($sNum){
    $iCnt = 0;
    $len = strlen($sNum);
    for($i = 0; $i < $len ; $i ++){
        $tmp = intval($sNum[$i]);
        if($tmp == 1) {
            $iCnt++;
            if ($iCnt > 1)
                return FALSE;
        } else if($tmp != 0){
            return FALSE;
        }
    }
    return TRUE;
}

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/23  9:58
 */
while(fscanf(STDIN,"%d",$num)){
    $line = stream_get_line(STDIN,1000002,"\n");
    $line = trim($line);
    $tanks = explode(" ",$line);
    //最后一个字符串会保留换行符 whitespaces
    $res = 0;
    $flag = false;
    foreach($tanks as $t){
        //fprintf(STDOUT,"%s\n",$t);
        if( "0" == $t ) {
            $flag = true;
            break;
        }
        //var_dump((substr_count($t,"0") + substr_count($t,"1") != strlen($t)));
       if($t[0] != '1'|| substr_count($t, "1") > 1 ){
            $head = $t;
       }else{
            $et = false;
            for($i = 0 ; $i < strlen($t);$i++){
                if($t[$i] != '0' and $t[$i] != '1'){
                    $head = $t;
                    $et = true;
                }
            }

            if(!$et)
                $res += strlen($t) - 1;
       }
    }
    if($flag){
        fprintf(STDOUT,0);
    }else{
        if(isset($head)) {
            fprintf(STDOUT,"%s",$head);
        }else{
            fprintf(STDOUT,1);
        }
        for($i = 0 ; $i < count($res) ; $i++){
            for($zeroNum = 0 ; $zeroNum < $res ; $zeroNum++){
                fprintf(STDOUT,"0");
            }
        }
    }
    exit();
}

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

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_product($b);
print number_format($c, 0, "" , "");
?>

<?php

$n = intval( trim(fgets(STDIN)) );
$sLine = trim(fgets(STDIN));

$aLine = explode(' ',$sLine);

$bZero = TRUE;

$sNum = 0;

for($i = 0; $i < $n; $i ++){
    if($aLine[$i] == '0'){
        echo 0;
        exit;
    }
    if(!isBecaufulNum($aLine[$i])){
        $sNum = $aLine[$i];
    } else {
        $iLen += intval( strlen($aLine[$i]) ) - 1;
    }
}
if(!isset($sNum)) $sNum = 1;
$L = strlen($sNum);

for($i = 0 ;$i < $L ;$i++){
    echo $sNum[$i];
}
if($sNum == 0) exit;
for($i = 0; $i < $iLen ;$i++){
    echo 0;
}

function isBecaufulNum($sNum){
    $iCnt = 0;
    $len = strlen($sNum);
    for($i = 0; $i < $len ; $i ++){
        $tmp = intval($sNum[$i]);
        if($tmp == 1) {
            $iCnt++;
            if ($iCnt > 1)
                return FALSE;
        } else if($tmp != 0){
            return FALSE;
        }
    }
    return TRUE;
}

<?php

$n = intval( trim(fgets(STDIN)) );
$sLine = trim(fgets(STDIN));

$aLine = explode(' ',$sLine);

$bZero = TRUE;

$sNum = 0;
$iLen = 0;

for($i = 0; $i < $n; $i ++){
    if($aLine[$i] == '0'){
        echo 0;
        exit;
    }
    if(!isBecaufulNum($aLine[$i])){
        $sNum = $aLine[$i];
    } else {
        $iLen += intval( strlen($aLine[$i]) ) - 1;
    }
}
$L = strlen($sNum);
$j = 0;
for($i = 0; $i <  $L ; $i ++){
    if($sNum[$i] != 0 || ($sNum[$i] == 0 && $i + 1 == L)){
        $j = $i;
        break;
    }
}

for($i = $j ;$i < $L ;$i++){
    echo $sNum[$i];
}
if($j + 1 == $L  && $sNum[$j] == 0) exit;
for($i = 0; $i < $iLen ;$i++){
    echo 0;
}

function isBecaufulNum($sNum){
    $iCnt = 0;
    $len = strlen($sNum);
    for($i = 0; $i < $len ; $i ++){
        $tmp = intval($sNum[$i]);
        if($tmp == 1) {
            $iCnt++;
            if ($iCnt > 1)
                return FALSE;
        } else if($tmp != 0){
            return FALSE;
        }
    }
    return TRUE;
}

<?php

$n = intval( trim(fgets(STDIN)) );
$sLine = trim(fgets(STDIN));

$aLine = explode(' ',$sLine);

$bZero = TRUE;

$sNum = 0;
$iLen = 0;

for($i = 0; $i < $n; $i ++){
    if($aLine[$i] == '0'){
        echo 0;
        exit;
    }
    if(!isBecaufulNum($aLine[$i])){
        $sNum = $aLine[$i];
    } else {
        $iLen += intval( strlen($aLine[$i]) ) - 1;
    }
}
$L = strlen($sNum);
$j = 0;
for($i = 0; $i <  $L ; $i ++){
    if($sNum[$i] != 0 || ($sNum[$i] == 0 && $i + 1 == L)){
        $j = $i;
        break;
    }
}

for($i = $j ;$i < $L ;$i++){
    echo $sNum[$i];
}
if($j + 1 == $L) exit;
for($i = 0; $i < $iLen ;$i++){
    echo 0;
}

function isBecaufulNum($sNum){
    $iCnt = 0;
    $len = strlen($sNum);
    for($i = 0; $i < $len ; $i ++){
        $tmp = intval($sNum[$i]);
        if($tmp == 1) {
            $iCnt++;
            if ($iCnt > 1)
                return FALSE;
        } else if($tmp != 0){
            return FALSE;
        }
    }
    return TRUE;
}

<?php

$n = intval( trim(fgets(STDIN)) );
$sLine = trim(fgets(STDIN));

$aLine = explode(' ',$sLine);

$bZero = TRUE;

$sNum = 0;
$iLen = 0;

for($i = 0; $i < $n; $i ++){
    if($aLine[$i] == '0'){
        echo 0;
        exit;
    }
    if(!isBecaufulNum($aLine[$i])){
        $sNum = $aLine[$i];
    } else {
        $iLen += intval( strlen($aLine[$i]) ) - 1;
    }
}
$L = strlen($sNum);
$j = 0;
for($i = 0; $i <  $L ; $i ++){
    if($sNum[$i] != 0 || ($sNum[$i] == 0 && $i + 1 == L)){
        $j = $i;
        break;
    }
}

for($i = $j ;$i < $L ;$i++){
    echo $sNum[$i];
}
for($i = 0; $i < $iLen ;$i++){
    echo 0;
}

function isBecaufulNum($sNum){
    $iCnt = 0;
    $len = strlen($sNum);
    for($i = 0; $i < $len ; $i ++){
        $tmp = intval($sNum[$i]);
        if($tmp == 1) {
            $iCnt++;
            if ($iCnt > 1)
                return FALSE;
        } else if($tmp != 0){
            return FALSE;
        }
    }
    return TRUE;
}

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/23  9:58
 */

while(fscanf(STDIN,"%d",$num)){
    $line = stream_get_line(STDIN,65535,"\n");
    $line = trim($line);
    $tanks = explode(" ",$line);
    //最后一个字符串会保留换行符
    $res = array();
    $flag = false;
    foreach($tanks as $t){
        //beautifle num 只有0和1组成
        //fprintf(STDOUT,"%s\n",$t);
        if( 0 == $t) {
            $flag = true;
            break;
        }

       // var_dump($t);
        if( substr_count($t,"0") + substr_count($t,"1") != strlen($t) ){
            //不是beautiful num 要保留前面的部分
            $head = $t;
         //   fprintf(STDOUT,"ss %d %d %d %s\n",substr_count($t,"0") , substr_count($t,"1"),strlen($t),$t);
        }else{
            //是beautiful num时记录要偏移的傡数
            $res[]= strlen($t);
        }

    }
    if($flag){
        fprintf(STDOUT,0);
    }else{
        fprintf(STDOUT,"%s",$head);
        for($i = 0 ; $i < count($res) ; $i++){
            for($zeroNum = 1 ; $zeroNum < $res[$i] ; $zeroNum++){
                fprintf(STDOUT,"0");
            }
        }
    }
    exit();
}

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/23  9:58
 */
while(fscanf(STDIN,"%d",$num)){
    $line = stream_get_line(STDIN,100002,"\n");
    $line = trim($line);
    $tanks = explode(" ",$line);
    //最后一个字符串会保留换行符 whitespaces
    $res = 0;
    $flag = false;
    foreach($tanks as $t){
        //fprintf(STDOUT,"%s\n",$t);
        if( "0" == $t ) {
            $flag = true;
            break;
        }
        //var_dump((substr_count($t,"0") + substr_count($t,"1") != strlen($t)));
       if($t[0] != '1'|| substr_count($t, "1") > 1 ){
            $head = $t;
       }else{
            $et = false;
            for($i = 0 ; $i < strlen($t);$i++){
                if($t[$i] != '0' and $t[$i] != '1'){
                    $head = $t;
                    $et = true;
                }
            }

            if(!$et)
                $res += strlen($t) - 1;
       }
    }
    if($flag){
        fprintf(STDOUT,0);
    }else{
        if(isset($head)) {
            fprintf(STDOUT,"%s",$head);
        }else{
            fprintf(STDOUT,1);
        }
        for($i = 0 ; $i < count($res) ; $i++){
            for($zeroNum = 0 ; $zeroNum < $res ; $zeroNum++){
                fprintf(STDOUT,"0");
            }
        }
    }
    exit();
}

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/23  9:58
 */
while(fscanf(STDIN,"%d",$num)){
    $line = stream_get_line(STDIN,65535,"\n");
    $line = trim($line);
    $tanks = explode(" ",$line);
    //最后一个字符串会保留换行符 whitespaces
    $res = 0;
    $flag = false;
    foreach($tanks as $t){
        //fprintf(STDOUT,"%s\n",$t);
        if( "0" == $t ) {
            $flag = true;
            break;
        }
        //var_dump((substr_count($t,"0") + substr_count($t,"1") != strlen($t)));
       if($t[0] != '1'|| substr_count($t, "1") > 1){
            $head = $t;
       }else{
            $et = false;
            for($i = 0 ; $i < strlen($t);$i++){
                if($t[$i] != '0' and $t[$i] != '1'){
                    $head = $t;
                    $et = true;
                }
            }

            if(!$et)
                $res += strlen($t) - 1;
       }
    }
    if($flag){
        fprintf(STDOUT,0);
    }else{
        if(isset($head)) {
            fprintf(STDOUT,"%s",$head);
        }else{
            fprintf(STDOUT,1);
        }
        for($i = 0 ; $i < count($res) ; $i++){
            for($zeroNum = 0 ; $zeroNum < $res ; $zeroNum++){
                fprintf(STDOUT,"0");
            }
        }
    }
    exit();
}

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/23  9:58
 */

while(fscanf(STDIN,"%d",$num)){
    $line = stream_get_line(STDIN,65535,"\n");
    $tanks = explode(" ",$line);
    $res = 1;
    foreach($tanks as $t){
        //beautifle num 只有0和1组成
        if( substr_count($t,"0") + substr_count($t,"1") != strlen($t) ){
            //不是beautiful num
        }else{
            //是beautiful num
        }

        $res *= $t;
    }
    fprintf(STDOUT,"%d",$res);

    exit();
}

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/23  9:58
 */
while(fscanf(STDIN,"%d",$num)){
    $line = stream_get_line(STDIN,65535,"\n");
    $line = trim($line);
    $tanks = explode(" ",$line);
    //最后一个字符串会保留换行符 whitespaces
    $res = 0;
    $flag = false;
    foreach($tanks as $t){
        //fprintf(STDOUT,"%s\n",$t);
        if( "0" == $t ) {
            $flag = true;
            break;
        }
        //var_dump((substr_count($t,"0") + substr_count($t,"1") != strlen($t)));
       if($t[0] != '1'){
            $head = $t;
       }else{
            $et = false;
            for($i = 0 ; $i < strlen($t);$i++){
                if($t[$i] != '0' and $t[$i] != '1'){
                    $head = $t;
                    $et = true;
                }
            }

            if(!$et)
                $res += strlen($t) - 1;
       }
    }
    if($flag){
        fprintf(STDOUT,0);
    }else{
        if(isset($head)) {
            fprintf(STDOUT,"%s",$head);
        }else{
            fprintf(STDOUT,1);
        }
        for($i = 0 ; $i < count($res) ; $i++){
            for($zeroNum = 0 ; $zeroNum < $res ; $zeroNum++){
                fprintf(STDOUT,"0");
            }
        }
    }
    exit();
}

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/23  9:58
 */
while(fscanf(STDIN,"%d",$num)){
    $line = stream_get_line(STDIN,65535,"\n");
    $line = trim($line);
    $tanks = explode(" ",$line);
    //最后一个字符串会保留换行符 whitespaces
    $res = 0;
    $flag = false;
    foreach($tanks as $t){
        //fprintf(STDOUT,"%s\n",$t);
        if( "0" == $t ) {
            $flag = true;
            break;
        }
        //var_dump((substr_count($t,"0") + substr_count($t,"1") != strlen($t)));
       if($t[0] != '1' || substr_count($t,"1") > 1){
            $head = $t;
       }else{
            $res += strlen($t) - 1;
       }
    }
    if($flag){
        fprintf(STDOUT,0);
    }else{
        if(isset($head)) {
            fprintf(STDOUT,"%s",$head);
        }else{
            fprintf(STDOUT,1);
        }
        for($i = 0 ; $i < count($res) ; $i++){
            for($zeroNum = 0 ; $zeroNum < $res ; $zeroNum++){
                fprintf(STDOUT,"0");
            }
        }
    }
    exit();
}

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/23  9:58
 */
while(fscanf(STDIN,"%d",$num)){
    $line = stream_get_line(STDIN,65535,"\n");
    $line = trim($line);
    $tanks = explode(" ",$line);
    //最后一个字符串会保留换行符 whitespaces
    $res = array();
    $flag = false;
    foreach($tanks as $t){
        //fprintf(STDOUT,"%s\n",$t);
        if( 0 == $t) {
            $flag = true;
            break;
        }
        //var_dump((substr_count($t,"0") + substr_count($t,"1") != strlen($t)));
        $oneNum = substr_count($t,"1");
        $zeroNum = substr_count($t, "0");
        if($oneNum <= 1 && ($oneNum + $zeroNum == strlen($t)) ){
            $res[]= strlen($t);
        }else{
            $head = $t;
        }
    }
    if($flag){
        fprintf(STDOUT,0);
    }else{
        if(isset($head)) {
            fprintf(STDOUT,"%s",$head);
        }else{
            fprintf(STDOUT,1);
        }
        for($i = 0 ; $i < count($res) ; $i++){
            for($zeroNum = 1 ; $zeroNum < $res[$i] ; $zeroNum++){
                fprintf(STDOUT,"0");
            }
        }
    }
    exit();
}

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/23  9:58
 */

while(fscanf(STDIN,"%d",$num)){
    $line = stream_get_line(STDIN,65535,"\n");
    $line = trim($line);
    $tanks = explode(" ",$line);
    //最后一个字符串会保留换行符
    $res = array();
    $flag = false;
    foreach($tanks as $t){
        //beautifle num 只有0和1组成
        //fprintf(STDOUT,"%s\n",$t);
        if( 0 == $t) {
            $flag = true;
            break;
        }

        //var_dump((substr_count($t,"0") + substr_count($t,"1") != strlen($t)));
        $oneNum = substr_count($t,"1");
        $zeroNum = substr_count($t, "0");
        if($oneNum <= 1 && ($oneNum + $zeroNum == strlen($t)) ){
            $res[]= strlen($t);
        }else{
            //是beautiful num时记录要偏移的傡数
            $head = $t;
            //fprintf(STDOUT,"ss %d %d %d %s\n",$oneNum , $zeroNum,strlen($t),$t);
        }
    }
    if($flag){
        fprintf(STDOUT,0);
    }else{
        fprintf(STDOUT,"%s",$head);
        for($i = 0 ; $i < count($res) ; $i++){
            for($zeroNum = 1 ; $zeroNum < $res[$i] ; $zeroNum++){
                fprintf(STDOUT,"0");
            }
        }
    }
    exit();
}


You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts. Suppose you decided to sell packs with $$$a$$$ cans in a pack with a discount and some customer wants to buy $$$x$$$ cans of cat food. Then he follows a greedy strategy:   he buys $$$\left\lfloor \frac{x}{a} \right\rfloor$$$ packs with a discount;  then he wants to buy the remaining $$$(x \bmod a)$$$ cans one by one. $$$\left\lfloor \frac{x}{a} \right\rfloor$$$ is $$$x$$$ divided by $$$a$$$ rounded down, $$$x \bmod a$$$ is the remainer of $$$x$$$ divided by $$$a$$$.But customers are greedy in general, so if the customer wants to buy $$$(x \bmod a)$$$ cans one by one and it happens that $$$(x \bmod a) \ge \frac{a}{2}$$$ he decides to buy the whole pack of $$$a$$$ cans (instead of buying $$$(x \bmod a)$$$ cans). It makes you, as a marketer, happy since the customer bought more than he wanted initially.You know that each of the customers that come to your shop can buy any number of cans from $$$l$$$ to $$$r$$$ inclusive. Can you choose such size of pack $$$a$$$ that each customer buys more cans than they wanted initially?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first and only line of each test case contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the range of the number of cans customers can buy.

For each test case, print YES if you can choose such size of pack $$$a$$$ that each customer buys more cans than they wanted initially. Otherwise, print NO. You can print each character in any case.

NoteIn the first test case, you can take, for example, $$$a = 5$$$ as the size of the pack. Then if a customer wants to buy $$$3$$$ cans, he'll buy $$$5$$$ instead ($$$3 \bmod 5 = 3$$$, $$$\frac{5}{2} = 2.5$$$). The one who wants $$$4$$$ cans will also buy $$$5$$$ cans.In the second test case, there is no way to choose $$$a$$$.In the third test case, you can take, for example, $$$a = 80$$$.

<?php

$in = 'php://stdin';
$input = fopen($in, "r");

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

$arr = [];

for ($i = 0; $i < $t; $i++) {
	list($x, $y) = explode(" ", trim(fgets($input)));

	$try = $y + 1;
	if (
		($x % $try >= $try / 2) &&
		($y % $try >= $try / 2)
	) {
		echo 'YES' . PHP_EOL;
	} else {
		echo 'NO' . PHP_EOL;
	}
}

<?php

ob_start(null, 65536);

$__ln = explode("\n", file_get_contents("php://stdin"));
$__lc = 0;

function nl() {
    global $__ln, $__lc;
    return $__ln[$__lc++];
}

function nla() {
    global $__ln, $__lc;
    return explode(" ", $__ln[$__lc++]);
}

function asInt($x) {
    return (int)$x;
}

function asDouble($x) {
    return (double)$x;
}

$tc = asInt(nl());
for($cc=0; $cc<$tc; $cc++) {
    list($l, $r) = array_map(asInt::class, nla());
    if($r >= 2 * $l) {
        echo "NO\n";
    } else {
        echo "YES\n";
    }
}


DZY loves Physics, and he enjoys calculating density.Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows:  where v is the sum of the values of the nodes, e is the sum of the values of the edges.Once DZY got a graph G, now he wants to find a connected induced subgraph G' of the graph, such that the density of G' is as large as possible.An induced subgraph G'(V', E') of a graph G(V, E) is a graph that satisfies:  ;  edge  if and only if , and edge ;  the value of an edge in G' is the same as the value of the corresponding edge in G, so as the value of a node. Help DZY to find the induced subgraph with maximum density. Note that the induced subgraph you choose must be connected.

The first line contains two space-separated integers n (1 ≤ n ≤ 500), . Integer n represents the number of nodes of the graph G, m represents the number of edges. The second line contains n space-separated integers xi (1 ≤ xi ≤ 106), where xi represents the value of the i-th node. Consider the graph nodes are numbered from 1 to n. Each of the next m lines contains three space-separated integers ai, bi, ci (1 ≤ ai < bi ≤ n; 1 ≤ ci ≤ 103), denoting an edge between node ai and bi with value ci. The graph won't contain multiple edges.

Output a real number denoting the answer, with an absolute or relative error of at most 10 - 9.

NoteIn the first sample, you can only choose an empty subgraph, or the subgraph containing only node 1.In the second sample, choosing the whole graph is optimal.

<?php

list($n, $m) = sscanf(fgets(STDIN), "%d%d");
$node_value = array_map(
    function ($x) {
        list($r) = sscanf($x, "%d");
        return $r;
    },
    explode(" ", trim(fgets(STDIN))));
$res = 0.0;
for ($i = 0; $i < $m; ++$i) {
    list($a, $b, $w) = sscanf(fgets(STDIN), "%d%d%d");
    $res = max($res, ($node_value[$a - 1] + $node_value[$b - 1]) / $w);
}
echo number_format($res, 9, '.', ''), "\n";

?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
array_unshift($c, " ");
unset($c[0]);
$d = array();
for($x = 1; $x <= $b; $x++)
{
    list($e, $f, $g) = explode(" ", trim(fgets(STDIN)));
    $h = number_format(($c[$e] + $c[$f]) / $g, 15, ".", "");
    array_push($d, $h);
}
rsort($d);
print $d[0];
?>

<?php

list($n, $m) = sscanf(fgets(STDIN), "%d%d");
$node_value = array_map(
    function ($x) {
        list($r) = sscanf($x, "%d");
        return $r;
    },
    explode(" ", trim(fgets(STDIN))));
$res = 0.0;
for ($i = 0; $i < $m; ++$i) {
    list($a, $b, $w) = sscanf(fgets(STDIN), "%d%d%d");
    $res = max($res, ($node_value[$a - 1] + $node_value[$b - 1]) / $w);
}
echo number_format($res, 9), "\n";

?>