A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend.

The first input file line contains integers n and m — the total number of clothing items in the shop and the total number of matching pairs of clothing items (). Next line contains n integers ai (1 ≤ ai ≤ 106) — the prices of the clothing items in rubles. Next m lines each contain a pair of space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different.

Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).

NoteIn the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles.The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1.In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.

<?php

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

$data = file($src);

list($n, $m) = array_map('intval', explode(' ', array_shift($data)));

$prices = array_map('intval', explode(' ', array_shift($data)));

$exists = false;
$map = array();
foreach ($data as $match) {
	if (!$match) {
		break;
	}
	$new_match = array_map('intval', explode(' ', $match));
	$map[$new_match[0] - 1][$new_match[1] - 1] = $map[$new_match[1] - 1][$new_match[0] - 1] = true;
}

$min = -1;
foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		continue;
	}
	$matches_keys = array_keys($matches);
	$m = count($matches);
	for ($i = 0; $i < $m - 1; $i++) {
		$item_2 = $matches_keys[$i];
		for ($j = $i + 1; $j < $m; $j++) {
			$item_3 = $matches_keys[$j];
			if (!isset($map[$item_2][$item_3])) {
				continue;
			}
			$price = $prices[$item] + $prices[$item_2] + $prices[$item_3];
			if ($price < $min || $min == -1) {
				$min = $price;
			}
		}
	}
}

echo $min;

<?php

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

$data = file_get_contents($src);
$data = explode("\r\n", $data); // If this was the case, I blame the contest staff as highly unprofessional

list($n, $m) = array_map('intval', explode(' ', array_shift($data)));

$prices = array_map('intval', explode(' ', array_shift($data)));

$exists = false;
$map = array();
foreach ($data as $match) {
	if (!$match) {
		break;
	}
	$new_match = array_map('intval', explode(' ', $match));
	foreach ($new_match as $k => $item) {
		$new_match[$k] = $item - 1;
	}
	foreach ($new_match as $k => $item) {
		$other_item = $new_match[(int) !$k];
		$map[$item][$other_item] = true;
	}
}

$min = -1;
foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		foreach ($map as $k => $it) {
			unset($map[$k][$item]);
		}
	}
}

foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		continue;
	}
	$matches_keys = array_keys($matches);
	for ($i = 0; $i < count($matches) - 1; $i++) {
		$item_2 = $matches_keys[$i];
		for ($j = $i + 1; $j < count($matches); $j++) {
			$item_3 = $matches_keys[$j];
			if (!isset($map[$item_2][$item_3])) {
				continue;
			}
			$price = array_sum(array_intersect_key($prices, array($item, $item_2, $item_3)));
			if ($price < $min || $min == -1) {
				$min = $price;
			}
		}
	}
}

echo $min;

<?php

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

$data = file($src);

list($n, $m) = array_map('intval', explode(' ', array_shift($data)));

$prices = array_map('intval', explode(' ', array_shift($data)));

$exists = false;
$map = array();
foreach ($data as $match) {
	if (!$match) {
		break;
	}
	$new_match = array_map('intval', explode(' ', $match));
	foreach ($new_match as $k => $item) {
		$new_match[$k] = $item - 1;
	}
	foreach ($new_match as $k => $item) {
		$other_item = $new_match[(int) !$k];
		$map[$item][$other_item] = true;
	}
}

$min = -1;
foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		foreach ($map as $k => $it) {
			unset($map[$k][$item]);
		}
	}
}

foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		continue;
	}
	$matches_keys = array_keys($matches);
	for ($i = 0; $i < count($matches) - 1; $i++) {
		$item_2 = $matches_keys[$i];
		for ($j = $i + 1; $j < count($matches); $j++) {
			$item_3 = $matches_keys[$j];
			if (!isset($map[$item_2][$item_3])) {
				continue;
			}
			$price = array_sum(array_intersect_key($prices, array($item, $item_2, $item_3)));
			if ($price < $min || $min == -1) {
				$min = $price;
			}
		}
	}
}

echo $min . "\r\n";

<?php

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

$data = file($src);

list($n, $m) = array_map('intval', explode(' ', array_shift($data)));

$prices = array_map('intval', explode(' ', array_shift($data)));

$exists = false;
$map = array();
foreach ($data as $match) {
	if (!$match) {
		break;
	}
	$new_match = array_map('intval', explode(' ', $match));
	foreach ($new_match as $k => $item) {
		$new_match[$k] = $item - 1;
	}
	foreach ($new_match as $k => $item) {
		$other_item = $new_match[(int) !$k];
		$map[$item][$other_item] = true;
	}
}

$min = PHP_INT_MAX;
foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		foreach ($map as $k => $it) {
			unset($map[$k][$item]);
		}
	}
}

foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		continue;
	}
	$matches_keys = array_keys($matches);
	for ($i = 0; $i < count($matches) - 1; $i++) {
		$item_2 = $matches_keys[$i];
		for ($j = $i + 1; $j < count($matches); $j++) {
			$item_3 = $matches_keys[$j];
			if (!isset($map[$item_2][$item_3])) {
				continue;
			}
			$price = array_sum(array_intersect_key($prices, array($item, $item_2, $item_3)));
			if ($price < $min) {
				$min = $price;
			}
		}
	}
}

echo $min == PHP_INT_MAX ? -1 : $min;
echo PHP_EOL;

<?php

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

$data = file($src);

list($n, $m) = array_map('intval', explode(' ', array_shift($data)));

$prices = array_map('intval', explode(' ', array_shift($data)));

$exists = false;
$map = array();
foreach ($data as $match) {
	if (!$match) {
		break;
	}
	$new_match = array_map('intval', explode(' ', $match));
	foreach ($new_match as $k => $item) {
		$new_match[$k] = $item - 1;
	}
	foreach ($new_match as $k => $item) {
		$other_item = $new_match[(int) !$k];
		$map[$item][$other_item] = true;
	}
}

$min = -1;
foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		foreach ($map as $k => $it) {
			unset($map[$k][$item]);
		}
	}
}

foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		continue;
	}
	$matches_keys = array_keys($matches);
	for ($i = 0; $i < count($matches) - 1; $i++) {
		$item_2 = $matches_keys[$i];
		for ($j = $i + 1; $j < count($matches); $j++) {
			$item_3 = $matches_keys[$j];
			if (!isset($map[$item_2][$item_3])) {
				continue;
			}
			$price = array_sum(array_intersect_key($prices, array($item, $item_2, $item_3)));
			if ($price < $min || $min == -1) {
				$min = $price;
			}
		}
	}
}

echo $min;

<?php

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

$data = file($src);

list($n, $m) = array_map('intval', explode(' ', array_shift($data)));

$prices = array_map('intval', explode(' ', array_shift($data)));

$exists = false;
$map = array();
foreach ($data as $match) {
	if (!$match) {
		break;
	}
	$new_match = array_map('intval', explode(' ', $match));
	foreach ($new_match as $k => $item) {
		$new_match[$k] = $item - 1;
	}
	foreach ($new_match as $k => $item) {
		$other_item = $new_match[(int) !$k];
		$map[$item][$other_item] = true;
	}
}

$min = -1;
foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		foreach ($map as $k => $it) {
			unset($map[$k][$item]);
		}
	}
}

foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		continue;
	}
	$matches_keys = array_keys($matches);
	for ($i = 0; $i < count($matches) - 1; $i++) {
		$item_2 = $matches_keys[$i];
		for ($j = $i + 1; $j < count($matches); $j++) {
			$item_3 = $matches_keys[$j];
			if (!isset($map[$item_2][$item_3])) {
				continue;
			}
			$price = array_sum(array_intersect_key($prices, array($item, $item_2, $item_3)));
			if ($price < $min || $min == -1) {
				$min = $price;
			}
		}
	}
}

echo $min;

<?php

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

$data = file_get_contents($src);
$data = explode("\n", $data); // If this was the case, I blame the contest staff as highly unprofessional

list($n, $m) = array_map('intval', explode(' ', array_shift($data)));

$prices = array_map('intval', explode(' ', array_shift($data)));

$exists = false;
$map = array();
foreach ($data as $match) {
	if (!$match) {
		break;
	}
	$new_match = array_map('intval', explode(' ', $match));
	foreach ($new_match as $k => $item) {
		$new_match[$k] = $item - 1;
	}
	foreach ($new_match as $k => $item) {
		$other_item = $new_match[(int) !$k];
		$map[$item][$other_item] = true;
	}
}

$min = -1;
foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		foreach ($map as $k => $it) {
			unset($map[$k][$item]);
		}
	}
}

foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		continue;
	}
	$matches_keys = array_keys($matches);
	for ($i = 0; $i < count($matches) - 1; $i++) {
		$item_2 = $matches_keys[$i];
		for ($j = $i + 1; $j < count($matches); $j++) {
			$item_3 = $matches_keys[$j];
			if (!isset($map[$item_2][$item_3])) {
				continue;
			}
			$price = array_sum(array_intersect_key($prices, array($item, $item_2, $item_3)));
			if ($price < $min || $min == -1) {
				$min = $price;
			}
		}
	}
}

echo $min;

<?php

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

$data = file_get_contents($src);
die($data);
$data = explode("\n", $data); // If this was the case, I blame the contest staff as highly unprofessional

list($n, $m) = array_map('intval', explode(' ', array_shift($data)));

$prices = array_map('intval', explode(' ', array_shift($data)));

$exists = false;
$map = array();
foreach ($data as $match) {
	if (!$match) {
		break;
	}
	$new_match = array_map('intval', explode(' ', $match));
	foreach ($new_match as $k => $item) {
		$new_match[$k] = $item - 1;
	}
	foreach ($new_match as $k => $item) {
		$other_item = $new_match[(int) !$k];
		$map[$item][$other_item] = true;
	}
}

$min = -1;
foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		foreach ($map as $k => $it) {
			unset($map[$k][$item]);
		}
	}
}

foreach ($map as $item => $matches) {
	if (count($matches) < 2) {
		continue;
	}
	$matches_keys = array_keys($matches);
	for ($i = 0; $i < count($matches) - 1; $i++) {
		$item_2 = $matches_keys[$i];
		for ($j = $i + 1; $j < count($matches); $j++) {
			$item_3 = $matches_keys[$j];
			if (!isset($map[$item_2][$item_3])) {
				continue;
			}
			$price = array_sum(array_intersect_key($prices, array($item, $item_2, $item_3)));
			if ($price < $min || $min == -1) {
				$min = $price;
			}
		}
	}
}

echo $min;


Victor has a 24-hour clock that shows the time in the format "HH:MM" (00 $$$\le$$$ HH $$$\le$$$ 23, 00 $$$\le$$$ MM $$$\le$$$ 59). He looks at the clock every $$$x$$$ minutes, and the clock is currently showing time $$$s$$$. How many different palindromes will Victor see in total after looking at the clock every $$$x$$$ minutes, the first time being at time $$$s$$$?For example, if the clock starts out as 03:12 and Victor looks at the clock every $$$360$$$ minutes (i.e. every $$$6$$$ hours), then he will see the times 03:12, 09:12, 15:12, 21:12, 03:12, and the times will continue to repeat. Here the time 21:12 is the only palindrome he will ever see, so the answer is $$$1$$$.A palindrome is a string that reads the same backward as forward. For example, the times 12:21, 05:50, 11:11 are palindromes but 13:13, 22:10, 02:22 are not.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of each test case follows. The only line of each test case contains a string $$$s$$$ of length $$$5$$$ with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59" (both "HH" and "MM" have exactly two digits) and an integer $$$x$$$ ($$$1 \leq x \leq 1440$$$) — the number of minutes Victor takes to look again at the clock.

For each test case, output a single integer — the number of different palindromes Victor will see if he looks at the clock every $$$x$$$ minutes starting from time $$$s$$$.

NoteThe first test case is explained in the statement.

<?php

$testCases = (int) fgets(STDIN);
$answers = [];

for ($j=0; $j < $testCases; $j++) {
    $line = explode(' ', fgets(STDIN));
    $time = $line[0];
    $minutes = (int) $line[1];

    $lastTime = null;
    $palindromeCount = 0;
    while ($time != $lastTime) {
        $lastTime = date('H:i', strtotime("+" . $minutes . " minutes", strtotime($lastTime ?? $time)));
        $palindromeCount += ($lastTime === strrev($lastTime)) ? 1 : 0;
    }

    $answers[] = $palindromeCount;
}

foreach ($answers as $item) {
    echo $item . PHP_EOL;
}

<?php
function getPal(){
    $time = explode(" ", trim(fgets(STDIN)));
    $out_dt='';
    $pal = 0;
    while ($out_dt!=$time[0]){
        if ($out_dt!=''){
            $in_dt = $out_dt;
        } else {
            $in_dt = $time[0];
        }
        $data_time = explode(":",$in_dt);
        $date = new DateTime('2001-01-01');
        $dt= $date->setTime($data_time[0],$data_time[1]);
        $dt->add(new DateInterval('PT' . $time[1] . 'M'));
        $out_dt = $dt->format('H:i');
        if ($out_dt[0]==$out_dt[4] && $out_dt[1]==$out_dt[3]){
            ++$pal;
        }
    }
    echo "$pal\n";

}
$num = trim(fgets(STDIN));
for($k = 0; $k<$num; $k++){
    getPal();
}
?>

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%s %d", $s, $x);
    $s2 = $s;
    $i = 0;
    do {
        $s2 = date_add(new DateTime($s2), new DateInterval("PT{$x}M"))->format('H:i')
        and $s2 == strrev($s2)
        and $i++;
    } while ($s2 != $s);
    echo $i, "\n";
}

<?php

$testCases = (int) fgets(STDIN);
$answers = [];

for ($j=0; $j < $testCases; $j++) {
    $line = explode(' ', fgets(STDIN));
    $time = $line[0];
    $minutes = (int) $line[1];

    $loop = ceil(1440/$minutes);
    $lastTime = $time;

    $palindromeCount = 0;

    for ($i=0; $i < $loop; $i++) {
        $lastTime = date('H:i', strtotime("+" . $minutes . " minutes", strtotime($lastTime)));
        $splitTime = explode(':', $lastTime);
        $palindromeCount += $splitTime[0] === strrev($splitTime[1]) ? 1 : 0;
    }

    $answers[] = $palindromeCount;
}

foreach ($answers as $item) {
    echo $item . PHP_EOL;
}


A coordinate line has n segments, the i-th segment starts at the position li and ends at the position ri. We will denote such a segment as [li, ri].You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.Formally we will assume that segment [a, b] covers segment [c, d], if they meet this condition a ≤ c ≤ d ≤ b.

The first line contains integer n (1 ≤ n ≤ 105) — the number of segments. Next n lines contain the descriptions of the segments. The i-th line contains two space-separated integers li, ri (1 ≤ li ≤ ri ≤ 109) — the borders of the i-th segment. It is guaranteed that no two segments coincide.

Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input.

<?php

function main()
{
    fscanf(STDIN, "%d", $n);
    $segment = -1;
    $leftmost = 1e9;
    $rightmost = 0;
    for ($i = 1; $i <= $n; ++$i)
    {
        fscanf(STDIN, "%d %d", $l, $r);
        if ($l <= $leftmost && $r >= $rightmost)
            $segment = $i;
        else if ($l >= $leftmost && $r <= $rightmost)
            continue;
        else
            $segment = -1;
        $leftmost = min($l, $leftmost);
        $rightmost = max($r, $rightmost);
    }
    fprintf(STDOUT, "%d\n", $segment);
}

main();


Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this function does the following: function rangeIncrement(l, r)    for i := l .. r do        a[i] = a[i] + 1Polycarpus knows the state of the array a after a series of function calls. He wants to determine the minimum number of function calls that lead to such state. In addition, he wants to find what function calls are needed in this case. It is guaranteed that the required number of calls does not exceed 105.Before calls of function rangeIncrement(l, r) all array elements equal zero.

The first input line contains a single integer n (1 ≤ n ≤ 105) — the length of the array a[1... n].  The second line contains its integer space-separated elements, a[1], a[2], ..., a[n] (0 ≤ a[i] ≤ 105) after some series of function calls rangeIncrement(l, r).  It is guaranteed that at least one element of the array is positive. It is guaranteed that the answer contains no more than 105 calls of function rangeIncrement(l, r).

Print on the first line t — the minimum number of calls of function rangeIncrement(l, r), that lead to the array from the input data. It is guaranteed that this number will turn out not more than 105. Then print t lines — the descriptions of function calls, one per line. Each line should contain two integers li, ri (1 ≤ li ≤ ri ≤ n) — the arguments of the i-th call rangeIncrement(l, r). Calls can be applied in any order. If there are multiple solutions, you are allowed to print any of them.

NoteThe first sample requires a call for the entire array, and four additional calls:  one for the segment [2,2] (i.e. the second element of the array),  three for the segment [5,5] (i.e. the fifth element of the array).

<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$T = (int)$Scanner->Scan();

	for ($i = 0; $i < $T; $i++) $array[] = (int)$Scanner->Scan();
	array_unshift($array, 0);
	array_push($array, 0);

	$len = count($array);
	for ($i = 1; $i < $len; $i++) {
		$dif = $array[$i] - $array[$i - 1];

		while ($dif > 0) {
			$start[] = $i;
			$dif--;
		}

		while ($dif < 0) {
			$indexes[] = array_pop($start). " ". ($i - 1);
			$dif++;
		}
	}

	print(count($indexes)."\n");

	print(implode("\n", $indexes));

	$Scanner->Close();
}

class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);
		$contents = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	public function Scan(){
		return $this->Scanners[$this->Id++];
	}

	public function Close(){
		fclose($this->Stream);
	}
}

?>


Fox Ciel has a board with n rows and n columns. So, the board consists of n × n cells. Each cell contains either a symbol '.', or a symbol '#'.A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.Please, tell Ciel if she can draw the crosses in the described way.

The first line contains an integer n (3 ≤ n ≤ 100) — the size of the board. Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.

Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".

NoteIn example 1, you can draw two crosses. The picture below shows what they look like.In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.


The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle:   on each holiday day the Hedgehog will necessarily receive a present,  he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day).  For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer).

The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them.

Print a single number — the minimal number of presents the Hedgehog will receive over the following N days.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array_slice($c, 1);
$e = array();
$f = $b;
$g = range(1, $a);
array_unshift($g, " ");
unset($g[0]);
for($x = 1; $x <= $a; $x++)
{
    if($x == $f)
    {
        array_push($e, $g[$x]);
        $f += $b;
    }
}
$h = array_merge($d, $e);
$i = array_unique($h);
print count($i);
?>


You are given a chess board with $$$n$$$ rows and $$$n$$$ columns. Initially all cells of the board are empty, and you have to put a white or a black knight into each cell of the board.A knight is a chess piece that can attack a piece in cell ($$$x_2$$$, $$$y_2$$$) from the cell ($$$x_1$$$, $$$y_1$$$) if one of the following conditions is met:  $$$|x_1 - x_2| = 2$$$ and $$$|y_1 - y_2| = 1$$$, or  $$$|x_1 - x_2| = 1$$$ and $$$|y_1 - y_2| = 2$$$. Here are some examples of which cells knight can attack. In each of the following pictures, if the knight is currently in the blue cell, it can attack all red cells (and only them).  A duel of knights is a pair of knights of different colors such that these knights attack each other. You have to put a knight (a white one or a black one) into each cell in such a way that the number of duels is maximum possible.

The first line contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of rows (and columns) in the board.

Print $$$n$$$ lines with $$$n$$$ characters in each line. The $$$j$$$-th character in the $$$i$$$-th line should be W, if the cell ($$$i$$$, $$$j$$$) contains a white knight, or B, if it contains a black knight. The number of duels should be maximum possible. If there are multiple optimal answers, print any of them.

NoteIn the first example, there are $$$8$$$ duels:  the white knight in ($$$1$$$, $$$1$$$) attacks the black knight in ($$$3$$$, $$$2$$$);  the white knight in ($$$1$$$, $$$1$$$) attacks the black knight in ($$$2$$$, $$$3$$$);  the white knight in ($$$1$$$, $$$3$$$) attacks the black knight in ($$$3$$$, $$$2$$$);  the white knight in ($$$1$$$, $$$3$$$) attacks the black knight in ($$$2$$$, $$$1$$$);  the white knight in ($$$3$$$, $$$1$$$) attacks the black knight in ($$$1$$$, $$$2$$$);  the white knight in ($$$3$$$, $$$1$$$) attacks the black knight in ($$$2$$$, $$$3$$$);  the white knight in ($$$3$$$, $$$3$$$) attacks the black knight in ($$$1$$$, $$$2$$$);  the white knight in ($$$3$$$, $$$3$$$) attacks the black knight in ($$$2$$$, $$$1$$$).


Consider the array $$$a$$$ composed of all the integers in the range $$$[l, r]$$$. For example, if $$$l = 3$$$ and $$$r = 7$$$, then $$$a = [3, 4, 5, 6, 7]$$$.Given $$$l$$$, $$$r$$$, and $$$k$$$, is it possible for $$$\gcd(a)$$$ to be greater than $$$1$$$ after doing the following operation at most $$$k$$$ times?   Choose $$$2$$$ numbers from $$$a$$$.  Permanently remove one occurrence of each of them from the array.  Insert their product back into $$$a$$$. $$$\gcd(b)$$$ denotes the greatest common divisor (GCD) of the integers in $$$b$$$.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The description of test cases follows. The input for each test case consists of a single line containing $$$3$$$ non-negative integers $$$l$$$, $$$r$$$, and $$$k$$$ ($$$1 \leq l \leq r \leq 10^9, \enspace 0 \leq k \leq r - l$$$).

For each test case, print "YES" if it is possible to have the GCD of the corresponding array greater than $$$1$$$ by performing at most $$$k$$$ operations, and "NO" otherwise (case insensitive).

NoteFor the first test case, $$$a = [1]$$$, so the answer is "NO", since the only element in the array is $$$1$$$.For the second test case the array is $$$a = [3, 4, 5]$$$ and we have $$$1$$$ operation. After the first operation the array can change to: $$$[3, 20]$$$, $$$[4, 15]$$$ or $$$[5, 12]$$$ all of which having their greatest common divisor equal to $$$1$$$ so the answer is "NO".For the third test case, $$$a = [13]$$$, so the answer is "YES", since the only element in the array is $$$13$$$.For the fourth test case, $$$a = [4]$$$, so the answer is "YES", since the only element in the array is $$$4$$$.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
    list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
    if($c - $b == 0)
    {
         if($b == 1)
         {
              print "NO\n";
         }
         else
         {
              print "YES\n";
         }
    }
    elseif($c - $b == 1)
    {
         if($d == 0)
         {
              print "NO\n";
         }
         else
         {
              print "YES\n";
         }
    }
    else
    {
         $e = $c - $b + 1;
         if($e % 2 == 0)
         {
              if($e / 2 > $d)
              {
                   print "NO\n";
              }
              else
              {
                   print "YES\n";
              }
         }
         else
         {
               $f = ceil($e / 2);
               if($b % 2 == 0)
               {
                    if($f <= $d + 1)
                    {
                         print "YES\n";
                    }
                    else
                    {
                         print "NO\n";
                    }
               }
               else
               {
                    if($f <= $d)
                    {
                         print "YES\n";
                    }
                    else
                    {
                         print "NO\n";
                    }
               }
         }
    }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
     if($c - $b == 0)
     {
          if($b == 1)
          {
               print "NO\n";
          }
          else
          {
               print "YES\n";
          }
     }
     elseif($c - $b == 1)
     {
          if($d == 0)
          {
               print "NO\n";
          }
          else
          {
               print "YES\n";
          }
     }
     else
     {
          $e = $c - $b + 1;
          $f = ceil($e / 2);
          if($b % 2 == 0)
          {
               if($f <= $d + 1)
               {
                    print "YES\n";
               }
               else
               {
                    print "NO\n";
               }
          }
          else
          {
               if($f <= $d)
               {
                    print "YES\n";
               }
               else
               {
                    print "NO\n";
               }
          }

     }
}
?>


Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it's body extends to (1, m), then goes down 2 rows to (3, m), then goes left to (3, 1) and so on.Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#').Consider sample tests in order to understand the snake pattern.

The only line contains two integers: n and m (3 ≤ n, m ≤ 50).  n is an odd number.

Output n lines. Each line should contain a string consisting of m characters. Do not output spaces.

<?php

list($line, $length) = explode(' ', fgets(STDIN));

$mainLine  = str_repeat('#', $length);
$leftLine  = '#' . str_repeat('.', $length - 1);
$rightLine = str_repeat('.', $length - 1) . '#';

for ($curLine = 0; $curLine < $line; ++$curLine) {
    if ($curLine % 2 === 0) {
        echo $mainLine . PHP_EOL;
    }

    if ($curLine % 4 === 1) {
        echo $rightLine . PHP_EOL;
    }
    if ($curLine % 4 === 3) {
        echo $leftLine . PHP_EOL;
    }
}

<?php
// 510A     Лиса и змейка
$in = fopen("php://stdin", 'r');

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

$n = (int) $n;
$m = (int) $m;

$strC = str_repeat('#', $m) . "\n";
$strL = '#' . str_repeat('.', $m - 1) . "\n";
$strR = str_repeat('.', $m - 1) . "#\n";

for ($i=0; $i < $n; $i+=4) {
    echo $strC;
    if (($i + 1) < $n) {
        echo $strR;
    }
    if (($i + 2) < $n) {
        echo $strC;
    }
    if (($i + 3) < $n) {
        echo $strL;
    }
}

?>

<?php

fscanf(STDIN, '%d%d', $n, $m);

$out = array_fill(0, $n, array_fill(0, $m, '.'));

$i = $j = 0;
$dir = 1;

while ($i < $n) {
    $out[$i][$j] = '#';
    $j += $dir;
    if ($j == $m || $j == -1) {
        $j -= $dir;
        $out[$i + 1][$j] = '#';
        $i += 2;
        $dir *= -1;
    }
}

unset($out[$n]);

function glue(array $strings)
{
    return join('', $strings);
}

echo join(PHP_EOL, array_map('glue', $out));


You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x).

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

Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.

NoteIn the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).In the second example all pairs of indexes (i, j) (where i < j) include in answer.


There is a square field of size $$$n \times n$$$ in which two cells are marked. These cells can be in the same row or column.You are to mark two more cells so that they are the corners of a rectangle with sides parallel to the coordinate axes.For example, if $$$n=4$$$ and a rectangular field looks like this (there are asterisks in the marked cells):$$$$$$ \begin{matrix} . & . & * & . \\ . & . & . & . \\ * & . & . & . \\ . & . & . & . \\ \end{matrix} $$$$$$Then you can mark two more cells as follows$$$$$$ \begin{matrix} * & . & * & . \\ . & . & . & . \\ * & . & * & . \\ . & . & . & . \\ \end{matrix} $$$$$$If there are several possible solutions, then print any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 400$$$). Then $$$t$$$ test cases follow. The first row of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 400$$$) — the number of rows and columns in the table. The following $$$n$$$ lines each contain $$$n$$$ characters '.' or '*' denoting empty and marked cells, respectively. It is guaranteed that the sums of $$$n$$$ for all test cases do not exceed $$$400$$$. It is guaranteed that there are exactly two asterisks on the field. They can be in the same row/column. It is guaranteed that the solution exists.

For each test case, output $$$n$$$ rows of $$$n$$$ characters — a field with four asterisks marked corresponding to the statements. If there multiple correct answers, print any of them.

<?php
    $rectangles = [];
    $cases = trim(fgets(STDIN));
    for($i=0; $i<$cases; $i++){
        $lines = [];
        $n = trim(fgets(STDIN));
        for($j=0; $j<$n; $j++){
            array_push($lines,trim(fgets(STDIN)));
        }
        array_push($rectangles,$lines);
    }

    //v poli (obrazci) hledáme řádek a v něm porovnáme každý znak s *
    for($i=0; $i<count($rectangles); $i++){
        $firstAstX = 0;
        $firstAstY = 0;
        $secondAstX = 0;
        $secondAstY = 0;
        $thirdAstX = 0;
        $thirdAstY = 0;
        $fourthAstX = 0;
        $fourthAstY = 0;
        for($j=0; $j<count($rectangles[$i]); $j++){
            for($k=0; $k<strlen($rectangles[$i][$j]); $k++){
                if(substr($rectangles[$i][$j],$k,1) == "*"){
                    //nalezení druhé * vyvolá komplet změny
                    if($firstAstX > 0){
                        $secondAstX = $k+1;
                        $secondAstY = $j+1;
                        //pokud jsou dvě * nad sebou
                        if($firstAstX == $secondAstX){
                            if($firstAstX > 1){
                                $thirdAstX = $firstAstX-1;
                                $thirdAstY = $firstAstY;
                                $fourthAstX = $secondAstX-1;
                                $fourthAstY = $secondAstY;

                                //přepsání řádku se čtvrtou *
                                if($fourthAstX == 1){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                                    $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                                }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                                }else{
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                                    $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                                }

                                //přepsání řádku se třetí *
                                if($thirdAstX == 1){
                                    $thirdZ = substr($rectangles[$i][$j],1);
                                    $rectangles[$i][$j] = "*" . $thirdZ;
                                }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                                    $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                                    $rectangles[$i][$j] = $thirdZ . "*";
                                }else{
                                    $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                                    $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                                    $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }else{
                                $thirdAstX = $firstAstX+1;
                                $thirdAstY = $firstAstY;
                                $fourthAstX = $secondAstX+1;
                                $fourthAstY = $secondAstY;

                                //přepsání řádku se čtvrtou *
                                if($fourthAstX == 1){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                                    $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                                }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                                }else{
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                                    $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                                }

                                //přepsání řádku se třetí *
                                if($thirdAstX == 1){
                                    $thirdZ = substr($rectangles[$i][$j],1);
                                    $rectangles[$i][$j] = "*" . $thirdZ;
                                }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                                    $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                                    $rectangles[$i][$j] = $thirdZ . "*";
                                }else{
                                    $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                                    $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                                    $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }
                        }
                        //pokud jsou dvě * vedle sebe na řádku
                        if($firstAstY == $secondAstY){
                            if($firstAstY > 1){
                                $thirdAstX = $firstAstX;
                                $thirdAstY = $firstAstY-1;
                                $fourthAstX = $secondAstX;
                                $fourthAstY = $secondAstY-1;

                                //přepsání řádku se třetí a čtvrtou *
                                if($thirdAstX == 1){
                                    if($fourthAstX == 2){
                                        $space = substr($rectangles[$i][$firstAstY-2],$fourthAstX,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                        $rectangles[$i][$firstAstY-2] = "**" . $space;
                                    }else{
                                        $thirdZ = substr($rectangles[$i][$firstAstY-2],1,$fourthAstX-$thirdAstX-1);
                                        $fourthZ = substr($rectangles[$i][$firstAstY-2],$thirdAstX,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                        $rectangles[$i][$firstAstY-2] = "*" . $thirdZ . "*" . $fourthZ;
                                    }
                                }else{
                                    $thirdZ = substr($rectangles[$i][$firstAstY-2],0,$thirdAstX-1);
                                    $fourthZ = substr($rectangles[$i][$firstAstY-2],$thirdAstX,$fourthAstX-$thirdAstX-1);
                                    $space = substr($rectangles[$i][$firstAstY-2],$fourthAstX,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-2] = $thirdZ . "*" . $fourthZ . "*" . $space;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }else{
                                $thirdAstX = $firstAstX;
                                $thirdAstY = $firstAstY+1;
                                $fourthAstX = $secondAstX;
                                $fourthAstY = $secondAstY+1;

                                //přepsání řádku se třetí a čtvrtou *
                                if($thirdAstX == 1){
                                    if($fourthAstX == 2){
                                        $space = substr($rectangles[$i][$firstAstY],$fourthAstX,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                        $rectangles[$i][$firstAstY] = "**" . $space;
                                    }else{
                                        $thirdZ = substr($rectangles[$i][$firstAstY],1,$fourthAstX-$thirdAstX-1);
                                        $fourthZ = substr($rectangles[$i][$firstAstY],$thirdAstX,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                        $rectangles[$i][$firstAstY] = "*" . $thirdZ . "*" . $fourthZ;
                                    }
                                }else{
                                    $thirdZ = substr($rectangles[$i][$firstAstY],0,$thirdAstX-1);
                                    $fourthZ = substr($rectangles[$i][$firstAstY],$thirdAstX,$fourthAstX-$thirdAstX-1);
                                    $space = substr($rectangles[$i][$firstAstY],$fourthAstX,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                    $rectangles[$i][$firstAstY] = $thirdZ . "*" . $fourthZ . "*" . $space;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }
                        }
                        //pokud jsou dvě * na různých pozicích
                        $thirdAstX = $firstAstX;
                        $thirdAstY = $secondAstY;
                        $fourthAstX = $secondAstX;
                        $fourthAstY = $firstAstY;

                        //přepsání řádku se čtvrtou *
                        if($fourthAstX == 1){
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                            $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                        }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                            $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                        }else{
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                            $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                            $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                        }

                        //přepsání řádku se třetí *
                        if($thirdAstX == 1){
                            $thirdZ = substr($rectangles[$i][$j],1);
                            $rectangles[$i][$j] = "*" . $thirdZ;
                        }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                            $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                            $rectangles[$i][$j] = $thirdZ . "*";
                        }else{
                            $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                            $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                            $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                        }

                        for($l=0; $l<count($rectangles[$i]); $l++){
                            echo $rectangles[$i][$l] . "\n";
                        }

                        continue 3;
                    }
                    $firstAstX = $k+1;
                    $firstAstY = $j+1;
                }
            }
        }
    }
?>

<?php

function print_rect($matrix, $lines, $positions)
{
    for ($k=1; $k <= $matrix; $k++) {
        for ($l=1; $l <= $matrix; $l++) {
            if ($k == $lines[0] || $k == $lines[1]) {
                if ($l == $positions[0] || $l == $positions[1]) {
                    echo "*";
                } else {
                    echo ".";
                }

            }else {
                echo ".";
            }
        }
        echo "\n";
    }
}

function position_maker($lines, $positions)
{
    if ($positions[0] == $positions[1]) {
        if ($positions[0] == $lines) {
            $positions[0]-= 1;
        }else {
            $positions[1]+= 1;
        }
    }

    return $positions;
}

function line_maker($lines, $star_line)
{
    if ($star_line[0] == $star_line[1]) {
        if ($star_line[1] == $lines) {
            $star_line[1]-= 1;
        }else {
            $star_line[1]+= 1;
        }
    }else {

    }

    return $star_line;
}

// --------------
$looper = readline();

for ($x=0; $x < $looper; $x++) {

    $matrix = readline();

    $star_line = array();
    $position = array();

    for ($i=0; $i < $matrix; $i++) {
        $s_line = readline();

        for ($j=0; $j < $matrix; $j++) {
            if ($s_line[$j] == "*") {
                array_push($star_line, $i+1);
                array_push($position, $j+1);
            }
        }
    }

    $star_line = line_maker($matrix, $star_line);
    $position = position_maker($matrix, $position);

    // (4, [1,3], [3,1]);
    print_rect($matrix, $star_line, $position);
}

<?php

$t = readline();

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

    $n = readline();
    $matrix=[];
    $count = 0;
    $position_i1 = "";
    $position_i2 = "";
    $position_j1 = "";
    $position_j2 = "";

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

        $char = readline();
        $char_element = str_split($char);

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

            $matrix[$i][$j] = $char_element[$j];
        }
    }

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

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

            if($matrix[$i][$j] == "*"){
                if($count>0){

                    $position_i2 = $i;
                    $position_j2 = $j;
                }
                else{
                    $position_i1 = $i;
                    $position_j1 = $j;
                }
                $count++;
            }

            if($count==2){
                break;
            }
        }
    }

    if(($position_i1<$position_i2 && $position_j1>$position_j2) ||
        ($position_i1<$position_i2 && $position_j1<$position_j2) ){

        $matrix[$position_i1][$position_j2] = "*";
        $matrix[$position_i2][$position_j1] = "*";
    }

    elseif (($position_i1<$position_i2 && $position_j1==$position_j2)){

        if($position_j1 == ($n-1)){

            $matrix[$position_i1][$position_j1-1] = "*";
            $matrix[$position_i2][$position_j2-1] = "*";
        }
        else{
            $matrix[$position_i1][$position_j1+1] = "*";
            $matrix[$position_i2][$position_j2+1] = "*";
        }
    }
    elseif($position_i1==$position_i2){

        if($position_i1 == ($n-1)){
            $matrix[$position_i1-1][$position_j1] = "*";
            $matrix[$position_i2-1][$position_j2] = "*";
        }
        else{
            $matrix[$position_i1+1][$position_j1] = "*";
            $matrix[$position_i2+1][$position_j2] = "*";
        }
    }

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

        for ($j = 0; $j < $n; $j++) {
            echo $matrix[$i][$j];
        }
        echo "\n";

    }
}

<?php
    $rectangles = [];
    $cases = trim(fgets(STDIN));
    for($i=0; $i<$cases; $i++){
        $lines = [];
        $n = trim(fgets(STDIN));
        for($j=0; $j<$n; $j++){
            array_push($lines,trim(fgets(STDIN)));
        }
        array_push($rectangles,$lines);
    }

    //v poli (obrazci) hledáme řádek a v něm porovnáme každý znak s *
    for($i=0; $i<count($rectangles); $i++){
        $firstAstX = 0;
        $firstAstY = 0;
        $secondAstX = 0;
        $secondAstY = 0;
        $thirdAstX = 0;
        $thirdAstY = 0;
        $fourthAstX = 0;
        $fourthAstY = 0;
        for($j=0; $j<count($rectangles[$i]); $j++){
            for($k=0; $k<strlen($rectangles[$i][$j]); $k++){
                if(substr($rectangles[$i][$j],$k,1) == "*"){
                    //nalezení druhé * vyvolá komplet změny
                    if($firstAstX > 0){
                        $secondAstX = $k+1;
                        $secondAstY = $j+1;
                        //pokud jsou dvě * nad sebou
                        if($firstAstX == $secondAstX){
                            if($firstAstX > 1){
                                $thirdAstX = $firstAstX-1;
                                $thirdAstY = $firstAstY;
                                $fourthAstX = $secondAstX-1;
                                $fourthAstY = $secondAstY;

                                //přepsání řádku se čtvrtou *
                                if($fourthAstX == 1){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                                    $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                                }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                                }else{
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                                    $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                                }

                                //přepsání řádku se třetí *
                                if($thirdAstX == 1){
                                    $thirdZ = substr($rectangles[$i][$j],1);
                                    $rectangles[$i][$j] = "*" . $thirdZ;
                                }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                                    $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                                    $rectangles[$i][$j] = $thirdZ . "*";
                                }else{
                                    $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                                    $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                                    $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }else{
                                $thirdAstX = $firstAstX+1;
                                $thirdAstY = $firstAstY;
                                $fourthAstX = $secondAstX+1;
                                $fourthAstY = $secondAstY;

                                //přepsání řádku se čtvrtou *
                                if($fourthAstX == 1){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                                    $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                                }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                                }else{
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                                    $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                                }

                                //přepsání řádku se třetí *
                                if($thirdAstX == 1){
                                    $thirdZ = substr($rectangles[$i][$j],1);
                                    $rectangles[$i][$j] = "*" . $thirdZ;
                                }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                                    $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                                    $rectangles[$i][$j] = $thirdZ . "*";
                                }else{
                                    $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                                    $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                                    $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }
                        }
                        //pokud jsou dvě * vedle sebe na řádku
                        if($firstAstY == $secondAstY){
                            if($firstAstY > 1){
                                $thirdAstX = $firstAstX;
                                $thirdAstY = $firstAstY-1;
                                $fourthAstX = $secondAstX;
                                $fourthAstY = $secondAstY-1;

                                //přepsání řádku se třetí a čtvrtou *
                                if($thirdAstX == 1){
                                    if($fourthAstX == 2){
                                        $space = substr($rectangles[$i][$firstAstY-2],$fourthAstX,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                        $rectangles[$i][$firstAstY-2] = "**" . $space;
                                    }else{
                                        $thirdZ = substr($rectangles[$i][$firstAstY-2],1,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                        $fourthZ = substr($rectangles[$i][$firstAstY-2],$thirdAstX,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                        $rectangles[$i][$firstAstY-2] = "*" . $thirdZ . "*" . $fourthZ;
                                    }
                                }else{
                                    $thirdZ = substr($rectangles[$i][$firstAstY-2],0,$thirdAstX-1);
                                    $fourthZ = substr($rectangles[$i][$firstAstY-2],$thirdAstX,$fourthAstX-$thirdAstX-1);
                                    $space = substr($rectangles[$i][$firstAstY-2],$fourthAstX,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-2] = $thirdZ . "*" . $fourthZ . "*" . $space;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }else{
                                $thirdAstX = $firstAstX;
                                $thirdAstY = $firstAstY+1;
                                $fourthAstX = $secondAstX;
                                $fourthAstY = $secondAstY+1;

                                //přepsání řádku se třetí a čtvrtou *
                                if($thirdAstX == 1){
                                    if($fourthAstX == 2){
                                        $space = substr($rectangles[$i][$firstAstY],$fourthAstX,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                        $rectangles[$i][$firstAstY] = "**" . $space;
                                    }else{
                                        $thirdZ = substr($rectangles[$i][$firstAstY],1,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                        $fourthZ = substr($rectangles[$i][$firstAstY],$thirdAstX,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                        $rectangles[$i][$firstAstY] = "*" . $thirdZ . "*" . $fourthZ;
                                    }
                                }else{
                                    $thirdZ = substr($rectangles[$i][$firstAstY],0,$thirdAstX-1);
                                    $fourthZ = substr($rectangles[$i][$firstAstY],$thirdAstX,$fourthAstX-$thirdAstX-1);
                                    $space = substr($rectangles[$i][$firstAstY],$fourthAstX,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                    $rectangles[$i][$firstAstY] = $thirdZ . "*" . $fourthZ . "*" . $space;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }
                        }
                        //pokud jsou dvě * na různých pozicích
                        $thirdAstX = $firstAstX;
                        $thirdAstY = $secondAstY;
                        $fourthAstX = $secondAstX;
                        $fourthAstY = $firstAstY;

                        //přepsání řádku se čtvrtou *
                        if($fourthAstX == 1){
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                            $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                        }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                            $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                        }else{
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                            $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                            $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                        }

                        //přepsání řádku se třetí *
                        if($thirdAstX == 1){
                            $thirdZ = substr($rectangles[$i][$j],1);
                            $rectangles[$i][$j] = "*" . $thirdZ;
                        }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                            $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                            $rectangles[$i][$j] = $thirdZ . "*";
                        }else{
                            $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                            $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                            $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                        }

                        for($l=0; $l<count($rectangles[$i]); $l++){
                            echo $rectangles[$i][$l] . "\n";
                        }

                        continue 3;
                    }
                    $firstAstX = $k+1;
                    $firstAstY = $j+1;
                }
            }
        }
    }
?>

<?php
    $rectangles = [];
    $cases = trim(fgets(STDIN));
    for($i=0; $i<$cases; $i++){
        $lines = [];
        $n = trim(fgets(STDIN));
        for($j=0; $j<$n; $j++){
            array_push($lines,trim(fgets(STDIN)));
        }
        array_push($rectangles,$lines);
    }

    //v poli (obrazci) hledáme řádek a v něm porovnáme každý znak s *
    for($i=0; $i<count($rectangles); $i++){
        $firstAstX = 0;
        $firstAstY = 0;
        $secondAstX = 0;
        $secondAstY = 0;
        $thirdAstX = 0;
        $thirdAstY = 0;
        $fourthAstX = 0;
        $fourthAstY = 0;
        for($j=0; $j<count($rectangles[$i]); $j++){
            for($k=0; $k<strlen($rectangles[$i][$j]); $k++){
                if(substr($rectangles[$i][$j],$k,1) == "*"){
                    //nalezení druhé * vyvolá komplet změny
                    if($firstAstX > 0){
                        $secondAstX = $k+1;
                        $secondAstY = $j+1;
                        //pokud jsou dvě * nad sebou
                        if($firstAstX == $secondAstX){
                            if($firstAstX > 1){
                                $thirdAstX = $firstAstX-1;
                                $thirdAstY = $firstAstY;
                                $fourthAstX = $secondAstX-1;
                                $fourthAstY = $secondAstY;

                                //přepsání řádku se čtvrtou *
                                if($fourthAstX == 1){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                                    $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                                }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                                }else{
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                                    $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                                }

                                //přepsání řádku se třetí *
                                if($thirdAstX == 1){
                                    $thirdZ = substr($rectangles[$i][$j],1);
                                    $rectangles[$i][$j] = "*" . $thirdZ;
                                }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                                    $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                                    $rectangles[$i][$j] = $thirdZ . "*";
                                }else{
                                    $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                                    $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                                    $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }else{
                                $thirdAstX = $firstAstX+1;
                                $thirdAstY = $firstAstY;
                                $fourthAstX = $secondAstX+1;
                                $fourthAstY = $secondAstY;

                                //přepsání řádku se čtvrtou *
                                if($fourthAstX == 1){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                                    $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                                }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                                }else{
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                                    $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                                }

                                //přepsání řádku se třetí *
                                if($thirdAstX == 1){
                                    $thirdZ = substr($rectangles[$i][$j],1);
                                    $rectangles[$i][$j] = "*" . $thirdZ;
                                }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                                    $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                                    $rectangles[$i][$j] = $thirdZ . "*";
                                }else{
                                    $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                                    $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                                    $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }
                        }
                        //pokud jsou dvě * vedle sebe na řádku
                        if($firstAstY == $secondAstY){
                            if($firstAstY > 1){
                                $thirdAstX = $firstAstX;
                                $thirdAstY = $firstAstY-1;
                                $fourthAstX = $secondAstX;
                                $fourthAstY = $secondAstY-1;

                                //přepsání řádku se třetí a čtvrtou *
                                if($thirdAstX == 1){
                                    if($fourthAstX == 2){
                                        $space = substr($rectangles[$i][$firstAstY-2],$fourthAstX,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                        $rectangles[$i][$firstAstY-2] = "**" . $space;
                                    }else{
                                        $thirdZ = substr($rectangles[$i][$firstAstY-2],1,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX-1);
                                        $fourthZ = substr($rectangles[$i][$firstAstY-2],$fourthAstX,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                        $rectangles[$i][$firstAstY-2] = "*" . $thirdZ . "*" . $fourthZ;
                                    }
                                }else{
                                    $thirdZ = substr($rectangles[$i][$firstAstY-2],0,$thirdAstX-1);
                                    $fourthZ = substr($rectangles[$i][$firstAstY-2],$thirdAstX,$fourthAstX-$thirdAstX-1);
                                    $space = substr($rectangles[$i][$firstAstY-2],$fourthAstX,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-2] = $thirdZ . "*" . $fourthZ . "*" . $space;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }else{
                                $thirdAstX = $firstAstX;
                                $thirdAstY = $firstAstY+1;
                                $fourthAstX = $secondAstX;
                                $fourthAstY = $secondAstY+1;

                                //přepsání řádku se třetí a čtvrtou *
                                if($thirdAstX == 1){
                                    if($fourthAstX == 2){
                                        $space = substr($rectangles[$i][$firstAstY],$fourthAstX,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                        $rectangles[$i][$firstAstY] = "**" . $space;
                                    }else{
                                        $thirdZ = substr($rectangles[$i][$firstAstY],1,strlen($rectangles[$i][$firstAstY])-$fourthAstX-1);
                                        $fourthZ = substr($rectangles[$i][$firstAstY],$fourthAstX,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                        $rectangles[$i][$firstAstY] = "*" . $thirdZ . "*" . $fourthZ;
                                    }
                                }else{
                                    $thirdZ = substr($rectangles[$i][$firstAstY],0,$thirdAstX-1);
                                    $fourthZ = substr($rectangles[$i][$firstAstY],$thirdAstX,$fourthAstX-$thirdAstX-1);
                                    $space = substr($rectangles[$i][$firstAstY],$fourthAstX,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                    $rectangles[$i][$firstAstY] = $thirdZ . "*" . $fourthZ . "*" . $space;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }
                        }
                        //pokud jsou dvě * na různých pozicích
                        $thirdAstX = $firstAstX;
                        $thirdAstY = $secondAstY;
                        $fourthAstX = $secondAstX;
                        $fourthAstY = $firstAstY;

                        //přepsání řádku se čtvrtou *
                        if($fourthAstX == 1){
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                            $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                        }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                            $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                        }else{
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                            $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                            $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                        }

                        //přepsání řádku se třetí *
                        if($thirdAstX == 1){
                            $thirdZ = substr($rectangles[$i][$j],1);
                            $rectangles[$i][$j] = "*" . $thirdZ;
                        }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                            $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                            $rectangles[$i][$j] = $thirdZ . "*";
                        }else{
                            $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                            $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                            $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                        }

                        for($l=0; $l<count($rectangles[$i]); $l++){
                            echo $rectangles[$i][$l] . "\n";
                        }

                        continue 3;
                    }
                    $firstAstX = $k+1;
                    $firstAstY = $j+1;
                }
            }
        }
    }
?>

<?php
    $rectangles = [];
    $cases = trim(fgets(STDIN));
    for($i=0; $i<$cases; $i++){
        $lines = [];
        $n = trim(fgets(STDIN));
        for($j=0; $j<$n; $j++){
            array_push($lines,trim(fgets(STDIN)));
        }
        array_push($rectangles,$lines);
    }

    //v poli (obrazci) hledáme řádek a v něm porovnáme každý znak s *
    for($i=0; $i<count($rectangles); $i++){
        $firstAstX = 0;
        $firstAstY = 0;
        $secondAstX = 0;
        $secondAstY = 0;
        $thirdAstX = 0;
        $thirdAstY = 0;
        $fourthAstX = 0;
        $fourthAstY = 0;
        for($j=0; $j<count($rectangles[$i]); $j++){
            for($k=0; $k<strlen($rectangles[$i][$j]); $k++){
                if(substr($rectangles[$i][$j],$k,1) == "*"){
                    //nalezení druhé * vyvolá komplet změny
                    if($firstAstX > 0){
                        $secondAstX = $k+1;
                        $secondAstY = $j+1;
                        //pokud jsou dvě * nad sebou
                        if($firstAstX == $secondAstX){
                            if($firstAstX > 1){
                                $thirdAstX = $firstAstX-1;
                                $thirdAstY = $firstAstY;
                                $fourthAstX = $secondAstX-1;
                                $fourthAstY = $secondAstY;

                                //přepsání řádku se čtvrtou *
                                if($fourthAstX == 1){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                                    $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                                }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                                }else{
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                                    $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                                }

                                //přepsání řádku se třetí *
                                if($thirdAstX == 1){
                                    $thirdZ = substr($rectangles[$i][$j],1);
                                    $rectangles[$i][$j] = "*" . $thirdZ;
                                }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                                    $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                                    $rectangles[$i][$j] = $thirdZ . "*";
                                }else{
                                    $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                                    $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                                    $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }else{
                                $thirdAstX = $firstAstX+1;
                                $thirdAstY = $firstAstY;
                                $fourthAstX = $secondAstX+1;
                                $fourthAstY = $secondAstY;

                                //přepsání řádku se čtvrtou *
                                if($fourthAstX == 1){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                                    $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                                }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                                }else{
                                    $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                                    $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                                }

                                //přepsání řádku se třetí *
                                if($thirdAstX == 1){
                                    $thirdZ = substr($rectangles[$i][$j],1);
                                    $rectangles[$i][$j] = "*" . $thirdZ;
                                }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                                    $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                                    $rectangles[$i][$j] = $thirdZ . "*";
                                }else{
                                    $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                                    $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                                    $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }
                        }
                        //pokud jsou dvě * vedle sebe na řádku
                        if($firstAstY == $secondAstY){
                            if($firstAstY > 1){
                                $thirdAstX = $firstAstX;
                                $thirdAstY = $firstAstY-1;
                                $fourthAstX = $secondAstX;
                                $fourthAstY = $secondAstY-1;

                                //přepsání řádku se třetí a čtvrtou *
                                if($thirdAstX == 1){
                                    $thirdZ = substr($rectangles[$i][$firstAstY-2],1,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX-1);
                                    $fourthZ = substr($rectangles[$i][$firstAstY-2],$fourthAstX,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-2] = "*" . $thirdZ . "*" . $fourthZ;
                                }else{
                                    $thirdZ = substr($rectangles[$i][$firstAstY-2],0,$thirdAstX-1);
                                    $fourthZ = substr($rectangles[$i][$firstAstY-2],$thirdAstX,$fourthAstX-$thirdAstX-1);
                                    $space = substr($rectangles[$i][$firstAstY-2],$fourthAstX,strlen($rectangles[$i][$firstAstY-2])-$fourthAstX);
                                    $rectangles[$i][$firstAstY-2] = $thirdZ . "*" . $fourthZ . "*" . $space;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }else{
                                $thirdAstX = $firstAstX;
                                $thirdAstY = $firstAstY+1;
                                $fourthAstX = $secondAstX;
                                $fourthAstY = $secondAstY+1;

                                //přepsání řádku se třetí a čtvrtou *
                                if($thirdAstX == 1){
                                    $thirdZ = substr($rectangles[$i][$firstAstY],1,strlen($rectangles[$i][$firstAstY])-$fourthAstX-1);
                                    $fourthZ = substr($rectangles[$i][$firstAstY],$fourthAstX,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                    $rectangles[$i][$firstAstY] = "*" . $thirdZ . "*" . $fourthZ;
                                }else{
                                    $thirdZ = substr($rectangles[$i][$firstAstY],0,$thirdAstX-1);
                                    $fourthZ = substr($rectangles[$i][$firstAstY],$thirdAstX,$fourthAstX-$thirdAstX-1);
                                    $space = substr($rectangles[$i][$firstAstY],$fourthAstX,strlen($rectangles[$i][$firstAstY])-$fourthAstX);
                                    $rectangles[$i][$firstAstY] = $thirdZ . "*" . $fourthZ . "*" . $space;
                                }

                                for($l=0; $l<count($rectangles[$i]); $l++){
                                    echo $rectangles[$i][$l] . "\n";
                                }

                                continue 3;
                            }
                        }
                        //pokud jsou dvě * na různých pozicích
                        $thirdAstX = $firstAstX;
                        $thirdAstY = $secondAstY;
                        $fourthAstX = $secondAstX;
                        $fourthAstY = $firstAstY;

                        //přepsání řádku se čtvrtou *
                        if($fourthAstX == 1){
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],1);
                            $rectangles[$i][$firstAstY-1] = "*" . $fourthZ;
                        }elseif($fourthAstX == strlen($rectangles[$i][$firstAstY-1])){
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],0,strlen($rectangles[$i][$firstAstY-1])-1);
                            $rectangles[$i][$firstAstY-1] = $fourthZ . "*";
                        }else{
                            $fourthZ = substr($rectangles[$i][$firstAstY-1],0,$fourthAstX-1);
                            $fourthZz = substr($rectangles[$i][$firstAstY-1],$fourthAstX,strlen($rectangles[$i][$firstAstY-1])-$fourthAstX);
                            $rectangles[$i][$firstAstY-1] = $fourthZ . "*" . $fourthZz;
                        }

                        //přepsání řádku se třetí *
                        if($thirdAstX == 1){
                            $thirdZ = substr($rectangles[$i][$j],1);
                            $rectangles[$i][$j] = "*" . $thirdZ;
                        }elseif($thirdAstX == strlen($rectangles[$i][$j])){
                            $thirdZ = substr($rectangles[$i][$j],0,strlen($rectangles[$i][$j])-1);
                            $rectangles[$i][$j] = $thirdZ . "*";
                        }else{
                            $thirdZ = substr($rectangles[$i][$j],0,$thirdAstX-1);
                            $thirdZz = substr($rectangles[$i][$j],$thirdAstX,strlen($rectangles[$i][$j])-$thirdAstX);
                            $rectangles[$i][$j] = $thirdZ . "*" . $thirdZz;
                        }

                        for($l=0; $l<count($rectangles[$i]); $l++){
                            echo $rectangles[$i][$l] . "\n";
                        }

                        continue 3;
                    }
                    $firstAstX = $k+1;
                    $firstAstY = $j+1;
                }
            }
        }
    }
?>

<?php

function print_rect($matrix, $lines, $positions)
{
    for ($k=1; $k <= $matrix; $k++) {
        for ($l=1; $l <= $matrix; $l++) {
            if ($k == $lines[0] || $k == $lines[1]) {
                if ($l == $positions[0] || $l == $positions[1]) {
                    echo "*";
                } else {
                    echo ".";
                }

            }else {
                echo ".";
            }
        }
        echo "\n";
    }
}

function position_maker($lines, $positions)
{
    if ($positions[0] == $positions[1]) {
        if ($positions[0] == $lines) {
            $positions[0]-= 1;
        }else {
            $positions[1]+= 1;
        }
    }

    return $positions;
}

function line_maker($lines, $star_line)
{
    if ($star_line[0] == $star_line[1]) {
        if ($star_line[1] == $lines) {
            $star_line[1]-= 1;
        }else {
            $star_line[1]+= 1;
        }
    }else {

    }

    return $star_line;
}

// --------------
fscanf(STDIN, "%d", $looper);

for ($x=0; $x < $looper; $x++) {

    $matrix = readline();

    $star_line = array();
    $position = array();

    for ($i=0; $i < $matrix; $i++) {
        $s_line = readline();

        for ($j=0; $j < $matrix; $j++) {
            if ($s_line[$j] == "*") {
                array_push($star_line, $i+1);
                array_push($position, $j+1);
            }
        }
    }

    $star_line = line_maker($matrix, $star_line);
    $position = position_maker($matrix, $position);

    // (4, [1,3], [3,1]);
    print_rect($matrix, $star_line, $position);
}

<?php

function print_rect($matrix, $lines, $positions)
{
    for ($i=1; $i <= $matrix; $i++) {
        for ($j=1; $j <= $matrix; $j++) {
            if ($i == $lines[0] || $i == $lines[1]) {
                if ($j == $positions[0] || $j == $positions[1]) {
                    echo "*";
                } else {
                    echo ".";
                }

            }else {
                echo ".";
            }
        }
        echo "\n";
    }
}

function position_maker($lines, $positions)
{
    if ($positions[0] == $positions[1]) {
        if ($positions[0] == $lines) {
            $positions[0]-= 1;
        }else {
            $positions[1]+= 1;
        }
    }

    return $positions;
}

function line_maker($lines, $star_line)
{
    if ($star_line[0] == $star_line[1]) {
        if ($star_line[1] == $lines) {
            $star_line[1]-= 1;
        }else {
            $star_line[1]+= 1;
        }
    }else {

    }

    return $star_line;
}

fscanf(STDIN, "%d", $looper);

while ($looper--) {

    fscanf(STDIN, "%d", $matrix);

    $star_line = [];
    $position = [];

    for ($i=0; $i < $matrix; $i++) {
        $s_line = readline();

        for ($j=0; $j < 4; $j++) {
            if ($s_line[$j] == "*") {
                array_push($star_line, $i+1);
                array_push($position, $j+1);
            }
        }
    }

    $star_line = line_maker($matrix, $star_line);
    $position = position_maker($matrix, $position);

    // (4, [1,3], [3,1]);
    print_rect($matrix, $star_line, $position);
}


During a New Year special offer the "Sudislavl Bars" offered n promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum k, that the promotional code could be uniquely identified if it was typed with no more than k errors. At that, k = 0 means that the promotional codes must be entered exactly.A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits.

The first line of the output contains number n (1 ≤ n ≤ 1000) — the number of promocodes. Each of the next n lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0".

Print the maximum k (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most k mistakes.

NoteIn the first sample k < 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it.

<?php
ini_set("memory_limit", "256M");
ini_set("max_execution_time", 3);

$fd = fopen("php://stdin", 'r');
$count = fgets($fd);

function compare($a, $b) {
    $result = 0;
    for ($i = 0; $i < 6; $i++) {
        if ($a[$i] == $b[$i]) {
            $result++;
        }
    }
    return $result;
}

$similar = 0;
$numbers = [];

while (!feof($fd)) {
    $num = substr(fgets($fd), 0, 6);
    foreach ($numbers as $stored) {
        $cmp = compare($num, $stored);
        if ($cmp > $similar) {
            $similar = $cmp;
        }
    }
    $numbers[] = $num;
}
if ($count == 1) {
    echo 6;
} else {
    echo max(floor((5 - $similar) / 2), 0);
}

<?

$n = (int) fgets(STDIN);

$length = 6;
$codes = [];

$k = $length;
for ($i = 0; $i < $n; $i++) {
    $code = trim(fgets(STDIN));

    $min_differences = $length;
    foreach ($codes as $item) {
        $differences = 0;
        for ($j = 0; $j < $length; $j++) {
            if ($item{$j} !== $code{$j}) {
                $differences++;
            }
        }

        if ($min_differences > $differences) {
            $min_differences = $differences;
        }
    }

    if ($k > $min_differences) {
        $k = $min_differences;
    }

    $codes[] = $code;
}

echo ($n == 1 ? $length : floor(($k - 1) / 2));

<?php
ini_set("memory_limit", "256M");
ini_set("max_execution_time", 3);

$fd = fopen("php://stdin", 'r');
fgets($fd);

function compare($a, $b) {
    $result = 0;
    for ($i = 0; $i < 6; $i++) {
        if ($a[$i] == $b[$i]) {
            $result++;
        }
    }
    return $result;
}

$similar = 0;
$numbers = [];

while (!feof($fd)) {
    $num = substr(fgets($fd), 0, 6);
    foreach ($numbers as $stored) {
        $cmp = compare($num, $stored);
        if ($cmp > $similar) {
            $similar = $cmp;
        }
    }
    $numbers[] = $num;
}

echo max(floor((5 - $similar) / 2), 0);

<?php
ini_set("memory_limit", "256M");
ini_set("max_execution_time", 3);

$fd = fopen("php://stdin", 'r');
fgets($fd);

function compare($a, $b) {
    $result = 0;
    for ($i = 0; $i < 6; $i++) {
        if ($a[$i] == $b[$i]) {
            $result++;
        }
    }
    return $result;
}

$similar = 0;
$numbers = [];

while (!feof($fd)) {
    $num = substr(fgets($fd), 0, 6);
    foreach ($numbers as $stored) {
        $cmp = compare($num, $stored);
        if ($cmp > $similar) {
            $similar = $cmp;
        }
    }
    $numbers[] = $num;
}
if (count($numbers) == 1) {
    echo 6;
} else {
    echo max(floor((5 - $similar) / 2), 0);
}

<?php
ini_set("memory_limit", "256M");
ini_set("max_execution_time", 3);

$fd = fopen("php://stdin", 'r');
fgets($fd);

function compare($a, $b) {
    $result = 0;
    for ($i = 0; $i < 6; $i++) {
        if ($a[$i] == $b[$i]) {
            $result++;
        }
    }
    return $result;
}

$similar = 0;
$numbers = [];

while (!feof($fd)) {
    $num = substr(fgets($fd), 0, 6);
    foreach ($numbers as $stored) {
        $cmp = compare($num, $stored);
        if ($cmp > $similar) {
            $similar = $cmp;
        }
    }
    $numbers[] = $num;
}

echo floor((6 - $similar) / 2);

<?

$n = (int) fgets(STDIN);

$length = 6;
$codes = [];

$k = $length;
for ($i = 0; $i < $n; $i++) {
    $code = trim(fgets(STDIN));

    $min_differences = $length;
    foreach ($codes as $item) {
        $differences = 0;
        for ($j = 0; $j < $length; $j++) {
            if ($item{$j} !== $code{$j}) {
                $differences++;
            }
        }

        if ($min_differences > $differences) {
            $min_differences = $differences;
        }
    }

    if ($k > $min_differences) {
        $k = $min_differences;
    }

    $codes[] = $code;
}

echo ($k ? floor(($k - 1) / 2) : 0);


One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal. The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with size $$$1\times1$$$, Rainbow Dash has an infinite amount of light blue blocks, Fluttershy has an infinite amount of yellow blocks. The blocks are placed according to the following rule: each newly placed block must touch the built on the previous turns figure by a side (note that the outline borders of the grid are built initially). At each turn, one pony can place any number of blocks of her color according to the game rules.Rainbow and Fluttershy have found out that they can build patterns on the grid of the game that way. They have decided to start with something simple, so they made up their mind to place the blocks to form a chess coloring. Rainbow Dash is well-known for her speed, so she is interested in the minimum number of turns she and Fluttershy need to do to get a chess coloring, covering the whole grid with blocks. Please help her find that number!Since the ponies can play many times on different boards, Rainbow Dash asks you to find the minimum numbers of turns for several grids of the games.The chess coloring in two colors is the one in which each square is neighbor by side only with squares of different colors.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$): the number of grids of the games.  Each of the next $$$T$$$ lines contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$): the size of the side of the grid of the game.

For each grid of the game print the minimum number of turns required to build a chess coloring pattern out of blocks on it.

NoteFor $$$3\times3$$$ grid ponies can make two following moves:

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     if($b == 1)
     {
          print "1\n";
     }
     else
     {
          print floor($b / 2) + 1 . "\n";
     }
}
?>

<?php
$tests = readline();
$answers = [];
for ($t = 1; $t <= $tests; $t++) {

	# read input and convert sequences into arrays
	$n = readline();
	if($n%2) $n--;
	$answers[]= $n - (floor($n/2) - 1);
}

foreach($answers as $a) echo $a.PHP_EOL;


The only difference between easy and hard versions is the maximum value of $$$n$$$.You are given a positive integer number $$$n$$$. You really love good numbers so you want to find the smallest good number greater than or equal to $$$n$$$.The positive integer is called good if it can be represented as a sum of distinct powers of $$$3$$$ (i.e. no duplicates of powers of $$$3$$$ are allowed).For example:  $$$30$$$ is a good number: $$$30 = 3^3 + 3^1$$$,  $$$1$$$ is a good number: $$$1 = 3^0$$$,  $$$12$$$ is a good number: $$$12 = 3^2 + 3^1$$$,  but $$$2$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ ($$$2 = 3^0 + 3^0$$$),  $$$19$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representations $$$19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0$$$ are invalid),  $$$20$$$ is also not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representation $$$20 = 3^2 + 3^2 + 3^0 + 3^0$$$ is invalid). Note, that there exist other representations of $$$19$$$ and $$$20$$$ as sums of powers of $$$3$$$ but none of them consists of distinct powers of $$$3$$$.For the given positive integer $$$n$$$ find such smallest $$$m$$$ ($$$n \le m$$$) that $$$m$$$ is a good number.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Then $$$q$$$ queries follow. The only line of the query contains one integer $$$n$$$ ($$$1 \le n \le 10^4$$$).

For each query, print such smallest integer $$$m$$$ (where $$$n \le m$$$) that $$$m$$$ is a good number.


On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The child can remove a single part at a time, and each remove consume an energy. Let's define an energy value of part i as vi. The child spend vf1 + vf2 + ... + vfk energy for removing part i where f1, f2, ..., fk are the parts that are directly connected to the i-th and haven't been removed.Help the child to find out, what is the minimum total energy he should spend to remove all n parts.

The first line contains two integers n and m (1 ≤ n ≤ 1000; 0 ≤ m ≤ 2000). The second line contains n integers: v1, v2, ..., vn (0 ≤ vi ≤ 105). Then followed m lines, each line contains two integers xi and yi, representing a rope from part xi to part yi (1 ≤ xi, yi ≤ n; xi ≠ yi). Consider all the parts are numbered from 1 to n.

Output the minimum total energy the child should spend to remove all n parts of the toy.

NoteOne of the optimal sequence of actions in the first sample is:  First, remove part 3, cost of the action is 20.  Then, remove part 2, cost of the action is 10.  Next, remove part 4, cost of the action is 10.  At last, remove part 1, cost of the action is 0. So the total energy the child paid is 20 + 10 + 10 + 0 = 40, which is the minimum.In the second sample, the child will spend 400 no matter in what order he will remove the parts.