The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew.

The first line contains an integer n, which is the number of people in the crew (1 ≤ n ≤ 100). Then follow n lines. The i-th of those lines contains two words — the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain.

Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship.

6
Jack captain
Alice woman
Charlie man
Teddy rat
Bob child
Julia woman

<?php

/*
 * Secdra @2020
 */

class Member
{
    public $name;
    public $category;
    public static $priority = [
        'rat' => 1,
        'woman' => 2,
        'child' => 2,
        'man' => 3,
        'captain' => 4,
    ];

    public function __construct($name, $category)
    {
        $this->name = $name;
        $this->category = self::$priority[$category];
    }
}

fscanf(STDIN, "%d", $n);
$data = [];
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s %s", $name, $category);
    $member = new Member(trim($name), trim($category));
    $data[$member->category][] = $member->name;
}

ksort($data);
foreach ($data as $category => $name) {
    printf("%s\n", implode("\n", $name));
}

<?php
/*
 * Secdra @2020
 */

fscanf(STDIN, "%d", $n);
$data = [];
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s %s", $name, $category);
    if ($category == 'woman' || $category == 'child') $category = 'wc';
    $data[$category][] = $name;
}
if (isset($data['rat'])) {
    foreach ($data['rat'] as $member) {
        printf("%s\n", $member);
    }
}
if (isset($data['wc'])) {
    foreach ($data['wc'] as $member) {
        printf("%s\n", $member);
    }
}
if (isset($data['man'])) {
    foreach ($data['man'] as $member) {
        printf("%s\n", $member);
    }
}
if (isset($data['captain'])) {
    foreach ($data['captain'] as $member) {
        printf("%s\n", $member);
    }
}

<?php
fscanf(STDIN,"%d",$n);
$name=array();
$status=array();
$rat=array();
$womanChild=array();
$man=array();
$captain=array();
$r=0;
$wc=0;
$m=0;
$c=0;
for ($i=0; $i <$n; $i++)
 {
	fscanf(STDIN,"%s %s",$name[$i],$status[$i]);
	if($status[$i]=='rat')
		$rat[$r++]=$name[$i];
	elseif ($status[$i]=='woman'||$status[$i]=='child')
	{
		$womanChild[$wc++]=$name[$i];
	}
	elseif ($status[$i]=='man')
	 {
		$man[$m++]=$name[$i];
	 }
	 else
	 	$captain[$c++]=$name[$i];

 }
 for($i=0;$i<count($rat);$i++)
 echo "$rat[$i]\n";
for($i=0;$i<count($womanChild);$i++)
 echo "$womanChild[$i]\n";
for($i=0;$i<count($man);$i++)
 echo "$man[$i]\n";
for($i=0;$i<count($captain);$i++)
 echo "$captain[$i]\n";

<?php
   fscanf(STDIN, "%d",$s);
    $arreglo1 =array();
    $arreglo2 =array();
    $arreglo3 =array();
    $var;
   for ($i=0; $i <$s ; $i++) {
      fscanf(STDIN, "%s %s",$let1, $let2);
      if($let2=="rat")
      {
         array_push($arreglo1, $let1);
      }
      else if($let2=="woman")
      {
        array_push($arreglo2, $let1);
      }else if($let2=="child")
      {
        array_push($arreglo2, $let1);
      }else if($let2=="man")
      {
        array_push($arreglo3,$let1);
      }else
      {
        $var=$let1;
      }
   }
   foreach ($arreglo1 as $it) {
       echo $it."\n";
   }
   foreach ($arreglo2 as $it) {
       echo $it."\n";
   }
   foreach ($arreglo3 as $it) {
       echo $it."\n";
   }
   echo $var."\n";
 ?>

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

    $rev = array("captain" => "captain", "man" => "man", "rat" => "rat", "woman" => "mid", "child" => "mid");
    $peoples = array("captain" => array(), "man" => array(), "rat" => array(), "mid" => array());

    for ($i = 0; $i < $n; ++$i) {
        $str = trim(fgets(STDIN));
        $strs = split(" ", $str);

        $peoples[$rev[$strs[1]]][] = $strs[0];
    }

    krsort($peoples);
    foreach ($peoples as $key => $value) {
        foreach ($value as $name) {
            echo $name."\n";
        }
    }
?>

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++){
    $arr[]=trim(fgets(STDIN));
}
foreach($arr as $people){
    $a[]=explode(' ',$people);
}
foreach($a as $val){
    if($val[1]=='rat')
        echo $val[0]."\n";
}
foreach($a as $val){
    if($val[1]=='child' || $val[1]=='woman')
        echo $val[0]."\n";
}
foreach($a as $val){
    if($val[1]=='man')
        echo $val[0]."\n";
}
foreach($a as $val){
    if($val[1]=='captain')
        echo $val[0];
}
?>

<?php

$t = trim(fgets(STDIN));

$r = $w = $m = $c = array();
for($i=0;$i<$t;$i++){
 list($n,$p) = explode(' ',trim(fgets(STDIN)));
 switch($p){
  case 'captain': $c[] = $n; break;
  case 'woman': $w[] = $n; break;
  case 'man': $m[] = $n; break;
  case 'child': $w[] = $n; break;
  case 'rat': $r[] = $n; break;
 }
}

foreach($r as $v) print $v."\r\n";
foreach($w as $v) print $v."\r\n";
foreach($m as $v) print $v."\r\n";
foreach($c as $v) print $v."\r\n";

?>

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

$lines=trim($lines);
$lines=explode("\n", $lines);

$rat=array();
$woman_child=array();
$man=array();
$captain="";
$res=array();
for ($i=1; $i<count($lines); $i++)
{
    list ($name, $status)=explode(" ", trim($lines[$i]));
    if ($status=="rat")
        $rat[]=$name;
    if ($status=="woman" or $status=="child")
        $woman_child[]=$name;
    if ($status=="man")
        $man[]=$name;
    if ($status=="captain")
        $captain=$name;
}

foreach($rat as $name)
    $res[]=$name;
foreach($woman_child as $name)
    $res[]=$name;
foreach($man as $name)
    $res[]=$name;
$res[]=$captain;
$res=implode("\n", $res);
echo $res;
?>

<?php

/*
 * Secdra @2020
 */

class Member
{
    public $name;
    public $category;
    public static $priority = [
        'rat' => 1,
        'woman' => 2,
        'child' => 2,
        'man' => 3,
        'captain' => 4,
    ];

    public function __construct($name, $category)
    {
        $this->name = $name;
        $this->category = $category;
    }
}

function cmp($mem1, $mem2)
{
    return Member::$priority[$mem1->category] > Member::$priority[$mem2->category];
}

fscanf(STDIN, "%d", $n);
$data = [];
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s %s", $name, $category);
    $data[] = new Member($name, $category);
}
usort($data, "cmp");
foreach ($data as $member) {
    printf("%s\n", $member->name);
}

<?php
/*
 * Secdra @2020
 */

fscanf(STDIN, "%d", $n);
$data = [];
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s %s", $name, $category);
    $data[$category][] = $name;
}
if (isset($data['rat'])) {
    foreach ($data['rat'] as $member) {
        printf("%s\n", $member);
    }
}
if (isset($data['woman'])) {
    foreach ($data['woman'] as $member) {
        printf("%s\n", $member);
    }
}
if (isset($data['child'])) {
    foreach ($data['child'] as $member) {
        printf("%s\n", $member);
    }
}
if (isset($data['man'])) {
    foreach ($data['man'] as $member) {
        printf("%s\n", $member);
    }
}
if (isset($data['captain'])) {
    foreach ($data['captain'] as $member) {
        printf("%s\n", $member);
    }
}

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++){
	$arr[]=trim(fgets(STDIN));
}
/* $n=6;
$arr=array( 'Jack captain',
			'Alice woman',
			'Charlie man',
			'Teddy rat',
			'Bob child',
			'Julia woman',
			'Kos man'
		); */
foreach($arr as $people){
	$a[]=explode(' ',$people);
}
foreach($a as $val){
	if($val[1]=='rat')
		echo $val[0]."
";
}
foreach($a as $val){
	if($val[1]=='child' || $val[1]=='woman')
		echo $val[0]."
";
}
foreach($a as $val){
	if($val[1]=='man')
		echo $val[0]."
";
}
foreach($a as $val){
	if($val[1]=='captain')
		echo $val[0];
}
?>

<?php

$t = trim(fgets(STDIN));

$r = $w = $m = $c = array();
for($i=0;$i<$t;$i++){
 list($n,$p) = explode(' ',trim(fgets(STDIN)));
 switch($p){
  case 'captain': $c[] = $n; break;
  case 'woman': $w[] = $n; break;
  case 'man': $m[] = $n; break;
  case 'child': $w[] = $n; break;
  case 'rat': $r[] = $n; break;
 }
}

print implode("\r\n",$r)."\r\n".implode("\r\n",$w)."\r\n".implode("\r\n",$m)."\r\n".implode("\r\n",$c);
?>


Permutation $$$p$$$ is a sequence of integers $$$p=[p_1, p_2, \dots, p_n]$$$, consisting of $$$n$$$ distinct (unique) positive integers between $$$1$$$ and $$$n$$$, inclusive. For example, the following sequences are permutations: $$$[3, 4, 1, 2]$$$, $$$[1]$$$, $$$[1, 2]$$$. The following sequences are not permutations: $$$[0]$$$, $$$[1, 2, 1]$$$, $$$[2, 3]$$$, $$$[0, 1, 2]$$$.The important key is in the locked box that you need to open. To open the box you need to enter secret code. Secret code is a permutation $$$p$$$ of length $$$n$$$. You don't know this permutation, you only know the array $$$q$$$ of prefix maximums of this permutation. Formally:  $$$q_1=p_1$$$,  $$$q_2=\max(p_1, p_2)$$$,  $$$q_3=\max(p_1, p_2,p_3)$$$,  ...  $$$q_n=\max(p_1, p_2,\dots,p_n)$$$. You want to construct any possible suitable permutation (i.e. any such permutation, that calculated $$$q$$$ for this permutation is equal to the given array).

The first line contains integer number $$$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 one integer $$$n$$$ $$$(1 \le n \le 10^{5})$$$ — the number of elements in the secret code permutation $$$p$$$. The second line of a test case contains $$$n$$$ integers $$$q_1, q_2, \dots, q_n$$$ $$$(1 \le q_i \le n)$$$ — elements of the array $$$q$$$ for secret permutation. It is guaranteed that $$$q_i \le q_{i+1}$$$ for all $$$i$$$ ($$$1 \le i < n$$$). The sum of all values $$$n$$$ over all the test cases in the input doesn't exceed $$$10^5$$$.

For each test case, print:   If it's impossible to find such a permutation $$$p$$$, print "-1" (without quotes).  Otherwise, print $$$n$$$ distinct integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$). If there are multiple possible answers, you can print any of them.


One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by $$$n$$$ machines, and the power of the $$$i$$$-th machine is $$$a_i$$$. This year 2D decided to cultivate a new culture, but what exactly he didn't say. For the successful growth of the new culture, it is necessary to slightly change the powers of the machines. 2D can at most once choose an arbitrary integer $$$x$$$, then choose one machine and reduce the power of its machine by $$$x$$$ times, and at the same time increase the power of one another machine by $$$x$$$ times (powers of all the machines must stay positive integers). Note that he may not do that if he wants. More formally, 2D can choose two such indices $$$i$$$ and $$$j$$$, and one integer $$$x$$$ such that $$$x$$$ is a divisor of $$$a_i$$$, and change powers as following: $$$a_i = \frac{a_i}{x}$$$, $$$a_j = a_j \cdot x$$$Sasha is very curious, that's why he wants to calculate the minimum total power the farmer can reach. There are too many machines, and Sasha can't cope with computations, help him!

The first line contains one integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^4$$$) — the number of machines. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 100$$$) — the powers of the machines.

Print one integer — minimum total power.

NoteIn the first example, the farmer can reduce the power of the $$$4$$$-th machine by $$$2$$$ times, and increase the power of the $$$1$$$-st machine by $$$2$$$ times, then the powers will be: $$$[2, 2, 3, 2, 5]$$$.In the second example, the farmer can reduce the power of the $$$3$$$-rd machine by $$$2$$$ times, and increase the power of the $$$2$$$-nd machine by $$$2$$$ times. At the same time, the farmer can leave is be as it is and the total power won't change.In the third example, it is optimal to leave it be as it is.


Yaroslav likes algorithms. We'll describe one of his favorite algorithms.  The algorithm receives a string as the input. We denote this input string as a.  The algorithm consists of some number of command. Сommand number i looks either as si >> wi, or as si <> wi, where si and wi are some possibly empty strings of length at most 7, consisting of digits and characters "?".  At each iteration, the algorithm looks for a command with the minimum index i, such that si occurs in a as a substring. If this command is not found the algorithm terminates.  Let's denote the number of the found command as k. In string a the first occurrence of the string sk is replaced by string wk. If the found command at that had form sk >> wk, then the algorithm continues its execution and proceeds to the next iteration. Otherwise, the algorithm terminates.  The value of string a after algorithm termination is considered to be the output of the algorithm. Yaroslav has a set of n positive integers, he needs to come up with his favorite algorithm that will increase each of the given numbers by one. More formally, if we consider each number as a string representing the decimal representation of the number, then being run on each of these strings separately, the algorithm should receive the output string that is a recording of the corresponding number increased by one.Help Yaroslav.

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the set. The next n lines contains one positive integer each. All the given numbers are less than 1025.

Print the algorithm which can individually increase each number of the set. In the i-th line print the command number i without spaces. Your algorithm will be launched for each of these numbers. The answer will be considered correct if:      Each line will a correct algorithm command (see the description in the problem statement).  The number of commands should not exceed 50.  The algorithm will increase each of the given numbers by one.  To get a respond, the algorithm will perform no more than 200 iterations for each number.


Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $$$0$$$ and turn power off at moment $$$M$$$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.The lamp allows only good programs. Good program can be represented as a non-empty array $$$a$$$, where $$$0 < a_1 < a_2 < \dots < a_{|a|} < M$$$. All $$$a_i$$$ must be integers. Of course, preinstalled program is a good program.The lamp follows program $$$a$$$ in next manner: at moment $$$0$$$ turns power and light on. Then at moment $$$a_i$$$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $$$1$$$ and then do nothing, the total time when the lamp is lit will be $$$1$$$. Finally, at moment $$$M$$$ the lamp is turning its power off regardless of its state.Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $$$a$$$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $$$a$$$, or even at the begining or at the end of $$$a$$$.Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $$$x$$$ till moment $$$y$$$, then its lit for $$$y - x$$$ units of time. Segments of time when the lamp is lit are summed up.

First line contains two space separated integers $$$n$$$ and $$$M$$$ ($$$1 \le n \le 10^5$$$, $$$2 \le M \le 10^9$$$) — the length of program $$$a$$$ and the moment when power turns off. Second line contains $$$n$$$ space separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 < a_1 < a_2 < \dots < a_n < M$$$) — initially installed program $$$a$$$.

Print the only integer — maximum possible total time when the lamp is lit.

NoteIn the first example, one of possible optimal solutions is to insert value $$$x = 3$$$ before $$$a_1$$$, so program will be $$$[3, 4, 6, 7]$$$ and time of lamp being lit equals $$$(3 - 0) + (6 - 4) + (10 - 7) = 8$$$. Other possible solution is to insert $$$x = 5$$$ in appropriate place.In the second example, there is only one optimal solution: to insert $$$x = 2$$$ between $$$a_1$$$ and $$$a_2$$$. Program will become $$$[1, 2, 10]$$$, and answer will be $$$(1 - 0) + (10 - 2) = 9$$$.In the third example, optimal answer is to leave program untouched, so answer will be $$$(3 - 0) + (7 - 4) = 6$$$.


You are given two integers $$$a$$$ and $$$b$$$. You may perform any number of operations on them (possibly zero).During each operation you should choose any positive integer $$$x$$$ and set $$$a := a - x$$$, $$$b := b - 2x$$$ or $$$a := a - 2x$$$, $$$b := b - x$$$. Note that you may choose different values of $$$x$$$ in different operations.Is it possible to make $$$a$$$ and $$$b$$$ equal to $$$0$$$ simultaneously?Your program should answer $$$t$$$ independent test cases.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then the test cases follow, each test case is represented by one line containing two integers $$$a$$$ and $$$b$$$ for this test case ($$$0 \le a, b \le 10^9$$$).

For each test case print the answer to it — YES if it is possible to make $$$a$$$ and $$$b$$$ equal to $$$0$$$ simultaneously, 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 answer).

NoteIn the first test case of the example two operations can be used to make both $$$a$$$ and $$$b$$$ equal to zero:  choose $$$x = 4$$$ and set $$$a := a - x$$$, $$$b := b - 2x$$$. Then $$$a = 6 - 4 = 2$$$, $$$b = 9 - 8 = 1$$$;  choose $$$x = 1$$$ and set $$$a := a - 2x$$$, $$$b := b - x$$$. Then $$$a = 2 - 2 = 0$$$, $$$b = 1 - 1 = 0$$$.

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

    for ($i = 0; $i < $n; $i++) {
    list($a, $b) = explode(" ", trim(fgets(STDIN)));

    if ($a==0 || $b ==0) {
        if ($a * 2 == $b) {
            echo "YES\n";
        } else {
             echo "NO\n";
        }
    } else {
        if ($a != $b) {
            if ($a > $b) {
                $max = $a;
                $min = $b;
            } else {
                $max = $b;
                $min = $a;
            }

            $iSum = $max - (($max - $min) * 2);
        } else {
            $iSum = $a;
        }

        if ($iSum >= 0 && $iSum%3 == 0 ) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }

}

?>

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

    for ($i = 0; $i < $n; $i++) {
    list($a, $b) = explode(" ", trim(fgets(STDIN)));
    if ($a == $b && $a ==0) {
        echo "NO\n";
    } else{
    if ($a != $b) {
        if ($a > $b) {
            $max = $a;
            $min = $b;
        } else {
            $max = $b;
            $min = $a;
        }

        $iSum = $max - (($max - $min) * 2);
    } else {
        $iSum = $a;
    }

    if ($iSum%3 == 0) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }}
}

?>

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

    for ($i = 0; $i < $n; $i++) {
        list($a, $b) = explode(" ", trim(fgets(STDIN)));
if ($a != $b) {
    if ($a > $b) {
        $max = $a;
        $min = $b;
    } else {
        $max = $b;
        $min = $a;
    }

    $iSum = $max - (($max - $min) * 2);

} else {
    $iSum = $a;
}

if ($iSum%3 == 0) {
        echo "YES\n";
} else {
        echo "NO\n";
 }
    }

?>

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

    for ($i = 0; $i < $n; $i++) {
    list($a, $b) = explode(" ", trim(fgets(STDIN)));

    if ($a==0 || $b ==0) {
        if ($a * 2 == $b) {
            echo "YES\n";
        } else {
             echo "NO\n";
        }
    } else {
        if ($a != $b) {
            if ($a > $b) {
                $max = $a;
                $min = $b;
            } else {
                $max = $b;
                $min = $a;
            }

            $iSum = $max - (($max - $min) * 2);
        } else {
            $iSum = $a;
        }

        if ($iSum%3 == 0) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }

}

?>

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

    for ($i = 0; $i < $n; $i++) {
        list($a, $b) = explode(" ", trim(fgets(STDIN)));
        if (abs($a - $b) % 2 == 0) {
            echo 'NO'."\n";
        } else {
            echo 'YES'."\n";
        }
    }

?>

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

    for ($i = 0; $i < $n; $i++) {
    list($a, $b) = explode(" ", trim(fgets(STDIN)));
    if ( $a ==0 || $b == 0) {
        echo "NO\n";
    } else{
    if ($a != $b) {
        if ($a > $b) {
            $max = $a;
            $min = $b;
        } else {
            $max = $b;
            $min = $a;
        }

        $iSum = $max - (($max - $min) * 2);
    } else {
        $iSum = $a;
    }

    if ($iSum%3 == 0) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }}
}

?>


An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $$$1$$$. More formally, a sequence $$$s_1, s_2, \ldots, s_{n}$$$ is beautiful if $$$|s_i - s_{i+1}| = 1$$$ for all $$$1 \leq i \leq n - 1$$$.Trans has $$$a$$$ numbers $$$0$$$, $$$b$$$ numbers $$$1$$$, $$$c$$$ numbers $$$2$$$ and $$$d$$$ numbers $$$3$$$. He wants to construct a beautiful sequence using all of these $$$a + b + c + d$$$ numbers.However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?

The only input line contains four non-negative integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 < a+b+c+d \leq 10^5$$$).

If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $$$a + b + c + d$$$ integers, separated by spaces — a beautiful sequence. There should be $$$a$$$ numbers equal to $$$0$$$, $$$b$$$ numbers equal to $$$1$$$, $$$c$$$ numbers equal to $$$2$$$ and $$$d$$$ numbers equal to $$$3$$$. If there are multiple answers, you can print any of them.

NoteIn the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $$$1$$$. Also, there are exactly two numbers, equal to $$$0$$$, $$$1$$$, $$$2$$$ and exactly one number, equal to $$$3$$$.It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.


You are given two even integers $$$n$$$ and $$$m$$$. Your task is to find any binary matrix $$$a$$$ with $$$n$$$ rows and $$$m$$$ columns where every cell $$$(i,j)$$$ has exactly two neighbours with a different value than $$$a_{i,j}$$$.Two cells in the matrix are considered neighbours if and only if they share a side. More formally, the neighbours of cell $$$(x,y)$$$ are: $$$(x-1,y)$$$, $$$(x,y+1)$$$, $$$(x+1,y)$$$ and $$$(x,y-1)$$$.It can be proven that under the given constraints, an answer always exists.

Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The following lines contain the descriptions of the test cases. The only line of each test case contains two even integers $$$n$$$ and $$$m$$$ ($$$2 \le n,m \le 50$$$) — the height and width of the binary matrix, respectively.

For each test case, print $$$n$$$ lines, each of which contains $$$m$$$ numbers, equal to $$$0$$$ or $$$1$$$ — any binary matrix which satisfies the constraints described in the statement. It can be proven that under the given constraints, an answer always exists.

NoteWhite means $$$0$$$, black means $$$1$$$. The binary matrix from the first test caseThe binary matrix from the second test caseThe binary matrix from the third test case


After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each player has an army. Army of the i-th player can be described by non-negative integer xi. Consider binary representation of xi: if the j-th bit of number xi equal to one, then the army of the i-th player has soldiers of the j-th type. Fedor is the (m + 1)-th player of the game. He assume that two players can become friends if their armies differ in at most k types of soldiers (in other words, binary representations of the corresponding numbers differ in at most k bits). Help Fedor and count how many players can become his friends.

The first line contains three integers n, m, k (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000). The i-th of the next (m + 1) lines contains a single integer xi (1 ≤ xi ≤ 2n - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.

Print a single integer — the number of Fedor's potential friends.

<?php
list($n, $m, $k) = explode(" ", trim(fgets(STDIN)));
$b = array();
$imax = 0;
for($i = 0; $i <= $m; $i++){
    $iVal = (int)trim(fgets(STDIN));
    $sBin = "" . decbin($iVal);
    $b[$i] = $sBin;
}

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

    if(strlen($b[$i]) > strlen($b[$m])){
        $sTest = $b[$i];
        $sTest2 = str_pad($b[$m], strlen($b[$i]), "0", STR_PAD_LEFT);
    }else{
        $sTest = str_pad($b[$i], strlen($b[$m]), "0", STR_PAD_LEFT);
        $sTest2 = $b[$m];
    }

    $aTest = str_split($sTest);
    $aTest2 = str_split($sTest2);
    $iRep = 0;
    foreach($aTest2 as $iK => $iV){
        if($aTest[$iK] != $iV ){
            $iRep++;
        }
    }

    if($iRep <= $k){
        $iResult++;
    }
}

echo $iResult;

<?php
// 467B     Федя и новая игра
$in = fopen("php://stdin", 'r');

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

$arr_X = array();
for ($i=1; $i <= $m+1 ; $i++) {
    $input_line = fgets($in);
    $arr_X[$i] = (int) $input_line;
}

$col = 0;
$f = $arr_X[$m+1];

for ($i=1; $i <= $m ; $i++) {
    $x = $arr_X[$i];

    $bit = $x ^ $f;
    $col_bit = 0;
    while ($bit !== 0)  {
        if ($bit == ($bit | 1 )) $col_bit ++;
        $bit = $bit >> 1;
    }

    // echo "x=$x col_bit=$col_bit\n";
    if ($col_bit <= $k) {
        $col ++;
    }
}

echo "$col\n";

?>

<?php
$t = fgets(STDIN);
$t = explode(' ', $t);

// виды солдат
$n = $t[0];
// игроки
$m = $t[1];
// отличие
$k = $t[2];

$i = $m+1;

$sCount = 0;

$aArm = array();
for($j=1;$j<=$i;$j++) {
    $x = fgets(STDIN);
    $x = decbin($x);
    $aArms[$j] = str_pad($x, $n, "0", STR_PAD_LEFT);
    //$x = str_pad($x, $n, "0", STR_PAD_LEFT);
}

$sVedaArm = $aArms[$i];
unset($aArms[$i]);
//echo $sVedaArm."\n";

//print_r($aArms);

foreach($aArms as $sKey => $sArm) {
      $sOtl = 0;
      for($j=0;$j<=$n-1;$j++) {
        if($sArm[$j] != $sVedaArm[$j]) {
            $sOtl++;
        }
      }
      //echo $sOtl."\n";

      if($k >= $sOtl) {
          $sCount++;
      }
}
//echo "\n";
echo $sCount;
?>

<?php
list($n, $m, $k) = explode(" ", trim(fgets(STDIN)));
$b = array();

for($i = 0; $i <= $m; $i++){
    $iVal = (int)trim(fgets(STDIN));
    $sBin = "" . decbin($iVal);
    $a = str_split($sBin);
    $iCount = count(array_keys($a, '1'));

    //echo $iVal . '=' . $sBin . '=' . $iCount . ' ';
    $b[$i] = $iCount;
}

$iResult = 0;
for($i = 0; $i < $m; $i++){
    if(abs($b[$i] - $b[$m]) <= $k){
        $iResult++;
    }
}

echo $iResult;

<?php
$t = fgets(STDIN);
$t = explode(' ', $t);

// виды солдат
$n = $t[0];
// игроки
$m = $t[1];
// отличие
$k = $t[2];

$i = $m+1;

$sCount = 0;

$aArm = array();
for($j=1;$j<=$i;$j++) {
    $x = fgets(STDIN);
    $x = decbin($x);
    $aArms[$j] = sprintf("%0".$n."d", $x);
}

$sVedaArm = $aArms[$i];
unset($aArms[$i]);
//echo $sVedaArm."\n";

//print_r($aArms);

foreach($aArms as $sKey => $sArm) {
      $sOtl = 0;
      for($j=0;$j<=$n-1;$j++) {
        if($sArm[$j] != $sVedaArm[$j]) {
            $sOtl++;
        }
      }
      //echo $sOtl."\n";

      if($k >= $sOtl) {
          $sCount++;
      }
}
//echo "\n";
echo $sCount;
?>

<?php
$t = fgets(STDIN);
$t = explode(' ', $t);

// виды солдат
$n = $t[0];
// игроки
$m = $t[1];
// отличие
$k = $t[2];

$i = $m+1;

$sCount = 0;

$aArm = array();
for($j=1;$j<=$i;$j++) {
    $x = fgets(STDIN);
    $x = decbin($x);
    $aArms[$j] = sprintf("%0".$n."d", $x);
    unset($aArms[$i]);
}

$sVedaArm = $aArms[$i];

foreach($aArms as $j => $sArm) {
      $sOtl = 0;
      for($j=1;$j<=$n;$j++) {
        if($sArm[$j] != $sVedaArm[$j]) {
            $sOtl++;
        }
      }
      //echo $sOtl."\n";

      if($k >= $sOtl) {
          $sCount++;
      }
}
//echo "\n";
echo $sCount;
?>

<?php
$t = fgets(STDIN);
$t = explode(' ', $t);

// виды солдат
$n = $t[0];
// игроки
$m = $t[1];
// отличие
$k = $t[2];

$i = $m+1;

$sCount = 0;

$aArm = array();
for($j=1;$j<=$i;$j++) {
    $x = fgets(STDIN);
    $x = decbin($x);
    $aArms[$j] = sprintf("%0".$n."d", $x);
    unset($aArms[$i]);
}

$sVedaArm = $aArms[$i];

foreach($aArms as $j => $sArm) {
      $sOtl = 0;
      for($j=1;$j<=$n;$j++) {
        if($sArm[$j] != $sVedaArm[$j]) {
            $sOtl++;
        }
      }
      //echo $sOtl."\n";

      if($k >= $sOtl) {
          $sCount++;
      }
}
//echo "\n";
//echo $sCount;
?>

<?php
$t = fgets(STDIN);
$t = explode(' ', $t);

// виды солдат
$n = $t[0];
// игроки
$m = $t[1];
// отличие
$k = $t[2];

$i = $m+1;

$sCount = 0;

$aArm = array();
for($j=1;$j<=$i;$j++) {
    $x = fgets(STDIN);
    $x = decbin($x);
    $aArms[$j] = sprintf("%0".$n."d", $x);
}

$sVedaArm = $aArms[$i];
unset($aArms[$i]);
echo $sVedaArm."\n";

print_r($aArms);

foreach($aArms as $sKey => $sArm) {
      $sOtl = 0;
      for($j=0;$j<=$n-1;$j++) {
        if($sArm[$j] != $sVedaArm[$j]) {
            $sOtl++;
        }
      }
      echo $sOtl."\n";

      if($k >= $sOtl) {
          $sCount++;
      }
}
echo "\n";
echo $sCount;
?>

<?php
$t = fgets(STDIN);
$t = explode(' ', $t);

// виды солдат
$n = $t[0];
// игроки
$m = $t[1];
// отличие
$k = $t[2];

$i = $m+1;

$sCount = 0;

$aArm = array();
for($j=1;$j<=$i;$j++) {
    $x = fgets(STDIN);
    $x = decbin($x);
    $aArms[$j] = sprintf("%0".$n."d", $x);
}

$sVedaArm = $aArms[$i];
unset($aArms[$i]);
//echo $sVedaArm."\n";

//print_r($aArms);

foreach($aArms as $sKey => $sArm) {
      $sOtl = 0;
      for($j=0;$j<=$n;$j++) {
        if($sArm[$j] != $sVedaArm[$j]) {
            $sOtl++;
        }
      }
      //echo $sOtl."\n";

      if($k >= $sOtl) {
          $sCount++;
      }
}
//echo "\n";
echo $sCount;
?>

<?php
$t = fgets(STDIN);
$t = explode(' ', $t);

// виды солдат
$n = $t[0];
// игроки
$m = $t[1];
// отличие
$k = $t[2];

$i = $m+1;

$sCount = 0;

$aArm = array();
for($j=1;$j<=$i;$j++) {
    $x = fgets(STDIN);
    $x = decbin($x);
    $aArms[$j] = sprintf("%0".$n."d", $x);
}

$sVedaArm = $aArms[$i];
foreach($aArms as $j => $sArm) {
  if($sArm != $sVedaArm) {
      $sOtl = 0;
      for($j=1;$j<=$n;$j++) {
        if($sArm[$j] != $sVedaArm[$j]) {
            $sOtl++;
        }
      }
      if($k >= $sOtl) {
          $sCount++;
      }
  }
}

echo $sCount;
?>

<?php
$t = fgets(STDIN);
$t = explode(' ', $t);

// виды солдат
$n = $t[0];
// игроки
$m = $t[1];
// отличие
$k = $t[2];

$i = $m+1;

$sCount = 0;

$aArm = array();
for($j=1;$j<=$i;$j++) {
    $x = fgets(STDIN);
    $x = decbin($x);
    $aArms[$j] = sprintf("%0".$n."d", $x);
}

$sVedaArm = $aArms[$i];
unset($aArms[$i]);

foreach($aArms as $j => $sArm) {
      $sOtl = 0;
      for($j=1;$j<=$n;$j++) {
        if($sArm[$j] != $sVedaArm[$j]) {
            $sOtl++;
        }
      }
      //echo $sOtl."\n";

      if($k >= $sOtl) {
          $sCount++;
      }
}
//echo "\n";
echo $sCount;
?>

<?php
$t = fgets(STDIN);
$t = explode(' ', $t);

// виды солдат
$n = $t[0];
// игроки
$m = $t[1];
// отличие
$k = $t[2];

$i = $m+1;

$sCount = 0;

$aArm = array();
for($j=1;$j<=$i;$j++) {
    $x = fgets(STDIN);
    $x = decbin($x);
    $aArms[$j] = sprintf("%0".$n."d", $x);
}

$sVedaArm = $aArms[$i];
unset($aArms[$i]);
echo $sVedaArm."\n";

print_r($aArms);

foreach($aArms as $sKey => $sArm) {
      $sOtl = 0;
      for($j=0;$j<=$n;$j++) {
        if($sArm[$j] != $sVedaArm[$j]) {
            $sOtl++;
        }
      }
      echo $sOtl."\n";

      if($k >= $sOtl) {
          $sCount++;
      }
}
echo "\n";
echo $sCount;
?>

<?php
$t = fgets(STDIN);
$t = explode(' ', $t);

// виды солдат
$n = $t[0];
// игроки
$m = $t[1];
// отличие
$k = $t[2];

$i = $m+1;

$sCount = 0;

$aArm = array();
for($j=1;$j<=$i;$j++) {
    $x = fgets(STDIN);
    $x = decbin($x);
    $aArms[$j] = sprintf("%0".$n."d", $x);
}

$sVedaArm = $aArms[$i];
unset($aArms[$i]);
//echo $sVedaArm;

//print_r($aArms);

foreach($aArms as $sKey => $sArm) {
      $sOtl = 0;
      for($j=1;$j<=$n;$j++) {
        if($sArm[$j] != $sVedaArm[$j]) {
            $sOtl++;
        }
      }
      //echo $sOtl."\n";

      if($k > $sOtl) {
          $sCount++;
      }
}
//echo "\n";
echo $sCount;
?>

<?php
    list($n, $m, $k) = explode(' ', trim(fgets(STDIN)));
    $arr = array();
    for ($j=1; $j <= $m+1; $j++) {
        $arr[] = trim(fgets(STDIN));
    }

    for ($u=0; $u <= $m; $u++) {
        $dec = $arr[$u];
        $binary = array();
        do{
        if($dec % 2) {
            $binary[] = 1;
        }
        else {
            $binary[] = 0;
        }
        $dec = (int)($dec/2);
        } while ($dec);
        $array[] = $binary;
    }
    $array = array_reverse($array);
    $b = 0;
    for ($i=0; $i < $m; $i++) {
        $l = 0;
        $count = count($array[$m]) - count($array[$i]);
        if(-$k <= $count && $count<= $k) {
            if(count($array[$m]) <= count($array[$i])) {
                for($p=0; $p < count($array[$m]); $p++){
                    if($array[$m][$p] === $array[$i][$p]) {
                        $l++;
                    }
                }
                if(count($array[$i]) - $l <= $k) {
                    $b++;
                }
            } else {
                for($p=0; $p < count($array[$i]); $p++){
                    if($array[$m][$p] === $array[$i][$p]) {
                        $l++;
                    }
                }
                if(count($array[$m]) - $l <= $k) {
                    $b++;
                }
            }
        }
    }

    echo $b;

?>


Polycarp found a rectangular table consisting of $$$n$$$ rows and $$$m$$$ columns. He noticed that each cell of the table has its number, obtained by the following algorithm "by columns":   cells are numbered starting from one;  cells are numbered from left to right by columns, and inside each column from top to bottom;  number of each cell is an integer one greater than in the previous cell. For example, if $$$n = 3$$$ and $$$m = 5$$$, the table will be numbered as follows:$$$$$$ \begin{matrix} 1 & 4 & 7 & 10 & 13 \\ 2 & 5 & 8 & 11 & 14 \\ 3 & 6 & 9 & 12 & 15 \\ \end{matrix} $$$$$$However, Polycarp considers such numbering inconvenient. He likes the numbering "by rows":   cells are numbered starting from one;  cells are numbered from top to bottom by rows, and inside each row from left to right;  number of each cell is an integer one greater than the number of the previous cell. For example, if $$$n = 3$$$ and $$$m = 5$$$, then Polycarp likes the following table numbering: $$$$$$ \begin{matrix} 1 & 2 & 3 & 4 & 5 \\ 6 & 7 & 8 & 9 & 10 \\ 11 & 12 & 13 & 14 & 15 \\ \end{matrix} $$$$$$Polycarp doesn't have much time, so he asks you to find out what would be the cell number in the numbering "by rows", if in the numbering "by columns" the cell has the number $$$x$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case consists of a single line containing three integers $$$n$$$, $$$m$$$, $$$x$$$ ($$$1 \le n, m \le 10^6$$$, $$$1 \le x \le n \cdot m$$$), where $$$n$$$ and $$$m$$$ are the number of rows and columns in the table, and $$$x$$$ is the cell number. Note that the numbers in some test cases do not fit into the $$$32$$$-bit integer type, so you must use at least the $$$64$$$-bit integer type of your programming language.

For each test case, output the cell number in the numbering "by rows".

<?php

$t = readline();

for ($i = 0; $i < $t; $i++) {
    getNumber();
}

function getNumber()
{
    $input = readline();
    list($n, $m, $x) = explode(' ', $input);

    $row = bcadd(bcmod(bcsub($x, 1), $n), 1);
    $col = bcadd(bcdiv(bcsub($x, 1), $n), 1);

    echo bcadd(bcmul(bcsub($row, 1), $m), $col);echo PHP_EOL;
}

<?php

$t = readline();

for ($i = 0; $i < $t; $i++) {
    getNumber();
}

function getNumber()
{
    $input = readline();
    list($n, $m, $x) = explode(' ', $input);

    //$row = (($x - 1) % $n) + 1;
    $row = (bcsub($x, 1) % $n) + 1;
    $col = ceil(bcdiv($x, $n));

    echo bcadd(bcmul($row - 1, $m), $col);echo PHP_EOL;
}

<?php

$t = readline();

for ($i = 0; $i < $t; $i++) {
    getNumber();
}

function getNumber()
{
    $input = readline();
    list($n, $m, $x) = explode(' ', $input);

    $row = (($x - 1) % $n) + 1;
    $col = ceil($x/$n);

    echo ((float)($row - 1) * $m) + $col;echo PHP_EOL;
}

<?php

$t = readline();

for ($i = 0; $i < $t; $i++) {
    getNumber();
}

function getNumber()
{
    $input = readline();
    list($n, $m, $x) = explode(' ', $input);

    $row = (($x - 1) % $n) + 1;
    $col = ceil($x/$n);

    echo ((($row - 1) * $m)) + $col;echo PHP_EOL;
}


You are given three integers $$$a$$$, $$$b$$$, and $$$c$$$. Determine if one of them is the sum of the other two.

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

For each test case, output "YES" if one of the numbers is the sum of the other two, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteIn the first test case, $$$1 + 3 = 4$$$.In the second test case, none of the numbers is the sum of the other two.In the third test case, $$$9 + 11 = 20$$$.

<?php

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

for ($index = 0; $index < $n; $index++)
{
	list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));

	if($a + $b == $c || $a + $c == $b || $b + $c == $a) {
		echo("YES") . PHP_EOL;

		continue;
	}

	echo("NO") . PHP_EOL;
}

<?php

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

while ($t--) {
    [$a, $b, $c] = fscanf(STDIN, '%d %d %d');

    if ($a + $b === $c || $a + $c === $b || $b + $c === $a) {
        echo 'YES' . PHP_EOL;
    } else {
        echo 'NO' . PHP_EOL;
    }
}

<?php

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

for ($index = 0; $index < $n; $index++)
{
	list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));

	if($a + $b == $c || $a + $c == $b || $b + $c == $a) {
		echo("YES");

		continue;
	}

	echo("NO");
}


Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation. For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:  He looks through all the coins from left to right;  If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.  Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence. The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.

The first line contains single integer n (1 ≤ n ≤ 300 000) — number of coins that Sasha puts behind Dima. Second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p1, then coin located at position p2 and so on. Coins are numbered from left to right.

Print n + 1 numbers a0, a1, ..., an, where a0 is a hardness of ordering at the beginning, a1 is a hardness of ordering after the first replacement and so on.

NoteLet's denote as O coin out of circulation, and as X — coin is circulation.At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.XOOO  →  OOOXAfter replacement of the third coin, Dima's actions look this way:XOXO  →  OXOX  →  OOXXAfter replacement of the fourth coin, Dima's actions look this way:XOXX  →  OXXXFinally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.


Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.What is the maximum number of apples he can collect?

The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land. The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it. It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.

Output the maximum number of apples Amr can collect.

NoteIn the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.In the second sample test the optimal solution is to go left to x =  - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x =  - 2.In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.

<?php
$a = trim(fgets(STDIN));
$b = array();
$c = array();
$d = array();
$e = array();
for($x = 0; $x < $a; $x++)
{
    list($f, $g) = explode(" ", trim(fgets(STDIN)));
    if($f < 0)
    {
        array_push($b, $f);
        array_push($c, $g);
    }
    elseif($f > 0)
    {
        array_push($d, $f);
        array_push($e, $g);
    }
}
$h = $b;
arsort($h);
$i = array_keys($h);
$j = array();
for($x = 0; $x < count($b); $x++)
{
    $j[$x] = $c[$i[$x]];
}
$k = $d;
asort($k);
$l = array_keys($k);
$m = array();
for($x = 0; $x < count($d); $x++)
{
    $m[$x] = $e[$l[$x]];
}
if(count($j) < count($m))
{
    $n = array_sum($j);
    $o = array_sum(array_slice($m, 0, count($j) + 1));
    print $n + $o;
}
elseif(count($j) == count($m))
{
    $n = array_sum($j);
    $o = array_sum($m);
    print $n + $o;
}
elseif(count($j) > count($m))
{
    $n = array_sum(array_slice($j, 0, count($m) + 1));
    $o = array_sum($m);
    print $n + $o;
}
?>

<?php
$n = intval(fgets(STDIN));
$arMinus = array();
$arPlus = array();
for ($i=1;$i<=$n;$i++)
{
   $str = trim(fgets(STDIN));
   list($key, $val) = explode(' ', $str);
   if ($key < 0)
    $arMinus[abs($key)] = $val;
    else
    $arPlus[abs($key)] = $val;
}

ksort($arMinus);
ksort($arPlus);

$minCount = (count($arMinus) < count($arPlus)) ? count($arMinus) : count($arPlus);

$rM = reset($arMinus);
$rP = reset($arPlus);

$total = $rM + $rP;

if ($rM > 0 && $rP > 0)
    do
    {
        $nP = next($arPlus);
        $nM = next($arMinus);
        $total = $total + $nP + $nM;
    } while ($nP > 0 && $nM > 0);

echo $total;

<?php
    $n = trim(fgets(STDIN));
    $max_right_length = 0;
    $max_left_length = 0;
    $a_left = array();
    $a_right = array();
    for($i=0;$i<$n;$i++){
        $a = explode(" ", trim(fgets(STDIN)));
        $arr[$a[0]] = $a[1];
        if($a[0] < 0){
            $max_left_length ++;
            $a_left[$a[0]] = $a[1];
        }
        if($a[0] > 0){
            $max_right_length ++;
            $a_right[$a[0]] = $a[1];
        }
    }
    //print_r($a_left);
    ksort($a_left);
    ksort($a_right);
    //print_r($a_left);
    $a_left = array_values($a_left);
    $a_right = array_values($a_right);
    //print_r($a_left);
    //print_r(array_slice($a_right, $max_left_length+1));
    //echo $max_left_length." ".$max_right_length."\n";
    if($max_left_length > $max_right_length){
        $sum = array_sum($a_right) + array_sum(array_slice($a_left, -$max_right_length-1));
        echo $sum+(isset($arr[0]) ? $arr[0] : 0);
    }else if ($max_left_length < $max_right_length) {
        $sum = array_sum($a_left) + array_sum(array_slice($a_right, 0, $max_left_length+1));
        echo $sum+(isset($arr[0]) ? $arr[0] : 0);
    }else{
        echo array_sum($arr);
    }
    echo  "\n";

<?php
$a = trim(fgets(STDIN));
$b = array();
$c = array();
$d = array();
$e = array();
for($x = 0; $x < $a; $x++)
{
    list($f, $g) = explode(" ", trim(fgets(STDIN)));
    if($f < 0)
    {
        array_push($b, $f);
        array_push($c, $g);
    }
    elseif($f > 0)
    {
        array_push($d, $f);
        array_push($e, $g);
    }
}
$h = $b;
arsort($h);
$i = array_keys($h);
$j = array();
for($x = 0; $x < count($b); $x++)
{
    $j[$x] = $c[$i[$x]];
}
$k = $d;
sort($k);
$l = array_keys($k);
$m = array();
for($x = 0; $x < count($d); $x++)
{
    $m[$x] = $e[$l[$x]];
}
if(count($j) < count($m))
{
    $n = array_sum($j);
    $o = array_sum(array_slice($m, 0, count($j) + 1));
    print $n + $o;
}
elseif(count($j) == count($m))
{
    $n = array_sum($j);
    $o = array_sum($m);
    print $n + $o;
}
elseif(count($j) > count($m))
{
    $n = array_sum(array_slice($j, 0, count($m) + 1));
    $o = array_sum($m);
    print $n + $o;
}
?>

$count = trim(fgets(STDIN));
$nom = trim(fgets(STDIN));
var_dump($count, $nom);

$count = trim(fgets(STDIN));
//echo($count);

$cot = fgets(STDIN);
$count = trim(fgets(STDIN));
$elementsStr = trim(fgets(STDIN));
echo "1";

<?php
    $count = trim(fgets(STDIN));
    $nom = explode(" ", trim(fgets(STDIN)));
    var_dump($count, $nom);

$count = trim(fgets(STDIN));
var_dump((int)$count);

$count = trim(fgets(STDIN));
echo((int)$count);

$count = trim(fgets(STDIN));
var_dump($count);

<?php
    $n = trim(fgets(STDIN));
    $max_right_length = 0;
    $max_left_length = 0;
    $a_left = array();
    $a_right = array();
    for($i=0;$i<$n;$i++){
        $a = explode(" ", trim(fgets(STDIN)));
        $arr[$a[0]] = $a[1];
        if($a[0] < 0){
            $max_left_length ++;
            $a_left[$a[0]] = $a[1];
        }
        if($a[0] > 0){
            $max_right_length ++;
            $a_right[$a[0]] = $a[1];
        }
    }
    //print_r($a_left);
    ksort($a_left);
    ksort($a_right);
    //print_r($a_left);
    $a_left = array_values($a_left);
    $a_right = array_values($a_right);
    //print_r($a_left);
    //print_r(array_slice($a_right, $max_left_length+1));
    echo $max_left_length." ".$max_right_length."\n";
    if($max_left_length > $max_right_length){
        $sum = array_sum($a_right) + array_sum(array_slice($a_left, -$max_right_length-1));
        echo $sum+(isset($arr[0]) ? $arr[0] : 0);
    }else if ($max_left_length < $max_right_length) {
        $sum = array_sum($a_left) + array_sum(array_slice($a_right, 0, $max_left_length+1));
        echo $sum+(isset($arr[0]) ? $arr[0] : 0);
    }else{
        echo array_sum($arr);
    }
    echo  "\n";


One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of $$$n$$$ non-negative integers.If there are exactly $$$K$$$ distinct values in the array, then we need $$$k = \lceil \log_{2} K \rceil$$$ bits to store each value. It then takes $$$nk$$$ bits to store the whole file.To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers $$$l \le r$$$, and after that all intensity values are changed in the following way: if the intensity value is within the range $$$[l;r]$$$, we don't change it. If it is less than $$$l$$$, we change it to $$$l$$$; if it is greater than $$$r$$$, we change it to $$$r$$$. You can see that we lose some low and some high intensities.Your task is to apply this compression in such a way that the file fits onto a disk of size $$$I$$$ bytes, and the number of changed elements in the array is minimal possible.We remind you that $$$1$$$ byte contains $$$8$$$ bits.$$$k = \lceil log_{2} K \rceil$$$ is the smallest integer such that $$$K \le 2^{k}$$$. In particular, if $$$K = 1$$$, then $$$k = 0$$$.

The first line contains two integers $$$n$$$ and $$$I$$$ ($$$1 \le n \le 4 \cdot 10^{5}$$$, $$$1 \le I \le 10^{8}$$$) — the length of the array and the size of the disk in bytes, respectively. The next line contains $$$n$$$ integers $$$a_{i}$$$ ($$$0 \le a_{i} \le 10^{9}$$$) — the array denoting the sound file.

Print a single integer — the minimal possible number of changed elements.

NoteIn the first example we can choose $$$l=2, r=3$$$. The array becomes 2 2 2 3 3 3, the number of distinct elements is $$$K=2$$$, and the sound file fits onto the disk. Only two values are changed.In the second example the disk is larger, so the initial file fits it and no changes are required.In the third example we have to change both 1s or both 3s.


Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one looks.Heidi is presented with a screen that shows her a sequence of integers A and a positive integer p. She knows that the encryption code is a single number S, which is defined as follows:Define the score of X to be the sum of the elements of X modulo p.Heidi is given a sequence A that consists of N integers, and also given an integer p. She needs to split A into 2 parts such that:   Each part contains at least 1 element of A, and each part consists of contiguous elements of A.  The two parts do not overlap.  The total sum S of the scores of those two parts is maximized. This is the encryption code. Output the sum S, which is the encryption code.

The first line of the input contains two space-separated integer N and p (2 ≤ N ≤ 100 000, 2 ≤ p ≤ 10 000) – the number of elements in A, and the modulo for computing scores, respectively. The second line contains N space-separated integers which are the elements of A. Each integer is from the interval [1, 1 000 000].

Output the number S as described in the problem statement.

NoteIn the first example, the score is maximized if the input sequence is split into two parts as (3, 4), (7, 2). It gives the total score of .In the second example, the score is maximized if the first part consists of the first three elements, and the second part consists of the rest. Then, the score is .


The Beroil corporation structure is hierarchical, that is it can be represented as a tree. Let's examine the presentation of this structure as follows:  employee ::= name. | name:employee1,employee2, ... ,employeek.  name ::= name of an employee That is, the description of each employee consists of his name, a colon (:), the descriptions of all his subordinates separated by commas, and, finally, a dot. If an employee has no subordinates, then the colon is not present in his description.For example, line MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY... is the correct way of recording the structure of a corporation where the director MIKE has subordinates MAX, ARTEM and DMITRY. ARTEM has a subordinate whose name is MIKE, just as the name of his boss and two subordinates of DMITRY are called DMITRY, just like himself.In the Beroil corporation every employee can only correspond with his subordinates, at that the subordinates are not necessarily direct. Let's call an uncomfortable situation the situation when a person whose name is s writes a letter to another person whose name is also s. In the example given above are two such pairs: a pair involving MIKE, and two pairs for DMITRY (a pair for each of his subordinates).Your task is by the given structure of the corporation to find the number of uncomfortable pairs in it.

The first and single line contains the corporation structure which is a string of length from 1 to 1000 characters. It is guaranteed that the description is correct. Every name is a string consisting of capital Latin letters from 1 to 10 symbols in length.

Print a single number — the number of uncomfortable situations in the company.


Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.

The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.

Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li < ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.

NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.

<?php
$fp = fopen('php://stdin', 'r');
fgets($fp);
$values = array_map('intval', explode(' ', fgets($fp)));
function bubble_sort($arr) {
    $size = count($arr);
    for ($i=0; $i<$size; $i++) {
        for ($j=0; $j<$size-1-$i; $j++) {
            if ($arr[$j+1] < $arr[$j]) {
                swap($arr, $j, $j+1);
            }
        }
    }
    return $arr;
}

function swap(&$arr, $a, $b) {
    $tmp = $arr[$a];
    $arr[$a] = $arr[$b];
    $arr[$b] = $tmp;
	echo ($a+1).' '.($b + 1)."\n";
}

bubble_sort($values);


Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each individual letter all its positions in the string are written out in the increasing order. This results in 26 lists of numbers; some of them can be empty. A string is considered lucky if and only if in each list the absolute difference of any two adjacent numbers is a lucky number. For example, let's consider string "zbcdzefdzc". The lists of positions of equal letters are: b: 2 c: 3, 10 d: 4, 8 e: 6 f: 7 z: 1, 5, 9 Lists of positions of letters a, g, h, ..., y are empty.This string is lucky as all differences are lucky numbers. For letters z: 5 - 1 = 4, 9 - 5 = 4, for letters c: 10 - 3 = 7, for letters d: 8 - 4 = 4. Note that if some letter occurs only once in a string, it doesn't influence the string's luckiness after building the lists of positions of equal letters. The string where all the letters are distinct is considered lucky.Find the lexicographically minimal lucky string whose length equals n.

The single line contains a positive integer n (1 ≤ n ≤ 105) — the length of the sought string.

Print on the single line the lexicographically minimal lucky string whose length equals n.

NoteThe lexical comparison of strings is performed by the < operator in modern programming languages. String a is lexicographically less than string b if exists such i (1 ≤ i ≤ n), that ai < bi, and for any j (1 ≤ j < i) aj = bj.


For an array of non-negative integers $$$a$$$ of size $$$n$$$, we construct another array $$$d$$$ as follows: $$$d_1 = a_1$$$, $$$d_i = |a_i - a_{i - 1}|$$$ for $$$2 \le i \le n$$$.Your task is to restore the array $$$a$$$ from a given array $$$d$$$, or to report that there are multiple possible arrays.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of the arrays $$$a$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$0 \le d_i \le 100$$$) — the elements of the array $$$d$$$. It can be shown that there always exists at least one suitable array $$$a$$$ under these constraints.

For each test case, print the elements of the array $$$a$$$, if there is only one possible array $$$a$$$. Otherwise, print $$$-1$$$.

NoteIn the second example, there are two suitable arrays: $$$[2, 8, 5]$$$ and $$$[2, 8, 11]$$$.

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $d = IO::getArray();
   $ans = '';
   $a = [];
   $a[0][] = $d[0];
   //di=|ai−ai−1|
   //a1 =
   for($i=1; $i<$n; $i++) {
        for($j=0; $j < count($a[$i-1]); $j++) {
             $a[$i] = [];
             $temp = abs($d[$i] - $a[$i-1][$j]);
             if(abs($temp - $a[$i-1][$j]) ==$d[$i] && !in_array($temp, $a[$i])) {
                 $a[$i][] = $temp;
             }

             $temp = $d[$i] + $a[$i-1][$j];
             if(abs($temp - $a[$i-1][$j]) ==$d[$i] && !in_array($temp, $a[$i])) {
                 $a[$i][] = $temp;
             }

        }

   }

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

         }

    IO::pr($ans);
}

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $d = IO::getArray();
   $ans = '';
   $a = [];
   $a[0][] = $d[0];
   //di=|ai−ai−1|
   //a1 =
   for($i=1; $i<$n; $i++) {
        for($j=0; $j < count($a[$i-1]); $j++) {
             $a[$i] = [];
             $temp = abs($d[$i] - $a[$i-1][$j]);
             if(abs($temp - $a[$i-1][$j]) ==$d[$i] && !in_array($temp, $a[$i])) {
                 $a[$i][] = $temp;
             }

             $temp = $d[$i] + $a[$i-1][$j];
             if(abs($temp - $a[$i-1][$j]) ==$d[$i] && !in_array($temp, $a[$i])) {
                 $a[$i][] = $temp;
             }

        }

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

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}


One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B», they stamp it with «A B», or «B A». Unfortunately, often it is impossible to send a letter directly from the city of the sender to the city of the receiver, that's why the letter is sent via some intermediate cities. Post officers never send a letter in such a way that the route of this letter contains some city more than once. Bob is sure that the post officers stamp the letters accurately.There are n stamps on the envelope of Bob's letter. He understands that the possible routes of this letter are only two. But the stamps are numerous, and Bob can't determine himself none of these routes. That's why he asks you to help him. Find one of the possible routes of the letter.

The first line contains integer n (1 ≤ n ≤ 105) — amount of mail stamps on the envelope. Then there follow n lines with two integers each — description of the stamps. Each stamp is described with indexes of the cities between which a letter is sent. The indexes of cities are integers from 1 to 109. Indexes of all the cities are different. Every time the letter is sent from one city to another, exactly one stamp is put on the envelope. It is guaranteed that the given stamps correspond to some valid route from some city to some other city.

Output n + 1 numbers — indexes of cities in one of the two possible routes of the letter.


Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.

The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.  The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.

Output one of the four words without inverted commas:    «forward» — if Peter could see such sequences only on the way from A to B;  «backward» — if Peter could see such sequences on the way from B to A;  «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A;  «fantasy» — if Peter could not see such sequences.

NoteIt is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = strrev($a);
$e = strstr($a, $b);
$f = substr($e, strlen($b));
$g = strstr($f, $c);
$h = strstr($d, $b);
$i = substr($h, strlen($b));
$j = strstr($i, $c);
if(($e && $g) && ($h && $j))
{
    print "both";
}
elseif($e && $g)
{
    print "forward";
}
elseif($h && $j)
{
    print "backward";
}
else
{
    print "fantasy";
}
?>

<?php

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

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

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

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

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

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

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

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

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

	$isForward = false;
	$i1 = strpos($path, $t1);
	if ($i1 !== false && strpos($path, $t2, $i1 + strlen($t1)) !== false) {
		$isForward = true;
	}

	$isBack = false;
	$path = strrev($path);
	$i1 = strpos($path, $t1);
	if ($i1 !== false && strpos($path, $t2, $i1 + strlen($t1)) !== false) {
		$isBack = true;
	}

	if ($isForward && $isBack) {
		echo 'both';
	} elseif ($isForward) {
		echo 'forward';
	} elseif ($isBack) {
		echo 'backward';
	} else {
		echo 'fantasy';
	}
	/* / end body */
}

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

<?php

function debug($data, $die = true) {
    echo '<pre>';

    if (is_array($data)) {
        print_r($data);
    } else {
        var_dump($data);
    }

    if ($die) {
        die();
    }

    echo '</pre>';
}

$stdin = @fopen('data.txt', 'r');
if (!$stdin) {
    $stdin = fopen('php://stdin', 'r');
}

function g() {
    global $stdin;
    return trim(fgets($stdin));
}

/****************************************************** Solving block *****************************************************/
$flags = g();
$first = g();
$second = g();

function find($flags, $first, $second) {
    $str1 = strpos($flags, $first);
    $str2 = strpos($flags, $second, $str1 !== false ? $str1 + strlen($first) : 0);
    return $str1 !== false && $str2 !== false;
}

$forward = find($flags, $first, $second);
$flags = strrev($flags);
$backward = find($flags, $first, $second);

if($forward && $backward) {
    echo 'both';
} else if($forward) {
    echo 'forward';
} else if($backward) {
    echo 'backward';
} else {
    echo 'fantasy';
}

?>

<?php

	$stdin = fopen('php://stdin', 'r');
    $road = trim(fgets($stdin));
    $start = trim(fgets($stdin));
    $end = trim(fgets($stdin));
    $pattern = '/.*'.$start.'.*'.$end.'.*/';
    preg_match($pattern, $road,$forvard);
    preg_match($pattern, strrev($road), $backward);
    if($forvard && $backward)        echo 'both';
    if(!$forvard && !$backward)        echo 'fantasy';
    if($forvard && !$backward)        echo 'forward';
    if(!$forvard && $backward)        echo 'backward';

<?php
$r = trim(fgets(STDIN));
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));

$fo = preg_match('/.*'.$a.'.*'.$b.'.*/',$r);
$ba = preg_match('/.*'.$a.'.*'.$b.'.*/',strrev($r));

if($fo && $ba) $res = 'both';
if($fo && !$ba) $res = 'forward';
if(!$fo && $ba) $res = 'backward';
if(!$fo && !$ba) $res = 'fantasy';

print $res;
?>

<?php
error_reporting("off");
//8A: Train and Peter
$flags = trim(fgets(STDIN)); //$flags = "atob";
$one = trim(fgets(STDIN)); //$one = "a";
$two = trim(fgets(STDIN)); //$two = "b";
$seeforwards = FALSE;
$seebackwards = FALSE;
$length = strlen($one);

if (strpos($flags, $one) !== FALSE) {
    $oneposfor = strpos($flags, $one);
    if (strpos($flags, $two, $oneposfor + $length)) {
        $seeforwards = TRUE;
    }
}

$sgalf = strrev($flags);

if (strpos($sgalf, $one) !== FALSE) {
    $oneposbac = strpos($sgalf, $one);
    if (strpos($sgalf, $two, $oneposbac + $length)) {
        $seebackwards = TRUE;
    }
}

if ($seeforwards == TRUE && $seebackwards == TRUE) {
    echo "both";
} elseif ($seeforwards == TRUE && $seebackwards == FALSE) {
    echo "forward";
} elseif ($seeforwards == FALSE && $seebackwards == TRUE) {
    echo "backward";
} else {
    echo "fantasy";
}
?>

<?php

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

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

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

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

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

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

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

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

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

	$isForward = false;
	$i1 = strpos($path, $t1);
	if ($i1 !== false && strpos($path, $t2, $i1 + 1) !== false) {
		$isForward = true;
	}

	$isBack = false;
	$path = strrev($path);
	if ($i1 !== false && strpos($path, $t2, $i1 + 1) !== false) {
		$isBack = true;
	}

	if ($isForward && $isBack) {
		echo 'both';
	} elseif ($isForward) {
		echo 'forward';
	} elseif ($isBack) {
		echo 'backward';
	} else {
		echo 'fantasy';
	}
	/* / end body */
}

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

<?php

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

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

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

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

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

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

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

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

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

	$isForward = false;
	$i1 = strpos($path, $t1);
	if ($i1 !== false && strpos($path, $t2, $i1 + 1) !== false) {
		$isForward = true;
	}

	$isBack = false;
	$path = strrev($path);
	$i1 = strpos($path, $t1);
	if ($i1 !== false && strpos($path, $t2, $i1 + 1) !== false) {
		$isBack = true;
	}

	if ($isForward && $isBack) {
		echo 'both';
	} elseif ($isForward) {
		echo 'forward';
	} elseif ($isBack) {
		echo 'backward';
	} else {
		echo 'fantasy';
	}
	/* / end body */
}

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

<?php

	$stdin = fopen('php://stdin', 'r');
    $road = trim(fgets($stdin));
    $start = trim(fgets($stdin));
    $end = trim(fgets($stdin));
    $pattern = '/.*'.$start.'.*'.$end.'.*/';
    preg_match($pattern, $road,$forvard);
    preg_match($pattern, strrev($road), $backward);
    if($forvard && $backward)        echo 'both';
    if(!$forvard && !$backward)        echo 'fantasy';
    if($forvard && !$backward)        echo 'forvard';
    if(!$forvard && $backward)        echo 'backward';


Polycarp found under the Christmas tree an array $$$a$$$ of $$$n$$$ elements and instructions for playing with it:   At first, choose index $$$i$$$ ($$$1 \leq i \leq n$$$) — starting position in the array. Put the chip at the index $$$i$$$ (on the value $$$a_i$$$).  While $$$i \leq n$$$, add $$$a_i$$$ to your score and move the chip $$$a_i$$$ positions to the right (i.e. replace $$$i$$$ with $$$i + a_i$$$).  If $$$i > n$$$, then Polycarp ends the game. For example, if $$$n = 5$$$ and $$$a = [7, 3, 1, 2, 3]$$$, then the following game options are possible:   Polycarp chooses $$$i = 1$$$. Game process: $$$i = 1 \overset{+7}{\longrightarrow} 8$$$. The score of the game is: $$$a_1 = 7$$$.  Polycarp chooses $$$i = 2$$$. Game process: $$$i = 2 \overset{+3}{\longrightarrow} 5 \overset{+3}{\longrightarrow} 8$$$. The score of the game is: $$$a_2 + a_5 = 6$$$.  Polycarp chooses $$$i = 3$$$. Game process: $$$i = 3 \overset{+1}{\longrightarrow} 4 \overset{+2}{\longrightarrow} 6$$$. The score of the game is: $$$a_3 + a_4 = 3$$$.  Polycarp chooses $$$i = 4$$$. Game process: $$$i = 4 \overset{+2}{\longrightarrow} 6$$$. The score of the game is: $$$a_4 = 2$$$.  Polycarp chooses $$$i = 5$$$. Game process: $$$i = 5 \overset{+3}{\longrightarrow} 8$$$. The score of the game is: $$$a_5 = 3$$$. Help Polycarp to find out the maximum score he can get if he chooses the starting index in an optimal way.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the array $$$a$$$. The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output on a separate line one number — the maximum score that Polycarp can get by playing the game on the corresponding array according to the instruction from the statement. Note that Polycarp chooses any starting position from $$$1$$$ to $$$n$$$ in such a way as to maximize his result.

NoteThe first test case is explained in the statement.In the second test case, the maximum score can be achieved by choosing $$$i = 1$$$.In the third test case, the maximum score can be achieved by choosing $$$i = 2$$$.In the fourth test case, the maximum score can be achieved by choosing $$$i = 1$$$.

<?php
function buildMap($arr)
{
	$MAX = 0;
	$s = sizeof($arr);
	for($i=$s-1; $i>=0; $i--)
	{
		$el = $arr[$i];
		if($i + $el < $s)
			$arr[$i] = $el + $arr[$i + $el];
		if($arr[$i] > $MAX)
			$MAX = $arr[$i];
	}
	return $MAX;
}

$t = fgets(STDIN);
for($i=0;$i<$t;$i++)
{
	$arr = array();
	$n = fgets(STDIN);
	$arr_str = fgets(STDIN);
	$arr = explode(" ", trim($arr_str));
	print(buildMap($arr)."\r\n");
}
//$end = fgets(STDIN);
?>

<?php
function buildMap($arr)
{
	$MAX = 0;
	$s = sizeof($arr);
	for($i=$s-1; $i>=0; $i--)
	{
		$el = $arr[$i];
		if($i + $el < $s)
			$arr[$i] = $el + $arr[$i + $el];
		if($arr[$i] > $MAX)
			$MAX = $arr[$i];
	}
	return $MAX;
}

$t = fgets(STDIN);
for($i=0;$i<$t;$i++)
{
	$arr = array();
	$n = fgets(STDIN);
	$arr_str = fgets(STDIN);
	$arr = preg_split("/[\s,]+/", $arr_str);
	print(buildMap($arr)."\r\n");
}
//$end = fgets(STDIN);
?>

<?php
function buildMap($arr)
{
	$MAX = 0;
	$s = sizeof($arr);
	for($i=$s-1; $i>=0; $i--)
	{
		$el = $arr[$i];
		if($i + $el < $s)
		{
			$arr[$i] = $el + $arr[$i + $el];
			$el = $arr[$i];
		}
		if($el > $MAX)
			$MAX = $el;
	}
	return $MAX;
}

$t = fgets(STDIN);
for($i=0;$i<$t;$i++)
{
	$arr = array();
	$n = fgets(STDIN);
	$arr_str = fgets(STDIN);
	$arr = preg_split("/[\s,]+/", $arr_str);
	print(buildMap($arr)."\r\n");
}
//$end = fgets(STDIN);
?>

<?php
function buildMap($arr)
{
	$s = sizeof($arr);
	for($i=$s-1; $i>=0; $i--)
	{
		$el = $arr[$i];
		if($i + $el < $s)
			$arr[$i] = $el + $arr[$i + $el];
	}
	return max($arr);
}

$t = fgets(STDIN);
for($i=0;$i<$t;$i++)
{
	$arr = array();
	$n = fgets(STDIN);
	$arr_str = fgets(STDIN);;
	$arr = preg_split("/[\s,]+/", $arr_str);
	print(buildMap($arr)."\r\n");
}
$end = fgets(STDIN);
?>

<?php

$times = (int) trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    $ni[] = (int) trim(fgets(STDIN));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $a = &$ai[$idx];

    $s=[];
    for ($i = $n - 1; $i >= 0; --$i) {
        $s[$i] = $a[$i];
        if ($i + $a[$i] < $n) {
            $s[$i] += $s[$i + $a[$i]];
        }
    }
    echo max($s).PHP_EOL;
}

<?php
function solve() {
    $n = intval(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $a = preg_split("/[\s,]+/", $s);
    $aRes = [];
    for ($i = $n - 1; $i >= 0; $i--) {
        $aRes[$i] = $a[$i];
        $k = $i + $a[$i];
        if ($k < $n) {
            $aRes[$i] += $aRes[$k];
        }
    }
    echo max($aRes);
}

$t = trim(fgets(STDIN));
while ($t--) {
    solve();
    echo "\n";
}
?>

<?php
function solve() {
    $n = intval(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $a = preg_split("/[\s,]+/", $s);
    $aRes = [];
    for ($i = $n; $i >= 0; $i--) {
        if (isset($aRes[$i])) {
            $aRes[$i] += $a[$i];
        } else {
            $aRes[$i] = $a[$i];
        }
        $k = $i + $a[$i];
        if ($k < $n) {
            $aRes[$i] += $aRes[$k];
        }
    }

    echo max($aRes);
}

$t = trim(fgets(STDIN));
while ($t--) {
    solve();
    echo "\n";
}
?>

<?php
function buildMap($arr)
{
	$MAX = 0;
	$s = sizeof($arr);
	for($i=$s-1; $i>=0; $i--)
	{
		$el = $arr[$i];
		if($i + $el < $s)
			$arr[$i] = $el + $arr[$i + $el];
		if($arr[$i] > $MAX)
			$MAX = $arr[$i];
	}
	return $MAX;
}

$t = fgets(STDIN);
for($i=0;$i<$t;$i++)
{
	$arr = array();
	$n = fgets(STDIN);
	$arr_str = fgets(STDIN);
	$arr = explode(" ", $arr_str);
	print(buildMap($arr)."\r\n");
}
//$end = fgets(STDIN);
?>

<?php
function buildMap($arr)
{
	$MAX = 0;
	$s = sizeof($arr);
	for($i=$s-1; $i>=0; $i--)
	{
		$el = $arr[$i];
		if($i + $el < $s)
		{
			$arr[$i] = $el + $arr[$i + $el];
			$el = $arr[$i];
		}
		if($el > $MAX)
			$MAX = $el;
	}
	return $MAX;
}

$t = fgets(STDIN);
for($i=0;$i<$t;$i++)
{
	$arr = array();
	$n = fgets(STDIN);
	$arr_str = fgets(STDIN);
	$arr = explode(" ", $arr_str);
	print(buildMap($arr)."\r\n");
}
$end = fgets(STDIN);
?>

<?php
function buildMap($arr)
{
	$MAX = 0;
	$MAP = array();
	$s = sizeof($arr);
	for($i=$s-1; $i>=0; $i--)
	{
		$el = $arr[$i];
		if($i + $el >= $s)
		{
			if($el > $MAX)
				$MAX = $el;
			$MAP[$i] = $el;
		}
		else
		{
			$el2 = $MAP[$i + $el];
			if($el + $el2 > $MAX)
				$MAX = $el + $el2;
			$MAP[$i] = $el + $el2;
		}
	}
	return $MAX;
}

$ans = array();
$t = readline();
for($i=0;$i<$t;$i++)
{
	$arr = array();
	$n = readline();
	$arr = fscanf(STDIN, str_repeat("%d ", $n)."\n");
	array_push($ans, buildMap($arr)."\r\n");
}
foreach($ans as $key => $value)
	print($value);
//$end = readline();
?>

<?php
function buildMap($arr)
{
	$MAX = 0;
	$MAP = array();
	$s = sizeof($arr);
	for($i=$s-1; $i>=0; $i--)
	{
		$el = $arr[$i];
		if($i + $el >= $s)
		{
			if($el > $MAX)
				$MAX = $el;
			$MAP[$i] = $el;
		}
		else
		{
			$el2 = $MAP[$i + $el];
			if($el + $el2 > $MAX)
				$MAX = $el + $el2;
			$MAP[$i] = $el + $el2;
		}
	}
	return $MAX;
}

$ans = array();
$t = readline();
for($i=0;$i<$t;$i++)
{
	$arr = array();
	$n = readline();
	$arr = fscanf(STDIN, str_repeat("%d ", $n));
	array_push($ans, buildMap($arr)."\r\n");
}
foreach($ans as $key => $value)
	print($value);
$end = readline();
?>

<?php
function buildMap($arr)
{
	$MAX = 0;
	$MAP = array();
	$s = sizeof($arr);
	for($i=$s-1; $i>=0; $i--)
	{
		$el = $arr[$i];
		if($i + $el >= $s)
		{
			if($el > $MAX)
				$MAX = $el;
			$MAP[$i] = $el;
		}
		else
		{
			if($el > $MAX)
				$MAX = $el;
			$MAP[$i] = $el + $MAP[$i + $el];
		}
	}
	return $MAX;
}

$arr = array();
$ans = array();
$t = readline();
for($i=0;$i<$t;$i++)
{
	$n = readline();
	$arr_str = readline();
	$arr = explode(" ", $arr_str);
	array_push($ans, buildMap($arr)."\r\n");
}
foreach($ans as $key => $value)
	print($value);
$end = readline();
?>

<?php
$MAX = 0;
function maxs($a)
{
	global $MAX;
	if($a > $MAX)
		$MAX = $a;
	return $a;
}

function buildMap($arr)
{
	global $MAX;
	$MAP = array();
	$s = sizeof($arr);
	for($i=$s-1; $i>=0; $i--)
	{
		$el = $arr[$i];
		if($i + $el >= $s)
			$MAP[$i] = maxs($el);
		else
			$MAP[$i] = maxs($el + $MAP[$i + $el]);
	}
	return $MAX;
}

$arr = array();
$ans = array();
$t = readline();
for($i=0;$i<$t;$i++)
{
	$n = readline();
	$arr_str = readline();
	$arr = explode(" ", $arr_str);
	array_push($ans, buildMap($arr)."\r\n");
}
foreach($ans as $key => $value)
	print($value);
$end = readline();
?>

<?php

$times = (int) trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    $ni[] = (int) trim(fgets(STDIN));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $a = &$ai[$idx];
    for ($i = $n - 1; $i >= 0; --$i) {
        $s[$i] = $a[$i];
        if ($i + $a[$i] < $n) {
            $s[$i] += $s[$i + $a[$i]];
        }
    }
    echo max($s).PHP_EOL;
}


Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics.Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word.Implement a program that can, given two distinct words S and T of the same length n determine how many words W of length n + 1 are there with such property that you can transform W into both S, and T by deleting exactly one character. Words S and T consist of lowercase English letters. Word W also should consist of lowercase English letters.

The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T. The second line contains word S. The third line contains word T. Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words.

Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo.

NoteIn the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold).In the second sample test the two given words couldn't be obtained from the same word by removing one letter.In the third sample test the two given words could be obtained from either word "tory" or word "troy".

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
for($x = 0; $x < $a; $x++)
{
    if($b[$x] == $c[$x])
    {
        $d .= 1;
    }
    else
    {
        $d .= 0;
    }
}
$e = 0;
$f = 0;
$g = 0;
for($x = 0; $x < $a; $x++)
{
    if(($d[$x] == 0) && ($f == 1))
    {
        $g = 1;
        break;
    }
    elseif($d[$x] == 0)
    {
        $e = 1;
    }
    elseif(($d[$x] == 1) && ($e == 1))
    {
        $f = 1;
    }
    if($d[$x] == 0)
    {
        $h .= $b[$x];
        $i .= $c[$x];
    }
}
if($b == "bbababaabaabaabbbbbbaabbabbabbaabababababbbbabaaabbbbaaabbbbbbbabababaaaaabbbbabaababbababbaaaaaabbaaabbaabaaababbbbbabbaabaabaabbbaaabaabbaaabbaabababbaaabaaabaaaaabbbababaabbbbabbbbbababbbaabaabbabaabbabbababbbbbaababbaabbbbbbbbaabbabbbababaaaaaaaaaaabababaaabbaabbbabbabbbbabbbaabaaabbbaabbabbbbbbbaaabbbabaaaaaabaabbbabbbbaaaabbbbbbabaaaaaaabbbbbbabababbaabbbaabaabbbabbbbaaaabbbbbabaaababbababbbabaaabbbbaababaababaaaaabbbaabbababaabaaabaaabbbbbabbbabbaaabbbbbbbaaaaabaaabbabaabbabbbbbbbbabbbab")
{
    print $h . "\n";
    print $l . "\n";
}
if($g == 1)
{
    print "0";
}
else
{
    if(strlen($h) == 1)
    {
        print "2";
    }
    else
    {
        $j = substr($h, 0, strlen($h) - 1);
        $k = substr($i, 1);
        $l = substr($i, 0, strlen($i) - 1);
        $m = substr($h, 1);
        if(($j == $k) || ($l == $m))
        {
            print "1";
        }
        else
        {
            print "0";
        }
    }
}
?>


Everyone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play $$$t$$$ matches of a digit game...In each of $$$t$$$ matches of the digit game, a positive integer is generated. It consists of $$$n$$$ digits. The digits of this integer are numerated from $$$1$$$ to $$$n$$$ from the highest-order digit to the lowest-order digit. After this integer is announced, the match starts.Agents play in turns. Raze starts. In one turn an agent can choose any unmarked digit and mark it. Raze can choose digits on odd positions, but can not choose digits on even positions. Breach can choose digits on even positions, but can not choose digits on odd positions. The match ends, when there is only one unmarked digit left. If the single last digit is odd, then Raze wins, else Breach wins.It can be proved, that before the end of the match (for every initial integer with $$$n$$$ digits) each agent has an ability to make a turn, i.e. there is at least one unmarked digit, that stands on a position of required parity.For each of $$$t$$$ matches find out, which agent wins, if both of them want to win and play optimally.

First line of input contains an integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of matches. The first line of each match description contains an integer $$$n$$$ $$$(1 \le n \le 10^3)$$$  — the number of digits of the generated number. The second line of each match description contains an $$$n$$$-digit positive integer without leading zeros.

For each match print $$$1$$$, if Raze wins, and $$$2$$$, if Breach wins.

NoteIn the first match no one can make a turn, the only digit left is $$$2$$$, it's even, so Breach wins.In the second match the only digit left is $$$3$$$, it's odd, so Raze wins.In the third match Raze can mark the last digit, after that Breach can only mark $$$0$$$. $$$1$$$ will be the last digit left, it's odd, so Raze wins.In the fourth match no matter how Raze plays, Breach can mark $$$9$$$, and in the end there will be digit $$$0$$$. It's even, so Breach wins.

<?php
	$t = trim (fgets(STDIN));
	for ($s=0; $s < $t ; $s++) {
		$n =trim (fgets(STDIN));
		$input = trim (fgets(STDIN));
		$tmp = str_split($input);
		$res = "0";
/*
		n нечетная?
			da
				есть хотя бы одна нечетная цифра на нечет позиции?
					да - res =1
					нет -res = 2
			нет (n четная)
				есть хотя бы одна четная цифра на чет позиции? (123...)
					да - res =2
					нет -res = 1
*/
		if (($n % 2)) {
			// da (necet)
			for ($i=0 ; $i <= count($tmp)-1 ; $i = $i+2) {
				if ($tmp[$i] % 2) {
					$res = 1;
					break;
				}
				else {
					$res = 2;
				}
			}
		}
		else {	//нет (n четная)
			for ($j=1 ; $j <= count($tmp)-1 ; $j = $j+2) {
				if (!($tmp[$j] % 2)) {
					$res = 2;
					break;
				}
				else {
					$res = 1;
				}
			}
		}
		echo $res."\n";
	}

  ?>


You are given $$$n$$$ strings $$$s_1, s_2, \dots, s_n$$$ of length at most $$$\mathbf{8}$$$. For each string $$$s_i$$$, determine if there exist two strings $$$s_j$$$ and $$$s_k$$$ such that $$$s_i = s_j + s_k$$$. That is, $$$s_i$$$ is the concatenation of $$$s_j$$$ and $$$s_k$$$. Note that $$$j$$$ can be equal to $$$k$$$.Recall that the concatenation of strings $$$s$$$ and $$$t$$$ is $$$s + t = s_1 s_2 \dots s_p t_1 t_2 \dots t_q$$$, where $$$p$$$ and $$$q$$$ are the lengths of strings $$$s$$$ and $$$t$$$ respectively. For example, concatenation of "code" and "forces" is "codeforces".

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of strings. Then $$$n$$$ lines follow, the $$$i$$$-th of which contains non-empty string $$$s_i$$$ of length at most $$$\mathbf{8}$$$, consisting of lowercase English letters. Among the given $$$n$$$ strings, there may be equal (duplicates). The sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

For each test case, output a binary string of length $$$n$$$. The $$$i$$$-th bit should be $$$\texttt{1}$$$ if there exist two strings $$$s_j$$$ and $$$s_k$$$ where $$$s_i = s_j + s_k$$$, and $$$\texttt{0}$$$ otherwise. Note that $$$j$$$ can be equal to $$$k$$$.

3

5

abab

ab

abc

abacb

c

3

x

xx

xxx

8

codeforc

es

codes

cod

forc

forces

e

code

NoteIn the first test case, we have the following:   $$$s_1 = s_2 + s_2$$$, since $$$\texttt{abab} = \texttt{ab} + \texttt{ab}$$$. Remember that $$$j$$$ can be equal to $$$k$$$.  $$$s_2$$$ is not the concatenation of any two strings in the list.  $$$s_3 = s_2 + s_5$$$, since $$$\texttt{abc} = \texttt{ab} + \texttt{c}$$$.  $$$s_4$$$ is not the concatenation of any two strings in the list.  $$$s_5$$$ is not the concatenation of any two strings in the list.  Since only $$$s_1$$$ and $$$s_3$$$ satisfy the conditions, only the first and third bits in the answer should be $$$\texttt{1}$$$, so the answer is $$$\texttt{10100}$$$.

<?php

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

function readInt() {
	return (int) read() ;
}

function readStrs() {
	return explode(" ",read()) ;
}

function readIntArray() {
	return array_map('intval', readStrs());
}

function readAsArray() {
	return str_split(read()) ;
}

function printLine($arg) {

	print_r($arg) ;
	print_r("\n") ;

}

$t = readInt() ;

while($t--) {
	$n = readInt() ;
	$arr = [] ;
	$dic = [] ;
	for($i=0;$i<$n;$i++) {
		$temp = read() ;
		$arr[] = $temp ;
		$dic[$temp] = 1 ;
	}
	$ans = [] ;
	// print_r($arr);
	foreach($arr as $e) {
		$l = strlen($e) ;
		$mark = 0 ;
		for($i=1;$i<$l;$i++) {
			$r = substr($e,0,$i) ;
			$z = substr($e,$i,($l-$i)) ;
			if(isset($dic[$r]) && isset($dic[$z])) {
				$mark = 1;
				break ;
			}
		}
		$ans[] = $mark ;
	}
	printLine(implode('',$ans));
}


In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.

The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.

Print the string that satisfies all the constraints. If there are multiple answers, print any of them.

NoteA palindrome is a sequence of characters which reads the same backward and forward.