Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not.

The first line contains integer n (3 ≤ n ≤ 100) — amount of days during which Vasya checked if there were any signals. The second line contains n characters 1 or 0 — the record Vasya kept each of those n days. It’s guaranteed that the given record sequence contains at least three 1s.

If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO.

<?php
    $in = fopen("input.txt", 'r');
    $out = fopen("output.txt", 'w');

    while (!feof($in)) {
        $get[] = fgets($in);
    }

    $get = explode("\n", implode("", $get));
    $n = $get[0];
    $signals = ltrim(rtrim($get[1], "0\n"), "0");

    $interval = -1;
    $zeros = 0;

    for($i=1;$i<strlen($signals);++$i){
        echo $signals[$i] . " ";
        echo $zeros . "\n";
        if($signals[$i]=="0") $zeros++;

        else if($signals[$i]=="1"){
            if($interval==-1){
                $interval = $zeros;
                $zeros=0;
            }
            else if($zeros!=$interval){
                fputs($out, "NO");
                return;
            }
            else $zeros = 0;
        }
    }

    fputs($out, "YES");
?>

<?php
    $in = fopen("input.txt", 'r');
    $out = fopen("output.txt", 'w');

    $i=0;
    while (!feof($in)) {
        $get[++$i] = fgets($in);
    }

    $get = explode("\n", implode("", $get));

    $n = $get[0];

    $interval = -1;
    $zeros = 0;
    $count_now=false;
    for($i=0;$i<$n;++$i){
        if($signals[$i]=="0")$zeros++;
        else if($signals[$i]=="1"){
            if($count_now==false){
               $count_now=true;
               $zeros=0;
            }
            else{
                if($interval==-1){
                    $interval = $zeros;
                    $zeros=0;
                }
                else if($zeros!=$interval){
                    fputs($out, "NO");
                    return;
                }
            }
        }
    }

    fputs($out, "YES");
?>

<?php
    $in = fopen("input.txt", 'r');
    $out = fopen("output.txt", 'w');

    $i=0;
    while (!feof($in)) {
        $get[++$i] = fgets($in);
    }

    $get = explode("\n", implode("", $get));

    $n = $get[0];
    $signals = $get[1];

    $interval = -1;
    $zeros = 0;
    $count_now=false;
    for($i=0;$i<$n;++$i){
        if($signals[$i]=="0")$zeros++;
        else {
            if($count_now==false){
               $count_now=true;
               $zeros=0;
            }
            else{
                if($interval==-1){
                    $interval = $zeros;
                    $zeros=0;
                }
                else if($zeros!=$interval){
                    fputs($out, "NO");
                    return;
                }
            }
        }
    }

    fputs($out, "YES");
?>

<?php
    $stdin = fopen('php://stdin', 'r');
    $stdout = fopen('php://stdout', 'w');
    $get = explode("\n", file_get_contents("input.txt"));

    $signals = $get[0];
    $n = $get[1];

    $interval = -1;
    $zeros = 0;
    $count_now=false;
    for($i=0;$i<$n;++$i){
        if($signals[$i]=="0")$zeros++;
        else {
            if($count_now==false){
               $count_now=true;
               $zeros=0;
            }
            else{
                if($interval==-1){
                    $interval = $zeros;
                    $zeros=0;
                }
                else if($zeros!=$interval){
                    fputs($stdout, "NO");
                    return;
                }
            }
        }
    }

    fputs($stdout, "YES");
?>

<?php
    $stdin = fopen("input.txt", 'r');
    $stdout = fopen('php://stdout', 'w');

    $i=0;
    while (!feof($stdin)) {
        $get[++$i] = fgets($stdin);
    }

    $get = explode("\n", implode("", $get));

    $n = $get[0];
    $signals = $get[1];

    $interval = -1;
    $zeros = 0;
    $count_now=false;
    for($i=0;$i<$n;++$i){
        if($signals[$i]=="0")$zeros++;
        else {
            if($count_now==false){
               $count_now=true;
               $zeros=0;
            }
            else{
                if($interval==-1){
                    $interval = $zeros;
                    $zeros=0;
                }
                else if($zeros!=$interval){
                    fputs($stdout, "NO");
                    return;
                }
            }
        }
    }

    fputs($stdout, "YES");
?>

<?php
    $in = fopen("input.txt", 'r');
    $out = fopen("output.txt", 'w');

    $i=0;
    while (!feof($in)) {
        $get[++$i] = fgets($in);
    }

    $get = explode("\n", implode("", $get));

    $n = $get[0];
    $signals = $get[1];

    $interval = -1;
    $zeros = 0;
    $count_now=false;
    for($i=0;$i<$n;++$i){
        if($signals[$i]=="0")$zeros++;
        else if($signals[$i]=="1"){
            if($count_now==false){
               $count_now=true;
               $zeros=0;
            }
            else{
                if($interval==-1){
                    $interval = $zeros;
                    $zeros=0;
                }
                else if($zeros!=$interval){
                    fputs($out, "NO");
                    return;
                }
            }
        }
    }

    fputs($out, "YES");
?>

<?php
    $in = fopen("input.txt", 'r');
    $out = fopen("output.txt", 'w');

    $i=0;
    while (!feof($in)) {
        $get[++$i] = fgets($in);
    }

    $get = explode("\n", implode("", $get));

    $n = $get[0];
    $signals = rtrim(" \r\n", $get[1]);

    $interval = -1;
    $zeros = 0;
    $count_now=false;
    for($i=0;$i<$n;++$i){
        if($signals[$i]=="0")$zeros++;
        else if($signals[$i]=="1"){
            if($count_now==false){
               $count_now=true;
               $zeros=0;
            }
            else{
                if($interval==-1){
                    $interval = $zeros;
                    $zeros=0;
                }
                else if($zeros!=$interval){
                    fputs($out, "NO");
                    return;
                }
            }
        }
    }

    fputs($out, "YES");
?>


Luca has a cypher made up of a sequence of $$$n$$$ wheels, each with a digit $$$a_i$$$ written on it. On the $$$i$$$-th wheel, he made $$$b_i$$$ moves. Each move is one of two types:   up move (denoted by $$$\texttt{U}$$$): it increases the $$$i$$$-th digit by $$$1$$$. After applying the up move on $$$9$$$, it becomes $$$0$$$.  down move (denoted by $$$\texttt{D}$$$): it decreases the $$$i$$$-th digit by $$$1$$$. After applying the down move on $$$0$$$, it becomes $$$9$$$.     Example for $$$n=4$$$. The current sequence is 0 0 0 0. Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of wheels. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$0 \leq a_i \leq 9$$$) — the digit shown on the $$$i$$$-th wheel after all moves have been performed. Then $$$n$$$ lines follow, the $$$i$$$-th of which contains the integer $$$b_i$$$ ($$$1 \leq b_i \leq 10$$$) and $$$b_i$$$ characters that are either $$$\texttt{U}$$$ or $$$\texttt{D}$$$ — the number of moves performed on the $$$i$$$-th wheel, and the moves performed. $$$\texttt{U}$$$ and $$$\texttt{D}$$$ represent an up move and a down move respectively.

For each test case, output $$$n$$$ space-separated digits  — the initial sequence of the cypher.

3

3

9 3 1

3 DDD

4 UDUU

2 DU

2

0 9

9 DDDDDDDDD

9 UUUUUUUUU

5

0 5 9 8 3

10 UUUUUUUUUU

3 UUD

8 UUDUUDDD

10 UUDUUDUDDU

4 UUUU

NoteIn the first test case, we can prove that initial sequence was $$$[2,1,1]$$$. In that case, the following moves were performed:   On the first wheel: $$$2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{D}]{} 9$$$.  On the second wheel: $$$1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{U}]{} 3$$$.  On the third wheel: $$$1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{U}]{} 1$$$.  The final sequence was $$$[9,3,1]$$$, which matches the input.

<?php

$t = intval(readline());

$i = 0;

$final_result = [];

while($i++ < $t) {

    $wheelCount = intval(readline());

    $currentState = explode(' ', readline());

    foreach($currentState as $key => $value) {
        $opCountAndOps = explode(' ', readline());
        $opCount = $opCountAndOps[0];
        $ops = $opCountAndOps[1];

        foreach(str_split($ops) as $op) {
            if($op === "D") {
                $currentState[$key] = (intval($currentState[$key]) + 1) % 10;
            } else {
                $currentState[$key] = (intval($currentState[$key]) - 1) % 10;

                if($currentState[$key] < 0) {
                    $currentState[$key] = 9;
                }
            }

        }
    }

    array_push($final_result, $currentState);
}

foreach($final_result as $result) {
    foreach($result as $value) {
        echo $value . ' ';
    }

    echo PHP_EOL;
}

<?php

$cnt = readline();
$res = array();
$k = 0;
while ($cnt--) {
    $s = readline();
    $ar = explode(' ', readline());

    foreach ($ar as $t) {
        list($x, $moves) = explode(' ', readline());
        $moves = str_split($moves);

        $i = 0;
        foreach ($moves as $move) {
            if ($move == 'U') {
                $i--;
            } else {
                $i++;
            }
        }

        $res[$k][] = $t + $i;
    }
    $k++;
}

//var_dump($res);
//exit();
foreach ($res as $ss) {
    foreach ($ss as $s) {
        echo parse($s) . " ";
    }
    echo "\n";
}

function parse($i)
{
    if ($i > 9) {
        $i = $i - 10;
    } elseif ($i < 0) {
        $i = $i + 10;
    }

    return $i;
}

<?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") ;

}

function sol($st) {
	$sum = 0 ;
	$arr = str_split($st) ;
	foreach($arr as $e) {
		if($e === "D") $sum += 1 ;
		else $sum -= 1 ;
	}
	return $sum ;
}

$t = readInt() ;

while($t--) {
	$n = readInt() ;
	$fin = readIntArray() ;
	$oprs = [] ;
	$ans = [] ;
	for($i=0;$i<$n;$i++) {
		[$r, $z] = explode(" ",read()) ;
		$oprs[] = sol($z) ;
	}
	// printLine($oprs);
	for($i=0;$i<$n;$i++) {
		$temp = ($oprs[$i] + $fin[$i]) % 10 ;
		if($temp < 0) {
			$temp = 10 + $temp ;
		}
		$ans[] = $temp ;
	}
	printLine(implode(" ", $ans));

}

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
//3
//3
//9 3 1
//3 DDD
//4 UDUU
//2 DU
function solve()
{
    $n = IO::get();
    $a = IO::getArray();

    $ans = [];
    for($i=0; $i<$n; $i++) {
        list($t, $s) = IO::getArray();
        $temp = (int)$a[$i];
        for($j=0; $j<$t; $j++) {
           if($s[$j] == 'U') {
               if($temp == 0) {
                   $temp = 9;
               } else {
                   $temp--;
               }
           } else {
               if($temp == 9) {
                   $temp = 0;
               } else {
                   $temp++;
               }
           }
        }

        $ans[] =  $temp;
    }
    IO::prArray($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;
    }
}


Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence!We say that a string formed by $$$n$$$ characters '(' or ')' is simple if its length $$$n$$$ is even and positive, its first $$$\frac{n}{2}$$$ characters are '(', and its last $$$\frac{n}{2}$$$ characters are ')'. For example, the strings () and (()) are simple, while the strings )( and ()() are not simple.Kuroni will be given a string formed by characters '(' and ')' (the given string is not necessarily simple). An operation consists of choosing a subsequence of the characters of the string that forms a simple string and removing all the characters of this subsequence from the string. Note that this subsequence doesn't have to be continuous. For example, he can apply the operation to the string ')()(()))', to choose a subsequence of bold characters, as it forms a simple string '(())', delete these bold characters from the string and to get '))()'. Kuroni has to perform the minimum possible number of operations on the string, in such a way that no more operations can be performed on the remaining string. The resulting string does not have to be empty.Since the given string is too large, Kuroni is unable to figure out how to minimize the number of operations. Can you help him do it instead?A sequence of characters $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters.

The only line of input contains a string $$$s$$$ ($$$1 \le |s| \le 1000$$$) formed by characters '(' and ')', where $$$|s|$$$ is the length of $$$s$$$.

In the first line, print an integer $$$k$$$  — the minimum number of operations you have to apply. Then, print $$$2k$$$ lines describing the operations in the following format: For each operation, print a line containing an integer $$$m$$$  — the number of characters in the subsequence you will remove. Then, print a line containing $$$m$$$ integers $$$1 \le a_1 < a_2 < \dots < a_m$$$  — the indices of the characters you will remove. All integers must be less than or equal to the length of the current string, and the corresponding subsequence must form a simple string. If there are multiple valid sequences of operations with the smallest $$$k$$$, you may print any of them.

NoteIn the first sample, the string is '(()(('. The operation described corresponds to deleting the bolded subsequence. The resulting string is '(((', and no more operations can be performed on it. Another valid answer is choosing indices $$$2$$$ and $$$3$$$, which results in the same final string.In the second sample, it is already impossible to perform any operations.


INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using the following method.The integers of the array are processed one by one, starting from the first. Processing i-th element of the array is done in three steps:1. The 8-bit binary notation of the ASCII-code of the previous printed character is reversed. When the first element of the array is processed, the result of this step is considered to be 0.2. The i-th element of the array is subtracted from the result of the previous step modulo 256.3. The binary notation of the result of the previous step is reversed again to produce ASCII-code of the i-th character to be printed.You are given the text printed using this method. Restore the array used to produce this text.

The input will consist of a single line text which contains the message printed using the described method. String text will contain between 1 and 100 characters, inclusive. ASCII-code of each character of text will be between 32 (space) and 126 (tilde), inclusive.

Output the initial array, which was used to produce text, one integer per line.

NoteLet's have a closer look at the beginning of the example. The first character is "H" with ASCII-code 72 = 010010002. Its reverse is 000100102 = 18, and this number should become the result of the second step of processing. The result of the first step is considered to be 0, so the first element of the array has to be (0 - 18) mod 256 = 238, where a mod b is the remainder of division of a by b.

<?php
function mod_math($k, $m) { return ($k - $m * floor($k/$m)); }
function convertSymbol($str,&$last) {
    if($last != 0) {
        $nlast = array('0','0','0','0','0','0','0','0');
        $lbin = decbin($last);
        $n=0;
        for($i=(strlen($lbin)-1);$i>=0;$i--) {
            $nlast[$n++] = $lbin[$i];
        }
        $last = bindec(implode('', $nlast));
    }
    $dec = ord($str);
    $bin = decbin($dec);
    $nbin = array('0','0','0','0','0','0','0','0');
    $n = 0;
    for($i=(strlen($bin)-1);$i>=0;$i--) {
        $nbin[$n++] = $bin[$i];
    }
    $nbin = implode('', $nbin);
    $ndec = bindec($nbin);
    $s = $last-$ndec;
    $res = mod_math($s,256);
    $last = $dec;
    echo( $res ."\n" );
}

$in = trim(fgets(STDIN));
$last = 0;
for($i=0;$i<strlen($in);$i++) {
    convertSymbol($in[$i],$last);
}

<?
$str=trim(fgets(STDIN));

function reverses(&$str){
    $ss="";
    $size=strlen($str);
    for($i=$size-1; $i>=0; $i--){
        $ss.=$str[$i];
    }
    for($i=$size+1; $i<=8; $i++)
        $ss.="0";
    return $ss;
}
$tmp=0;
for($i=0, $s=strlen($str); $i<$s; $i++){
    $char=ord($str[$i]);
    $bin=decbin($char);
    $rev_bin = reverses($bin);
    $dec=bindec($rev_bin);
    echo (($tmp-$dec)%256+256)%256,"\n";
    $tmp=$dec;
}
?>


You are given two arrays $$$a$$$ and $$$b$$$, each contains $$$n$$$ integers.You want to create a new array $$$c$$$ as follows: choose some real (i.e. not necessarily integer) number $$$d$$$, and then for every $$$i \in [1, n]$$$ let $$$c_i := d \cdot a_i + b_i$$$.Your goal is to maximize the number of zeroes in array $$$c$$$. What is the largest possible answer, if you choose $$$d$$$ optimally?

The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in both arrays. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). The third line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$).

Print one integer — the maximum number of zeroes in array $$$c$$$, if you choose $$$d$$$ optimally.

NoteIn the first example, we may choose $$$d = -2$$$.In the second example, we may choose $$$d = -\frac{1}{13}$$$.In the third example, we cannot obtain any zero in array $$$c$$$, no matter which $$$d$$$ we choose.In the fourth example, we may choose $$$d = 6$$$.


This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled.Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of $$$n$$$ stations, enumerated from $$$1$$$ through $$$n$$$. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit after station $$$i$$$ is station $$$i+1$$$ if $$$1 \leq i < n$$$ or station $$$1$$$ if $$$i = n$$$. It takes the train $$$1$$$ second to travel to its next station as described.Bob gave Alice a fun task before he left: to deliver $$$m$$$ candies that are initially at some stations to their independent destinations using the train. The candies are enumerated from $$$1$$$ through $$$m$$$. Candy $$$i$$$ ($$$1 \leq i \leq m$$$), now at station $$$a_i$$$, should be delivered to station $$$b_i$$$ ($$$a_i \neq b_i$$$).    The blue numbers on the candies correspond to $$$b_i$$$ values. The image corresponds to the $$$1$$$-st example. The train has infinite capacity, and it is possible to load off any number of candies at a station. However, only at most one candy can be loaded from a station onto the train before it leaves the station. You can choose any candy at this station. The time it takes to move the candies is negligible.Now, Alice wonders how much time is needed for the train to deliver all candies. Your task is to find, for each station, the minimum time the train would need to deliver all the candies were it to start from there.

The first line contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 100$$$; $$$1 \leq m \leq 200$$$) — the number of stations and the number of candies, respectively. The $$$i$$$-th of the following $$$m$$$ lines contains two space-separated integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n$$$; $$$a_i \neq b_i$$$) — the station that initially contains candy $$$i$$$ and the destination station of the candy, respectively.

In the first and only line, print $$$n$$$ space-separated integers, the $$$i$$$-th of which is the minimum time, in seconds, the train would need to deliver all the candies were it to start from station $$$i$$$.

NoteConsider the second sample.If the train started at station $$$1$$$, the optimal strategy is as follows.  Load the first candy onto the train.  Proceed to station $$$2$$$. This step takes $$$1$$$ second.  Deliver the first candy.  Proceed to station $$$1$$$. This step takes $$$1$$$ second.  Load the second candy onto the train.  Proceed to station $$$2$$$. This step takes $$$1$$$ second.  Deliver the second candy.  Proceed to station $$$1$$$. This step takes $$$1$$$ second.  Load the third candy onto the train.  Proceed to station $$$2$$$. This step takes $$$1$$$ second.  Deliver the third candy. Hence, the train needs $$$5$$$ seconds to complete the tasks.If the train were to start at station $$$2$$$, however, it would need to move to station $$$1$$$ before it could load the first candy, which would take one additional second. Thus, the answer in this scenario is $$$5+1 = 6$$$ seconds.


You are given two strings $$$s$$$ and $$$t$$$. Both strings have length $$$n$$$ and consist of lowercase Latin letters. The characters in the strings are numbered from $$$1$$$ to $$$n$$$.You can successively perform the following move any number of times (possibly, zero):  swap any two adjacent (neighboring) characters of $$$s$$$ (i.e. for any $$$i = \{1, 2, \dots, n - 1\}$$$ you can swap $$$s_i$$$ and $$$s_{i + 1})$$$. You can't apply a move to the string $$$t$$$. The moves are applied to the string $$$s$$$ one after another.Your task is to obtain the string $$$t$$$ from the string $$$s$$$. Find any way to do it with at most $$$10^4$$$ such moves.You do not have to minimize the number of moves, just find any sequence of moves of length $$$10^4$$$ or less to transform $$$s$$$ into $$$t$$$.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of strings $$$s$$$ and $$$t$$$. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. The third line of the input contains the string $$$t$$$ consisting of $$$n$$$ lowercase Latin letters.

If it is impossible to obtain the string $$$t$$$ using moves, print "-1". Otherwise in the first line print one integer $$$k$$$ — the number of moves to transform $$$s$$$ to $$$t$$$. Note that $$$k$$$ must be an integer number between $$$0$$$ and $$$10^4$$$ inclusive. In the second line print $$$k$$$ integers $$$c_j$$$ ($$$1 \le c_j < n$$$), where $$$c_j$$$ means that on the $$$j$$$-th move you swap characters $$$s_{c_j}$$$ and $$$s_{c_j + 1}$$$. If you do not need to apply any moves, print a single integer $$$0$$$ in the first line and either leave the second line empty or do not print it at all.

NoteIn the first example the string $$$s$$$ changes as follows: "abcdef" $$$\rightarrow$$$ "abdcef" $$$\rightarrow$$$ "abdcfe" $$$\rightarrow$$$ "abdfce" $$$\rightarrow$$$ "abdfec".In the second example there is no way to transform the string $$$s$$$ into the string $$$t$$$ through any allowed moves.


One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is.

The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100.

For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions.

5
I will go to play with you lala.
wow, welcome.
miao.lala.
miao.
miao .

Freda's
OMG>.< I don't know!
OMG>.< I don't know!
Rainbow's
OMG>.< I don't know!

<?php
$a = trim(fgets(STDIN));
$b = array();
for($x = 0; $x < $a; $x++)
{
     $c = fgets(STDIN);
     for($y = 0; $y < strlen($c); $y++)
     {
          if($c[$y] == " ")
          {
               $c[$y] = "!";
          }
     }
     $b[$x] = trim($c);
}
for($x = 0; $x < $a; $x++)
{
     $d = $b[$x];
     $e = substr($d, 0, 5);
     $f = substr($d, strlen($d) - 5);
     if(($e == "miao.") && ($f == "lala."))
     {
          print "OMG>.< I don't know!\n";
     }
     elseif($e == "miao.")
     {
          print "Rainbow's\n";
     }
     elseif($f == "lala.")
     {
          print "Freda's\n";
     }
     else
     {
          print "OMG>.< I don't know!\n";
     }
}
?>

<?php
	$n = fgets(STDIN);

	for($i = 0; $i < $n; ++$i)
	{
		$s = trim(fgets(STDIN), "\n\r");
		$l = substr($s, 0, 5);
		$r = substr($s, -5);
		if($l == 'miao.' && $r == 'lala.')
			echo 'OMG>.< I don\'t know!';
		elseif($l == 'miao.')
			echo 'Rainbow\'s';
		elseif($r == 'lala.')
			echo 'Freda\'s';
		else
			echo 'OMG>.< I don\'t know!';
		echo "\n";
	}

<?php
$t = trim(fgets(STDIN));
while($t--){
	$s = trim(fgets(STDIN), "\n\r");
	$l = substr($s, 0, 5);
	$r = substr($s, -5);
	if($l == 'miao.' && $r == 'lala.')
		echo 'OMG>.< I don\'t know!';
	elseif($l == 'miao.')
		echo 'Rainbow\'s';
	elseif($r == 'lala.')
		echo 'Freda\'s';
	else
		echo 'OMG>.< I don\'t know!';
	echo "\n";
}
?>

<?php

fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++)
{
	$str = trim(fgets(STDIN), "\r\n");
	$f = endsWith($str, 'lala.');
	$r = startsWith($str, 'miao.');

	if ($f xor $r)
	{
		if ($f)
			echo "Freda's" . PHP_EOL;
		elseif ($r)
			echo "Rainbow's" . PHP_EOL;
	} else
		echo "OMG>.< I don't know!" . PHP_EOL;
}

function startsWith($haystack, $needle)
{
	return !strncmp($haystack, $needle, strlen($needle));
}

function endsWith($haystack, $needle)
{
	$length = strlen($needle);
	if ($length == 0)
	{
		return true;
	}

	return (substr($haystack, -$length) === $needle);
}

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = "  " . trim(fgets(STDIN));
    $c = strpos($b, "miao.");
    $d = strpos($b, "lala.", strlen($b) - 5);
    if(($c == 2) && ($d != (strlen($b) - 5)))
    {
        print "Rainbow's\n";
    }
    elseif(($c != 2) && ($d == (strlen($b) - 5)))
    {
        print "Freda's\n";
    }
    else
    {
        print "OMG>.< I don't know!\n";
    }
}
$b = "  " . trim(fgets(STDIN));
$c = strpos($b, "miao.");
$d = strpos($b, "lala.", strlen($b) - 5);
if(($c == 2) && ($d != (strlen($b) - 5)))
{
    print "Rainbow's";
}
elseif(($c != 2) && ($d == (strlen($b) - 5)))
{
    print "Freda's";
}
else
{
    print "OMG>.< I don't know!";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = "  " . trim(fgets(STDIN));
    $c = strpos($b, "miao.");
    $d = strpos($b, "lala.", strlen($b) - 5);
    if($b == "  miaolala.")
    {
        print "OMG>.< I don't know!\n";
    }
    elseif(($c == 2) && ($d != (strlen($b) - 5)))
    {
        print "Rainbow's\n";
    }
    elseif(($c != 2) && ($d == (strlen($b) - 5)))
    {
        print "Freda's\n";
    }
    else
    {
        print "OMG>.< I don't know!\n";
    }
}
$b = "  " . trim(fgets(STDIN));
$c = strpos($b, "miao.");
$d = strpos($b, "lala.", strlen($b) - 5);
if(($c == 2) && ($d != (strlen($b) - 5)))
{
    print "Rainbow's";
}
elseif(($c != 2) && ($d == (strlen($b) - 5)))
{
    print "Freda's";
}
else
{
    print "OMG>.< I don't know!";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = substr($b, strlen($b) - 5);
    $d = substr($b, 0, 5);
    if(($c == "lala.") && ($d == "miao"))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c != "lala.") && ($d != "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c == "lala.") && ($d != "miao."))
    {
        print "Freda's" . "\n";
    }
    elseif(($c != "lala.") && ($d == "miao."))
    {
        print "Rainbow's" . "\n";
    }
}
$b = trim(fgets(STDIN));
$c = substr($b, strlen($b) - 5);
$d = substr($b, 0, 5);
if(($c == "lala.") && ($d == "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c != "lala.") && ($d != "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c == "lala.") && ($d != "miao."))
{
    print "Freda's";
}
elseif(($c != "lala.") && ($d == "miao."))
{
    print "Rainbow's";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = substr($b, strlen($b) - 5);
    $d = substr($b, 0, 5);
    if($b == "miaolala.")
    {
        print "Rainbow's" . "\n";
    }
    elseif(($c == "lala.") && ($d == "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c != "lala.") && ($d != "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c == "lala.") && ($d != "miao."))
    {
        print "Freda's" . "\n";
    }
    elseif(($c != "lala.") && ($d == "miao."))
    {
        print "Rainbow's" . "\n";
    }
}
$b = trim(fgets(STDIN));
$c = substr($b, strlen($b) - 5);
$d = substr($b, 0, 5);
if($b == "miaolala.")
{
    print "Rainbow's";
}
elseif(($c == "lala.") && ($d == "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c != "lala.") && ($d != "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c == "lala.") && ($d != "miao."))
{
    print "Freda's";
}
elseif(($c != "lala.") && ($d == "miao."))
{
    print "Rainbow's";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = substr($b, 0, 5);
    $d = substr($b, -5);
    if(($c == "miao.") && ($d == "lala."))
    {
        print "OMG>.< I don't know!\n";
    }
    elseif(($c == "miao.") && ($d != "lala."))
    {
        print "Rainbow's\n";
    }
    elseif(($c != "miao.") && ($d == "lala."))
    {
        print "Freda's\n";
    }
    elseif($b == "miaolala.")
    {
        print "OMG>.< I don't know!\n";
    }
    else
    {
        print "OMG>.< I don't know!\n";
    }
}
$b = trim(fgets(STDIN));
$c = substr($b, 0, 5);
$d = substr($b, -5);
if(($c == "miao.") && ($d == "lala."))
{
    print "OMG>.< I don't know!";
}
elseif(($c == "miao.") && ($d != "lala."))
{
    print "Rainbow's";
}
elseif(($c != "miao.") && ($d == "lala."))
{
    print "Freda's";
}
elseif($b == "miaolala.")
{
    print "OMG>.< I don't know!";
}
else
{
    print "OMG>.< I don't know!";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = substr($b, strlen($b) - 5);
    $d = substr($b, 0, 5);
    if($b == "miaolala.")
    {
        print "Rainbow's" . "\n";
    }
    elseif(($c == "lala.") && ($d == "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c != "lala.") && ($d != "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c == "lala.") && ($d != "miao."))
    {
        print "Freda's" . "\n";
    }
    elseif(($c != "lala.") && ($d == "miao."))
    {
        print "Rainbow's" . "\n";
    }
}
$b == trim(fgets(STDIN));
$c = substr($b, strlen($b) - 5);
$d = substr($b, 0, 5);
if($b = "miaolala.")
{
    print "Rainbow's";
}
elseif(($c == "lala.") && ($d == "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c != "lala.") && ($d != "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c == "lala.") && ($d != "miao."))
{
    print "Freda's";
}
elseif(($c != "lala.") && ($d == "miao."))
{
    print "Rainbow's";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = substr($b, strlen($b) - 5);
    $d = substr($b, 0, 5);
    if(($c == "lala.") && ($d == "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c != "lala.") && ($d != "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c == "lala.") && ($d != "miao."))
    {
        print "Freda's" . "\n";
    }
    elseif(($c != "lala.") && ($d == "miao."))
    {
        print "Rainbow's" . "\n";
    }
}
$b = trim(fgets(STDIN));
$c = substr($b, strlen($b) - 5);
$d = substr($b, 0, 5);
if(($c == "lala.") && ($d == "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c != "lala.") && ($d != "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c == "lala.") && ($d != "miao."))
{
    print "Freda's";
}
elseif(($c != "lala.") && ($d == "miao."))
{
    print "Rainbow's";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = fgets(STDIN);
    $c = substr($b, 0, 5);
    $d = substr($b, -5);
    if(($c == "miao.") && ($d == "lala."))
    {
        print "OMG>.< I don't know!\n";
    }
    elseif(($c == "miao.") && ($d != "lala."))
    {
        print "Rainbow's\n";
    }
    elseif(($c != "miao.") && ($d == "lala."))
    {
        print "Freda's\n";
    }
    else
    {
        print "OMG>.< I don't know!\n";
    }
}
$b = fgets(STDIN);
$c = substr($b, 0, 5);
$d = substr($b, -5);
if(($c == "miao.") && ($d == "lala."))
{
    print "OMG>.< I don't know!";
}
elseif(($c == "miao.") && ($d != "lala."))
{
    print "Rainbow's";
}
elseif(($c != "miao.") && ($d == "lala."))
{
    print "Freda's";
}
else
{
    print "OMG>.< I don't know!";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = substr($b, strlen($b) - 5);
    $d = substr($b, 0, 5);
    if($b = "miaolala.")
    {
        print "Rainbow's" . "\n";
    }
    elseif(($c == "lala.") && ($d == "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c != "lala.") && ($d != "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c == "lala.") && ($d != "miao."))
    {
        print "Freda's" . "\n";
    }
    elseif(($c != "lala.") && ($d == "miao."))
    {
        print "Rainbow's" . "\n";
    }
}
$b = trim(fgets(STDIN));
$c = substr($b, strlen($b) - 5);
$d = substr($b, 0, 5);
if($b = "miaolala.")
{
    print "Rainbow's" . "\n";
}
elseif(($c == "lala.") && ($d == "miao."))
{
    print "OMG>.< I don't know!" . "\n";
}
elseif(($c != "lala.") && ($d != "miao."))
{
    print "OMG>.< I don't know!" . "\n";
}
elseif(($c == "lala.") && ($d != "miao."))
{
    print "Freda's" . "\n";
}
elseif(($c != "lala.") && ($d == "miao."))
{
    print "Rainbow's" . "\n";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = substr($b, 0, 5);
    $d = substr($b, -5);
    if(($c == "miao.") && ($d == "lala."))
    {
        print "OMG>.< I don't know!\n";
    }
    elseif(($c == "miao.") && ($d != "lala."))
    {
        print "Rainbow's\n";
    }
    elseif(($c != "miao.") && ($d == "lala."))
    {
        print "Freda's\n";
    }
    else
    {
        print "OMG>.< I don't know!\n";
    }
}
$b = trim(fgets(STDIN));
$c = substr($b, 0, 5);
$d = substr($b, -5);
if(($c == "miao.") && ($d == "lala."))
{
    print "OMG>.< I don't know!";
}
elseif(($c == "miao.") && ($d != "lala."))
{
    print "Rainbow's";
}
elseif(($c != "miao.") && ($d == "lala."))
{
    print "Freda's";
}
else
{
    print "OMG>.< I don't know!";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = substr($b, strlen($b) - 5);
    $d = substr($b, 0, 5);
    if($b == "miaolala.")
    {
        print "Rainbow's" . "\n";
    }
    elseif(($c == "lala.") && ($d == "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c != "lala.") && ($d != "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c == "lala.") && ($d != "miao."))
    {
        print "Freda's" . "\n";
    }
    elseif(($c != "lala.") && ($d == "miao."))
    {
        print "Rainbow's" . "\n";
    }
}
$b == trim(fgets(STDIN));
$c = substr($b, strlen($b) - 5);
$d = substr($b, 0, 5);
if($b = "miaolala.")
{
    print "Rainbow's" . "\n";
}
elseif(($c == "lala.") && ($d == "miao."))
{
    print "OMG>.< I don't know!" . "\n";
}
elseif(($c != "lala.") && ($d != "miao."))
{
    print "OMG>.< I don't know!" . "\n";
}
elseif(($c == "lala.") && ($d != "miao."))
{
    print "Freda's" . "\n";
}
elseif(($c != "lala.") && ($d == "miao."))
{
    print "Rainbow's" . "\n";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = fgets(STDIN);
    $c = substr($b, strlen($b) - 5);
    $d = substr($b, 0, 5);
    if(($c == "lala.") && ($d == "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c != "lala.") && ($d != "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c == "lala.") && ($d != "miao."))
    {
        print "Freda's" . "\n";
    }
    elseif(($c != "lala.") && ($d == "miao."))
    {
        print "Rainbow's" . "\n";
    }
}
$b = fgets(STDIN);
$c = substr($b, strlen($b) - 5);
$d = substr($b, 0, 5);
if(($c == "lala.") && ($d == "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c != "lala.") && ($d != "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c == "lala.") && ($d != "miao."))
{
    print "Freda's";
}
elseif(($c != "lala.") && ($d == "miao."))
{
    print "Rainbow's";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = substr($b, strlen($b) - 5);
    $d = substr($b, 0, 5);
    if($b == "miaolala.")
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c == "lala.") && ($d == "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c != "lala.") && ($d != "miao."))
    {
        print "OMG>.< I don't know!" . "\n";
    }
    elseif(($c == "lala.") && ($d != "miao."))
    {
        print "Freda's" . "\n";
    }
    elseif(($c != "lala.") && ($d == "miao."))
    {
        print "Rainbow's" . "\n";
    }
}
$b = trim(fgets(STDIN));
$c = substr($b, strlen($b) - 5);
$d = substr($b, 0, 5);
if($b == "miaolala.")
{
    print "OMG>.< I don't know!" . "\n";
}
elseif(($c == "lala.") && ($d == "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c != "lala.") && ($d != "miao."))
{
    print "OMG>.< I don't know!";
}
elseif(($c == "lala.") && ($d != "miao."))
{
    print "Freda's";
}
elseif(($c != "lala.") && ($d == "miao."))
{
    print "Rainbow's";
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x < $a; $x++)
{
    $b = "  " . fgets(STDIN);
    $c = strpos($b, "miao.");
    $d = strpos($b, "lala.", strlen($b) - 5);
    if(($c == 2) && ($d != (strlen($b) - 5)))
    {
        print "Rainbow's\n";
    }
    elseif(($c != 2) && ($d == (strlen($b) - 5)))
    {
        print "Freda's\n";
    }
    else
    {
        print "OMG>.< I don't know!\n";
    }
}
$b = "  " . fgets(STDIN);
$c = strpos($b, "miao.");
$d = strpos($b, "lala.", strlen($b) - 5);
if(($c == 2) && ($d != (strlen($b) - 5)))
{
    print "Rainbow's";
}
elseif(($c != 2) && ($d == (strlen($b) - 5)))
{
    print "Freda's";
}
else
{
    print "OMG>.< I don't know!";
}
?>

<?php
	$n = fgets(STDIN);

	for($i = 0; $i < $n; ++$i)
	{
		$s = trim(fgets(STDIN), "\n");
		$l = substr($s, 0, 5);
		$r = substr($s, -5);
		if($l == 'miao.' && $r == 'lala.')
			echo 'OMG>.< I don\'t know!';
		elseif($l == 'miao.')
			echo 'Rainbow\'s';
		elseif($r == 'lala.')
			echo 'Freda\'s';
		else
			echo 'OMG>.< I don\'t know!';
		echo "\n";
	}

<?php
	$n = fgets(STDIN);

	for($i = 0; $i < $n; ++$i)
	{
		$s = fgets(STDIN);
		$l = substr($s, 0, 5);
		$r = substr($s, -5);
		echo $r;
		if($l == 'miao.' && $r == 'lala.')
			echo 'OMG>.< I don\'t know!';
		elseif($l == 'miao.')
			echo 'Rainbow\'s';
		elseif($r == 'lala.')
			echo 'Freda\'s';
		else
			echo 'OMG>.< I don\'t know!';
		echo "\n";
	}

<?php
	$n = fgets(STDIN);

	for($i = 0; $i < $n; ++$i)
	{
		$s = trim(fgets(STDIN), "\n", "\0");
		$l = substr($s, 0, 5);
		$r = substr($s, -5);
		if($l == 'miao.' && $r == 'lala.')
			echo 'OMG>.< I don\'t know!';
		elseif($l == 'miao.')
			echo 'Rainbow\'s';
		elseif($r == 'lala.')
			echo 'Freda\'s';
		else
			echo 'OMG>.< I don\'t know!';
		echo "\n";
	}

<?php
	$n = fgets(STDIN);

	for($i = 0; $i < $n; ++$i)
	{
		$s = trim(fgets(STDIN));
		$l = substr($s, 0, 5);
		$r = substr($s, -5);
		if($l == 'miao.' && $r == 'lala.')
			echo 'OMG>.< I don\'t know!';
		elseif($l == 'miao.')
			echo 'Rainbow\'s';
		elseif($r == 'lala.')
			echo 'Freda\'s';
		else
			echo 'OMG>.< I don\'t know!';
		echo "\n";
	}

<?php
	$n = fgets(STDIN);

	for($i = 0; $i < $n; ++$i)
	{
		$s = (fgets(STDIN));
		$l = substr($s, 0, 5);
		$r = substr($s, -7);
		if($l == 'miao.' && $r == 'lala.')
			echo 'OMG>.< I don\'t know!';
		elseif($l == 'miao.')
			echo 'Rainbow\'s';
		elseif($r == 'lala.')
			echo 'Freda\'s';
		else
			echo 'OMG>.< I don\'t know!';
		echo "\n";
	}

<?php
	$n = fgets(STDIN);

	for($i = 0; $i < $n; ++$i)
	{
		$s = trim(fgets(STDIN), "\n\n");
		$l = substr($s, 0, 5);
		$r = substr($s, -5);
		if($l == 'miao.' && $r == 'lala.')
			echo 'OMG>.< I don\'t know!';
		elseif($l == 'miao.')
			echo 'Rainbow\'s';
		elseif($r == 'lala.')
			echo 'Freda\'s';
		else
			echo 'OMG>.< I don\'t know!';
		echo "\n";
	}


Graph constructive problems are back! This time the graph you are asked to build should match the following properties.The graph is connected if and only if there exists a path between every pair of vertices.The diameter (aka "longest shortest path") of a connected undirected graph is the maximum number of edges in the shortest path between any pair of its vertices.The degree of a vertex is the number of edges incident to it.Given a sequence of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ construct a connected undirected graph of $$$n$$$ vertices such that:  the graph contains no self-loops and no multiple edges;  the degree $$$d_i$$$ of the $$$i$$$-th vertex doesn't exceed $$$a_i$$$ (i.e. $$$d_i \le a_i$$$);  the diameter of the graph is maximum possible. Output the resulting graph or report that no solution exists.

The first line contains a single integer $$$n$$$ ($$$3 \le n \le 500$$$) — the number of vertices in the graph. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n - 1$$$) — the upper limits to vertex degrees.

Print "NO" if no graph can be constructed under the given conditions. Otherwise print "YES" and the diameter of the resulting graph in the first line. The second line should contain a single integer $$$m$$$ — the number of edges in the resulting graph. The $$$i$$$-th of the next $$$m$$$ lines should contain two integers $$$v_i, u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$v_i \neq u_i$$$) — the description of the $$$i$$$-th edge. The graph should contain no multiple edges — for each pair $$$(x, y)$$$ you output, you should output no more pairs $$$(x, y)$$$ or $$$(y, x)$$$.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = ceil($b / $a);
printf("%.0f", $c);
?>


Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.

The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home. The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at. The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).

NotePictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):

<?php
list($xa, $ya) = explode(" ", trim(fgets(STDIN)));
list($xb, $yb) = explode(" ", trim(fgets(STDIN)));
$ans=0;

list($n)=explode(" ", trim(fgets(STDIN)));
	while ($n>0) {
	list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
		$tmp1 = $a * $xa + $b * $ya + $c;
		$tmp2 = $a * $xb + $b * $yb + $c;
		if ($tmp1 > 0 && $tmp2 < 0) $ans++;
		else if ($tmp1 < 0 && $tmp2 > 0) $ans++;
	$n--;}
	echo $ans. PHP_EOL;

?>


You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves:   decrease $$$n$$$ by $$$1$$$;  divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$).

For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line.

NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$.

<?php
# 1175A
$stdin = STDIN;
$t = (int)trim(fgets($stdin));
while ($t > 0) {
    [$n, $k] = explode(' ', trim(fgets($stdin)));
    $i = '0';
    while ($n !== '0') {
        $mod = bcmod($n, $k);
        if ($k > 1 && ($mod === '0')) {
            $n = bcdiv($n, $k);
            $i = bcadd($i, '1');
        } else {
            $n = bcadd($n, '-' . $mod);
            $i = bcadd($i, $mod);
        }
    }
    echo $i . PHP_EOL;
    $t--;
}

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = 0;
     while(TRUE)
     {
          if(bcmod($b, $c) == 0)
          {
               $b = bcdiv($b, $c);
               $d = bcadd($d, 1);
          }
          else
          {
               $d = bcadd($d, bcmod($b, $c));
               $b = bcsub($b, bcmod($b, $c));
          }
          if($b == 0)
          {
               print $d . "\n";
               break;
          }
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = 0;
     while(TRUE)
     {
          if(bcmod($b, $c) == 0)
          {
               $b = bcdiv($b, $c);
               $d++;
          }
          else
          {
               $d += bcmod($b, $c);
               $b = bcsub($b, bcmod($b, $c));
          }
          if($b == 0)
          {
               printf("%.0f", $d);
               print "\n";
               break;
          }
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = 0;
     while(TRUE)
     {
          if(bcmod($b, $c) == 0)
          {
               $b = bcdiv($b, $c);
               $d = bcadd($d, 1);
          }
          else
          {
               $d = bcadd($d, bcmod($b, $c));
               $b = bcsub($b, bcmod($b, $c));
          }
          if($b == 0)
          {
               printf("%.0f", $d);
               print "\n";
               break;
          }
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = 0;
     while(TRUE)
     {
          if(bcmod($b, $c) == 0)
          {
               $b = bcdiv($b, $c);
               $d++;
          }
          else
          {
               $d += bcmod($b, $c);
               $b = bcsub($b, bcmod($b, $c));
          }
          if($b == 0)
          {
               print $d . "\n";
               break;
          }
     }
}
?>


Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market.  Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.

For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).

NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     if($b % 4 == 0)
     {
          print "YES\n";
     }
     else
     {
          print "NO\n";
     }
}
?>

<?
$stdin = fopen("php://stdin", "r");
$t = fgets($stdin);

while($t > 0)
{
    $n = fgets($stdin);

    if ($n % 4 == 0)
        echo("YES\n");
    else
        echo("NO\n");

    $t -= 1;
}

fclose($stdin);
?>

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $n = intval(trim(fgets(STDIN))) ;

        echo $n&3 ? "NO\n" : "YES\n" ;
    }
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     if($b % 2 == 0)
     {
          print "YES\n";
     }
     else
     {
          print "NO\n";
     }
}
?>


You are given an array a. Some element of this array ai is a local minimum iff it is strictly less than both of its neighbours (that is, ai < ai - 1 and ai < ai + 1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, ai > ai - 1 and ai > ai + 1). Since a1 and an have only one neighbour each, they are neither local minima nor local maxima.An element is called a local extremum iff it is either local maximum or local minimum. Your task is to calculate the number of local extrema in the given array.

The first line contains one integer n (1 ≤ n ≤ 1000) — the number of elements in array a. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the elements of array a.

Print the number of local extrema in the given array.

<?php
$num = fgets(STDIN);
$string_array = fgets(STDIN);
$loc_extr = 0;
$array = explode(' ', $string_array);
for ($i=1; $i < ($num-1); $i++) {
	if (intval($array[$i-1])>intval($array[$i]) ) {
	    if (intval($array[$i+1])>intval($array[$i]))
	        $loc_extr++;
	}
	else if (intval($array[$i-1])<intval($array[$i])) {
	    if (intval($array[$i+1])<intval($array[$i]))
	        $loc_extr++;
	}
}
echo $loc_extr;
?>

<?php
$num = fgets(STDIN);
$string_array = fgets(STDIN);
$loc_extr = 0;
$array = explode(' ', $string_array);
for ($i=1; $i < ($num-1); $i++) {
	if (($array[$i-1]>=$array[$i] && $array[$i+1]>$array[$i])||($array[$i-1]>$array[$i] && $array[$i+1]>=$array[$i])) {
	    $loc_extr++;
	}
	else if (($array[$i-1]<=$array[$i] && $array[$i+1]<$array[$i])||($array[$i-1]<$array[$i] && $array[$i+1]<=$array[$i])) {
	    $loc_extr++;
	}
}
echo $loc_extr;
?>

<?php
$num = fgets(STDIN);
$string_array = fgets(STDIN);
$loc_extr = 0;
$array = explode(' ', $string_array);
for ($i=1; $i < ($num-1); $i++) {
	if ($array[$i-1]>$array[$i] ) {
	    if ($array[$i+1]>$array[$i])
	        $loc_extr++;
	}
	else if ($array[$i-1]<$array[$i]) {
	    if ($array[$i+1]<$array[$i])
	        $loc_extr++;
	}
}
echo $loc_extr;
?>

<?php
$num = fgets(STDIN);
$string_array = fgets(STDIN);
$loc_extr = 0;
$array = explode(' ', $string_array);
for ($i=1; $i < ($num-1); $i++) {
	if ($array[$i-1]>$array[$i]) {
	    if ($array[$i+1]>$array[i])
	        $loc_extr++;
	}
	else if ($array[$i-1]<$array[$i]) {
	    if ($array[$i+1]<$array[$i])
	        $loc_extr++;
	}
}
echo $loc_extr;
?>

<?php
$num = fgets(STDIN);
$string_array = fgets(STDIN);
$loc_extr = 0;
$array = explode(' ', $string_array);
for ($i=1; $i < $num; $i++) {
	if ($array[$i-1]>$array[$i]) {
	    if ($array[$i+1]>$array[i])
	        $loc_extr++;
	}
	else if ($array[$i-1]<$array[$i]) {
	    if ($array[$i+1]<$array[$i])
	        $loc_extr++;
	}
}
echo $loc_extr;
?>

<?php
$num = fgets(STDIN);
$string_array = fgets(STDIN);
$loc_extr = 0;
$array = explode(' ', $string_array);
for ($i=1; $i < ($num-1); $i++) {
	if (($array[$i-1]>=$array[$i] && $array[$i+1]>$array[i])||($array[$i-1]>$array[$i] && $array[$i+1]>=$array[i])) {
	    $loc_extr++;
	}
	else if (($array[$i-1]>=$array[$i] && $array[$i+1]>$array[i])||($array[$i-1]>$array[$i] && $array[$i+1]>=$array[i])) {
	    $loc_extr++;
	}
}
echo $loc_extr;
?>


A new Berland businessman Vitaly is going to open a household appliances' store. All he's got to do now is to hire the staff.The store will work seven days a week, but not around the clock. Every day at least k people must work in the store.Berland has a law that determines the order of working days and non-working days. Namely, each employee must work for exactly n consecutive days, then rest for exactly m days, then work for n more days and rest for m more, and so on. Vitaly doesn't want to break the law. Fortunately, there is a loophole: the law comes into force on the day when the employee is hired. For example, if an employee is hired on day x, then he should work on days [x, x + 1, ..., x + n - 1], [x + m + n, x + m + n + 1, ..., x + m + 2n - 1], and so on. Day x can be chosen arbitrarily by Vitaly.There is one more thing: the key to the store. Berland law prohibits making copies of keys, so there is only one key. Vitaly is planning to entrust the key to the store employees. At the same time on each day the key must be with an employee who works that day — otherwise on this day no one can get inside the store. During the day the key holder can give the key to another employee, if he also works that day. The key will handed to the first hired employee at his first working day.Each employee has to be paid salary. Therefore, Vitaly wants to hire as few employees as possible provided that the store can operate normally on each day from 1 to infinity. In other words, on each day with index from 1 to infinity, the store must have at least k working employees, and one of the working employees should have the key to the store.Help Vitaly and determine the minimum required number of employees, as well as days on which they should be hired.

The first line contains three integers n, m and k (1 ≤ m ≤ n ≤ 1000, n ≠ 1, 1 ≤ k ≤ 1000).

In the first line print a single integer z — the minimum required number of employees. In the second line print z positive integers, separated by spaces: the i-th integer ai (1 ≤ ai ≤ 104) should represent the number of the day, on which Vitaly should hire the i-th employee. If there are multiple answers, print any of them.

<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = $c;
$e = $a + $b;
$f = $a;
$g = array_fill(1, $c, 1);
if($c == 1)
{
     while(TRUE)
     {
          if($f == $e)
          {
               $d++;
               array_push($g, $f);
               break;
          }
          elseif($f > $e)
          {
               break;
          }
          elseif($f < $e)
          {
               $d++;
               array_push($g, $f);
               $f += $a - 1;
          }
     }
     print $d . "\n";
     print implode(" ", $g);
}
else
{
     while(TRUE)
     {
          if($f == $e)
          {
               $d++;
               array_push($g, $f);
               break;
          }
          elseif($f > $e)
          {
               break;
          }
          elseif($f < $e)
          {
               $d++;
               array_push($g, $f);
               $f++;
               $d += $c - 1;
               for($x = 1; $x <= $c - 1; $x++)
               {
                    array_push($g, $f);
               }
               $f += $a - 1;
          }
     }
     print $d . "\n";
     print implode(" ", $g);
}
?>

<?php
list($n, $m, $k) = explode(' ', fgets(STDIN));
$a = array();
$size = $n + $m + 1;

if ($k == 1){
  for($i=1;$i<$size;$i+=$n-1)
    $a[] = $i;
  echo count($a), PHP_EOL;
  foreach($a as $i)
    echo $i, ' ';
}else{
  $prev = 1;
  while($prev < $size-1){
    if ($prev == 1){
      for($i=0;$i<$k;$i++) $a[] = $prev;
    }else{
      $a[] = $prev;
      $prev++;
      for($i=0;$i<$k-1;$i++) $a[] = $prev;
    }
    $prev+=$n-1;
  }

  if ($prev < $size) $a[] = $size-1;
  echo count($a), PHP_EOL;
  foreach($a as $i)
    echo $i, ' ';
}
echo PHP_EOL;

<?php
// Retrieve input and show output
$stream = fopen('php://stdin', 'r');
$input = stream_get_contents($stream);
$inputs = preg_split("/[\s]+/", $input);
echo func($inputs);

// Codeforces Contest 133 - Problem C
function func($in) {
	$n = $in[0];
	$m = $in[1];
	$k = $in[2];

	$ans = "";
	if ($k == 1) {
		if (($n == 2) && ($m == 2)) {
			return "4\n1 2 3 4";
		}
		if ($n >= $m + 2) {
			return "2\n1 " . $n;
		} else {
			return "3\n1 " . $n . " " . (2 * $n - 1);
		}
	}
	if ($n >= $m + 1) {
		$ans = (2 * $k) . "\n" . str_repeat("1 ", $k) . $n . str_repeat(" " . ($n + 1), $k - 1);
	} else {
		$ans = (2 * $k + 1) . "\n" . str_repeat("1 ", $k) . $n . str_repeat(" " . ($n + 1), $k - 1) . " " . (2 * $n);
	}
	return $ans;
}

// End of submission file
// Submission by chaotic_iak
?>

<?php
// Retrieve input and show output
$stream = fopen('php://stdin', 'r');
$input = stream_get_contents($stream);
$inputs = preg_split("/[\s]+/", $input);
echo func($inputs);

// Codeforces Contest 133 - Problem C
function func($in) {
	$n = $in[0];
	$m = $in[1];
	$k = $in[2];

	$ans = "";
	if ($k == 1) {
		if ($n >= $m + 2) {
			return "2\n1 " . $n;
		} else {
			return "3\n1 " . $n . " " . (2 * $n - 1);
		}
	}
	if ($n >= $m + 1) {
		$ans = (2 * $k) . "\n" . str_repeat("1 ", $k) . $n . str_repeat(" " . ($n + 1), $k - 1);
	} else {
		$ans = (2 * $k + 1) . "\n" . str_repeat("1 ", $k) . $n . str_repeat(" " . ($n + 1), $k - 1) . " " . (2 * $n);
	}
	return $ans;
}

// End of submission file
// Submission by chaotic_iak
?>


Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card i you should calculate how much Toastman's cards have the letter equal to letter on ith, then sum up all these quantities, such a number of coins Appleman should give to Toastman.Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105). The next line contains n uppercase letters without spaces — the i-th letter describes the i-th card of the Appleman.

Print a single integer – the answer to the problem.

NoteIn the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.

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

list($n,$k) = explode(" ",trim(fgets($f)));
$s = str_split(trim(fgets($f)));

$a = array();
foreach($s as $x){
    $a[$x]+=1;
}
arsort($a);

$a = array_values($a);

$i = 0;
$sum = 0;
while($k>0){
    $m = $a[$i];

    if ($m<=$k){
        $sum = $sum + ($m*$m);
        $k = $k-$m;
    } else {
        $sum = $sum + ($k*$k);
        $k = 0;
    }
    $i++;
}

echo ($sum);

<?php

function FindCards($n,$k,$cards){

    $repeatChar = count_chars($cards,1);
    rsort($repeatChar);
    $count      = 0;
    $total      = 0;
    //print_r($repeatChar);
    foreach ($repeatChar as $key => $value) {
        $check = 0;
        if($count>$k)
            break;
        $check = $count + $value;

        if($check <= $k){
            $count += $value;
            $total +=$value*$value;

        }
        else{
            $left   = $k-$count;
            $count += $left;
            $total += $left*$left;
        }
    }

    echo $total;
}

$nk       = trim(fgets(STDIN));
$cards    = trim(fgets(STDIN));
$nk       = explode(" ", $nk);
$n        = $nk[0];
$k        = $nk[1];
FindCards($n,$k,$cards);

<?php

function FindCards($n,$k,$cards){

    $repeatChar = count_chars($cards,1);
    $count      = 0;
    $total      = 0;

    foreach ($repeatChar as $key => $value) {
        $check = 0;
        if($count>$k)
            break;
        $check = $count + $value;

        if($check <= $k){
            $count += $value;
            $total +=$value*$value;

        }

    }
    if($count<$k){
        $total += $k-$count;
    }
    echo $total;
}

$nk       = trim(fgets(STDIN));
$cards    = trim(fgets(STDIN));
$nk       = explode(" ", $nk);
$n        = $nk[0];
$k        = $nk[1];
FindCards($n,$k,$cards);

<?php

function FindCards($n,$k,$cards){

    $repeatChar = count_chars($cards,1);
    $count      = 0;
    $total      = 0;

    foreach ($repeatChar as $key => $value) {
        $check = 0;
        if($count>$k)
            break;
        $check = $count + $value;

        if($check <= $k){
            $count += $value;
            $total +=$value*$value;

        }
        else{
            $left   = $k-$count;
            $count += $left;
            $total += $left*$left;
        }
    }

    echo $total;
}

$nk       = trim(fgets(STDIN));
$cards    = trim(fgets(STDIN));
$nk       = explode(" ", $nk);
$n        = $nk[0];
$k        = $nk[1];
FindCards($n,$k,$cards);


Consider a conveyor belt represented using a grid consisting of $$$n$$$ rows and $$$m$$$ columns. The cell in the $$$i$$$-th row from the top and the $$$j$$$-th column from the left is labelled $$$(i,j)$$$. Every cell, except $$$(n,m)$$$, has a direction R (Right) or D (Down) assigned to it. If the cell $$$(i,j)$$$ is assigned direction R, any luggage kept on that will move to the cell $$$(i,j+1)$$$. Similarly, if the cell $$$(i,j)$$$ is assigned direction D, any luggage kept on that will move to the cell $$$(i+1,j)$$$. If at any moment, the luggage moves out of the grid, it is considered to be lost. There is a counter at the cell $$$(n,m)$$$ from where all luggage is picked. A conveyor belt is called functional if and only if any luggage reaches the counter regardless of which cell it is placed in initially. More formally, for every cell $$$(i,j)$$$, any luggage placed in this cell should eventually end up in the cell $$$(n,m)$$$. This may not hold initially; you are, however, allowed to change the directions of some cells to make the conveyor belt functional. Please determine the minimum amount of cells you have to change.Please note that it is always possible to make any conveyor belt functional by changing the directions of some set of cells.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n, m$$$ ($$$1 \le n \le 100$$$, $$$1 \le m \le 100$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines each contain $$$m$$$ characters. The $$$j$$$-th character in the $$$i$$$-th line, $$$a_{i,j}$$$ is the initial direction of the cell $$$(i, j)$$$. Please note that $$$a_{n,m}=$$$ C.

For each case, output in a new line the minimum number of cells that you have to change to make the conveyor belt functional.

4
3 3
RRD
DDR
RRC
1 4
DDDC
6 9
RDDDDDRRR
RRDDRRDDD
RRDRDRRDR
DDDDRDDRR
DRRDRDDDR
DDRDRRDDC
1 1
C

NoteIn the first case, just changing the direction of $$$(2,3)$$$ to D is enough.You can verify that the resulting belt is functional. For example, if we place any luggage at $$$(2,2)$$$, it first moves to $$$(3,2)$$$ and then to $$$(3,3)$$$. In the second case, we have no option but to change the first $$$3$$$ cells from D to R making the grid equal to RRRC.

<?php

define('DEBUG', false);

$stdIn = STDIN;
$stdOut = STDOUT;

if (DEBUG === true) {
    $stdIn = fopen('1391B.txt', 'r');
}

fscanf($stdIn, "%d\n", $nTestCase);

for ($testcase = 0; $testcase < $nTestCase; $testcase++) {
    fscanf($stdIn, "%d %d\n", $nRows, $nColumn);
    $str = [];
    $total = 0;

    for($row = 0; $row < $nRows; $row++) {
        $str[$row] = fgets($stdIn);
        $total += $str[$row][$nColumn-1] == 'D' || $str[$row][$nColumn-1] ==  'C' ? 0 : 1;

        if ($row == $nRows-1) {
            for ($col=0; $col < $nColumn; $col++) {
                $total += $str[$row][$col] == 'R' || $str[$row][$col] ==  'C' ? 0 : 1;
            }
        }
    }

    fprintf($stdOut, "%d\n", $total);
}
if (DEBUG === true) {
    $stdIn = fclose($stdIn);
}

<?php

define('DEBUG', false);

$stdIn = STDIN;
$stdOut = STDOUT;

if (DEBUG === true) {
    $stdIn = fopen('1391B.txt', 'r');
}

fscanf($stdIn, "%d\n", $nTestCase);

for ($testcase = 0; $testcase < $nTestCase; $testcase++) {
    fscanf($stdIn, "%d %d\n", $nRows, $nColumn);
    $str = [];
    $total = 0;

    for($row = 0; $row < $nRows; $row++) {
        $str[$row] = fgets($stdIn);
        $total += $str[$row][$nColumn-1] == 'D' || $str[$row][$nColumn-1] ==  'C' ? 0 : 1;

        if ($row == $nRows-1) {
            $perfectLastRow = array_fill(0, $nColumn-1, 'R');
            $perfectLastRow[$nColumn-1] = 'C';
            $perfectLastRow[$nColumn] = "\n";
            $total += count(array_diff(array_filter(str_split($str[$row])), $perfectLastRow));
        }
    }

    fprintf($stdOut, "%d\n", $total);
}
if (DEBUG === true) {
    $stdIn = fclose($stdIn);
}


You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.

The first line contains single positive integer n (1 ≤ n ≤ 105) — the number of integers. The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Print the maximum length of an increasing subarray of the given array.


You are given an array of $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. After you watched the amazing film "Everything Everywhere All At Once", you came up with the following operation.In one operation, you choose $$$n-1$$$ elements of the array and replace each of them with their arithmetic mean (which doesn't have to be an integer). For example, from the array $$$[1, 2, 3, 1]$$$ we can get the array $$$[2, 2, 2, 1]$$$, if we choose the first three elements, or we can get the array $$$[\frac{4}{3}, \frac{4}{3}, 3, \frac{4}{3}]$$$, if we choose all elements except the third.Is it possible to make all elements of the array equal by performing a finite number of such operations?

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$)  — the number of integers. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 100$$$).

For each test case, if it is possible to make all elements equal after some number of operations, output $$$\texttt{YES}$$$. Otherwise, output $$$\texttt{NO}$$$. You can output $$$\texttt{YES}$$$ and $$$\texttt{NO}$$$ in any case (for example, strings $$$\texttt{yEs}$$$, $$$\texttt{yes}$$$, $$$\texttt{Yes}$$$ will be recognized as a positive response).

NoteIn the first test case, all elements are already equal.In the second test case, you can choose all elements except the third, their average is $$$\frac{1 + 2 + 4 + 5}{4} = 3$$$, so the array will become $$$[3, 3, 3, 3, 3]$$$.It's possible to show that it's impossible to make all elements equal in the third and fourth test cases.

<?php
$t = trim(fgets(STDIN));
$res = [];
for ($test = 0; $test < $t; $test++) {
    $n = trim(fgets(STDIN));
    $a = explode(' ', trim(fgets(STDIN)));
    $s = 0;

    for ($i = 0; $i < $n; $i++) {
        $s += $a[$i];
    }

    $ok = false;

    for ($i = 0; $i < $n; $i++) {
        if ($s - $a[$i] == $a[$i] * ($n - 1)) {
            $ok = true;
            break;
        }
    }

    if ($ok) $res[] = 'Yes';
    else $res[] = 'No';
}

foreach ($res as $r) {
    echo "$r\n";
}

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

for ($test = 0; $test < $t; $test++) {
    $n = trim(fgets(STDIN));
    $a = explode(' ', trim(fgets(STDIN)));
    $s = 0;

    for ($i = 0; $i < $n; $i++) {
        $s += $a[$i];
    }

    $res = false;

    for ($i = 0; $i < $n; $i++) {
        if ($s - $a[$i] == $a[$i] * ($n - 1)) {
            $res = true;
            break;
        }
    }

    if ($res) echo "YES\n";
    else echo "NO\n";
}

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

 $loop = true;
 $t = $loop ? IO::getInt() : 1;

 while($t--) {
      solve();
 }

 function solve()
 {
      $ans = 'NO';
      $n = IO::getInt();
      $a = IO::getArray();

      $sum = array_sum($a);
      for($i=0; $i < $n; $i++) {
           if($a[$i] == ($sum - $a[$i]) / ($n-1)) {
                $ans = 'YES';
                break;
           }
      }
      IO::pr($ans);
 }

//   $ans = 0;
//        list($n, $x) = IO::getArray();

//        $len = strlen($x);
//        if($len > $n) {
//           $ans = -1;
//        } elseif($len < $n) {
//           $maxV = maxVal($x);
//           if($maxV == '1') {
//              $ans = -1;
//           } else {
//                $ind = [0, 1];

//                foreach(str_split($x) as $ch) {
//                     IO::pr($ch);
//                }

//           }

//        }

//        IO::pr($ans);

//  function temp($x, $$aTemp, $ans) {
//       while($n > strlen($x)) {
//         IO::pr($ans . " " . strlen($x) . " " . $x . " " . $maxV);
//         if($maxV < 9 && in_array('3', str_split($x))) {
//              $maxV = 3;
//         }
//           $x = bcmul($x, $maxV);
//           $ans++;
//           $maxV = IO::getMaxValue(maxVal($x) , $maxV);
//      }
//      return $ans;
//  }
function maxVal($x) {
     $max = $x[0];
          for($i=1; $i<strlen($x); $i++) {
              $max = IO::getMaxValue($max, $x[$i]);
              if($max == 9) {
                   break;
              }
          }
          return $max;
}

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

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

 class Algor {
    public static function isPrime($n) {
         $d = 2;
         while ($n % $d != 0) {
         $d += 1;
         }

        return $d == $n;
    }

     public static function fabicon($n, $a) {
         if($n <= 1) {
             return $a[$n];
         }
         for($i=2; $i<=$n; $i++) {
             $a[$i] = $a[$i-1] + $a[$i-2];
         }

         return $a[$n];
     }

     function getRotate($a, $s, $e, $ind) {
         $ar = [];
         for ($i= $s; $i<=$e; $i++) {
             $ar[$i] = $a[$i];
             $j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
             // echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
             $a[$i] = $j < $i ? $ar[$j] : $a[$j];
         }
         return $a;
     }

}

class bigOperation {
    public static function  isBigNumber($n)
    {
        return bccomp($n, INTMAXVALUE) == 1;
    }
    // bcadd — Сложить 2 числа произвольной точности
    public static function  bcAdd($x, $y)
    {
        return bcadd($x, $y);
    }
// bccomp — Сравнение двух чисел произвольной точности
//return 1 if x>y, 0= x==y, -1 x < y
    public static function  bcComp($x, $y)
    {
        return bccomp($x, $y);
    }
// bcdiv — Операция деления для чисел произвольной точности
    public static function  bcDiv($x, $y)
    {
        return bcdiv($x, $y);
    }
// bcmod — Получает остаток от деления чисел с произвольной точностью
    public static function  bcMod($x, $y)
    {
        return bcmod($x, $y);
    }
// bcmul — Умножение двух чисел с произвольной точностью
    public static function  bcMul($x, $y)
    {
        return bcmul($x, $y);
    }
// bcpow — Возведение в степень чисел с произвольной точностью
    public static function  bcPow($x, $y)
    {
        return bcpow($x, $y);
    }
// bcpowmod — Возводит одно число в степень другого и возвращает остаток от деления результата на третье число
// bcscale — Задает количество чисел после десятичной точки по умолчанию для всех bc math функций.
// bcsqrt — Извлекает квадратный корень из числа с произвольной точностью
    public static function  bcSqrt($x, $y)
    {
        return bcsqrt($x, $y);
    }
// bcsub — Вычитает одно число с произвольной точностью из другого
    public static function  bcSub($x, $y)
    {
        return bcsub($x, $y);
    }
    public static function getMaxValue($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    public static function getMinValue($x, $y) {
        return bccomp($x, $y) == 1 ? $y : $x;
    }

    public static function getDareje($n, $k) {
        if($k == 0) {
            return 1;
        }
        return bcmul($n, self::getDareje($n, $k-1));
    }
}

class Sorting
{
    public static function mergeSort($aArray) {
        if(count($aArray) <= 1) {
            return $aArray;
        }
        $aLeft = [];
        $aRight = [];
        $n =floor(count($aArray) / 2);
        for($i = 0; $i <$n; $i++) {
            $aLeft[] = $aArray[$i];
        }
        for($i = $n; $i <count($aArray); $i++) {
            $aRight[] = $aArray[$i];
        }

        return self::merge(self::mergeSort($aLeft), self::mergeSort($aRight));
    }

    public static function merge($aLeft, $aRight) {
        $aResult = [];
        $iL = 0;
        $iR = 0;

        while($iL < count($aLeft) && $iR < count($aRight)) {
            if($aLeft[$iL] <= $aRight[$iR]) {
                $aResult[] = $aLeft[$iL];
                $iL++;
            } else {
                $aResult[] = $aRight[$iR];
                $iR++;
            }
        }

        while($iL < count($aLeft)) {
            $aResult[] = $aLeft[$iL];
            $iL++;
        }
        while($iR < count($aRight)) {
            $aResult[] = $aRight[$iR];
            $iR++;
        }

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
    $t = trim(fgets(STDIN));
    for ($t1=1; $t1<=$t; $t1++) {
        $n = trim(fgets(STDIN));
        $a = explode(' ', trim(fgets(STDIN)));

        $iSum = 0;
        for ($i=0; $i<$n; $i++) {
            $iSum  = bcadd($a[$i], $iSum);
        }

        $b = false;
        for ($i=0; $i<$n; $i++) {
            $iS = bcsub($iSum, $a[$i]);
            if (bcmod($iS, $n-1) == 0) {
                $iSred = bcdiv($iS, $n-1);
                if ($iSred == $a[$i]) {
                    $b = true;
                    echo 'YES' . PHP_EOL;
                    break;
                }
            }
        }
        if (!$b) {
            echo 'NO' . PHP_EOL;
        }
    }

<?php
$t = trim(fgets(STDIN));
$ans = [];
for($i=0; $i<$t; $i++) {
    $n = trim(fgets(STDIN));
    $input = explode(' ', trim(fgets(STDIN)));

    $su = 0;
    $found = false;
    for($k=0; $k<$n; $k++) {
        $sum = 0;
        for($j=0; $j<$n; $j++) {
            if($su !== $j) {
                $sum += $input[$j];
            }
        }
        if(($sum / ($n - 1)) == $input[$su]) {
            $ans[]= 'yes';
            $found = true;
            $su++;
            break;
        }
        $su++;
    }
    if($found === false) {
        $ans[] = 'no';
    }
}

foreach ($ans as $v) {
    echo "$v\n";
}