Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.We assume that Bajtek can only heap up snow drifts at integer coordinates.

The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift. Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.

Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.

<?php
// Retrieve input
$stdin = fopen('php://stdin', 'r');
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Problem 217A
// Codeforces Contest 134 Div 2 Problem C
$raw = g();
$n = $raw[0];
$ct = 0;
for ($x = 0; $x < $n; $x++) {
	$raw = g();
	$xp[$x] = $raw[0];
	$yp[$x] = $raw[1];
	$found = false;
	for ($y = 0; $y < $ct; $y++) {
		if ($ys[$y][0] == $yp[$x]) {
			$found = true;
		}
	}
	if (!$found) {
		$ys[$ct][0] = $yp[$x];
		$ct++;
	}
}

for ($x = 0; $x < $n; $x++) {
	for ($y = 0; $y < $n; $y++) {
		if ($xp[$x] == $xp[$y]) {
			for ($q = 0; $q < $ct; $q++) {
				for ($w = 0; $w < count($ys[$q]); $w++) {
					if ($ys[$q][$w] == $yp[$x]) {
						$group1 = $q;
					}
					if ($ys[$q][$w] == $yp[$y]) {
						$group2 = $q;
					}
				}
			}
			if ($group1 != $group2) {
				for ($q = 0; $q < count($ys[$group2]); $q++) {
					$ys[$group1][] = $ys[$group2][$q];
				}
				unset($ys[$group2]);
			}
		}
	}
}
echo (count($ys) - 1);

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

<?php
$STDIN = fopen('./data.txt', 'r');
define('STDIN', $STDIN);
$n = trim(fgets(STDIN));
$a = array();
$b = array();
$par = array();
function find($num) {
	global $par;
	return $num == $par[$num] ? $num : $par[$num] = find($par[$num]);
}
for($i = 0; $i < $n; ++$i) {
	$par[$i] = $i;
	list($a[], $b[]) = explode(' ',trim(fgets(STDIN)));
}
$ans = $n - 1;
for($i = 0; $i < $n; ++$i) {
	for($j = $i + 1; $j < $n; ++$j) {
		if($a[$i] == $a[$j] || $b[$i] == $b[$j]) {
			$fi = find($i);
			$fj = find($j);
			if($fi != $fj) {
				--$ans;
				$par[$fi] = $fj;
			}
		}
	}
}
echo $ans."\n";
?>

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int x[110], y[110], z[110];
int n, cnt = 0;
void dfs(int k)
{
    z[k] = 1;
    for (int j = 0; j < n; j++)
    {
        if (z[j]!=1 && (x[k]==x[j] || y[k]==y[j]))
        {
            dfs(j);
        }

    }

}
int main()
{
    cin >> n;
    for(int i = 0; i<n; ++i)
    {
        cin >> x[i] >> y[i];
    }
        for (int i = 0; i < n; i++)
        {
            if (z[i]!=1)
            {
                dfs(i);
                cnt++;
            }
        }
    cout << cnt-1 << endl;
    return 0;
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers. Let's denote monotonic renumeration of array $$$a$$$ as an array $$$b$$$ consisting of $$$n$$$ integers such that all of the following conditions are met:  $$$b_1 = 0$$$;  for every pair of indices $$$i$$$ and $$$j$$$ such that $$$1 \le i, j \le n$$$, if $$$a_i = a_j$$$, then $$$b_i = b_j$$$ (note that if $$$a_i \ne a_j$$$, it is still possible that $$$b_i = b_j$$$);  for every index $$$i \in [1, n - 1]$$$ either $$$b_i = b_{i + 1}$$$ or $$$b_i + 1 = b_{i + 1}$$$. For example, if $$$a = [1, 2, 1, 2, 3]$$$, then two possible monotonic renumerations of $$$a$$$ are $$$b = [0, 0, 0, 0, 0]$$$ and $$$b = [0, 0, 0, 0, 1]$$$.Your task is to calculate the number of different monotonic renumerations of $$$a$$$. The answer may be large, so print it modulo $$$998244353$$$.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).

Print one integer — the number of different monotonic renumerations of $$$a$$$, taken modulo $$$998244353$$$.

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$a = $ir->readArrayOfInt($n);

$cnt = 0;
$R = 0;
$ends = [];

for ($l=0; $l<$n; $l++) {
	if ($l>$R) {
		$cnt++;
		//echo "edge: $R\n";
	}

	// find right position
	if (!isset($ends[$a[$l]])) {
		//$ends[$a[$l]] = $R;
		for ($r=$n-1; $r>$R; $r--) {
			if (!isset($ends[$a[$r]])) {
				$ends[$a[$r]] = $r;
			}

			if ($a[$l] == $a[$r]) {
				break;
			}
		}
	}

	if (!isset($ends[$a[$l]])) {
		$ends[$a[$l]] = $R;
	}

	$R = max([$ends[$a[$l]], $R]);
}

// var_dump($ends);
// echo "count: " . ($cnt+1) . "\n";
// echo "answer: " . (1<<$cnt) . "\n";
echo bcpowmod(2, $cnt, 998244353);

<?php

$in = fopen('php://stdin', 'r');
//$in = fopen('khaled.in', 'r');

const MOD = 998244353;

$n = rtrim(fgets($in));

$line = explode(" ", rtrim(fgets($in)));

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

$ans = 1;
$cmp = 0;

for ($i = 0; $i < $n; $i++) {
    if ($cmp < $i)
        $ans = ( 2 * $ans ) % MOD;
    $cmp = max($cmp, $mp[$a[$i]]);
}

echo $ans . "\n";

function what($x){fprintf(STDERR, $x . "\n");}

?>

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$a = $ir->readArrayOfInt($n);

$cnt = 0;
$R = 0;
$ends = [];

for ($l=0; $l<$n; $l++) {
	if ($l>$R) {
		$cnt++;
		//echo "edge: $R\n";
	}

	// find right position
	if (!isset($ends[$a[$l]])) {
		$ends[$a[$l]] = $R;
		for ($r=$n-1; $r>$R; $r--) {
			if (!isset($ends[$a[$r]])) {
				$ends[$a[$r]] = $r;
			}

			if ($a[$l] == $a[$r]) {
				break;
			}
		}
	}

	$R = max([$ends[$a[$l]], $R]);
}

//var_dump($ends);
//echo "count: " . $cnt+1 . "\n";
//echo "answer: " . (1<<$cnt) . "\n";
echo bcpowmod(2, $cnt, 998244353);


There are $$$n$$$ piles of stones, where the $$$i$$$-th pile has $$$a_i$$$ stones. Two people play a game, where they take alternating turns removing stones.In a move, a player may remove a positive number of stones from the first non-empty pile (the pile with the minimal index, that has at least one stone). The first player who cannot make a move (because all piles are empty) loses the game. If both players play optimally, determine the winner of the game.

The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$)  — the number of test cases. Next $$$2t$$$ lines contain descriptions of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 10^5$$$)  — the number of piles. The second line of each test case contains $$$n$$$ integers $$$a_1,\ldots,a_n$$$ ($$$1\le a_i\le 10^9$$$)  — $$$a_i$$$ is equal to the number of stones in the $$$i$$$-th pile. It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$10^5$$$.

For each test case, if the player who makes the first move will win, output "First". Otherwise, output "Second".

First
Second
Second
First
First
Second
First

NoteIn the first test case, the first player will win the game. His winning strategy is:   The first player should take the stones from the first pile. He will take $$$1$$$ stone. The numbers of stones in piles will be $$$[1, 5, 4]$$$.  The second player should take the stones from the first pile. He will take $$$1$$$ stone because he can't take any other number of stones. The numbers of stones in piles will be $$$[0, 5, 4]$$$.  The first player should take the stones from the second pile because the first pile is empty. He will take $$$4$$$ stones. The numbers of stones in piles will be $$$[0, 1, 4]$$$.  The second player should take the stones from the second pile because the first pile is empty. He will take $$$1$$$ stone because he can't take any other number of stones. The numbers of stones in piles will be $$$[0, 0, 4]$$$.  The first player should take the stones from the third pile because the first and second piles are empty. He will take $$$4$$$ stones. The numbers of stones in piles will be $$$[0, 0, 0]$$$.  The second player will lose the game because all piles will be empty.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     $d = 0;
     for($y = 0; $y < $b; $y++)
     {
          if($c[$y] == "1")
          {
               $d++;
          }
          else
          {
               break;
          }
     }
     if($d == 0)
     {
          print "First\n";
     }
     elseif($d == $b)
     {
          if($d % 2 == 0)
          {
               print "Second\n";
          }
          else
          {
               print "First\n";
          }
     }
     else
     {
          if($d % 2 == 0)
          {
               print "First\n";
          }
          else
          {
               print "Second\n";
          }
     }
}
?>


Thanos sort is a supervillain sorting algorithm, which works as follows: if the array is not sorted, snap your fingers* to remove the first or the second half of the items, and repeat the process.Given an input array, what is the size of the longest sorted array you can obtain from it using Thanos sort?*Infinity Gauntlet required.

The first line of input contains a single number $$$n$$$ ($$$1 \le n \le 16$$$) — the size of the array. $$$n$$$ is guaranteed to be a power of 2. The second line of input contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 100$$$) — the elements of the array.

Return the maximal length of a sorted array you can obtain using Thanos sort. The elements of the array have to be sorted in non-decreasing order.

NoteIn the first example the array is already sorted, so no finger snaps are required.In the second example the array actually has a subarray of 4 sorted elements, but you can not remove elements from different sides of the array in one finger snap. Each time you have to remove either the whole first half or the whole second half, so you'll have to snap your fingers twice to get to a 2-element sorted array.In the third example the array is sorted in decreasing order, so you can only save one element from the ultimate destruction.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$d = 1;
$e = $a;
while(TRUE)
{
     $f = 0;
     for($y = 1; $y <= $d; $y++)
     {
          $g = array_slice($b, $f, $e);
          $h = $g;
          sort($h);
          if($g == $h)
          {
               break;
          }
          $f += $e;
     }
     if($g == $h)
     {
          print $e;
          break;
     }
     $d *= 2;
     $e /= 2;
}
?>

<?php
# 1145A
declare(strict_types=1);

function isSorted(array $arr): bool {
    $sorted = true;
    $arrLength = count($arr) - 1;
    for($i = 0; $i < $arrLength; $i++) {
        if ($arr[$i] > $arr[$i + 1]) {
            $sorted = false;
        }
    }
    return $sorted;
}

function splitArr(array $arr): int {
    $arrCount = count($arr);
    if (isSorted($arr) === true) {
        return count($arr);
    }
    $half = (int)floor($arrCount / 2);
    return max(splitArr(array_slice($arr, 0, $half)), splitArr(array_slice($arr, $half)));
}

$n = fscanf(STDIN, '%u');
$items = explode(' ', trim(fgets(STDIN)));
echo splitArr($items);

<?php
# 1145A
declare(strict_types=1);

function isSorted(array $arr): bool {
    $sorted = true;
    $arrLength = count($arr) - 1;
    for($i = 0; $i < $arrLength; $i++) {
        if ($arr[$i] > $arr[$i + 1]) {
            $sorted = false;
            break;
        }
    }
    return $sorted;
}

function splitArr(array $arr): int {
    $arrCount = count($arr);
    if (isSorted($arr) === true) {
        return count($arr);
    }
    $half = (int)floor($arrCount / 2);
    return max(splitArr(array_slice($arr, 0, $half)), splitArr(array_slice($arr, $half)));
}

$n = fscanf(STDIN, '%u');
$items = explode(' ', trim(fgets(STDIN)));
echo splitArr($items);

<?php
function isArSorted($ar)
{
	$copy = $ar;
	sort($copy);
	if ($copy == $ar)
	{
		return true;
	}
	return false;
}

function checkAr($ar)
{
	$l = count($ar);
	if ($l <= 2)
	{
		return 1;
	}
	[$left, $right] = array_chunk($ar, $l / 2);
	if (isArSorted($left) || isArSorted($right))
	{
		return count($left);
	}
	elseif (count($left) > 1)
	{
		return max(checkAr($left), checkAr($right));
	}
	return 1;
}

function getResult($inputL, $input)
{
	$input = trim($input);
	$initialAr = explode(' ', $input);
	if (isArSorted($initialAr))
	{
		return count($initialAr);
	}
	return checkAr($initialAr);
}

fwrite(STDOUT, getResult(fgets(STDIN), fgets(STDIN)));

<?php
# 1145A
declare(strict_types=1);

function isSorted(array $arr): bool {
    $sorted = true;
    $arrLength = count($arr) - 1;
    for($i = 0; $i < $arrLength; $i++) {
        if ($arr[$i] > $arr[$i + 1]) {
            $sorted = false;
        }
    }
    return $sorted;
}

function splitArr(array $arr): int {
    $arrCount = count($arr);
    if (isSorted($arr) === true) {
        return count($arr);
    }
    $half = (int)floor($arrCount / 2);
    return max(splitArr(array_slice($arr, 0, $half)), splitArr(array_slice($arr, $half + 1)));
}

$n = fscanf(STDIN, '%u');
$items = explode(' ', trim(fgets(STDIN)));
echo splitArr($items);

<?php
function isArSorted($ar)
{
	$copy = $ar;
	sort($copy);
	if ($copy == $ar)
	{
		return true;
	}
	return false;
}

function checkAr($ar)
{
	$l = count($ar);
	if ($l <= 2)
	{
		return 1;
	}
	[$left, $right] = array_chunk($ar, $l / 2);
	if (isArSorted($left) || isArSorted($right))
	{
		return count($left);
	}
	elseif (count($left) > 1)
	{
		return max(checkAr($left), checkAr($right));
	}
	return 1;
}

function getResult($input)
{
	$input = trim($input);
	$input = explode("\n", $input);
	$initialAr = explode(' ', $input[1]);
	if (isArSorted($initialAr))
	{
		return count($initialAr);
	}
	return checkAr($initialAr);
}

fwrite(STDOUT, getResult(fgets(STDIN)));

<?php
function isArSorted($ar)
{
	$copy = $ar;
	sort($copy);
	if ($copy == $ar)
	{
		return true;
	}
	return false;
}

function checkAr($ar)
{
	$l = count($ar);
	if ($l <= 2)
	{
		return 1;
	}
	[$left, $right] = array_chunk($ar, $l / 2);
	if (isArSorted($left) || isArSorted($right))
	{
		return count($left);
	}
	elseif (count($left) > 1)
	{
		return max(checkAr($left), checkAr($right));
	}
	return 1;
}

function getResult($inputL, $input)
{
	$input = trim($input);
	$initialAr = explode(' ', $input[1]);
	if (isArSorted($initialAr))
	{
		return count($initialAr);
	}
	return checkAr($initialAr);
}

fwrite(STDOUT, getResult(fgets(STDIN), fgets(STDIN)));


You are given a sequence $$$b_1, b_2, \ldots, b_n$$$. Find the lexicographically minimal permutation $$$a_1, a_2, \ldots, a_{2n}$$$ such that $$$b_i = \min(a_{2i-1}, a_{2i})$$$, or determine that it is impossible.

Each test contains one or more test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The first line of each test case consists of one integer $$$n$$$ — the number of elements in the sequence $$$b$$$ ($$$1 \le n \le 100$$$). The second line of each test case consists of $$$n$$$ different integers $$$b_1, \ldots, b_n$$$ — elements of the sequence $$$b$$$ ($$$1 \le b_i \le 2n$$$). It is guaranteed that the sum of $$$n$$$ by all test cases doesn't exceed $$$100$$$.

For each test case, if there is no appropriate permutation, print one number $$$-1$$$. Otherwise, print $$$2n$$$ integers $$$a_1, \ldots, a_{2n}$$$ — required lexicographically minimal permutation of numbers from $$$1$$$ to $$$2n$$$.


Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars.Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?

First line of input contains an integer n (2 ≤ n ≤ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) — the bids of players.

Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.

NoteIn the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.It can be shown that in the second sample test there is no way to make all bids equal.

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$q = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));

foreach ($aArray as &$t) {
    $t /= pow(3,powCounter($t, 3));
    $t /= pow(2,powCounter($t, 2));
}
function powCounter($x, $p)
{
    $c = 0;
    while ($x > 1) {
        if ($x % $p == 0) {
            $x /= $p;
            $c++;
        } else {
            break;
        }

    }
    return $c;
}

$r = array_count_values($aArray);
$r = count($r);

echo $r > 1 ? "No" : "Yes";

<?php
$n = trim(fgets(STDIN));
$arr = explode(" ",trim(fgets(STDIN)));
for($i=0;$i<count($arr);$i+=1)
{
    $x = $arr[$i];
    while($x%2==0){$x/=2;}
    while($x%3==0){$x/=3;}
    $arr[$i]=$x;
}
sort($arr);
if($arr[0]==$arr[count($arr)-1])
{
    print('Yes');
}
else
{
    print('No');
}
?>

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$q = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
sort($aArray);

$t = $aArray[0];
$t /= pow(2,powCounter($t, 2));
$t /= pow(3,powCounter($t, 3));
function powCounter($x, $p)
{
    $c = 0;
    while ($x > 1) {
        if ($x % $p == 0) {
            $x /= $p;
            $c++;
        } else {
            break;
        }

    }
    return $c;
}

$x = 0;
for ($i = 1; $i < $q; $i++) {

        if ($aArray[$i]%$t !=0) {
            $x = 1;
            break;
        }

}
echo $x == 1 ? "No" : "Yes";

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$q = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
sort($aArray);
$pArray = array();
$t = $aArray[0];
$t2 = $t;
while ($t > 1) {
    $x = 0;
    if (!empty($pArray)) {
        sort($pArray);
        foreach ($pArray as $prime) {
            $x = $prime;
        }
    } else {
        $x = 1;
    }
    $sqrt = floor(sqrt($t))+1;
    for ($i = $x + 1; $i <= $sqrt; $i++) {
        $p = powCounter($t, $i);
        if ($p > 0) {
            $pArray[$i] = $p;
            $t /= pow($i, $p);
        }
    }
    if ($t2 == $t && $t != 1) {
        $pArray[$t] = 1;
        break;
    }
    $t2 = $t;
}
function powCounter($x, $p)
{
    $c = 0;
    while ($x > 1) {
        if ($x % $p == 0) {
            $x /= $p;
            $c++;
        } else {
            break;
        }

    }
    return $c;
}

if (isset($pArray[2])) {
    unset($pArray[2]);
}
if (isset($pArray[3])) {
    unset($pArray[3]);
}
$x = 0;
for ($i = 1; $i < $q; $i++) {
    foreach ($pArray as $prime => $pow) {
        if (powCounter($aArray[$i], $prime) != $pow) {
            $x = 1;
            break;
        }
    }
    if ($x == 1) {
        break;
    }
}
echo $x == 1 ? "No" : "Yes";

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$q = trim(fgets($file));
$aArray = explode(" ", trim(fgets($file)));
sort($aArray);
$pArray = array();
$t = $aArray[0];
$t2 = $t;
while ($t > 1) {
    $x = 0;
    if (!empty($pArray)) {
        foreach ($pArray as $prime) {
            $x = $prime;
        }
    } else {
        $x = 1;
    }
    $sqrt = floor(sqrt($t));
    for ($i = $x + 1; $i <= $sqrt; $i++) {
        $p = powCounter($t, $i);
        if ($p > 0) {
            $pArray[$i] = $p;
            $t /= pow($i, $p);
        }
    }
    if ($t2 == $t && $t != 1) {
        $pArray[$t] = 1;
        break;
    }
    $t2 = $t;
}
function powCounter($x, $p)
{
    $c = 0;
    while ($x > 1) {
        if ($x % $p == 0) {
            $x /= $p;
            $c++;
        } else {
            break;
        }

    }
    return $c;
}

if (isset($pArray[2])) {
    unset($pArray[2]);
}
if (isset($pArray[3])) {
    unset($pArray[3]);
}
$x = 0;
for ($i = 1; $i < $q; $i++) {
    foreach ($pArray as $prime => $pow) {
        if (powCounter($aArray[$i], $prime) != $pow) {
            $x = 1;
            break;
        }
    }
    if ($x == 1) {
        break;
    }
}
echo $x == 1 ? "No" : "Yes";


As the boat drifts down the river, a wood full of blossoms shows up on the riverfront."I've been here once," Mino exclaims with delight, "it's breathtakingly amazing.""What is it like?""Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?" There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.The wood can be represented by a rectangular grid of $$$n$$$ rows and $$$m$$$ columns. In each cell of the grid, there is exactly one type of flowers.According to Mino, the numbers of connected components formed by each kind of flowers are $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ respectively. Two cells are considered in the same connected component if and only if a path exists between them that moves between cells sharing common edges and passes only through cells containing the same flowers.You are to help Kanno depict such a grid of flowers, with $$$n$$$ and $$$m$$$ arbitrarily chosen under the constraints given below. It can be shown that at least one solution exists under the constraints of this problem.Note that you can choose arbitrary $$$n$$$ and $$$m$$$ under the constraints below, they are not given in the input.

The first and only line of input contains four space-separated integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$1 \leq a, b, c, d \leq 100$$$) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively.

In the first line, output two space-separated integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 50$$$) — the number of rows and the number of columns in the grid respectively. Then output $$$n$$$ lines each consisting of $$$m$$$ consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and 'D', representing Amaranths, Begonias, Centaureas and Dianthuses, respectively. In case there are multiple solutions, print any. You can output each letter in either case (upper or lower).

7 7
DDDDDDD
DDDBDBD
DDCDCDD
DBDADBD
DDCDCDD
DBDBDDD
DDDDDDD

NoteIn the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.


Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample.Limak will repeat the following operation till everything is destroyed.Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.

The first line contains single integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers h1, h2, ..., hn (1 ≤ hi ≤ 109) — sizes of towers.

Print the number of operations needed to destroy all towers.

NoteThe picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.    After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.

<?
$colCount = fgets (STDIN);
$colHeight = fgets (STDIN);
$colHeight = explode (' ', $colHeight);
$lastIteration = $minIteration = 0;

foreach ($colHeight as $key => &$value) {
  $minIteration = $key + 1;

  $lastIteration ++;
  if ($minIteration > $lastIteration) { $minIteration = $lastIteration; }

  if ($minIteration > $value) { $minIteration = $value; }

  $rowLength = $colCount - $key;
  if ($minIteration > $rowLength) { $minIteration = $rowLength; }

  $value = $lastIteration = $minIteration;
}

$result = $lastIteration = 0;
$maxIndex = $colCount - 1;

for ($i = $maxIndex; $i >= 0; $i--) {
  $minIteration = $maxIndex - $i + 1;

  $lastIteration ++;
  if ($minIteration > $lastIteration) { $minIteration = $lastIteration; }

  if ($minIteration > $colHeight [$i]) { $minIteration = $colHeight [$i]; }

  $rowLength = $i + 1;
  if ($minIteration > $rowLength) { $minIteration = $rowLength; }

  $lastIteration = $minIteration;

  if ($minIteration > $result) { $result = $minIteration; }
}

echo "$result\n";


Bob is a pirate looking for the greatest treasure the world has ever seen. The treasure is located at the point $$$T$$$, which coordinates to be found out.Bob travelled around the world and collected clues of the treasure location at $$$n$$$ obelisks. These clues were in an ancient language, and he has only decrypted them at home. Since he does not know which clue belongs to which obelisk, finding the treasure might pose a challenge. Can you help him?As everyone knows, the world is a two-dimensional plane. The $$$i$$$-th obelisk is at integer coordinates $$$(x_i, y_i)$$$. The $$$j$$$-th clue consists of $$$2$$$ integers $$$(a_j, b_j)$$$ and belongs to the obelisk $$$p_j$$$, where $$$p$$$ is some (unknown) permutation on $$$n$$$ elements. It means that the treasure is located at $$$T=(x_{p_j} + a_j, y_{p_j} + b_j)$$$. This point $$$T$$$ is the same for all clues.In other words, each clue belongs to exactly one of the obelisks, and each obelisk has exactly one clue that belongs to it. A clue represents the vector from the obelisk to the treasure. The clues must be distributed among the obelisks in such a way that they all point to the same position of the treasure.Your task is to find the coordinates of the treasure. If there are multiple solutions, you may print any of them.Note that you don't need to find the permutation. Permutations are used only in order to explain the problem.

The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of obelisks, that is also equal to the number of clues. Each of the next $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^6 \leq x_i, y_i \leq 10^6$$$) — the coordinates of the $$$i$$$-th obelisk. All coordinates are distinct, that is $$$x_i \neq x_j$$$ or $$$y_i \neq y_j$$$ will be satisfied for every $$$(i, j)$$$ such that $$$i \neq j$$$.  Each of the next $$$n$$$ lines contains two integers $$$a_i$$$, $$$b_i$$$ ($$$-2 \cdot 10^6 \leq a_i, b_i \leq 2 \cdot 10^6$$$) — the direction of the $$$i$$$-th clue. All coordinates are distinct, that is $$$a_i \neq a_j$$$ or $$$b_i \neq b_j$$$ will be satisfied for every $$$(i, j)$$$ such that $$$i \neq j$$$.  It is guaranteed that there exists a permutation $$$p$$$, such that for all $$$i,j$$$ it holds $$$\left(x_{p_i} + a_i, y_{p_i} + b_i\right) = \left(x_{p_j} + a_j, y_{p_j} + b_j\right)$$$.

Output a single line containing two integers $$$T_x, T_y$$$ — the coordinates of the treasure. If there are multiple answers, you may print any of them.

NoteAs $$$n = 2$$$, we can consider all permutations on two elements. If $$$p = [1, 2]$$$, then the obelisk $$$(2, 5)$$$ holds the clue $$$(7, -2)$$$, which means that the treasure is hidden at $$$(9, 3)$$$. The second obelisk $$$(-6, 4)$$$ would give the clue $$$(-1,-3)$$$ and the treasure at $$$(-7, 1)$$$. However, both obelisks must give the same location, hence this is clearly not the correct permutation.If the hidden permutation is $$$[2, 1]$$$, then the first clue belongs to the second obelisk and the second clue belongs to the first obelisk. Hence $$$(-6, 4) + (7, -2) = (2,5) + (-1,-3) = (1, 2)$$$, so $$$T = (1,2)$$$ is the location of the treasure.  In the second sample, the hidden permutation is $$$[2, 3, 4, 1]$$$.


Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains $$$26$$$ buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning. To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string $$$s$$$ appeared on the screen. When Polycarp presses a button with character $$$c$$$, one of the following events happened:  if the button was working correctly, a character $$$c$$$ appeared at the end of the string Polycarp was typing;  if the button was malfunctioning, two characters $$$c$$$ appeared at the end of the string. For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a $$$\rightarrow$$$ abb $$$\rightarrow$$$ abba $$$\rightarrow$$$ abbac $$$\rightarrow$$$ abbaca $$$\rightarrow$$$ abbacabb $$$\rightarrow$$$ abbacabba.You are given a string $$$s$$$ which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow. Each test case is represented by one line containing a string $$$s$$$ consisting of no less than $$$1$$$ and no more than $$$500$$$ lowercase Latin letters.

For each test case, print one line containing a string $$$res$$$. The string $$$res$$$ should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, $$$res$$$ should be empty.

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
		$str=trim(fgets(STDIN));
		$str2="";
		$flag=0;
		$alpha="abcdefghijklmnopqrstuvwxyz";
		for ($i=0; $i <strlen($alpha) ; $i++)
		 {
			 	$cnt=0;
				for ($j=0; $j <strlen($str) ; $j++)
				 {
						if($alpha[$i]==$str[$j])
						{
			                 $cnt++;
			                if($cnt%2==1&&$j==strlen($str)-1)
			                 {
			                 	$str2.=$alpha[$i];
			                 	$flag=1;
			                 	break;
			                 }

						}
			             else
			             {

			                if($cnt%2==1)
			                 {
			                 	$str2.=$alpha[$i];
			                 	$flag=1;
			                 	break;
			                 }
			                 $cnt=0;

			             }

				 }
		 }
		 if($flag==0)
		 	echo " \n";
		 else
		 {
		 	$split=str_split($str2);
		 	sort($split);
		 	echo implode($split)."\n";
		 }
}


You have a string $$$s$$$ of length $$$n$$$ consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the last one, nothing happens). If you choose a character <, the character that comes right before it is deleted (if the character you chose was the first one, nothing happens).For example, if we choose character > in string > > < >, the string will become to > > >. And if we choose character < in string > <, the string will become to <.The string is good if there is a sequence of operations such that after performing it only one character will remain in the string. For example, the strings >, > > are good. Before applying the operations, you may remove any number of characters from the given string (possibly none, possibly up to $$$n - 1$$$, but not the whole string). You need to calculate the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) – the number of test cases. Each test case is represented by two lines. The first line of $$$i$$$-th test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) – the length of string $$$s$$$. The second line of $$$i$$$-th test case contains string $$$s$$$, consisting of only characters > and <.

For each test case print one line. For $$$i$$$-th test case print the minimum number of characters to be deleted from string $$$s$$$ so that it becomes good.

NoteIn the first test case we can delete any character in string <>.In the second test case we don't need to delete any characters. The string > < < is good, because we can perform the following sequence of operations: > < < $$$\rightarrow$$$ < < $$$\rightarrow$$$ <.


As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to n in the order in which they send the cards. Let's introduce the same numbering for the cards, that is, according to the numbering the i-th friend sent to Alexander a card number i.Alexander also sends cards to friends, but he doesn't look for the new cards on the Net. He simply uses the cards previously sent to him (sometimes, however, he does need to add some crucial details). Initially Alexander doesn't have any cards. Alexander always follows the two rules:  He will never send to a firend a card that this friend has sent to him.  Among the other cards available to him at the moment, Alexander always chooses one that Alexander himself likes most. Alexander plans to send to each friend exactly one card. Of course, Alexander can send the same card multiple times.Alexander and each his friend has the list of preferences, which is a permutation of integers from 1 to n. The first number in the list is the number of the favorite card, the second number shows the second favorite, and so on, the last number shows the least favorite card.Your task is to find a schedule of sending cards for Alexander. Determine at which moments of time Alexander must send cards to his friends, to please each of them as much as possible. In other words, so that as a result of applying two Alexander's rules, each friend receives the card that is preferred for him as much as possible.Note that Alexander doesn't choose freely what card to send, but he always strictly follows the two rules.

The first line contains an integer n (2 ≤ n ≤ 300) — the number of Alexander's friends, equal to the number of cards. Next n lines contain his friends' preference lists. Each list consists of n different integers from 1 to n. The last line contains Alexander's preference list in the same format.

Print n space-separated numbers: the i-th number should be the number of the friend, whose card Alexander receives right before he should send a card to the i-th friend. If there are several solutions, print any of them.

NoteIn the sample, the algorithm of actions Alexander and his friends perform is as follows:   Alexander receives card 1 from the first friend.  Alexander sends the card he has received (at the moment he only has one card, and therefore it is the most preferable for him) to friends with the numbers 2 and 3.  Alexander receives card 2 from the second friend, now he has two cards — 1 and 2.  Alexander sends a card to the first friend. Despite the fact that Alexander likes card 1 more, he sends card 2 as he cannot send a friend the card sent by that very friend.  Alexander receives card 3 from the third friend.  Alexander receives card 4 from the fourth friend.  Among the cards Alexander has number 3 is his favorite and he sends it to the fourth friend. Note that Alexander can send cards to multiple friends at a time (in this case the second and the third one). Alexander can send card 3 to the fourth friend after he receives the third card or after he receives the fourth card (both variants are correct).


A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same time "][", "[[]" and "[[]]][" — are irregular. Draw the given sequence using a minimalistic pseudographics in the strip of the lowest possible height — use symbols '+', '-' and '|'. For example, the sequence "[[][]][]" should be represented as: +-        -++- -+    |+- -++- -+||   |||   ||   |||   ||+- -++- -+||   |+-        -++- -+Each bracket should be represented with the hepl of one or more symbols '|' (the vertical part) and symbols '+' and '-' as on the example which is given above.Brackets should be drawn without spaces one by one, only dividing pairs of consecutive pairwise brackets with a single-space bar (so that the two brackets do not visually merge into one symbol). The image should have the minimum possible height. The enclosed bracket is always smaller than the surrounding bracket, but each bracket separately strives to maximize the height of the image. So the pair of final brackets in the example above occupies the entire height of the image.Study carefully the examples below, they adequately explain the condition of the problem. Pay attention that in this problem the answer (the image) is unique.

The first line contains an even integer n (2 ≤ n ≤ 100) — the length of the sequence of brackets. The second line contains the sequence of brackets — these are n symbols "[" and "]". It is guaranteed that the given sequence of brackets is regular.

Print the drawn bracket sequence in the format which is given in the condition. Don't print extra (unnecessary) spaces.

<?php
error_reporting(E_ALL);
ini_set("memory_limit", "256M");
ini_set("max_execution_time", 1);

const BRACKET_OPEN  = "[";
const BRACKET_CLOSE = "]";

const MATRIX_SPACE = " ";
const MATRIX_LINE  = "|";
const MATRIX_PLUS  = "+";
const MATRIX_MINUS = "-";

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

$brackets = str_split($brackets, 1);
$bracketsDepth = [];
$maxDepth = 0;
$depth = 0;

foreach ($brackets as $bracket) {
    if ($bracket == BRACKET_OPEN) {
        $depth++;
        $maxDepth = max($maxDepth, $depth);
    }
    $bracketsDepth[] = [
        $bracket,
        $depth,
    ];
    if ($bracket == BRACKET_CLOSE) {
        $depth--;
    }
}

$matrix = [0 => []];
foreach ($bracketsDepth as $position => list($bracket, $depth)) {
    if ($position > 0) {
        list($prevBracket, $prevDepth) = $bracketsDepth[$position - 1];
        if ($bracket == BRACKET_CLOSE && $prevBracket == BRACKET_OPEN) {
            $matrix[0][] = MATRIX_SPACE;
            $matrix[0][] = MATRIX_SPACE;
            $matrix[0][] = MATRIX_SPACE;
        }
    }
    $matrix[0][] = MATRIX_LINE;
}

for($i = 1; $i <= $maxDepth; $i++) {
    $matrix[$i] = array_fill(0, count($matrix[0]), MATRIX_SPACE);
}

$bracketPtr = 0;
foreach ($matrix[0] as $position => $item) {
    if ($item == MATRIX_LINE) {
        list($bracket, $depth) = $bracketsDepth[$bracketPtr];
        $row = $maxDepth + 1 - $depth;
        $matrix[$row][$position] = MATRIX_PLUS;
        if ($bracket == BRACKET_OPEN) {
            $matrix[$row][$position + 1] = MATRIX_MINUS;
        } else {
            $matrix[$row][$position - 1] = MATRIX_MINUS;
        }
        for ($i = 1; $i < $row; $i++) {
            $matrix[$i][$position] = MATRIX_LINE;
        }
        $bracketPtr++;
    }
}

for($i = -$maxDepth; $i <= $maxDepth; $i++) {
    $ofs = abs($i);
    echo implode("", $matrix[$ofs]);
    if ($i != $maxDepth) echo "\n";
}


Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the m-th face contains m dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice n times.

A single line contains two integers m and n (1 ≤ m, n ≤ 105).

Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10  - 4.

NoteConsider the third test example. If you've made two tosses:  You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.  You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.  You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.  You can get 2 in the first toss, and 2 in the second. Maximum equals to 2. The probability of each outcome is 0.25, that is expectation equals to: You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value

<?php
error_reporting("off");
//454C: Little Pony and Expected Value
list($m, $n) = explode(" ", trim(fgets(STDIN))); //$m = 2; $n = 2;
$sum = 0;
for ($i = $m; $i >= 1; $i--) {
  $sum += $i * (pow($i / $m, $n) - pow(($i - 1) / $m, $n));
}
echo round($sum, 12);
?>

<?php
error_reporting("off");
//454C: Little Pony and Expected Value
list($m, $n) = explode(" ", trim(fgets(STDIN))); //$m = 2; $n = 2;
$sum = 0;
for ($i = $m; $i >= 1; $i--) {
  $sum += $i * (pow($i, $n) - pow($i - 1, $n));
}
echo $sum / (round(pow($m, $n), 12))
?>


One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are n lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of lines in the description. Then follow n lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.

Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.

<?php
$num=trim(fgets(STDIN));
$array=array();
for ($i=0; $i < $num; $i++) {
    $array[$i]=trim(fgets(STDIN));
}
$finalresult=array_count_values($array);
print_r(array_search(max($finalresult), $finalresult));
?>

<?php
fscanf(STDIN,"%d",$n);
$teams=array();
for ($i=0; $i <$n ; $i++)
 {
	$teams[$i]=trim(fgets(STDIN));

 }
 if(count($teams)==1)
 	echo "$teams[0]";
 else
 {

 $unique[0]=$teams[0];
 for ($i=1; $i <count($teams)-1 ; $i++)
 {
 	if($unique[0]!=$teams[$i])
 	{
 		$unique[1]=$teams[$i];
 		break;
 	}

 }

//$unique=array_unique($teams);
 	//echo $unique[1]."hi\n";

//print_r($unique);

$fG=0;
$sG=0;
for ($i=0; $i <count($teams) ; $i++)
 {
	if($unique[0]==$teams[$i])
		$fG++;
	else
		$sG++;
 }
 if($fG>$sG)
 	echo $unique[0];
 else
 	echo $unique[1];
}

<?php
$n = intval(trim(fgets(STDIN)));
$arr = [];
for($i = 0; $i < $n; $i++){
    $arr[] = trim(fgets(STDIN));
}
$a = array_count_values($arr);
$a = array_flip($a);
$max = max(array_keys($a));
echo $a[$max] .PHP_EOL;
exit;

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

    $goals = array();
    for ($i = 0; $i < $n; ++$i) {
        $str = trim(fgets(STDIN));

        if (array_key_exists($str, $goals))
                $goals[$str] += 1;
        else
                $goals[$str] = 1;
    }

    asort($goals);
    foreach ($goals as $key => $value);

    echo $key;
?>

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
foreach($arr as $v)
    $newarr[$v]++;
$m=max($newarr);
foreach($newarr as $k=>$v)
    if($v==$m) $winner=$k;
echo $winner;
?>

<?php
    $n = trim(fgets(STDIN));
    $temp=array("value"=>array(),"score"=>array());
    for($i=0;$i<$n;$i++){
        $input = strtoupper(trim(fgets(STDIN)));
        if(!in_array($input,$temp["value"])){
            $temp["value"][]=$input;
            $temp["score"][]=0;
        }
        $temp["score"][array_search($input,$temp["value"])]++;
    }
    echo $temp["value"][array_keys($temp["score"], max($temp["score"]))[0]];
?>

<?php
fscanf(STDIN,"%d",$n);
$teams=array();
for ($i=0; $i <$n ; $i++)
 {
	$teams[$i]=trim(fgets(STDIN));
 }
 $unique=array_unique($teams);

 if(count($unique)==1)
     echo "$teams[0]";
 else
  {
  	$firstTeamGoal=0;
  	$secondTeamGoal=0;
    for ($i=0; $i <count($teams) ; $i++)
    {
    	if($unique[0]==$teams[$i])
    		$firstTeamGoal++;
    	else
    		$secondTeamGoal++;

    }
    if($firstTeamGoal>$secondTeamGoal)

    	echo "$unique[0]";
    else
    	echo "$unique[1]";
  }

//print_r($str);

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=trim(fgets(STDIN));
foreach($arr as $v)
    $newarr[$v]++;
$m=max($newarr);
foreach($newarr as $k=>$v)
    if($v==$m) $k;
echo $k;
?>


New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of n - 1 positive integers a1, a2, ..., an - 1. For every integer i where 1 ≤ i ≤ n - 1 the condition 1 ≤ ai ≤ n - i holds. Next, he made n - 1 portals, numbered by integers from 1 to n - 1. The i-th (1 ≤ i ≤ n - 1) portal connects cell i and cell (i + ai), and one can travel from cell i to cell (i + ai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (i + ai) to cell i using the i-th portal. It is easy to see that because of condition 1 ≤ ai ≤ n - i one can't leave the Line World using portals.Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system.

The first line contains two space-separated integers n (3 ≤ n ≤ 3 × 104) and t (2 ≤ t ≤ n) — the number of cells, and the index of the cell which I want to go to. The second line contains n - 1 space-separated integers a1, a2, ..., an - 1 (1 ≤ ai ≤ n - i). It is guaranteed, that using the given transportation system, one cannot leave the Line World.

If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO".

NoteIn the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.

<?php
fscanf(STDIN,"%d %d\n",$n,$m);
$arr = explode(' ',trim(fgets(STDIN)));
   $t=1;

  while($t<$m){
  $t=$arr[$t-1]+$t;

  if($t==$m){echo "YES";break;}
  else
  if($t>$m){echo "NO";break;}

  }

    ?>

<?php
$n = explode(" ",trim(fgets(STDIN)));
$line = explode(" ",trim(fgets(STDIN)));
$key=0;
while ($key<=$n[1]-1)
{
    $key = $line[$key]+$key;
    if ($key==$n[1]-1)break;
}
if ($key==$n[1]-1)echo "YES";
else echo "NO";

<?php

list($n,$t)=fscanf(STDIN,"%d %d");

$rail=explode(' ',trim(fgets(STDIN)));

for($i=1;$i<=$n;$i++)    $visited[$i]=0;

function dfs($cell)    {
	global $t;
	global $visited;
	global $rail;
	global $n;
	//echo $cell."\n";

	if($cell==$t)    return 1;
	if($visited[$cell])    return 0;
	if($cell==$n)    return 0;

	$visited[$cell]=1;
	return dfs($cell+$rail[$cell-1]);
}

$ans=dfs(1);

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

?>

<?php
$n = explode(" ", trim(fgets(STDIN)));
$x = explode(" ", trim(fgets(STDIN)));
$s = "NO";
$i = 1;
while($i < $n[0]){
	$i = $i + $x[$i-1];
	if ($i == $n[1]){
		$s = "YES";
		break;
	}
}
print ($s);
?>

<?php
// 500A  Транспорт на Новый год
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
list($n, $t) = preg_split('/ /', $input_line, -1, PREG_SPLIT_NO_EMPTY);
$n = (int) $n;
$t = (int) $t;

$input_line = fgets($in);
$arr = preg_split('/ /', $input_line, -1, PREG_SPLIT_NO_EMPTY);

$out = 'NO';

$i = 0;
array_push($arr, 1);

while ( $i <= $n - 1) {
    if (($i + 1) == $t) {
        $out = 'YES';
        break;
    }
    if ($i >= $t) {
        break;
    }
    $i = $i + $arr[$i];
}

echo $out;

?>

<?php

$array1 = explode(' ', trim(fgets(STDIN)));

$numberOfArraysElements = $array1[0];
$transIndex = $array1[1];
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $array[$index] == $transIndex && $index < $numberOfArraysElements) {
		echo "YES";
		break;
	} elseif ($index + 1 + $array[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $array[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php
$n = explode(" ", trim(fgets(STDIN)));
$x = explode(" ", trim(fgets(STDIN)));
$s = "NO";
for ($i=1;$i<=$n[0]-1;$i++){
	$portal = $i+$x[$i-1];
	if ($portal == $n[1]){
		$s = "YES";
		break;
	}
}
print ($s);
?>

<?php
// 500A  Транспорт на Новый год
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
list($n, $t) = preg_split('/ /', $input_line, -1, PREG_SPLIT_NO_EMPTY);
$n = (int) $n;
$t = (int) $t;

$input_line = fgets($in);
$arr = preg_split('/ /', $input_line, -1, PREG_SPLIT_NO_EMPTY);

$out = 'NO';

$i = 0;
while ( $i < $n - 1) {
    if (($i + 1) == $t) {
        $out = 'YES';
        break;
    }
    if ($i >= $t) {
        break;
    }
    $i = $i + $arr[$i];
}

echo $out;

?>

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $array[$index] == $transIndex && $index < $numberOfArraysElements) {
		if($transIndex == 5) echo $index . " " . $array[$index]; else echo "YES";
		break;
	} elseif ($index + 1 + $array[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $array[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $array[$index] == $transIndex && $index < $numberOfArraysElements) {
		echo "YES"; if($transIndex == 5) echo $index . " " . $array[$index];
		break;
	} elseif ($index + 1 + $array[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $array[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $array[$index] == $transIndex && $index < $numberOfArraysElements) {
		echo "YES";
		break;
	} elseif ($index + 1 + $array[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $array[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));
echo $transIndex;
$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $array[$index] == $transIndex && $index < $numberOfArraysElements) {
		if($transIndex == 5) echo $index . " " . $array[$index]; else echo "YES";
		break;
	} elseif ($index + 1 + $array[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $array[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

while ($index < $numberOfArraysElements) {
    if ($index + 1 + $item[$index] == $transIndex && $index < $numberOfArraysElements) {
		echo "YES";
		break;
	} elseif ($index + 1 + $item[$index] < $transIndex && $index < $numberOfArraysElements) {
		$index += $item[$index];
	} else {
		echo "NO";
		break;
	}
}

<?php

$array=[];

$numberOfArraysElements = fgets(STDIN);
$transIndex = fgets(STDIN);
$array = explode(' ', trim(fgets(STDIN)));

$index = 0;

foreach ($array as $item) {
    if ($index + $item[$index] == $transIndex && $index <= $numberOfArraysElements) {
		echo "YES";
		break;
	} elseif ($index + $item[$index] < $transIndex && $index <= $numberOfArraysElements) {
		$index += $item[$index];
	} else {
		echo "NO";
		break;
	}
}

?>


The king of Berland organizes a ball! $$$n$$$ pair are invited to the ball, they are numbered from $$$1$$$ to $$$n$$$. Each pair consists of one man and one woman. Each dancer (either man or woman) has a monochrome costume. The color of each costume is represented by an integer from $$$1$$$ to $$$k$$$, inclusive.Let $$$b_i$$$ be the color of the man's costume and $$$g_i$$$ be the color of the woman's costume in the $$$i$$$-th pair. You have to choose a color for each dancer's costume (i.e. values $$$b_1, b_2, \dots, b_n$$$ and $$$g_1, g_2, \dots g_n$$$) in such a way that:  for every $$$i$$$: $$$b_i$$$ and $$$g_i$$$ are integers between $$$1$$$ and $$$k$$$, inclusive;  there are no two completely identical pairs, i.e. no two indices $$$i, j$$$ ($$$i \ne j$$$) such that $$$b_i = b_j$$$ and $$$g_i = g_j$$$ at the same time;  there is no pair such that the color of the man's costume is the same as the color of the woman's costume in this pair, i.e. $$$b_i \ne g_i$$$ for every $$$i$$$;  for each two consecutive (adjacent) pairs both man's costume colors and woman's costume colors differ, i.e. for every $$$i$$$ from $$$1$$$ to $$$n-1$$$ the conditions $$$b_i \ne b_{i + 1}$$$ and $$$g_i \ne g_{i + 1}$$$ hold. Let's take a look at the examples of bad and good color choosing (for $$$n=4$$$ and $$$k=3$$$, man is the first in a pair and woman is the second):Bad color choosing:   $$$(1, 2)$$$, $$$(2, 3)$$$, $$$(3, 2)$$$, $$$(1, 2)$$$ — contradiction with the second rule (there are equal pairs);  $$$(2, 3)$$$, $$$(1, 1)$$$, $$$(3, 2)$$$, $$$(1, 3)$$$ — contradiction with the third rule (there is a pair with costumes of the same color);  $$$(1, 2)$$$, $$$(2, 3)$$$, $$$(1, 3)$$$, $$$(2, 1)$$$ — contradiction with the fourth rule (there are two consecutive pairs such that colors of costumes of men/women are the same). Good color choosing:   $$$(1, 2)$$$, $$$(2, 1)$$$, $$$(1, 3)$$$, $$$(3, 1)$$$;  $$$(1, 2)$$$, $$$(3, 1)$$$, $$$(2, 3)$$$, $$$(3, 2)$$$;  $$$(3, 1)$$$, $$$(1, 2)$$$, $$$(2, 3)$$$, $$$(3, 2)$$$. You have to find any suitable color choosing or say that no suitable choosing exists.

The only line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n, k \le 2 \cdot 10^5$$$) — the number of pairs and the number of colors.

If it is impossible to find any suitable colors choosing, print "NO". Otherwise print "YES" and then the colors of the costumes of pairs in the next $$$n$$$ lines. The $$$i$$$-th line should contain two integers $$$b_i$$$ and $$$g_i$$$ — colors of costumes of man and woman in the $$$i$$$-th pair, respectively. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.


You are given a palindromic string $$$s$$$ of length $$$n$$$.You have to count the number of indices $$$i$$$ $$$(1 \le i \le n)$$$ such that the string after removing $$$s_i$$$ from $$$s$$$ still remains a palindrome. For example, consider $$$s$$$ = "aba"  If we remove $$$s_1$$$ from $$$s$$$, the string becomes "ba" which is not a palindrome.  If we remove $$$s_2$$$ from $$$s$$$, the string becomes "aa" which is a palindrome.  If we remove $$$s_3$$$ from $$$s$$$, the string becomes "ab" which is not a palindrome. A palindrome is a string that reads the same backward as forward. For example, "abba", "a", "fef" are palindromes whereas "codeforces", "acd", "xy" are not.

The input consists of multiple test cases. The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^3)$$$  — the number of test cases. Description of the test cases follows. The first line of each testcase contains a single integer $$$n$$$ $$$(2 \leq n \leq 10^5)$$$  — the length of string $$$s$$$. The second line of each test case contains a string $$$s$$$ consisting of lowercase English letters. It is guaranteed that $$$s$$$ is a palindrome. It is guaranteed that sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer  — the number of indices $$$i$$$ $$$(1 \le i \le n)$$$ such that the string after removing $$$s_i$$$ from $$$s$$$ still remains a palindrome.

NoteThe first test case is described in the statement.In the second test case, the indices $$$i$$$ that result in palindrome after removing $$$s_i$$$ are $$$3, 4, 5, 6$$$. Hence the answer is $$$4$$$. In the third test case, removal of any of the indices results in "d" which is a palindrome. Hence the answer is $$$2$$$.

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($j = 0; $j < $t; $j++) {
    $l = trim(fgets($handle));
    $s = trim(fgets($handle));

    $mid = (int)($l/2);
    $e=$mid-1;
    $x=$mid+1;
    $target = $s[$mid];
    $count = 1;
    while ($e >= 0 || $x<$l) {
        if($s[$e] === $target ) {
            $e--;
        }

        if($s[$x] === $target) {
            $x++;
        }

        if($s[$e] !== $target && $s[$x] !== $target ){
            break;
        }

    }

    echo ($x-$e) -1 . "\n";
}

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

   $t = IO::getInt();
//   $point = ord('a') + ord('b') ;

   for($q=0; $q <$t; $q++) {
       $ans = 0;
       $n = IO::getInt();
       $s = IO::getInt();

       $l = floor($n / 2);
       while ($l > 0 && $s[$l-1] == $s[$l]) {
           $l--;
       }
       $r = $n - 1 - $l;
       $ans = $r - $l + 1;
       IO::pr($ans);

   }

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

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

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

        return $d == $n;
    }

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

         return $a[$n];
     }

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

}

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

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

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

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

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

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

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

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($j = 0; $j < $t; $j++) {
    $l = trim(fgets($handle));
    $s = trim(fgets($handle));
    echo (int) ($l/2) . "\n";
    //echo $count . "\n";
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers. Initially all elements of $$$a$$$ are either $$$0$$$ or $$$1$$$. You need to process $$$q$$$ queries of two kinds:  1 x : Assign to $$$a_x$$$ the value $$$1 - a_x$$$.  2 k : Print the $$$k$$$-th largest value of the array. As a reminder, $$$k$$$-th largest value of the array $$$b$$$ is defined as following: Sort the array in the non-increasing order, return $$$k$$$-th element from it. For example, the second largest element in array $$$[0, 1, 0, 1]$$$ is $$$1$$$, as after sorting in non-increasing order it becomes $$$[1, 1, 0, 0]$$$, and the second element in this array is equal to $$$1$$$.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 10^5$$$) — the length of the given array and the number of queries. The second line contains $$$n$$$ integers $$$a_1, a_2, a_3, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$) — elements of the initial array. Each of the following $$$q$$$ lines contains two integers. The first integer is $$$t$$$ ($$$1 \le t \le 2$$$) — the type of query.   If $$$t = 1$$$ the second integer is $$$x$$$ ($$$1 \le x \le n$$$) — the position of the modified number. You have to assign to $$$a_x$$$ the value $$$1 - a_x$$$. If $$$t = 2$$$ the second integer is $$$k$$$ ($$$1 \le k \le n$$$) — you need to print the $$$k$$$-th largest value of the array. It's guaranteed that there will be at least one query of the second type (satisfying $$$t = 2$$$).

For each query of the second type, print a single integer — the answer to the query.

NoteInitially $$$a = [1, 1, 0, 1, 0]$$$.The first operation is printing the third largest value, which is $$$1$$$.The second operation is assigning $$$a_2$$$ the value $$$0$$$, $$$a$$$ becomes $$$[1, 0, 0, 1, 0]$$$.The third operation is printing the third largest value, it is $$$0$$$.The fourth operation is printing the first largest value, it is $$$1$$$.The last operation is printing the fifth largest value, it is $$$0$$$.

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

list($n, $q) = explode(" ", trim(fgets($file)));
$a = explode(" ", trim(fgets($file)));

$aa = array_count_values($a);
$c = $aa[1];

for ($i = 0; $i < $q; $i++) {
  list($t, $xk) = explode(" ", trim(fgets($file)));

  if ($t == 1) {
    $a[$xk - 1] = 1 - $a[$xk - 1];
    if ($a[$xk - 1] == 1) { $c++; }
    else { $c--; }
  } else {
    if ($c >= $xk) { echo '1'.PHP_EOL; }
    else { echo '0'.PHP_EOL; }
  }
}

?>

<?php

list($n, $q) = array_map('intval', explode(' ', trim(fgets(STDIN))));
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
for ($i = 0; $i < $q; ++$i) {
    list($t[$i], $k[$i]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
$cnt = count(array_keys($a, 1));
for ($i = 0; $i < $q; ++$i) {
    if (1 == $t[$i]) {
        $a[$k[$i] - 1] = 1 - $a[$k[$i] - 1];
        $a[$k[$i] - 1] ? ++$cnt : --$cnt;
    } else {
        echo (int) ($cnt >= $k[$i]).PHP_EOL;
    }
}

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

list($n, $q) = explode(" ", trim(fgets($file)));
$a = explode(" ", trim(fgets($file)));

for ($i = 0; $i < $q; $i++) {
  list($t, $xk) = explode(" ", trim(fgets($file)));

  if ($t == 1) {
    $a[$xk - 1] = 1 - $a[$xk - 1];
    echo $a[$xk - 1].PHP_EOL;
  } else {
    $aa = array_count_values($a);
    if ($aa[1] >= $xk) { echo '1'.PHP_EOL; }
    else { echo '0'.PHP_EOL; }
  }
}

?>


One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.Vitaly sees a building of n floors and 2·m windows on each floor. On each floor there are m flats numbered from 1 to m, and two consecutive windows correspond to each flat. If we number the windows from 1 to 2·m from left to right, then the j-th flat of the i-th floor has windows 2·j - 1 and 2·j in the corresponding row of windows (as usual, floors are enumerated from the bottom). Vitaly thinks that people in the flat aren't sleeping at that moment if at least one of the windows corresponding to this flat has lights on.Given the information about the windows of the given house, your task is to calculate the number of flats where, according to Vitaly, people aren't sleeping.

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of floors in the house and the number of flats on each floor respectively. Next n lines describe the floors from top to bottom and contain 2·m characters each. If the i-th window of the given floor has lights on, then the i-th character of this line is '1', otherwise it is '0'.

Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping.

NoteIn the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.In the second test case the house has one floor and the first floor has three flats. The light is on in the leftmost flat (in both windows) and in the middle flat (in one window). In the right flat the light is off.

<?php
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$ans = 0;
while($n--)
{
    $a = explode(" ", trim(fgets($file)));
    for($i = 0; $i < $m; $i++)
    {
        if($a[2 * $i] + $a[2 * $i + 1] > 0)
            $ans++;
    }
}
echo $ans;
?>

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$result = 0;
while($n--){
    $aArray = explode(" ", trim(fgets($file)));
    array_unshift($aArray, 0);
    for ($i = 1; $i <= $m; $i++) {
        if ($aArray[2*$i]==1 || $aArray[2*$i-1]==1) {
            $result++;
        }
    }
}
echo $result;

<?php
list($floor, $count) = explode(' ', fgets(STDIN));
$floor = (int)$floor;
$count = (int)$count*=2;

$isHome = 0;

if ($floor > 0 && $count > 0) {

    $data = [];
    $i = 0;
    while (($s = fgets(STDIN)) && ($i < $floor)) {
        $data = explode(" ", $s);
        if(count($data) !== $count) {
            echo 'window limit' . count($data) . $count;
            break;
        }

        $i++;

        for($j = 0; $j < $count; $j++) {
            if((int)$data[$j] === 1) {
                ++$isHome;
                if(($j % 2) === 0) {
                    ++$j;
                }
            }
        }

        if($i === $floor) { break; }

    }

    echo $isHome . PHP_EOL;

} else {
    echo 0;
}

<?php
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$result = 0;
while($n--){
    $aArray = explode(" ", trim(fgets($file)));
    for ($i = 0; $i < $m; $i++) {
        if ($aArray[2*$i] + $aArray[2*$i+1] > 0) {
            $result++;
        }
    }
}
echo $result;
?>

<?php
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$ans = 0;
while($n--)
{
    $a = explode(" ", trim(fgets($file)));
    for($i = 0; $i < $m; $i++)
    {
        if($a[2 * $i] + $a[2 * $i + 1] > 0)
            $ans++;
    }
    echo $ans;
}
?>

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$result = 0;
while($n--){
    $aArray = explode(" ", trim(fgets($file)));
    array_unshift($aArray, 0);
    print_r($aArray);
    for ($i = 1; $i <= $m; $i++) {
        if ($aArray[2*$i]==1 || $aArray[2*$i-1]==1) {
            $result++;
        }
    }
}
echo $result;

<?php
list($floor, $count) = explode(' ', fgets(STDIN));
$floor = (int)$floor;
$count = (int)$count*=2;

$isHome = 0;

if ($floor > 0 && $count > 0) {

    $data = [];
    $i = 0;
    while (($s = fgets(STDIN)) && ($i < $floor)) {
        $data = explode(" ", $s);
        if(count($data) !== $count) {
            echo 'window limit' . count($data) . $count;
            break;
        }

        $i++;

        for($j = 0; $j < $count; $j++) {
            if((int)$data[$j] === 1) {
                ++$isHome;
                if(($j % 2) === 0) {
                    ++$j;
                }
                ++$j;
            }
        }

        if($i === $floor) { break; }
    }

    echo $isHome . PHP_EOL;

} else {
    echo 0;
}


Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one of the routers bought before it. You are given the values $$$p_i$$$ — the index of the router to which the $$$i$$$-th router was connected after being purchased ($$$p_i < i$$$).There are $$$n$$$ routers in Boogle in total now. Print the sequence of routers on the path from the first to the $$$n$$$-th router.

The first line contains integer number $$$n$$$ ($$$2 \le n \le 200000$$$) — the number of the routers. The following line contains $$$n-1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i < i$$$), where $$$p_i$$$ is equal to index of the router to which the $$$i$$$-th was connected after purchase.

Print the path from the $$$1$$$-st to the $$$n$$$-th router. It starts with $$$1$$$ and ends with $$$n$$$. All the elements in the path should be distinct.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array($a);
$d = $a - 2;
for($x = $a - 2; $x >= 0; $x--)
{
     if($x == $d)
     {
          $c[count($c)] = $b[$d];
          $d = $b[$d] - 2;
     }
}
$e = array_reverse($c);
print implode(" ", $e);
?>

<?php

$n = readline();
$n = intval($n);

$a = readline();
$a = explode(" ", $a);

$count = $n;
$result = [$n];
while($count != 1) {
    $count = $a[$count - 2];
    $result[] = $count;
}

for ($i = sizeof($result) - 1; $i >= 0; $i--) {
    echo $result[$i] . ' ';
}


The official capital and the cultural capital of Berland are connected by a single road running through n regions. Each region has a unique climate, so the i-th (1 ≤ i ≤ n) region has a stable temperature of ti degrees in summer.This summer a group of m schoolchildren wants to get from the official capital to the cultural capital to visit museums and sights. The trip organizers transport the children between the cities in buses, but sometimes it is very hot. Specifically, if the bus is driving through the i-th region and has k schoolchildren, then the temperature inside the bus is ti + k degrees.Of course, nobody likes it when the bus is hot. So, when the bus drives through the i-th region, if it has more than Ti degrees inside, each of the schoolchild in the bus demands compensation for the uncomfortable conditions. The compensation is as large as xi rubles and it is charged in each region where the temperature in the bus exceeds the limit.To save money, the organizers of the trip may arbitrarily add or remove extra buses in the beginning of the trip, and between regions (of course, they need at least one bus to pass any region). The organizers can also arbitrarily sort the children into buses, however, each of buses in the i-th region will cost the organizers costi rubles. Please note that sorting children into buses takes no money.Your task is to find the minimum number of rubles, which the organizers will have to spend to transport all schoolchildren.

The first input line contains two integers n and m (1 ≤ n ≤ 105; 1 ≤ m ≤ 106) — the number of regions on the way and the number of schoolchildren in the group, correspondingly. Next n lines contain four integers each: the i-th line contains ti, Ti, xi and costi (1 ≤ ti, Ti, xi, costi ≤ 106). The numbers in the lines are separated by single spaces.

Print the only integer — the minimum number of roubles the organizers will have to spend to transport all schoolchildren. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

NoteIn the first sample the organizers will use only one bus to travel through the first region. However, the temperature in the bus will equal 30 + 10 = 40 degrees and each of 10 schoolchildren will ask for compensation. Only one bus will transport the group through the second region too, but the temperature inside won't exceed the limit. Overall, the organizers will spend 100 + 10 + 10 = 120 rubles.

<?php
function div($a,$b){
 if($b<=0)return "1000001000000";
 //return bcdiv(bcadd(bcadd($a,$b,0),"-1",0),$b,0);
 return strval(intval(($a+$b-1)/$b));
}
function comp($a,$b){
 if(strlen($a)!=strlen($b))
  return strlen($a)<strlen($b)?$a:$b;
 $l = strlen($a);
 for($i=0;$i<$l;++$i){
  if($a[$i]!=$b[$i])
   return $a[$i]<$b[$i]?$a:$b;
 }
 return $a;
}
$stdin=fopen("php://stdin","r");
$stdout=fopen("php://stdout","w");
list($n,$m)=explode(" ",fgets($stdin));
$m=trim($m);
$ans="0";
for($i=0;$i<$n;++$i){
 list($tcur,$tmax,$x,$cost)=explode(" ",$str=fgets($stdin));
 $tcur=trim($tcur);
 $tmax=trim($tmax);
 $x=trim($x);
 $cost=trim($cost);
 $cost1=$cost;
 if(intval($tcur)+intval($m)>intval($tmax)){
  $cost1=bcadd($cost1,bcmul($x,$m,0),0);
 }
 $cost2=bcmul($cost,div($m,$tmax-$tcur),0);
 $ans=bcadd($ans,comp($cost1,$cost2),0);
}
fputs($stdout,$ans);
?>

<?php
function div($a,$b){
if(b<=0)return 0x3f3f3f3f;
return (a+b-1)/b;
}
$stdin=fopen("php://stdin","r");
$stdout=fopen("php://stdout","w");
list($n,$m)=explode(" ",fgets($stdin));
for($i=0;$i<$n;++$i){
 list($tcur,$tmax,$x,$cost)=explode(" ",fgets($stdin));
 $cost1=$cost+($tcur+$m>$tmax?$x*$m:0);
 $cost2=$cost*div($m,$tmax-$tcur);
 $ans+=min($cost1,$cost2);
}
fputs($stdout,$ans);
?>

<?php
function div($a,$b){
 if($b<=0)return "10000010000";
 //return bcdiv(bcadd(bcadd($a,$b,0),"-1",0),$b,0);
 return strval(intval(($a+$b-1)/$b));
}
function comp($a,$b){
 if(strlen($a)!=strlen($b))
  return strlen($a)<strlen($b)?$a:$b;
 $l = strlen($a);
 for($i=0;$i<$l;++$i){
  if($a[$i]!=$b[$i])
   return $a[$i]<$b[$i]?$a:$b;
 }
 return $a;
}
$stdin=fopen("php://stdin","r");
$stdout=fopen("php://stdout","w");
list($n,$m)=explode(" ",fgets($stdin));
$m=trim($m);
$ans="0";
for($i=0;$i<$n;++$i){
 list($tcur,$tmax,$x,$cost)=explode(" ",$str=fgets($stdin));
 $tcur=trim($tcur);
 $tmax=trim($tmax);
 $x=trim($x);
 $cost=trim($cost);
 $cost1=$cost;
 if(intval($tcur)+intval($m)>intval($tmax)){
  $cost1=bcadd($cost1,bcmul($x,$m,0),0);
 }
 $cost2=bcmul($cost,div($m,$tmax-$tcur),0);
 $ans=bcadd($ans,comp($cost1,$cost2),0);
}
fputs($stdout,$ans);
?>

<?php
function div($a,$b){
 if($b<0)return "10000010000";
 //return bcdiv(bcadd(bcadd($a,$b,0),"-1",0),$b,0);
 return strval(intval(($a+$b-1)/$b));
}
function comp($a,$b){
 if(strlen($a)!=strlen($b))
  return strlen($a)<strlen($b)?$a:$b;
 $l = strlen($a);
 for($i=0;$i<$l;++$i){
  if($a[$i]!=$b[$i])
   return $a[$i]<$b[$i]?$a:$b;
 }
 return $a;
}
$stdin=fopen("php://stdin","r");
$stdout=fopen("php://stdout","w");
list($n,$m)=explode(" ",fgets($stdin));
$m=trim($m);
$ans="0";
for($i=0;$i<$n;++$i){
 list($tcur,$tmax,$x,$cost)=explode(" ",$str=fgets($stdin));
 $tcur=trim($tcur);
 $tmax=trim($tmax);
 $x=trim($x);
 $cost=trim($cost);
 $cost1=$cost;
 if(intval($tcur)+intval($m)>intval($tmax)){
  $cost1=bcadd($cost1,bcmul($x,$m,0),0);
 }
 $cost2=bcmul($cost,div($m,$tmax-$tcur),0);
 $ans=bcadd($ans,comp($cost1,$cost2),0);
}
fputs($stdout,$ans);
?>

<?php
function div($a,$b){
if($b<=0)return 0x3f3f3f3f;
return intval(($a+$b-1)/$b);
}
$stdin=fopen("php://stdin","r");
$stdout=fopen("php://stdout","w");
list($n,$m)=explode(" ",fgets($stdin));
$ans=0.0;
for($i=0;$i<$n;++$i){
 list($tcur,$tmax,$x,$cost)=explode(" ",fgets($stdin));
 $cost1=$cost+($tcur+$m>$tmax?$x*$m:0);
 $cost2=$cost*div($m,$tmax-$tcur);
 $ans+=min($cost1,$cost2);
}
fprintf($stdout,"%.0lf",$ans);
?>

<?php
function div($a,$b){
if($b<=0)return 0x3f3f3f3f;
return intval(($a+$b-1)/$b);
}
$stdin=fopen("php://stdin","r");
$stdout=fopen("php://stdout","w");
list($n,$m)=explode(" ",fgets($stdin));
for($i=0;$i<$n;++$i){
 list($tcur,$tmax,$x,$cost)=explode(" ",fgets($stdin));
 $cost1=$cost+($tcur+$m>$tmax?$x*$m:0);
 $cost2=$cost*div($m,$tmax-$tcur);
 $ans+=min($cost1,$cost2);
}
fputs($stdout,$ans);
?>

<?php
function div($a,$b){
if($b<=0)return 0x3f3f3f3f;
return ($a+$b-1)/$b;
}
$stdin=fopen("php://stdin","r");
$stdout=fopen("php://stdout","w");
list($n,$m)=explode(" ",fgets($stdin));
for($i=0;$i<$n;++$i){
 list($tcur,$tmax,$x,$cost)=explode(" ",fgets($stdin));
 $cost1=$cost+($tcur+$m>$tmax?$x*$m:0);
 $cost2=$cost*div($m,$tmax-$tcur);
 $ans+=min($cost1,$cost2);
}
fputs($stdout,$ans);
?>


Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size n × m cells, like this:Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.The key of this game is to find a cycle that contain dots of same color. Consider 4 blue dots on the picture forming a circle as an example. Formally, we call a sequence of dots d1, d2, ..., dk a cycle if and only if it meets the following condition:  These k dots are different: if i ≠ j then di is different from dj.  k is at least 4.  All dots belong to the same color.  For all 1 ≤ i ≤ k - 1: di and di + 1 are adjacent. Also, dk and d1 should also be adjacent. Cells x and y are called adjacent if they share an edge. Determine if there exists a cycle on the field.

The first line contains two integers n and m (2 ≤ n, m ≤ 50): the number of rows and columns of the board. Then n lines follow, each line contains a string consisting of m characters, expressing colors of dots in each line. Each character is an uppercase Latin letter.

Output "Yes" if there exists a cycle, and "No" otherwise.

7 6
AAAAAB
ABBBAB
ABAAAB
ABABBB
ABAAAB
ABBBAB
AAAAAB

NoteIn first sample test all 'A' form a cycle.In second sample there is no such cycle.The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red).


Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 ≤ i ≤ n). Help Polycarpus determine the length of the city phone code.

The first line of the input contains an integer n (2 ≤ n ≤ 3·104) — the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.

Print the number of digits in the city phone code.

NoteA prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".In the first sample the city phone code is string "00".In the second sample the city phone code is an empty string.In the third sample the city phone code is string "770123456789".

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$d = strlen($b);
for($x = 1; $x < $a; $x++)
{
    $c = trim(fgets(STDIN));
    for($y = 0; $y < $d; $y++)
    {
        if($b[$y] != $c[$y])
        {
            $d = $y + 1;
            break;
        }
    }
}
print $d - 1;
?>

<?php

function common_prefix_len($str1, $str2, $limit = 20) {
  $len1 = strlen($str1);
  $len2 = strlen($str2);
  $len_min = min($len1, $len2, $limit);

  for($i=0; $i < $len_min; $i++) {
    if ($str1[$i] != $str2[$i]) return $i;
  }
  return $len_min;
}

function find_prefix_len($str_list) {
  $list_count = count($str_list);
  $result = 20;
  for($i=0; $i < $list_count - 1; $i++) {
    $result = min(common_prefix_len($str_list[$i], $str_list[$i+1], $result), $result);
  }

  return $result;
}

function read_input() {
  $count = intval(fgets(STDIN));
  $str = array();
  for ($i=0; $i<$count; $i++) {
    $str[] = trim(fgets(STDIN));
  }

  return $str;
}

print (find_prefix_len(read_input())) ."\n";

<?php
//считываем
$n=fgets(STDIN);
$a=array();
for($i=0;$i<$n;$i++) $a[$i]=fgets(STDIN);
//обрабатываем
$b=array();
$buf;$size=0;$one;
for($i=0;$i<strlen($a[0]);$i++) {
$one=1;
$buf=$a[0][$i];
foreach($a as $k=>$v) {
if($v[$i]!=$buf) goto out;
elseif($one) {
$one=0;
$size++;
}
}
}
out:
$size--;
echo $size;
?>

<?php

$flag = 1; //must be not zero for STDIN
$in = 'php://stdin';
if (!$flag)
{
    $in = "input.txt";
}
$fd = fopen($in, "r");
fscanf($fd, "%d\n", $n);

$phones=array($n);
$result=0;
for ($c=0;$c<$n;$c++)
{
   fscanf($fd, "%s\n",$phones[$c]);
}
fclose($fd);

for ($c=0 ,$prefix=$phones[0];$c<$n;$c++ )
{

  for ($l=0 ;$l<=strlen($prefix);$l++ )
    {
  $cmp=strncmp($prefix,$phones[$c],(strlen($prefix)-$l));
  if ($cmp!=0)
  {
     continue;
  }
  $prefix=substr($prefix , 0 ,(strlen($prefix)-$l) );
  $result=strlen($prefix);

  break;
    }
  }

print "$result\n";
?>

<?php
while($s = fgets(STDIN)){
$input .= $s;
}
$input = explode("\r\n", $input);
$n = $input[0];
$a = $input[1][0];
$result = 0;
for ($s = 0; $s < strlen($input[1]); $s++) {
    for ($i=1; $i < (count($input)-1); $i++) {
        if ($a != $input[$i][$s]) {
            echo $result;

            die();
        }

    }
    $result++;
    $o = $s + 1;
    $a = "{$input[1][$o]}";
}
?>

<?php
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$x=explode("\n",$n);
$count=$x[0];
$len=strlen($x[(int)$count]);
for($t=0;$t<$len;){
    $cnt=0;
    for($i=1;$i<$count;$i++){
        if((int)$x[$i][$t]==(int)$x[$i+1][$t]){
            $cnt++;
        }

    }
    if(($cnt+1)==$count){
        $t++;
    }
    else{
        echo $t;
        break;
    }
}
?>

<?php
    define ("TEST", false);
    if (TEST) $GLOBALS['file'] = fopen('input.txt', 'r');
    else $GLOBALS['file'] = fopen('php://stdin', 'r');
    function debug($var){echo '<pre>'; print_r($var); echo '</pre>';}
    function read_str(){return trim(fgets($GLOBALS['file']));}
    function read_array(){return explode(' ', read_str());}
    /***************************************************************/
    $n = read_str();
    $s = read_str();

    function compare($s1, $s2)
    {
        $s = '';
        $len = strlen($s1);
        for($i=0; $i < $len; $i++)
        {
            if($s1[$i] == $s2[$i]) $s.= $s1[$i];
            else return $s;
        }

        return $s;
    }

    for($i=2; $i<=$n; $i++)
    {
        $s2 = read_str();

        $s = compare($s, $s2);
        if($s==='')
        {
            echo 0; die();
        }
    }

    echo strlen($s);

<?php
$fp = fopen('php://stdin', 'r');
$tmp='';
while($line = fgets($fp)) $tmp.=$line;

$tmp=explode("\n",$tmp);
$count=(int)$tmp[0];
$current=trim($tmp[1]);
$len=strlen($current);
for ($i=2;$i<=$count&&$len>0;$i++){
  while (strpos($tmp[$i],$current )!==0 && $len>0){
      $len--;
      $current=substr($current,0,$len);
  }
}
echo $len;
?>

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

$a = array();
for($i=0;$i<$n;$i++) $a[$i] = trim(fgets(STDIN));

sort($a, SORT_STRING);

$r = 0;
for($i=0;$i<strlen($a[0]);$i++) if($a[0][$i] == $a[$n - 1][$i]) $r ++; else break;

print $r;
?>

<?php

$f = fopen('php://stdin', 'r');
$n = intval(fgets($f));

$prefix = array(0 => "");

$s = "a".trim(fgets($f));

$answer = strlen($s);
for($i=1; $i<=$answer; $i++)
{
    $prefix[$i] = substr($s,0, $i);
}

for($i=1; $i<$n; $i++)
{
    $s = "a".trim(fgets($f));
    while($answer>0)
    {
        if(substr($s, 0, $answer)==$prefix[$answer]) break;
        $answer--;
    }
}

echo $answer-1;

<?php
while($s = fgets(STDIN)){
$input .= $s;
}
$input = explode("\r\n", $input);
$n = $input[0];
$a = $input[1][0];
$result = 0;
for ($s = 0; $s < strlen($input[1]); $s++) {
    for ($i=1; $i < count($input); $i++) {
        if ($a != $input[$i][$s]) {
            echo $result;

            die();
        }

    }
    $result++;
    $o = $s + 1;
    $a = "{$input[1][$o]}";
}
?>

<?php

$f = fopen('php://stdin', 'r');
$n = intval(fgets($f));

$prefix = array(0 => "");

$s = trim(fgets($f));

$answer = strlen($s);
for($i=1; $i<=$answer; $i++)
{
    $prefix[$i] = substr($s,0, $i);
}

for($i=1; $i<$n; $i++)
{
    $s = trim(fgets($f));
    while($answer>0)
    {
        if(substr($s, 0, $answer)==$prefix[$answer]) break;
        $answer--;
    }
}

echo $answer;


So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation. Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surrounded cities. At any moment all points of the flatland ring can begin to move quickly in the direction of the city — that's the strategy the flatlanders usually follow when they besiege cities.The berlanders are sure that they can repel the enemy's attack if they learn the exact time the attack starts. For that they need to construct a radar that would register any movement at the distance of at most r from it. Thus, we can install a radar at such point, that at least one point of the enemy ring will be in its detecting range (that is, at a distance of at most r). Then the radar can immediately inform about the enemy's attack. Due to the newest technologies, we can place a radar at any point without any problems. But the problem is that the berlanders have the time to make only one radar. Besides, the larger the detection radius (r) is, the more the radar costs.That's why Vasya's task (that is, your task) is to find the minimum possible detection radius for the radar. In other words, your task is to find the minimum radius r (r ≥ 0) such, that a radar with radius r can be installed at some point and it can register the start of the movements of both flatland rings from that point. In this problem you can consider the cities as material points, the attacking enemy rings - as circles with centers in the cities, the radar's detection range — as a disk (including the border) with the center at the point where the radar is placed.

The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers xi, yi, ri (|xi|, |yi| ≤ 104; 1 ≤ ri ≤ 104) — the city's coordinates and the distance from the city to the flatlanders, correspondingly. It is guaranteed that the cities are located at different points.

Print a single real number — the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10 - 6.

NoteThe figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2, 0).   The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0, 0).

<?php

error_reporting(0);

solve();

function solve(){
    //$Input = new Input("input.txt");
    $Input = new Input();

    $X1 = (int)$Input->in();
    $Y1 = (int)$Input->in();
    $R1 = (int)$Input->in();

    $X2 = (int)$Input->in();
    $Y2 = (int)$Input->in();
    $R2 = (int)$Input->in();

    $d = pow($X1 - $X2, 2) + pow($Y1 - $Y2, 2);
    $temp1 = sqrt($d) - $R1 - $R2;
    $temp2 = sqrt($d) - abs($R1 - $R2);
    if ($temp1 > 10E-6) $ans = $temp1 / 2;
    else {
        if ($temp2 > 10E-6) $ans = 0;
        else $ans = ((-1) * $temp2) / 2;
    }
    printf("%.15f", $ans);
}

class Input{
    private $handle = "";
    private $values = array();
    private $index = 0;

    public function __construct($localfile){

        if (is_file($localfile)) {

            $this->handle = fopen($localfile, "r");
            $contents = stream_get_contents($this->handle);

        } else {

            $contents = stream_get_contents(STDIN);

        }

        $no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
        $this->values = explode(" ", $no_newlines);
    }

    public function in(){

        return $this->values[$this->index++];

    }

    public function close(){

        if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

    }
}

?>

<?php

error_reporting(0);

solve();

function solve(){
	//$Input = new Input("input.txt");
	$Input = new Input();

	$X1 = (int)$Input->in();
	$Y1 = (int)$Input->in();
	$R1 = (int)$Input->in();

	$X2 = (int)$Input->in();
	$Y2 = (int)$Input->in();
	$R2 = (int)$Input->in();

	$d = pow($X1 - $X2, 2) + pow($Y1 - $Y2, 2);
	$ans = (sqrt($d) - $R1 - $R2) / 2;

	printf("%.15f", $ans);
}

class Input{
	private $handle = "";
	private $values = array();
	private $index = 0;

	public function __construct($localfile){

		if (is_file($localfile)) {

			$this->handle = fopen($localfile, "r");
			$contents = stream_get_contents($this->handle);

		} else {

			$contents = stream_get_contents(STDIN);

		}

		$no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->values = explode(" ", $no_newlines);
	}

	public function in(){

		return $this->values[$this->index++];

	}

	public function close(){

		if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

	}
}

?>


Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.

The only line contains odd integer n (1 ≤ n ≤ 49).

Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main diagonals should be odd.