A flower shop has got n bouquets, and the i-th bouquet consists of ai flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouquet should be odd. Each of the initial bouquets can be a part of at most one large bouquet. If an initial bouquet becomes a part of a large bouquet, all its flowers are included in the large bouquet.Determine the maximum possible number of large bouquets Vasya can make.

The first line contains a single positive integer n (1 ≤ n ≤ 105) — the number of initial bouquets. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the number of flowers in each of the initial bouquets.

Print the maximum number of large bouquets Vasya can make.

NoteIn the first example Vasya can make 2 large bouquets. For example, the first bouquet can contain the first and the fifth initial bouquets (the total number of flowers is then equal to 9), and the second bouquet can consist of the second and the third initial bouquets (the total number of flowers is then equal to 7). The fourth initial bouquet is unused in this scheme. In the second example it is not possible to form a single bouquet with odd number of flowers.In the third example Vasya can make one large bouquet. For example, he can make it using all three initial bouquets. The size of the large bouquet is then equal to 11 + 4 + 10 = 25.

<?php
  $input = (int)trim(fgets(STDIN));
  $hola = explode(' ',trim(fgets(STDIN)));
  $even=0;
  $odd=0;
  for($x=0; $x<$input; $x++)
  {
    if($hola[$x]%2==0)
      $even++;
    else {
      $odd++;
    }
  }
  if($even>=$odd)
    echo $odd;
  else {
    echo $even + ($odd-$even-($odd-$even)%3)/3;
  }
 ?>

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

	$even = 0;
	$odd = 0;

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

	foreach ($a as &$num) {
		$num = intval($num);
		if ($num % 2 == 0) {
	    		$even++;
	  	} else {
			$odd++;
	  	}
	}

	if ($odd == 0) {
		echo "0";
	} else {
		$best = 0;

		for($i = 0 ; $i <= $even ; $i++){
			$best = max(min($i, $odd) + max(floor(($odd - $i) / 3), 0), $best);
		}

		echo $best;
	}

?>

<?php

fscanf(STDIN, "%d", $n);
$odd = 0;
$even = 0;

$line = trim(fgets(STDIN));
$array = array();
$array = array_merge($array, explode(" ", $line));

for($i = 0; $i < $n; $i ++) {
    $t = $array[$i];
    if(($t & 1) > 0) $odd ++;
    else $even ++;
}
$mt = min($odd, $even);
$ans = $mt;
$odd -= $mt;
$ans = $ans + intval(($odd / 3));
print $ans;
/*
if($even >= $odd) {
    print $odd;
}
else {
    print $even + intval(($odd - $even) / 3);
}
*/

?>

<?php
	fscanf(STDIN, '%d\n', $n);
	$e = 0;
	$o = 0;
	$a = explode(' ', trim(fgets(STDIN)));
	foreach ($a as &$x) {
		$x = intval($x);
		if($x&1)
	    	$o++;
	  	else
			$e++;
	}
	if($o <= $e){
	    echo $o;
	}
	else {
	    echo $e + (floor(($o-$e)/3));
	}
?>

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

    $n =  fgets($dir);
    $arr = explode(' ', fgets($dir));

    $odds = 0; $even = 0; $ans = 0;

    for ($i = 0; $i < $n; $i++) {
        $x = $arr[$i];
        if($x % 2)  $odds++;
        else        $even++;
    }

    $ans = min($odds, $even);
    $odds -= min($odds, $even);
    $ans += floor($odds / 3);

    echo $ans;
?>

<?php

class Scanner {
  private $arr = [];
  private $count = 0;
  private $pointer = 0;
  public function next() {
    if($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}

class out {
  public static function println($str = "") {
    echo $str . PHP_EOL;
  }
}

$sc = new Scanner();
$n = $sc->nextInt();

$cnt = [0, 0];
for($i = 0; $i < $n; $i++) {
  $x = $sc->nextInt();
  $cnt[$x % 2]++;
}

if($cnt[0] >= $cnt[1]) {
  out::println($cnt[1]);
} else {
  out::println($cnt[0] + (int) (($cnt[1] - $cnt[0]) / 3));
}

<?php
$fl = STDIN;
fscanf($fl,"%d",$n);
$a=explode(" ",fgets(STDIN));
$temp=0;
for($i=0;$i<$n;++$i)
    if($a[$i]%2==1)$temp++;
$ans=$temp;
if($temp>($n-$temp))$ans=$n-$temp;
$temp=$temp-$ans;
$ans+=intval($temp/3);
echo $ans;
?>

<?

$input = explode(" ", trim(fgets(STDIN)));
$n = $input[0];

$c = 0;
$nc = 0;
$input = explode(" ", trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    $a = (int)$input[$i];
    if ($a & 1)
		$nc = $nc + 1;
	else
		$c = $c + 1;
}
$ans = 0;
$t = min($c, $nc);
$ans += $t;
$nc -= $t;
$ans += intdiv($nc, 3);
echo $ans;

<?php

$fl =STDIN;
fgets($fl);
$a = 0;
$b = 0;
$numbers = explode(" ", trim(fgets($fl)));
foreach ($numbers as &$number)
{
$number = intval($number);
//printf("%d\n", $number);
if ($number % 2 == 1)
$a = $a + 1;
else
$b = $b + 1;
}
//printf("%d %d", $a, $b);
if ($a >= $b) {
printf("%d", $b + ($a - $b) / 3);
} else {
printf("%d", $a);
}
?>

<?

    function printa($s){
        $stdout = fopen('php://stdout', 'w');

        fwrite($stdout, $s);

        fclose($stdout);
    }

    $stdin = fopen('php://stdin', 'r');
    $n = fgets($stdin) + 0;
    $a = explode(" ", fgets($stdin));

    $ch = 0;
    $nch = 0;

    for($i = 0; $i < count($a); $i++){
        if(($a[$i] + 0) % 2 == 0){
            $ch++;
        }else{
            $nch++;
        }
    }

    if($ch == $nch){
        printa($ch);
    }else if($ch > $nch){
        printa($nch);
    }else{
        $nch -= $ch;
        printa($ch + floor($nch / 3));
    }
?>

<?php
fscanf(STDIN,"%d", $iN);
$sNum = fgets(STDIN);

preg_match_all('!\d+!', $sNum, $aMatches);
$iCutOff = $aMatches[0][$iCutOffIndex - 1];
$a = 0;
$b = 0;
$c = 0;
$ans = 0;
foreach($aMatches[0] as $iNum)
{
	if($iNum %2 == 1)
		$a++;
	else
	    $b++;
}
$c = $a;
if( $c > $b )
    $c = $b;
$ans = $c + ($a-$c)/3;

fprintf(STDOUT, "%d", $ans);

<?php
$num=0;
$_fp = fopen("file.txt", "r");
$fr=fopen("php://stdin","r");
fscanf($fr, "%d\n",$num);
$input = explode(' ', trim(fgets($fr)));
$ans=0;
foreach ($input as $item){
   if ($item%2==1)
   $ans++;
}
$odd=$ans;
$even=count($input)-$odd;
if ($odd>$even)
   $answer=$even+intdiv($odd-$even,3);
   else
      $answer=$odd;
print($answer);
?>

<?php

$n =  trim(fgets(STDIN));
$uneven = 0;

foreach(explode(' ', trim(fgets(STDIN))) as $ch) {
	if ($ch%2==1) { $uneven+=1;}
}

$even = $n - $uneven;
$c = min($uneven, $even);

$uneven-= $c;

print($c+intdiv($uneven, 3));
?>

<?php

$fl = STDIN;
fscanf($fl,"%d",$n);
$e = 0;
$ne = 0;

$input = trim(fgets(STDIN));
$arr = explode(" ", $input);
foreach($arr as &$a){
    $a = (int)$a;
    if ($a % 2 == 0){
      $e++;
    }
    else {
      $ne++;
    }
}

if ($ne <= $e) {
  echo $ne . "\n";
} else {
  $g = $ne - $e;
  echo ($e + intdiv($g, 3)) . "\n";
}

?>

<?php
  $input = (int)trim(fgets(STDIN));
  $hola = explode(' ',trim(fgets(STDIN)));
  $even=0;
  $odd=0;
  for($x=0; $x<$input; $x++)
  {
    if($hola[$x]%2==0)
      $even++;
    else {
      $odd++;
    }
  }
  if($even>=$odd)
    echo $odd;
  else {
    echo $even + ($odd-$even)/3;
  }
 ?>

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

	$even = 0;
	$odd = 0;

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

	foreach ($a as &$num) {
		$num = intval($num);
		if ($num % 2 == 0) {
	    		$even++;
	  	} else {
			$odd++;
	  	}
	}

	if ($odd == 0) {
		echo "0";
	} else {
		echo max(min($even, $odd), floor($odd / 3) + min($odd % 3, $even));
	}

?>

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

$even = 0;
$odd = 0;

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

foreach ($a as &$num) {
  $num = intval($num);
  if ($num % 2 == 0) {
    $even++;
  } else {
    $odd++;
  }
}

if ($even == 0 || $odd == 0) {
  echo "0";
} else {
  echo min($even, $odd);
}

?>

<?php

fscanf(STDIN, "%d", $n);
$odd = 0;
$even = 0;

$array = array();
while($in = fread(STDIN, 1024)) {
    $array = array_merge($array, explode(" ", $in));
}

for($i = 0; $i < $n; $i ++) {
    $t = $array[$i];
    if(($t & 1) > 0) $odd ++;
    else $even ++;
}
$mt = min($odd, $even);
$ans = $mt;
$odd -= $mt;
$ans = $ans + intval(($odd / 3));
print $ans;
/*
if($even >= $odd) {
    print $odd;
}
else {
    print $even + intval(($odd - $even) / 3);
}
*/

?>

<?php

fscanf(STDIN, "%d", $n);
$odd = 0;
$even = 0;

$array = array();
while($in = fread(STDIN, 1024)) {
    $array = array_merge($array, explode(" ", $in));
}

for($i = 0; $i < $n; $i ++) {
    $t = $array[$i];
    if($t & 1) $odd ++;
    else $even ++;
}

$mt = min($odd, $even);
$ans = $mt;
$odd -= $mt;
$ans = $ans + ($odd / 3);
print $ans;

?>

<?php

fscanf(STDIN, "%d", $n);
$odd = 0;
$even = 0;

$array = array();
while($in = fread(STDIN, 10240000)) {
    $array = array_merge($array, explode(" ", $in));
}

for($i = 0; $i < $n; $i ++) {
    $t = $array[$i];
    if(($t & 1) > 0) $odd ++;
    else $even ++;
}

$mt = min($odd, $even);
$ans = $mt;
$odd -= $mt;
$ans = $ans + ($odd / 3);
print $ans;

?>

<?php

fscanf(STDIN, "%d", $n);
$odd = 0;
$even = 0;

$array = array();
while($in = fread(STDIN, 1024)) {
    $array = array_merge($array, explode(" ", $in));
}

for($i = 0; $i < $n; $i ++) {
    $t = $array[$i];
    if(($t & 1) > 0) $odd ++;
    else $even ++;
}

$mt = min($odd, $even);
$ans = $mt;
$odd -= $mt;
$ans = $ans + intval(($odd / 3));
print $ans;

?>

<?php

fscanf(STDIN, "%d", $n);
$odd = 0;
$even = 0;

$array = array();
while ($in = fread(STDIN, 1024)) {
    $array = array_merge($array, explode(" ", $in));
}

for($i = 0; $i < count($array); $i ++) {
    $t = $array[$i];
    if($t & 1) $odd ++;
    else $even ++;
}

$mt =  min($odd, $even);
$ans = $mt;
$odd -= $mt;
$ans = $ans + ($odd / 3);
print $ans;

?>

<?php

fscanf(STDIN, "%d", $n);
$odd = 0;
$even = 0;

$array = array();
while($in = fread(STDIN, 10240000)) {
    $array = array_merge($array, explode(" ", $in));
}

for($i = 0; $i < $n; $i ++) {
    $t = $array[$i];
    if($t & 1) $odd ++;
    else $even ++;
}

$mt = min($odd, $even);
$ans = $mt;
$odd -= $mt;
$ans = $ans + ($odd / 3);
print $ans;

?>

<?php

fscanf(STDIN, "%d", $n);
$odd = 0;
$even = 0;

$array = array();
while($in = fread(STDIN, 10240000)) {
    $array = array_merge($array, explode(" ", $in));
}

for($i = 0; $i < $n; $i ++) {
    $t = $array[$i];
    if(($t & 1) > 0) $odd ++;
    else $even ++;
}

$mt = min($odd, $even);
$ans = $mt;
$odd -= $mt;
$ans = $ans + (int)($odd / 3);
print $ans;

?>

<?php

fscanf(STDIN, "%d", $n);
$odd = 0;
$even = 0;

$array = array();
while($in = fread(STDIN, 1024 * 1000 * 100)) {
    $array = array_merge($array, explode(" ", $in));
}

for($i = 0; $i < $n; $i ++) {
    $t = $array[$i];
    if(($t & 1) > 0) $odd ++;
    else $even ++;
}

$mt = min($odd, $even);
$ans = $mt;
$odd -= $mt;
$ans = $ans + (int)($odd / 3);
print $ans;

?>

<?php

fscanf(STDIN, "%d", $n);
$odd = 0;
$even = 0;

$array = array();
while($in = fread(STDIN, 1024)) {
    $array = array_merge($array, explode(" ", $in));
}

for($i = 0; $i < $n; $i ++) {
    $t = $array[$i];
    if(($t & 1) > 0) $odd ++;
    else $even ++;
}
/*
$mt = min($odd, $even);
$ans = $mt;
$odd -= $mt;
$ans = $ans + intval(($odd / 3));
print $ans;
*/
if($even >= $odd) {
    print $odd;
}
else {
    print $even + intval(($odd - $even) / 3);
}

?>

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

    $n =  fgets($dir);
    $arr = explode(' ', fgets($dir));

    $ones = 0; $odds = 0; $even = 0;

    for ($i = 0; $i < $n; $i++) {
        $x = $arr[$i];
        if ($x == 1)    $ones++;
        else if($x % 2) $odds++;
        else            $even++;
    }

    $odds += min($ones, $even);
    $ones -= min($ones, $even);
    $odds += floor($ones / 3);

    echo $odds;
?>

<?
    $dir = fopen("php://stdin", 'r');
    $n =  fgets($dir);
    $arr = explode(' ', fgets($dir));

    $ones = 0; $odds = 0; $even = 0;

    for ($i = 0; $i < $n; $i++) {
        $x = $arr[$i];
        if ($x == 1)    $ones++;
        else if($x % 2) $odds++;
        else            $even++;
    }

    $odds += min($ones, $even);

    echo $odds;
?>

<?php

class Scanner {
  private $arr = [];
  private $count = 0;
  private $pointer = 0;
  public function next() {
    if($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}

class out {
  public static function println($str = "") {
    echo $str . PHP_EOL;
  }
}

$sc = new Scanner();
$n = $sc->nextInt();
$cnt = [0, 0];
for($i = 0; $i < $n; $i++) {
  $x = $sc->nextInt();
  $cnt[$x % 2]++;
}
out::println($cnt[0] < $cnt[1] ? $cnt[0] : $cnt[1]);

<?php

class Scanner {
  private $arr = [];
  private $count = 0;
  private $pointer = 0;
  public function next() {
    if($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}

class out {
  public static function println($str = "") {
    echo $str . PHP_EOL;
  }
}

$sc = new Scanner();
$n = $sc->nextInt();

$cnt = [0, 0];
for($i = 0; $i < $n; $i++) {
  $x = $sc->nextInt();
  $cnt[$x % 2]++;
}

if($cnt[0] >= $cnt[1]) {
  out::println($cnt[1]);
} else {
  out::println($cnt[0] + ($cnt[1] - $cnt[0]) / 3);
}

<?php
$fl = STDIN;
fscanf($fl,"%d",$n);
$a=explode(" ",fgets(STDIN));
$temp=0;
for($i=0;$i<$n;++$i)
    if($a[$i]%2==1)$temp++;
echo $temp;
?>

<?php
$fl = STDIN;
fscanf($fl,"%d",$n);
$a=explode(" ",fgets(STDIN));
$temp=0;
for($i=0;$i<$n;++$i)
    if($a[$i]%2==1)$temp++;
if($temp>($n-$temp))$temp=$n-$temp;
echo $temp;
?>

<?php
$fl = STDIN;
fscanf($fl,"%d",$n);
$a=explode(" ",fgets(STDIN));
$temp=0;
for($i=0;$i<$n;++$i)
    if($a[$i]%2==1)$temp++;
$ans=$temp;
if($temp>($n-$temp))$ans=$n-$temp;
$temp=$temp-$ans;
$ans+=$temp/3;
echo $ans;
?>

<?

$input = explode(" ", trim(fgets(STDIN)));
$n = $input[0];

$c = 0;
$nc = 0;
$input = explode(" ", trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    $a = (int)$input[$i];
    if ($a & 1)
		$nc = $nc + 1;
	else
		$c = $c + 1;
}
$ans = 0;
$t = min($c, $nc);
$ans = $ans + $t;
$nc -= $t;
$ans += $nc/3;
echo $ans;

<?

$input = explode(" ", trim(fgets(STDIN)));
$n = $input[0];

$c = 0;
$nc = 0;
$input = explode(" ", trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    $a = (int)$input[$i];
    if ($a & 1)
		$nc = $nc + 1;
	else
		$c = $c + 1;
}
if($c > $nc)
    echo $nc;
else
     echo $c;

<?

    function printa($s){
        $stdout = fopen('php://stdout', 'w');

        fwrite($stdout, $s);

        fclose($stdout);
    }

    $stdin = fopen('php://stdin', 'r');
    $n = fgets($stdin) + 0;
    $a = explode(" ", fgets($stdin));

    $ch = 0;
    $nch = 0;

    for($i = 0; $i < count($a); $i++){
        if(($a[$i] + 0) % 2 == 0){
            $ch++;
        }else{
            $nch++;
        }
    }

    if($ch == $nch){
        printa($ch);
    }else if($ch > $nch){
        printa($nch);
    }else{
        $nch -= $ch;
        printa($ch + $nch);
    }
?>

<?php
fscanf(STDIN,"%d", $iN);
$sNum = fgets(STDIN);

preg_match_all('!\d+!', $sNum, $aMatches);
$iCutOff = $aMatches[0][$iCutOffIndex - 1];
$a = 0;
$b = 0;
$c = 0;
$ans = 0;
foreach($aMatches[0] as $iNum)
{
	if($iNum %2 == 1)
		$a++;
	else
	    $b++;
}
$c = $a;
if( $c < $b )
    $c = $b;
$ans = $c + ($a-$c)/3;

fprintf(STDOUT, "%d", $ans);

<?php
fscanf(STDIN,"%d", $iN);
$sNum = fgets(STDIN);

preg_match_all('!\d+!', $sNum, $aMatches);
$iCutOff = $aMatches[0][$iCutOffIndex - 1];
$iCount = 0;
foreach($aMatches[0] as $iNum)
{
	if($iNum %2 == 1)
		$iCount++;
}

fprintf(STDOUT, "%d", $iCount);

<?php
$num=0;
$_fp = fopen("file.txt", "r");
$fr=fopen("php://stdin","r");
fscanf($fr, "%d\n",$num);
$input = explode(' ', trim(fgets($fr)));
$ans=0;
foreach ($input as $item){
   if ($item%2==1)
   $ans++;
}
print($ans);
?>

<?php

$fl = STDIN;
fscanf($fl,"%d",$n);
$e = 0;
$ne = 0;

$input = trim(fgets(STDIN));
$arr = explode(" ", $input);
foreach($arr as &$a){
    $a = (int)$a;
    if ($a % 2 == 0){
      $e++;
    }
    else {
      $ne++;
    }
}

if ($ne <= $e) {
  echo $ne . "\n";
} else {
  $g = $ne - $e;
  echo ($e + $g / 3) . "\n";
}

?>


In one school with Vasya there is a student Kostya. Kostya does not like physics, he likes different online games. Every day, having come home, Kostya throws his bag in the farthest corner and sits down at his beloved computer. Kostya even eats glued to the game. A few days ago Kostya bought a new RPG game "HaresButtle", which differs from all other games in this genre. It has a huge number of artifacts. As we know, artifacts are divided into basic and composite ones. Only the basic artifacts are available on sale. More powerful composite artifacts are collected from some number of basic artifacts.After the composing composite artifact, all the components disappear.Kostya is the head of the alliance, so he has to remember, what artifacts has not only himself, but also his allies. You must identify by sequence of artifacts purchased by Kostya and his allies, how many and which artifacts has been collected by each of them. It is believed that initially no one has any artifacts.

The first line has 4 natural numbers: k (1 ≤ k ≤ 100) — the number of Kostya's allies, n (1 ≤ n ≤ 50) — the number of basic artifacts, m (0 ≤ m ≤ 50) — the number of composite artifacts, q (1 ≤ q ≤ 500) — the number of his friends' purchases. The following n lines contain the names of basic artifacts. After them m lines contain the descriptions of composite artifacts in the following format: <Art. Name>: <Art. №1> <Art. №1 Number>, <Art. №2> <Art. №2 Number>, ... <Art. №X> <Art. №Х Number> All the numbers are natural numbers not exceeding 100 (1 ≤ X ≤ n). The names of all artifacts are different, they are composed of lowercase Latin letters, and the length of each name is from 1 to 100 characters inclusive. All the words in the format of the description of a composite artifact are separated by exactly one space. It is guaranteed that all components of the new artifact are different and have already been met in the input data as the names of basic artifacts.  Next, each of the following q lines is characterized by the number ai, the number of a friend who has bought the artifact (1 ≤ ai ≤ k), and the name of the purchased basic artifact. Let's assume that the backpacks of the heroes are infinitely large and any artifact bought later can fit in there. It is guaranteed that after the i-th purchase no more than one opportunity to collect the composite artifact appears. If such an opportunity arose, the hero must take advantage of it.

The output file should consist of k blocks. The first line should contain number bi — the number of different artifacts the i-th ally has. Then the block should contain bi lines with the names of these artifacts and the number of these artifacts. At that the lines should be printed in accordance with the lexicographical order of the names of the artifacts. In each block all the artifacts must be different, and all the numbers except the bi should be positive.

2 3 2 5
desolator
refresher
perseverance
vanguard: desolator 1, refresher 1
maelstorm: perseverance 2
1 desolator
2 perseverance
1 refresher
2 desolator
2 perseverance


You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).

The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.

Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.

NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".

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

$ab_left = strpos($line, "AB");
$ab_right = strrpos($line, "AB");
$ba_left = strpos($line, "BA");
$ba_right = strrpos($line, "BA");

if ($ab_left === false || $ba_left === false) {
  echo 'NO';
  exit(0);
}

if (abs($ab_left - $ba_left) > 1 || abs($ab_left - $ba_right) > 1 || abs($ab_right - $ba_left) > 1 || abs($ab_right - $ba_right) > 1) {
  echo 'YES';
  exit(0);
}

echo 'NO';

<?php
$input = fgets(STDIN);

if (empty($input))
{
    echo 'NO';
    exit;
}
else if (strlen($input) < 4)
{
    echo 'NO';
    exit;
}
else
{
    $chars = str_split($input);

    if (search($chars, 'A', 'B') || search($chars, 'B', 'A'))
    {
        echo 'YES';
        exit;
    }

    echo 'NO';
}

function search($chars, $fir, $sec)
{
    $n = count($chars);
    $flag = false;

    for ($i = 0; $i < ($n - 1); $i++)
    {
        if ($chars[$i] == $fir && $chars[$i + 1] == $sec)
        {
            $flag = true;
            break;
        }
    }

    if ($flag)
    {
        for ($j = $i + 2; $j < ($n - 1); $j++)
        {
            if ($chars[$j] == $sec && $chars[$j + 1] == $fir)
            {
                return true;
            }
        }
    }

    return false;
}

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$x= trim(fgets($handle));
$right=strlen($x)-1;
$one=false;$tow=false;$check=false;
$vis=[];
$vis1=[];
$first=true;
if(strlen($x)==1)echo "NO";
else
{
    for($i=0;$i<strlen($x)-1;$i++)
    {
        if($x[$i].$x[$i+1]=='AB' )
        {
           $vis[]=$i+1;
        }
        if($x[$i].$x[$i+1]=='BA' )
        {
            $vis1[]=$i+1;
        }
    }
    $temp=$vis;
    $mina=min($temp);$maxa=max($temp);

    $temp1=$vis1;
    $minb=min($temp1);$maxb=max($temp1);
    if((sizeof($vis)>=1 && sizeof($vis1)>=1) )
    {
        if((min($mina,$maxb)+1!=max($mina,$maxb) || min($minb,$maxa)+1!=max($minb,$maxa)))echo "YES";
        else
            echo "NO";
    }

    else echo "NO";
}
?>

<?php
$a = " " . trim(fgets(STDIN));
$b = "AB";
$c = "BA";
$d = "ABA";
$e = "BAB";
$f = strpos($a, $b);
$g = strpos($a, $c);
$h = strpos($a, $d);
$i = strpos($a, $e);
if(($h == TRUE) || ($i == TRUE))
{
    print "NO";
}
elseif(($f == TRUE) && ($g == TRUE))
{
    print "YES";
}
else
{
    print "NO";
}
?>

<?php
$line = trim(fgets(STDIN));
$ab_pos = strpos($line, "AB");
$ba_pos = strrpos($line, "BA");
if ($ab_pos !== false && $ba_pos !== false && abs($ba_pos - $ab_pos) > 2) {
  echo 'YES';
} else {
  echo 'NO';
}

<?php
$line = trim(fgets(STDIN));
$ab_pos = strpos($line, "AB");
$ba_pos = strrpos($line, "BA");
if ($ab_pos != -1 && $ba_pos != -1 && abs($ba_pos - $ab_pos) > 2) {
  echo 'YES';
} else {
  echo 'NO';
}

<?php
$line = trim(fgets(STDIN));
$ab_pos = strpos($line, "AB");
$ba_pos = strrpos($line, "BA");
if ($ab_pos !== false && $ba_pos !== false && abs($ba_pos - $ab_pos) >= 2) {
  echo 'YES';
} else {
  echo 'NO';
}

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

$ab_left = strpos($line, "AB");
$ab_right = strrpos($line, "AB");
$ba_left = strpos($line, "BA");
$ba_right = strpos($line, "BA");

//echo "$ab_left\n$ba_left\n$ba_right";

if ($ab_left === false || $ba_left === false) {
  echo 'NO';
  exit(0);
}

if (abs($ab_left - $ba_left) > 1 || abs($ab_left - $ba_right) > 1) {
  echo 'YES';
  exit(0);
}

echo 'NO';

<?php
$line = trim(fgets(STDIN));
$ab_left = strpos($line, "AB");
$ab_right = strrpos($line, "AB");
$ba_left = strpos($line, "BA");
$ba_right = strpos($line, "BA");
if ($ab_left == false || $ba_left == false) {
  echo 'NO';
  exit(0);
}
if (abs($ab_left - $ba_left) > 1 || abs($ab_left - $ba_right) > 1) {
  echo 'YES';
  exit(0);
}
echo 'NO';

<?php
$line = trim(fgets(STDIN));
$ab_pos = strpos($line, "AB");
$ba_pos = strrpos($line, "BA");
if ($ab_pos > 0 && $ba_pos > 0 && abs($ba_pos - $ab_pos) > 2) {
  echo 'YES';
} else {
  echo 'NO';
}

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

$ab_left = strpos($line, "AB");
$ab_right = strrpos($line, "AB");
$ba_left = strpos($line, "BA");
$ba_right = strrpos($line, "BA");

if ($ab_left === false || $ba_left === false) {
  echo 'NO';
  exit(0);
}

if (abs($ab_left - $ba_left) > 1 || abs($ab_left - $ba_right) > 1 || abs($ab_right - $ba_right) > 1) {
  echo 'YES';
  exit(0);
}

echo 'NO';

<?php
$line = trim(fgets(STDIN));
$ab_pos = strpos($line, "AB");
$ba_pos = strrpos($line, "BA");
if ($ab_pos && $ba_pos && abs($ba_pos - $ab_pos) > 2) {
  echo 'YES';
} else {
  echo 'NO';
}

<?php
$line = trim(fgets(STDIN));
$ab_pos = strpos($line, "AB");
$ba_pos = strrpos($line, "BA");
if ($ab_pos != -1 && $ba_pos != -1 && abs($ba_pos - $ab_pos) > 1) {
  echo 'YES';
} else {
  echo 'NO';
}

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

$ab_left = strpos($line, "AB");
$ab_right = strrpos($line, "AB");
$ba_left = strpos($line, "BA");
$ba_right = strrpos($line, "BA");

//echo "$ab_left\n$ba_left\n$ba_right";

if ($ab_left === false || $ba_left === false) {
  echo 'NO';
  exit(0);
}

//echo 'next';

if (abs($ab_left - $ba_left) > 1 || abs($ab_left - $ba_right) > 1) {
  echo 'YES';
  exit(0);
}

echo 'NO';

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

$ab_left = strpos($line, "AB");
$ab_right = strrpos($line, "AB");
$ba_left = strpos($line, "BA");
$ba_right = strpos($line, "BA");

//echo "$ab_left\n$ba_left\n$ba_right";

if ($ab_left === false || $ba_left === false) {
  echo 'NO';
  exit(0);
}

echo 'next';

if (abs($ab_left - $ba_left) > 1 || abs($ab_left - $ba_right) > 1) {
  echo 'YES';
  exit(0);
}

echo 'NO';

<?php
$input = fgets(STDIN);

if (empty($input))
{
    echo 'NO';
    exit;
}
else if (strlen($input) < 4)
{
    echo 'NO';
    exit;
}
else
{
    $chars = str_split($input);
    $ABFlag = false;
    $BAFlag = false;
    $fir = 'A';
    $sec = 'B';

    $n = count($chars);

    for ($i = 0; $i < ($n - 1); $i++)
    {
        if ($chars[$i] == $fir && $chars[$i + 1] == $sec)
        {
            $ABFlag = true;
            $fir = 'B';
            $sec = 'A';
            break;
        }

        if ($chars[$i] == $sec && $chars[$i + 1] == $fir)
        {
            $BAFlag = true;
            $fir = 'A';
            $sec = 'B';
            break;
        }
    }

    if ($ABFlag || $BAFlag)
    {
        for ($j = $i + 2; $j < count($chars) - 1; $j++)
        {
            if ($chars[$j] == $fir && $chars[$j + 1] == $sec)
            {
                echo 'YES';
                exit;
            }
        }
    }

    echo 'NO';
}

<?php

$input = !empty($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : null;

if (empty($input))
{
    echo 'NO';
    exit;
}
else if (strlen($input) < 4)
{
    echo 'NO';
    exit;
}
else
{
    $chars = str_split($input);
    $ABFlag = false;
    $BAFlag = false;
    $fir = 'A';
    $sec = 'B';

    $n = count($chars);

    for ($i = 0; $i < ($n - 1); $i++)
    {
        if ($chars[$i] == $fir && $chars[$i + 1] == $sec)
        {
            $ABFlag = true;
            $fir = 'B';
            $sec = 'A';
            break;
        }

        if ($chars[$i] == $sec && $chars[$i + 1] == $fir)
        {
            $BAFlag = true;
            $fir = 'A';
            $sec = 'B';
            break;
        }
    }

    if ($ABFlag || $BAFlag)
    {
        for ($j = $i + 2; $j < count($chars) - 1; $j++)
        {
            if ($chars[$j] == $fir && $chars[$j + 1] == $sec)
            {
                echo 'YES';
                exit;
            }
        }
    }

    echo 'NO';
}

<?php

$input = !empty($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : null;

if (empty($input))
{
    echo 'NO';
}
else if (strlen($input) < 4)
{
    echo 'NO';
}
else
{
    $chars = str_split($input);
    $ABFlag = false;
    $BAFlag = false;
    $fir = 'A';
    $sec = 'B';

    $n = count($chars);

    for ($i = 0; $i < ($n - 1); $i++)
    {
        if ($chars[$i] == $fir && $chars[$i + 1] == $sec)
        {
            $ABFlag = true;
            $fir = 'B';
            $sec = 'A';
            break;
        }

        if ($chars[$i] == $sec && $chars[$i + 1] == $fir)
        {
            $BAFlag = true;
            $fir = 'A';
            $sec = 'B';
            break;
        }
    }

    if ($ABFlag || $BAFlag)
    {
        for ($j = $i + 2; $j < count($chars) - 1; $j++)
        {
            if ($chars[$j] == $fir && $chars[$j + 1] == $sec)
            {
                echo 'YES';
                return;
            }
        }
    }

    echo 'NO';
}

<?php

$input = !empty($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : null;

if (empty($input))
{
    echo 'NO';
}
else if (strlen($input) < 4)
{
    echo 'NO';
}
else
{
    $chars = str_split($input);
    $ABFlag = false;
    $BAFlag = false;
    $flag = false;
    $fir = 'A';
    $sec = 'B';

    $n = count($chars);

    for ($i = 0; $i < ($n - 1); $i++)
    {
        if ($chars[$i] == $fir && $chars[$i + 1] == $sec)
        {
            $ABFlag = true;
            $fir = 'B';
            $sec = 'A';
            break;
        }

        if ($chars[$i] == $sec && $chars[$i + 1] == $fir)
        {
            $BAFlag = true;
            $fir = 'A';
            $sec = 'B';
            break;
        }
    }

    if ($ABFlag || $BAFlag)
    {
        for ($j = $i + 2; $j < count($chars) - 1; $j++)
        {
            if ($chars[$j] == $fir && $chars[$j + 1] == $sec)
            {
                echo 'YES';
                $flag = true;
            }
        }

        if (!$flag)
        {
            echo 'NO';
        }
    }
    else
    {
        echo 'NO';
    }
}

<?php
$input = fgets(STDIN);

if (empty($input))
{
    echo 'NO';
    exit;
}
else if (strlen($input) < 4)
{
    echo 'NO';
    exit;
}
else
{
    $chars = str_split($input);

    if (search($chars, 'A', 'B') || search($chars, 'B', 'A'))
    {
        echo 'YES';
    }

    echo 'NO';
}

function search($chars, $fir, $sec)
{
    $n = count($chars);
    $flag = false;

    for ($i = 0; $i < ($n - 1); $i++)
    {
        if ($chars[$i] == $fir && $chars[$i + 1] == $sec)
        {
            $flag = true;
            break;
        }
    }

    if ($flag)
    {
        for ($j = $i + 2; $j < ($n - 1); $j++)
        {
            if ($chars[$j] == $sec && $chars[$j + 1] == $fir)
            {
                return true;
            }
        }
    }

    return false;
}

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$x= trim(fgets($handle));
$right=strlen($x)-1;
$one=false;$tow=false;$check=false;
if(strlen($x)==1)echo "NO";
else
{
    for($i=0;$i<strlen($x)-1;$i+=2)
    {
        if($x[$i].$x[$i+1]=='AB')
        {
         $one=true;
        }
        if($x[$i].$x[$i+1]=='BA')
        {
            $tow=true;
        }
    }
    if($one==true)
    {
        for($i=0;$i<strlen($x)-1;$i+=2)
        {
            if($x[$i].$x[$i+1]=='BA')
            {
                $check=true;
            }
        }
    }else if($tow==true)
    { for($i=0;$i<strlen($x)-1;$i+=2)
    {
        if($x[$i].$x[$i+1]=='AB')
        {
            $check=true;
        }
    }

    }

    if($check==true)echo "YES";
    else echo "NO";
}
?>

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$x= trim(fgets($handle));
$right=strlen($x)-1;
$one=false;$tow=false;$check=false;
$vis=[];
$vis1=[];
$first=true;
if(strlen($x)==1)echo "NO";
else
{
    for($i=0;$i<strlen($x)-1;$i++)
    {
        if($x[$i].$x[$i+1]=='AB' )
        {
           $vis[]=$i+1;
        }
        if($x[$i].$x[$i+1]=='BA' )
        {
            $vis1[]=$i+1;
        }
    }
    $temp=$vis;
    $mina=min($temp);$maxa=max($temp);

    $temp1=$vis1;
    $minb=min($temp1);$maxb=max($temp1);

    if((sizeof($vis)>=1 && sizeof($vis1)>=1) && min($mina,$maxb)+1!=max($mina,$maxb) || min($minb,$maxa)+1!=max($minb,$maxa))echo "YES";
    else echo "NO";
}
?>

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$x= trim(fgets($handle));
$right=strlen($x)-1;
$one=false;$tow=false;$check=false;
if(strlen($x)==1)echo "NO";
else
{
    for($i=0;$i<strlen($x)-1;$i++)
    {
        if($x[$i].$x[$i+1]=='AB')
        {
         $one=true;
        }
        if($x[$i].$x[$i+1]=='BA')
        {
            $tow=true;
        }
    }
    if($one==true)
    {
        for($i=0;$i<strlen($x)-1;$i++)
        {
            if($x[$i].$x[$i+1]=='BA')
            {
                $check=true;
            }
        }
    }else if($tow==true)
    { for($i=0;$i<strlen($x)-1;$i++)
    {
        if($x[$i].$x[$i+1]=='AB')
        {
            $check=true;
        }
    }

    }

    if($check==true)echo "YES";
    else echo "NO";
}
?>

<?php

$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$x= trim(fgets($handle));
$right=strlen($x)-1;
$one=false;$tow=false;$check=false;
$vis=[];
$vis1=[];
$first=true;
if(strlen($x)==1)echo "NO";
else
{
    for($i=0;$i<strlen($x)-1;$i++)
    {
        if($x[$i].$x[$i+1]=='AB' )
        {
           $vis[]=$i+1;
        }
        if($x[$i].$x[$i+1]=='BA' )
        {
            $vis1[]=$i+1;
        }
    }
    $temp=array_merge($vis1,$vis);
    $mina=min($temp);$maxa=max($temp);

    if((sizeof($vis)>=1 && sizeof($vis1)>=1) && $mina+1!=$maxa)echo "YES";
    else echo "NO";
}
?>


Homer has two friends Alice and Bob. Both of them are string fans. One day, Alice and Bob decide to play a game on a string $$$s = s_1 s_2 \dots s_n$$$ of length $$$n$$$ consisting of lowercase English letters. They move in turns alternatively and Alice makes the first move.In a move, a player must choose an index $$$i$$$ ($$$1 \leq i \leq n$$$) that has not been chosen before, and change $$$s_i$$$ to any other lowercase English letter $$$c$$$ that $$$c \neq s_i$$$.When all indices have been chosen, the game ends. The goal of Alice is to make the final string lexicographically as small as possible, while the goal of Bob is to make the final string lexicographically as large as possible. Both of them are game experts, so they always play games optimally. Homer is not a game expert, so he wonders what the final string will be.A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds:   $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$;  in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.

Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Description of the test cases follows. The only line of each test case contains a single string $$$s$$$ ($$$1 \leq |s| \leq 50$$$) consisting of lowercase English letters.

For each test case, print the final string in a single line.

NoteIn the first test case: Alice makes the first move and must change the only letter to a different one, so she changes it to 'b'.In the second test case: Alice changes the first letter to 'a', then Bob changes the second letter to 'z', Alice changes the third letter to 'a' and then Bob changes the fourth letter to 'z'.In the third test case: Alice changes the first letter to 'b', and then Bob changes the second letter to 'y'.


Guy-Manuel and Thomas have an array $$$a$$$ of $$$n$$$ integers [$$$a_1, a_2, \dots, a_n$$$]. In one step they can add $$$1$$$ to any element of the array. Formally, in one step they can choose any integer index $$$i$$$ ($$$1 \le i \le n$$$) and do $$$a_i := a_i + 1$$$.If either the sum or the product of all elements in the array is equal to zero, Guy-Manuel and Thomas do not mind to do this operation one more time.What is the minimum number of steps they need to do to make both the sum and the product of all elements in the array different from zero? Formally, find the minimum number of steps to make $$$a_1 + a_2 +$$$ $$$\dots$$$ $$$+ a_n \ne 0$$$ and $$$a_1 \cdot a_2 \cdot$$$ $$$\dots$$$ $$$\cdot a_n \ne 0$$$.

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-100 \le a_i \le 100$$$) — elements of the array .

For each test case, output the minimum number of steps required to make both sum and product of all elements in the array different from zero.

NoteIn the first test case, the sum is $$$0$$$. If we add $$$1$$$ to the first element, the array will be $$$[3,-1,-1]$$$, the sum will be equal to $$$1$$$ and the product will be equal to $$$3$$$.In the second test case, both product and sum are $$$0$$$. If we add $$$1$$$ to the second and the third element, the array will be $$$[-1,1,1,1]$$$, the sum will be equal to $$$2$$$ and the product will be equal to $$$-1$$$. It can be shown that fewer steps can't be enough.In the third test case, both sum and product are non-zero, we don't need to do anything.In the fourth test case, after adding $$$1$$$ twice to the first element the array will be $$$[2,-2,1]$$$, the sum will be $$$1$$$ and the product will be $$$-4$$$.

<?php

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

$cases = fgets($f);

for ($k = 0; $k < $cases; $k++) {
  $line = trim(fgets($f));
  $line = trim(fgets($f));

  $arr = explode(" ", $line);

  // get the number of 0s
  $steps = 0;
  $sum = 0;
  for ($i = 0; $i < count($arr); $i++) {
    if($arr[$i] == 0) {
      $arr[$i]++;
      $steps++;
    }

    $sum += $arr[$i];
  }

  if ($sum == 0) {
    $steps++;
  }

  print $steps . "\n";

}

?>

<?php
/*dskhbfjkhs*/
$server = "php://stdin";
$handle = fopen($server, "r");
$input = trim(fgets($handle));

for ($j = 0; $j < $input; $j++) {
    $new = trim(fgets($handle));
    $array = trim(fgets($handle));
    $array = explode(' ', $array);
    $map = [];

    $s = 0;
    $cnt = 0;
    for ($i = 0; $i < $new; $i++) {
        if ($array[$i] == 0) {
            $cnt++;
            $array[$i] = 1;
        }
        $s += $array[$i];
    }
    if ($s == 0) {
        $cnt++;
    }
    echo $cnt . "\n";

}

?>

<?php

class ArgsHelper
{
	private $useStd;

	public function __construct($userStd = false)
	{
		$this->useStd = $userStd;
	}

	private function hasZeros($numbers)
	{
		foreach ($numbers as $item)
		{
			if ((int)$item === 0)
			{
				return true;
			}
		}
		return false;
	}

	public function calculateResult($input)
	{
		$numbers = array_map('intval', explode(' ', $input));
		sort($numbers);
		$numbers = array_reverse($numbers);
		$count = 0;
		while (true)
		{
			foreach ($numbers as $index => $number)
			{
				if ($number === 0)
				{
					$numbers[$index]++;
					$count++;
					continue 2;
				}
			}
			$sum = (int)array_sum($numbers);
			if ($sum !== 0 && !$this->hasZeros($numbers))
			{
				return $count;
			}

			foreach ($numbers as $index => $number)
			{
				$numbers[$index]++;

				$sum = (int)array_sum($numbers);
				if ($sum !== 0 && !$this->hasZeros($numbers))
				{
					$count++;
					return $count;
				}
				else
				{
					$numbers[$index]--;
				}
			}

			foreach ($numbers as $index => $number)
			{
				if ($number !== -1)
				{
					$numbers[$index]++;
					$count++;
					continue 2;
				}
			}
			foreach ($numbers as $index => $number)
			{
				$numbers[$index]++;
				$count++;
				break;
			}
		}
	}

	public function getInputLines()
	{
		$input = [];
		if ($this->useStd)
		{
			while ($line = fgets(STDIN))
			{
				$input[] = $line;
			}
		}
		else
		{
			$input = '';
			$input = explode("\n", trim($input));
		}
		return $input;
	}

	public function printResult($result)
	{
		if ($this->useStd)
		{
			fwrite(STDOUT, $result);
		}
		else
		{
			var_dump($result);
		}
	}

}

$helper = new ArgsHelper(true);
$lines = $helper->getInputLines();

$result = '';
#
array_shift($lines);
foreach ($lines as $index => $line)
{
	if ($index % 2 === 0)
	{
		continue;
	}
	$result .= $helper->calculateResult($line) . ' ';
}
$result = trim($result);
#

$helper->printResult($result);

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t= trim(fgets($handle));

for($j=0;$j<$t;$j++)
{
    $n=trim(fgets($handle));
    $a=trim(fgets($handle));
    $a=explode(' ',$a);
    $map=[];

    $sum=0;$count=0;
    for($i=0;$i<$n;$i++)
    {
       if($a[$i]==0){$count++;$a[$i]=1;}
       $sum+=$a[$i];
    }
    if($sum==0)
    {
        $count++;
    }
    echo $count."\n";

}

?>

<?php

class ArgsHelper
{
	private $useStd;

	public function __construct($userStd = false)
	{
		$this->useStd = $userStd;
	}

	public function calculateResult($input)
	{
		$numbers = array_map('intval', explode(' ', $input));
		sort($numbers);
		$numbers = array_reverse($numbers);
		$count = 0;
		while (true)
		{
			$sum = array_sum($numbers);
			$product = array_product($numbers);
			if ($sum !== 0 && $product !== 0)
			{
				return $count;
			}
			foreach ($numbers as $index => $number)
			{
				$numbers[$index]++;
				$count++;

				$sum = array_sum($numbers);
				$product = array_product($numbers);
				if ($sum !== 0 && $product !== 0)
				{
					return $count;
				}
				else
				{
					$numbers[$index]--;
					$count--;
				}
			}
			foreach ($numbers as $index => $number)
			{
				if ($number === 0)
				{
					$numbers[$index]++;
					$count++;
					continue 2;
				}
			}
			foreach ($numbers as $index => $number)
			{
				if ($number !== -1)
				{
					$numbers[$index]++;
					$count++;
					continue 2;
				}
			}
			foreach ($numbers as $index => $number)
			{
				$numbers[$index]++;
				$count++;
				break;
			}
		}
	}

	public function getInputLines()
	{
		$input = [];
		if ($this->useStd)
		{
			while ($line = fgets(STDIN))
			{
				$input[] = $line;
			}
		}
		else
		{
			$input = '1000
100
0 0 -60 0 20 0 -85 0 0 0 -88 -77 83 0 10 0 98 0 1 68 0 0 0 0 0 0 -46 -95 0 -63 0 0 0 41 5 21 -60 0 -23 0 32 61 0 0 67 -87 73 -88 0 0 0 56 0 27 0 0 0 0 -42 -49 59 0 -74 -34 0 0 42 0 0 0 55 -36 -59 0 0 94 0 0 -58 54 0 2 67 0 0 0 100 0 45 73 -54 54 0 94 0 0 -1 -12 -40 -59
100
-25 0 0 -33 -43 0 0 0 -10 -15 0 58 -23 -90 -82 0 0 0 0 83 0 8 -51 0 -54 0 43 59 0 4 29 0 -23 0 0 43 70 47 -45 0 62 0 -75 -75 0 0 62 -71 0 -36 74 0 0 0 53 0 0 -39 0 97 0 -34 0 0 0 0 55 0 0 0 17 -94 27 32 0 72 14 -47 0 -70 0 -...
';
			$input = explode("\n", trim($input));
		}
		return $input;
	}

	public function printResult($result)
	{
		if ($this->useStd)
		{
			fwrite(STDOUT, $result);
		}
		else
		{
			var_dump($result);
		}
	}

}

$helper = new ArgsHelper(true);
$lines = $helper->getInputLines();

$result = '';
#
array_shift($lines);
foreach ($lines as $index => $line)
{
	if ($index % 2 === 0)
	{
		continue;
	}
	$result .= $helper->calculateResult($line) . ' ';
}
$result = trim($result);
#

$helper->printResult($result);

<?php

class ArgsHelper
{
	private $useStd;

	public function __construct($userStd = false)
	{
		$this->useStd = $userStd;
	}

	public function calculateResult($input)
	{
		$numbers = array_map('intval', explode(' ', $input));
		sort($numbers);
		$numbers = array_reverse($numbers);
		$count = 0;
		while (true)
		{
			$sum = array_sum($numbers);
			$product = array_product($numbers);
			if ($sum !== 0 && $product !== 0)
			{
				return $count;
			}
			foreach ($numbers as $index => $number)
			{
				if ($number === 0)
				{
					$numbers[$index]++;
					$count++;
					continue 2;
				}
			}
			foreach ($numbers as $index => $number)
			{
				if ($number !== -1)
				{
					$numbers[$index]++;
					$count++;
					continue 2;
				}
			}
			foreach ($numbers as $index => $number)
			{
				$numbers[$index]++;
				$count++;
				break;
			}
		}
	}

	public function getInputLines()
	{
		$input = [];
		if ($this->useStd)
		{
			while ($line = fgets(STDIN))
			{
				$input[] = $line;
			}
		}
		else
		{
			$input = '4
3
2 -1 -1
4
-1 0 0 1
2
-1 2
3
0 -2 1
';
			$input = explode("\n", trim($input));
		}
		return $input;
	}

	public function printResult($result)
	{
		if ($this->useStd)
		{
			fwrite(STDOUT, $result);
		}
		else
		{
			var_dump($result);
		}
	}

}

$helper = new ArgsHelper(true);
$lines = $helper->getInputLines();

$result = '';
#
array_shift($lines);
foreach ($lines as $index => $line)
{
	if ($index % 2 === 0)
	{
		continue;
	}
	$result .= $helper->calculateResult($line) . ' ';
}
$result = trim($result);
#

$helper->printResult($result);


The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.

The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively. Next n lines define the image. Each line contains m lowercase Latin letters.

In the single line print the number of faces on the image.

NoteIn the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:   In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.In the third sample two faces are shown:   In the fourth sample the image has no faces on it.

<?php
$input = fopen("php://stdin", 'r');
$input = stream_get_contents($input);
$input = explode("\n", $input);
$paramsStr = explode(' ',$input[0]);
$width = $paramsStr[1];
$height = $paramsStr[0];
$needsWords = array ('f', 'a', 'c', 'e');
$matrix = array();
for ($i =1; $i <= $height; $i ++){
    for ($j = 0 ; $j < $width; $j ++) {
        $matrix[$i][] = $input[$i][$j];
    }
}

$cnt = 0;
foreach ($matrix as $rowNumber => $row){
    foreach ($row as $colNumber => $word){
        if (in_array($word, $needsWords)){

            $exist = array($word);
            $a = 1;
            //echo "\r\n".$word." ".$matrix[$colNumber + 1][$rowNumber].' '.$matrix[$colNumber][$rowNumber].' '.$matrix[$colNumber][$rowNumber]."\r\n";
            if (isset($matrix[$rowNumber + 1][$colNumber]) && in_array($matrix[$rowNumber + 1][$colNumber], $needsWords) && !in_array($matrix[$rowNumber + 1][$colNumber], $exist)){
                $a++;
                $exist[] = $matrix[$rowNumber + 1][$colNumber];
            }
            if (isset($matrix[$rowNumber + 1][$colNumber + 1]) && in_array($matrix[$rowNumber + 1][$colNumber + 1], $needsWords) && !in_array($matrix[$rowNumber + 1][$colNumber + 1], $exist)){
                $a++;
                $exist[] =$matrix[$rowNumber + 1][$colNumber + 1];
            }
            if (isset($matrix[$rowNumber][$colNumber + 1]) && in_array($matrix[$rowNumber][$colNumber + 1], $needsWords) && !in_array($matrix[$rowNumber][$colNumber + 1], $exist)){
                $a++;
                $exist[] = $matrix[$rowNumber][$colNumber + 1];
            }
            if ($a == 4){
                $cnt ++;
            }
        }
    }
}
echo $cnt;

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

list($n,$m) = explode(" ",trim(fgets($f)));

$a = array();

function check($a,$x,$y){

    $b = array();

    if (isset($a[$x][$y]))
        $b[] = $a[$x][$y];
    else return false;

    if (isset($a[$x+1][$y]))
        $b[] = $a[$x+1][$y];
    else return false;

    if (isset($a[$x][$y+1]))
        $b[] = $a[$x][$y+1];
    else return false;

    if (isset($a[$x+1][$y+1]))
        $b[] = $a[$x+1][$y+1];
    else return false;

    sort($b);

    if ($b[0]=='a' && $b[1]=='c' && $b[2]=='e' && $b[3]=='f') return true;

    return false;
}

$count = 0;

for($i=0;$i<$n;$i++){
    $a[$i] = str_split(trim(fgets($f)));
}

for($i=0;$i<$n;$i++){
    for($j=0;$j<$m;$j++){

        if (check($a,$i,$j)){
            $count++;
        }
    }
}

echo $count;

<?php
$input = fopen("php://stdin", 'r');
$input = stream_get_contents($input);
$input = explode("\n", $input);
$paramsStr = explode(' ',$input[0]);
$width = $paramsStr[0];
$height = $paramsStr[1];
$needsWords = array ('f', 'a', 'c', 'e');
$matrix = array();
for ($i =1; $i <$height; $i ++){
    for ($j = 0 ; $j< $width; $j ++) {
        $matrix[$i][] = $input[$i][$j];
    }
}
$cnt = 0;
foreach ($matrix as $rowNumber => $row){
    echo 'Row: '.$rowNumber."\r\n";
    foreach ($row as $colNumber => $word){
        echo 'Col: '.$colNumber."\r\n";
        if (in_array($word, $needsWords)){
            $exist = array($word);
            $a = 1;
            //echo "\r\n".$word." ".$matrix[$colNumber + 1][$rowNumber].' '.$matrix[$colNumber][$rowNumber].' '.$matrix[$colNumber][$rowNumber]."\r\n";
            if (isset($matrix[$rowNumber + 1][$colNumber]) && in_array($matrix[$rowNumber + 1][$colNumber], $needsWords) && !in_array($matrix[$rowNumber + 1][$colNumber], $exist)){
                $a++;
                $exist[] = $matrix[$rowNumber + 1][$colNumber];
            }
            if (isset($matrix[$rowNumber + 1][$colNumber + 1]) && in_array($matrix[$rowNumber + 1][$colNumber + 1], $needsWords) && !in_array($matrix[$rowNumber + 1][$colNumber + 1], $exist)){
                $a++;
                $exist[] =$matrix[$rowNumber + 1][$colNumber + 1];
            }
            if (isset($matrix[$rowNumber][$colNumber + 1]) && in_array($matrix[$rowNumber][$colNumber + 1], $needsWords) && !in_array($matrix[$rowNumber][$colNumber + 1], $exist)){
                $a++;
                $exist[] = $matrix[$rowNumber][$colNumber + 1];
            }
            if ($a == 4){
                $cnt ++;
            }
        }
    }
}
echo $cnt;

<?php
$input = fopen("php://stdin", 'r');
$input = stream_get_contents($input);
$input = explode("\n", $input);
$paramsStr = explode(' ',$input[0]);
$width = $paramsStr[0];
$height = $paramsStr[1];
$needsWords = array ('f', 'a', 'c', 'e');
$matrix = array();
for ($i =1; $i <$height; $i ++){
    for ($j = 0 ; $j< $width; $j ++) {
        $matrix[$i][] = $input[$i][$j];
    }
}
$cnt = 0;
foreach ($matrix as $rowNumber => $row){
    foreach ($row as $colNumber => $word){
        if (in_array($word, $needsWords)){
            $exist = array($word);
            $a = 1;
            //echo "\r\n".$word." ".$matrix[$colNumber + 1][$rowNumber].' '.$matrix[$colNumber][$rowNumber].' '.$matrix[$colNumber][$rowNumber]."\r\n";
            if (isset($matrix[$rowNumber + 1][$colNumber]) && in_array($matrix[$rowNumber + 1][$colNumber], $needsWords) && !in_array($matrix[$rowNumber + 1][$colNumber], $exist)){
                $a++;
                $exist[] = $matrix[$rowNumber + 1][$colNumber];
            }
            if (isset($matrix[$rowNumber + 1][$colNumber + 1]) && in_array($matrix[$rowNumber + 1][$colNumber + 1], $needsWords) && !in_array($matrix[$rowNumber + 1][$colNumber + 1], $exist)){
                $a++;
                $exist[] =$matrix[$rowNumber + 1][$colNumber + 1];
            }
            if (isset($matrix[$rowNumber][$colNumber + 1]) && in_array($matrix[$rowNumber][$colNumber + 1], $needsWords) && !in_array($matrix[$rowNumber][$colNumber + 1], $exist)){
                $a++;
                $exist[] = $matrix[$rowNumber][$colNumber + 1];
            }
            if ($a == 4){
                $cnt ++;
            }
        }
    }
}
echo $cnt;

<?php
$input = fopen("php://stdin", 'r');
$input = stream_get_contents($input);
$input = explode("\n", $input);
$paramsStr = explode(' ',$input[0]);
$width = $paramsStr[0];
$height = $paramsStr[1];
$needsWords = array ('f', 'a', 'c', 'e');
$matrix = array();
for ($i =1; $i <$height; $i ++){
    for ($j = 0 ; $j< $width; $j ++) {
        $matrix[$i][] = $input[$i][$j];
    }
}
$cnt = 0;
foreach ($matrix as $rowNumber => $row){
    foreach ($row as $colNumber => $word){
        if (in_array($word, $needsWords)){
            $exist = array($word);
            $a = 1;
            if (isset($matrix[$colNumber + 1][$rowNumber]) && in_array($matrix[$colNumber + 1][$rowNumber], $needsWords) && !in_array($matrix[$colNumber + 1][$rowNumber], $exist)){
                $a++;
                $exist[] = $matrix[$colNumber + 1];
            }

            if (isset($matrix[$colNumber + 1][$rowNumber + 1]) && in_array($matrix[$colNumber + 1][$rowNumber + 1], $needsWords) && !in_array($matrix[$colNumber + 1][$rowNumber + 1], $exist)){
                $a++;
                $exist[] = $matrix[$colNumber + 1];
            }

            if (isset($matrix[$colNumber][$rowNumber + 1]) && in_array($matrix[$colNumber][$rowNumber + 1], $needsWords) && !in_array($matrix[$colNumber][$rowNumber + 1], $exist)){
                $a++;
                $exist[] = $matrix[$colNumber + 1];
            }

            if ($a == 4){
                $cnt ++;
            }
        }
    }
}
echo $cnt;

<?php
$input = fopen("php://stdin", 'r');
$input = stream_get_contents($input);
$input = explode("\n", $input);
$paramsStr = explode(' ',$input[0]);
$width = $paramsStr[1];
$height = $paramsStr[0];
$needsWords = array ('f', 'a', 'c', 'e');
$matrix = array();
for ($i =1; $i <$height; $i ++){
    for ($j = 0 ; $j< $width; $j ++) {
        $matrix[$i][] = $input[$i][$j];
    }
}

$cnt = 0;
foreach ($matrix as $rowNumber => $row){
    foreach ($row as $colNumber => $word){
        if (in_array($word, $needsWords)){
            $exist = array($word);
            $a = 1;
            //echo "\r\n".$word." ".$matrix[$colNumber + 1][$rowNumber].' '.$matrix[$colNumber][$rowNumber].' '.$matrix[$colNumber][$rowNumber]."\r\n";
            if (isset($matrix[$rowNumber + 1][$colNumber]) && in_array($matrix[$rowNumber + 1][$colNumber], $needsWords) && !in_array($matrix[$rowNumber + 1][$colNumber], $exist)){
                $a++;
                $exist[] = $matrix[$rowNumber + 1][$colNumber];
            }
            if (isset($matrix[$rowNumber + 1][$colNumber + 1]) && in_array($matrix[$rowNumber + 1][$colNumber + 1], $needsWords) && !in_array($matrix[$rowNumber + 1][$colNumber + 1], $exist)){
                $a++;
                $exist[] =$matrix[$rowNumber + 1][$colNumber + 1];
            }
            if (isset($matrix[$rowNumber][$colNumber + 1]) && in_array($matrix[$rowNumber][$colNumber + 1], $needsWords) && !in_array($matrix[$rowNumber][$colNumber + 1], $exist)){
                $a++;
                $exist[] = $matrix[$rowNumber][$colNumber + 1];
            }
            if ($a == 4){
                $cnt ++;
            }
        }
    }
}
echo $cnt;


A palindrome is a string $$$t$$$ which reads the same backward as forward (formally, $$$t[i] = t[|t| + 1 - i]$$$ for all $$$i \in [1, |t|]$$$). Here $$$|t|$$$ denotes the length of a string $$$t$$$. For example, the strings 010, 1001 and 0 are palindromes.You have $$$n$$$ binary strings $$$s_1, s_2, \dots, s_n$$$ (each $$$s_i$$$ consists of zeroes and/or ones). You can swap any pair of characters any number of times (possibly, zero). Characters can be either from the same string or from different strings — there are no restrictions.Formally, in one move you:  choose four integer numbers $$$x, a, y, b$$$ such that $$$1 \le x, y \le n$$$ and $$$1 \le a \le |s_x|$$$ and $$$1 \le b \le |s_y|$$$ (where $$$x$$$ and $$$y$$$ are string indices and $$$a$$$ and $$$b$$$ are positions in strings $$$s_x$$$ and $$$s_y$$$ respectively),  swap (exchange) the characters $$$s_x[a]$$$ and $$$s_y[b]$$$. What is the maximum number of strings you can make palindromic simultaneously?

The first line contains single integer $$$Q$$$ ($$$1 \le Q \le 50$$$) — the number of test cases. The first line on each test case contains single integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of binary strings you have. Next $$$n$$$ lines contains binary strings $$$s_1, s_2, \dots, s_n$$$ — one per line. It's guaranteed that $$$1 \le |s_i| \le 50$$$ and all strings constist of zeroes and/or ones.

Print $$$Q$$$ integers — one per test case. The $$$i$$$-th integer should be the maximum number of palindromic strings you can achieve simultaneously performing zero or more swaps on strings from the $$$i$$$-th test case.

NoteIn the first test case, $$$s_1$$$ is palindrome, so the answer is $$$1$$$.In the second test case you can't make all three strings palindromic at the same time, but you can make any pair of strings palindromic. For example, let's make $$$s_1 = \text{0110}$$$, $$$s_2 = \text{111111}$$$ and $$$s_3 = \text{010000}$$$.In the third test case we can make both strings palindromic. For example, $$$s_1 = \text{11011}$$$ and $$$s_2 = \text{100001}$$$.In the last test case $$$s_2$$$ is palindrome and you can make $$$s_1$$$ palindrome, for example, by swapping $$$s_1[2]$$$ and $$$s_1[3]$$$.


An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $$$091$$$), a colon (ASCII code $$$058$$$), some (possibly zero) vertical line characters (ASCII code $$$124$$$), another colon, and a closing bracket (ASCII code $$$093$$$). The length of the accordion is the number of characters in it.For example, [::], [:||:] and [:|||:] are accordions having length $$$4$$$, $$$6$$$ and $$$7$$$. (:|:), {:||:}, [:], ]:||:[ are not accordions. You are given a string $$$s$$$. You want to transform it into an accordion by removing some (possibly zero) characters from it. Note that you may not insert new characters or reorder existing ones. Is it possible to obtain an accordion by removing characters from $$$s$$$, and if so, what is the maximum possible length of the result?

The only line contains one string $$$s$$$ ($$$1 \le |s| \le 500000$$$). It consists of lowercase Latin letters and characters [, ], : and |.

If it is not possible to obtain an accordion by removing some characters from $$$s$$$, print $$$-1$$$. Otherwise print maximum possible length of the resulting accordion.

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

$s = $ir->readString();
$n = strlen($s);
$lb = null;
$rb = null;
$rsc = null;
$lsc = null;

for ($i=0; $i<$n; $i++) {
	if ($s[$i]=='[') {
		$lb = $i;
		break;
	}
}

if ($lb===null) {
	echo -1; exit();
}
//echo $lb;
for ($i=$lb+1; $i<$n; $i++) {
	if ($s[$i]==':') {
		$lsc = $i;
		break;
	}
}

if ($lsc===null) {
	echo -1; exit();
}
//echo $lsc;
for ($i=$n-1; $i>$lsc; $i--) {
	if ($s[$i]==']') {
		$rb = $i;
		break;
	}
}

if ($rb===null) {
	echo -1; exit();
}
//echo $rb;
for ($i=$rb-1; $i>=$lsc; $i--) {
	if ($s[$i]==':') {
		$rsc = $i;
		break;
	}
}

if ($rsc===null) {
	echo -1; exit();
}
//echo $rsc;
if ($rsc===$lsc) {
	echo -1; exit();
}

$bars = 0;
for ($i=$lsc+1; $i<=$rsc-1; $i++) {
	if ($s[$i] == '|') {
		$bars++;
	}
}

echo $bars+4;

<?php

$sStr = trim(fgets(STDIN));

$sStr = preg_replace('~[a-z0-9]+~','',$sStr);
//echo $sStr . "\n";

$iCount = -1;
if(($i = strpos($sStr, '[')) !== false) {
    $iCount = 1;
    $sStr = substr($sStr, $i + 1);
//    echo 1 . ' [ ' . $i .  "\n";
    if(($i1 = strpos($sStr, ':')) !== false) {
        $sStr = substr($sStr, $i1 + 1);
        $iCount++;
//        echo 2 . ' : ' . $i1 .  "\n";

        if(($i2 = strrpos($sStr, ']')) !== false) {
            $iCount++;
            $sStr = substr($sStr, 0, $i2);
//            echo $iCount . ' : ' . $i2 .  "\n";
            if(($i3 = strrpos($sStr, ':')) !== false) {
                $iCount++;
                $sStr = substr($sStr, 0, $i3);
//                echo $iCount . ' ] ' . $i3 . "\n";

                $i1 = -1;
                $sStr = preg_replace('~[\[\]\:]+~','',$sStr);
//                echo $sStr . "\n";
//                $iCount += strlen($sStr);
                while (true) {
                    if (($i4 = strpos($sStr, '|', $i1 + 1)) !== false) {

                        $iCount++;
//                        echo $iCount . ' | ' . $i2 . "\n";

                        $i1 = $i4;
                    } else {
                        break;
                    }
                }
            } else {
                $iCount = -1;
            }
        } else {
            $iCount = -1;
        }
    } else {
        $iCount = -1;
    }
}

echo $iCount;

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

$s = $ir->readString();

$lb = null;
$rb = null;
$rsc = null;
$lsc = null;

for ($i=0; $i<strlen($s); $i++) {
	if ($s[$i]=='[') {
		$lb = $i;
		break;
	}
}

if ($lb===null) {
	echo -1; exit();
}

for ($i=$lb+1; $i<strlen($s); $i++) {
	if ($s[$i]==':') {
		$lsc = $i;
		break;
	}
}

if ($lsc===null) {
	echo -1; exit();
}

for ($i=$n-1; $i<=$lsc; $i--) {
	if ($s[$i]==']') {
		$rb = $i;
		break;
	}
}

if ($rb===null) {
	echo -1; exit();
}

for ($i=$rb-1; $i<=$lsc; $i--) {
	if ($s[$i]==':') {
		$rsc = $i;
		break;
	}
}

if ($rsc===null) {
	echo -1; exit();
}

if ($rsc===$lsc) {
	echo -1; exit();
}

$bars = 0;
for ($i=$lsc+1; $i<=$rsc-1; $i++) {
	if ($s[$i] == '|') {
		$bars++;
	}
}

echo $bars+4;

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

$s = $ir->readString();

$lb = null;
$rb = null;
$rsc = null;
$lsc = null;
for ($i=0; $i<strlen($s); $i++) {
	if ($s[$i]=='[') $lb = $lb ?? $i;
	if ($lb!==null && $s[$i]==':') $lsc = $lsc ?? $i;
	if ($lb!==null && $lsc!==null) break;
}

for ($i=strlen($s)-1; $i>=0; $i--) {
	if ($s[$i]==']') $rb = $rb ?? $i;
	if ($rb!==null && $s[$i]==':') $rsc = $rsc ?? $i;
	if ($rb!==null && $rsc!==null) break;
}

//var_dump([$lb, $lsc, $rsc, $rb]);
$bars = 0;
if ($rb>$lb && $lsc!==null && $rsc!==null && $lsc!=$rsc) {
	for ($i=$rsc; $i<$lsc; $i++) {
		if ($s[$i] == '|') {
			$bars++;
		}
	}

	echo $bars+4;
}
else {
	echo -1;
}

<?php

$sStr = trim(fgets(STDIN));

$sStr = preg_replace('~[a-b]+~','',$sStr);
//echo $sStr;exit;

$iCount = -1;
if(($i = strpos($sStr, '[')) !== false) {
    $iCount = 1;
    $sStr = substr($sStr, $i + 1);
//    echo 1 . ' [ ' . $i .  "\n";
    if(($i1 = strpos($sStr, ':')) !== false) {
        $sStr = substr($sStr, $i1 + 1);
        $iCount++;
//        echo 2 . ' : ' . $i1 .  "\n";

        if(($i2 = strrpos($sStr, ':')) !== false) {
            $iCount++;
//            echo $iCount . ' : ' . $i2 .  "\n";
            if(($i3 = strpos($sStr, ']', $i2 + 1)) !== false) {
                $iCount++;
                $sStr = substr($sStr, 0, $i2);
//                echo $iCount . ' ] ' . $i3 . "\n";

                $i1 = -1;
                while (true) {
                    if (($i4 = strpos($sStr, '|', $i1 + 1)) !== false) {

                        $iCount++;
//                        echo $iCount . ' | ' . $i2 . "\n";

                        $i1 = $i4;
                    } else {
                        break;
                    }
                }
            } else {
                $iCount = -1;
            }
        } else {
            $iCount = -1;
        }
    } else {
        $iCount = -1;
    }
}

echo $iCount;

<?php

$sStr = trim(fgets(STDIN));

$sStr = preg_replace('~[a-b]+~','',$sStr);
//echo $sStr . "\n";

$iCount = -1;
if(($i = strpos($sStr, '[')) !== false) {
    $iCount = 1;
    $sStr = substr($sStr, $i + 1);
//    echo 1 . ' [ ' . $i .  "\n";
    if(($i1 = strpos($sStr, ':')) !== false) {
        $sStr = substr($sStr, $i1 + 1);
        $iCount++;
//        echo 2 . ' : ' . $i1 .  "\n";

        if(($i2 = strrpos($sStr, ']')) !== false) {
            $iCount++;
            $sStr = substr($sStr, 0, $i2);
//            echo $iCount . ' : ' . $i2 .  "\n";
            if(($i3 = strrpos($sStr, ':')) !== false) {
                $iCount++;
                $sStr = substr($sStr, 0, $i3);
//                echo $iCount . ' ] ' . $i3 . "\n";

                $i1 = -1;
                $sStr = preg_replace('~[\[\]\:0-9]+~','',$sStr);
//                echo $sStr . "\n";
                $iCount += strlen($sStr);
//                while (true) {
//                    if (($i4 = strpos($sStr, '|', $i1 + 1)) !== false) {
//
//                        $iCount++;
////                        echo $iCount . ' | ' . $i2 . "\n";
//
//                        $i1 = $i4;
//                    } else {
//                        break;
//                    }
//                }
            } else {
                $iCount = -1;
            }
        } else {
            $iCount = -1;
        }
    } else {
        $iCount = -1;
    }
}

echo $iCount;

<?php

$sStr = trim(fgets(STDIN));

$iCount = -1;
if(($i = strpos($sStr, '[')) !== false) {
    $iCount = 1;
//    echo 1 . ' [ ' . $i .  "\n";
    if(($i1 = strpos($sStr, ':', $i + 1)) !== false) {

        $iCount++;
//        echo 2 . ' : ' . $i1 .  "\n";

        if(($i2 = strrpos($sStr, ':', $i1 + 1)) !== false) {
            $iCount++;
//            echo $iCount . ' : ' . $i2 .  "\n";
            if(($i3 = strpos($sStr, ']', $i2 + 1)) !== false) {
                $iCount++;
//                echo $iCount . ' ] ' . $i3 . "\n";

                while (true) {
                    if (($i4 = strpos($sStr, '|', $i1 + 1)) !== false) {

                        if ($i4 >= $i2) {
                            break;
                        }

                        $iCount++;
//                        echo $iCount . ' | ' . $i2 . "\n";

                        $i1 = $i4;
                    } else {
                        break;
                    }
                }
            } else {
                $iCount = -1;
            }
        } else {
            $iCount = -1;
        }
    } else {
        $iCount = -1;
    }
}

echo $iCount;

<?php

$sStr = trim(fgets(STDIN));

$sStr = preg_replace('~[a-b]+~','',$sStr);
//echo $sStr;exit;

$iCount = -1;
if(($i = strpos($sStr, '[')) !== false) {
    $iCount = 1;
//    echo 1 . ' [ ' . $i .  "\n";
    if(($i1 = strpos($sStr, ':', $i + 1)) !== false) {

        $iCount++;
//        echo 2 . ' : ' . $i1 .  "\n";

        if(($i2 = strrpos($sStr, ':', $i1 + 1)) !== false) {
            $iCount++;
//            echo $iCount . ' : ' . $i2 .  "\n";
            if(($i3 = strpos($sStr, ']', $i2 + 1)) !== false) {
                $iCount++;
//                echo $iCount . ' ] ' . $i3 . "\n";

                while (true) {
                    if (($i4 = strpos($sStr, '|', $i1 + 1)) !== false) {

                        if ($i4 > $i2) {
                            break;
                        }

                        $iCount++;
//                        echo $iCount . ' | ' . $i2 . "\n";

                        $i1 = $i4;
                    } else {
                        break;
                    }
                }
            } else {
                $iCount = -1;
            }
        } else {
            $iCount = -1;
        }
    } else {
        $iCount = -1;
    }
}

echo $iCount;


Let's define a number ebne (even but not even) if and only if its sum of digits is divisible by $$$2$$$ but the number itself is not divisible by $$$2$$$. For example, $$$13$$$, $$$1227$$$, $$$185217$$$ are ebne numbers, while $$$12$$$, $$$2$$$, $$$177013$$$, $$$265918$$$ are not. If you're still unsure what ebne numbers are, you can look at the sample notes for more clarification.You are given a non-negative integer $$$s$$$, consisting of $$$n$$$ digits. You can delete some digits (they are not necessary consecutive/successive) to make the given number ebne. You cannot change the order of the digits, that is, after deleting the digits the remaining digits collapse. The resulting number shouldn't contain leading zeros. You can delete any number of digits between $$$0$$$ (do not delete any digits at all) and $$$n-1$$$.For example, if you are given $$$s=$$$222373204424185217171912 then one of possible ways to make it ebne is: 222373204424185217171912 $$$\rightarrow$$$ 2237344218521717191. The sum of digits of 2237344218521717191 is equal to $$$70$$$ and is divisible by $$$2$$$, but number itself is not divisible by $$$2$$$: it means that the resulting number is ebne.Find any resulting number that is ebne. If it's impossible to create an ebne number from the given number report about it.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3000$$$)  — the number of digits in the original number. The second line of each test case contains a non-negative integer number $$$s$$$, consisting of $$$n$$$ digits. It is guaranteed that $$$s$$$ does not contain leading zeros and the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.

For each test case given in the input print the answer in the following format:  If it is impossible to create an ebne number, print "-1" (without quotes); Otherwise, print the resulting number after deleting some, possibly zero, but not all digits. This number should be ebne. If there are multiple answers, you can print any of them. Note that answers with leading zeros or empty strings are not accepted. It's not necessary to minimize or maximize the number of deleted digits.

NoteIn the first test case of the example, $$$1227$$$ is already an ebne number (as $$$1 + 2 + 2 + 7 = 12$$$, $$$12$$$ is divisible by $$$2$$$, while in the same time, $$$1227$$$ is not divisible by $$$2$$$) so we don't need to delete any digits. Answers such as $$$127$$$ and $$$17$$$ will also be accepted.In the second test case of the example, it is clearly impossible to create an ebne number from the given number.In the third test case of the example, there are many ebne numbers we can obtain by deleting, for example, $$$1$$$ digit such as $$$17703$$$, $$$77013$$$ or $$$17013$$$. Answers such as $$$1701$$$ or $$$770$$$ will not be accepted as they are not ebne numbers. Answer $$$013$$$ will not be accepted as it contains leading zeroes.Explanation: $$$1 + 7 + 7 + 0 + 3 = 18$$$. As $$$18$$$ is divisible by $$$2$$$ while $$$17703$$$ is not divisible by $$$2$$$, we can see that $$$17703$$$ is an ebne number. Same with $$$77013$$$ and $$$17013$$$; $$$1 + 7 + 0 + 1 = 9$$$. Because $$$9$$$ is not divisible by $$$2$$$, $$$1701$$$ is not an ebne number; $$$7 + 7 + 0 = 14$$$. This time, $$$14$$$ is divisible by $$$2$$$ but $$$770$$$ is also divisible by $$$2$$$, therefore, $$$770$$$ is not an ebne number.In the last test case of the example, one of many other possible answers is given. Another possible answer is: 222373204424185217171912 $$$\rightarrow$$$ 22237320442418521717191 (delete the last digit).

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t= trim(fgets($handle));

for($j=0;$j<$t;$j++)
{
    $n= trim(fgets($handle));
    $s= trim(fgets($handle));
    $sum=0;
    if($n==1){echo '-1'."\n";}
    else {
        $str='';$check=0;$ch=false;
       for ($i=0;$i<$n;$i++)
       {
           if($s[$i]%2!=0)
           {$str.=$s[$i];$sum=$sum+(int)$s[$i];$check++;}

           if($sum%2==0 && $check>1){$ch=true;break;}
       }
       if($ch)
       {
           echo $str."\n";
       }
       else
       {
           echo '-1'."\n";
       }
    }
}

?>

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t= trim(fgets($handle));

for($j=0;$j<$t;$j++)
{
    $n= trim(fgets($handle));
    $s= trim(fgets($handle));
    $sum=0;
    if($n==1){echo '-1'."\n";}
    else {
        $str='';$check=0;
       for ($i=0;$i<$n;$i++)
       {
           if($s[$i]%2!=0)
           {echo $s[$i];$str.=$s[$i];$sum=$sum+(int)$s[$i];$check++;}

           if($sum%2==0 && $check>1){break;}
       }
       echo "\n";
    }
}

?>

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t= trim(fgets($handle));

for($j=0;$j<$t;$j++)
{
    $n= trim(fgets($handle));
    $s= trim(fgets($handle));
    $sum=0;
    if($n==1){echo '-1'."\n";}
    else {
        for ($i = 0; $i < $n; $i++) $sum += (int)$s[$i];
       $str=$s;
       for ($i=$n-1;$i>0;$i--)
       {
           //var_dump($str);
           if($str[$i]%2!=0)
           {
               if($sum%2==0)
               {
                   echo substr($str, 0,$i+1)."\n";
                   break;
               }
               else
               {
                   $sum=$sum-$str[$i];
                   $str=substr($str, 0,$i);
               }
           }else
           {
               $sum=$sum-$str[$i];
               $str=substr($str, 0,$i);

           }

       }
    }
}

?>

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t= trim(fgets($handle));

for($j=0;$j<$t;$j++)
{
    $n= trim(fgets($handle));
    $s= trim(fgets($handle));
    $sum=0;
    if($n==1){echo '-1'."\n";}
    else {
        for ($i = 0; $i < $n; $i++) $sum += (int)$s[$i];
       $str=$s;
       for ($i=$n-1;$i>0;$i--)
       {
           var_dump($str);
           if($str[$i]%2!=0)
           {
               if($sum%2==0)
               {
                   echo substr($str, 0,$i+1)."\n";
                   break;
               }
               else
               {
                   $sum=$sum-$str[$i];
                   $str=substr($str, 0,$i);
               }
           }else
           {
               $sum=$sum-$str[$i];
               $str=substr($str, 0,$i);

           }

       }
    }
}

?>


Levko loves permutations very much. A permutation of length n is a sequence of distinct positive integers, each is at most n.Let’s assume that value gcd(a, b) shows the greatest common divisor of numbers a and b. Levko assumes that element pi of permutation p1, p2, ... , pn is good if gcd(i, pi) > 1. Levko considers a permutation beautiful, if it has exactly k good elements. Unfortunately, he doesn’t know any beautiful permutation. Your task is to help him to find at least one of them.

The single line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ n).

In a single line print either any beautiful permutation or -1, if such permutation doesn’t exist. If there are multiple suitable permutations, you are allowed to print any of them.

NoteIn the first sample elements 4 and 3 are good because gcd(2, 4) = 2 > 1 and gcd(3, 3) = 3 > 1. Elements 2 and 1 are not good because gcd(1, 2) = 1 and gcd(4, 1) = 1. As there are exactly 2 good elements, the permutation is beautiful.The second sample has no beautiful permutations.


You play your favourite game yet another time. You chose the character you didn't play before. It has $$$str$$$ points of strength and $$$int$$$ points of intelligence. Also, at start, the character has $$$exp$$$ free experience points you can invest either in strength or in intelligence (by investing one point you can either raise strength by $$$1$$$ or raise intelligence by $$$1$$$).Since you'd like to make some fun you want to create a jock character, so it has more strength than intelligence points (resulting strength is strictly greater than the resulting intelligence).Calculate the number of different character builds you can create (for the purpose of replayability) if you must invest all free points. Two character builds are different if their strength and/or intellect are different.

The first line contains the single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Next $$$T$$$ lines contain descriptions of queries — one per line. This line contains three integers $$$str$$$, $$$int$$$ and $$$exp$$$ ($$$1 \le str, int \le 10^8$$$, $$$0 \le exp \le 10^8$$$) — the initial strength and intelligence of the character and the number of free points, respectively.

Print $$$T$$$ integers — one per query. For each query print the number of different character builds you can create.

NoteIn the first query there are only three appropriate character builds: $$$(str = 7, int = 5)$$$, $$$(8, 4)$$$ and $$$(9, 3)$$$. All other builds are either too smart or don't use all free points.In the second query there is only one possible build: $$$(2, 1)$$$.In the third query there are two appropriate builds: $$$(7, 6)$$$, $$$(8, 5)$$$.In the fourth query all builds have too much brains.


Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers.During the game the host takes numbered balls one by one from a bag. He reads the number aloud in a high and clear voice and then puts the ball away. All participants cross out the number if it occurs on their cards. The person who crosses out all numbers from his card first, wins. If multiple people cross out all numbers from their cards at the same time, there are no winners in the game. At the beginning of the game the bag contains 100 balls numbered 1 through 100, the numbers of all balls are distinct.You are given the cards for each player. Write a program that determines whether a player can win the game at the most favorable for him scenario or not.

The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of the players. Then follow n lines, each line describes a player's card. The line that describes a card starts from integer mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, 2, ..., ai, mi (1 ≤ ai, k ≤ 100) — the numbers on the i-th player's card. The numbers in the lines are separated by single spaces. It is guaranteed that all the numbers on each card are distinct.

Print n lines, the i-th line must contain word "YES" (without the quotes), if the i-th player can win, and "NO" (without the quotes) otherwise.

<? $f = file('php://stdin',FILE_IGNORE_NEW_LINES);
define('L',PHP_EOL);
//-----------------------

array_shift($f);

foreach ($f as $p) {
	$p = explode(' ',$p);
	array_shift($p);

	$player[] = $p;
}

$player_c = $player;

foreach ($player as $i=>$poll) {

	$turns = sizeof($poll);

	$res = 'YES';

	foreach ($player_c as $j=>$c) if ($i!=$j) {
		$x = 0;

		foreach ($poll as $p) {
			if (($index = array_search($p,$c))!==false) {
				$x++;
				unset($c[$index]);

				if (!$c) {
					break;
				}
			}
		}

		if (!$c && $x && $x<=$turns) {
			$res = 'NO';
			break;
		}
	}

	$result[] = $res;
}

echo implode(L,$result);

<? $f = file('php://stdin',FILE_IGNORE_NEW_LINES);
define('L',PHP_EOL);
//-----------------------

array_shift($f);

foreach ($f as $p) {
	$p = explode(' ',$p);
	array_shift($p);

	$player[] = $p;
}

$player_c = $player;

foreach ($player as $i=>$poll) {

	$turns = sizeof($poll);

	$res = 'YES';

	foreach ($player_c as $j=>$c) if ($i!=$j) {
		$first = current($c);
		$x = 0;

		foreach ($poll as $p) {
			if ($p==$first) {
				$x++;
				array_shift($c);

				if ($c) {
					$first = current($c);
				} else {
					break;
				}
			}
		}
		if (!$c && $x && $x<=$turns) {
			$res = 'NO';
			break;
		}
	}

	$result[] = $res;
}

echo implode(L,$result);


Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second — from a2 to b2What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.

The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi).

Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = array();
$d = array();
for($x = 1; $x <= $a; $x++)
{
    list($e, $f) = explode(" ", trim(fgets(STDIN)));
    $g = max($e, $f);
    $h = min($e, $f);
    array_push($c, $g);
    array_push($d, $h);
}
rsort($d);
sort($c);
if($c[0] >= $d[0])
{
    if($b > $c[0])
    {
        print $b - $c[0];
    }
    elseif($b < $d[0])
    {
        print $d[0] - $b;
    }
    else
    {
        print "0";
    }
}
else
{
    print "-1";
}
?>

<?php

$in = 'php://stdin';
//$in = 'input.txt';

$arr = file($in);
//$data = file_get_contents($in);
//$r = fopen($in, 'r');

list($n, $x0) = explode(' ', array_shift($arr));

$n = intval($n);
$x0 = intval($x0);

while (!trim($arr[count($arr) - 1])) {
	array_pop($arr);
}

for ($i = 0; $i < $n ; $i++) {
	$value = $arr[$i];
	$vals = explode(' ', trim($value));
	sort($vals, SORT_NUMERIC);
	$min = intval(array_shift($vals));
	$max = intval(array_shift($vals));
//	echo "$min $max\n";
	$supermin = isset($supermin) ? ($min > $supermin ? $min : $supermin) : $min;
	$supermax = isset($supermax) ? ($max < $supermax ? $max : $supermax) : $max;
}
//echo "\n";

echo $supermax < $supermin ? '-1' : (($x0 <= $supermax && $x0 >= $supermin ? 0 : min(abs($x0 - $supermin), abs($x0 - $supermax))));

//fclose($r);

<?php
list($n,$m)=explode(' ',rtrim(fgets(STDIN)));
$min_x=$min_y=100;
$max_x=$max_y=-1;
$letter=array();
for ($i=0;$i<$n;$i++) {
  $line=rtrim(fgets(STDIN));
  $letter[]=$line;
  for ($j=0;$j<$m;$j++) {
    if ($line[$j]=='*') {
      $min_x=min($min_x,$j);
      $min_y=min($min_y,$i);
      $max_x=max($max_x,$j);
      $max_y=max($max_y,$i);
    }
  }
}
for ($i=$min_y;$i<=$max_y;$i++) {
  for ($j=$min_x;$j<=$max_x;$j++) {
    echo $letter[$i][$j];
  }
  echo "\n";
}
?>

<?php

$in = 'php://stdin';
//$in = 'input.txt';

$arr = file($in);
//$data = file_get_contents($in);
//$r = fopen($in, 'r');

list($n, $x0) = explode(' ', array_shift($arr));

while (!trim($arr[count($arr) - 1])) {
	array_pop($arr);
}

for ($i = 0; $i < $n ; $i++) {
	$value = $arr[$i];
	$vals = explode(' ', trim($value));
	sort($vals, SORT_NUMERIC);
	$min = intval(array_shift($vals));
	$max = intval(array_shift($vals));
//	echo "$min $max\n";
	$supermin = isset($supermin) ? ($min > $supermin ? $min : $supermin) : $min;
	$supermax = isset($supermax) ? ($max < $supermax ? $max : $supermax) : $max;
}
//echo "\n";
//echo "$supermin $supermax\n";

echo $supermax < $supermin ? '-1' : min(abs($x0 - $supermin), abs($x0 - $supermax));

//fclose($r);

<?php

$in = 'php://stdin';
//$in = 'input.txt';

$arr = file($in);
//$data = file_get_contents($in);
//$r = fopen($in, 'r');

list($n, $x0) = explode(' ', array_shift($arr));

while (!trim($arr[count($arr) - 1])) {
	array_pop($arr);
}

foreach ($arr as $value) {
	$vals = explode(' ', trim($value));
	sort($vals, SORT_NUMERIC);
	$min = intval(array_shift($vals));
	$max = intval(array_shift($vals));
//	echo "$min $max\n";
	$supermin = isset($supermin) ? ($min > $supermin ? $min : $supermin) : $min;
	$supermax = isset($supermax) ? ($max < $supermax ? $max : $supermax) : $max;
}
//echo "\n";
//echo "$supermin $supermax\n";

echo $supermax < $supermin ? '-1' : min(abs($x0 - $supermin), abs($x0 - $supermax));

//fclose($r);

<?php

$in = 'php://stdin';
//$in = 'input.txt';

$arr = file($in);
//$data = file_get_contents($in);
//$r = fopen($in, 'r');

list($n, $x0) = explode(' ', array_shift($arr));

while (!$arr[count($arr) - 1]) {
	array_pop($arr);
}

foreach ($arr as $value) {
	$vals = explode(' ', $value);
	sort($vals, SORT_NUMERIC);
	$min = intval(array_shift($vals));
	$max = intval(array_shift($vals));

	$supermin = isset($supermin) ? ($min > $supermin ? $min : $supermin) : $min;
	$supermax = isset($supermax) ? ($max < $supermax ? $max : $supermax) : $max;
}

echo $supermax < $supermin ? '-1' : min(abs($x0 - $supermin), abs($x0 - $supermax));

//fclose($r);


Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to learn those letters. That's why he decided to lose some part of the string (not necessarily a connected part). The lost part can consist of any number of segments of any length, at any distance from each other. However, Gerald knows that if he loses more than k characters, it will be very suspicious. Find the least number of distinct characters that can remain in the string after no more than k characters are deleted. You also have to find any possible way to delete the characters.

The first input data line contains a string whose length is equal to n (1 ≤ n ≤ 105). The string consists of lowercase Latin letters. The second line contains the number k (0 ≤ k ≤ 105).

Print on the first line the only number m — the least possible number of different characters that could remain in the given string after it loses no more than k characters. Print on the second line the string that Gerald can get after some characters are lost. The string should have exactly m distinct characters. The final string should be the subsequence of the initial string. If Gerald can get several different strings with exactly m distinct characters, print any of them.

NoteIn the first sample the string consists of five identical letters but you are only allowed to delete 4 of them so that there was at least one letter left. Thus, the right answer is 1 and any string consisting of characters "a" from 1 to 5 in length.In the second sample you are allowed to delete 4 characters. You cannot delete all the characters, because the string has length equal to 7. However, you can delete all characters apart from "a" (as they are no more than four), which will result in the "aaaa" string.In the third sample you are given a line whose length is equal to 8, and k = 10, so that the whole line can be deleted. The correct answer is 0 and an empty string.

<?php

//$src = 'input.txt';
$src = 'php://stdin';

$data = file($src);
//$data = array('aaaaa', '4');

$str = trim(array_shift($data));
$k = $num = (int) array_shift($data);

$cnt = array_count_values(str_split($str));
asort($cnt);

$letters = array();
while ($k > 0 && $cnt) {
	$m = current($cnt);
	if ($k >= $m) {
		$letters[key($cnt)] = true;
		$k -= $m;
		array_shift($cnt);
	} else {
		$k = 0;
	}
}
echo count($cnt) . PHP_EOL;
if (!count($cnt)) {
	exit;
}
$removed = 0;
for ($i = 0; $i < strlen($str); $i++) {
	if (isset($letters[$str{$i}]) && $removed < $num) {
		$removed++;
	} else {
		echo $str{$i};
	}
}

<?php

//$src = 'input.txt';
$src = 'php://stdin';

$data = file($src);
//$data = array('aaaaa', '4');

$str = trim(array_shift($data));
$k = $num = (int) array_shift($data);

$cnt = array_count_values(str_split($str));
asort($cnt);

$letters = array();
while ($k > 0 && $cnt) {
	$m = current($cnt);
	if ($k > $m) {
		$letters[key($cnt)] = true;
		$k -= $m;
		array_shift($cnt);
	} else {
		$k = 0;
	}
}
echo count($cnt) . PHP_EOL;
if (!count($cnt)) {
	exit;
}
$removed = 0;
for ($i = 0; $i < strlen($str); $i++) {
	if (isset($letters[$str{$i}]) && $removed < $num) {
		$removed++;
	} else {
		echo $str{$i};
	}
}

<?php

//$src = 'input.txt';
$src = 'php://input';

$data = file($src);
//$data = array('aaaaa', '4');

$str = trim(array_shift($data));
$k = $num = (int) array_shift($data);

$cnt = array_count_values(str_split($str));
sort($cnt);

$letters = array();
while ($k > 0 && $cnt) {
	$letters[key($cnt)] = true;
	$k -= array_shift($cnt);
}
echo count($cnt) . PHP_EOL;
if (!count($cnt)) {
	exit;
}
$removed = 0;
for ($i = 0; $i < strlen($str); $i++) {
	if (isset($letters[$str{$i}]) && $removed < $num) {
		$removed++;
	} else {
		echo $str{$i};
	}
}

<?php

//$src = 'input.txt';
$src = 'php://input';

//$data = file($src);
$data = array('aaaaa', '4');

$str = trim(array_shift($data));
$k = $num = (int) array_shift($data);

$cnt = array_count_values(str_split($str));
sort($cnt);

$letters = array();
while ($k > 0 && $cnt) {
	$letters[key($cnt)] = true;
	$k -= array_shift($cnt);
}
echo count($cnt) . PHP_EOL;
if (!count($cnt)) {
	exit;
}
$removed = 0;
for ($i = 0; $i < strlen($str); $i++) {
	if (isset($letters[$str{$i}]) && $removed < $num) {
		$removed++;
	} else {
		echo $str{$i};
	}
}