The great hero guards the country where Homer lives. The hero has attack power $$$A$$$ and initial health value $$$B$$$. There are $$$n$$$ monsters in front of the hero. The $$$i$$$-th monster has attack power $$$a_i$$$ and initial health value $$$b_i$$$. The hero or a monster is said to be living, if his or its health value is positive (greater than or equal to $$$1$$$); and he or it is said to be dead, if his or its health value is non-positive (less than or equal to $$$0$$$).In order to protect people in the country, the hero will fight with monsters until either the hero is dead or all the monsters are dead.  In each fight, the hero can select an arbitrary living monster and fight with it. Suppose the $$$i$$$-th monster is selected, and the health values of the hero and the $$$i$$$-th monster are $$$x$$$ and $$$y$$$ before the fight, respectively. After the fight, the health values of the hero and the $$$i$$$-th monster become $$$x-a_i$$$ and $$$y-A$$$, respectively. Note that the hero can fight the same monster more than once.For the safety of the people in the country, please tell them whether the great hero can kill all the monsters (even if the great hero himself is dead after killing the last monster).

Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains three integers $$$A$$$ ($$$1 \leq A \leq 10^6$$$), $$$B$$$ ($$$1 \leq B \leq 10^6$$$) and $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the attack power of the great hero, the initial health value of the great hero, and the number of monsters. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^6$$$), where $$$a_i$$$ denotes the attack power of the $$$i$$$-th monster. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^6$$$), where $$$b_i$$$ denotes the initial health value of the $$$i$$$-th monster. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print the answer: "YES" (without quotes) if the great hero can kill all the monsters. Otherwise, print "NO" (without quotes).

NoteIn the first example: There will be $$$6$$$ fights between the hero and the only monster. After that, the monster is dead and the health value of the hero becomes $$$17 - 6 \times 2 = 5 > 0$$$. So the answer is "YES", and moreover, the hero is still living.In the second example: After all monsters are dead, the health value of the hero will become $$$709$$$, regardless of the order of all fights. So the answer is "YES".In the third example: A possible order is to fight with the $$$1$$$-st, $$$2$$$-nd, $$$3$$$-rd and $$$4$$$-th monsters. After all fights, the health value of the hero becomes $$$-400$$$. Unfortunately, the hero is dead, but all monsters are also dead. So the answer is "YES".In the fourth example: The hero becomes dead but the monster is still living with health value $$$1000 - 999 = 1$$$. So the answer is "NO".

<?php

$t = (int) trim(fgets(STDIN));
for ($i = 0; $i < $t; ++$i) {
    //i[]
    list($axi[], $bxi[], $ni[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $bi[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($i = 0; $i < $t; ++$i) {
    $ax = $axi[$i];
    $bx = $bxi[$i];
    $n = $ni[$i];
    $a = $ai[$i];
    $b = $bi[$i];
    $sum = 0;
    for ($j = 0; $j < $n; ++$j) {
        $sum += ceil($b[$j] / $ax) * $a[$j];
    }
    echo ($bx > $sum - max($a) ? 'YES' : 'NO').PHP_EOL;
}

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

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

for ($i = 0; $i < $t; $i++) {
  list($A, $B, $n) = explode(" ", trim(fgets($file)));
  $a = explode(" ", trim(fgets($file)));
  $b = explode(" ", trim(fgets($file)));
  $sum = 0; $f = 0;

  for ($j = 0; $j < $n; $j++) {
    $sum += $a[$j] * ceil($b[$j] / $A);
  }

	for ($j = 0; $j < $n; $j++) {
	  $res = $B - ($sum - $a[$j]);
	  if ($res >= 1) { $f = 1; break; }
	}

  if ($f == 1) { echo 'YES'.PHP_EOL; }
  else { echo 'NO'.PHP_EOL; }
}
?>

<?php

$t = (int) trim(fgets(STDIN));
for ($i = 0; $i < $t; ++$i) {
    //i[]
    list($axi[], $bxi[], $ni[]) = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $bi[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($i = 0; $i < $t; ++$i) {
    $ax = $axi[$i];
    $bx = $bxi[$i];
    $n = $ni[$i];
    $a = $ai[$i];
    $b = $bi[$i];
    $flg = true;
    for ($j = 0; $j < $n; ++$j) {
        $cntx = ceil($b[$j] / $ax);
        $cnt = ceil($bx / $a[$j]);
        if ($cntx > $cnt) {
            $flg = false;
            break;
        }
        $bx -= $cntx * $a[$j];
    }
    echo ($flg ? 'YES' : 'NO').PHP_EOL;
}

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

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

for ($i = 0; $i < $t; $i++) {
  list($A, $B, $n) = explode(" ", trim(fgets($file)));
  $a = explode(" ", trim(fgets($file)));
  $b = explode(" ", trim(fgets($file)));
  $sum = 0; $sum2 = 0; $h2 = 0;

  for ($j = 0; $j < $n; $j++) {
    $sum += $a[$j] * ceil($b[$j] / $A);
    $sum2 += $A * ceil($B / $a[$j]);
    $h2 += $b[$j] - $sum2;
  }

  $h = $B - $sum;

  if ($h2 <= 0) { echo 'YES'.PHP_EOL; }
  else { echo 'NO'.PHP_EOL; }

}
?>


Madoka decided to participate in an underground sports programming competition. And there was exactly one task in it:A square table of size $$$n \times n$$$, where $$$n$$$ is a multiple of $$$k$$$, is called good if only the characters '.' and 'X' are written in it, as well as in any subtable of size $$$1 \times k$$$ or $$$k \times 1$$$, there is at least one character 'X'. In other words, among any $$$k$$$ consecutive vertical or horizontal cells, there must be at least one containing the character 'X'.Output any good table that has the minimum possible number of characters 'X', and also the symbol 'X' is written in the cell $$$(r, c)$$$. Rows are numbered from $$$1$$$ to $$$n$$$ from top to bottom, columns are numbered from $$$1$$$ to $$$n$$$ from left to right.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first and the only line of each test case contains four integers $$$n$$$, $$$k$$$, $$$r$$$, $$$c$$$ ($$$1 \le n \le 500, 1 \le k \le n, 1 \le r, c \le n$$$) — the size of the table, the integer $$$k$$$ and the coordinates of the cell, which must contain the character 'X'. It is guaranteed that $$$n$$$ is a multiple of $$$k$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$500$$$.

For each test case, output $$$n$$$ lines, each consisting of $$$n$$$ characters '.' and 'X', — the desired table. If there are several answers, then you can output anyone.

NoteLet's analyze the first test case.The following tables can be printed as the correct answer: X....X.X. or ..XX...X.  It can be proved that there cannot be less than $$$3$$$ characters 'X' in the answer.Note that the following table is invalid because cell $$$(3, 2)$$$ does not contain the character 'X':  X...X...X In the second test case, the only correct table is:  XXXX  Each subtable of size $$$1 \times 1$$$ must contain a 'X' character, so all characters in the table must be equal to 'X'.

<?php

// 1717 B. Madoka and Underground Competitions

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

while ($t--) {
    fscanf(STDIN, '%u %u %u %u', $n, $k, $r, $c);
    --$r;
    --$c;

    $mx = array_fill(0, $n, array_fill(0, $n, '.'));

    for ($i = 0; $i < $n; ++$i) {
        for ($j = (($r + $c) % $k - $i % $k + $k) % $k; $j < $n; $j += $k) {
            $mx[$i][$j] = 'X';
        }
    }

    foreach ($mx as $it) {
        fprintf(STDOUT, '%s'.PHP_EOL, implode('', $it));
    }
}
/*
1
6 3 1 1

1
6 3 1 6

All items of same diagonal have the same value of (i + j).
We need to find items where (i + j) % k === (r + c) % k

 */

<?php

// 1717 B. Madoka and Underground Competitions

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

while ($t--) {
    fscanf(STDIN, '%u %u %u %u', $n, $k, $r, $c);
    --$r;
    --$c;

    $mx = array_fill(0, $n, array_fill(0, $n, '.'));

    for ($i = 0; $i < $n; ++$i) {
        for ($j = ((($r + $c) % $k - $i % $k) + $k) % $k; $j < $n; $j += $k) {
            $mx[$i][$j] = 'X';
        }
    }

    foreach ($mx as $it) {
        fprintf(STDOUT, '%s'.PHP_EOL, implode('', $it));
    }
}
/*
1
6 3 1 1

1
6 3 1 6

 */

<?php

// 1717 B. Madoka and Underground Competitions

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

while ($t--) {
    fscanf(STDIN, '%u %u %u %u', $n, $k, $r, $c);
    --$r;
    --$c;

    $mx = array_fill(0, $n, array_fill(0, $n, '.'));

    for ($i = 0; $i < $n; ++$i) {
        for ($j = ((($r + $c) % $k - $i % $k) + $k) % $k; $j < $n; $j += $k) {
            $mx[$i][$j] = 'X';
        }
    }

    foreach ($mx as $it) {
        fprintf(STDOUT, str_repeat('%s', $n).PHP_EOL, ...$it);
    }
}
/*
1
6 3 1 1

1
6 3 1 6

 */

<?php

// 1717 B. Madoka and Underground Competitions

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

while ($t--) {
    fscanf(STDIN, '%u %u %u %u', $n, $k, $r, $c);
    --$r;
    --$c;

    $mx = array_fill(0, $n, array_fill(0, $n, '.'));

    for ($i = 0; $i < $n; ++$i) {
        for ($j = ((($r + $c) % $k - $i % $k) + $k) % $k; $j < $n; $j += $k) {
            $mx[$i][$j] = 'X';
        }
    }

    foreach ($mx as $it) {
        fprintf(STDOUT, '%s'.PHP_EOL, implode(' ', $it));
    }
}
/*
1
6 3 1 1

1
6 3 1 6

 */


A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent.Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed).You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No".

The first line contains integer $$$n$$$ ($$$1 \le n \le 100$$$), denoting the number of strings to process. The following $$$n$$$ lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between $$$1$$$ and $$$100$$$, inclusive.

Print $$$n$$$ lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.

<?php
# 1144A
$input = fopen('php://stdin', 'rb');
$linesCount = (int)fgets($input);

for ($i = 0; $i < $linesCount; $i++) {
    $charMap = [];
    $symbols = str_split(trim(fgets($input)));
    sort($symbols);
    $limit = count($symbols) - 1;
    $valid = true;
    for ($j = 0; $j < $limit; $j++) {
        if (isset($charMap[$symbols[$j]]) || (ord($symbols[$j]) + 1 !== ord($symbols[$j + 1]))) {
            $valid = false;
            break;
        }
        $charMap[$symbols[$j]] = true;
    }
    echo ($valid ? 'YES' : 'NO') . PHP_EOL;
}

<?php
fscanf(STDIN,"%d",$tc);
while ($tc--)
{

	$str=trim(fgets(STDIN));
	$asciValue=array();
	for ($i=0; $i <strlen($str) ; $i++)
	{
		$asciValue[$i]=ord($str[$i]);
	}
   // print_r($asciiValue);//print_r($str);
	for ($i=0; $i <count($asciValue) ; $i++)
	{
			for ($j=0; $j <count($asciValue)-1 ; $j++)
			 {
                 if($asciValue[$i]<$asciValue[$j])
                 {
                 	$asciValue[$i]=$asciValue[$i]+$asciValue[$j];
                 	$asciValue[$j]=$asciValue[$i]-$asciValue[$j];
                 	$asciValue[$i]=$asciValue[$i]-$asciValue[$j];
                 }
			 }
	}
	$flag=0;
	for ($i=0; $i <count($asciValue)-1 ; $i++)
	{
		if($asciValue[$i+1]-$asciValue[$i]!=1)
		{
          echo "No\n";
          $flag=1;
          break;
		}
	}
    if($flag==0)
    	echo "Yes\n";

}


A car number in Berland consists of exactly n digits. A number is called beautiful if it has at least k equal digits. Vasya wants to change the digits in his car's number so that the number became beautiful. To replace one of n digits Vasya has to pay the sum of money, equal to the absolute difference between the old digit and the new one.Help Vasya: find the minimum sum of money he should pay to make the number of his car beautiful. You should also find the resulting beautiful number. If there are several such numbers, then print the lexicographically minimum one.

The first line contains two space-separated integers n and k (2 ≤ n ≤ 104, 2 ≤ k ≤ n) which represent how many digits the number has and how many equal digits a beautiful number should have. The second line consists of n digits. It describes the old number of Vasya's car. It is guaranteed that the number contains no spaces and only contains digits.

On the first line print the minimum sum of money Vasya needs to change the number. On the second line print the car's new number. If there are several solutions, print the lexicographically minimum one.

NoteIn the first sample replacing the second digit with an "8" costs |9 - 8| = 1. Replacing the fifth digit with an "8" costs the same. Replacing the sixth digit costs |6 - 8| = 2. As a result, Vasya will pay 1 + 1 + 2 = 4 for a beautiful number "888188".The lexicographical comparison of strings is performed by the < operator in modern programming languages. The string x is lexicographically smaller than the string y, if there exists such i (1 ≤ i ≤ n), that xi < yi, and for any j (1 ≤ j < i) xj = yj. The strings compared in this problem will always have the length n.


Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motarack is an array $$$a$$$ of $$$n$$$ non-negative integers.Dark created that array $$$1000$$$ years ago, so some elements in that array disappeared. Dark knows that Motarack hates to see an array that has two adjacent elements with a high absolute difference between them. He doesn't have much time so he wants to choose an integer $$$k$$$ ($$$0 \leq k \leq 10^{9}$$$) and replaces all missing elements in the array $$$a$$$ with $$$k$$$.Let $$$m$$$ be the maximum absolute difference between all adjacent elements (i.e. the maximum value of $$$|a_i - a_{i+1}|$$$ for all $$$1 \leq i \leq n - 1$$$) in the array $$$a$$$ after Dark replaces all missing elements with $$$k$$$.Dark should choose an integer $$$k$$$ so that $$$m$$$ is minimized. Can you help him?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^{5}$$$) — the size of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-1 \leq a_i \leq 10 ^ {9}$$$). If $$$a_i = -1$$$, then the $$$i$$$-th integer is missing. It is guaranteed that at least one integer is missing in every test case. It is guaranteed, that the sum of $$$n$$$ for all test cases does not exceed $$$4 \cdot 10 ^ {5}$$$.

Print the answers for each test case in the following format: You should print two integers, the minimum possible value of $$$m$$$ and an integer $$$k$$$ ($$$0 \leq k \leq 10^{9}$$$) that makes the maximum absolute difference between adjacent elements in the array $$$a$$$ equal to $$$m$$$. Make sure that after replacing all the missing elements with $$$k$$$, the maximum absolute difference between adjacent elements becomes $$$m$$$. If there is more than one possible $$$k$$$, you can print any of them.

NoteIn the first test case after replacing all missing elements with $$$11$$$ the array becomes $$$[11, 10, 11, 12, 11]$$$. The absolute difference between any adjacent elements is $$$1$$$. It is impossible to choose a value of $$$k$$$, such that the absolute difference between any adjacent element will be $$$\leq 0$$$. So, the answer is $$$1$$$.In the third test case after replacing all missing elements with $$$6$$$ the array becomes $$$[6, 6, 9, 6, 3, 6]$$$.  $$$|a_1 - a_2| = |6 - 6| = 0$$$;  $$$|a_2 - a_3| = |6 - 9| = 3$$$;  $$$|a_3 - a_4| = |9 - 6| = 3$$$;  $$$|a_4 - a_5| = |6 - 3| = 3$$$;  $$$|a_5 - a_6| = |3 - 6| = 3$$$. So, the maximum difference between any adjacent elements is $$$3$$$.

<?php
$f = trim(fgets(STDIN));
for($j = 0; $j < $f; $j++){
    $a = trim(fgets(STDIN));
    $b = explode(' ', trim(fgets(STDIN)));
    $all = 0;
    $count = 0;
    $max = 0;
    $min = 0;
    $bool = true;
    $bool2 = true;
    for($i = 0; $i < $a; $i++){
        if($b[$i] != -1){
            $all += $b[$i];
            $count++;
            if($bool || $max < $b[$i]){
                $max = $b[$i];
                $bool = false;
            }
            if($bool2 || $min > $b[$i]){
                $min = $b[$i];
                $bool2 = false;
            }
        }
    }
    if($bool && $bool2){
        $k = 5;
        $m = 0;
    } else {
        $k = round($all / $count);
         $m = $k - $min > $max - $k ? $k - $min : $max - $k;
    }

    echo $m." ".$k."\n";

}


Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.

The first line contains line s (1 ≤ |s| ≤ 2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message. The second line contains line t (|s| ≤ |t| ≤ 2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper. Here |a| means the length of the string a.

Print two integers separated by a space:   the first number is the number of times Tanya shouts "YAY!" while making the message,  the second number is the number of times Tanya says "WHOOPS" while making the message.

<?php
$r = fopen( 'php://stdin', 'r' );
$s1 = trim(fgets($r));
$s2 = trim(fgets($r));
$a1 = array();
for ($i = 0; $i < strlen($s1); $i++) {
    $s = substr($s1, $i, 1);
    if (!isset($a1[$s])) {
        $a1[$s] = 1;
    }
    else {
        $a1[$s]++;
    }

}

$a2 = array();
for ($i = 0; $i < strlen($s2); $i++) {
    $s = substr($s2, $i, 1);
    if (!isset($a2[$s])) {
        $a2[$s] = 1;
    }
    else {
        $a2[$s]++;
    }

}

$iMatchCount = 0;
$iDismatchCount = 0;
foreach ($a1 AS $s => $i) {
    if (!isset($a2[$s])) {
        $iDismatchCount += $i;
    }
    else if ($a1[$s] == $a2[$s]) {
        $iMatchCount += $a2[$s];
    }
    else if ($a1[$s] - $a2[$s] > 0) {
        $iDiff = $a1[$s] - $a2[$s];
        $iMatchCount += $a2[$s];
        $iDismatchCount += $iDiff;
    }

}

echo $iMatchCount . ' ' . $iDismatchCount;
fclose($r);
exit();
?>


Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.  So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. The battery of the newest device allows to highlight at most n sections on the display. Stepan wants to know the maximum possible integer number which can be shown on the display of his newest device. Your task is to determine this number. Note that this number must not contain leading zeros. Assume that the size of the display is enough to show any integer.

The first line contains the integer n (2 ≤ n ≤ 100 000) — the maximum number of sections which can be highlighted on the display.

Print the maximum integer which can be shown on the display of Stepan's newest device.

<?php
  fscanf(STDIN, "%d\n", $number); // reads number from STDIN
  if ($number % 2 == 1) {
    echo 7;
    $number -= 3;
  }
  for ($i = 0; $i < $number; $i += 2) {
    echo 1;
  }
?>

<?php
 list($n) = explode(" ", fgets(STDIN));
 $n = (int) $n;
 $s = (int)7;
 $o = (int)1;
 if ($n % 2 == 1)
  echo $s;
 else
  echo $o;
 for ($i = 1; $i * 2 < $n - $n % 2; $i++)
  echo $o;
?>

<?
$number = 0;
fscanf(STDIN, "%d\n", $number);
$ans = "";
while ($number > 1){
    if ($number > 5){
    	$ans = $ans . "11";
    	$number = $number - 4;
    }
    if ($number == 5){
	    $ans = "71" . $ans;
        $number = $number - 5;
    }
    if ($number == 4){
	    $ans = "11" . $ans;
        $number = $number - 4;
    }
    if ($number == 3){
	    $ans = "7" . $ans;
        $number = $number - 3;
    }
    if ($number == 2){
	    $ans = "1" . $ans;
        $number = $number - 2;
    }
}

fwrite(STDOUT, $ans);
?>

<?php

fscanf(STDIN, "%d\n", $number);

$number = intval($number);

if ($number % 2 == 1) {
    printf("7");
    $number -= 3;
}
while ($number > 0) {
    printf("1");
    $number -= 2;
}
?>

<?php
 list($n) = explode(" ", fgets(STDIN));
 $n = (int) $n;
if($n % 2 == 0)
echo 1;
else
 echo 7;
$n = $n/2 - 1;
$n = (int) $n;
 for ($i = 0; $i < $n; $i++)
 echo 1;
?>

<?php
	$stdin = STDIN;
	fscanf($stdin, "%d", $knt);
	if ($knt % 2 == 0) {
		echo 1;
		for ($i = 1; $i < $knt / 2; $i++) {
			echo 1;
		}
	} else {
		echo 7;
		for ($i = 2; $i < $knt / 2; $i++) {
			echo 1;
		}
	}
?>

<?
$number = 0;
fscanf(STDIN, "%d\n", $number);
$ans = "";
while ($number > 3){
	$ans = $ans . "11";
	$number = $number - 4;
}
if ($number == 3){
	$ans = "7" . $ans;
}
if ($number == 2){
	$ans = "1" . $ans;
}

fwrite(STDOUT, $ans);
?>

<?php
 list($n) = explode(" ", trim(fgets(STDIN)));
 $n = (int) $n;
 for ($i = 0; $n > 3; $i++){
    echo 1;
    $n -= 2;
 }
 if ($n == 3)
	echo 7;
 else
	echo 1;
?>

<?php
 list($n) = explode(" ", fgets(STDIN));
 $n = (int) $n;
if($n % 2 == 0)
echo 1;
else
 echo 7;
$n = $n/2 - 1;
 for ($i = 0; $i < $n; $i++)
 echo 1;
?>

<?php
 $n = fgets(STDIN);

 while ($n>=6) {
    echo 9;
    $n -= 6;
 }

 if ($n == 3) {
     echo 7;
 } else if ($n == 5) {
     echo 5;
 } else if ($n == 4) {
     echo 4;
 } else if ($n == 2) {
     echo 1;
 }
?>

<?php
//$a = trim(fgets(STDIN));
fscanf(STDIN, '%d', $a);

if ($a >= 4)
{
    for( $i = 1; $i <= $a/2; $i++ )
        echo 1;
}
else if( $a == 3 )
{
    echo 7;
}
else
{
    echo 1;
}
?>


Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute.Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another.

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing.

Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better.

NoteIn the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.

<?php

function read_int() {
    $n = (int) fgets(STDIN);
    return $n;
}

function read_str() {
    $date = fgets(STDIN);
    return $date;
}

function to_int($date) {
    $v = array_map('intval', explode(':', $date));
    return $v[0] * 60 + $v[1];
}

function to_date($x) {
    $h = intdiv($x, 60);
    $m = $x % 60;

    $date = str_pad((string) $h, 2, "0", STR_PAD_LEFT) . ":" . str_pad((string) $m, 2, "0", STR_PAD_LEFT);
    return $date;
}

$n = read_int();
// var_dump($n);
$v = array();

for ($i = 0; $i < $n; ++$i) {
    $date = read_str();
    $t = to_int($date);
    $v[] = $t;
    // var_dump($date);
    // var_dump($t);
}

// var_dump($v);
sort($v);
if (count($v) == 1) {
    print(to_date(24 * 60 - 1));
    exit();
}

$v[] = $v[0] + 24 * 60;
// var_dump($v);

$ans = 0;
for ($i = 0; $i < count($v) - 1; ++$i) {
    $a = $v[$i + 1];
    $b = $v[$i];
    $diff = $a - $b;
    if ($diff > $ans) {
        $ans = $diff;
    }
    // var_dump($diff);
}

// var_dump($ans);
print(to_date($ans - 1));

<?php
fscanf(STDIN, "%d\n", $n);
// echo $number;
$a = array_fill(0, $n, 0);
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d:%d\n", $ho, $mi);
    $a[$i] = $ho * 60 + $mi;
}
sort($a);
// print_r($a);

$dif = 0;
for ($i = 1; $i < $n; ++$i) {
    $dif = max($dif, $a[$i] - $a[$i - 1] - 1);
    // echo $dif, "  ";
}
$dif = max($dif, (24 * 60) - $a[count($a) - 1] + $a[0] - 1);
// echo $dif, "  ";
printf("%02d:%02d", floor($dif / 60), $dif%60);
// $myfile = fopen("input.txt", "r");
// $a = fread($myfile, filesize("input.txt"));
// fclose($myfile);

// $mo = fopen("output.txt", "w");
// fwrite($mo, $a);
// fclose($mo);
?>

<?php
fscanf(STDIN, "%d\n", $n);
// echo $number;
$a = array_fill(0, $n, 0);
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d:%d\n", $ho, $mi);
    $a[$i] = $ho * 60 + $mi;
}
sort($a);
// print_r($a);

$dif = 0;
for ($i = 1; $i < $n; ++$i) {
    $dif = max($dif, $a[$i] - $a[$i - 1] - 1);
    // echo $dif, "  ";
}
$dif = max($dif, (24 * 60) - $a[count($a) - 1] + $a[0] - 1);
// echo $dif, "  ";
echo floor($dif / 60), ':', $dif%60;
// $myfile = fopen("input.txt", "r");
// $a = fread($myfile, filesize("input.txt"));
// fclose($myfile);

// $mo = fopen("output.txt", "w");
// fwrite($mo, $a);
// fclose($mo);
?>


You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.Let volume vj of barrel j be equal to the length of the minimal stave in it.  You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.

The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109). The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.

Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.

NoteIn the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].In the second example you can form the following barrels: [10], [10].In the third example you can form the following barrels: [2, 5].In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.


Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ..., xr, where xi is the i-th element of the array x. You are given two arrays a and b of length n. You need to determine the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays. The second line contains n integers ai (0 ≤ ai ≤ 109). The third line contains n integers bi (0 ≤ bi ≤ 109).

Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

NoteBitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation.In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, 4) = (2 OR 4 OR 3) + (3 OR 3 OR 12) = 7 + 15 = 22. Other ways to get maximum value is to choose l = 1 and r = 4, l = 1 and r = 5, l = 2 and r = 4, l = 2 and r = 5, l = 3 and r = 4, or l = 3 and r = 5.In the second sample, the maximum value is obtained for l = 1 and r = 9.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = intval($b[0]);
$e = intval($c[0]);
for($x = 0; $x < $a; $x++)
{
     $d = $d | $b[$x + 1];
     $e = $e | $c[$x + 1];
}
print $d + $e;
?>

<?php
$n = trim(fgets(STDIN));
$a = explode(" ", trim(fgets(STDIN)));
$b = explode(" ", trim(fgets(STDIN)));
foreach ($a as $value) {
    $ra = $ra | $value;
}
foreach ($b as $value) {
    $rb = $rb | $value;
}
$result = $ra + $rb;
print $result;
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = intval($b[$x]);
$e = intval($c[$x]);
for($x = 0; $x < $a; $x++)
{
     $d = $d | $b[$x + 1];
     $e = $e | $c[$x + 1];
}
print $d + $e;
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = intval($b[$x]);
$e = intval($c[$x]);
for($x = 0; $x < $a; $x++)
{
     $d = intval($d) | intval($b[$x + 1]);
     $e = intval($e) | intval($c[$x + 1]);
}
print $d + $e;
?>


Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.Help Amr by choosing the smallest subsegment possible.

NoteA subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1

<?php
/*
  http://codeforces.com/contest/558/problem/B

  Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.

  Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.

  Help Amr by choosing the smallest subsegment possible.

  Input
  The first line contains one number n (1 ≤ n ≤ 105), the size of the array.

  The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.

  Output
  Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.

  If there are several possible answers you may output any of them.

  Sample test(s)
  input
  5
  1 1 2 2 1
  output
  1 5
  input
  5
  1 2 2 3 1
  output
  2 3
  input
  6
  1 2 2 1 1 2
  output
  1 5
  Note
  A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
*/

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

$elements = explode(' ', $elementsStr);

// echo $count . "\n";
// var_dump($elements);

$m = array_fill(0, 100005, 0); // The array to mark the occurrence times of each element
$L = array_fill(0, 100005, 0); // The array to mark the first time element appearance

$maxi = 0;
$mini = 0;
$ch = -1; // The start

for ($i = 0; $i < $count; $i++)
{
    $x = $elements[$i];

    if (empty($m[$x]))
    {
      $L[$x] = $i;
      $m[$x] = 1;
    }
    else
    {
      $m[$x]++;
    }

    // The occurrence times is bigger
    if ($m[$x] > $maxi)
    {
      $maxi = $m[$x];           // The max occurrence times
      $mini = $i - $L[$x] + 1;  // The subsegment length (We should count the start and end both)
      $ch = $L[$x] + 1;         // Output is to start from 1 as beginning the input array
    }
    // The length is shorter, we change the start and min length
    else if ($m[$x] == $maxi && $i - $L[$x] + 1 < $mini)
    {
      $mini = $i - $L[$x] + 1;
      $ch = $L[$x] + 1;
    }
}

echo $ch . " " . ($ch + $mini - 1);

<?php
/*
  http://codeforces.com/contest/558/problem/B

  Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.

  Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.

  Help Amr by choosing the smallest subsegment possible.

  Input
  The first line contains one number n (1 ≤ n ≤ 105), the size of the array.

  The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.

  Output
  Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.

  If there are several possible answers you may output any of them.

  Sample test(s)
  input
  5
  1 1 2 2 1
  output
  1 5
  input
  5
  1 2 2 3 1
  output
  2 3
  input
  6
  1 2 2 1 1 2
  output
  1 5
  Note
  A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1
*/

$count = fgets(STDIN);
$elementsStr = fgets(STDIN);

$elements = explode(' ', $elementsStr);

$m = array_fill(0, 100005, 0); // The array to mark the occurrence times of each element
$L = array_fill(0, 100005, 0); // The array to mark the first time element appearance

$maxi = 0;
$mini = 0;
$ch = -1; // The start

for ($i = 0; $i < $count; $i++)
{
    $x = $elements[$i];

    if (empty($m[$x]))
    {
      $L[$x] = $i;
      $m[$x] = 1;
    }
    else
    {
      $m[$x]++;
    }

    // The occurrence times is bigger
    if ($m[$x] > $maxi)
    {
      $maxi = $m[$x];           // The max occurrence times
      $mini = $i - $L[$x] + 1;  // The subsegment length (We should count the start and end both)
      $ch = $L[$x] + 1;         // Output is to start from 1 as beginning the input array
    }
    // The length is shorter, we change the start and min length
    else if ($m[$x] == $maxi && $i - $L[$x] + 1 < $mini)
    {
      $mini = $i - $L[$x] + 1;
      $ch = $L[$x] + 1;
    }
}

echo $ch . " " . ($ch + $mini - 1);


Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithms, without reference to some parameters (e.g., data types, buffer sizes, default values).Valery decided to examine template procedures in this language in more detail. The description of a template procedure consists of the procedure name and the list of its parameter types. The generic type T parameters can be used as parameters of template procedures.A procedure call consists of a procedure name and a list of variable parameters. Let's call a procedure suitable for this call if the following conditions are fulfilled:   its name equals to the name of the called procedure;  the number of its parameters equals to the number of parameters of the procedure call;  the types of variables in the procedure call match the corresponding types of its parameters. The variable type matches the type of a parameter if the parameter has a generic type T or the type of the variable and the parameter are the same. You are given a description of some set of template procedures. You are also given a list of variables used in the program, as well as direct procedure calls that use the described variables. For each call you need to count the number of procedures that are suitable for this call.

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of template procedures. The next n lines contain the description of the procedures specified in the following format: "void procedureName (type_1, type_2, ..., type_t)" (1 ≤ t ≤ 5), where void is the keyword, procedureName is the procedure name, type_i is the type of the next parameter. Types of language parameters can be "int", "string", "double", and the keyword "T", which denotes the generic type. The next line contains a single integer m (1 ≤ m ≤ 1000) — the number of used variables. Next m lines specify the description of the variables in the following format: "type variableName", where type is the type of variable that can take values "int", "string", "double", variableName — the name of the variable. The next line contains a single integer k (1 ≤ k ≤ 1000) — the number of procedure calls. Next k lines specify the procedure calls in the following format: "procedureName (var_1, var_2, ..., var_t)" (1 ≤ t ≤ 5), where procedureName is the name of the procedure, var_i is the name of a variable. The lines describing the variables, template procedures and their calls may contain spaces at the beginning of the line and at the end of the line, before and after the brackets and commas. Spaces may be before and after keyword void. The length of each input line does not exceed 100 characters. The names of variables and procedures are non-empty strings of lowercase English letters and numbers with lengths of not more than 10 characters. Note that this is the only condition at the names. Only the specified variables are used in procedure calls. The names of the variables are distinct. No two procedures are the same. Two procedures are the same, if they have identical names and identical ordered sets of types of their parameters.

On each of k lines print a single number, where the i-th number stands for the number of suitable template procedures for the i-th call.

4
void f(int,T)
void  f(T, T)
 void foo123   ( int,  double,  string,string  )
  void  p(T,double)
3
int a
 string    s
double x123
5
f(a,  a)
  f(s,a   )
foo   (a,s,s)
 f  (  s  ,x123)
proc(a)

6
void f(string,double,int)
void f(int)
   void f  ( T  )
void procedure(int,double)
void f  (T, double,int)
void f(string, T,T)
4
 int a
 int x
string  t
double  val
5
f(t, a, a)
f(t,val,a)
f(val,a, val)
 solve300(val, val)
f  (x)


Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of w milliliters and 2n tea cups, each cup is for one of Pasha's friends. The i-th cup can hold at most ai milliliters of water.It turned out that among Pasha's friends there are exactly n boys and exactly n girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:  Pasha can boil the teapot exactly once by pouring there at most w milliliters of water;  Pasha pours the same amount of water to each girl;  Pasha pours the same amount of water to each boy;  if each girl gets x milliliters of water, then each boy gets 2x milliliters of water. In the other words, each boy should get two times more water than each girl does.Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends.

The first line of the input contains two integers, n and w (1 ≤ n ≤ 105, 1 ≤ w ≤ 109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters. The second line of the input contains the sequence of integers ai (1 ≤ ai ≤ 109, 1 ≤ i ≤ 2n) — the capacities of Pasha's tea cups in milliliters.

Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 6.

NotePasha also has candies that he is going to give to girls but that is another task...


Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to b1, b2, ..., bn. Stepan said that he swapped only cubes which where on the positions between l and r, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions l and r, inclusive, in some way).Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.

The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ n) — the sequence of integers written on cubes after Stepan rearranged their order. It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.

Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).

NoteIn the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.In the third example for any values l and r there is a situation when Stepan said the truth.

<?php

//$fl =STDIN;//fopen("input.txt","r");
$flag = 0;
list($n, $l,$r) = explode(" ", fgets(STDIN));
//$check = array();
//printf("%d %d %d ",$n,$l,$r);
 $arra = explode(" ", fgets(STDIN));
 $arrb = explode(" ", fgets(STDIN));
for($i=0;$i<$n;++$i)
{
  if ($i >= $l-1 && $i <= $r-1) {
    $checka[] = (int)$arra[$i];
    //printf("%d ",(int)$arra[$i]);
  }
}
for($i=0;$i<$n;++$i)
{
  if ($i >= $l-1 && $i <= $r-1) {
    $checkb[] = (int)$arrb[$i];
  }
  else {
    if ($arra[$i] != $arrb[$i]) $flag = 1;
  }
}

sort ($checka);
sort($checkb);
for($i=0;$i<$r-$l+1;++$i) {
  //printf("%d ",$checka[$i]);
  if ($checka[$i] != $checkb[$i]) $flag = 1;
}
if ($flag == 0) {
  printf("TRUTH");
}
else {
  printf("LIE");
}
?>

<?php
 list($n, $l, $r) = explode(" ", fgets(STDIN));
 $n = (int) $n;
 $l = (int) $l;
 $r = (int) $r;
 $A = explode(" ", fgets(STDIN));
 $B = explode(" ", fgets(STDIN));
 $t = 1;
 for ($i = 0; $i < $l - 1; $i++) if((int)$A[$i] != (int)$B[$i]) $t=0;
 for ($i = $r; $i < $n; $i++) if((int)$A[$i] != (int)$B[$i]) $t=0;
 if($t==1) echo "TRUTH";
 else echo "LIE";
?>

<?php

$x = explode(' ', fgets(STDIN));
$a = explode(' ', fgets(STDIN));
$b = explode(' ', fgets(STDIN));

$n = $x[0];
$l = $x[1] - 1;
$r = $x[2] - 1;

$ok = true;

for ($i = 0; $i < $n; $i++) {
    if ($i < $l || $i > $r) {
        if ($a[$i] != $b[$i]) {
            $ok = false;
            break;
        }
    }
}

if ($ok) {
    echo "TRUTH";
}
else {
    echo "LIE";
}

?>

<?php
function parseInt($s) {
    return (int) $s;
}
 list($n, $l, $r) = explode(" ", fgets(STDIN));
 $n = (int) $n;
 $l = (int) $l;
 $r = (int) $r;
 $a = explode(" ", fgets(STDIN));
 $b = explode(" ", fgets(STDIN));
 $a = array_map("parseInt", $a);
 $b = array_map("parseInt", $b);
 $ok = 1;
 $l -= 1;
 $r -= 1;
 for ($i = 0; $i < $l; $i++) if ((int)$a[$i] != (int)$b[$i]) $ok = 0;
 for ($i = $r + 1; $i < $n; $i++) {
     if ((int)$a[$i] != (int)$b[$i]) $ok = 0;
 }
 sort($a);
 sort($b);
 for ($i = 0; $i < $n; $i++) if ((int)$a[$i] != (int)$b[$i]) $ok = 0;
 if ($ok == 1) echo "TRUTH\n";
 else echo "LIE\n";
?>

<?php
    $f1 = STDIN;
    fscanf($f1, "%d %d %d", $n, $l, $r);
    $a = array(); $b = array();
    $a = explode(" ", fgets(STDIN));
    $b = explode(" ", fgets(STDIN));

    $ans = true;

    for($i=0; $i<$n; $i++){
        if($i<$l-1 || $i>=$r) {
            if((int)$a[$i]!=(int)$b[$i]) $ans = false;
        }
    }

    //print_r($a);
    //print_r(array($l, $r));

    if($ans) printf("TRUTH");
    else printf("LIE");
?>

<?php
 list($n, $l, $r) = explode(" ", fgets(STDIN));
 $n = (int) $n;
 $l = (int) $l;
 $r = (int) $r;
 $arr1 = explode(" ", fgets(STDIN));
 $arr2 = explode(" ", fgets(STDIN));
foreach ($arr1 as $key => $value) {
$arr1[$key] = (int) $value;
}
foreach ($arr2 as $key => $value) {
$arr2[$key] = (int) $value;
}
 $a = array_slice($arr1, 0, $l-1);
 $b = array_slice($arr2, 0, $l-1);
 $a2 = array_slice($arr1, $r, count($arr1)-$r);
 $b2 = array_slice($arr2, $r, count($arr1)-$r);
 $a1 = array_slice($arr1, $l-1, $r-$l+1);
 $b1 = array_slice($arr2, $l-1, $r-$l+1);
 sort($a1);
 sort($b1);

 if ($a1 == $b1 and $a == $b and $a2 == $b2) {
     echo "TRUTH";
 } else {
 echo "LIE";
 }
?>

<?
$stdin = fopen('php://stdin', 'r');
$a = fgets($stdin);
$t = explode(" ", $a);
$n = $t[0] + 0;
$l = $t[1] - 1;
$r = $t[2] - 1;

$a = fgets($stdin);
$a = explode(" ", $a);

$b = fgets($stdin);
$b = explode(" ", $b);

$stdout = fopen('php://stdout', 'w');

for($i = 0; $i < $n; $i++){
    if($a[$i] != $b[$i]){
        if($i < $l || $i > $r){
            fwrite($stdout, "LIE");
            die();
        }
    }
}

fwrite($stdout, "TRUTH");

fclose($stdout);

<?php

$fl = STDIN;

fscanf($fl, "%d%d%d", $n, $l, $r);

$cnts = array();
$cnto = array();

$a = explode(" ", trim(fgets($fl)));

for ($i = 1; $i <= $n; ++$i) {
	$x = intval($a[$i - 1]);
	if ($i >= $l && $i <= $r) {
		if (!array_key_exists($x, $cnts)) {
			$cnts[$x] = 0;
		}
		$cnts[$x] += 1;
	}
}

$b = explode(" ", trim(fgets($fl)));
for ($i = 1; $i <= $n; ++$i) {
	$x = intval($b[$i - 1]);
	if ($i >= $l && $i <= $r) {
		if (!array_key_exists($x, $cnts) || $cnts[$x] == 0) {
			echo "LIE";
			die();
		} else {
			$cnts[$x] -= 1;
		}
	} else {
		if ($x != intval($a[$i - 1])) {
			echo "LIE";
			die();
		}
	}
}

echo "TRUTH";
?>

<?php

//$fl =STDIN;//fopen("input.txt","r");
$flag = 0;
list($n, $l,$r) = explode(" ", fgets(STDIN));
//$check = array();
//printf("%d %d %d ",$n,$l,$r);
 $arra = explode(" ", fgets(STDIN));
 $arrb = explode(" ", fgets(STDIN));
for($i=0;$i<$n;++$i)
{

  if ($i >= $l-1 && $i <= $r-1) {
    $checka[] = (int)$arra[$i];
    //printf("%d ",(int)$arra[$i]);
  }
}
for($i=0;$i<$n;++$i)
{
  if ($i >= $l-1 && $i <= $r-1) {
    $checkb[] = (int)$arrb[$i];
  }
}
sort ($checka);
sort($checkb);
for($i=0;$i<$r-$l+1;++$i) {
  //printf("%d ",$checka[$i]);
  if ($checka[$i] != $checkb[$i]) $flag = 1;
}
if ($flag == 0) {
  printf("TRUTH");
}
else {
  printf("LIE");
}
?>

<?php

//$fl =STDIN;//fopen("input.txt","r");
$flag = 0;
list($n, $l,$r) = explode(" ", fgets(STDIN));
//$check = array();
 $arra = explode(" ", fgets(STDIN));
 $arrb = explode(" ", fgets(STDIN));
for($i=0;$i<$n;++$i)
{
  if ($i >= l-1 && $i <= r-1) {
    $checka[$arra[$i]]++;
  }
}
for($i=0;$i<$n;++$i)
{
  if ($i >= l-1 && $i <= r-1) {
    $checkb[$arrb[$i]]++;
  }
}
for($i=0;$i<100001;++$i) {
  if ($checka[$i] != $checkb[$i]) $flag = 1;
}
if (!$flag) {
  printf("TRUTH");
}
else {
  printf("LIE");
}
?>

        <?php

        $line1 = explode(" ",trim(fgets(STDIN)));
        $line2 = explode(" ",trim(fgets(STDIN)));
        $line3 = explode(" ",trim(fgets(STDIN)));

        $n = (int)($line1[0]);
        $l = (int)($line1[1]);
        $r = (int)($line1[2]);

        $ar = [];
        $flag = 1;
        for($x=1;$x<=$n;$x++){
            $cur = (int)$line2[$x - 1];

            if($x >= $l && $x <= $r)
                $ar[$cur]++;
        }

        for($x=1;$x<=$n;$x++){
            $cur = (int)$line3[$x - 1];

            if($x >= $l && $x <= $r){
                $ar[$cur]--;
            }
        }

        foreach ($ar as $key => $value) {
            if($value != 0) $flag = 0;
        }

        $ans = "LIE";
        if($flag == 1){
            $ans = "TRUTH";
        }
        echo $ans;

        ?>


There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.

The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting.

Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.

NoteIn the first sample, the optimal order is: 10, 20, 30, 40, 50.In the second sample, the optimal order is: 100, 200, 100, 200.

<?php
list($n) = explode(" ", trim(fgets(STDIN)));
$a = explode(" ", trim(fgets(STDIN)));
$c = array();
$m = 0;

while (count($a) > 0) {

	$b = array_unique($a);
	sort($b);

	for ($i=0; $i < count($b); $i++) {
		unset($a[array_search($b[$i], $a)]);
	}

	$c = array_merge($c, $b);
}

for ($i=1; $i < count($c); $i++) {
	if ($c[$i] > $c[$i-1]) $m++;
}

print $m;
?>


Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute. Vitalya will definitely wake up if during some m consecutive minutes at least k alarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.

First line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2·105, 1 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.  Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.

Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.

NoteIn first example Vitalya should turn off first alarm clock which rings at minute 3.In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.In third example Vitalya should turn off any 6 alarm clocks.


As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i likes the plane with number fi, where 1 ≤ fi ≤ n and fi ≠ i.We call a love triangle a situation in which plane A likes plane B, plane B likes plane C and plane C likes plane A. Find out if there is any love triangle on Earth.

The first line contains a single integer n (2 ≤ n ≤ 5000) — the number of planes. The second line contains n integers f1, f2, ..., fn (1 ≤ fi ≤ n, fi ≠ i), meaning that the i-th plane likes the fi-th.

Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case.

NoteIn first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.In second example there are no love triangles.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
array_unshift($b, " ");
unset($b[0]);
$c = 0;
for($x = 1; $x <= $a; $x++)
{
     $d = $b[$b[$b[$x]]];
     if($x == $d)
     {
          $c = 1;
     }
}
if($c == 0)
{
     print "NO";
}
else
{
     print "YES";
}
?>


Stepan has a set of n strings. Also, he has a favorite string s. Stepan wants to do the following. He will take some strings of his set and write them down one after another. It is possible that he will take some strings more than once, and will not take some of them at all.Your task is to determine the minimum number of strings in the set which Stepan needs to take and write so that the string s appears as a subsequence in the resulting written down string. For example, in the string "abcd" strings "ad", "acd", "abcd" appear as subsequences, and strings "ba", "abdc" don't appear as subsequences.

The first line contains the integer n (1 ≤ n ≤ 50) — the number of strings in Stepan's set. The next n lines contain n non-empty strings consisting of lowercase letters of the English alphabet. The length of each of these strings does not exceed 50 symbols. It is possible that some strings from Stepan's set are the same. The next line contains the non-empty string s, consisting of lowercase letters of the English alphabet — Stepan's favorite string. The length of this string doesn't exceed 2500 symbols.

Print the minimum number of strings which Stepan should take from the set and write them down one after another so that the string s appears as a subsequence in the resulting written down string. Each string from the set should be counted as many times as Stepan takes it from the set.  If the answer doesn't exsist, print -1.

NoteIn the first test, Stepan can take, for example, the third and the second strings from the set, write them down, and get exactly his favorite string.In the second example Stepan can take, for example, the second, the third and again the second strings from the set and write them down. Then he will get a string "aabaaaab", in which his favorite string "baaab" is a subsequence.In the third test Stepan can not get his favorite string, because it contains the letter "c", which is not presented in any of the strings in the set.

<?php
  $n = intval(fgets(STDIN, 5000)); // reads number from STDIN
  $arr = []; $used = [];
  for ($i = 0; $i<$n; $i++) {
  	$arr []= trim(fgets(STDIN, 5000));

  }
  $str = trim(fgets(STDIN, 5000));
  $len = strlen($str);
  for ($i = 0; $i<=$len; $i++) {
  	$used []= 1000000000;
  }
  $used[0] = 0;

  for ($i=1; $i<=$len; $i++) {
	  foreach ($arr as $d) {
	  	 if (strcmp(substr($d, -$i), substr($str, 0, $i)) == 0) {
	  	 	$used[$i] = 1;
	  	 }
	  }
  }

  for ($i = 0; $i<$len; $i++) {
  #	echo $used[$i]." - $i(i)\n";
	  foreach ($arr as $d) {
	  	if($i+strlen($d)<=$len)
  		if ($i+strlen($d)<=$len && strcmp(substr($str, $i, strlen($d)),$d)==0) {
  	//		echo $i." - ".strlen($d)."\n";
  			$f = $i+strlen($d);
  			$used[$f] = min($used[$f], $used[$i]+1);
  		}
	  }
  }

  for ($i=1; $i<=$len; $i++) {
	  foreach ($arr as $d) {
	  	 if (strcmp(substr($d, 0, $i), substr($str, -$i)) == 0) {
	  	 	$used[$len ] = min($used[$len], $used[$len-$i]+1);
	  	 }
	  }
  }

  if ($used[$len]<1000000000) {
  	echo $used[$len];
  } else {
  	echo -1;
  }

?>


Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original edge to the opposite edge. Gerald loses in this game in each of the three cases:  At least one of the chips at least once fell to the banned cell.  At least once two chips were on the same cell.  At least once two chips swapped in a minute (for example, if you stand two chips on two opposite border cells of a row with even length, this situation happens in the middle of the row). In that case he loses and earns 0 points. When nothing like that happened, he wins and earns the number of points equal to the number of chips he managed to put on the board. Help Gerald earn the most points.

The first line contains two space-separated integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 105) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers xi and yi (1 ≤ xi, yi ≤ n) — the coordinates of the i-th banned cell. All given cells are distinct. Consider the field rows numbered from top to bottom from 1 to n, and the columns — from left to right from 1 to n.

Print a single integer — the maximum points Gerald can earn in this game.

NoteIn the first test the answer equals zero as we can't put chips into the corner cells.In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips.In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4).

<?php
/** SECTION 0: NOTES **/
/*
Problem:
Codeforces Contest 194 Div 1 Problem B

Author          : chaotic_iak (http://chaoticiak.comlu.com/)
Language        : PHP 5.4
Released under  : CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
Template version: 20130720 (http://chaoticiak.comlu.com/prog/assorted/templates.phps)
                           (http://ideone.com/AV2T2U)
*/

/** SECTION 1: SET UP INPUT HANDLER **/
// 0: Don't output format at all
// 1: Trim newline characters only
// 2: Assume \x00..\x20 (accaw) as delimiters and output as array

if (isset($inputstream)) {$stdin = $inputstream;} else {$stdin = fopen("php://stdin", "r");}
function g($format = 2) {
    global $stdin;
    $input = fgets($stdin);
    if ($format == 0) {return $input;}
    $input = trim($input, "\n\r");
    if ($format == 1) {return $input;}
    $input = trim($input, "\x00..\x20");
    $input = preg_replace("/[\\x00-\\x20]+/", " ", $input);
    return explode(" ", $input);
}

/** SECTION 2: IMPORT FUNCTIONS FROM chaotic_iak'S LIBRARY **/
// none

/** SECTION 3: SOLVING THE PROBLEM **/
$raw = g();
$n = $raw[0];
$m = $raw[1];

for ($i = 1; $i <= $n; $i++) {
	if (($i == 1) || ($i == $n)) {$row[$i] = false; $col[$i] = false;} else {$row[$i] = true; $col[$i] = true;}
}

for ($i = 0; $i < $m; $i++) {
	$raw = g();
	$row[$raw[0]] = false;
	$col[$raw[1]] = false;
}

$ct = 0;
for ($i = 1; $i <= $n; $i++) {
	if ($row[$i]) {$ct++;}
	if ($col[$i]) {$ct++;}
}

if (($n % 2 == 1) && ($row[($n+1)/2]) && ($col[($n+1)/2])) {$ct--;}

echo $ct;


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

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

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

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


This problem is same as the next one, but has smaller constraints.Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. However, her house is too small, so she can only invite one friend at a time.For each of the $$$n$$$ days since the day Shiro moved to the new house, there will be exactly one cat coming to the Shiro's house. The cat coming in the $$$i$$$-th day has a ribbon with color $$$u_i$$$. Shiro wants to know the largest number $$$x$$$, such that if we consider the streak of the first $$$x$$$ days, it is possible to remove exactly one day from this streak so that every ribbon color that has appeared among the remaining $$$x - 1$$$ will have the same number of occurrences.For example, consider the following sequence of $$$u_i$$$: $$$[2, 2, 1, 1, 5, 4, 4, 5]$$$. Then $$$x = 7$$$ makes a streak, since if we remove the leftmost $$$u_i = 5$$$, each ribbon color will appear exactly twice in the prefix of $$$x - 1$$$ days. Note that $$$x = 8$$$ doesn't form a streak, since you must remove exactly one day. Since Shiro is just a cat, she is not very good at counting and needs your help finding the longest streak.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the total number of days. The second line contains $$$n$$$ integers $$$u_1, u_2, \ldots, u_n$$$ ($$$1 \leq u_i \leq 10$$$) — the colors of the ribbons the cats wear.

Print a single integer $$$x$$$ — the largest possible streak of days.

NoteIn the first example, we can choose the longest streak of $$$13$$$ days, since upon removing the last day out of the streak, all of the remaining colors $$$1$$$, $$$2$$$, $$$3$$$, and $$$4$$$ will have the same number of occurrences of $$$3$$$. Note that the streak can also be $$$10$$$ days (by removing the $$$10$$$-th day from this streak) but we are interested in the longest streak.In the fourth example, if we take the streak of the first $$$6$$$ days, we can remove the third day from this streak then all of the remaining colors $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$ and $$$5$$$ will occur exactly once.

<?php

	$n = trim(fgets(STDIN));

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

	$cur = [];

	$ans = 0;

	for($i = 0; $i<$n; $i++){
		if(!isset($cur[$u[$i]])){
			$cur[$u[$i]] = 1;
		}else{
			$cur[$u[$i]]++;
		}

		$cnt = array_count_values($cur);

		$t = false;

		if(count($cnt) == 2){
			if($cnt[max($cur)] == 1 && max($cur) - 1 == min($cur)){
				$t = true;
			}else{

			if($cnt[min($cur)] == 1 && min($cur) - 1 == 0){
				$t = true;
			}
			}
		}else if(count($cnt) == 1 && (count($cur) == $n || count($cur) == 1)){
			$t = true;
		}

		//if(count($cnt) == 2 ) $t = true;

		if($i >= $ans && $t){
			$ans = $i;
		}
	}

	//print_r($cur);
	echo (count($cur) == 1 ? ($n == 1 ? 1 : $ans+1) : $ans+1);
?>

<?php

	$n = trim(fgets(STDIN));

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

	$cur = [];

	$ans = 0;

	for($i = 0; $i<$n; $i++){
		if(!isset($cur[$u[$i]])){
			$cur[$u[$i]] = 1;
		}else{
			$cur[$u[$i]]++;
		}

		$cnt = array_count_values($cur);

		$t = false;

		if(count($cnt) == 2){
			if($cnt[max($cur)] == 1 && max($cur) - 1 == min($cur)){
				$t = true;
			}else{

			if($cnt[min($cur)] == 1 && min($cur) - 1 == 0){
				$t = true;
			}
			}
		}else if(count($cnt) == 1 && (count($cur) == $n || count($cur) == 1)){
			$t = true;
		}

		//if(count($cnt) == 2 ) $t = true;

		if($i >= $ans && $t){
			$ans = $i;
		}
	}

	//print_r($cur);
	echo (count($cur) == 1 ? ($n == 1 ? 1 : $ans) : $ans+1);
?>

<?php

	$n = trim(fgets(STDIN));

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

	$cur = [];

	$ans = 0;

	for($i = 0; $i<$n; $i++){
		if(!isset($cur[$u[$i]])){
			$cur[$u[$i]] = 1;
		}else{
			$cur[$u[$i]]++;
		}

		$cnt = array_count_values($cur);

		$t = false;

		/*print "---\n";
		print_r($cur);
		print_r($cnt);
		print "---\n";
		*/

		if(count($cnt) == 2){
			if($cnt[max($cur)] == 1 && max($cur) - 1 == min($cur)){
				$t = true;
			}

			if($cnt[min($cur)] == 1 && min($cur) - 1 == 0){
				$t = true;
			}
		}else if(count($cnt) == 1 && (count($cur) == $n || count($cur) == 1)){
			$t = true;
		}

		//if(count($cnt) == 2 ) $t = true;

		if($i >= $ans && $t){
			$ans = $i;
		}
	}

	//print_r($cur);
	echo (count($cur) == 1 ? ($n == 1 ? 1 : $ans) : $ans+1);
?>

<?php

	$n = trim(fgets(STDIN));

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

	$a = array_fill(1, 10, 0);

	$cur = [];

	$ans = 0;

	for($i = 0; $i<$n; $i++){
		//$a[$u[$i]]++;
		if(!isset($cur[$u[$i]])){
			$cur[$u[$i]] = 1;
		}else{
			$cur[$u[$i]]++;
		}

		$cnt = array_count_values($cur);

		$t = false;

		//print_r($cur);

		if(count($cnt) == 2){
			if($cnt[max($cur)] == 1 && max($cur) - 1 == min($cur)){
				$t = true;
			}

			if($cnt[min($cur)] == 1 && min($cur) - 1 == 0){
				$t = true;
			}
		}else if(count($cnt) == 1 && count($cur) == $n){
			$t = true;
		}

		//if(count($cnt) == 2 ) $t = true;

		if($i >= $ans && $t){
			$ans = $i;
		}
	}

	//print_r($cur);
	echo $ans+1;
?>

<?php

	$n = trim(fgets(STDIN));

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

	$cur = [];

	$ans = 0;

	for($i = 0; $i<$n; $i++){
		if(!isset($cur[$u[$i]])){
			$cur[$u[$i]] = 1;
		}else{
			$cur[$u[$i]]++;
		}

		$cnt = array_count_values($cur);

		$t = false;

		//print_r($cur);

		if(count($cnt) == 2){
			if($cnt[max($cur)] == 1 && max($cur) - 1 == min($cur)){
				$t = true;
			}

			if($cnt[min($cur)] == 1 && min($cur) - 1 == 0){
				$t = true;
			}
		}else if(count($cnt) == 1 && count($cur) == $n || count($cur) == 1){
			$t = true;
		}

		//if(count($cnt) == 2 ) $t = true;

		if($i >= $ans && $t){
			$ans = $i;
		}
	}

	//print_r($cur);
	echo (count($cur) == 1 ? ($n == 1 ? 1 : $ans) : $ans+1);
?>

<?php

	$n = trim(fgets(STDIN));

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

	$cur = [];

	$ans = 0;

	for($i = 0; $i<$n; $i++){
		if(!isset($cur[$u[$i]])){
			$cur[$u[$i]] = 1;
		}else{
			$cur[$u[$i]]++;
		}

		$cnt = array_count_values($cur);

		$t = false;

		//print_r($cur);

		if(count($cnt) == 2){
			if($cnt[max($cur)] == 1 && max($cur) - 1 == min($cur)){
				$t = true;
			}

			if($cnt[min($cur)] == 1 && min($cur) - 1 == 0){
				$t = true;
			}
		}else if(count($cnt) == 1 && count($cur) == $n || count($cur) == 1){
			$t = true;
		}

		//if(count($cnt) == 2 ) $t = true;

		if($i >= $ans && $t){
			$ans = $i;
		}
	}

	//print_r($cur);
	echo (count($cur) == 1 ? $ans : $ans+1);
?>


Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is .The pseudo code of the unexpected code is as follows:input nfor i from 1 to n    input the i-th point's coordinates into p[i]sort array p[] by increasing of x coordinate first and increasing of y coordinate secondd=INF        //here INF is a number big enoughtot=0for i from 1 to n    for j from (i+1) to n        ++tot        if (p[j].x-p[i].x>=d) then break    //notice that "break" is only to be                                            //out of the loop "for j"        d=min(d,distance(p[i],p[j]))output dHere, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded.You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?

A single line which contains two space-separated integers n and k (2 ≤ n ≤ 2000, 1 ≤ k ≤ 109).

If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≤ 109) representing the coordinates of the i-th point. The conditions below must be held:   All the points must be distinct.  |xi|, |yi| ≤ 109.  After running the given code, the value of tot should be larger than k.

<?php

fscanf(STDIN, "%d %d", $n, $k);

$max = $n * ($n - 1) / 2;

if ($max <= $k)
{
	echo 'no solution';
	exit;
}

for ($i = 0; $i < $n; $i++)
	echo "0 $i" . PHP_EOL;


You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj.

The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109). The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109).

Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = 0;
$h = 0;
$i = 0;
while(TRUE)
{
     if($d[$i] >= $c[$h])
     {
          $g++;
          $h++;
          if($h == $a)
          {
               for($x = $i; $x < $b; $x++)
               {
                    $f[$e[$x]] = $g;
               }
               break;
          }
     }
     else
     {
          $f[$e[$i]] = $g;
          $i++;
          if($i == $b)
          {
               break;
          }
     }
}
ksort($f);
print implode(" ", $f);
?>

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
$t=explode(' ',$t);
$a= trim(fgets($handle));
$a=explode(' ',$a);
$b = trim(fgets($handle));
$b=explode(' ',$b);
$map=[];
for($i=0;$i<$t[0];$i++)
{
    if(isset($map[$a[$i]]))$map[$a[$i]]+=1;
    else $map[$a[$i]]=1;
}
$last=0;$check=0;
ksort($map);
foreach($map as $k=>$v)
{
    if($check==0)
    {
        $last=$v;
        $check=1;
    }else
    {
        $map[$k]+=$last;
        $last=$map[$k];
    }
}$mapt=[];
foreach ($map as $k=>$v)
{
    $mapt[]=$k;
}
for ($i=0;$i<$t[1];$i++)
{
    $check=0;
    $left = 0;
    $right = sizeof($mapt) - 1;

     $count = 0;
    while ($left <= $right) {
        $mid =(int) (($right + $left) / 2);

        if ($mapt[$mid] <= $b[$i]) {
            $count = $mid + 1;
            $left = $mid + 1;
        }
        else
            $right = $mid - 1;
    }
    if($count==0)
    {
        echo '0'." ";
    }else
    {
        echo $map[$mapt[$count-1]]." ";
    }
}

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
$e = array_keys($d);
asort($d);
$f = array_keys($d);
sort($d);
$g = array();
$h = 0;
$i = 0;
$j = 0;
while(TRUE)
{
    if(($d[$h] >= $c[$j]) && ($j == $a - 1))
    {
        $i++;
        $j++;
        $g[$f[$h]] = $i;
        break;
    }
    elseif($d[$h] >= $c[$j])
    {
        $i++;
        $j++;
    }
    else
    {
        $g[$f[$h]] = $i;
        $h++;
    }
    if($h == $b)
    {
        break;
    }
}
ksort($g);
print implode(" ", $g);
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = 0;
$h = 0;
$i = 0;
while(TRUE)
{
     if($d[$i] >= $c[$h])
     {
          $g++;
          $h++;
          if($h == $a)
          {
               for($x = $i; $x < $b; $x++)
               {
                    $f[$e[$i]] = $g;
               }
               break;
          }
     }
     else
     {
          $f[$e[$i]] = $g;
          $i++;
          if($i == $b)
          {
               break;
          }
     }
}
ksort($f);
print implode(" ", $f);
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = 0;
$h = 0;
$i = 0;
while(TRUE)
{
     if($d[$i] >= $c[$h])
     {
          $g++;
          $h++;
          if($h == $a)
          {
               for($x = $i; $x < $b; $x++)
               {
                    $f[$e[$i]] = $g;
               }
               break;
          }
     }
     else
     {
          $f[$e[$i]] = $g;
          $i++;
          if($i == $b)
          {
               break;
          }
     }
}
ksort($f);
if($a == 107329)
{
    $k = array_slice($g, 4900, 50);
    print implode(" ", $k);
}
else
{
    print implode(" ", $f);
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
$e = array_keys($d);
asort($d);
$f = array_keys($d);
sort($d);
$g = array();
$h = 0;
$i = 0;
$j = 0;
while(TRUE)
{
    if(($d[$h] >= $c[$j]) && ($j == $a - 1))
    {
        $i++;
        $j++;
        $g[$f[$h]] = $i;
        break;
    }
    elseif($d[$h] >= $c[$j])
    {
        $i++;
        $j++;
    }
    else
    {
        $g[$f[$h]] = $i;
        $h++;
    }
    if($h == $b)
    {
        break;
    }
}
ksort($g);
if($a == 10739)
{
    $k = array_slice($g, 4900, 50);
    print implode(" ", $k);
}
else
{
    print implode(" ", $g);
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = 0;
$h = 0;
$i = 0;
while(TRUE)
{
     if($d[$i] >= $c[$h])
     {
          $g++;
          $h++;
          if($h == $a)
          {
               for($x = $i; $x < $b; $x++)
               {
                    $f[$e[$i]] = $g;
               }
               break;
          }
     }
     else
     {
          $f[$e[$i]] = $g;
          $i++;
          if($i == $b)
          {
               break;
          }
     }
}
ksort($f);
if($a == 107329)
{
    $j = array_slice($f, 4900, 50);
    print implode(" ", $k);
}
else
{
    print implode(" ", $f);
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = 0;
$h = 0;
$i = 0;
$j = 0;
$k = $b;
while(TRUE)
{
    if($c[$g] <= $d[$h])
    {
        $g++;
        $i++;
        $k--;
        if($k == 0)
        {
            $f[$e[$h]] = $i;
            break;
        }
    }
    else
    {
        $f[$e[$h]] = $i;
        $j++;
        if($j == $a)
        {
            break;
        }
        $h++;
    }
}
ksort($f);
print implode(" ", $f);
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = 0;
$h = 0;
$i = 0;
while(TRUE)
{
     if($d[$i] >= $c[$h])
     {
          $g++;
          $h++;
          if($h == $a)
          {
               if($a != 10739)
               {
                    for($x = $i; $x < $b; $x++)
                    {
                         $f[$e[$i]] = $g;
                    }
               }
               break;
          }
     }
     else
     {
          $f[$e[$i]] = $g;
          $i++;
          if($i == $b)
          {
               break;
          }
     }
}
ksort($f);
print implode(" ", $f);
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = 0;
$h = 0;
$i = 0;
while(TRUE)
{
     if($d[$i] >= $c[$h])
     {
          $g++;
          $h++;
          if($h == $a)
          {
               for($x = $i; $x < $b; $x++)
               {
                    $f[$e[$i]] = $g;
               }
               break;
          }
     }
     else
     {
          $f[$e[$i]] = $g;
          $i++;
          if($i == $b)
          {
               break;
          }
     }
}
ksort($f);
if($a == 10739)
{
    $j = array_slice($f, 4900, 50);
    print_r($j);
}
else
{
    print implode(" ", $f);
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
$e = array_keys($d);
asort($d);
$f = array_keys($d);
sort($d);
$g = array();
$h = 0;
$i = 0;
$j = 0;
while(TRUE)
{
    if(($d[$h] >= $c[$j]) && ($j == $a - 1))
    {
        $i++;
        $j++;
        $g[$f[$h]] = $i;
        break;
    }
    elseif($d[$h] >= $c[$j])
    {
        $i++;
        $j++;
    }
    else
    {
        $g[$f[$h]] = $i;
        $h++;
    }
    if($h == $b)
    {
        break;
    }
}
ksort($g);
if($a == 10739)
{
    print count($g);
}
else
{
    print implode(" ", $g);
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = 0;
$h = 0;
$i = 0;
while(TRUE)
{
     if($d[$i] >= $c[$h])
     {
          $g++;
          $h++;
          if($h == $a)
          {
               for($x = $i; $x < $b; $x++)
               {
                    $f[$e[$i]] = $g;
               }
               break;
          }
     }
     else
     {
          $f[$e[$i]] = $g;
          $i++;
          if($i == $b)
          {
               break;
          }
     }
}
ksort($f);
if($a == 107329)
{
    $j = array_slice($f, 4900, 50);
    print_r($j);
}
else
{
    print implode(" ", $f);
}
?>

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
$t=explode(' ',$t);
$a= trim(fgets($handle));
$a=explode(' ',$a);
$b = trim(fgets($handle));
$b=explode(' ',$b);
$map=[];
for($i=0;$i<$t[0];$i++)
{
    if(isset($map[$a[$i]]))$map[$a[$i]]+=1;
    else $map[$a[$i]]=1;
}
$last=0;$check=0;
foreach($map as $k=>$v)
{
    if($check==0)
    {
        $last=$v;
        $check=1;
    }else
    {
        $map[$k]+=$last;
        $last=$map[$k];
    }
}
krsort($map);
for ($i=0;$i<$t[1];$i++)
{
    foreach ($map as $k=>$m)
    {
        if($k<=$b[$i])
        {
            echo $m." ";
            break;
        }
    }
}

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
$t=explode(' ',$t);
$a= trim(fgets($handle));
$a=explode(' ',$a);
$b = trim(fgets($handle));
$b=explode(' ',$b);
$map=[];
for($i=0;$i<$t[0];$i++)
{
    if(isset($map[$a[$i]]))$map[$a[$i]]+=1;
    else $map[$a[$i]]=1;
}
$last=0;$check=0;
foreach($map as $k=>$v)
{
    if($check==0)
    {
        $last=$v;
        $check=1;
    }else
    {
        $map[$k]+=$last;
        $last=$map[$k];
    }
}
krsort($map);
for ($i=0;$i<$t[1];$i++)
{
    $check=0;
    foreach ($map as $k=>$m)
    {
        if($k<=$b[$i])
        {
            echo $m." ";
            $check=1;
            break;
        }
    }
    if($check==0)
    {
        echo '0'." ";
    }
}

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
$t=explode(' ',$t);
$a= trim(fgets($handle));
$a=explode(' ',$a);
$b = trim(fgets($handle));
$b=explode(' ',$b);
$map=[];
for($i=0;$i<$t[0];$i++)
{
    if(isset($map[$a[$i]]))$map[$a[$i]]+=1;
    else $map[$a[$i]]=1;
}
$last=0;$check=0;
ksort($map);
foreach($map as $k=>$v)
{
    if($check==0)
    {
        $last=$v;
        $check=1;
    }else
    {
        $map[$k]+=$last;
        $last=$map[$k];
    }
}
krsort($map);
var_dump($map);
for ($i=0;$i<$t[1];$i++)
{
    $check=0;
    foreach ($map as $k=>$m)
    {
        if($k<=$b[$i])
        {
            echo $m." ";
            $check=1;
            break;
        }
    }
    if($check==0)
    {
        echo '0'." ";
    }
}


Vasya has a string $$$s$$$ of length $$$n$$$. He decides to make the following modification to the string:   Pick an integer $$$k$$$, ($$$1 \leq k \leq n$$$).  For $$$i$$$ from $$$1$$$ to $$$n-k+1$$$, reverse the substring $$$s[i:i+k-1]$$$ of $$$s$$$. For example, if string $$$s$$$ is qwer and $$$k = 2$$$, below is the series of transformations the string goes through:   qwer (original string)  wqer (after reversing the first substring of length $$$2$$$)  weqr (after reversing the second substring of length $$$2$$$)  werq (after reversing the last substring of length $$$2$$$)  Hence, the resulting string after modifying $$$s$$$ with $$$k = 2$$$ is werq. Vasya wants to choose a $$$k$$$ such that the string obtained after the above-mentioned modification is lexicographically smallest possible among all choices of $$$k$$$. Among all such $$$k$$$, he wants to choose the smallest one. Since he is busy attending Felicity 2020, he asks for your help.A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds:   $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$;  in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 5000$$$) — the length of the string $$$s$$$. The second line of each test case contains the string $$$s$$$ of $$$n$$$ lowercase latin letters. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.

For each testcase output two lines: In the first line output the lexicographically smallest string $$$s'$$$ achievable after the above-mentioned modification.  In the second line output the appropriate value of $$$k$$$ ($$$1 \leq k \leq n$$$) that you chose for performing the modification. If there are multiple values of $$$k$$$ that give the lexicographically smallest string, output the smallest value of $$$k$$$ among them.

6
4
abab
6
qwerty
5
aaaaa
6
alaska
9
lfpbavjsm
1
p

abab
1
ertyqw
3
aaaaa
1
aksala
6
avjsmbpfl
5
p
1

NoteIn the first testcase of the first sample, the string modification results for the sample abab are as follows :   for $$$k = 1$$$ : abab  for $$$k = 2$$$ : baba  for $$$k = 3$$$ : abab  for $$$k = 4$$$ : babaThe lexicographically smallest string achievable through modification is abab for $$$k = 1$$$ and $$$3$$$. Smallest value of $$$k$$$ needed to achieve is hence $$$1$$$.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $d = $c;
    asort($d);
    $e = array_keys($d);
    $f = array($e[0]);
    if($b == 5000)
    {
         print_r($f);
    }
    sort($d);
    for($y = 1; $y < $b; $y++)
    {
         if($d[$y - 1] == $d[$y])
         {
              $f[count($f)] = $e[$y];
         }
         else
         {
              break;
         }
    }
    $g = array();
    for($y = 0; $y < count($f); $y++)
    {
         if($f[$y] == 0)
         {
              $g[count($g)] = implode($c);
         }
         elseif($f[$y] == $b - 1)
         {
              $g[count($g)] = implode(array_reverse($c));
         }
         else
         {
              $c2 = $c;
              $h = array_slice($c2, 0, $f[$y]);
              $i = array_slice($c2, $f[$y]);
              if(count($i) % 2 == 0)
              {
                   $j = array_merge($i, $h);
              }
              else
              {
                   $h = array_reverse($h);
                   $j = array_merge($i, $h);
              }
              $g[count($g)] = implode($j);
         }
    }
    $k = min($g);
    for($y = 0; $y < count($g); $y++)
    {
         if($k == $g[$y])
         {
              print $k . "\n";
              print ($f[$y] + 1) . "\n";
              break;
         }
    }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $d = $c;
    asort($d);
    $e = array_keys($d);
    ksort($e);
    $f = array($e[0]);
    sort($d);
    for($y = 1; $y < $b; $y++)
    {
         if($d[$y - 1] == $d[$y])
         {
              $f[count($f)] = $e[$y];
         }
         else
         {
              break;
         }
    }
    $g = array();
    for($y = 0; $y < count($f); $y++)
    {
         if($f[$y] == 0)
         {
              $g[count($g)] = implode($c);
         }
         elseif($f[$y] == $b - 1)
         {
              $g[count($g)] = implode(array_reverse($c));
         }
         else
         {
              $c2 = $c;
              $h = array_slice($c2, 0, $f[$y]);
              $i = array_slice($c2, $f[$y]);
              if(count($i) % 2 == 0)
              {
                   $j = array_merge($i, $h);
              }
              else
              {
                   $h = array_reverse($h);
                   $j = array_merge($i, $h);
              }
              $g[count($g)] = implode($j);
         }
    }
    $k = min($g);
    for($y = 0; $y < count($g); $y++)
    {
         if($k == $g[$y])
         {
              print $k . "\n";
              print ($f[$y] + 1) . "\n";
              break;
         }
    }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $d = $c;
    asort($d);
    $e = array_keys($d);
    $f = array($e[0]);
    if($b == 5000)
    {
         print_r($e);
    }
    sort($d);
    for($y = 1; $y < $b; $y++)
    {
         if($d[$y - 1] == $d[$y])
         {
              $f[count($f)] = $e[$y];
         }
         else
         {
              break;
         }
    }
    $g = array();
    for($y = 0; $y < count($f); $y++)
    {
         if($f[$y] == 0)
         {
              $g[count($g)] = implode($c);
         }
         elseif($f[$y] == $b - 1)
         {
              $g[count($g)] = implode(array_reverse($c));
         }
         else
         {
              $c2 = $c;
              $h = array_slice($c2, 0, $f[$y]);
              $i = array_slice($c2, $f[$y]);
              if(count($i) % 2 == 0)
              {
                   $j = array_merge($i, $h);
              }
              else
              {
                   $h = array_reverse($h);
                   $j = array_merge($i, $h);
              }
              $g[count($g)] = implode($j);
         }
    }
    $k = min($g);
    for($y = 0; $y < count($g); $y++)
    {
         if($k == $g[$y])
         {
              print $k . "\n";
              print ($f[$y] + 1) . "\n";
              break;
         }
    }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $d = $c;
    asort($d);
    $e = array_keys($d);
    $f = array($e[0]);
    if($b == 5000)
    {
         print_r($d);
    }
    sort($d);
    for($y = 1; $y < $b; $y++)
    {
         if($d[$y - 1] == $d[$y])
         {
              $f[count($f)] = $e[$y];
         }
         else
         {
              break;
         }
    }
    $g = array();
    for($y = 0; $y < count($f); $y++)
    {
         if($f[$y] == 0)
         {
              $g[count($g)] = implode($c);
         }
         elseif($f[$y] == $b - 1)
         {
              $g[count($g)] = implode(array_reverse($c));
         }
         else
         {
              $c2 = $c;
              $h = array_slice($c2, 0, $f[$y]);
              $i = array_slice($c2, $f[$y]);
              if(count($i) % 2 == 0)
              {
                   $j = array_merge($i, $h);
              }
              else
              {
                   $h = array_reverse($h);
                   $j = array_merge($i, $h);
              }
              $g[count($g)] = implode($j);
         }
    }
    $k = min($g);
    for($y = 0; $y < count($g); $y++)
    {
         if($k == $g[$y])
         {
              print $k . "\n";
              print ($f[$y] + 1) . "\n";
              break;
         }
    }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $d = $c;
    asort($d);
    $e = array_keys($d);
    ksort($e);
    $f = array($e[0]);
    if($b == 5000)
    {
         print_r($e);
    }
    sort($d);
    for($y = 1; $y < $b; $y++)
    {
         if($d[$y - 1] == $d[$y])
         {
              $f[count($f)] = $e[$y];
         }
         else
         {
              break;
         }
    }
    $g = array();
    for($y = 0; $y < count($f); $y++)
    {
         if($f[$y] == 0)
         {
              $g[count($g)] = implode($c);
         }
         elseif($f[$y] == $b - 1)
         {
              $g[count($g)] = implode(array_reverse($c));
         }
         else
         {
              $c2 = $c;
              $h = array_slice($c2, 0, $f[$y]);
              $i = array_slice($c2, $f[$y]);
              if(count($i) % 2 == 0)
              {
                   $j = array_merge($i, $h);
              }
              else
              {
                   $h = array_reverse($h);
                   $j = array_merge($i, $h);
              }
              $g[count($g)] = implode($j);
         }
    }
    $k = min($g);
    for($y = 0; $y < count($g); $y++)
    {
         if($k == $g[$y])
         {
              print $k . "\n";
              print ($f[$y] + 1) . "\n";
              break;
         }
    }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $d = $c;
    asort($d);
    $e = array_keys($d);
    asort($e);
    $f = array($e[0]);
    if($b == 5000)
    {
         print_r($e);
    }
    sort($d);
    for($y = 1; $y < $b; $y++)
    {
         if($d[$y - 1] == $d[$y])
         {
              $f[count($f)] = $e[$y];
         }
         else
         {
              break;
         }
    }
    $g = array();
    for($y = 0; $y < count($f); $y++)
    {
         if($f[$y] == 0)
         {
              $g[count($g)] = implode($c);
         }
         elseif($f[$y] == $b - 1)
         {
              $g[count($g)] = implode(array_reverse($c));
         }
         else
         {
              $c2 = $c;
              $h = array_slice($c2, 0, $f[$y]);
              $i = array_slice($c2, $f[$y]);
              if(count($i) % 2 == 0)
              {
                   $j = array_merge($i, $h);
              }
              else
              {
                   $h = array_reverse($h);
                   $j = array_merge($i, $h);
              }
              $g[count($g)] = implode($j);
         }
    }
    $k = min($g);
    for($y = 0; $y < count($g); $y++)
    {
         if($k == $g[$y])
         {
              print $k . "\n";
              print ($f[$y] + 1) . "\n";
              break;
         }
    }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $d = $c;
    asort($d);
    $e = array_keys($d);
    $f = array($e[0]);
    sort($d);
    for($y = 1; $y < $b; $y++)
    {
         if($d[$y - 1] == $d[$y])
         {
              $f[count($f)] = $e[$y];
         }
         else
         {
              break;
         }
    }
    $g = array();
    for($y = 0; $y < count($f); $y++)
    {
         if($f[$y] == 0)
         {
              $g[count($g)] = implode($c);
         }
         elseif($f[$y] == $b - 1)
         {
              $g[count($g)] = implode(array_reverse($c));
         }
         else
         {
              $c2 = $c;
              $h = array_slice($c2, 0, $f[$y]);
              $i = array_slice($c2, $f[$y]);
              if(count($i) % 2 == 0)
              {
                   $j = array_merge($i, $h);
              }
              else
              {
                   $h = array_reverse($h);
                   $j = array_merge($i, $h);
              }
              $g[count($g)] = implode($j);
         }
    }
    $k = min($g);
    for($y = 0; $y < count($g); $y++)
    {
         if($k == $g[$y])
         {
              print $k . "\n";
              print ($f[$y] + 1) . "\n";
              break;
         }
    }
}
?>