Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.

The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct.

Print the minimum area of the city that can cover all the mines with valuable resources.


You are given an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. Your task is to find the number of connected components which are cycles.Here are some definitions of graph theory.An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of vertices. All edges are bidirectional (i.e. if a vertex $$$a$$$ is connected with a vertex $$$b$$$, a vertex $$$b$$$ is also connected with a vertex $$$a$$$). An edge can't connect vertex with itself, there is at most one edge between a pair of vertices.Two vertices $$$u$$$ and $$$v$$$ belong to the same connected component if and only if there is at least one path along edges connecting $$$u$$$ and $$$v$$$.A connected component is a cycle if and only if its vertices can be reordered in such a way that:  the first vertex is connected with the second vertex by an edge,  the second vertex is connected with the third vertex by an edge,  ...  the last vertex is connected with the first vertex by an edge,  all the described edges of a cycle are distinct. A cycle doesn't contain any other edges except described above. By definition any cycle contains three or more vertices.    There are $$$6$$$ connected components, $$$2$$$ of them are cycles: $$$[7, 10, 16]$$$ and $$$[5, 11, 9, 15]$$$.

The first line contains two integer numbers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) — number of vertices and edges. The following $$$m$$$ lines contains edges: edge $$$i$$$ is given as a pair of vertices $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$u_i \ne v_i$$$). There is no multiple edges in the given graph, i.e. for each pair ($$$v_i, u_i$$$) there no other pairs ($$$v_i, u_i$$$) and ($$$u_i, v_i$$$) in the list of edges.

Print one integer — the number of connected components which are also cycles.

NoteIn the first example only component $$$[3, 4, 5]$$$ is also a cycle.The illustration above corresponds to the second example.


Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of n points (called vertices), some of which are connected using n - 1 line segments (edges) so that each pair of vertices is connected by a path (a sequence of one or more edges).To decipher the prophecy, Heidi needs to perform a number of steps. The first is counting the number of lifelines in the tree – these are paths of length 2, i.e., consisting of two edges. Help her!

The first line of the input contains a single integer n – the number of vertices in the tree (1 ≤ n ≤ 10000). The vertices are labeled with the numbers from 1 to n. Then n - 1 lines follow, each describing one edge using two space-separated numbers a b – the labels of the vertices connected by the edge (1 ≤ a < b ≤ n). It is guaranteed that the input represents a tree.

Print one integer – the number of lifelines in the tree.

NoteIn the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5.


Consider the set of all nonnegative integers: $$${0, 1, 2, \dots}$$$. Given two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^4$$$). We paint all the numbers in increasing number first we paint $$$0$$$, then we paint $$$1$$$, then $$$2$$$ and so on.Each number is painted white or black. We paint a number $$$i$$$ according to the following rules:    if $$$i = 0$$$, it is colored white;   if $$$i \ge a$$$ and $$$i - a$$$ is colored white, $$$i$$$ is also colored white;   if $$$i \ge b$$$ and $$$i - b$$$ is colored white, $$$i$$$ is also colored white;   if $$$i$$$ is still not colored white, it is colored black. In this way, each nonnegative integer gets one of two colors.For example, if $$$a=3$$$, $$$b=5$$$, then the colors of the numbers (in the order from $$$0$$$) are: white ($$$0$$$), black ($$$1$$$), black ($$$2$$$), white ($$$3$$$), black ($$$4$$$), white ($$$5$$$), white ($$$6$$$), black ($$$7$$$), white ($$$8$$$), white ($$$9$$$), ...Note that:    It is possible that there are infinitely many nonnegative integers colored black. For example, if $$$a = 10$$$ and $$$b = 10$$$, then only $$$0, 10, 20, 30$$$ and any other nonnegative integers that end in $$$0$$$ when written in base 10 are white. The other integers are colored black.   It is also possible that there are only finitely many nonnegative integers colored black. For example, when $$$a = 1$$$ and $$$b = 10$$$, then there is no nonnegative integer colored black at all. Your task is to determine whether or not the number of nonnegative integers colored black is infinite.If there are infinitely many nonnegative integers colored black, simply print a line containing "Infinite" (without the quotes). Otherwise, print "Finite" (without the quotes).

The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then $$$t$$$ lines follow, each line contains two space-separated integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^4$$$).

For each test case, print one line containing either "Infinite" or "Finite" (without the quotes). Output is case-insensitive (i.e. "infinite", "inFiNite" or "finiTE" are all valid answers).

<?php

function gcd($a,$b)
{
    while($b)
    {
        $a%=$b;
        $tmp=$b;
        $b=$a;
        $a=$tmp;

    }
    return $a;
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";$d=0;$t=0;
    $x=trim(fgets($handle));
    for($i=0;$i<$x;$i++)
    {
        $str=trim(fgets($handle));
        $str1=explode(" ",$str);
        $a=$str1[0];
        $b=$str1[1];

            if(gcd($a,$b)!=1)
            {
                echo "Infinite\n";
            }else{
                echo "Finite\n";
            }

    }

}

solve();
?>

<?php

function gcd($a,$b)
{
    while($b)
    {
        $a%=$b;
        $tmp=$b;
        $b=$a;
        $a=$tmp;

    }
    return $a;
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";$d=0;$t=0;
    $x=trim(fgets($handle));
    for($i=0;$i<$x;$i++)
    {
        $str=trim(fgets($handle));
        $str1=explode(" ",$str);
        $a=$str1[0];
        $b=$str1[1];

            if(gcd($a,$b)==1)
            {
                echo "Infinite\n";
            }else{
                echo "Finite\n";
            }

    }

}

solve();
?>

<?php

function check($s,$d)
{
    $c=0;$r=0;
    for ($i=0;$i<$d;$i++)
    {
        if($s[$i]=='A')$c++;
        else $r++;
    }

    if($c>$r)
        return "Anton";
    else if($c<$r)
        return "Danik";
    else
        return "Friendship";
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";$d=0;$t=0;
    $x=trim(fgets($handle));
    for($i=0;$i<$x;$i++)
    {
        $str=trim(fgets($handle));
        $str1=explode(" ",$str);
        $a=$str1[0];
        $b=$str1[1];
        if($a<=$b)
        {
            $black=$a-1;
            $white=$b-$a+1;
            if($white+1<$black)
            {
                echo "Infinite\n";
            }else{
                echo "Finite\n";
            }
        }else{
            $black=$b-1;
            $white=$a-$b+1;
            if($white+1<$black)
            {
                echo "Infinite\n";
            }else{
                echo "Finite\n";
            }
        }
    }

}

solve();
?>

<?php

function check($s,$d)
{
    $c=0;$r=0;
    for ($i=0;$i<$d;$i++)
    {
        if($s[$i]=='A')$c++;
        else $r++;
    }

    if($c>$r)
        return "Anton";
    else if($c<$r)
        return "Danik";
    else
        return "Friendship";
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";$d=0;$t=0;
    $x=trim(fgets($handle));
    for($i=0;$i<$x;$i++)
    {
        $str=trim(fgets($handle));
        $str1=explode(" ",$str);
        $a=$str1[0];
        $b=$str1[1];
        if($a<=$b)
        {
            $black=$a-1;
            $white=$b-$a;
            if($white<$black)
            {
                echo "Infinite\n";
            }else{
                echo "Finite\n";
            }
        }else{
            $black=$b-1;
            $white=$a-$b;
            if($white<$black)
            {
                echo "Infinite\n";
            }else{
                echo "Finite\n";
            }
        }
    }

}

solve();
?>

<?php

function check($s,$d)
{
    $c=0;$r=0;
    for ($i=0;$i<$d;$i++)
    {
        if($s[$i]=='A')$c++;
        else $r++;
    }

    if($c>$r)
        return "Anton";
    else if($c<$r)
        return "Danik";
    else
        return "Friendship";
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";$d=0;$t=0;
    $x=trim(fgets($handle));
    for($i=0;$i<$x;$i++)
    {
        $str=trim(fgets($handle));
        $str1=explode(" ",$str);
        $a=$str1[0];
        $b=$str1[1];
        if($a<=$b)
        {
            $black=$a-1;
            $white=$a-$black;
            if($white+1<$black)
            {
                echo "Infinite\n";
            }else{
                echo "Finite\n";
            }
        }else{
            $black=$b-1;
            $white=$b-$black;
            if($white+1<$black)
            {
                echo "Infinite";
            }else{
                echo "Finite";
            }
        }
    }

}

solve();
?>

<?php

function check($s,$d)
{
    $c=0;$r=0;
    for ($i=0;$i<$d;$i++)
    {
        if($s[$i]=='A')$c++;
        else $r++;
    }

    if($c>$r)
        return "Anton";
    else if($c<$r)
        return "Danik";
    else
        return "Friendship";
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($local, "r");
    $s="";$d=0;$t=0;
    $x=trim(fgets($handle));
    for($i=0;$i<$x;$i++)
    {
        $str=trim(fgets($handle));
        $str1=explode(" ",$str);
        $a=$str1[0];
        $b=$str1[1];
        if($a<=$b)
        {
            $black=$a-1;
            $white=$a-$black;
            if($white+1<$black)
            {
                echo "Infinite\n";
            }else{
                echo "Finite\n";
            }
        }else{
            $black=$b-1;
            $white=$b-$black;
            if($white+1<$black)
            {
                echo "Infinite\n";
            }else{
                echo "Finite\n";
            }
        }
    }

}

solve();
?>

    <?php

    function check($s,$d)
    {
        $c=0;$r=0;
        for ($i=0;$i<$d;$i++)
        {
            if($s[$i]=='A')$c++;
            else $r++;
        }

        if($c>$r)
            return "Anton";
        else if($c<$r)
            return "Danik";
        else
            return "Friendship";
    }
    function solve()
    {
        $server="php://stdin";
        $local="input.txt";
        $handle = fopen($server, "r");
        $s="";$d=0;$t=0;
        $x=trim(fgets($handle));
        for($i=0;$i<$x;$i++)
        {
            $str=trim(fgets($handle));
            $str1=explode(" ",$str);
            $a=$str1[0];
            $b=$str1[1];
            if($a<=$b)
            {
                $black=$a-1;
                $white=$a-$black;
                if($white+1<$black)
                {
                    echo "Infinite\n";
                }else{
                    echo "Finite\n";
                }
            }else{
                $black=$b-1;
                $white=$b-$black;
                if($white+1<$black)
                {
                    echo "Infinite\n";
                }else{
                    echo "Finite\n";
                }
            }
        }

    }

    solve();
    ?>


Polycarp is a great fan of television.He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri.Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV.Polycarp wants to check out all n shows. Are two TVs enough to do so?

The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of shows. Each of the next n lines contains two integers li and ri (0 ≤ li < ri ≤ 109) — starting and ending time of i-th show.

If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).


This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs n ingredients, and for each ingredient she knows the value ai — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all n ingredients.Apollinaria has bi gram of the i-th ingredient. Also she has k grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the n ingredients and can be used for baking cookies.Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.

The first line of the input contains two positive integers n and k (1 ≤ n, k ≤ 1000) — the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 1000), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has.

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.

NoteIn the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredient with the index 3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.

<?

$a = array();
$b = array();
//$fp = fopen('input.txt', 'r');
fscanf(STDIN, "%d %d\n", $n, $k);
$a = explode(' ', fgets(STDIN));
$b = explode(' ', fgets(STDIN));

$l = 0; $r = PHP_INT_MAX;
for($i = 0; $i < 50; $i++){
    $m = ($l + $r)/2;
    $m = intval($m);
    if(can($m)){
        $l = $m;
    }else{
        $r = $m;
    }
}

echo $l;

function can($x){
    $need = 0;
    global $n, $a, $b, $k;
    for($i = 0; $i < $n; $i++){
        $need += max(0, $a[$i]*1*$x - $b[$i]);
        if($need > $k) return false;
    }

    return $need <= $k;
}

<?

new Planning();

class Planning{

    private $n;
    private $k;
    private $a = array();
    private $b = array();
    private $inputFilename = '';

    public function __construct($inputFilename = 'input.txt')
    {
        $this->inputFilename = $inputFilename;
        $this->readData();
        echo $this->findSolution();
    }

    public function readData()
    {
        //$fp = fopen($this->inputFilename, 'r');
        fscanf(STDIN, "%d %d\n", $this->n, $this->k);
        $this->a = explode(' ', fgets(STDIN));
        $this->b = explode(' ', fgets(STDIN));
    }

    private function findSolution()
    {
        $l = 0; $r = 1E+15;

        for($i = 0; $i < 50; $i++){
            $m = ($l + $r)/2;
            $m = (int)$m;
            if($this->can($m)){
                $l = $m;
            }else{
                $r = $m;
            }
        }

        return $l;
    }

    private function can($x)
    {
        $need = 0;
        for($i = 0; $i < $this->n; $i++){
            $need += max(0, $this->a[$i]*1*$x - $this->b[$i]);
            if($need > $this->k) return false;
        }

        return $need <= $this->k;
    }

}

<?

$a = array();
$b = array();
//$fp = fopen('input.txt', 'r');
fscanf(STDIN, "%d %d\n", $n, $k);
$a = explode(' ', fgets(STDIN));
$b = explode(' ', fgets(STDIN));

$l = 0; $r = 10000000000;
for($i = 0; $i < 50; $i++){
    $m = (int)($l + $r)/2;
    if(can($m)){
        $l = $m;
    }else{
        $r = $m;
    }
}

echo $l;

function can($x){
    $need = 0;
    global $n, $a, $b, $k;
    for($i = 0; $i < $n; $i++){
        $need += max(0, $a[$i]*1*$x - $b[$i]);
        if($need > $k) return false;
    }

    return $need <= $k;
}


There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.

The first line contains a sequence of letters without spaces s1s2... sn (1 ≤ n ≤ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.

Print a single integer — the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.

NoteIn the first test case the sequence of changes looks as follows: MFM  →  FMM.The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF  →  MFMF  →  FMFM  →  FFMM.

$str = trim(fgets(STDIN));
        //$str = "MFMFM";
        $needle = "MF";
        $replace = "FM";
        $seconds = 0;
      while(preg_match("/$needle/i", $str)){
            $seconds++;
            $str = str_replace($needle, $replace, $str);
        }
        print $seconds;

$str = trim(fgets(STDIN));
        $needle = "MF";
        $replace = "FM";
        $seconds = 0;
        $hasRotations = TRUE;
        while($hasRotations){
            $hasRotations = FALSE;
            for($i=0;$i<strlen($str)-1;$i++){
               if(strcmp($str[$i].$str[$i+1], $needle) == 0){
                   $str = str_replace($needle, $replace, $str);
                   $seconds++;
                   $hasRotations = TRUE;
               }
            }
        }

        $str = trim(fgets(STDIN));
        //$str = "FFMMM";
        $needle = "MF";
        $replace = "FM";
        $seconds = 0;
        $hasRotations = TRUE;
        while($hasRotations){
            $hasRotations = FALSE;
            for($i=0;$i<strlen($str)-1;$i++){
               if(strcmp($str[$i].$str[$i+1], $needle) == 0){
                   $str = str_replace($needle, $replace, $str);
                   $seconds++;
                   $hasRotations = TRUE;
               }
            }
        }
        /*while(preg_match("/$needle/i", $str)){
            $seconds++;
            $str = str_replace($needle, $replace, $str);
        }*/
        print $seconds;

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

$t = 0;

$fcount = 0;

$len = strlen($str);
for ($i = 0; $i < $len; $i++) {
	if ($str[$i] == "F") {
		$t = (($i - $fcount) > t) ? $i - $fcount : $t+1;
		$fcount++;
	}
}

print $t;

<?
$str = trim(fgets(STDIN));
//$str = "MMFF";
$t = 0;

$fcount = 0;

$len = strlen($str);
for ($i = 0; $i < $len; $i++) {
    if ($str[$i] == "F") {
        $ti = $i - $fcount;
        $t = ($ti > $t) ? $ti : $t+1;
        $fcount++;
    }
}

print $t;

<?
$str = trim(fgets(STDIN));
        //$str = "MFMFM";
        $needle = "MF";
        $replace = "FM";
        $seconds = 0;
      	while(strripos($str, $needle)) {
            $seconds++;
            $str = str_replace($needle, $replace, $str);
        }
        print $seconds;

<?
$str = trim(fgets(STDIN));
        //$str = "MFMFM";
        $needle = "MF";
        $replace = "FM";
        $seconds = 0;
      	while(stripos($str, $needle)) {
            $seconds++;
            $str = str_replace($needle, $replace, $str);
        }
        print $seconds;

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

$t = 0;

$fcount = 0;

$len = strlen($str);
for ($i; $i >= $len; $i++) {
    if ($str[$i] == "F") {
        $t = (($i - $fcount) > t) ? $i - $fcount : $t++;
        $fcount++;
    }
}

print $t;

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

$t = 0;

$fcount = 0;

$len = strlen($str);
for ($i = 0; $i < $len; $i++) {
	if ($str[$i] == "F") {
		$t = (($i - $fcount) > t) ? $i - $fcount : $t++;
		$fcount++;
	}
}

print $t;

<?
$str = trim(fgets(STDIN));
        //$str = "MFMFM";
        $needle = "MF";
        $replace = "FM";
        $seconds = 0;
      	while(strpos($str, $needle)) {
            $seconds++;
            $str = str_replace($needle, $replace, $str);
        }
        print $seconds;

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

$t = 0;

$fcount = 0;

$len = strlen($str);
for ($i = 0; $i >= $len; $i++) {
	if ($str[$i] == "F") {
		$t = (($i - $fcount) > t) ? $i - $fcount : $t++;
		$fcount++;
	}
}

print $t;

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

$t = 0;

$fcount = 0;

$len = strlen($str);
for ($i = 0; $i < $len; $i++) {
    if ($str[$i] == "F") {
        $t = (($i - $fcount) > $t) ? $i - $fcount : $t++;
        $fcount++;
    }
}

print $t;


You are given integer $$$n$$$. You have to arrange numbers from $$$1$$$ to $$$2n$$$, using each of them exactly once, on the circle, so that the following condition would be satisfied:For every $$$n$$$ consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard $$$2n$$$ numbers differ not more than by $$$1$$$.For example, choose $$$n = 3$$$. On the left you can see an example of a valid arrangement: $$$1 + 4 + 5 = 10$$$, $$$4 + 5 + 2 = 11$$$, $$$5 + 2 + 3 = 10$$$, $$$2 + 3 + 6 = 11$$$, $$$3 + 6 + 1 = 10$$$, $$$6 + 1 + 4 = 11$$$, any two numbers differ by at most $$$1$$$. On the right you can see an invalid arrangement: for example, $$$5 + 1 + 6 = 12$$$, and $$$3 + 2 + 4 = 9$$$, $$$9$$$ and $$$12$$$ differ more than by $$$1$$$.

The first and the only line contain one integer $$$n$$$ ($$$1 \le n \le 10^5$$$).

If there is no solution, output "NO" in the first line.  If there is a solution, output "YES" in the first line. In the second line output $$$2n$$$ numbers — numbers from $$$1$$$ to $$$2n$$$ in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them.

NoteExample from the statement is shown for the first example. It can be proved that there is no solution in the second example.


The BFS algorithm is defined as follows.  Consider an undirected graph with vertices numbered from $$$1$$$ to $$$n$$$. Initialize $$$q$$$ as a new queue containing only vertex $$$1$$$, mark the vertex $$$1$$$ as used.  Extract a vertex $$$v$$$ from the head of the queue $$$q$$$.  Print the index of vertex $$$v$$$.  Iterate in arbitrary order through all such vertices $$$u$$$ that $$$u$$$ is a neighbor of $$$v$$$ and is not marked yet as used. Mark the vertex $$$u$$$ as used and insert it into the tail of the queue $$$q$$$.  If the queue is not empty, continue from step 2.  Otherwise finish. Since the order of choosing neighbors of each vertex can vary, it turns out that there may be multiple sequences which BFS can print.In this problem you need to check whether a given sequence corresponds to some valid BFS traversal of the given tree starting from vertex $$$1$$$. The tree is an undirected graph, such that there is exactly one simple path between any two vertices.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) which denotes the number of nodes in the tree.  The following $$$n - 1$$$ lines describe the edges of the tree. Each of them contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$) — the endpoints of the corresponding edge of the tree. It is guaranteed that the given graph is a tree. The last line contains $$$n$$$ distinct integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the sequence to check.

Print "Yes" (quotes for clarity) if the sequence corresponds to some valid BFS traversal of the given tree and "No" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower).

NoteBoth sample tests have the same tree in them.In this tree, there are two valid BFS orderings:   $$$1, 2, 3, 4$$$,  $$$1, 3, 2, 4$$$. The ordering $$$1, 2, 4, 3$$$ doesn't correspond to any valid BFS order.

<?php
class QueStruct
{
	public $data;
	public $next;
	public function __construct($data){
        $this->data = $data;
        $this->next = null;
	}
}
class Queue
{
	protected $head;
	protected $trail;
	protected $num;
	public function __construct(){
		$this->num = 0;
		$this->head = null;
		$this->trail = null;
	}
	public function push($data){
       $this->num++;
       if($this->head == null){
       	 $this->head = $this->trail = new QueStruct($data);
       }
       else {
         $this->trail->next = new QueStruct($data);
         $this->trail = $this->trail->next;
       }
	}
    public function front(){
    	return $this->head->data;
    }
    public function pop()
    {
        $this->num--;
        $p = &$this->head;
        $this->head = $this->head->next;
        if($this->num == 0)
        	$this->trail = $this->head = null;
        unset($p);
    }
    public function size()
    {
    	return $this->num;
    }
    public function isEmpty()
    {
        if($this->num == 0)
        	return true;
        return false;
    }
}
fscanf(STDIN,"%d",$n);
$edge = array();
$mark_point = array();
for($i = 1;$i < $n;$i++)
{
	fscanf(STDIN,"%d %d",$point_x,$point_y);
	if(!isset($edge[$point_x])){
         $edge[$point_x] = array();
	}
	if(!isset($edge[$point_y])){
		$edge[$point_y] = array();
	}
    array_push($edge[$point_x],$point_y);
    array_push($edge[$point_y],$point_x);
}

$str = trim(fgets(STDIN));
$squ= explode(' ',$str);
if($n == 1){
	echo "Yes\n";
	return ;
}
for($i = 0;$i < $n;$i++)
{
	$squence[$i] = (int)$squ[$i];
	$mark_point[$squence[$i]] = $i;
}
for($i = 1;$i <= $n; $i++)
{
    if(isset($edge[$i]))
    	usort($edge[$i],'cmp');
}
if(bfs($edge,$squence)){
	echo "Yes\n";
}
else echo "No\n";
function cmp($first,$second)
{
	global $mark_point;
	if($mark_point[$first] < $mark_point[$second]){
		return -1;
	}
	else if($mark_point[$first] > $mark_point[$second]){
		return 1;
	}
	return 0;
}
function bfs(&$edge,$original)
{
   if($original[0] != 1)
     return false;
   $cnt = 1;
   global $mark_point;
   $queue = new Queue();
   $vis_flag = array();
   if(isset($edge[1])){
      $vis_flag[1] = true;
      $num = count($edge[1]);
      for($i = 0;$i < $num;$i++)
      {   $id = $edge[1][$i];
      	  if(!isset($vis_flag[$id]))
      	  {
      	  	$vis_flag[$id] = true;
      	  	if($mark_point[$id] < $mark_point[1])
      	  		return false;
      	  	$queue->push($id);
      	  }
      }
   }
   else return false;
   while(!$queue->isEmpty())
   {
   	 $point = $queue->front();
   	 if($point != $original[$cnt++])
   	 	return false;
     $queue->pop();
     if(!isset($edge[$point]))
     	continue;
     $num = count($edge[$point]);
     for($i = 0;$i < $num;$i++)
     {
         $id = $edge[$point][$i];
         if(!isset($vis_flag[$id]))
         {
         	$vis_flag[$id] = true;
         	if($mark_point[$id] < $mark_point[$point])
         		return false;
            $queue->push($id);
         }
     }
   }
   return true;
}

<?php
fscanf(STDIN,"%d",$n);
$edge = array();
$mark_point = array();
$vis_flag  = array();
for($i = 1;$i < $n;$i++)
{
	fscanf(STDIN,"%d %d",$point_x,$point_y);
	if(!isset($edge[$point_x])){
         $edge[$point_x] = array();
	}
	if(!isset($edge[$point_y])){
		$edge[$point_y] = array();
	}
    array_push($edge[$point_x],$point_y);
    array_push($edge[$point_y],$point_x);
}
dfs_mark(1,0,$mark_point,$vis_flag);
$str = trim(fgets(STDIN));
$squ= explode(' ',$str);
if($n == 1){
	echo "Yes\n";
	return ;
}
for($i = 0;$i < $n;$i++)
{
	$squence[$i+1] = (int)$squ[$i];
}
for($i = 1;$i <= $n;$i++){
	//fscanf(STDIN,"%d",$sequence[$i]);
	$squence[$i] = $mark_point[$squence[$i]];
}
for($i = 2;$i <= $n;$i++)
{
	if($squence[$i] < $squence[$i - 1])
	{
		echo "No\n";
		return ;
	}
}
echo "Yes\n";
function dfs_mark($point_id,$mark,&$mark_point,&$vis_flag)
{
     global $edge;
     $vis_flag[$point_id] = true;
     $mark_point[$point_id] = $mark;
     //var_dump($point_id,$mark);
     if(!isset($edge[$point_id]))
     	return ;
     $edge_num = count($edge[$point_id]);
     for($i = 0;$i < $edge_num;$i++)
     {
     	$id = $edge[$point_id][$i];
     	if(!isset($vis_flag[$id])){
     		dfs_mark($id,$mark + 1,$mark_point,$vis_flag);
     	}
     }
}

<?php
class QueStruct
{
	public $data;
	public $next;
	public function __construct($data){
        $this->data = $data;
        $this->next = null;
	}
}
class Queue
{
	protected $head;
	protected $trail;
	protected $num;
	public function __construct(){
		$this->num = 0;
		$this->head = null;
		$this->trail = null;
	}
	public function push($data){
       $this->num++;
       if($this->head == null){
       	 $this->head = $this->trail = new QueStruct($data);
       }
       else {
         $this->trail->next = new QueStruct($data);
         $this->trail = $this->trail->next;
       }
	}
    public function front(){
    	return $this->head->data;
    }
    public function pop()
    {
        $this->num--;
        $p = &$this->head;
        $this->head = $this->head->next;
        if($this->num == 0)
        	$this->trail = $this->head = null;
        unset($p);
    }
    public function size()
    {
    	return $this->num;
    }
    public function isEmpty()
    {
        if($this->num == 0)
        	return true;
        return false;
    }
}
fscanf(STDIN,"%d",$n);
$edge = array();
$mark_point = array();
for($i = 1;$i < $n;$i++)
{
	fscanf(STDIN,"%d %d",$point_x,$point_y);
	if(!isset($edge[$point_x])){
         $edge[$point_x] = array();
	}
	if(!isset($edge[$point_y])){
		$edge[$point_y] = array();
	}
    array_push($edge[$point_x],$point_y);
    array_push($edge[$point_y],$point_x);
}

$str = trim(fgets(STDIN));
$squ= explode(' ',$str);
if($n == 1){
	echo "Yes\n";
	return ;
}
for($i = 0;$i < $n;$i++)
{
	$squence[$i] = (int)$squ[$i];
	$mark_point[$squence[$i]] = $i;
}
for($i = 1;$i < $n; $i++)
{
    if(isset($edge[$i]))
    	usort($edge[$i],'cmp');
}
if(bfs($edge,$squence)){
	echo "Yes\n";
}
else echo "No\n";
function cmp($first,$second)
{
	global $mark_point;
	if($mark_point[$first] < $mark_point[$second]){
		return -1;
	}
	else if($mark_point[$first] > $mark_point[$second]){
		return 1;
	}
	return 0;
}
function bfs(&$edge,$original)
{
   if($original[0] != 1)
     return false;
   $cnt = 1;
   global $mark_point;
   $queue = new Queue();
   $vis_flag = array();
   if(isset($edge[1])){
      $vis_flag[1] = true;
      $num = count($edge[1]);
      for($i = 0;$i < $num;$i++)
      {   $id = $edge[1][$i];
      	  if(!isset($vis_flag[$id]))
      	  {
      	  	$vis_flag[$id] = true;
      	  	if($mark_point[$id] < $mark_point[1])
      	  		return false;
      	  	$queue->push($id);
      	  }
      }
   }
   else return false;
   while(!$queue->isEmpty())
   {
   	 $point = $queue->front();
   	 if($point != $original[$cnt++])
   	 	return false;
     $queue->pop();
     if(!isset($edge[$point]))
     	continue;
     $num = count($edge[$point]);
     for($i = 0;$i < $num;$i++)
     {
         $id = $edge[$point][$i];
         if(!isset($vis_flag[$id]))
         {
         	$vis_flag[$id] = true;
         	if($mark_point[$id] < $mark_point[$point])
         		return false;
            $queue->push($id);
         }
     }
   }
   return true;
}


You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.

For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.

NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.

<?php
$a = trim(fgets(STDIN));
for($i = 1; $i <= $a; $i++)
{
	$x=trim(fgets(STDIN));
	print "1 ".($x-1). "\n";
}

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t= trim(fgets($handle));
for($k=0;$k<$t;$k++)
{
    $n= trim(fgets($handle));
    echo '1'." ".($n-1)."\n";

}

<?php

	function gcd ($a, $b) {
		return $b ? gcd ($b, $a % $b) : $a;
	}

	$t = trim(fgets(STDIN));

	$ans = '';
	for ($o = 0; $o < $t; $o++) {
		$x = trim(fgets(STDIN));
		$ans .= "1 ".($x-1)."\n";
	}

	print $ans;

?>


You are given an undirected unweighted connected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.Your task is to find any spanning tree of this graph such that the maximum degree over all vertices is maximum possible. Recall that the degree of a vertex is the number of edges incident to it.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$n - 1 \le m \le min(2 \cdot 10^5, \frac{n(n-1)}{2})$$$) — the number of vertices and edges, respectively. The following $$$m$$$ lines denote edges: edge $$$i$$$ is represented by a pair of integers $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$u_i \ne v_i$$$), which are the indices of vertices connected by the edge. There are no loops or multiple edges in the given graph, i. e. for each pair ($$$v_i, u_i$$$) there are no other pairs ($$$v_i, u_i$$$) or ($$$u_i, v_i$$$) in the list of edges, and for each pair $$$(v_i, u_i)$$$ the condition $$$v_i \ne u_i$$$ is satisfied.

Print $$$n-1$$$ lines describing the edges of a spanning tree such that the maximum degree over all vertices is maximum possible. Make sure that the edges of the printed spanning tree form some subset of the input edges (order doesn't matter and edge $$$(v, u)$$$ is considered the same as the edge $$$(u, v)$$$). If there are multiple possible answers, print any of them.

NotePicture corresponding to the first example: In this example the number of edges of spanning tree incident to the vertex $$$3$$$ is $$$3$$$. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer.Picture corresponding to the second example: In this example the number of edges of spanning tree incident to the vertex $$$1$$$ is $$$3$$$. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer.Picture corresponding to the third example: In this example the number of edges of spanning tree incident to the vertex $$$2$$$ is $$$4$$$. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer. But because this example is symmetric, we can choose almost the same spanning tree but with vertex $$$5$$$ instead of $$$2$$$.


There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters.

The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = "";
for($x = 0; $x < strlen($c); $x++)
{
     if(is_numeric($c[$x]) == TRUE)
     {
          $d .= $c[$x];
     }
     else
     {
          if(ctype_upper($c[$x]) == TRUE)
          {
               $e = strtolower($c[$x]);
               for($y = 0; $y < strlen($a); $y++)
               {
                    if($a[$y] == $e)
                    {
                         break;
                    }
               }
               $f = strtoupper($b[$y]);
               $d .= $f;
          }
          else
          {
               $e = $c[$x];
               for($y = 0; $y < strlen($a); $y++)
               {
                    if($a[$y] == $e)
                    {
                         break;
                    }
               }
               $d .= $b[$y];
          }
     }
}
print $d;
?>

<?php

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

while ($s = fgets($fh, 1024))
  $alph_src[] = $s;

for ($i = 0; $i < strlen($alph_src[0]); $i++)
{
  $alph[$alph_src[0][$i]] = $alph_src[1][$i];
  $alph[strtoupper($alph_src[0][$i])] = strtoupper($alph_src[1][$i]);
}

for ($i = 0; $i < strlen($alph_src[2]); $i++)
{
  if (is_numeric($alph_src[2][$i]))
    $res[$i] = $alph_src[2][$i];
  else
    $res[$i] = $alph[$alph_src[2][$i]];
}

echo implode('', $res);

<?php
$str1=trim(fgets(STDIN));
$str2=trim(fgets(STDIN));
$str3=trim(fgets(STDIN));
$str4=strtoupper($str2);
for ($i=0; $i <strlen($str3) ; $i++)
 {
 	if(ord($str3[$i])>=48 && ord($str3[$i])<=57)
 		echo "$str3[$i]";
   else if(ord($str3[$i])>=65&&ord($str3[$i])<=90)
   {
			for ($j=0; $j <strlen($str1) ; $j++)
		     {
		       if(strtolower($str3[$i])==$str1[$j])
		       	   echo "$str4[$j]";

		     }
   }
   else {
   				for ($j=0; $j <strlen($str1) ; $j++)
		     {
		       if(strtolower($str3[$i])==$str1[$j])
		       	   echo "$str2[$j]";

		     }
   }

}

<?php
$a=trim(fgets(STDIN));
$b=trim(fgets(STDIN));
$c=trim(fgets(STDIN));
$d='';
$n=strlen($c);
for ($i=0;$i<$n;$i++){
    if (is_numeric($c[$i])){
        $d=$d.$c[$i];
    }
    else if(ord($c[$i])<97){
        $d=$d.strtoupper($b[strpos($a,strtolower($c[$i]))]);
    }
    else{
        $d=$d.$b[strpos($a,$c[$i])];
    }
}
echo $d;
?>

<?php
// $stdin = fopen('php://stdin', 'r');
$keyboard_wrong = str_split(fgets(STDIN));
$keyboard_correct = str_split(fgets(STDIN));
$problem_string = str_split(fgets(STDIN));

$pattern = [];
foreach (array_fill(0, 10, null) as $number => $crap) {
	$pattern["$number"] = "$number";
}
foreach ($keyboard_wrong as $index => $character) {
	$pattern[$keyboard_wrong[$index]] = $keyboard_correct[$index];
	$pattern[strtoupper($keyboard_wrong[$index])] = strtoupper($keyboard_correct[$index]);
}

$output = "";
foreach ($problem_string as $index => $character) {
	$output .= $pattern[$character];
}
// echo $output;
fwrite(STDOUT, $output);

<?php
// $stdin = fopen('php://stdin', 'r');
$keyboard_wrong = str_split(fgets(STDIN));
$keyboard_correct = str_split(fgets(STDIN));
$problem_string = str_split(fgets(STDIN));

$pattern = [];
foreach (array_fill(1, 10, null) as $number => $crap) {
	$pattern["$number"] = "$number";
}
foreach ($keyboard_wrong as $index => $character) {
	$pattern[$keyboard_wrong[$index]] = $keyboard_correct[$index];
	$pattern[strtoupper($keyboard_wrong[$index])] = strtoupper($keyboard_correct[$index]);
}

$output = "";
foreach ($problem_string as $index => $character) {
	$output .= $pattern[$character];
}
// echo $output;
fwrite(STDOUT, $output);


IA has so many colorful magnets on her fridge! Exactly one letter is written on each magnet, 'a' or 'b'. She loves to play with them, placing all magnets in a row. However, the girl is quickly bored and usually thinks how to make her entertainment more interesting.Today, when IA looked at the fridge, she noticed that the word formed by magnets is really messy. "It would look much better when I'll swap some of them!" — thought the girl — "but how to do it?". After a while, she got an idea. IA will look at all prefixes with lengths from $$$1$$$ to the length of the word and for each prefix she will either reverse this prefix or leave it as it is. She will consider the prefixes in the fixed order: from the shortest to the largest. She wants to get the lexicographically smallest possible word after she considers all prefixes. Can you help her, telling which prefixes should be chosen for reversing?A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds: $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$; in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.

The first and the only line contains a string $$$s$$$ ($$$1 \le |s| \le 1000$$$), describing the initial string formed by magnets. The string $$$s$$$ consists only of characters 'a' and 'b'.

Output exactly $$$|s|$$$ integers. If IA should reverse the $$$i$$$-th prefix (that is, the substring from $$$1$$$ to $$$i$$$), the $$$i$$$-th integer should be equal to $$$1$$$, and it should be equal to $$$0$$$ otherwise. If there are multiple possible sequences leading to the optimal answer, print any of them.

NoteIn the first example, IA can reverse the second and the third prefix and get a string "abbb". She cannot get better result, since it is also lexicographically smallest string obtainable by permuting characters of the initial string.In the second example, she can reverse any subset of prefixes — all letters are 'a'.


Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.After occupying all the window seats (for m > 2n) the non-window seats are occupied:1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.  The seating for n = 9 and m = 36. You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.

The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.

Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.

<?php
$dir = fopen("php://stdin", 'r');
$data = stream_get_contents($dir);
$parsed = explode(' ', $data);
$n = (int)$parsed[0];
$m = (int)$parsed[1];
$final = $m;
$resultArray = [];
for ($i = 0; $i < $final; $i++) {
    $row = floor($i/4);
    $column = $i%4;
    $result = null;
    switch ($column) {
        case 0:
            $result = 1 + 2*$n + $row * 2;
            break;
        case 1:
            $result = 1 + $row * 2; break;
        case 2:
            $result = 2 + 2*$n + $row * 2; break;
        case 3:
            $result = 2 + $row * 2; break;
    }
    if ($result > $m) {
        $result = null;
        $final++;
    }

    if ($result !== null) {
        $resultArray[] = $result;
    }
}
echo implode($resultArray, ' ');
?>

<?php
	list($n,$m) = explode(' ',trim(fgets(STDIN)));
	class WantSome {
		public $lw;
		public $l;
		public $r;
		public $rw;
		public $lwc = false;
		public $lc = false;
		public $rc = false;
		public $rwc = false;
	}
	$a = array();
	$p = 1;
	for ($i = 0; $i < $n; $i++) array_push($a,new WantSome);
	for ($i = 0; $i < $n && $m > 0; $i++) {
		$a[$i]->lw = $p;
		$p++;
		$m--;
		$a[$i]->lwc = true;
		if ($m > 0) {
			$a[$i]->rw = $p;
			$p++;
			$m--;
			$a[$i]->rwc = true;
		}
	}
	for ($i = 0; $i < $n && $m > 0; $i++) {
		$a[$i]->l = $p;
		$p++;
		$m--;
		$a[$i]->lc = true;
		if ($m > 0) {
			$a[$i]->r = $p;
			$p++;
			$m--;
			$a[$i]->rc = true;
		}
	}
	for ($i = 0; $i < $n; $i++) {
		if ($a[$i]->lc) {
			echo $a[$i]->l;
			echo ' ';
		}
		if ($a[$i]->lwc) {
			echo $a[$i]->lw;
			echo ' ';
		}
		if ($a[$i]->rc) {
			echo $a[$i]->r;
			echo ' ';
		}
		if ($a[$i]->rwc) {
			echo $a[$i]->rw;
			echo ' ';
		}
	}
?>

<?php
$dir = fopen("php://stdin", 'r');
$data = stream_get_contents($dir);
$parsed = explode(' ', $data);
$n = $parsed[0];
$m = $parsed[1];
$final = $m;
$resultArray = [];
for ($i = 0; $i < $final; $i++) {
    $row = floor($i/4);
    $column = $i%4;
    $result = null;
    switch ($column) {
        case 0:
            $result = 1 + 2*$n + $row * 2;
            break;
        case 1:
            $result = 1 + $row * 2; break;
        case 2:
            $result = 2 + 2*$n + $row * 2; break;
        case 3:
            $result = 2 + $row * 2; break;
    }
    if ($result > $m) {
        $result = null;
        $final++;
    }
    if ($result !== null) {
        $resultArray[] = $result;
    }
}
echo implode($resultArray, ' ');
?>

<?php
$dir = fopen("php://stdin", 'r');
$data = stream_get_contents($dir);
$parsed = explode(' ', $data);
$n = $parsed[0];
$m = $parsed[1];
$final = $m;
$resultArray = [];
for ($i = 0; $i < $final; $i++) {
    $row = floor($i/4);
    $column = $i%4;
    $result = null;
    switch ($column) {
        case 0:
            $result = 1 + 2*$n + $row * 2;
            break;
        case 1:
            $result = 1 + $row * 2; break;
        case 2:
            $result = 2 + 2*$n + $row * 2; break;
        case 3:
            $result = 2 + $row * 2; break;
    }
    if ($result > $m) {
        $result = null;
        $final++;
    }

    if ($result !== null) {
        $resultArray[] = $result;
    }
}
var_dump($resultArray);
echo implode($resultArray, ' ');
?>

<?php
$dir = fopen("php://stdin", 'r');
$data = stream_get_contents($dir);
$parsed = explode(' ', $data);
$n = $parsed[0];
$m = $parsed[1];
$final = $m;
$resultArray = [];
var_dump($n, $m);
for ($i = 0; $i < $final; $i++) {
    $row = floor($i/4);
    $column = $i%4;
    $result = null;
    switch ($column) {
        case 0:
            $result = 1 + 2*$n + $row * 2;
            break;
        case 1:
            $result = 1 + $row * 2; break;
        case 2:
            $result = 2 + 2*$n + $row * 2; break;
        case 3:
            $result = 2 + $row * 2; break;
    }
    if ($result > $m) {
        $result = null;
        $final++;
    }

    if ($result !== null) {
        $resultArray[] = $result;
    }
}
echo implode($resultArray, ' ');
?>


Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all $$$26$$$ lowercase Latin letters will be arranged in some order.Polycarp uses the same password $$$s$$$ on all websites where he is registered (it is bad, but he doesn't care). He wants to assemble a keyboard that will allow to type this password very easily. He doesn't like to move his fingers while typing the password, so, for each pair of adjacent characters in $$$s$$$, they should be adjacent on the keyboard. For example, if the password is abacaba, then the layout cabdefghi... is perfect, since characters a and c are adjacent on the keyboard, and a and b are adjacent on the keyboard. It is guaranteed that there are no two adjacent equal characters in $$$s$$$, so, for example, the password cannot be password (two characters s are adjacent).Can you help Polycarp with choosing the perfect layout of the keyboard, if it is possible?

The first line contains one integer $$$T$$$ ($$$1 \le T \le 1000$$$) — the number of test cases. Then $$$T$$$ lines follow, each containing one string $$$s$$$ ($$$1 \le |s| \le 200$$$) representing the test case. $$$s$$$ consists of lowercase Latin letters only. There are no two adjacent equal characters in $$$s$$$.

For each test case, do the following:   if it is impossible to assemble a perfect keyboard, print NO (in upper case, it matters in this problem);  otherwise, print YES (in upper case), and then a string consisting of $$$26$$$ lowercase Latin letters — the perfect layout. Each Latin letter should appear in this string exactly once. If there are multiple answers, print any of them.

5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza

YES
bacdefghijklmnopqrstuvwxyz
YES
edocabfghijklmnpqrstuvwxyz
NO
YES
xzytabcdefghijklmnopqrsuvw
NO

<?php

$fh = fopen('php://stdin','r');
$numberOfTests = fgets($fh);

for ($testNr=0;$testNr<$numberOfTests;$testNr++){
    $input = rtrim(fgets($fh)," \t\n\r\0\x0B");
    $keyPosition = 0;
    $keyboard = array();
    $fail = 0;
    $alphabet="abcdefghijklmnopqrstuvwxyz";
    $keyboard[$keyPosition] = $input[0];
    $alphabet = preg_replace("/".$input[0]."/", "", $alphabet);

    for ($i = 1; $i < strlen($input); $i++){
        $char = $input[$i];
        if (strpos($alphabet,$char) === FALSE){
            if (array_key_exists($keyPosition-1,$keyboard) && $keyboard[$keyPosition-1]==$char){
                $keyPosition -= 1;
            }
            else if (array_key_exists($keyPosition+1,$keyboard) && $keyboard[$keyPosition+1]==$char){
                $keyPosition += 1;
            }
            else{
                $fail = 1;
                break;
            }
        }
        else{
            if (array_key_exists($keyPosition-1,$keyboard)){
                if (array_key_exists($keyPosition+1,$keyboard)){
                    $fail = 1;
                    break;
                }
                else{
                    $keyPosition += 1;
                }
            }
            else{
                $keyPosition -= 1;
            }
        }
        $alphabet = preg_replace("/".$char."/", "", $alphabet);
        $keyboard[$keyPosition] = $char;
        //print $keyPosition . " has " . $char . " and " . $keyboard[$keyPosition];
    }

    if ($fail){
        print "NO";
    }
    else{
        print "YES";
        print "\n";
        ksort($keyboard);
        foreach ($keyboard as $key){
            print $key;
        }
        print $alphabet;
    }
    print "\n";
}
?>

<?php

$fh = fopen('php://stdin','r');
$numberOfTests = fgets($fh);

for ($testNr=0;$testNr<$numberOfTests;$testNr++){
    $input = rtrim(fgets($fh)," \t\n\r\0\x0B");
    $keyPosition = 0;
    $keyboard = array();
    $fail = 0;
    $alphabet="abcdefghijklmnopqrstuvwxyz";
    $keyboard[$keyPosition] = $input[0];
    $alphabet = preg_replace("/".$input[0]."/", "", $alphabet);

    for ($i = 1; $i < strlen($input); $i++){
        $char = $input[$i];
        if (strpos($alphabet,$char) === FALSE){
            if (array_key_exists($keyPosition-1,$keyboard) && $keyboard[$keyPosition-1]==$char){
                $keyPosition -= 1;
            }
            else if (array_key_exists($keyPosition+1,$keyboard) && $keyboard[$keyPosition+1]==$char){
                $keyPosition += 1;
            }
            else{
                $fail = 1;
                break;
            }
        }
        else{
            if (array_key_exists($keyPosition-1)){
                if (array_key_exists($keyPosition+1)){
                    $fail = 1;
                    break;
                }
                else{
                    $keyPosition += 1;
                }
            }
            else{

                $keyPosition -= 1;
            }
        }
        $alphabet = preg_replace("/".$char."/", "", $alphabet);
        $keyboard[$keyPosition] = $char;
    }

    if ($fail){
        print "NO";
    }
    else{
        print "YES";
        print "\n";
        ksort($keyboard);
        foreach ($keyboard as $key){
            print $key;
        }
        print $alphabet;
    }
    print "\n";
}
?>

<?php

$fh = fopen('php://stdin','r') or die($php_errormsg);
$numberOfTests = fgets($fh);

for ($testNr=0;$testNr<$numberOfTests;$testNr++){

$input = fgets($fh);
$index = 30;
$keyboard = array();
$keyboard[$index] = $input[0];
$fail = 0;
$alphabet="abcdefghijklmnopqrstuvwxyz";

for ($i = 1; $i < strlen($input); $i++){
  if ($keyboard[$index]==$input[$i]){
  }
  else if (array_key_exists($index-1,$keyboard) && $keyboard[$index-1]==$input[$i]){
      $index -= 1;
  }
  else if (array_key_exists($index+1,$keyboard) && $keyboard[$index+1]==$input[$i]){
      $index += 1;
  }
  else if (array_key_exists($index+1,$keyboard)){
      if (array_key_exists($index-1,$keyboard)){
          $fail = 1;
          break;
      }
      else{
          $index -= 1;
      }
  }
  else{
      $index += 1;
  }
  $alphabet = preg_replace("/".$input[$i]."/", "", $alphabet);
  $keyboard[$index] = $input[$i];

if ($fail){
    print "NO";
}
else{
    print "YES";
    print "\n";
    ksort($keyboard);
    foreach ($keyboard as $key){
        print $key;
    }
    print $alphabet;
}
}
}
?>


Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all n cities of Berland were connected by n two-way roads in the ring, i. e. each city was connected directly to exactly two other cities, and from each city it was possible to get to any other city. Government of Berland introduced one-way traffic on all n roads, but it soon became clear that it's impossible to get from some of the cities to some others. Now for each road is known in which direction the traffic is directed at it, and the cost of redirecting the traffic. What is the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other?

The first line contains integer n (3 ≤ n ≤ 100) — amount of cities (and roads) in Berland. Next n lines contain description of roads. Each road is described by three integers ai, bi, ci (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ ci ≤ 100) — road is directed from city ai to city bi, redirecting the traffic costs ci.

Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other.


You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, the string s=";;" contains three empty words separated by ';'.You should find all words in the given string that are nonnegative INTEGER numbers without leading zeroes and build by them new string a. String a should contain all words that are numbers separating them by ',' (the order of numbers should remain the same as in the string s). By all other words you should build string b in the same way (the order of numbers should remain the same as in the string s).Here strings "101", "0" are INTEGER numbers, but "01" and "1.0" are not.For example, for the string aba,123;1a;0 the string a would be equal to "123,0" and string b would be equal to "aba,1a".

The only line of input contains the string s (1 ≤ |s| ≤ 105). The string contains only symbols '.' (ASCII 46), ',' (ASCII 44), ';' (ASCII 59), digits, lowercase and uppercase latin letters.

Print the string a to the first line and string b to the second line. Each string should be surrounded by quotes (ASCII 34). If there are no words that are numbers print dash (ASCII 45) on the first line. If all words are numbers print dash on the second line.

NoteIn the second example the string s contains five words: "1", "", "01", "a0", "".

<?php

$s = trim(fgets(STDIN));

$s = str_replace([',', ';'], ',', $s);
$words = explode(',', $s);

$a = [];
$b = [];

foreach ($words as $word) {
	if (is_numeric($word) && strpos($word, '.') === false && (strlen($word) == 1 || $word[0] != '0')) {
		$a[] = $word;
	} else {
		$b[] = $word;
	}
}

if (count($a)) {
	echo "\"" . implode(',', $a) . "\"\n";
} else {
	echo "-\n";
}

if (count($b)) {
	echo "\"" . implode(',', $b) . "\"\n";
} else {
	echo "-\n";
}

<?php
fscanf(STDIN, "%s", $str);
foreach(explode(',', strtr($str, ";.", ",,")) as $e) $arr[strval(intval($e)) === $e && $e >= 0][] = $e;
fprintf(STDOUT, '"%s"\n"%s"', implode("," ,$arr[1]), implode("," ,$arr[0]));
?>

<?php

$s = trim(fgets(STDIN));

$s = str_replace([',', ';'], ',', $s);
$words = explode(',', $s);

$a = [];
$b = [];

foreach ($words as $word) {
	if (is_numeric($word) && floatval($word) == intval($word) && (strlen($word) == 1 || $word[0] != '0')) {
		$a[] = $word;
	} else {
		$b[] = $word;
	}
}

if (count($a)) {
	echo "\"" . implode(',', $a) . "\"\n";
} else {
	echo "-\n";
}

if (count($b)) {
	echo "\"" . implode(',', $b) . "\"\n";
} else {
	echo "-\n";
}

<?php

$s = trim(fgets(STDIN));

$s = str_replace([',', ';'], ',', $s);
$words = explode(',', $s);

$a = [];
$b = [];

foreach ($words as $word) {
	if (is_numeric($word) && is_int(intval($word)) && (strlen($word) == 1 || $word[0] != '0')) {
		$a[] = $word;
	} else {
		$b[] = $word;
	}
}

if (count($a)) {
	echo "\"" . implode(',', $a) . "\"\n";
} else {
	echo "-\n";
}

if (count($b)) {
	echo "\"" . implode(',', $b) . "\"\n";
} else {
	echo "-\n";
}


You are given a integer $$$n$$$ ($$$n > 0$$$). Find any integer $$$s$$$ which satisfies these conditions, or report that there are no such numbers:In the decimal representation of $$$s$$$:   $$$s > 0$$$,  $$$s$$$ consists of $$$n$$$ digits,  no digit in $$$s$$$ equals $$$0$$$,  $$$s$$$ is not divisible by any of it's digits.

The input consists of multiple test cases. The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 400$$$), the number of test cases. The next $$$t$$$ lines each describe a test case. Each test case contains one positive integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$). It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$10^5$$$.

For each test case, print an integer $$$s$$$ which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for $$$s$$$, print any solution.

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

        if($n == 1) echo "-1\n" ;
        else echo str_repeat("5", $n - 1) . "4\n" ;
    }
?>


There is a field divided into $$$n$$$ rows and $$$m$$$ columns. Some cells are empty (denoted as E), other cells contain robots (denoted as R).You can send a command to all robots at the same time. The command can be of one of the four types:  move up;  move right;  move down;  move left. When you send a command, all robots at the same time attempt to take one step in the direction you picked. If a robot tries to move outside the field, it explodes; otherwise, every robot moves to an adjacent cell in the chosen direction.You can send as many commands as you want (possibly, zero), in any order. Your goal is to make at least one robot reach the upper left corner of the field. Can you do this without forcing any of the robots to explode?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases. Each test case starts with a line containing two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 5$$$) — the number of rows and the number of columns, respectively. Then $$$n$$$ lines follow; each of them contains a string of $$$m$$$ characters. Each character is either E (empty cell} or R (robot). Additional constraint on the input: in each test case, there is at least one robot on the field.

If it is possible to make at least one robot reach the upper left corner of the field so that no robot explodes, print YES. Otherwise, print NO.

6

1 3

ERR

2 2

ER

RE

2 2

ER

ER

1 1

R

4 3

EEE

EEE

ERR

EER

3 3

EEE

EER

REE

NoteExplanations for test cases of the example:  in the first test case, it is enough to send a command to move left.  in the second test case, if you try to send any command, at least one robot explodes.  in the third test case, it is enough to send a command to move left.  in the fourth test case, there is already a robot in the upper left corner.  in the fifth test case, the sequence "move up, move left, move up" leads one robot to the upper left corner;  in the sixth test case, if you try to move any robot to the upper left corner, at least one other robot explodes.

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";

  $t = getT();
//   $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = false;
      list($n, $m) = getA();
      $a =[];
      $b = [];
      $c = [];
      $tt = 0;
      $cc = 0;
      for($i=0; $i<$n; $i++) {
          $a[] = getT();

          for($j=0; $j<$m; $j++) {
              if($a[$i][$j] == 'R') {
                  $b[] = $j;
                  $tt++;
                  break;
              }
          }
      }
          $ans = true;
          $dd = 0;
          $ans = $b[0] == min($b) ? true : false;
        //   if($tt > 1) {
        //       for($i=0; $i<$tt-1; $i++) {
        //           if($b[$i] > $b[$i + 1]) {

        //               $ans = false;
        //               break;
        //           }
        //       }
        //   }
        //   if(!$ans && $b[0] == min($b)) {
        //      $ans  = true;
        //   }

          pr($ans ? $yes : $no);

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
function getDar($n) {
    $dar = [2];
    for($i=0; $i<$n; $i++) {
        $dar[] = $dar[$i] * 2;
    }
    return $dar;
}
function getDar2($n, $k) {
    if($k == 0) {
        return 1;
    }
    return bcmul($n, getDar2($n, $k-1));
}

  function getT() {
      return trim(fgets(STDIN));
  }
  function getA() {
      return explode(' ', trim(fgets(STDIN)));
  }

  function is_prime($n) {
    $d = 2;
        while ($n % $d != 0) {
        	 $d += 1;
        }

        return $d == $n;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

    function getMaxValueBc($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    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;
    }
    function pr($s) {
        if(is_array($s)) {
            echo implode( ' ', $s), PHP_EOL;
        } else {
            echo $s, PHP_EOL;
        }
    }
    function fab2($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 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 merge(mergeSort($aLeft), mergeSort($aRight));
}

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;

}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    $arr = [];
    $flag = true;
    fscanf(STDIN, "%d %d", $n, $m);
    for ($y = 0; $y < $n; $y++) {
        for ($s = trim(fgets(STDIN)), $x = 0; $x < $m; $x++) {
            if ('R' == $s[$x]) {
                $arr[] = str_replace('E', ' ', $s);
                break;
            }
        }
    }
    while ('R' != $arr[0][0]) {
        if (isset(array_column(array_map('str_split', $arr), 0, 0)['R'])) {
            $flag = false;
            break;
        }
        $arr = array_map('ltrim', $arr);
    }
    echo ['NO', 'YES'][$flag], "\n";
}

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";

  $t = getT();
//   $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = false;
      list($n, $m) = getA();
      $a =[];
      $b = [];
      $tt = 0;
      for($i=0; $i<$n; $i++) {
          $a[] = getT();

          for($j=0; $j<$m; $j++) {
              if($a[$i][$j] == 'R') {
                  $b[] = $j+1;
                  $tt++;
                  break;
              }
          }
      }
      if($b[0] == 'R') {
          $ans = true;
      } else {
          $ans = true;
          if($tt > 1) {
              for($i=0; $i<$tt-1; $i++) {
                  if($b[$i] > $b[$i + 1]) {
                      $ans = false;
                      break;
                  }
              }
          }

      }

          pr($ans ? $yes : $no);

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
function getDar($n) {
    $dar = [2];
    for($i=0; $i<$n; $i++) {
        $dar[] = $dar[$i] * 2;
    }
    return $dar;
}
function getDar2($n, $k) {
    if($k == 0) {
        return 1;
    }
    return bcmul($n, getDar2($n, $k-1));
}

  function getT() {
      return trim(fgets(STDIN));
  }
  function getA() {
      return explode(' ', trim(fgets(STDIN)));
  }

  function is_prime($n) {
    $d = 2;
        while ($n % $d != 0) {
        	 $d += 1;
        }

        return $d == $n;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

    function getMaxValueBc($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    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;
    }
    function pr($s) {
        if(is_array($s)) {
            echo implode( ' ', $s), PHP_EOL;
        } else {
            echo $s, PHP_EOL;
        }
    }
    function fab2($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 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 merge(mergeSort($aLeft), mergeSort($aRight));
}

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;

}


You are given an array $$$a$$$ consisting of $$$n$$$ integers.In one move, you can choose two indices $$$1 \le i, j \le n$$$ such that $$$i \ne j$$$ and set $$$a_i := a_j$$$. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose $$$i$$$ and $$$j$$$ and replace $$$a_i$$$ with $$$a_j$$$).Your task is to say if it is possible to obtain an array with an odd (not divisible by $$$2$$$) sum of elements.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. The next $$$2t$$$ lines describe test cases. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the number of elements in $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2000$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$ ($$$\sum n \le 2000$$$).

For each test case, print the answer on it — "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.

<?

$n = intval(fgets(STDIN));
for ($i = 0; $i < $n; $i++) {
    $t = intval(fgets(STDIN));
    $numbers = array_map('intval', explode(" ", fgets(STDIN)));
    $even = 0;
    $odd = 0;
    foreach($numbers as $val) {
        if($val % 2 == 0) $even++;
        else $odd++;
    }
    if($odd !== 0 && ($odd !== $t || $t % 2 == 1)) echo "YES\n";
    else echo "NO\n";
}
?>

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

for($j=0;$j<$t;$j++)
{
    $n= trim(fgets($handle));
    $a= trim(fgets($handle));
    $a=explode(' ',$a);
    $sum=0;$odd=0;$enev=0;
    for ($i=0;$i<$n;$i++)
    {
        if($a[$i]%2!=0)
            $odd++;
        else
            $enev++;
        $sum=$sum+$a[$i];
    }

    if(($sum)%2!=0)
        echo "YES"."\n";
    else if($enev>=1 && $odd>=1)
        echo 'YES'."\n";
    else
        echo "NO"."\n";

}

?>

<?php

    $input = file_get_contents("php://stdin");

    function doo ($input) {

        $t = (int)explode("\n",$input)[0];

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

            $n = explode("\n",$input)[($i * 2) + 1];

            $arr = explode(" ",explode("\n",$input)[($i * 2) + 2]);

            $even = 0;
            $odd = 0;

            //Loop Inside This Array.
            for($q = 0;$q < $n;$q++) {

                //Check If They're All Even.
                if($arr[$q] % 2 == 0) {

                    $even++;

                }else {

                    $odd++;

                }

            }

            if($even == $n) {

                echo "NO\n";
                continue;

            }elseif($odd == $n) {

                //Check If Their Sum Is Even.
                if(array_sum($arr) % 2 == 0) {

                    echo "NO\n";
                    continue;

                }else {

                    echo "YES\n";
                    continue;

                }

            }

            echo "YES\n";

        }

    }

    doo($input);

<?php

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

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

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

	$tc = next_int();
	for($cc=0; $cc<$tc; $cc++) {
		$n = next_int();
		$odd = 0;
		for($i=0; $i<$n; $i++) if((next_int() & 1) == 1) $odd++;
		$ans = (($odd > 0) && ((($n&1) == 1) || ($odd != $n))) ? "YES" : "NO";
		printf("%s\n", $ans);
	}
}

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

?>

<?php
$input = file_get_contents("php://stdin");

$lines = explode("\n", $input);
array_shift($lines);

for ($i = 0; $i < count($lines)-1; $i = $i + 2) {
    // We only do the odd lines.
    $numbers = explode(' ', $lines[$i+1]);
    $sum = 0;
    $evenCount = 0;
    $oddCount = 0;

    foreach ($numbers as $number) {
        if ($number % 2 ===0) {
            $evenCount++;
        } else {
            $oddCount++;
        }

        $sum += $number;
    }

    if ($sum % 2 !== 0) {
        echo "YES\n";
    } else {
        if ($evenCount === 0 || $oddCount === 0) {
            echo "NO\n";
        } else {
            echo "YES\n";
        }
    }
}

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

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

       $count1 = 0;
       $count2 = 0;

        for($j = 0; $j < count($a); $j++){
            if($a[$j] % 2) {
                 $count1 += 1;
            } else {
                $count2 += 1;
            }
        }

        if($count1 == 0) {
            echo "NO\n";
        } elseif (
                    (($count1 - $count2) > 1 && ($count1 - $count2) % 2 == 1)
                    || ($count1 - $count2) == 0)
        {
            echo "YES\n";
        } else {
            echo "NO\n";
        }

    }

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

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

       $count1 = 0;
       $count2 = 0;

        for($j = 0; $j < count($a); $j++){
            if($a[$j] % 2) {
                 $count1 += 1;
            } else {
                $count2 += 1;
            }
        }

        if($count1 == 0) {
            echo "NO\n";
        } elseif ($count1 % 2 == 1)
        {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }

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

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

       $count = 0;

        for($j = 0; $j < count($a); $j++){
           $count += $a[$j];
        }

        if($count % 2 == 1) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }

    }

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

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

       $count1 = 0;
       $count2 = 0;

        for($j = 0; $j < count($a); $j++){
            if($a[$j] % 2) {
                 $count1 += 1;
            } else {
                $count2 += 1;
            }
        }

        if((($count1 - $count2) > 1 && ($count1 - $count2) % 2 == 1) || ($count1 - $count2) == 0) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }

    }

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

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

       $count1 = 0;
       $count2 = 0;

        for($j = 0; $j < count($a); $j++){
            if($a[$j] % 2) {
                 $count1 += 1;
            } else {
                $count2 += 1;
            }
        }

        if($count1 == 0) {
            echo "NO\n";
        } elseif ($count1 % 2 == 1)
        {
            echo "YES\n";
        } elseif (($count1 - $count2) % 2 == 1)
        {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }

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

for($j=0;$j<$t;$j++)
{
    $n= trim(fgets($handle));
    $a= trim(fgets($handle));
    $a=explode(' ',$a);
    $sum=0;
    for ($i=0;$i<$n;$i++)
    {
        if($a[$i]%2!=0)
        $sum=$sum+$a[$i];
    }

    if(($sum)%2!=0)
        echo "YES"."\n";
    else
        echo "NO"."\n";

}

?>

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

for($j=0;$j<$t;$j++)
{
    $n= trim(fgets($handle));
    $a= trim(fgets($handle));
    $a=explode(' ',$a);
    $sum=0;$odd=0;$enev=0;
    for ($i=0;$i<$n;$i++)
    {
        if($a[$i]%2!=0)
            $odd++;
        else
            $enev++;
        $sum=$sum+$a[$i];
    }

    if(($sum)%2!=0)
        echo "YES"."\n";
    else if($sum%2==0 && $enev%2!=0)
        echo 'YES'."\n";
    else
        echo "NO"."\n";

}

?>

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

for($j=0;$j<$t;$j++)
{
    $n= trim(fgets($handle));
    $a= trim(fgets($handle));
    $a=explode(' ',$a);
    $sum=0;$odd=0;$enev=0;
    for ($i=0;$i<$n;$i++)
    {
        if($a[$i]%2!=0)
            $odd++;
        else
            $enev++;
        $sum=$sum+$a[$i];
    }

    if(($sum)%2!=0)
        echo "YES"."\n";
    else if($sum%2==0 && $enev>1 && $odd>1)
        echo 'YES'."\n";
    else
        echo "NO"."\n";

}

?>

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

for($j=0;$j<$t;$j++)
{
    $n= trim(fgets($handle));
    $a= trim(fgets($handle));
    $a=explode(' ',$a);
    $sum=0;$odd=0;$enev=0;
    for ($i=0;$i<$n;$i++)
    {
        if($a[$i]%2!=0)
            $odd++;
        else
            $enev++;
        $sum=$sum+$a[$i];
    }

    if(($sum)%2!=0)
        echo "YES"."\n";
    else if($sum%2==0 && $enev>1)
        echo 'YES'."\n";
    else
        echo "NO"."\n";

}

?>

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

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

    if($sum%2!=0)
        echo "YES"."\n";
    else
        echo "NO"."\n";

}

?>

<?php

$input = trim(fgets(STDIN));

$lines = explode("\n", $a);
array_shift($lines);

for ($i = 1; $i <= count($lines); $i = $i + 2) {
    // We only do the odd lines.
    $numbers = explode(' ', $lines[$i]);
    $sum = 0;

    foreach ($numbers as $number) {
        $sum += $number;
    }

    if ($sum % 2 == 1) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

<?php
$input = file_get_contents("php://stdin");

$lines = explode("\n", $input);
array_shift($lines);

for ($i = 0; $i < count($lines)-1; $i = $i + 2) {
    // We only do the odd lines.
    $numbers = explode(' ', $lines[$i+1]);
    $sum = 0;

    foreach ($numbers as $number) {
        $sum += $number;
    }

    if ($sum % 2 == 1) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

<?php

$input = trim(fgets(STDIN));

$lines = explode("\n", $input);
array_shift($lines);

for ($i = 1; $i <= count($lines); $i = $i + 2) {
    // We only do the odd lines.
    $numbers = explode(' ', $lines[$i]);
    $sum = 0;

    foreach ($numbers as $number) {
        $sum += $number;
    }

    if ($sum % 2 == 1) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

<?php
$input = file_get_contents("php://stdin");

$lines = explode("\n", $input);
array_shift($lines);

for ($i = 1; $i <= count($lines); $i = $i + 2) {
    // We only do the odd lines.
    $numbers = explode(' ', $lines[$i]);
    $sum = 0;

    foreach ($numbers as $number) {
        $sum += $number;
    }

    if ($sum % 2 == 1) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}


You are given two integers $$$l$$$ and $$$r$$$, $$$l\le r$$$. Find the largest possible value of $$$a \bmod b$$$ over all pairs $$$(a, b)$$$ of integers for which $$$r\ge a \ge b \ge l$$$.As a reminder, $$$a \bmod b$$$ is a remainder we get when dividing $$$a$$$ by $$$b$$$. For example, $$$26 \bmod 8 = 2$$$.

Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ $$$(1\le t\le 10^4)$$$, denoting the number of test cases. Description of the test cases follows. The only line of each test case contains two integers $$$l$$$, $$$r$$$ ($$$1\le l \le r \le 10^9$$$).

For every test case, output the largest possible value of $$$a \bmod b$$$ over all pairs $$$(a, b)$$$ of integers for which $$$r\ge a \ge b \ge l$$$.

NoteIn the first test case, the only allowed pair is $$$(a, b) = (1, 1)$$$, for which $$$a \bmod b = 1 \bmod 1 = 0$$$.In the second test case, the optimal choice is pair $$$(a, b) = (1000000000, 999999999)$$$, for which $$$a \bmod b = 1$$$.

<?php
fscanf(STDIN, "%d", $number);
while($number--){
	fscanf(STDIN,"%d%d",$a,$b);
	$res = (int)($b/2);
	if($a == $b){
		echo "0\n";
	}else if($res >= $a){
		if($b % 2 == 0){
			$res-=1;
		}
		echo $res."\n";
	}else{
		echo $b % $a."\n";
	}
}
?>

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

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

for ($j = 0; $j < $t; $j++) {
  list($a, $b) = explode(" ", trim(fgets($file)));
  if ($a == $b) { echo '0'.PHP_EOL; }
  else {
    if ($b < $a * 2) { $c = $b - $a; }
    else { $c = floor(($b - 1) / 2); }

    echo $c.PHP_EOL;
  }
}
?>

  <?php

  $t = trim(fgets(STDIN));
  for($q=0; $q <$t; $q++) {
     list($l, $r) = explode(' ', trim(fgets(STDIN)));
     $mod = 0;
     if($l == $r) {
        $mod = 0;
     } else {
        $mod = ($r - $l ) < $l ? $r - $l : floor( ($r-1) / 2) ;
     }

     echo $mod . "\n";
  }


This is the hard version of the problem. The difference between the versions is the constraint on $$$n$$$ and the required number of operations. You can make hacks only if all versions of the problem are solved.There are two binary strings $$$a$$$ and $$$b$$$ of length $$$n$$$ (a binary string is a string consisting of symbols $$$0$$$ and $$$1$$$). In an operation, you select a prefix of $$$a$$$, and simultaneously invert the bits in the prefix ($$$0$$$ changes to $$$1$$$ and $$$1$$$ changes to $$$0$$$) and reverse the order of the bits in the prefix.For example, if $$$a=001011$$$ and you select the prefix of length $$$3$$$, it becomes $$$011011$$$. Then if you select the entire string, it becomes $$$001001$$$.Your task is to transform the string $$$a$$$ into $$$b$$$ in at most $$$2n$$$ operations. It can be proved that it is always possible.

The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$)  — the number of test cases. Next $$$3t$$$ lines contain descriptions of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 10^5$$$)  — the length of the binary strings. The next two lines contain two binary strings $$$a$$$ and $$$b$$$ of length $$$n$$$. It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$10^5$$$.

For each test case, output an integer $$$k$$$ ($$$0\le k\le 2n$$$), followed by $$$k$$$ integers $$$p_1,\ldots,p_k$$$ ($$$1\le p_i\le n$$$). Here $$$k$$$ is the number of operations you use and $$$p_i$$$ is the length of the prefix you flip in the $$$i$$$-th operation.

NoteIn the first test case, we have $$$01\to 11\to 00\to 10$$$.In the second test case, we have $$$01011\to 00101\to 11101\to 01000\to 10100\to 00100\to 11100$$$.In the third test case, the strings are already the same. Another solution is to flip the prefix of length $$$2$$$, which will leave $$$a$$$ unchanged.


You have a string $$$s_1 s_2 \ldots s_n$$$ and you stand on the left of the string looking right. You want to choose an index $$$k$$$ ($$$1 \le k \le n$$$) and place a mirror after the $$$k$$$-th letter, so that what you see is $$$s_1 s_2 \ldots s_k s_k s_{k - 1} \ldots s_1$$$. What is the lexicographically smallest string you can see?A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds:   $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$;  in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.

The first line of input contains one integer $$$t$$$ ($$$1 \leq t \leq 10\,000$$$): the number of test cases. The next $$$t$$$ lines contain the description of the test cases, two lines per a test case. In the first line you are given one integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$): the length of the string. The second line contains the string $$$s$$$ consisting of $$$n$$$ lowercase English characters. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print the lexicographically smallest string you can see.

4
10
codeforces
9
cbacbacba
3
aaa
4
bbaa

NoteIn the first test case choose $$$k = 1$$$ to obtain "cc".In the second test case choose $$$k = 3$$$ to obtain "cbaabc".In the third test case choose $$$k = 1$$$ to obtain "aa".In the fourth test case choose $$$k = 1$$$ to obtain "bb".


Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.

The first line contains an integer n (1 ≤ n ≤ 1000).

On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.

<?php

$stdin = fopen('php://stdin', 'r');
$line1 = fgets($stdin);
$arr=explode(' ',$line1);
fclose($stdin);
$n=$arr[0];

$stdout=fopen('php://stdout','w');
if ($n%2==0) {$c=floor($n*$n/2);} else {$c=floor((floor($n/2)+1)*(floor($n/2)+1)+floor($n/2)*floor($n/2));}
fwrite($stdout,$c."\n");
$line='';
for ($i=1;$i<=$n;$i++)
{
for ($j=1;$j<=$n;$j++)
{
    if (($i+$j)%2==0) {$line=$line.'C';} else {$line=$line.'.';}
}
    fwrite($stdout,$line."\n");
    $line='';
}

fclose($stdout);

?>

<?php

$n = (int)get_line();

print intval(($n * $n + 1) / 2);
print PHP_EOL;

$output = '';

for ($i = 0; $i < $n; $i ++) {
  for ($j = 0; $j < $n; $j ++) {
    if ($i % 2 == 0) {
      $output .= ($j % 2 == 0) ? 'C' : '.';
    } else {
      $output .= ($j % 2 == 0) ? '.' : 'C';
    }
  }
  $output .= PHP_EOL;
}

print $output;

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

<?php
error_reporting("off");
//384A: Coder
$n = trim(fgets(STDIN));
if ($n == 1) {
	echo "1\n";
	echo "C";
} elseif ($n % 2 == 0) {
	$firstline = str_repeat("C.", $n / 2);
	$secondline = strrev($firstline);
	$twolines = $firstline."\n".$secondline."\n";
	$result = str_repeat($twolines, $n / 2);
	$numberofc = $n * $n;
	$numberofc = $numberofc / 2;
	echo $numberofc."\n";
	echo $result;
} else {
	$other = $n - 1;
	$times = $other / 2;
	$firstline = str_repeat("C.", $times)."C";
	$secondline = str_repeat(".C", $times).".";
	$twolines = $firstline."\n".$secondline."\n";
	$result = str_repeat($twolines, $times).$firstline;
	$numberofc = $times * $n;
	$numberofc += $times + 1;
	echo $numberofc."\n";
	echo $result;
}
?>

<?php
error_reporting("off");
//384A: Coder
$n = trim(fgets(STDIN));
if ($n % 2 == 0) {
    $firstline = str_repeat("C.", $n / 2);
    $secondline = strrev($firstline);
    $twolines = $firstline."\n".$secondline."\n";
    $result = str_repeat($twolines, $n / 2);
} else {
    $other = $n - 1;
    $times = $other / 2;
    $firstline = str_repeat("C.", $times)."C";
    $secondline = str_repeat(".C", $times).".";
    $twolines = $firstline."\n".$secondline."\n";
    $result = str_repeat($twolines, $times).$firstline;
}
echo $result;
?>

<?php
error_reporting("off");
//384A: Coder
$n = trim(fgets(STDIN));
if ($n == 1) {
    echo "C";
} elseif ($n % 2 == 0) {
    $firstline = str_repeat("C.", $n / 2);
    $secondline = strrev($firstline);
    $twolines = $firstline."\n".$secondline."\n";
    $result = str_repeat($twolines, $n / 2);
    echo $result;
} else {
    $other = $n - 1;
    $times = $other / 2;
    $firstline = str_repeat("C.", $times)."C";
    $secondline = str_repeat(".C", $times).".";
    $twolines = $firstline."\n".$secondline."\n";
    $result = str_repeat($twolines, $times).$firstline;
    echo $result;
}
?>

<?php
error_reporting("off");
//384A: Coder
$n = trim(fgets(STDIN));
if ($n == 1) {
    echo "C";
} elseif ($n % 2 == 0) {
    $firstline = str_repeat("C.", $n / 2);
    $secondline = strrev($firstline);
    $twolines = $firstline."\n".$secondline."\n";
    $result = str_repeat($twolines, $n / 2);
    $numberofc = $n * $n;
    $numberofc = $numberofc / 2;
    echo $numberofc."\n";
    echo $result;
} else {
    $other = $n - 1;
    $times = $other / 2;
    $firstline = str_repeat("C.", $times)."C";
    $secondline = str_repeat(".C", $times).".";
    $twolines = $firstline."\n".$secondline."\n";
    $result = str_repeat($twolines, $times).$firstline;
    $numberofc = $times * $n;
    $numberofc += $times + 1;
    echo $numberofc."\n";
    echo $result;
}
?>


You are given two arrays $$$a$$$ and $$$b$$$, both of length $$$n$$$. All elements of both arrays are from $$$0$$$ to $$$n-1$$$.You can reorder elements of the array $$$b$$$ (if you want, you may leave the order of elements as it is). After that, let array $$$c$$$ be the array of length $$$n$$$, the $$$i$$$-th element of this array is $$$c_i = (a_i + b_i) \% n$$$, where $$$x \% y$$$ is $$$x$$$ modulo $$$y$$$.Your task is to reorder elements of the array $$$b$$$ to obtain the lexicographically minimum possible array $$$c$$$.Array $$$x$$$ of length $$$n$$$ is lexicographically less than array $$$y$$$ of length $$$n$$$, if there exists such $$$i$$$ ($$$1 \le i \le n$$$), that $$$x_i < y_i$$$, and for any $$$j$$$ ($$$1 \le j < i$$$) $$$x_j = y_j$$$.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$, $$$b$$$ and $$$c$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i < n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. The third line of the input contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$0 \le b_i < n$$$), where $$$b_i$$$ is the $$$i$$$-th element of $$$b$$$.

Print the lexicographically minimum possible array $$$c$$$. Recall that your task is to reorder elements of the array $$$b$$$ and obtain the lexicographically minimum possible array $$$c$$$, where the $$$i$$$-th element of $$$c$$$ is $$$c_i = (a_i + b_i) \% n$$$.

<?php
# 1157E
declare(strict_types=1);

$start = microtime(true);
$stdin = STDIN;
[$n] = fscanf($stdin, '%u');

$arrA = explode(' ', trim(fgets($stdin)));
$arrB = explode(' ', trim(fgets($stdin)));
sort($arrB);
$arrC = [];
$amountB = array_fill(0, $n, 0);
foreach ($arrB as $itemB) {
    $amountB[$itemB]++;
}

$orderList = array_keys($amountB);
unset($orderList[0]);
sort($orderList);
$orderList[] = 0;

foreach ($arrA as $itemA) {
    $currentValue = ($n - $itemA) % $n;
    while ($amountB[$currentValue] === 0) {
        $nextValue = $orderList[$currentValue];
        if ($amountB[$nextValue] === 0) {
            $nextValue = $orderList[$currentValue] = $orderList[$nextValue];
        }
        $currentValue = $nextValue;
    }
    $arrC[] = ($itemA + $currentValue) % $n;
    $amountB[$currentValue]--;
}
echo implode(' ', $arrC);

<?php
# 1157E
declare(strict_types=1);

$start = microtime(true);
$stdin = STDIN;
[$n] = fscanf($stdin, '%u');

$arrA = explode(' ', trim(fgets($stdin)));
$arrB = explode(' ', trim(fgets($stdin)));
sort($arrB);
$result = '';

$amountB = array_fill(0, $n, 0);
foreach ($arrB as $itemB) {
    $amountB[$itemB]++;
}

unset($arrB);

$orderList = array_keys($amountB);
unset($orderList[0]);
sort($orderList);
$orderList[] = 0;

foreach ($arrA as $i => $itemA) {
    $currentValue = ($n - $itemA) % $n;
    while ($amountB[$currentValue] === 0) {
        $nextValue = $orderList[$currentValue];
        if ($amountB[$nextValue] === 0) {
            $nextValue = $orderList[$currentValue] = $orderList[$nextValue];
        }
        $currentValue = $nextValue;
    }
    $res .= ($i ? ' ' : '') . (($itemA + $currentValue) % $n);
    $amountB[$currentValue]--;
}
echo $res;

<?php
# 1157E
declare(strict_types=1);

$start = microtime(true);
$stdin = STDIN;
[$n] = fscanf($stdin, '%u');

$arrA = explode(' ', trim(fgets($stdin)));
$arrB = explode(' ', trim(fgets($stdin)));
sort($arrB);
$arrC = [];
$amountB = array_fill(0, $n, 0);
foreach ($arrB as $itemB) {
    $amountB[$itemB]++;
}

$orderList = array_keys($amountB);
unset($orderList[0]);
sort($orderList);
$orderList[] = 0;

foreach ($arrA as $i => $itemA) {
    $currentValue = ($n - $itemA) % $n;
    while ($amountB[$currentValue] === 0) {
        $nextValue = $orderList[$currentValue];
        if ($amountB[$nextValue] === 0) {
            $nextValue = $orderList[$currentValue] = $orderList[$nextValue];
        }
        $currentValue = $nextValue;
    }
    echo ($i ? ' ' : '') . (($itemA + $currentValue) % $n);
    $amountB[$currentValue]--;
}