A median of an array of integers of length $$$n$$$ is the number standing on the $$$\lceil {\frac{n}{2}} \rceil$$$ (rounding up) position in the non-decreasing ordering of its elements. Positions are numbered starting with $$$1$$$. For example, a median of the array $$$[2, 6, 4, 1, 3, 5]$$$ is equal to $$$3$$$. There exist some other definitions of the median, but in this problem, we will use the described one.Given two integers $$$n$$$ and $$$k$$$ and non-decreasing array of $$$nk$$$ integers. Divide all numbers into $$$k$$$ arrays of size $$$n$$$, such that each number belongs to exactly one array.You want the sum of medians of all $$$k$$$ arrays to be the maximum possible. Find this maximum possible sum.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of test cases. The first line of the description of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 \leq n, k \leq 1000$$$). The second line of the description of each test case contains $$$nk$$$ integers $$$a_1, a_2, \ldots, a_{nk}$$$ ($$$0 \leq a_i \leq 10^9$$$) — given array. It is guaranteed that the array is non-decreasing: $$$a_1 \leq a_2 \leq \ldots \leq a_{nk}$$$. It is guaranteed that the sum of $$$nk$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print a single integer — the maximum possible sum of medians of all $$$k$$$ arrays.


Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.

The first line of the input contains one integer, n (1 ≤ n ≤ 100 000). The next line contains n space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.

Print the maximum possible even sum that can be obtained if we use some of the given integers.

NoteIn the first sample, we can simply take all three integers for a total sum of 6.In the second sample Wet Shark should take any four out of five integers 999 999 999.

<?php
$n = (int)fgets(STDIN);
$a = explode(" ", trim(fgets(STDIN)));
sort($a);
$sum = "0";
foreach ($a as $n) {
  $sum = bcadd($sum, $n);
}
if (bcmod($sum, 2)) {
  foreach ($a as $n) {
    if ($n % 2) {
      $sum = bcsub($sum, $n);
      break;
    }
  }
}

echo "$sum\n";

<?php
$n = trim(fgets(STDIN));
$arr = explode(" ", trim(fgets(STDIN)));
sort($arr);

$k = array_sum($arr);
$i = 0;
while($k%2 != 0) {
    if($arr[$i]%2 != 0)
        $k -= $arr[$i];
    $i++;
}
echo $k;
?>

<?php

$n = trim(fgets(STDIN));

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

sort($arSearch);
$summ = array_sum($arSearch);

if ($summ%2 == 0)
    printf("%.0f",$summ);
else
{
    foreach ($arSearch as $val)
    {

        $asw = $summ - $val;
        if ($asw%2 == 0)
        {
            printf("%.0f",$asw);
            die();
        }
    }
    echo "0";
}

<?php
$n = trim(fgets(STDIN));
$arr = explode(" ", trim(fgets(STDIN)));
sort($arr);

$i = 0;
$k = array_sum($arr);
while($k%2 != 0) {
    $k -= $arr[$i];
    $i++;
}
echo $k;
?>

<?php

$n = trim(fgets(STDIN));

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

sort($arSearch);
$summ = array_sum($arSearch);

if ($summ%2 == 0) printf("%.0f",$summ);
else
{
    foreach ($arSearch as $val)
    {
        $asw = $summ - $val;
        if ($asw%2 == 0) printf("%.0f",$asw);
            die();
    }
    echo 0;
}

<?php

$n = trim(fgets(STDIN));

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

sort($arSearch);
$summ = array_sum($arSearch);

if ($summ%2 == 0) echo round($summ);
else
{
    foreach ($arSearch as $val)
    {
        $asw = $summ - $val;
        if ($asw%2 == 0) echo round($asw);
            die();
    }
    echo 0;
}

<?php

$n = trim(fgets(STDIN));

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

sort($arSearch);
$summ = array_sum($arSearch);

if ($summ%2 == 0) echo $summ;
else
{
    foreach ($arSearch as $val)
    {
        $asw = $summ - $val;
        if ($asw%2 == 0) echo $asw;
            die();
    }
    echo 0;
}


Given the integer $$$n$$$ — the number of available blocks. You must use all blocks to build a pedestal. The pedestal consists of $$$3$$$ platforms for $$$2$$$-nd, $$$1$$$-st and $$$3$$$-rd places respectively. The platform for the $$$1$$$-st place must be strictly higher than for the $$$2$$$-nd place, and the platform for the $$$2$$$-nd place must be strictly higher than for the $$$3$$$-rd place. Also, the height of each platform must be greater than zero (that is, each platform must contain at least one block).    Example pedestal of $$$n=11$$$ blocks: second place height equals $$$4$$$ blocks, first place height equals $$$5$$$ blocks, third place height equals $$$2$$$ blocks.Among all possible pedestals of $$$n$$$ blocks, deduce one such that the platform height for the $$$1$$$-st place minimum as possible. If there are several of them, output any of them.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case contains a single integer $$$n$$$ ($$$6 \le n \le 10^5$$$) — the total number of blocks for the pedestal. All $$$n$$$ blocks must be used. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^6$$$.

For each test case, output $$$3$$$ numbers $$$h_2, h_1, h_3$$$ — the platform heights for $$$2$$$-nd, $$$1$$$-st and $$$3$$$-rd places on a pedestal consisting of $$$n$$$ blocks ($$$h_1+h_2+h_3=n$$$, $$$0 < h_3 < h_2 < h_1$$$).  Among all possible pedestals, output the one for which the value of $$$h_1$$$ minimal. If there are several of them, output any of them.

NoteIn the first test case we can not get the height of the platform for the first place less than $$$5$$$, because if the height of the platform for the first place is not more than $$$4$$$, then we can use at most $$$4 + 3 + 2 = 9$$$ blocks. And we should use $$$11 = 4 + 5 + 2$$$ blocks. Therefore, the answer 4 5 2 fits. In the second set, the only suitable answer is: 2 3 1.

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

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

 function solve()
 {
     $n = IO::getInt();

     $ans = [];
     $h1 = $h1 = $h3 = 0;

     $h2 = round($n/3);
     $h3 = $h2-1;
     $h1 = $n-$h2-$h3;

     if($h2==$h1) {
          $h3 -=1;
          $h1 +=1;
     }

      IO::pr("$h2 $h1 $h3");

 }

 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
$iter = InOutPut::get();

for($i=0; $i <$iter; $i++) {
       $ans = [];
       $n = InOutPut::get();

       $n2 = round($n/3);
       $n3 = $n2 - 1;
       $n1 = $n - $n2 - $n3;

       if($n1 == $n2){
       	$n3 -= 1;
       	$n1 = $n1 + 1;
       }
       $ans = $n2 . " " . $n1 . " " . $n3;

       	InOutPut::print($ans);
}
class InOutPut {
      public static function get()
      {
          return trim(fgets(STDIN));
      }

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

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

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

 function solve()
 {
     $n = IO::getInt();

     $ans = [];
     $h1 = $h1 = $h3 = 0;

     if(($n-1)%2 == 0) {
          $h3 = 2;
     } else {
          $h3 = 1;
     }
     $h2 = floor(($n-$h3)/2);
     if($h2 == $h3) {
          if($h3 == 2) {
               $h3 = $h3 - 1;
          }
     }
          $h1 = $n - $h3 - $h2;

      IO::pr("$h2 $h1 $h3");

 }

 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
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     $n = IO::getInt();

     $ans = [];
     $h1 = $h1 = $h3 = 0;

     if(($n-1)%2 == 0) {
          $h3 = 2;
     } else {
          $h3 = 1;
     }
     $h2 = floor(($n-1)/2);
          $h1 = $n - $h3 - $h2;

      IO::pr("$h1 $h2 $h3");

 }

 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
$iter = InOutPut::get();

for($i=0; $i <$iter; $i++) {
       $ans = [];
       $n = InOutPut::get();

       $n2 = floor($n/3);
       $n3 = $n2 - 1;
       $n1 = $n - $n2 - $n3;

       if($n1 == $n2){
       	$n3 = $n3 - 1;
       	$n1 = $n1 + 1;
       }
       $ans = $n2 . " " . $n1 . " " . $n3;

       	InOutPut::print($ans);
}
class InOutPut {
      public static function get()
      {
          return trim(fgets(STDIN));
      }

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


You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.The following definition of a regular bracket sequence is well-known, so you can be familiar with it.Let's define a regular bracket sequence (RBS). Empty string is RBS. Let s1 and s2 be a RBS then the strings <s1>s2, {s1}s2, [s1]s2, (s1)s2 are also RBS.For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.Determine the least number of replaces to make the string s RBS.

The only line contains a non empty string s, consisting of only opening and closing brackets of four kinds. The length of s does not exceed 106.

If it's impossible to get RBS from s print Impossible. Otherwise print the least number of replaces needed to get RBS from s.

<?php
    $s = trim(fgets(STDIN));
    $n = strlen($s);
    $stack = array();
    $ans = 0;
    for ($i = 0; $i < $n; $i++) {
        $c = substr($s, $i, 1);
        if ($c == ')') {
            if (count($stack) == 0) { $ans = 'Impossible'; break; }
            if (array_pop($stack) != '(') $ans++;
        } elseif ($c == ']') {
            if (count($stack) == 0) { $ans = 'Impossible'; break; }
            if (array_pop($stack) != '[') $ans++;
        } elseif ($c == '}') {
            if (count($stack) == 0) { $ans = 'Impossible'; break; }
            if (array_pop($stack) != '{') $ans++;
        } elseif ($c == '>') {
            if (count($stack) == 0) { $ans = 'Impossible'; break; }
            if (array_pop($stack) != '<') $ans++;
        } else {
            $stack[] = $c;
        }
    }

    echo count($stack) > 0 ? 'Impossible' : $ans;


The student council has a shared document file. Every day, some members of the student council write the sequence TMT (short for Towa Maji Tenshi) in it.However, one day, the members somehow entered the sequence into the document at the same time, creating a jumbled mess. Therefore, it is Suguru Doujima's task to figure out whether the document has malfunctioned. Specifically, he is given a string of length $$$n$$$ whose characters are all either T or M, and he wants to figure out if it is possible to partition it into some number of disjoint subsequences, all of which are equal to TMT. That is, each character of the string should belong to exactly one of the subsequences.A string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero) characters.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$3 \le n < 10^5$$$), the number of characters in the string entered in the document. It is guaranteed that $$$n$$$ is divisible by $$$3$$$. The second line of each test case contains a string of length $$$n$$$ consisting of only the characters T and M. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print a single line containing YES if the described partition exists, and a single line containing NO otherwise.

5
3
TMT
3
MTT
6
TMTMTT
6
TMTTTT
6
TTMMTT

NoteIn the first test case, the string itself is already a sequence equal to TMT.In the third test case, we may partition the string into the subsequences TMTMTT. Both the bolded and the non-bolded subsequences are equal to TMT.

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

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

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

  $str = trim(fgets($file));
  $e = str_split($str);

  if ($str[0] == 'M') { echo 'NO'.PHP_EOL; }
  else {
    if ($str[$n - 1] == 'M') { echo 'NO'.PHP_EOL; }
    else {
      $g = $n / 3;
      $a = array_count_values($e);
      if ($a['M'] != $g && $a['T'] != $g * 2) { echo 'NO'.PHP_EOL; }
      else {
        $tt = 0; $mm = 0; $f = 0;
        for ($j = 0; $j < $n; $j++) {
          if ($str[$j] == 'T') { $tt++; }
          if ($str[$j] == 'M') {
            $mm++;
            if ($tt < $mm) { $f = 1; break; }
          }
        }

        if ($f != 1) {
          $str = strrev($str);
          $tt = 0; $mm = 0; $f = 0;
          for ($j = 0; $j < $n; $j++) {
            if ($str[$j] == 'T') { $tt++; }
            if ($str[$j] == 'M') {
              $mm++;
              if ($tt < $mm) { $f = 1; break; }
            }
          }

          if ($f != 1) { echo 'YES'.PHP_EOL; }
          else { echo 'NO'.PHP_EOL; }

        } else { echo 'NO'.PHP_EOL; }
      }
    }
  }
}

?>

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = str_split(IO::str());
    $d = array_reverse($a);
    $t = $m = 0;
    $bool = true;
    foreach ($a as $v) {
        if ($v == 'T') {
            $t++;
        } else {
            $m++;
        }
        if ($m > $t) {
            $bool = false;
            break;
        }
    }
    if ($bool) {
        $t = $m = 0;
        foreach ($d as $v) {
            if ($v == 'T') {
                $t++;
            } else {
                $m++;
            }
            if ($m > $t) {
                $bool = false;
                break;
            }
        }
    }

    if ($m * 2 == $t && $bool) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>

<?php

$map = [];
fscanf(STDIN, "%d", $n);

for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d", $l);
    $s = trim(fgets(STDIN));

    $can = true;
    $m = 0;

    $left = 0;
    $len = strlen($s);

    for ($j = 0; $j < $len; ++$j) {
        if ($s[$j] === 'T') {
            $left++;
        } else {
            $left--;
            $m++;
        }

        if ($left < 0) {
            $can = false;
        }
    }

    $right = 0;
    for ($j = $len-1; $j >= 0; --$j) {
        if ($s[$j] === 'T') {
            $right++;
        } else {
            $right--;
        }

        if ($right < 0) {
            $can = false;
        }
    }

    if($m !== $len / 3){
        $can = false;
    }

    if ($can) {
        echo 'YES' . PHP_EOL;
    } else {
        echo 'NO' . PHP_EOL;
    }
}

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

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

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

  $str = trim(fgets($file));
  $e = str_split($str);

  if ($str[0] == 'M') { echo 'NO'.PHP_EOL; }
  else {
    if ($str[$n - 1] == 'M') { echo 'NO'.PHP_EOL; }
    else {
      $g = $n / 3;
      $a = array_count_values($e);
      if ($a['M'] != $g && $a['T'] != $g * 2) { echo 'NO'.PHP_EOL; }
      else {
        $tt = 0; $mm = 0; $f = 0;
        for ($j = 0; $j < $n; $j++) {
          if ($str[$j] == 'T') { $tt++; }
          if ($str[$j] == 'M') {
            $mm++;
            if ($tt < $mm) { $f = 1; break; }
          }
        }

        if ($f != 1) {
          $str1 = strrev($str);
          $tt = 0; $mm = 0; $f = 0;
          for ($j = 0; $j < $n; $j++) {
            if ($str[$j] == 'T') { $tt++; }
            if ($str[$j] == 'M') {
              $mm++;
              if ($tt < $mm) { $f = 1; break; }
            }
          }

          if ($f != 1) { echo 'YES'.PHP_EOL; }
          else { echo 'NO'.PHP_EOL; }

        } else { echo 'NO'.PHP_EOL; }
      }
    }
  }
}

?>

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

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

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

  $str = trim(fgets($file));
  $e = str_split($str);

  if ($str[0] == 'M') { echo 'NO'.PHP_EOL; }
  else {
    if ($str[$n - 1] == 'M') { echo 'NO'.PHP_EOL; }
    else {
      $g = $n / 3;
      $a = array_count_values($e);
      if ($a['M'] != $g && $a['T'] != $g * 2) { echo 'NO'.PHP_EOL; }
      else {
        $tt = 0; $mm = 0; $f = 0;
        for ($j = 0; $j < $n; $j++) {
          if ($str[$j] == 'T') { $tt++; }
          if ($str[$j] == 'M') {
            $mm++;
            if ($tt < $mm) { $f = 1; break; }
          }
        }
      if ($f != 1) { echo 'YES'.PHP_EOL; }
      else { echo 'NO'.PHP_EOL; }
      }
    }
  }
}

?>

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

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

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

  $str = trim(fgets($file));
  $e = str_split($str);

  if ($str[0] == 'M') { echo 'NO'.PHP_EOL; }
  else {
    if ($str[$n - 1] == 'M') { echo 'NO'.PHP_EOL; }
    else {
      $g = $n / 3;
      $a = array_count_values($e);
      if ($a['M'] != $g && $a['T'] != $g * 2) { echo 'NO'.PHP_EOL; }
      else {
        echo 'YES'.PHP_EOL;
      }
    }
  }
}

?>

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

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

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

  $str = trim(fgets($file));
  $e = str_split($str);

  if ($str[0] == 'M') { echo 'NO'.PHP_EOL; }
  else {
    if ($str[$n - 1] == 'M') { echo 'NO'.PHP_EOL; }
    else {
      $g = $n / 3;
      $a = array_count_values($e);
      if ($a['M'] != $g) { echo 'NO'.PHP_EOL; }
      else {
        for ($j = 0; $j < $g; $j++) {
          $pos = strpos('T', $str);
          $str = substr_replace($str, '', $pos, $pos + 1);

          $pos = strpos('M', $str);
          $str = substr_replace($str, '', $pos, $pos + 1);
        }

        $s = '';
        for ($j = 0; $j < $g; $j++) { $s .= 'T'; }

        if ($str == $s) { echo 'YES'.PHP_EOL; }
        else { echo 'NO'.PHP_EOL; }
      }
    }
  }
}

?>

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = str_split(IO::str());
    $t = $m = 0;
    $bool = true;
    foreach ($a as $v) {
        if ($v == 'T') {
            $t++;
        } else {
            $m++;
        }
        if ($m > $t) {
            $bool = false;
            break;
        }
    }
    if ($m * 2 == $t && $bool) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>


The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dn - 1 is the distance between the n - 1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.

The first line contains integer n (3 ≤ n ≤ 100) — the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 100) — the distances between pairs of neighboring stations. The third line contains two integers s and t (1 ≤ s, t ≤ n) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces.

Print a single number — the length of the shortest path between stations number s and t.

NoteIn the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
list($c, $d) = explode(" ", trim(fgets(STDIN)));
$g = 0;
$h = 0;
if($c == $d)
{
    print "0";
}
else
{
    $e = min($c, $d) - 1;
    $f = max($c, $d) - 2;
    for($x = $e; $x <= $f; $x++)
    {
        $g += $b[$x];
    }
    $h = array_slice($b, $e, $f - $e + 1);
    $i = array_sum($h);
    $j = array_sum($b) - $i;
    print min($g, $j);
}
?>

<?PHP
$putdata = fopen("php://stdin", "r");
$data = fread($putdata, 500000);
fclose($putdata);
$tr = fopen('php://output', 'w');

$a = explode("\n",$data);
$n = intval($a[0]);
$sts = explode(' ',$a[1]);
$a[2] = explode(' ',$a[2]);
$st1 = intval($a[2][0]);
$st2 = intval($a[2][1]);
if($st1==$st2){fputs($tr,0); die();}
if($st1>$st2){$st1=intval($a[2][1]);$st2=intval($a[2][0]);}
$way=0;
$allway=0;
for($i=0;$i<$n;$i++){$allway += $sts[$i];}
for ($i=$st1-1;$i<($st2-1);$i++){
    $way+=$sts[$i];
}
$backway=$allway-$way;
if($backway>$way){$ans=$way;}else{$ans=$backway;}

fputs($tr,$ans);

<?
$putdata = fopen("php://stdin", "r");
$data = fread($putdata, 300000);
fclose($putdata);
$data = explode("\n",$data); //Каждая строка
$data2=explode(" ",$data[1]); //Растояние между каждой станцией
$st=explode(" ",$data[2]); //Искомы естанции st[0] - 1; st[2] - 2

$kol=(int)$data[0];

$st1=(int)$st[0];
$st2=(int)$st[1];

if((int)$st[0]==(int)$st[1]){
$otvet=0;
}else{

$st1=(int)$st[0];
$st2=(int)$st[1];

while(1){
    if($st1==$st2){ break;}//Если дошли до станции

    if($st1==$kol){
    $s=$st1;
    $st1=0;
    $sum1=$sum1+$data2[$s-1];
    }else{
    $sum1=$sum1+$data2[$st1-1];
    }

    $st1++;
}

$st1=(int)$st[0];
$st2=(int)$st[1];
$s=0;
while(1){
    if($st1==$st2){ break;}//Если дошли до станции

    if($st2==$kol){
    $s=$st2;
    $st2=0;
    $sum2=$sum2+$data2[$s-1];
    }else{
    $sum2=$sum2+$data2[$st2-1];
    }
    $st2++;
}

if($sum1<$sum2){
$otvet=$sum1;
}elseif($sum1>$sum2){
$otvet=$sum2;
}elseif($sum1==$sum2){
$otvet=$sum1;
}
}
//$otvet=$sum1." ".$sum2;
//Вывод ответа
$out = fopen('php://output', 'w');
fputs($out,$otvet);

<?php

$stationCnt = (int) trim(fgets(STDIN));
$distances = array_map(function($n) { return (int) $n; }, explode(' ', trim(fgets(STDIN))));
$targets = explode(' ', trim(fgets(STDIN)));
$s = (int) $targets[0];
$t = (int) $targets[1];

if ($s === $t) {
	echo 0;
} else {
	if ($s > $t) {
		list($s, $t) = [$t,$s];
	}

	$s--; $t--;

	$directPath = 0;
	for ($i = $s; $i < $t; $i++) {
		$directPath += $distances[$i];
	}

	$reversePath = 0;
	for ($i = $t; $i != $s; $i = ($i + 1) % $stationCnt) {
		$reversePath += $distances[$i];
	}

	echo $directPath > $reversePath ? $reversePath : $directPath;
}

<?php
fscanf(STDIN, "%d",$n);
$num = fgets(STDIN);
$b = explode(' ', $num);
$sum = 0;
for($i = 0;$i < $n;$i ++){
    $a[$i] = intval($b[$i]);
    $sum += $a[$i];
}
$num = fgets(STDIN);
$b = explode(' ', $num);
$st = intval($b[0]);
$end = intval($b[1]);
if($st > $end){
    $tmp = $st;
    $st = $end;
    $end = $tmp;
}

$sum1 = 0;

for($i = $st-1;$i < $end-1;$i ++){
    $sum1 += $a[$i];
}

if($sum1 < $sum - $sum1){
    printf("%d", $sum1 );
}else {
    printf("%d", $sum - $sum1);
}

?>

<?php
// 278A   Кольцевая
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$n = (int) $input_line;

$input_line = fgets($in);
$arrD = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$input_line = fgets($in);
list($s, $t) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);
$s = (int) $s;
$t = (int) $t;

if ($s > $t) {
    $tmp = $s;
    $s = $t;
    $t = $tmp;
}

function sumArray($from, $to, $arr)
{
    $sum  = 0;
    for ($i=$from-1; $i < $to-1 ; $i++) {
        $sum += (int) $arr[$i];
    }

    return $sum;
}

$left = sumArray(1, $s, $arrD) + sumArray($t, $n+1, $arrD);
$rigth = sumArray($s, $t, $arrD);

echo min($left, $rigth);

?>

<?// BismiLahi Rahmani Rahim ?>

<?php

fscanf(STDIN, "%d", $n);
$d = explode(" ", trim(fgets(STDIN)));

fscanf(STDIN, "%d %d", $s, $t);
$s --;
$t --;

if ($s > $t) swap($s, $t);

$dist1 = 0;
$dist2 = 0;

$start = $t;
$end = $s;

while ($start != $end) {
	$dist1 += $d[$start];
	$start = ($start + 1) % $n;
}

$start = $s;
$end = $t;

while ($start != $end) {
	$dist2 += $d[$start];
	$start = ($start + 1) % $n;
}

printf("%d", min($dist1, $dist2));

function swap(&$a, &$b) {
	$t = $a;
	$a = $b;
	$b = $t;
}

?>

<?php
error_reporting("off");
//278A: Circle Line
$n = trim(fgets(STDIN)); //$n = 3;
$d = explode(" ", trim(fgets(STDIN))); //$d = explode(" ", "31 41 59");
$tosort = explode(" ", trim(fgets(STDIN)));
sort($tosort);
list($s, $t) = $tosort; //so that s and t aren't true anymore but s <= t
//$s = 1; $t = 1;
$betweenforward = $t - $s;
$distfor = 0;
$distbac = 0;
$curindex = $s - 1;
for ($i = 0; $i < $betweenforward; $i++) {
    $distfor += $d[$curindex];
    $curindex++;
}
$distbac = array_sum($d) - $distfor;if ($distfor <= $distbac) {
    echo $distfor;
} else {
    echo $distbac;
}
?>

<?php
    $n = trim(fgets(STDIN));
    $d = explode(" ", trim(fgets(STDIN)));
    $st = explode(" ", trim(fgets(STDIN)));
    $s = ((int)$st[0])-1;
    $t = ((int)$st[1])-1;

    if ($s == $t) {fwrite(STDOUT,"0"); exit; }
    if ($s > $t){ $tmp = $s; $s = $t; $t = $tmp;}

    for ($i=0, $end = abs($t-$s); $i<$end; $i++){
        $res1 += $d[$s+$i];
    }
    for ($i=0, $end = $n-$s-2; $i<$end; $i++){
        $now = $t+$i;
        if ($now > $n) $now = $i;
        $res2 += $d[$now];
    }
    if ($res1 < $res2){
        fwrite(STDOUT,"$res1");
    }else{
        fwrite(STDOUT,"$res2");
    }
?>

<?php
    $n = trim(fgets(STDIN));
    $d = explode(" ", trim(fgets(STDIN)));
    $st = explode(" ", trim(fgets(STDIN)));
    $s = ((int)$st[0])-1;
    $t = ((int)$st[1])-1;
    $z = abs($s-$t);

    if ($s == $t) {fwrite(STDOUT,"0"); exit; }
    if ($s > $t){ $tmp = $s; $s = $t; $t = $tmp;}

    for ($i=0, $end = abs($t-$s); $i<$end; $i++){
        $res1 += $d[$s+$i];
    }
    for ($i=0, $end = $n-$t+$z; $i<$end; $i++){
        $now = $t+$i;
        if ($now > $n) $now = $i;
        $res2 += $d[$now];
    }
    if ($res1 < $res2){
        fwrite(STDOUT,"$res1");
    }else{
        fwrite(STDOUT,"$res2");
    }
?>

<?//johnbug?>

<?php
fscanf(STDIN, "%d",$n);

$sum = 0;
for($i = 0;$i < $n;$i ++){
    fscanf(STDIN, "%d",$num);
    $sum += $num;
    $a[$i] = $num;
}
fscanf(STDIN, "%d",$st);
fscanf(STDIN, "%d",$end);

if($st > $end){
    $tmp = $st;
    $st = $end;
    $end = $tmp;
}

$sum1 = 0;

for($i = $st-1;$i < $end-1;$i ++){
    $sum1 += $a[$i];
}

if($sum1 < $sum - $sum1){
    printf("%d", $sum1 );
}else {
    printf("%d", $sum - $sum1);
}

?>


A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:  Is it true that y is strictly larger than number x?  Is it true that y is strictly smaller than number x?  Is it true that y is larger than or equal to number x?  Is it true that y is smaller than or equal to number x? On each question the host answers truthfully, "yes" or "no".Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".

The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:   ">" (for the first type queries),  "<" (for the second type queries),  ">=" (for the third type queries),  "<=" (for the fourth type queries).  All values of x are integer and meet the inequation  - 109 ≤ x ≤ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no"). Consequtive elements in lines are separated by a single space.

Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation  - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).

<?php
$a = trim(fgets(STDIN));
$e = -2000000000;
$f = 2000000000;
for($x = 1; $x <= $a; $x++)
{
    list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
    if($d == "Y")
    {
        switch($b)
        {
            case ">":
            $e = max($e, $c + 1);
            break;
            case "<":
            $f = min($f, $c - 1);
            break;
            case ">=":
            $e = max($e, $c);
            break;
            case "<=":
            $f = min($f, $c);
            break;
        }
    }
    else
    {
        switch($b)
        {
            case ">":
            $f = min($f, $c);
            break;
            case "<":
            $e = max($e, $c);
            break;
            case ">=":
            $f = min($f, $c - 1);
            break;
            case "<=":
            $e = max($e, $c + 1);
            break;
        }
    }
}
if($e > $f)
{
    print "Impossible";
}
else
{
    print rand($e, $f);
}
?>

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

// pow('UGH', 2)
$max = 2000000000;
$min = -2000000000;

for($i = 0; $i<$n; $i++):
	list($sym, $val, $ans) = explode(" ", trim(fgets(STDIN)));

	if( ($sym == ">" && $ans == "Y"))
	{
		// fix for super imposed rules
		$min = max($min, $val + 1);
		continue;
	}

	// split these out since a negative does not prohibit use of val
	if($sym == "<" && $ans == "N")
	{
		$min = max($min, $val);
		continue;
	}

	if( ($sym == "<" && $ans == "Y") )
	{
		$max = min($max, $val - 1);
		continue;
	}

	// non prohibit fix
	if($sym == ">" && $ans == "N")
	{
		$max = min($max, $val);
		continue;
	}

	if( ($sym == "<=" && $ans == "Y") || ($sym == ">=" && $ans == "N") )
	{
		$max = min($val, $max);
		continue;
	}

	if( ($sym == ">=" && $ans == "Y") || ($sym == "<=" && $ans == "N") )
	{
		$min = max($min, $val);
	}

endfor;

if( $max < $min )
{
	echo "Impossible";
} else {
	echo rand($min, $max);
}

echo PHP_EOL;

<?php
fscanf(STDIN, "%d", $n);
$min=-2000000000;
$max=2000000000;
for ($i = 0; $i<$n; $i++){
    fscanf(STDIN, '%s %d %s\n', $cmp, $x, $answer);
    if ($answer=='N'){
        switch($cmp){
            case '>=':
                $cmp='<';
                break;
            case '>':
                $cmp='<=';
                break;
            case '<=':
                $cmp='>';
                break;
            case '<':
                $cmp='>=';
                break;
        }
    }
        switch ($cmp){
            case '>=':
                $min=max($min,$x);
                break;
            case '>':
                $min=max($min,$x+1);
                break;
            case '<=':
                $max=min($max,$x);
                break;
            case '<':
                $max=min($max,$x-1);
                break;
        }
}
if ($max<$min || $max>2000000000 || $min<-2000000000)
    echo "Impossible";
else
    fprintf(STDOUT, "%0.0f",$max);

<?php
function inverse( $str ) // error no poner $
{
   $val = "";
   if($str == ">")
      $val =  "<=";
   else if($str == "<")
      $val = ">=";
   else  if($str == ">=")
      $val = "<";
   else
      $val = ">";
   return $val;
}

$min_ = -2000000000;
$max_ = 2000000000;
$n = trim(fgets(STDIN));
for($i = 0; $i < $n; ++$i)
{
   $arr = explode(" ", trim(fgets(STDIN)));
   $sign = $arr[0];
   $num = $arr[1];
   $yn = $arr[2];
   if($yn == "N")
     $sign = inverse($sign);
   if($sign == "<=")
      $max_ = min($max_, $num);
   else if($sign == "<")
      $max_ = min($max_, $num - 1);
   else  if($sign == ">=")
      $min_ = max($min_, $num);
   else
      $min_ = max($min_, $num + 1);
}
if($min_ <= $max_)
   printf("%d", $min_);
else
   print("Impossible");

?>

<?php
$a = trim(fgets(STDIN));
$e = -2000000000;
$f = 2000000000;
for($x = 1; $x <= 4; $x++)
{
    list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
    if($d == "Y")
    {
        switch($b)
        {
            case ">":
            $e = max($e, $c + 1);
            break;
            case "<":
            $f = min($f, $c - 1);
            break;
            case ">=":
            $e = max($e, $c);
            break;
            case "<=":
            $f = min($f, $c);
            break;
        }
    }
    else
    {
        switch($b)
        {
            case ">":
            $f = min($f, $c);
            break;
            case "<":
            $e = max($e, $c);
            break;
            case ">=":
            $f = min($f, $c - 1);
            break;
            case "<=":
            $e = max($e, $c + 1);
            break;
        }
    }
}
if($e > $f)
{
    print "Impossible";
}
else
{
    print rand($e, $f);
}
?>

<?php
$a = trim(fgets(STDIN));
$e = -1000000000;
$f = 1000000000;
for($x = 1; $x <= 4; $x++)
{
    list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
    if($d == "Y")
    {
        switch($b)
        {
            case ">":
            $e = max($e, $c + 1);
            break;
            case "<":
            $f = min($f, $c - 1);
            break;
            case ">=":
            $e = max($e, $c);
            break;
            case "<=":
            $f = min($f, $c);
            break;
        }
    }
    else
    {
        switch($b)
        {
            case ">":
            $f = min($f, $c - 1);
            break;
            case "<":
            $e = max($e, $c + 1);
            break;
            case ">=":
            $f = min($f, $c);
            break;
            case "<=":
            $e = max($e, $c);
            break;
        }
    }
}
if($e > $f)
{
    print "Impossible";
}
else
{
    print rand($e, $f);
}
?>

<?php
$a = trim(fgets(STDIN));
$e = -1000000000;
$f = 1000000000;
for($x = 1; $x <= 4; $x++)
{
    list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
    if($d == "Y")
    {
        switch($b)
        {
            case ">":
            $e = max($e, $c + 1);
            break;
            case "<":
            $f = min($f, $c - 1);
            break;
            case ">=":
            $e = max($e, $c);
            break;
            case "<=":
            $f = min($f, $c);
            break;
        }
    }
    else
    {
        switch($b)
        {
            case ">":
            $f = min($f, $c);
            break;
            case "<":
            $e = max($e, $c);
            break;
            case ">=":
            $f = min($f, $c - 1);
            break;
            case "<=":
            $e = max($e, $c + 1);
            break;
        }
    }
}
if($e > $f)
{
    print "Impossible";
}
else
{
    print rand($e, $f);
}
?>

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

$max = PHP_INT_MAX;
$min = -PHP_INT_MAX;

for($i = 0; $i<$n; $i++):
	list($sym, $val, $ans) = explode(" ", trim(fgets(STDIN)));

	if( ($sym == ">" && $ans == "Y"))
	{
		// fix for super imposed rules
		$min = max($min, $val + 1);
		continue;
	}

	// split these out since a negative does not prohibit use of val
	if($sym == "<" && $ans == "N")
	{
		$min = max($min, $val);
		continue;
	}

	if( ($sym == "<" && $ans == "Y") )
	{
		$max = min($max, $val - 1);
		continue;
	}

	// non prohibit fix
	if($sym == ">" && $ans == "N")
	{
		$max = min($max, $val);
		continue;
	}

	if( ($sym == "<=" && $ans == "Y") || ($sym == ">=" && $ans == "N") )
	{
		$max = min($val, $max);
		continue;
	}

	if( ($sym == ">=" && $ans == "Y") || ($sym == "<=" && $ans == "N") )
	{
		$min = max($min, $val);
	}

endfor;

if( $max < $min )
{
	echo "Impossible";
} else {
	echo rand($min, $max);
}

echo PHP_EOL;

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

$max = -PHP_INT_MAX;
$min = PHP_INT_MAX;

for($i = 0; $i<$n; $i++):
	list($sym, $val, $ans) = explode(" ", trim(fgets(STDIN)));

	if( ($sym == ">" && $ans == "Y"))
	{
		$min = $val + 1;
		continue;
	}

	// split these out since a negative does not prohibit use of val
	if($sym == "<" && $ans == "N")
	{
		$min = $val;
		continue;
	}

	if( ($sym == "<" && $ans == "Y") )
	{
		$max = $val - 1;
		continue;
	}

	// non prohibit fix
	if($sym == ">" && $ans == "N")
	{
		$max = $val;
		continue;
	}

	if( ($sym == "<=" && $ans == "Y") || ($sym == ">=" && $ans == "N") )
	{
		$max = $val;
		continue;
	}

	if( ($sym == ">=" && $ans == "Y") || ($sym == "<=" && $ans == "N") )
	{
		$min = $val;
	}

endfor;

if( $max < $min )
{
	echo "Impossible";
} else {
	echo rand($min, $max);
}

echo PHP_EOL;

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

// UGH
$max = 1361956;
$min = -1361956;

for($i = 0; $i<$n; $i++):
	list($sym, $val, $ans) = explode(" ", trim(fgets(STDIN)));

	if( ($sym == ">" && $ans == "Y"))
	{
		// fix for super imposed rules
		$min = max($min, $val + 1);
		continue;
	}

	// split these out since a negative does not prohibit use of val
	if($sym == "<" && $ans == "N")
	{
		$min = max($min, $val);
		continue;
	}

	if( ($sym == "<" && $ans == "Y") )
	{
		$max = min($max, $val - 1);
		continue;
	}

	// non prohibit fix
	if($sym == ">" && $ans == "N")
	{
		$max = min($max, $val);
		continue;
	}

	if( ($sym == "<=" && $ans == "Y") || ($sym == ">=" && $ans == "N") )
	{
		$max = min($val, $max);
		continue;
	}

	if( ($sym == ">=" && $ans == "Y") || ($sym == "<=" && $ans == "N") )
	{
		$min = max($min, $val);
	}

endfor;

if( $max < $min )
{
	echo "Impossible";
} else {
	echo rand($min, $max);
}

echo PHP_EOL;

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

$max = -PHP_INT_MAX;
$min = PHP_INT_MAX;

for($i = 0; $i<$n; $i++):
	list($sym, $val, $ans) = explode(" ", trim(fgets(STDIN)));

	if( ($sym == ">" && $ans == "Y") || ($sym == "<" && $ans == "N") )
	{
		$min = $val + 1;
		continue;
	}

	if( ($sym == "<" && $ans == "Y") || ($sym == ">" && $ans == "N") )
	{
		$max = $val - 1;
		continue;
	}

	if( ($sym == "<=" && $ans == "Y") || ($sym == ">=" && $ans == "N") )
	{
		$max = $val;
		continue;
	}

	if( ($sym == ">=" && $ans == "Y") || ($sym == "<=" && $ans == "N") )
	{
		$min = $val;
	}

endfor;

if( $max < $min )
{
	echo "Impossible";
} else {
	echo rand($min, $max);
}

echo PHP_EOL;

<?php
fscanf(STDIN, "%d", $n);
$min=-2000000000;
$max=2000000000;
for ($i = 0; $i<$n; $i++){
    fscanf(STDIN, '%s %d %s\n', $cmp, $x, $answer);
    if ($answer=='N'){
        switch($cmp){
            case '=>':
                $cmp='<';
                break;
            case '>':
                $cmp='<=';
                break;
            case '<=':
                $cmp='>';
                break;
            case '<':
                $cmp='>=';
                break;
        }
    }
        switch ($cmp){
            case '>=':
                $min=max($min,$x);
                break;
            case '>':
                $min=max($min,$x+1);
                break;
            case '<=':
                $max=min($max,$x);
                break;
            case '<':
                $max=min($max,$x-1);
                break;
        }
}
if ($max<$min || $max>2000000000 || $min<-2000000000)
    echo "Impossible";
else
    fprintf(STDOUT, "%0.0f",$max);

<?php
fscanf(STDIN, "%d", $n);
$min=-2000000000;
$max=2000000000;
for ($i = 0; $i<$n; $i++){
    fscanf(STDIN, '%s %d %s\n', $cmp, $x, $answer);
    if ($answer=='N'){
        switch($cmp){
            case '=>':
                $cmp='<';
                break;
            case '>':
                $cmp='<=';
                break;
            case '<=':
                $cmp='>';
                break;
            case '<':
                $cmp='>=';
                break;
        }
    }
        switch ($cmp){
            case '=>':
                $min=max($min,$x);
                break;
            case '>':
                $min=max($min,$x+1);
                break;
            case '<=':
                $max=min($max,$x);
                break;
            case '<':
                $max=min($max,$x-1);
                break;
        }
}
if ($max<$min || $max>2000000000 || $min<-2000000000)
    echo "Impossible";
else
    fprintf(STDOUT, "%0.0f",$max);

<?php
fscanf(STDIN, "%d", $n);
$min=-2000000000;
$max=2000000000;
for ($i = 0; $i<$n; $i++){
    fscanf(STDIN, '%s %d %s\n', $cmp, $x, $answer);
    if ($answer=='N'){
        switch($cmp){
            case '>=':
                $cmp='<';
                break;
            case '>':
                $cmp='<=';
                break;
            case '<=':
                $cmp='>';
                break;
            case '<':
                $cmp='>=';
                break;
        }
    }
        switch ($cmp){
            case '=>':
                $min=max($min,$x);
                break;
            case '>':
                $min=max($min,$x+1);
                break;
            case '<=':
                $max=min($max,$x);
                break;
            case '<':
                $max=min($max,$x-1);
                break;
        }
}
if ($max<$min || $max>2000000000 || $min<-2000000000)
    echo "Impossible";
else
    fprintf(STDOUT, "%0.0f",$max);


Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.

The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.

Print a single number — the number of distinct letters in Anton's set.

<?php
$a = trim(fgets(STDIN));
if($a == "{}")
{
    print "0";
}
else
{
    $b = str_split($a);
    unset($b[count($b) - 1]);
    unset($b[0]);
    $c = implode("", $b);
    $d = explode(", ", $c);
    $e = array_unique($d);
    print count($e);
}
?>

<?php

$a =  trim(trim(fgets(STDIN)), '{}');

if($a=="")
echo 0;
else
{
  echo count(array_unique(explode(", ", $a)));
}

?>

<?php
    $arr =  trim(fgets(STDIN));
    $v = array();
        for ($i = 0; $i < strlen($arr); $i++){
            if ($arr[$i] >= 'a' && $arr[$i] <= 'z'){
                $v[$arr[$i]] = 1;
            }

        }
         echo count($v);

<?php
/*
By Tianyi Chen
*/
$s=fgets(STDIN);
if($s[1]==='}')die('0');
$s=str_replace(', ','","',$s);
$s=str_replace('{',"[\"",$s);
$s=str_replace('}',"\"]",$s);
print(count(array_unique(json_decode($s))));

<?php
/*
By Tianyi Chen
*/
$s=fgets(STDIN);
if($s[1]==='}')die('0');
print(count(array_unique(json_decode(str_replace('}',"\"]",str_replace('{',"[\"",str_replace(', ','","',$s)))))));

<?php
/*
 * A. Антон и буквы
 */
$s = trim(fgets(STDIN));

preg_match_all('/[a-z]/',$s,$m);

$m = array_unique($m[0]);

echo sizeof($m) > 0 ? sizeof($m) : '0';

<?php
$arr = str_replace(" ","",substr(substr(trim(fgets(STDIN)),0,-1),1));
$ArrOfBkv = explode(",", $arr );
if ($ArrOfBkv[0]=="")
echo "0"; else
echo count(array_unique($ArrOfBkv));
?>

<?php
$line = explode(",",str_replace(array("{","}"," "),"",trim(fgets(STDIN))));
$line = array_unique($line);
if (count($line)==1)
{
    if ($line[0]=="")echo 0;
    else echo 1;
}
else echo count($line);

<?php

$input = explode(", ", trim(fgets(STDIN),"{}\n\r"));
$result = array_unique($input);
$col = count($result);
if ( $col == 1) {
    if (empty($result[0])) {
        $output = 0;
    } else {
        $output = $col;
    }
} else {
    $output = $col;
}
print_r($output);

<?php
$set=trim(fgets(STDIN));
if ($set=="{}") {
	echo "0";
}
else{
$rmvbrket=trim($set,'{}');
$rmvspace=str_replace(', ','',$rmvbrket);

$count=0;
$alpbet="abcdefghijklmnopqrstuvwxyz";
for($i=0;$i<strlen($alpbet);$i++)
{
	for($j=0;$j<strlen($rmvspace);$j++)
	{
		if($alpbet[$i]==$rmvspace[$j])
		{
			$count++;
			break;
		}

	}
}
echo "$count";
}

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

//$s = trim(fgets($f));
$s = trim(fgets($f));

$s = trim($s,'{');
$s = trim($s,'}');

$s = str_replace(" ","",$s);

if ($s==""){ echo(0);exit;}

$a = explode(',',$s);

$b = array();
foreach($a as $item){
    $b[$item] = 1;
}

echo count($b);

<?php

$stdout = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");

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

$s = str_replace( "{" , "" , $s ) ;
$s = str_replace( "}" , "" , $s ) ;

$arr = [] ;

if( $s != '' )
{
     for( $i=0 ; $i<strlen($s)-1 ; )
     {
          if( ! in_array( $s[$i] , $arr) )
          {
               $arr[] = $s[$i] ;
          }
          $i+= 3 ;
     }
}

echo count( $arr )  ;

fwrite($stdout);

fclose($stdin);
fclose($stdout);

?>

<?

$input = trim(fgets(STDIN));
$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo count(array_count_values($array)); }

?>

<?php
// 443A     Антон и буквы
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$arr = preg_split('/, /', substr($input_line, 1, strlen($input_line)-4), -1, PREG_SPLIT_NO_EMPTY);

$arr = array_unique($arr);

echo count($arr);

?>

<?php

$line = fgets(STDIN);

$used = array();
for ($i = ord('a'); $i <= ord('z'); $i ++) {
	$used[$i] = FALSE;
}

$output = 0;

for ($i = 0; $i < strlen($line); $i ++) {
	if (ctype_alpha($line{$i}) && $used[ord($line{$i})] === FALSE) {
		$used[ord($line{$i})] = TRUE;
		$output ++;
	}
}

print $output;

<?php

$letters = fgets(STDIN);
$letters = trim($letters);
$letters = substr($letters, 1, (strlen($letters) - 2));
$letters = explode(', ', $letters);

	$letters = array_unique($letters);

if($letters[0] == null){
	$letters = array();
}

print_r(count($letters));

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

$a = explode(", ",substr(rtrim(fgets($in)),1,-1));

if($a[0]=="")
    echo 0;
else
    echo count(array_unique($a));

<?php
$s = trim(trim(fgets(STDIN)), '{}');
if (!$s)
    print 0;
else
    print count(array_unique(explode(", ", $s)));
?>

<?php
error_reporting("off");
//443A: Anton and Letters
$n = explode(", ", substr(trim(fgets(STDIN)), 1, -1));
$unique = array_filter(array_unique($n));
echo count($unique);
?>

<?php
$a = trim(fgets(STDIN));
$b = substr($a, 1);
$c = substr($b, 0, -1);
$d = explode(", ", $c);
$e = array_unique($d);
print count($d) - count($e);
?>

<?php
$a = trim(fgets(STDIN));
$b = substr($a, 1);
$c = substr($b, 0, -1);
$d = explode(", ", $c);
$e = array_unique($d);
print count($e);
?>

<?php
$a = trim(fgets(STDIN));
$b = str_split($a);
unset($b[0]);
unset($b[count($b)]);
$c = implode("", $b);
$e = array_unique($d);
if($a == "{}")
{
    print "0";
}
else
{
    print count($e);
}
?>

<?php
/*
By Tianyi Chen
*/
$s=fgets(STDIN);
if($s[1]==='}')die('0');
print(count(array_unique(json_decode(str_replace('}',"\"]",str_replace(', ','","',$s))))));

<?php
/*
By Tianyi Chen
*/
fscanf(STDIN,'%[^\n]',$s);
if($s[1]==='}')die('0');
$s=str_replace('{',"[\"",$s);
$s=str_replace('}',"\"]",$s);
$s=str_replace(', ','","',$s);
print(count(array_unique(json_decode($s))));

<?php
/*
By Tianyi Chen
*/
fscanf(STDIN,'%[^\n]',$s);
if(strlen($s)===2)die('0');
$s=str_replace('{',"[\"",$s);
$s=str_replace('}',"\"]",$s);
$s=str_replace(', ','","',$s);
print(count(array_unique(json_decode($s))));

<?php
$arr = str_replace(" ","",substr(substr(trim(fgets(STDIN)),0,-1),1));
$ArrOfBkv = explode(",", $arr );
echo count(array_unique($ArrOfBkv));
?>

<?php
list ($k,$n) = explode(" ",trim(fgets(STDIN)));
$n=$n-1;
if ($n<$k/2) echo intval($k/($k/2))*$n+1;
else echo 2+2*($n-round($k/2));

<?php
$input = explode(", ", trim(fgets(STDIN), "{}\n"));
$result = array_unique($input);
print(count($result));

<?php
$input = explode(", ", trim(fgets(STDIN), "{}\n\r"));
$result = array_unique($input, SORT_REGULAR);
print(count($result));

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

//$s = trim(fgets($f));
$s = trim(fgets($f));

$s = trim($s,'{');
$s = trim($s,'}');

$s = str_replace(" ","",$s);

if ($s=="") echo(0);exit;

$a = explode(',',$s);

$b = array();
foreach($a as $item){
    $b[$item] = 1;
}

echo count($b);

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

//$s = trim(fgets($f));
$s = trim(fgets($f));

$s = trim($s,'{');
$s = trim($s,'}');

$s = str_replace(" ","",$s);

if ($s=="") exit(0);

$a = explode(',',$s);

$b = array();
foreach($a as $item){
    $b[$item] = 1;
}

echo count($b);

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');
//$a = explode(" ",trim(fgets($f)));

//$s = trim(fgets($f));
$s = trim(fgets($f));

$s = trim($s,'{');
$s = trim($s,'}');

$s = str_replace(" ","",$s);
$a = explode(',',$s);

$b = array();
foreach($a as $item){
    $b[$item] = 1;
}

echo count($b);

<?

$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo intval(count(array_count_values($array))); }

?>

<?

$input = '{a, b, c}';
$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo intval(count(array_count_values($array))); }

?>

<?

$s = fopen("php://stdin", 'r');
$input = stream_get_contents($s);
$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo count(array_count_values($array)); }

?>

<?

$input = 'php://stdin';
$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo count(array_count_values($array)); }

?>

$input = '{a, b, a, b}';
$string = substr($input, 1, strlen($input)-2);
$array = explode(', ', $string);
if($array[0]==''){ echo 0; }else{ echo count(array_count_values($array)); }

<?php
error_reporting("off");
//443A: Anton and Letters
$n = explode(", ", substr(trim(fgets(STDIN)), 1, -1));
$unique = array_unique($n);
echo count($unique);
?>


Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is connected to the terminal next to him. After pressing a Play button a rough voice starts playing from the tape:"Listen up Smith. As you can see, you are in pretty tough situation and in order to escape, you have to solve a puzzle. You are given N strings which represent words. Each word is of the maximum length L and consists of characters 'a'-'e'. You are also given M strings which represent patterns. Pattern is a string of length  ≤  L and consists of characters 'a'-'e' as well as the maximum 3 characters '?'. Character '?' is an unknown character, meaning it can be equal to any character 'a'-'e', or even an empty character. For each pattern find the number of words that matches with the given pattern. After solving it and typing the result in the terminal, the key will drop from the ceiling and you may escape. Let the game begin."Help Smith escape.

The first line of input contains two integers N and M (1 ≤ N ≤  100 000, 1 ≤ M ≤  5000), representing the number of words and patterns respectively. The next N lines represent each word, and after those N lines, following M lines represent each pattern. Each word and each pattern has a maximum length L (1 ≤ L ≤ 50). Each pattern has no more that three characters '?'. All other characters in words and patters are lowercase English letters from 'a' to 'e'.

Output contains M lines and each line consists of one integer, representing the number of words that match the corresponding pattern.

NoteIf we switch '?' with 'b', 'e' and with empty character, we get 'abc', 'aec' and 'ac' respectively.


There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move:   'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$;  'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$;  'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$;  'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' — the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ — endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them.

<?php

namespace io {
	$input_file_content = file_get_contents("php://stdin");
	$input_buf = explode("\r\n", $input_file_content);
	unset($input_file_content);
}

namespace main {
	error_reporting(E_ALL);
	ini_set('display_errors', true);
	ini_set('html_errors', false);

	use function io\next_line as next_line;
	use function io\next_ as next;
	use function io\next_int as next_int;
	use function io\next_double as next_double;

	$tc = next_int();
	for($cc=0; $cc<$tc; $cc++) {
		$n = next_int();
		$s = next();

		$l = -1; $r = -1;
		$mn = 1234567;
		$lr = 0; $ud = 0;
		$a = [($lr . "+" . $ud) => 0];
		for($i=0; $i<$n; $i++) {
			if($s[$i] == "L") $lr--;
			elseif($s[$i] == "R") $lr++;
			elseif($s[$i] == "D") $ud--;
			else $ud++;

			$t = $lr . "+" . $ud;
			if(array_key_exists($t, $a)) {
				if($i + 1 - $a[$t] < $mn) {
					$mn = $i + 1 - $a[$t];
					$l = $a[$t] + 1;
					$r = $i + 1;
				}
			}
			$a[$t] = $i + 1;
		}
		if($l == -1) printf("%d\n", -1);
		else printf("%d %d\n", $l, $r);
	}
}

namespace io {
	function next_line() {
		static $cnt = 0;
		global $input_buf;
		// while($input_buf[$cnt] == "") $cnt++;
		return $input_buf[$cnt++];
		// return trim($input_buf[$cnt++]);
	}
	function next_() {
		static $tk = [];
		static $tk_cnt = 0;
		if($tk_cnt == count($tk)) {
			$tk = explode(" ", next_line());
			$tk_cnt = 0;
		}
		return $tk[$tk_cnt++];
	}
	function next_int() {
		return (int)next_();
	}
	function next_double() {
		return (double)next_();
	}
}

?>

<?php

namespace io {
	$input_file_content = file_get_contents("php://stdin");
	$input_buf = explode("\r\n", $input_file_content);
	unset($input_file_content);
}

namespace main {
	error_reporting(E_ALL);
	ini_set('display_errors', true);
	ini_set('html_errors', false);

	use function io\next_line as next_line;
	use function io\next_ as next;
	use function io\next_int as next_int;
	use function io\next_double as next_double;

	$tc = next_int();
	for($cc=0; $cc<$tc; $cc++) {
		$n = next_int();
		$s = next();

		$l = -1; $r = -1;
		$min_len = 1234567;
		$sum = 0;
		$a = [$sum => 0];
		for($i=0; $i<$n; $i++) {
			if($s[$i] == "L") $sum -= 1;
			elseif($s[$i] == "R") $sum += 1;
			elseif($s[$i] == "D") $sum -= 200001;
			else $sum += 200001;

			if(array_key_exists($sum, $a)) {
				if($i + 1 - $a[$sum] < $min_len) {
					$min_len = $i + 1 - $a[$sum];
					$l = $a[$sum] + 1;
					$r = $i + 1;
				}
			}
			$a[$sum] = $i + 1;
		}
		if($l == -1) printf("%d\n", -1);
		else printf("%d %d\n", $l, $r);
	}
}

namespace io {
	function next_line() {
		static $cnt = 0;
		global $input_buf;
		// while($input_buf[$cnt] == "") $cnt++;
		return $input_buf[$cnt++];
		// return trim($input_buf[$cnt++]);
	}
	function next_() {
		static $tk = [];
		static $tk_cnt = 0;
		if($tk_cnt == count($tk)) {
			$tk = explode(" ", next_line());
			$tk_cnt = 0;
		}
		return $tk[$tk_cnt++];
	}
	function next_int() {
		return (int)next_();
	}
	function next_double() {
		return (double)next_();
	}
}

?>


Vasya is a born Berland film director, he is currently working on a new blockbuster, "The Unexpected". Vasya knows from his own experience how important it is to choose the main characters' names and surnames wisely. He made up a list of n names and n surnames that he wants to use. Vasya haven't decided yet how to call characters, so he is free to match any name to any surname. Now he has to make the list of all the main characters in the following format: "Name1 Surname1, Name2 Surname2, ..., Namen Surnamen", i.e. all the name-surname pairs should be separated by exactly one comma and exactly one space, and the name should be separated from the surname by exactly one space. First of all Vasya wants to maximize the number of the pairs, in which the name and the surname start from one letter. If there are several such variants, Vasya wants to get the lexicographically minimal one. Help him.An answer will be verified a line in the format as is shown above, including the needed commas and spaces. It's the lexicographical minimality of such a line that needs to be ensured. The output line shouldn't end with a space or with a comma.

The first input line contains number n (1 ≤ n ≤ 100) — the number of names and surnames. Then follow n lines — the list of names. Then follow n lines — the list of surnames. No two from those 2n strings match. Every name and surname is a non-empty string consisting of no more than 10 Latin letters. It is guaranteed that the first letter is uppercase and the rest are lowercase.

The output data consist of a single line — the needed list. Note that one should follow closely the output data format!

4
Ann
Anna
Sabrina
John
Petrov
Ivanova
Stoltz
Abacaba

Ann Abacaba, Anna Ivanova, John Petrov, Sabrina Stoltz


Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches. The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.

Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.

NoteIn the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	readNum($f);
	$path = trim(readString($f));
	$n = strlen($path);

	$b = $r = array(0,0);
	for ($i = 0; $i < $n; $i++) {
		if ($path[$i] == 'r') {
			$r[$i % 2] ++;
		} else {
			$b[$i % 2] ++;
		}
	}
	echo min(max($r[0], $b[1]), max($r[1], $b[0]));
	/* / end body */
}

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

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	$n = readNum($f);
	$path = trim(readString($f));

	$actionCount = 0;
	for ($i = 1; $i < $n; $i++) {
		if ($path[$i] != $path[$i - 1]) {
			continue;
		}
		$doublePos = false;
		for ($j = $i + 2; $j < $n; $j++) {
			if ($path[$i] != $path[$j] && $path[$j] == $path[$j - 1]) {
				$doublePos = $j - 1;
				break;
			}
		}
		if ($doublePos !== false) {
			$t = $path[$i];
			$path[$i] = $path[$doublePos];
			$path[$doublePos] = $t;
			$actionCount++;
		} else {
			$actionCount++;
			if ($path[$i] == 'r') {
				$path[$i] = 'b';
			} else {
				$path[$i] = 'r';
			}
		}
	}
	echo $actionCount;
	/* / end body */
}

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

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	readNum($f);
	$path = trim(readString($f));
	$n = strlen($path);

	$actionCount = 0;
	for ($i = 1; $i < $n; $i++) {
		if ($path[$i] != $path[$i - 1]) {
			continue;
		}
		$doublePos = false;
		for ($j = $i + 2; $j < $n; $j++) {
			if ($path[$i] != $path[$j] && $path[$j] == $path[$j - 1]) {
				$doublePos = $j - 1;
				break;
			}
			if ($path[$i] != $path[$j] && $j + 1 == $n) {
				$doublePos = $j;
				break;
			}
		}
		if ($doublePos !== false) {
			$t = $path[$i];
			$path[$i] = $path[$doublePos];
			$path[$doublePos] = $t;
			$actionCount++;
		} else {
			$actionCount++;
			if ($path[$i] == 'r') {
				$path[$i] = 'b';
			} else {
				$path[$i] = 'r';
			}
		}
	}

	echo $actionCount;
	/* / end body */
}

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

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	readNum($f);
	$path = trim(readString($f));
	$n = strlen($path);

	$actionCount = 0;
	for ($i = 1; $i < $n; $i++) {
		if ($path[$i] != $path[$i - 1]) {
			continue;
		}
		$doublePos = false;
		for ($j = $i + 2; $j < $n; $j++) {
			if ($path[$i] != $path[$j] && $path[$j] == $path[$j - 1]) {
				$doublePos = $j - 1;
				break;
			}
		}
		if ($i + 2 == $n && $path[$i] != $path[$i + 1]) {
			$doublePos = $i + 1;
		}
		if ($doublePos !== false) {
			$t = $path[$i];
			$path[$i] = $path[$doublePos];
			$path[$doublePos] = $t;
			$actionCount++;
		} else {
			$actionCount++;
			if ($path[$i] == 'r') {
				$path[$i] = 'b';
			} else {
				$path[$i] = 'r';
			}
		}
	}

	echo $actionCount;
	/* / end body */
}

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


Given a positive integer $$$k$$$, two arrays are called $$$k$$$-similar if:  they are strictly increasing;  they have the same length;  all their elements are positive integers between $$$1$$$ and $$$k$$$ (inclusive);  they differ in exactly one position. You are given an integer $$$k$$$, a strictly increasing array $$$a$$$ and $$$q$$$ queries. For each query, you are given two integers $$$l_i \leq r_i$$$. Your task is to find how many arrays $$$b$$$ exist, such that $$$b$$$ is $$$k$$$-similar to array $$$[a_{l_i},a_{l_i+1}\ldots,a_{r_i}]$$$.

The first line contains three integers $$$n$$$, $$$q$$$ and $$$k$$$ ($$$1\leq n, q \leq 10^5$$$, $$$n\leq k \leq 10^9$$$) — the length of array $$$a$$$, the number of queries and number $$$k$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots,a_n$$$ ($$$1 \leq a_i \leq k$$$). This array is strictly increasing  — $$$a_1 < a_2 < \ldots < a_n$$$. Each of the following $$$q$$$ lines contains two integers $$$l_i$$$, $$$r_i$$$ ($$$1 \leq l_i \leq r_i \leq n$$$).

Print $$$q$$$ lines. The $$$i$$$-th of them should contain the answer to the $$$i$$$-th query.

NoteIn the first example:In the first query there are $$$4$$$ arrays that are $$$5$$$-similar to $$$[2,4]$$$: $$$[1,4],[3,4],[2,3],[2,5]$$$.In the second query there are $$$3$$$ arrays that are $$$5$$$-similar to $$$[4,5]$$$: $$$[1,5],[2,5],[3,5]$$$.


Phoenix is playing with a new puzzle, which consists of $$$n$$$ identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below.    A puzzle piece The goal of the puzzle is to create a square using the $$$n$$$ pieces. He is allowed to rotate and move the pieces around, but none of them can overlap and all $$$n$$$ pieces must be used (of course, the square shouldn't contain any holes as well). Can he do it?

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the number of puzzle pieces.

For each test case, if Phoenix can create a square with the $$$n$$$ puzzle pieces, print YES. Otherwise, print NO.

NoteFor $$$n=2$$$, Phoenix can create a square like this:    For $$$n=4$$$, Phoenix can create a square like this:    For $$$n=6$$$, it is impossible for Phoenix to create a square.

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

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

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

  if ($n % 2 != 0) { echo 'NO'.PHP_EOL; }
  else {
    $m1 = $n / 2;
    $ans1 = sqrt($m1);
    $v1 = round($ans1);

    $m2 = $n / 4;
    $ans2 = sqrt($m2);
    $v2 = round($ans2);
    if ($ans1 == $v1 || $ans2 == $v2) { $r = 1; }

    if ($r == 1) { echo 'YES'.PHP_EOL; }
    else { echo 'NO'.PHP_EOL; }
  }

}

?>

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

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

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $r = 0;
  if ($n % 2 != 0) { echo 'NO'.PHP_EOL; }
  else {
    $m1 = $n / 2;
    $m2 = $n / 4;
    $ans1 = sqrt($m1);
    $v1 = round($ans1);

    $ans2 = sqrt($m2);
    $v2 = round($ans2);
    if ($ans1 == $v1 || $ans2 == $v2) { $r = 1; }
  }

  if ($r == 1) { echo 'YES'.PHP_EOL; }
  else { echo 'NO'.PHP_EOL; }
}

?>


You are given a table consisting of n rows and m columns.Numbers in each row form a permutation of integers from 1 to m.You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order.You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table.  Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m.

If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).

NoteIn the first sample, one can act in the following way:   Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2  In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4


Walking along a riverside, Mino silently takes a note of something."Time," Mino thinks aloud."What?""Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this.""And what are you recording?""You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.Doubtfully, Kanno peeks at Mino's records. The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$p$$$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.In this problem, a positive integer $$$p$$$ is considered a period of string $$$s$$$, if for all $$$1 \leq i \leq \lvert s \rvert - p$$$, the $$$i$$$-th and $$$(i + p)$$$-th characters of $$$s$$$ are the same. Here $$$\lvert s \rvert$$$ is the length of $$$s$$$.

The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and contains at least one '.' character.

Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).

NoteIn the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different.In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different.In the third example, $$$9$$$ is always a period because the only constraint that the first and last characters are the same is already satisfied.Note that there are multiple acceptable answers for the first two examples, you can print any of them.

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] === '.'
            || $notes[$i+$p] === '.'
            || $notes[$i] !== $notes[$i+$p];
        $notes[$i+$p] = (int)($notes[$i+$p] === '.'
            ? ($notes[$i] === '.' ? mt_rand(0,1) : !(bool)(int)$notes[$i])
            : $notes[$i+$p]);
        $notes[$i] = (int)($notes[$i] === '.'
            ? !(bool)(int)($notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] === '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] == '.'
            || $notes[$i+$p] == '.'
            || $notes[$i] != $notes[$i+$p];
        $notes[$i+$p] = (int)($notes[$i+$p] == '.'
            ? !(bool)($notes[$i] == '.' ? mt_rand(0,1) : (int)$notes[$i])
            : $notes[$i+$p]);
        $notes[$i] = (int)($notes[$i] == '.'
            ? !(bool)(int)($notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result || $notes[$i] == '.' || $notes[$i+$p] == '.' || $notes[$i] != $notes[$i+$p];
        $notes[$i] = (int)($notes[$i] == '.'
            ? !(bool)(int)($notes[$i+$p] = $notes[$i+$p] == '.' ? mt_rand(0,1) : $notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] == '.'
            || $notes[$i+$p] == '.'
            || $notes[$i] != $notes[$i+$p];
        $notes[$i+$p] = $notes[$i+$p] == '.'
            ? ($notes[$i] == '.' ? mt_rand(0,1) : !(bool)(int)$notes[$i])
            : $notes[$i+$p];
        $notes[$i] = (int)($notes[$i] == '.'
            ? !(bool)(int)($notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;

for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] == '.'
            || $notes[$i+$p] == '.'
            || $notes[$i] != $notes[$i+$p];

        if ($notes[$i+$p] == '.') {
            $notes[$i+$p] = (int)($notes[$i] == '.' ? 1 : !(bool)(int)$notes[$i]);
        }

        if ($notes[$i] == '.') {
            $notes[$i] = (int)!(bool)(int)($notes[$i+$p]);
        }

    } else {
        $notes[$i] = $notes[$i] == '.' ? 1 : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;

for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] == '.'
            || $notes[$i+$p] == '.'
            || $notes[$i] != $notes[$i+$p];

        if ($notes[$i+$p] == '.') {
            $notes[$i+$p] = (int)($notes[$i] == '.' ? mt_rand(0,1) : !(bool)(int)$notes[$i]);
        }

        if ($notes[$i] == '.') {
            $notes[$i] = (int)!(bool)(int)($notes[$i+$p]);
        }

    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $notes[$i] == '.' || $notes[$i+$p] == '.' || $notes[$i] != $notes[$i+$p];
        $notes[$i] = (int)($notes[$i] == '.'
            ? !(bool)(int)($notes[$i+$p] = $notes[$i+$p] == '.' ? mt_rand(0,1) : $notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";

<?php

list($n, $p) = explode(' ', fgets(STDIN));
$notes = str_split(substr(fgets(STDIN), 0, $n));

$n = (int)$n;
$p = (int)$p;

$result = false;
for ($i = 0; $i < $n; $i++) {
    if ($i + $p < $n) {
        $result = $result
            || $notes[$i] == '.'
            || $notes[$i+$p] == '.'
            || $notes[$i] != $notes[$i+$p];
        $notes[$i+$p] = (int)($notes[$i+$p] == '.'
            ? (int)($notes[$i] == '.' ? mt_rand(0,1) : !(bool)(int)$notes[$i])
            : $notes[$i+$p]);
        $notes[$i] = (int)($notes[$i] == '.'
            ? !(bool)(int)($notes[$i+$p])
            : $notes[$i]);
    } else {
        $notes[$i] = $notes[$i] == '.' ? mt_rand(0,1) : $notes[$i];
    }
}

echo $result ? implode('', $notes) : "No";