After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.

The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109). Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place.

Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.

NoteConsider the first sample.  Initially Kay and Gerda have 7 packs of ice cream.  Carrier brings 5 more, so now they have 12 packs.  A kid asks for 10 packs and receives them. There are only 2 packs remaining.  Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.  Carrier bring 40 packs, now Kay and Gerda have 42 packs.  Kid asks for 20 packs and receives them. There are 22 packs remaining.

<?php

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

fscanf($stdin, "%d %d" , $n , $x ) ;
$dist = 0 ;
for( $i=0 ; $i<$n ; $i++ )
{
     fscanf( $stdin , "%s %d" , $s , $m );
     if( $s == "+" )
     {
          $x += $m ;
     }
     else
     {
          if( $m <= $x )
          {
               $x -= $m ;
          }
          else
          {
               $dist++ ;
          }
     }
}
echo $x , " " , $dist ;

fwrite($stdout);

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

?>

<?php
  list($n,$have)=explode(" ",trim(fgets(STDIN)));
 $st=0;
  for($i=0; $i<$n ; $i++){
   list($sign,$val)=explode(" ",trim(fgets(STDIN)));
   if($sign=='+') $have+=$val;

  else{
         if($val<=$have){
             $have-=$val;
         }else{
          $st++;
          }
   }

  }
  echo $have ." ".$st;
?>

<?

function addIce(&$ice_cnt,$count){
	$ice_cnt+=$count;
}

function getIce(&$ice_cnt,$count){
	if($ice_cnt>=$count){
		$ice_cnt-=$count;
		return true;
	}
	return false;
}

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$cards = explode(" ",$s);
$ice_cnt = $cards[1];
$people_cnt=$cards[0];
$sad =0;
while (!feof($stdin)) {

	$s =  trim(fgets($stdin));
	$cards = explode(" ",$s);
	if($cards[0]=="+"){
		addIce($ice_cnt,$cards[1]);
	}elseif($cards[0]=="-"){
		if(!getIce($ice_cnt,$cards[1])){
			$sad+=1;
		}

	}

}

echo $ice_cnt." ".$sad;

<?php
//$in = fopen("input.txt","r");
$in = fopen("php://stdin","r");
list($n,$x) = explode(' ',trim(fgets($in)));
$nds=0;
for($i = 0; $i < $n; $i++)
{
 list($s,$d) = explode(' ',trim(fgets($in)));
 if($s == '-')
 {
   if($d <= $x)
     $x -= $d;
   else
     $nds++;
 }
 else
   $x += $d;
}
echo "$x $nds";


Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of the seats were occupied.The classroom contains $$$n$$$ rows of seats and there are $$$m$$$ seats in each row. Then the classroom can be represented as an $$$n \times m$$$ matrix. The character '.' represents an empty seat, while '*' means that the seat is occupied. You need to find $$$k$$$ consecutive empty seats in the same row or column and arrange those seats for you and your friends. Your task is to find the number of ways to arrange the seats. Two ways are considered different if sets of places that students occupy differs.

The first line contains three positive integers $$$n,m,k$$$ ($$$1 \leq n, m, k \leq 2\,000$$$), where $$$n,m$$$ represent the sizes of the classroom and $$$k$$$ is the number of consecutive seats you need to find. Each of the next $$$n$$$ lines contains $$$m$$$ characters '.' or '*'. They form a matrix representing the classroom, '.' denotes an empty seat, and '*' denotes an occupied seat.

A single number, denoting the number of ways to find $$$k$$$ empty seats in the same row or column.

NoteIn the first sample, there are three ways to arrange those seats. You can take the following seats for your arrangement.   $$$(1,3)$$$, $$$(2,3)$$$  $$$(2,2)$$$, $$$(2,3)$$$  $$$(2,1)$$$, $$$(2,2)$$$

<?php
$line = explode(' ', trim(fgets(STDIN)));
$n = intval($line[0]);
$m = intval($line[1]);
$k = intval($line[2]);
$Gird = [];
for($i = 0; $i < $n; $i++) {
  $Grid[$i] = trim(fgets(STDIN));
}

$rows = 0;
$cols = 0;

for($i = 0 ; $i < $n ; $i++){
  $count_of_pt = 0;
  for($j = 0 ; $j < $m ; $j++){
    if($Grid[$i][$j] == '.'){
      ++$count_of_pt;
    }
    else{
      if($count_of_pt >= $k) $rows += $count_of_pt - $k + 1;
      $count_of_pt = 0;
    }
  }
  if($count_of_pt >= $k) $rows += $count_of_pt - $k + 1;
}
if($k == 1) {
  echo $rows;
  exit;
}
for($j = 0 ; $j < $m ; $j++){
  $count_of_pt = 0;
  for($i = 0 ; $i < $n ; $i++){
    if($Grid[$i][$j] == '.'){
      ++$count_of_pt;
    }
    else{
      if($count_of_pt >= $k) $cols += $count_of_pt - $k + 1;
      $count_of_pt = 0;
    }
  }
  if($count_of_pt >= $k) $cols += $count_of_pt - $k + 1;
}
echo $rows + $cols;

<?php
fscanf(STDIN, '%d %d %d\n', $n, $m, $k);
$Gird = [];
for($i = 0; $i < $n; $i++) {
  $Grid[$i] = trim(fgets(STDIN));
}

$rows = 0;
$cols = 0;
for($i = 0 ; $i < $n ; $i++){
  $count_of_pt = 0;
  for($j = 0 ; $j < $m ; $j++){
    if($Grid[$i][$j] == '.'){
      ++$count_of_pt;
    }
    else{
      if($count_of_pt >= $k) $rows += $count_of_pt - $k + 1;
      $count_of_pt = 0;
    }
  }
  if($count_of_pt >= $k) $rows += $count_of_pt - $k + 1;
}

for($j = 0 ; $j < $m ; $j++){
  $count_of_pt = 0;
  for($i = 0 ; $i < $n ; $i++){
    if($Grid[$i][$j] == '.'){
      ++$count_of_pt;
    }
    else{
      if($count_of_pt >= $k) $cols += $count_of_pt - $k + 1;
      $count_of_pt = 0;
    }
  }
  if($count_of_pt >= $k) $cols += $count_of_pt - $k + 1;
}
echo $rows + $cols;


There is a rectangular grid of n rows of m initially-white cells each.Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that  or , where  denotes intersection of sets, and  denotes the empty set.You are to determine whether a valid sequence of operations exists that produces a given final grid.

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively. Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.

If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes). You can print each character in any case (upper or lower).

NoteFor the first example, the desired setup can be produced by 3 operations, as is shown below.  For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.


There are $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$. For the one move you can choose any even value $$$c$$$ and divide by two all elements that equal $$$c$$$.For example, if $$$a=[6,8,12,6,3,12]$$$ and you choose $$$c=6$$$, and $$$a$$$ is transformed into $$$a=[3,8,12,3,3,12]$$$ after the move.You need to find the minimal number of moves for transforming $$$a$$$ to an array of only odd integers (each element shouldn't be divisible by $$$2$$$).

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. The first line of a test case contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — the number of integers in the sequence $$$a$$$. The second line contains positive integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). The sum of $$$n$$$ for all test cases in the input doesn't exceed $$$2\cdot10^5$$$.

For $$$t$$$ test cases print the answers in the order of test cases in the input. The answer for the test case is the minimal number of moves needed to make all numbers in the test case odd (i.e. not divisible by $$$2$$$).

NoteIn the first test case of the example, the optimal sequence of moves can be as follows:  before making moves $$$a=[40, 6, 40, 3, 20, 1]$$$;  choose $$$c=6$$$;  now $$$a=[40, 3, 40, 3, 20, 1]$$$;  choose $$$c=40$$$;  now $$$a=[20, 3, 20, 3, 20, 1]$$$;  choose $$$c=20$$$;  now $$$a=[10, 3, 10, 3, 10, 1]$$$;  choose $$$c=10$$$;  now $$$a=[5, 3, 5, 3, 5, 1]$$$ — all numbers are odd. Thus, all numbers became odd after $$$4$$$ moves. In $$$3$$$ or fewer moves, you cannot make them all odd.


Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x is a string formed by consecutive segment of characters from x. Two substrings of string x overlap if there is position i in string x occupied by both of them.GukiZ was disappointed because none of his students managed to solve the problem. Can you help them and find one of possible strings k?

The first line contains string a, the second line contains string b, and the third line contains string c (1 ≤ |a|, |b|, |c| ≤ 105, where |s| denotes the length of string s). All three strings consist only of lowercase English letters.  It is possible that b and c coincide.

Find one of possible strings k, as described in the problem statement. If there are multiple possible answers, print any of them.

NoteIn the third sample, this optimal solutions has three non-overlaping substrings equal to either b or c on positions 1 – 2 (ab), 3 – 4 (ab), 5 – 7 (aca). In this sample, there exist many other optimal solutions, one of them would be acaababbcc.

<?php
// 490A     Командная олимпиада
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$a = substr($input_line, 0, strlen($input_line)-2);
$lena = strlen($a);

$input_line = fgets($in);
$b = substr($input_line, 0, strlen($input_line)-2);
$lenb = strlen($b);

$input_line = fgets($in);
$c = substr($input_line, 0, strlen($input_line)-2);
$lenc = strlen($c);

if (($lenb > $lena) and ($lenc > $lena)) {
    echo "$a\n";
    exit;
}

$arr_a = $arr_b = $arr_c = array();

for ($i=0; $i < $lena; $i++) {
    $k = $a[$i];
    $arr_a[$k] ++;
}

for ($i=0; $i < $lenb; $i++) {
    $k = $b[$i];
    $arr_b[$k] ++;
}

for ($i=0; $i < $lenc; $i++) {
    $k = $c[$i];
    $arr_c[$k] ++;
}

$max_b = $lena;
foreach ($arr_b as $key => $value) {
    if (!isset($arr_a[$key]) or ($arr_a[$key] < $value)) {
        $max_b = 0;
        break;
    } elseif ($max_b > intval($arr_a[$key] / $value)) {
        $max_b = intval($arr_a[$key] / $value);
    }
}

$max = 0;
$col_b = $col_c = 0;
$arr_x = $arr_a;
for ($i=0; $i <= $max_b ; $i++) {

    $max_c = $lena;
    foreach ($arr_c as $key => $value) {
        if (!isset($arr_x[$key]) or ($arr_x[$key] < $value)) {
            $max_c = 0;
            break;
        } elseif ($max_c > intval($arr_x[$key] / $value)) {
            $max_c = intval($arr_x[$key] / $value);
        }
    }

    if ($max < ($i + $max_c)) {
        $max = $i + $max_c;
        $col_b = $i;
        $col_c = $max_c;
    }

    foreach ($arr_b as $key => $value) {
        $arr_x[$key] -= $value;
    }
}

$out = '';

for ($i=1; $i <= $col_b ; $i++) {
    $out .= $b;
//    echo "$b";
    foreach ($arr_b as $key => $value) {
        $arr_a[$key] -= $value;
    }
}

for ($i=1; $i <= $col_c ; $i++) {
    $out .= $c;
//    echo "$c";
    foreach ($arr_c as $key => $value) {
        $arr_a[$key] -= $value;
    }
}

foreach ($arr_a as $key => $value) {
    if ($value !== 0) {
        $out .= str_repeat("$key", $value);
//    echo str_repeat("$key", $value);
    }
}

echo "$out\n";

?>

<?php
// 490A     Командная олимпиада
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$a = substr($input_line, 0, strlen($input_line)-2);
$lena = strlen($a);

$input_line = fgets($in);
$b = substr($input_line, 0, strlen($input_line)-2);
$lenb = strlen($b);

$input_line = fgets($in);
$c = substr($input_line, 0, strlen($input_line)-2);
$lenc = strlen($c);

if ($lenb > $lenc) {
    $x = $b;
    $b = $c;
    $c = $x;
    $x = $lenb;
    $lenb = $lenc;
    $lenc = $x;
}

$n = 0;

while ( $n <= $lena ) {

    for ($i=0; $i < $lenb; $i++) {
        $str = substr($a, $n);
        if (strpos ($str, $b[$i]) === false) {
            break;
        }
    }

    if ($i === $lenb) {
        for ($i=0; $i < $lenb; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $b[$i]);
            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $x;
            $n ++;
        }
        continue;
    }

    if ($n >= $lena) {
        break;
    }

    for ($i=0; $i < $lenc; $i++) {
        $str = substr($a, $n);
        if (strpos ($str, $c[$i]) === false) {
            break;
        }
    }

    if ($i === $lenc) {
        for ($i=0; $i < $lenc; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $c[$i]);
            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $x;
            $n ++;
        }
        continue;
    }

    break;
}

echo $a;

?>

<?php
// 490A     Командная олимпиада
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$a = substr($input_line, 0, strlen($input_line)-2);
$lena = strlen($a);

$input_line = fgets($in);
$b = substr($input_line, 0, strlen($input_line)-2);
$lenb = strlen($b);

$input_line = fgets($in);
$c = substr($input_line, 0, strlen($input_line)-2);
$lenc = strlen($c);

if (($lenb > $lena) and ($lenc > $lena)) {
    echo "$a\n";
    exit;
}

$arr_a = $arr_b = $arr_c = array();

for ($i=0; $i < $lena; $i++) {
    $k = $a[$i];
    $arr_a[$k] ++;
}

for ($i=0; $i < $lenb; $i++) {
    $k = $b[$i];
    $arr_b[$k] ++;
}

for ($i=0; $i < $lenc; $i++) {
    $k = $c[$i];
    $arr_c[$k] ++;
}

$max_b = $lena;
foreach ($arr_b as $key => $value) {
    if (!isset($arr_a[$key]) or ($arr_a[$key] < $value)) {
        $max_b = 0;
        break;
    } elseif ($max_b > intval($arr_x[$key] / $value)) {
        $max_b = intval($arr_a[$key] / $value);
    }
}

$max = 0;
$col_b = $col_c = 0;
$arr_x = $arr_a;
for ($i=0; $i <= $max_b ; $i++) {

    $max_c = $lena;
    foreach ($arr_c as $key => $value) {
        if (!isset($arr_x[$key]) or ($arr_x[$key] < $value)) {
            $max_c = 0;
            break;
        } elseif ($max_c > intval($arr_x[$key] / $value)) {
            $max_c = intval($arr_x[$key] / $value);
        }
    }

    if ($max < ($i + $max_c)) {
        $max = $i + $max_c;
        $col_b = $i;
        $col_c = $max_c;
    }

    foreach ($arr_b as $key => $value) {
        $arr_x[$key] -= $value;
    }
}

$out = '';

for ($i=1; $i <= $col_b ; $i++) {
    $out .= $b;
    foreach ($arr_b as $key => $value) {
        $arr_a[$key] -= $value;
    }
}

for ($i=1; $i <= $col_c ; $i++) {
    $out .= $c;
    foreach ($arr_c as $key => $value) {
        $arr_a[$key] -= $value;
    }
}

foreach ($arr_a as $key => $value) {
    if ($value !== 0) {
        $out .= str_repeat("$key", $value);
    }
}

echo "$out\n";

?>

<?php
// 490A     Командная олимпиада
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$a = substr($input_line, 0, strlen($input_line)-2);
$lena = strlen($a);

$input_line = fgets($in);
$b = substr($input_line, 0, strlen($input_line)-2);
$lenb = strlen($b);

$input_line = fgets($in);
$c = substr($input_line, 0, strlen($input_line)-2);
$lenc = strlen($c);

if (($lenb > $lena) or ($lenc > $lena)) {
    echo "$a\n";
    exit;
}

if ($lenb > $lenc) {
    $x = $b;
    $b = $c;
    $c = $x;
    $x = $lenb;
    $lenb = $lenc;
    $lenc = $x;
}

$n = 0;

while ( $n < $lena ) {

    $str = substr($a, $n);
    for ($i=0; $i < $lenb; $i++) {
        if (strpos ($str, $b[$i]) === false) {
            break;
        }
    }

    if ($i === $lenb) {
        for ($i=0; $i < $lenb; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $b[$i]);
            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $b[$i];
            $n ++;
        }
        continue;
    }

    if ($n >= $lena) {
        break;
    }

    $str = substr($a, $n);
    for ($i=0; $i < $lenc; $i++) {
        if (strpos ($str, $c[$i]) === false) {
            break;
        }
    }

    if ($i === $lenc) {
        for ($i=0; $i < $lenc; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $c[$i]);
//            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $c[$i];
            $n ++;
        }
        continue;
    }

    break;
}

echo "$a\n";

?>

<?php
// 490A     Командная олимпиада
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$a = substr($input_line, 0, strlen($input_line)-2);
$lena = strlen($a);

$input_line = fgets($in);
$b = substr($input_line, 0, strlen($input_line)-2);
$lenb = strlen($b);

$input_line = fgets($in);
$c = substr($input_line, 0, strlen($input_line)-2);
$lenc = strlen($c);

if (($lenb > $lena) and ($lenc > $lena)) {
    echo "$a\n";
    exit;
}

$arr_a = $arr_b = $arr_c = array();

for ($i=0; $i < $lena; $i++) {
    $k = $a[$i];
    $arr_a[$k] ++;
}

for ($i=0; $i < $lenb; $i++) {
    $k = $b[$i];
    $arr_b[$k] ++;
}

for ($i=0; $i < $lenc; $i++) {
    $k = $c[$i];
    $arr_c[$k] ++;
}

$max_b = $lena;
foreach ($arr_b as $key => $value) {
    if (!isset($arr_a[$key]) or ($arr_a[$key] < $value)) {
        $max_b = 0;
        break;
    } elseif ($max_b > intval($arr_x[$key] / $value)) {
        $max_b = intval($arr_a[$key] / $value);
    }
}

$max = 0;
$col_b = $col_c = 0;
$arr_x = $arr_a;
for ($i=0; $i <= $max_b ; $i++) {

    $max_c = $lena;
    foreach ($arr_c as $key => $value) {
        if (!isset($arr_x[$key]) or ($arr_x[$key] < $value)) {
            $max_c = 0;
            break;
        } elseif ($max_c > intval($arr_x[$key] / $value)) {
            $max_c = intval($arr_x[$key] / $value);
        }
    }

    if ($max < ($i + $max_c)) {
        $max = $i + $max_c;
        $col_b = $i;
        $col_c = $max_c;
    }

    foreach ($arr_b as $key => $value) {
        $arr_x[$key] -= $value;
    }
}

$out = '';

for ($i=1; $i <= $col_b ; $i++) {
//    $out .= $b;
    echo "$b";
    foreach ($arr_b as $key => $value) {
        $arr_a[$key] -= $value;
    }
}

for ($i=1; $i <= $col_c ; $i++) {
//    $out .= $c;
    echo "$c";
    foreach ($arr_c as $key => $value) {
        $arr_a[$key] -= $value;
    }
}

foreach ($arr_a as $key => $value) {
    if ($value !== 0) {
//        $out .= str_repeat("$key", $value);
    echo str_repeat("$key", $value);
    }
}

echo "$out\n";

?>

<?php
// 490A     Командная олимпиада
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$a = substr($input_line, 0, strlen($input_line)-2);
$lena = strlen($a);

$input_line = fgets($in);
$b = substr($input_line, 0, strlen($input_line)-2);
$lenb = strlen($b);

$input_line = fgets($in);
$c = substr($input_line, 0, strlen($input_line)-2);
$lenc = strlen($c);

if ($lenb > $lenc) {
    $x = $b;
    $b = $c;
    $c = $x;
    $x = $lenb;
    $lenb = $lenc;
    $lenc = $x;
}

$n = 0;

while ( $n <= $lena ) {

    for ($i=0; $i < $lenb; $i++) {
        $str = substr($a, $n);
        if (strpos ($str, $b[$i]) === false) {
            break;
        }
    }

    if ($i === $lenb) {
        for ($i=0; $i < $lenb; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $b[$i]);
            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $x;
            $n ++;
        }
        continue;
    }

    if ($n >= $lena) {
        break;
    }

    for ($i=0; $i < $lenc; $i++) {
        $str = substr($a, $n);
        if (strpos ($str, $c[$i]) === false) {
            break;
        }
    }

    if ($i === $lenc) {
        for ($i=0; $i < $lenc; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $c[$i]);
            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $x;
            $n ++;
        }
        continue;
    }

    break;
}

echo "$a\n";

?>

<?php
// 490A     Командная олимпиада
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$a = substr($input_line, 0, strlen($input_line)-2);
$lena = strlen($a);

$input_line = fgets($in);
$b = substr($input_line, 0, strlen($input_line)-2);
$lenb = strlen($b);

$input_line = fgets($in);
$c = substr($input_line, 0, strlen($input_line)-2);
$lenc = strlen($c);

if (($lenb > $lena) or ($lenc > $lena)) {
    echo "$a\n";
    exit;
}

if ($lenb > $lenc) {
    $x = $b;
    $b = $c;
    $c = $x;
    $x = $lenb;
    $lenb = $lenc;
    $lenc = $x;
}

$n = 0;

while ( $n < $lena ) {

    $str = substr($a, $n);
    for ($i=0; $i < $lenb; $i++) {
        if (strpos ($str, $b[$i]) === false) {
            break;
        }
    }

    if ($i === $lenb) {
        for ($i=0; $i < $lenb; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $b[$i]);
//            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $b[$i];
            $n ++;
        }
        continue;
    }

    if ($n >= $lena) {
        break;
    }

    $str = substr($a, $n);
    for ($i=0; $i < $lenc; $i++) {
        if (strpos ($str, $c[$i]) === false) {
            break;
        }
    }

    if ($i === $lenc) {
        for ($i=0; $i < $lenc; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $c[$i]);
//            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $c[$i];
            $n ++;
        }
        continue;
    }

    break;
}

echo "$a\n";

?>

<?php
// 490A     Командная олимпиада
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$a = substr($input_line, 0, strlen($input_line)-2);
$lena = strlen($a);

$input_line = fgets($in);
$b = substr($input_line, 0, strlen($input_line)-2);
$lenb = strlen($b);

$input_line = fgets($in);
$c = substr($input_line, 0, strlen($input_line)-2);
$lenc = strlen($c);

if ($lenb > $lenc) {
    $x = $b;
    $b = $c;
    $c = $x;
    $x = $lenb;
    $lenb = $lenc;
    $lenc = $x;
}

$flag = true;
$n = 0;

while ( $n <= $lena ) {

    for ($i=0; $i < $lenb; $i++) {
        $str = substr($a, $n);
        if (strpos ($str, $b[$i]) === false) {
            break;
        }
    }

    if ($i === $lenb) {
        for ($i=0; $i < $lenb; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $b[$i]);
            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $x;
            $n ++;
        }
        continue;
    }

    if ($n >= $lena) {
        break;
    }

    for ($i=0; $i < $lenc; $i++) {
        $str = substr($a, $n);
        if (strpos ($str, $c[$i]) === false) {
            break;
        }
    }

    if ($i === $lenc) {
        for ($i=0; $i < $lenc; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $c[$i]);
            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $x;
            $n ++;
        }
        continue;
    }

    break;
}

echo $a;

?>

<?php
// 490A     Командная олимпиада
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$a = substr($input_line, 0, strlen($input_line)-2);
$lena = strlen($a);

$input_line = fgets($in);
$b = substr($input_line, 0, strlen($input_line)-2);
$lenb = strlen($b);

$input_line = fgets($in);
$c = substr($input_line, 0, strlen($input_line)-2);
$lenc = strlen($c);

if (($lenb > $lena) or ($lenc > $lena)) {
    echo "$a\n";
    exit;
}

if ($lenb > $lenc) {
    $x = $b;
    $b = $c;
    $c = $x;
    $x = $lenb;
    $lenb = $lenc;
    $lenc = $x;
}

$n = 0;

while ( $n < $lena ) {

    $str = substr($a, $n);
    for ($i=0; $i < $lenb; $i++) {
        if (strpos ($str, $b[$i]) === false) {
            break;
        }
    }

    if ($i === $lenb) {
        for ($i=0; $i < $lenb; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $b[$i]);
            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $x;
            $n ++;
        }
        continue;
    }

    if ($n >= $lena) {
        break;
    }

    $str = substr($a, $n);
    for ($i=0; $i < $lenc; $i++) {
        if (strpos ($str, $c[$i]) === false) {
            break;
        }
    }

    if ($i === $lenc) {
        for ($i=0; $i < $lenc; $i++) {
            $str = substr($a, $n);
            $pos = strpos ($str, $c[$i]);
            $x = substr($a, $n+$pos, 1);
            $a[$n+$pos] = $a[$n];
            $a[$n] = $x;
            $n ++;
        }
        continue;
    }

    break;
}

echo "$a\n";

?>


You are both a shop keeper and a shop assistant at a small nearby shop. You have $$$n$$$ goods, the $$$i$$$-th good costs $$$a_i$$$ coins.You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More precisely you decided to set the same price for all $$$n$$$ goods you have.However, you don't want to lose any money so you want to choose the price in such a way that the sum of new prices is not less than the sum of the initial prices. It means that if you sell all $$$n$$$ goods for the new price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.On the other hand, you don't want to lose customers because of big prices so among all prices you can choose you need to choose the minimum one.So you need to find the minimum possible equal price of all $$$n$$$ goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 100)$$$ — the number of goods. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^7$$$), where $$$a_i$$$ is the price of the $$$i$$$-th good.

For each query, print the answer for it — the minimum possible equal price of all $$$n$$$ goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     $d = ceil(array_sum($c) / $b);
     print $d . "\n";
}
?>

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $c; $i++){
    list($d) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iAvg = ceil(array_sum($aArray)/count($aArray));
    echo $iAvg . "\n";
}

<?php
$q = intval(fgets(STDIN));
for ($i = 0; $i < $q; $i++) {
    $n = intval(fgets(STDIN));
    $x = array_map('intval', explode(' ', trim(fgets(STDIN))));
    echo intdiv(array_sum($x) + count($x) - 1, count($x)) . PHP_EOL;
}

<?php

while(! feof(STDIN)){
    $arr[]=fgets(STDIN);
}

$k=0;
for($i=0; $i<$arr[0]; $i++){
    $k++;
     $v=explode(" ", $arr[$i+$k+1]);
     echo $result=ceil(array_sum($v)/count($v));
     if($i!=$arr[0]-1) echo "\n";
}

?>

<?php
$a = trim(fgets(STDIN));
for($i = 0; $i < $a; $i++){
    $n = trim(fgets(STDIN));
    $m = explode(' ', trim(fgets(STDIN)));
    $count = 0;
    foreach($m as $v){
        $count += $v;
    }
    echo ceil($count/$n)."\n";
}


You are given an array $$$a_1, a_2, \ldots, a_n$$$.In one operation you can choose two elements $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$) and decrease each of them by one.You need to check whether it is possible to make all the elements equal to zero or not.

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

Print "YES" if it is possible to make all elements zero, otherwise print "NO".

NoteIn the first example, you can make all elements equal to zero in $$$3$$$ operations:   Decrease $$$a_1$$$ and $$$a_2$$$,  Decrease $$$a_3$$$ and $$$a_4$$$,  Decrease $$$a_3$$$ and $$$a_4$$$ In the second example, one can show that it is impossible to make all elements equal to zero.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
$d = max($b);
if($c % 2 != 0)
{
     print "NO";
}
else
{
     if($d > $c - $d)
     {
          print "NO";
     }
     else
     {
          print "YES";
     }
}
?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));
$iSum = array_sum($aArray);
$iMax = max($aArray);
if($iSum % 2 != 0){
    echo "NO";
} else {
    if($iMax > $iSum - $iMax){
        echo "NO";
    } else {
        echo "YES";
    }
}

<?php
	$cin = fopen("php://stdin", "r");
	$n = intval(fgets($cin));
	$s = fgets($cin);
	$a = explode(" ", $s);
	$ans = 0;$k = 0;
	for($i = 0; $i < count($a); $i++){
		$ans = $ans + intval($a[$i]);
		$k = max($k, intval($a[$i]));
	}
	if($ans % 2 == 0 && $k <= $ans - $k){
		print_r("YES");
	}
	else{
		print_r("NO");
	}
	fclose($cin);
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
if($c % 2 == 1)
{
     print "NO";
}
else
{
     rsort($b);
     $d = $b[0];
     $e = 0;
     for($x = 1; $x < $a; $x++)
     {
          $e = bcadd($e, $b[$x]);
     }
     if($d <= $e)
     {
          print "YES";
     }
     else
     {
          print "NO";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = intval(array_sum($b));
$d = max($b);
if($c % 2 == 1)
{
     print "NO";
}
else
{
     if($d > $c - $d)
     {
          print "NO";
     }
     else
     {
          print "YES";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
$d = max($b);
if($c % 2 == "1")
{
     print "NO";
}
else
{
     if($d > $c - $d)
     {
          print "NO";
     }
     else
     {
          print "YES";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
$d = max($b);
if($c % 2 === 1)
{
     print "NO";
}
else
{
     if($d > $c - $d)
     {
          print "NO";
     }
     else
     {
          print "YES";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
if($c % 2 == 1)
{
     print "NO";
}
else
{
     sort($b);
     $d = array_slice($b, 0, -1);
     $e = $b[$a - 1];
     if($e > array_sum($d))
     {
          print "NO";
     }
     else
     {
          print "YES";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
if($c % 2 == 1)
{
     print "NO";
}
else
{
     rsort($b);
     if($b[0] > $c - $b[0])
     {
          print "NO";
     }
     else
     {
          print "YES";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
$d = max($b);
if($c % 2 == 1)
{
     print "NO";
}
else
{
     if($d > $c - $d)
     {
          print "NO";
     }
     else
     {
          print "YES";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
if($c % 2 == 1)
{
     print "NO";
}
else
{
     rsort($b);
     $d = $b[0];
     $e = array_sum(array_slice($b, 1));
     print $d . " " . $e . "\n";
     if($d <= $e)
     {
          print "NO";
     }
     else
     {
          print "YES";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
if($c % 2 == 1)
{
     print "NO";
}
else
{
     rsort($b);
     $d = $b[0];
     $e = $b[1];
     for($x = 2; $x < $a; $x++)
     {
          $e = bcadd($e, $b[$x]);
     }
     if($d > $e)
     {
          print "NO";
     }
     else
     {
          print "YES";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
if($c % 2 == 1)
{
     print "NO";
}
else
{
     rsort($b);
     $d = $b[0];
     $e = array_sum($b) - $d;
     if($d <= $e)
     {
          print "YES";
     }
     else
     {
          print "NO";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
$d = max($b);
if(intval($c) % 2 == 1)
{
     print "NO";
}
else
{
     if($d > $c - $d)
     {
          print "NO";
     }
     else
     {
          print "YES";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
if($c % 2 == 1)
{
     print "NO";
}
else
{
     rsort($b);
     $d = $b[0];
     $e = $b[1];
     for($x = 2; $x < $a; $x++)
     {
          $e = bcadd($e, $b[$x]);
     }
     if($d <= $e)
     {
          print "NO";
     }
     else
     {
          print "YES";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
if($c % 2 == 1)
{
     print "NO";
}
else
{
     rsort($b);
     $d = $b[0];
     $e = array_sum(array_slice($b, 1));
     if($d <= $e)
     {
          print "YES";
     }
     else
     {
          print "NO";
     }
}
?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));
if(array_sum($aArray) % 2 == 0){
    echo "YES";
} else {
    echo "NO";
}


Little penguin Polo adores strings. But most of all he adores strings of length n.One day he wanted to find a string that meets the following conditions:  The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct.  No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si ≠ si + 1(1 ≤ i < n).  Among all strings that meet points 1 and 2, the required string is lexicographically smallest. Help him find such string or state that such string doesn't exist.String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes.

A single line contains two positive integers n and k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26) — the string's length and the number of distinct letters.

In a single line print the required string. If there isn't such string, print "-1" (without the quotes).


Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ ai; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal bi. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises by xi·yi. Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!

The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).

In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.

NoteIn the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.

<?php
error_reporting("off");
//390B: Inna, Dima, and Song
$n = trim(fgets(STDIN));
$a = explode(" ", trim(fgets(STDIN)));
$b = explode(" ", trim(fgets(STDIN)));
$joy = 0;
for ($i = 0; $i < $n; $i++) {
	$max = $a[$i];
	$vol = $b[$i];
	if ($max * 2 >= $vol && $vol > 1) {
		if ($vol % 2 == 0) {
			$tosquare = $vol / 2;
			$joyadd = pow($tosquare, 2);
			$joy += $joyadd;
		} else {
			$down = floor($vol / 2);
			$up = ceil($vol / 2);
			$joy += $up * $down;
		}
	} else {
		$joy--;
	}
}
echo implode(explode(",", number_format($joy, 0)));
?>


Ezzat has an array of $$$n$$$ integers (maybe negative). He wants to split it into two non-empty subsequences $$$a$$$ and $$$b$$$, such that every element from the array belongs to exactly one subsequence, and the value of $$$f(a) + f(b)$$$ is the maximum possible value, where $$$f(x)$$$ is the average of the subsequence $$$x$$$. A sequence $$$x$$$ is a subsequence of a sequence $$$y$$$ if $$$x$$$ can be obtained from $$$y$$$ by deletion of several (possibly, zero or all) elements.The average of a subsequence is the sum of the numbers of this subsequence divided by the size of the subsequence.For example, the average of $$$[1,5,6]$$$ is $$$(1+5+6)/3 = 12/3 = 4$$$, so $$$f([1,5,6]) = 4$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$)— the number of test cases. Each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3\cdot10^5$$$.

For each test case, print a single value — the maximum value that Ezzat can achieve. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$$$.

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    sort($a);
    $b = $c = $d = $x = [];
    $res = 0;
    $key = $n - 1;
    $b = [$a[$key]];
    unset($a[$key]);
    $res = (array_sum($b) / count($b)) + (array_sum($a) / count($a));
    IO::line($res);

}

?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    asort($aArray);
    $aAnswer = [];
    $iMax = max($aArray);
    $iAnswer = (array_sum($aArray) - $iMax)/ (count($aArray) - 1);
    echo $iAnswer + $iMax . "\n";
}

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    sort($a);
    $b = $c = $d = $x = [];
    $res = 0;
    $last = $last2 = 0;
    $bool = true;
    foreach ($a as $v) {
        if ($v < 0) {
            if (isset($b[$v])) {
                $x[$v] = $v;
            } else {
                $last = $v;
                $b[$v] = $v;
            }
        } else {
            if (isset($c[$v])) {
                $d[$v] = $v;
            } else {
                $last2 = $v;
                $c[$v] = $v;
            }
        }
    }
    foreach ($d as $v) {
        $b[$v] = $v;
    }
    foreach ($x as $v) {
        $c[$v] = $v;
    }
    if (count($b) == 0) {
        $b[$last2] = $last2;
        unset($c[$last2]);
    }
    if (count($c) == 0) {
        $c[$last] = $last;
        unset($b[$last]);
    }
    $res = (array_sum($b) / count($b)) + (array_sum($c) / count($c));
    IO::line($res);

}

?>

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

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

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

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    sort($a);
    $b = $c = $d = $x = [];
    $res = 0;
    $last = $last2 = 0;
    $bool = true;
    foreach ($a as $v) {
        if ($v < 0) {
            if (isset($b[$v])) {
                $x[$v] = $v;
            } else {
                $last = $v;
                $b[$v] = $v;
            }
        } else {
            if (isset($c[$v])) {
                $d[$v] = $v;
            } else {
                $last2 = $v;
                $c[$v] = $v;
            }
        }
    }
    if (count($b) % 2 == 1) {
        unset($b[$last]);
        $c[$last] = $last;
    }
    foreach ($d as $v) {
        $b[$v] = $v;
    }
    foreach ($x as $v) {
        $c[$v] = $v;
    }
    if (count($b) == 0) {
        $b[$last2] = $last2;
        unset($c[$last2]);
    }
    if (count($c) == 0) {
        $c[$last] = $last;
        unset($b[$last]);
    }
    $res = (array_sum($b) / count($b)) + (array_sum($c) / count($c));
    IO::line($res);

}

?>


Suppose you are living with two cats: A and B. There are $$$n$$$ napping spots where both cats usually sleep.Your cats like to sleep and also like all these spots, so they change napping spot each hour cyclically:   Cat A changes its napping place in order: $$$n, n - 1, n - 2, \dots, 3, 2, 1, n, n - 1, \dots$$$ In other words, at the first hour it's on the spot $$$n$$$ and then goes in decreasing order cyclically;  Cat B changes its napping place in order: $$$1, 2, 3, \dots, n - 1, n, 1, 2, \dots$$$ In other words, at the first hour it's on the spot $$$1$$$ and then goes in increasing order cyclically. The cat B is much younger, so they have a strict hierarchy: A and B don't lie together. In other words, if both cats'd like to go in spot $$$x$$$ then the A takes this place and B moves to the next place in its order (if $$$x < n$$$ then to $$$x + 1$$$, but if $$$x = n$$$ then to $$$1$$$). Cat B follows his order, so it won't return to the skipped spot $$$x$$$ after A frees it, but will move to the spot $$$x + 2$$$ and so on.Calculate, where cat B will be at hour $$$k$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^9$$$; $$$1 \le k \le 10^9$$$) — the number of spots and hour $$$k$$$.

For each test case, print one integer — the index of the spot where cat B will sleep at hour $$$k$$$.

NoteIn the first and second test cases $$$n = 2$$$, so:   at the $$$1$$$-st hour, A is on spot $$$2$$$ and B is on $$$1$$$;  at the $$$2$$$-nd hour, A moves to spot $$$1$$$ and B — to $$$2$$$.  If $$$n = 3$$$ then:   at the $$$1$$$-st hour, A is on spot $$$3$$$ and B is on $$$1$$$;  at the $$$2$$$-nd hour, A moves to spot $$$2$$$; B'd like to move from $$$1$$$ to $$$2$$$, but this spot is occupied, so it moves to $$$3$$$;  at the $$$3$$$-rd hour, A moves to spot $$$1$$$; B also would like to move from $$$3$$$ to $$$1$$$, but this spot is occupied, so it moves to $$$2$$$. In the sixth test case:   A's spots at each hour are $$$[5, 4, 3, 2, 1]$$$;  B's spots at each hour are $$$[1, 2, 4, 5, 2]$$$.

<?php

$times = (int)trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($ni[], $ki[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $k = &$ki[$idx];
    --$k;
    if ($n % 2) {
        $jump_cnt = floor($n / 2);
        $k += floor($k / $jump_cnt);
    }
    echo $k % $n + 1 . PHP_EOL;
}

<?php

$times = (int)trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    list($ni[], $ki[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $k = &$ki[$idx];
    --$k;
    if ($n % 2) {
        $jump_cicle = floor($n / 2);
        $jump_cnt = floor($k / $jump_cicle);
        echo ($k + $jump_cnt) % $n + 1 . PHP_EOL;
    } else {
        echo $k % $n + 1 . PHP_EOL;
    }
}


According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw n people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks?The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE

The first line contains an integer n (1 ≤ n ≤ 100) which is the number of the bar's clients. Then follow n lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators. Only the drinks from the list given above should be considered alcohol.

Print a single number which is the number of people Vasya should check to guarantee the law enforcement.

NoteIn the sample test the second and fifth clients should be checked.

<?php
$a = trim(fgets(STDIN));
$b = array("ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE");
array_unshift($b, " ");
unset($b[0]);
$e = 0;
for($x = 1; $x <= $a; $x++)
{
    $c = trim(fgets(STDIN));
    $d = array_search($c, $b);
    if(is_numeric($c) == TRUE)
    {
        if($c < 18)
        {
            $e++;
        }
    }
    else
    {
        if($d == TRUE)
        {
            $e++;
        }
    }
}
print $e;
?>

<?php
$str = " ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE ";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  $cnt += preg_match("/ $text /", $str) || (preg_match("/^[0-9]*$/", $text)&&($text<18));
}
echo $cnt;

<?php
$n = (int)trim(fgets(STDIN));
$a = array( "ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE");
$r = 0;
for($i = 0; $i < $n;$i++){
	$t = trim(fgets(STDIN));
	if(is_numeric($t) && intval($t) < 18) $r++;
	elseif(!is_numeric($t) && in_array($t,$a)) $r++;
}
echo $r;

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
$alc=array('ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE');
$count=0;
foreach($arr as $val){
    if(in_array($val,$alc) || (is_numeric($val) && $val<18))
    $count++;
}
echo $count;
?>

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  $text = fgets($handle);
  echo preg_match("/$text/", $str)."\n";
  $cnt += preg_match("$text", $str) || (is_integer($text)&&($text<18));
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  $cnt += preg_match("$text", $str) || ($text<18);
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  $cnt += preg_match("$text", $str) || ((int)$text>=18);
}
echo $cnt;

<?php
$str ="ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf("%s", $text);
  $cnt += preg_match("/$text/", $str) || ((int)$text>=18);
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  $cnt += preg_match("$text", $str) || (is_integer($text) && ($text<18));
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  echo is_integer($text)."\n";
  $cnt += preg_match("$text", $str) || (is_integer($text)&&($text<18));
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  $cnt += preg_match("/$text/", $str) || (preg_match("/^[0-9]*$/", $text)&&($text<18));
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  $cnt += preg_match("/$text/", $str) || (preg_match('/[0-9]/', $str)&&$str<18);
}
echo $cnt;

<?php
$str ="ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  $cnt += preg_match("$text", $str) || ((int)$text>=18);
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  $cnt += preg_match("/$text/", $str) || (preg_match('/[0-9]/', $str)&&$text<18);
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  echo preg_match("/$text/", $str)."\n";
  $cnt += preg_match("$text", $str) || (is_integer($text)&&($text<18));
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  $text = fgets($handle);
  echo "$text is integer ".is_integer($text)."\n";
  $cnt += preg_match("$text", $str) || (is_integer($text)&&($text<18));
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  $cnt += preg_match("/$text/", $str) || (preg_match("/^[0-9]*$/", $str)&&($text<18));
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  echo "$text\n";
  $cnt += preg_match("$text", $str) || ((int)$text>=18);
}
echo $cnt;

<?php
$str = "ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin", "r");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  $text = fgets($handle);
  echo preg_match("$text", $str)."\n";
  $cnt += preg_match("$text", $str) || (is_integer($text)&&($text<18));
}
echo $cnt;

<?php
$str ="ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE";
$handle = fopen("php://stdin");
fscanf($handle, "%d", $n);
$cnt = 0;
while($n--) {
  fscanf($handle, "%s", $text);
  echo "$text\n";
  $cnt += preg_match("$text", $str) || ((int)$text>=18);
}
echo $cnt;

<?php
$n = (int)trim(fgets(STDIN));
$a = array( "ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE");
$r = 0;
for($i = 0; $i < $n;$i++){
	$t = trim(fgets(STDIN));
	if(is_numeric($t) && intval($t) < 18) $r++;
	elseif(!is_numeric($t) && !in_array($t,$a)) $r++;
}
echo $r;

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
$alc=array('ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE');
$count=0;
foreach($arr as $val){
    if(in_array($val,$alc) || ((int)$val<18 &&(int)$val!=0))
    $count++;
}
echo $count;
?>

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
$alc=array('ABSINTH', 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE');
$count=0;
foreach($arr as $val){
    if(in_array($val,$alc) || ((int)$val<18 && (int)$val!=0))
    $count++;
}
echo $count;
?>


As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs.

The first line contains integer n (1 ≤ n ≤ 105) — the number of snowballs. The next line contains n integers — the balls' radii r1, r2, ..., rn (1 ≤ ri ≤ 109). The balls' radii can coincide.

Print on the first line a single number k — the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers — the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them.


Alice has a grid with $$$2$$$ rows and $$$n$$$ columns. She fully covers the grid using $$$n$$$ dominoes of size $$$1 \times 2$$$ — Alice may place them vertically or horizontally, and each cell should be covered by exactly one domino.Now, she decided to show one row of the grid to Bob. Help Bob and figure out what the other row of the grid looks like!

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 5000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the width of the grid. The second line of each test case contains a string $$$s$$$ consisting of $$$n$$$ characters, each of which is either L, R, U, or D, representing the left, right, top, or bottom half of a domino, respectively (see notes for better understanding). This string represents one of the rows of the grid.  Additional constraint on the input: each input corresponds to at least one valid tiling.

For each test case, output one string — the other row of the grid, using the same format as the input string. If there are multiple answers, print any.

NoteIn the first test case, Alice shows Bob the top row, the whole grid may look like:   In the second test case, Alice shows Bob the bottom row, the whole grid may look like:   In the third test case, Alice shows Bob the bottom row, the whole grid may look like:   In the fourth test case, Alice shows Bob the top row, the whole grid may look like:


You are given a string s, consisting of lowercase English letters, and the integer m.One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order.Formally, we choose a subsequence of indices 1 ≤ i1 < i2 < ... < it ≤ |s|. The selected sequence must meet the following condition: for every j such that 1 ≤ j ≤ |s| - m + 1, there must be at least one selected index that belongs to the segment [j,  j + m - 1], i.e. there should exist a k from 1 to t, such that j ≤ ik ≤ j + m - 1.Then we take any permutation p of the selected indices and form a new string sip1sip2... sipt.Find the lexicographically smallest string, that can be obtained using this procedure.

The first line of the input contains a single integer m (1 ≤ m ≤ 100 000). The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string s.

Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.

NoteIn the first sample, one can choose the subsequence {3} and form a string "a".In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".


There are three cells on an infinite 2-dimensional grid, labeled $$$A$$$, $$$B$$$, and $$$F$$$. Find the length of the shortest path from $$$A$$$ to $$$B$$$ if:   in one move you can go to any of the four adjacent cells sharing a side;  visiting the cell $$$F$$$ is forbidden (it is an obstacle).

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Before each test case, there is an empty line. Each test case contains three lines. The first one contains two integers $$$x_A, y_A$$$ ($$$1 \le x_A, y_A \le 1000$$$) — coordinates of the start cell $$$A$$$. The second one contains two integers $$$x_B, y_B$$$ ($$$1 \le x_B, y_B \le 1000$$$) — coordinates of the finish cell $$$B$$$. The third one contains two integers $$$x_F, y_F$$$ ($$$1 \le x_F, y_F \le 1000$$$) — coordinates of the forbidden cell $$$F$$$. All cells are distinct. Coordinate $$$x$$$ corresponds to the column number and coordinate $$$y$$$ corresponds to the row number (see the pictures below).

Output $$$t$$$ lines. The $$$i$$$-th line should contain the answer for the $$$i$$$-th test case: the length of the shortest path from the cell $$$A$$$ to the cell $$$B$$$ if the cell $$$F$$$ is not allowed to be visited.

Note    An example of a possible shortest path for the first test case.     An example of a possible shortest path for the second test case.


You are given an array $$$a_1, a_2, \dots , a_n$$$, which is sorted in non-decreasing order ($$$a_i \le a_{i + 1})$$$. Find three indices $$$i$$$, $$$j$$$, $$$k$$$ such that $$$1 \le i < j < k \le n$$$ and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$ (for example it is possible to construct a non-degenerate triangle with sides $$$3$$$, $$$4$$$ and $$$5$$$ but impossible with sides $$$3$$$, $$$4$$$ and $$$7$$$). If it is impossible to find such triple, report it.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$3 \le n \le 5 \cdot 10^4$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$; $$$a_{i - 1} \le a_i$$$) — the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print the answer to it in one line. If there is a triple of indices $$$i$$$, $$$j$$$, $$$k$$$ ($$$i < j < k$$$) such that it is impossible to construct a non-degenerate triangle having sides equal to $$$a_i$$$, $$$a_j$$$ and $$$a_k$$$, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1.

NoteIn the first test case it is impossible with sides $$$6$$$, $$$11$$$ and $$$18$$$. Note, that this is not the only correct answer.In the second test case you always can construct a non-degenerate triangle.


Casimir has a string $$$s$$$ which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions:  he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the string (these letters don't have to be adjacent);  or he can erase exactly one letter 'B' and exactly one letter 'C' from arbitrary places in the string (these letters don't have to be adjacent). Therefore, each turn the length of the string is decreased exactly by $$$2$$$. All turns are independent so for each turn, Casimir can choose any of two possible actions.For example, with $$$s$$$ $$$=$$$ "ABCABC" he can obtain a string $$$s$$$ $$$=$$$ "ACBC" in one turn (by erasing the first occurrence of 'B' and the second occurrence of 'A'). There are also many other options for a turn aside from this particular example.For a given string $$$s$$$ determine whether there is a sequence of actions leading to an empty string. In other words, Casimir's goal is to erase all letters from the string. Is there a way to do this?

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case is described by one string $$$s$$$, for which you need to determine if it can be fully erased by some sequence of turns. The string $$$s$$$ consists of capital letters 'A', 'B', 'C' and has a length from $$$1$$$ to $$$50$$$ letters, inclusive.

Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be YES if there is a way to fully erase the corresponding string and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answers).

6
ABACAB
ABBA
AC
ABC
CABCBB
BCBCBCBCBCBCBCBC

<?php
$RES = array();
$t = (int)fgets(STDIN);
while($t--)
{
	$str = trim(fgets(STDIN));
	$A = 0;
	$B = 0;
	$C = 0;
	for($i=0; $i<strlen($str); $i++)
	{
		if($str[$i] == "A")
			$A++;
		else if($str[$i] == "B")
			$B++;
		else if($str[$i] == "C")
			$C++;
	}
	if($B - $A == $C)
		array_push($RES, "YES");
	else
		array_push($RES, "NO");
}
foreach($RES as $key => $value)
	print($value."\r\n");
$end = readline();
?>

<?php
$i = trim(fgets(STDIN));
for($x = 1; $x <= $i; $x++)
{
	$s = trim(fgets(STDIN));

	$iA = substr_count($s, 'A');
    $iB = substr_count($s, 'B');
    $iC = substr_count($s, 'C');

    if ($iA + $iC == $iB) {
        echo 'Yes' . PHP_EOL;
    } else {
        echo 'No' . PHP_EOL;
    }
}

<?php

/*
 * Complete the 'fizzBuzz' function below.
 *
 * The function accepts INTEGER n as parameter.
 */

$n = intval(trim(fgets(STDIN)));
for ($i = 1; $i <= $n; $i++) {
    $inp = fgets(STDIN);
    $a = 0; $b = 0; $c = 0;

    $inp = str_split($inp);
    foreach ($inp as $in) {
        if ($in == 'A') $a++;
        if ($in == 'B') $b++;
        if ($in == 'C') $c++;
    }

    if ($b == $a+$c) echo "YES";
    else echo "NO";
    echo "\n";
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($sText) = explode(' ', trim(fgets(STDIN)));
    $aArray = [];
    $aArray["A"] = 0;
    $aArray["B"] = 0;
    $aArray["C"] = 0;
    for ($i = 0; $i < strlen($sText); $i++) {
        $aArray[$sText[$i]] += 1;
    }

//    var_dump($aArray);
    if (($aArray["A"] + $aArray["C"] == $aArray["B"])) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

<?php
$RES = array();
$t = (int)fgets(STDIN);
while($t--)
{
	$str = trim(readline());
	$A = 0;
	$B = 0;
	$C = 0;
	for($i=0; $i<strlen($str); $i++)
	{
		if($str[$i] == "A")
			$A++;
		else if($str[$i] == "B")
			$B++;
		else if($str[$i] == "C")
			$C++;
	}
	if($B - $A == $C)
		array_push($RES, "YES");
	else
		array_push($RES, "NO");
}
foreach($RES as $key => $value)
	print($value."\r\n");
$end = readline();
?>

<?php
$RES = array();
$t = (int)fgets(STDIN);
while($t--)
{
	$str = trim(readline());
	$A = 0;
	$B = 0;
	$C = 0;
	for($i=0; $i<strlen($str); $i++)
	{
		if($str[$i] === 'A')
			$A++;
		else if($str[$i] === 'B')
			$B++;
		else if($str[$i] === 'C')
			$C++;
	}
	if($B - $A == $C)
		array_push($RES, "YES");
	else
		array_push($RES, "NO");
}
foreach($RES as $key => $value)
	print($value."\r\n");
$end = readline();
?>

<?php
$t = (int)fgets(STDIN);
while($t--)
{
	$str = trim(readline());
	$A = 0;
	$B = 0;
	$C = 0;
	for($i=0; $i<strlen($str); $i++)
	{
		if($str[$i] === 'A')
			$A++;
		else if($str[$i] === 'B')
			$B++;
		else if($str[$i] === 'C')
			$C++;
	}
	if($B - $A == $C)
		print("YES\r\n");
	else
		print("NO\r\n");
}
$end = readline();
?>

<?php
$i = trim(fgets(STDIN));
for($x = 1; $x <= $i; $x++)
{
	$s = trim(fgets(STDIN));

	$iA = substr_count($s, 'A');
    $iB = substr_count($s, 'B');
    $iC = substr_count($s, 'C');

    if ($iA == $iB && $iA == $iC) {
        echo 'NO' . PHP_EOL;
    } else if ($iA - $iB > 0 || $iC > 0) {
        echo 'NO' . PHP_EOL;
    } else if ($iC - $iB > 0 || $iA) {
        echo 'NO' . PHP_EOL;
    } else {
        echo 'YES' . PHP_EOL;
    }

}

<?php
$i = trim(fgets(STDIN));
for($x = 1; $x <= $i; $x++)
{
	$s = trim(fgets(STDIN));

	$iA = substr_count($s, 'A');
    $iB = substr_count($s, 'B');
    $iC = substr_count($s, 'C');

    if ($iA == $iB && $iA == $iC) {
        echo 'NO' . PHP_EOL;
    } else if ($iA - $iB > 0) {
        echo 'NO' . PHP_EOL;
    } else if ($iC - $iB > 0) {
        echo 'NO' . PHP_EOL;
    } else {
        echo 'YES' . PHP_EOL;
    }
}


Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.

The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.

Output string s after performing m operations described above.

NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
for($x = 1; $x <= $b; $x++)
{
     list($d, $e, $f, $g) = explode(" ", trim(fgets(STDIN)));
     for($y = $d - 1; $y <= $e - 1; $y++)
     {
          if($c[$y] == $f)
          {
               $c[$y] = $g;
          }
     }
}
print $c;
?>

<?php

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

$input_str = trim(fgets(STDIN));

$result = $input_str;
for ($i = 0; $i < $m; $i++)
{
	list($l, $r, $c1, $c2) = explode(' ', trim(fgets(STDIN)));

	for ($j = $l - 1; $j <= $r - 1; $j++)
	{
		if ($result[$j] === $c1)
		{
			$result[$j] = $c2;
		}
	}
}

echo $result;

<?php

$in = fopen('php://stdin', 'r');
fscanf($in, "%d%d\n", $n, $m);
$string = fread($in, $n);
for ($k = 0; $k < $m; $k++) {
    $result = fscanf($in, "\n%d %d %c %c\n", $from, $to, $needle, $replacement);
    if ($result < 0) {
        $k--;
        continue;
    }
    $from--;
    $to--;
    $string = substr($string, 0, $from) .
              strtr(substr($string, $from, $to - $from + 1), [$needle => $replacement]) .
              substr($string, $to + 1);
}
echo $string, PHP_EOL;


There are $$$n$$$ pieces of cake on a line. The $$$i$$$-th piece of cake has weight $$$a_i$$$ ($$$1 \leq i \leq n$$$).The tastiness of the cake is the maximum total weight of two adjacent pieces of cake (i. e., $$$\max(a_1+a_2,\, a_2+a_3,\, \ldots,\, a_{n-1} + a_{n})$$$).You want to maximize the tastiness of the cake. You are allowed to do the following operation at most once (doing more operations would ruin the cake):   Choose a contiguous subsegment $$$a[l, r]$$$ of pieces of cake ($$$1 \leq l \leq r \leq n$$$), and reverse it. The subsegment $$$a[l, r]$$$ of the array $$$a$$$ is the sequence $$$a_l, a_{l+1}, \dots, a_r$$$.If you reverse it, the array will become $$$a_1, a_2, \dots, a_{l-2}, a_{l-1}, \underline{a_r}, \underline{a_{r-1}}, \underline{\dots}, \underline{a_{l+1}}, \underline{a_l}, a_{r+1}, a_{r+2}, \dots, a_{n-1}, a_n$$$.For example, if the weights are initially $$$[5, 2, 1, 4, 7, 3]$$$, you can reverse the subsegment $$$a[2, 5]$$$, getting $$$[5, \underline{7}, \underline{4}, \underline{1}, \underline{2}, 3]$$$. The tastiness of the cake is now $$$5 + 7 = 12$$$ (while before the operation the tastiness was $$$4+7=11$$$).Find the maximum tastiness of the cake after doing the operation at most once.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 50$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — the number of pieces of cake. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — $$$a_i$$$ is the weight of the $$$i$$$-th piece of cake.

For each test case, print a single integer: the maximum tastiness of the cake after doing the operation at most once.

NoteIn the first test case, after reversing the subsegment $$$a[2, 5]$$$, you get a cake with weights $$$[5, \underline{7}, \underline{4}, \underline{1}, \underline{2}, 3]$$$. The tastiness of the cake is now $$$\max(5+7, 7+4, 4+1, 1+2, 2+3) = 12$$$. This is the maximum possible tastiness of the cake one can obtain by performing the operation at most once.In the second test case, it's optimal not to do any operation. The tastiness is $$$78+78 = 156$$$.In the third test case, after reversing the subsegment $$$a[1, 2]$$$, you get a cake with weights $$$[\underline{54}, \underline{69}, 91]$$$. The tastiness of the cake is now $$$\max(54+69, 69+91) = 160$$$. There is no way to make the tastiness of the cake greater than $$$160$$$ by performing at most one operation.


A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say that the number of the date's occurrences is the number of such substrings in the Prophesy. For example, the Prophesy "0012-10-2012-10-2012" mentions date 12-10-2012 twice (first time as "0012-10-2012-10-2012", second time as "0012-10-2012-10-2012").The date of the Apocalypse is such correct date that the number of times it is mentioned in the Prophesy is strictly larger than that of any other correct date.A date is correct if the year lies in the range from 2013 to 2015, the month is from 1 to 12, and the number of the day is strictly more than a zero and doesn't exceed the number of days in the current month. Note that a date is written in the format "dd-mm-yyyy", that means that leading zeroes may be added to the numbers of the months or days if needed. In other words, date "1-1-2013" isn't recorded in the format "dd-mm-yyyy", and date "01-01-2013" is recorded in it.Notice, that any year between 2013 and 2015 is not a leap year.

The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters.

In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique.

<?php
	$str = fgets(STDIN);

	$months = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	$dates = array();

        $len = strlen($str);

	for ($i = 0; $i + 9 < $len; ++$i) {
                $value = substr($str, $i, 10);
                if (!preg_match("/\d\d-\d\d-201(3|4|5)/", $value))
                    continue;

		$day = intval(substr($value, 0, 2));
		$month = intval(substr($value, 3, 2));

		if ($day > 0 && $month > 0 && $month < 13 && $day <= $months[$month - 1]) {
                        if (array_key_exists($value, $dates))
                            $dates[$value] += 1;
                        else
                            $dates[$value] = intval("1");
                }
	}

	$max = 0;
	$answer = "";
	foreach ($dates as $key => $value) {
		if ($max < $value) {
			$max = $value;
			$answer = $key;
		}
	}

	echo $answer;
?>

<?php
	$time=trim(fgets(STDIN));
	$months=array(31,28,31,30,31,30,31,31,30,31,30,31);
	$len=strlen($time);
	$date=array();
	for($i=0;$i+9<$len;$i++){
		$cur=substr($time,$i,10);
		if(!preg_match("/\d\d-\d\d-201(3|4|5)/",$cur)){
			continue;
		}
		$day=intval(substr($cur,0,2));
		$month=intval(substr($cur,3,2));
		if($month<=12&&$month>0&&$day>0&&$day<=$months[$month-1]){
			if(array_key_exists($cur,$date)){
				$date[$cur]++;
			}
			else $date[$cur]=1;
		}
	}
	$max=0;
	$ans="";
	foreach($date as $key=>$value){
		if($max<$value){
				$max=$value;
				$ans=$key;
			}
	}
	echo $ans.PHP_EOL;
?>


Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor of all numbers from this segment was maximal possible. Help him with that.The xor operation is the bitwise exclusive "OR", that is denoted as "xor" in Pascal and "^" in C/C++/Java.

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.

Print a single integer — the required maximal xor of a segment of consecutive elements.

NoteIn the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one.The second sample contains only one optimal segment, which contains exactly one array element (element with index three).

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

fgets($f);
$nums = explode(" ", fgets($f));

$last = array();
$otr = array();
$max = 0;
for ($i = 0; $i <= count($nums); $i++) {
for ($j = $i; $j <= count($nums); $j++) {
if (!array_search(implode("", $otr), $last)) {
$xor = getxor($otr);
if ($xor > $max) $max = $xor;
}
$otr[] = $nums[$j];
}
$otr = array();
}

echo $max;

function getxor($otr) {
$xor = 0;
foreach ($otr as $num) {
$xor ^= $num;
}
return $xor;
}

<?php

$n = (int) trim(fgets(STDIN));
$nums = array_map('intval', explode(' ', trim(fgets(STDIN))));
$max = 0;
for($i =0; $i<$n; $i++){
    $current = $nums[$i];
    $max_round = $current;
    for($j=$i+1; $j<$n;$j++){
        $current= $current ^ $nums[$j];
        if($current > $max_round){
            $max_round = $current;
        }
    }
    if($max_round > $max){
        $max = $max_round;
    }
}

echo $max;

<?php

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

$max = $res = 0;

    for ($i = 0; $i < $n; $i++)
        for ($j = $i; $j < $n; $j++)
        {
            $res = 0;
            for ($k = $i; $k <= $j; $k++) $res ^= $a[$k];
            if ($res >= $max) $max = $res;
        }
 echo $max;

<?php

$n = (int) trim(fgets(STDIN));
$nums = array_map('intval', explode(' ', trim(fgets(STDIN))));
$max = 0;
for($i =0; $i<$n-1; $i++){
    $current = $nums[$i] ^ $nums[$i+1];
    $max_round = $current;
    for($j=$i+2; $j<$n;$j++){
        $current= $current ^ $nums[$j];
        if($current > $max_round){
            $max_round = $current;
        }
    }
    if($max_round > $max){
        $max = $max_round;
    }
}
echo $max;